@adaline/gateway 0.30.0 → 0.31.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 +48 -48
- package/dist/index.d.ts +48 -48
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -519,7 +519,7 @@ declare const CompleteChatHandlerRequest: z.ZodObject<{
|
|
|
519
519
|
param: string;
|
|
520
520
|
title: string;
|
|
521
521
|
description: string;
|
|
522
|
-
default: string
|
|
522
|
+
default: string;
|
|
523
523
|
choices: string[];
|
|
524
524
|
}>;
|
|
525
525
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -564,7 +564,7 @@ declare const CompleteChatHandlerRequest: z.ZodObject<{
|
|
|
564
564
|
param: string;
|
|
565
565
|
title: string;
|
|
566
566
|
description: string;
|
|
567
|
-
default: string
|
|
567
|
+
default: string;
|
|
568
568
|
choices: string[];
|
|
569
569
|
}>;
|
|
570
570
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -853,7 +853,7 @@ declare const CompleteChatHandlerRequest: z.ZodObject<{
|
|
|
853
853
|
param: string;
|
|
854
854
|
title: string;
|
|
855
855
|
description: string;
|
|
856
|
-
default: string
|
|
856
|
+
default: string;
|
|
857
857
|
choices: string[];
|
|
858
858
|
}>;
|
|
859
859
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -1063,7 +1063,7 @@ declare const CompleteChatHandlerRequest: z.ZodObject<{
|
|
|
1063
1063
|
param: string;
|
|
1064
1064
|
title: string;
|
|
1065
1065
|
description: string;
|
|
1066
|
-
default: string
|
|
1066
|
+
default: string;
|
|
1067
1067
|
choices: string[];
|
|
1068
1068
|
}>;
|
|
1069
1069
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -2265,7 +2265,7 @@ declare const GetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
2265
2265
|
param: string;
|
|
2266
2266
|
title: string;
|
|
2267
2267
|
description: string;
|
|
2268
|
-
default: string
|
|
2268
|
+
default: string;
|
|
2269
2269
|
choices: string[];
|
|
2270
2270
|
}>;
|
|
2271
2271
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -2309,7 +2309,7 @@ declare const GetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
2309
2309
|
param: string;
|
|
2310
2310
|
title: string;
|
|
2311
2311
|
description: string;
|
|
2312
|
-
default: string
|
|
2312
|
+
default: string;
|
|
2313
2313
|
choices: string[];
|
|
2314
2314
|
}>;
|
|
2315
2315
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -2386,7 +2386,7 @@ declare const GetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
2386
2386
|
param: string;
|
|
2387
2387
|
title: string;
|
|
2388
2388
|
description: string;
|
|
2389
|
-
default: string
|
|
2389
|
+
default: string;
|
|
2390
2390
|
choices: string[];
|
|
2391
2391
|
}>;
|
|
2392
2392
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -2486,7 +2486,7 @@ declare const GetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
2486
2486
|
param: string;
|
|
2487
2487
|
title: string;
|
|
2488
2488
|
description: string;
|
|
2489
|
-
default: string
|
|
2489
|
+
default: string;
|
|
2490
2490
|
choices: string[];
|
|
2491
2491
|
}>;
|
|
2492
2492
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -2816,7 +2816,7 @@ declare const ProxyCompleteChatHandlerRequest: z.ZodObject<{
|
|
|
2816
2816
|
param: string;
|
|
2817
2817
|
title: string;
|
|
2818
2818
|
description: string;
|
|
2819
|
-
default: string
|
|
2819
|
+
default: string;
|
|
2820
2820
|
choices: string[];
|
|
2821
2821
|
}>;
|
|
2822
2822
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -2861,7 +2861,7 @@ declare const ProxyCompleteChatHandlerRequest: z.ZodObject<{
|
|
|
2861
2861
|
param: string;
|
|
2862
2862
|
title: string;
|
|
2863
2863
|
description: string;
|
|
2864
|
-
default: string
|
|
2864
|
+
default: string;
|
|
2865
2865
|
choices: string[];
|
|
2866
2866
|
}>;
|
|
2867
2867
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -2912,7 +2912,7 @@ declare const ProxyCompleteChatHandlerRequest: z.ZodObject<{
|
|
|
2912
2912
|
param: string;
|
|
2913
2913
|
title: string;
|
|
2914
2914
|
description: string;
|
|
2915
|
-
default: string
|
|
2915
|
+
default: string;
|
|
2916
2916
|
choices: string[];
|
|
2917
2917
|
}>;
|
|
2918
2918
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -2962,7 +2962,7 @@ declare const ProxyCompleteChatHandlerRequest: z.ZodObject<{
|
|
|
2962
2962
|
param: string;
|
|
2963
2963
|
title: string;
|
|
2964
2964
|
description: string;
|
|
2965
|
-
default: string
|
|
2965
|
+
default: string;
|
|
2966
2966
|
choices: string[];
|
|
2967
2967
|
}>;
|
|
2968
2968
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -3484,7 +3484,7 @@ declare const ProxyGetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
3484
3484
|
param: string;
|
|
3485
3485
|
title: string;
|
|
3486
3486
|
description: string;
|
|
3487
|
-
default: string
|
|
3487
|
+
default: string;
|
|
3488
3488
|
choices: string[];
|
|
3489
3489
|
}>;
|
|
3490
3490
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -3528,7 +3528,7 @@ declare const ProxyGetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
3528
3528
|
param: string;
|
|
3529
3529
|
title: string;
|
|
3530
3530
|
description: string;
|
|
3531
|
-
default: string
|
|
3531
|
+
default: string;
|
|
3532
3532
|
choices: string[];
|
|
3533
3533
|
}>;
|
|
3534
3534
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -3578,7 +3578,7 @@ declare const ProxyGetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
3578
3578
|
param: string;
|
|
3579
3579
|
title: string;
|
|
3580
3580
|
description: string;
|
|
3581
|
-
default: string
|
|
3581
|
+
default: string;
|
|
3582
3582
|
choices: string[];
|
|
3583
3583
|
}>;
|
|
3584
3584
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -3627,7 +3627,7 @@ declare const ProxyGetEmbeddingsHandlerRequest: z.ZodObject<{
|
|
|
3627
3627
|
param: string;
|
|
3628
3628
|
title: string;
|
|
3629
3629
|
description: string;
|
|
3630
|
-
default: string
|
|
3630
|
+
default: string;
|
|
3631
3631
|
choices: string[];
|
|
3632
3632
|
}>;
|
|
3633
3633
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -3828,7 +3828,7 @@ declare const ProxyStreamChatHandlerRequest: z.ZodObject<{
|
|
|
3828
3828
|
param: string;
|
|
3829
3829
|
title: string;
|
|
3830
3830
|
description: string;
|
|
3831
|
-
default: string
|
|
3831
|
+
default: string;
|
|
3832
3832
|
choices: string[];
|
|
3833
3833
|
}>;
|
|
3834
3834
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -3873,7 +3873,7 @@ declare const ProxyStreamChatHandlerRequest: z.ZodObject<{
|
|
|
3873
3873
|
param: string;
|
|
3874
3874
|
title: string;
|
|
3875
3875
|
description: string;
|
|
3876
|
-
default: string
|
|
3876
|
+
default: string;
|
|
3877
3877
|
choices: string[];
|
|
3878
3878
|
}>;
|
|
3879
3879
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -3924,7 +3924,7 @@ declare const ProxyStreamChatHandlerRequest: z.ZodObject<{
|
|
|
3924
3924
|
param: string;
|
|
3925
3925
|
title: string;
|
|
3926
3926
|
description: string;
|
|
3927
|
-
default: string
|
|
3927
|
+
default: string;
|
|
3928
3928
|
choices: string[];
|
|
3929
3929
|
}>;
|
|
3930
3930
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -3974,7 +3974,7 @@ declare const ProxyStreamChatHandlerRequest: z.ZodObject<{
|
|
|
3974
3974
|
param: string;
|
|
3975
3975
|
title: string;
|
|
3976
3976
|
description: string;
|
|
3977
|
-
default: string
|
|
3977
|
+
default: string;
|
|
3978
3978
|
choices: string[];
|
|
3979
3979
|
}>;
|
|
3980
3980
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -4312,7 +4312,7 @@ declare const StreamChatHandlerRequest: z.ZodObject<{
|
|
|
4312
4312
|
param: string;
|
|
4313
4313
|
title: string;
|
|
4314
4314
|
description: string;
|
|
4315
|
-
default: string
|
|
4315
|
+
default: string;
|
|
4316
4316
|
choices: string[];
|
|
4317
4317
|
}>;
|
|
4318
4318
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -4357,7 +4357,7 @@ declare const StreamChatHandlerRequest: z.ZodObject<{
|
|
|
4357
4357
|
param: string;
|
|
4358
4358
|
title: string;
|
|
4359
4359
|
description: string;
|
|
4360
|
-
default: string
|
|
4360
|
+
default: string;
|
|
4361
4361
|
choices: string[];
|
|
4362
4362
|
}>;
|
|
4363
4363
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -4646,7 +4646,7 @@ declare const StreamChatHandlerRequest: z.ZodObject<{
|
|
|
4646
4646
|
param: string;
|
|
4647
4647
|
title: string;
|
|
4648
4648
|
description: string;
|
|
4649
|
-
default: string
|
|
4649
|
+
default: string;
|
|
4650
4650
|
choices: string[];
|
|
4651
4651
|
}>;
|
|
4652
4652
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -4745,7 +4745,7 @@ declare const StreamChatHandlerRequest: z.ZodObject<{
|
|
|
4745
4745
|
param: string;
|
|
4746
4746
|
title: string;
|
|
4747
4747
|
description: string;
|
|
4748
|
-
default: string
|
|
4748
|
+
default: string;
|
|
4749
4749
|
choices: string[];
|
|
4750
4750
|
}>;
|
|
4751
4751
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -6266,7 +6266,7 @@ declare const GatewayCompleteChatRequest: z.ZodObject<{
|
|
|
6266
6266
|
param: string;
|
|
6267
6267
|
title: string;
|
|
6268
6268
|
description: string;
|
|
6269
|
-
default: string
|
|
6269
|
+
default: string;
|
|
6270
6270
|
choices: string[];
|
|
6271
6271
|
}>;
|
|
6272
6272
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -6311,7 +6311,7 @@ declare const GatewayCompleteChatRequest: z.ZodObject<{
|
|
|
6311
6311
|
param: string;
|
|
6312
6312
|
title: string;
|
|
6313
6313
|
description: string;
|
|
6314
|
-
default: string
|
|
6314
|
+
default: string;
|
|
6315
6315
|
choices: string[];
|
|
6316
6316
|
}>;
|
|
6317
6317
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -6609,7 +6609,7 @@ declare const GatewayCompleteChatRequest: z.ZodObject<{
|
|
|
6609
6609
|
param: string;
|
|
6610
6610
|
title: string;
|
|
6611
6611
|
description: string;
|
|
6612
|
-
default: string
|
|
6612
|
+
default: string;
|
|
6613
6613
|
choices: string[];
|
|
6614
6614
|
}>;
|
|
6615
6615
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -6709,7 +6709,7 @@ declare const GatewayCompleteChatRequest: z.ZodObject<{
|
|
|
6709
6709
|
param: string;
|
|
6710
6710
|
title: string;
|
|
6711
6711
|
description: string;
|
|
6712
|
-
default: string
|
|
6712
|
+
default: string;
|
|
6713
6713
|
choices: string[];
|
|
6714
6714
|
}>;
|
|
6715
6715
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -6810,7 +6810,7 @@ declare const GatewayStreamChatRequest: z.ZodObject<{
|
|
|
6810
6810
|
param: string;
|
|
6811
6811
|
title: string;
|
|
6812
6812
|
description: string;
|
|
6813
|
-
default: string
|
|
6813
|
+
default: string;
|
|
6814
6814
|
choices: string[];
|
|
6815
6815
|
}>;
|
|
6816
6816
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -6855,7 +6855,7 @@ declare const GatewayStreamChatRequest: z.ZodObject<{
|
|
|
6855
6855
|
param: string;
|
|
6856
6856
|
title: string;
|
|
6857
6857
|
description: string;
|
|
6858
|
-
default: string
|
|
6858
|
+
default: string;
|
|
6859
6859
|
choices: string[];
|
|
6860
6860
|
}>;
|
|
6861
6861
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -7151,7 +7151,7 @@ declare const GatewayStreamChatRequest: z.ZodObject<{
|
|
|
7151
7151
|
param: string;
|
|
7152
7152
|
title: string;
|
|
7153
7153
|
description: string;
|
|
7154
|
-
default: string
|
|
7154
|
+
default: string;
|
|
7155
7155
|
choices: string[];
|
|
7156
7156
|
}>;
|
|
7157
7157
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -7251,7 +7251,7 @@ declare const GatewayStreamChatRequest: z.ZodObject<{
|
|
|
7251
7251
|
param: string;
|
|
7252
7252
|
title: string;
|
|
7253
7253
|
description: string;
|
|
7254
|
-
default: string
|
|
7254
|
+
default: string;
|
|
7255
7255
|
choices: string[];
|
|
7256
7256
|
}>;
|
|
7257
7257
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -7351,7 +7351,7 @@ declare const GatewayGetEmbeddingsRequest: z.ZodObject<{
|
|
|
7351
7351
|
param: string;
|
|
7352
7352
|
title: string;
|
|
7353
7353
|
description: string;
|
|
7354
|
-
default: string
|
|
7354
|
+
default: string;
|
|
7355
7355
|
choices: string[];
|
|
7356
7356
|
}>;
|
|
7357
7357
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -7395,7 +7395,7 @@ declare const GatewayGetEmbeddingsRequest: z.ZodObject<{
|
|
|
7395
7395
|
param: string;
|
|
7396
7396
|
title: string;
|
|
7397
7397
|
description: string;
|
|
7398
|
-
default: string
|
|
7398
|
+
default: string;
|
|
7399
7399
|
choices: string[];
|
|
7400
7400
|
}>;
|
|
7401
7401
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -7481,7 +7481,7 @@ declare const GatewayGetEmbeddingsRequest: z.ZodObject<{
|
|
|
7481
7481
|
param: string;
|
|
7482
7482
|
title: string;
|
|
7483
7483
|
description: string;
|
|
7484
|
-
default: string
|
|
7484
|
+
default: string;
|
|
7485
7485
|
choices: string[];
|
|
7486
7486
|
}>;
|
|
7487
7487
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -7542,7 +7542,7 @@ declare const GatewayGetEmbeddingsRequest: z.ZodObject<{
|
|
|
7542
7542
|
param: string;
|
|
7543
7543
|
title: string;
|
|
7544
7544
|
description: string;
|
|
7545
|
-
default: string
|
|
7545
|
+
default: string;
|
|
7546
7546
|
choices: string[];
|
|
7547
7547
|
}>;
|
|
7548
7548
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -7605,7 +7605,7 @@ declare const GatewayProxyCompleteChatRequest: z.ZodObject<{
|
|
|
7605
7605
|
param: string;
|
|
7606
7606
|
title: string;
|
|
7607
7607
|
description: string;
|
|
7608
|
-
default: string
|
|
7608
|
+
default: string;
|
|
7609
7609
|
choices: string[];
|
|
7610
7610
|
}>;
|
|
7611
7611
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -7650,7 +7650,7 @@ declare const GatewayProxyCompleteChatRequest: z.ZodObject<{
|
|
|
7650
7650
|
param: string;
|
|
7651
7651
|
title: string;
|
|
7652
7652
|
description: string;
|
|
7653
|
-
default: string
|
|
7653
|
+
default: string;
|
|
7654
7654
|
choices: string[];
|
|
7655
7655
|
}>;
|
|
7656
7656
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -7701,7 +7701,7 @@ declare const GatewayProxyCompleteChatRequest: z.ZodObject<{
|
|
|
7701
7701
|
param: string;
|
|
7702
7702
|
title: string;
|
|
7703
7703
|
description: string;
|
|
7704
|
-
default: string
|
|
7704
|
+
default: string;
|
|
7705
7705
|
choices: string[];
|
|
7706
7706
|
}>;
|
|
7707
7707
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -7751,7 +7751,7 @@ declare const GatewayProxyCompleteChatRequest: z.ZodObject<{
|
|
|
7751
7751
|
param: string;
|
|
7752
7752
|
title: string;
|
|
7753
7753
|
description: string;
|
|
7754
|
-
default: string
|
|
7754
|
+
default: string;
|
|
7755
7755
|
choices: string[];
|
|
7756
7756
|
}>;
|
|
7757
7757
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -7802,7 +7802,7 @@ declare const GatewayProxyStreamChatRequest: z.ZodObject<{
|
|
|
7802
7802
|
param: string;
|
|
7803
7803
|
title: string;
|
|
7804
7804
|
description: string;
|
|
7805
|
-
default: string
|
|
7805
|
+
default: string;
|
|
7806
7806
|
choices: string[];
|
|
7807
7807
|
}>;
|
|
7808
7808
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -7847,7 +7847,7 @@ declare const GatewayProxyStreamChatRequest: z.ZodObject<{
|
|
|
7847
7847
|
param: string;
|
|
7848
7848
|
title: string;
|
|
7849
7849
|
description: string;
|
|
7850
|
-
default: string
|
|
7850
|
+
default: string;
|
|
7851
7851
|
choices: string[];
|
|
7852
7852
|
}>;
|
|
7853
7853
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -7898,7 +7898,7 @@ declare const GatewayProxyStreamChatRequest: z.ZodObject<{
|
|
|
7898
7898
|
param: string;
|
|
7899
7899
|
title: string;
|
|
7900
7900
|
description: string;
|
|
7901
|
-
default: string
|
|
7901
|
+
default: string;
|
|
7902
7902
|
choices: string[];
|
|
7903
7903
|
}>;
|
|
7904
7904
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -7948,7 +7948,7 @@ declare const GatewayProxyStreamChatRequest: z.ZodObject<{
|
|
|
7948
7948
|
param: string;
|
|
7949
7949
|
title: string;
|
|
7950
7950
|
description: string;
|
|
7951
|
-
default: string
|
|
7951
|
+
default: string;
|
|
7952
7952
|
choices: string[];
|
|
7953
7953
|
}>;
|
|
7954
7954
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -7998,7 +7998,7 @@ declare const GatewayProxyGetEmbeddingsRequest: z.ZodObject<{
|
|
|
7998
7998
|
param: string;
|
|
7999
7999
|
title: string;
|
|
8000
8000
|
description: string;
|
|
8001
|
-
default: string
|
|
8001
|
+
default: string;
|
|
8002
8002
|
choices: string[];
|
|
8003
8003
|
}>;
|
|
8004
8004
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -8042,7 +8042,7 @@ declare const GatewayProxyGetEmbeddingsRequest: z.ZodObject<{
|
|
|
8042
8042
|
param: string;
|
|
8043
8043
|
title: string;
|
|
8044
8044
|
description: string;
|
|
8045
|
-
default: string
|
|
8045
|
+
default: string;
|
|
8046
8046
|
choices: string[];
|
|
8047
8047
|
}>;
|
|
8048
8048
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -8092,7 +8092,7 @@ declare const GatewayProxyGetEmbeddingsRequest: z.ZodObject<{
|
|
|
8092
8092
|
param: string;
|
|
8093
8093
|
title: string;
|
|
8094
8094
|
description: string;
|
|
8095
|
-
default: string
|
|
8095
|
+
default: string;
|
|
8096
8096
|
choices: string[];
|
|
8097
8097
|
}>;
|
|
8098
8098
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
|
@@ -8141,7 +8141,7 @@ declare const GatewayProxyGetEmbeddingsRequest: z.ZodObject<{
|
|
|
8141
8141
|
param: string;
|
|
8142
8142
|
title: string;
|
|
8143
8143
|
description: string;
|
|
8144
|
-
default: string
|
|
8144
|
+
default: string;
|
|
8145
8145
|
choices: string[];
|
|
8146
8146
|
}>;
|
|
8147
8147
|
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ var ie__default = /*#__PURE__*/_interopDefault(ie);
|
|
|
16
16
|
var vt__default = /*#__PURE__*/_interopDefault(vt);
|
|
17
17
|
var Se__default = /*#__PURE__*/_interopDefault(Se);
|
|
18
18
|
|
|
19
|
-
var pt=Object.defineProperty,lt=Object.defineProperties;var ut=Object.getOwnPropertyDescriptors;var ye=Object.getOwnPropertySymbols;var yt=Object.prototype.hasOwnProperty,ht=Object.prototype.propertyIsEnumerable;var W=(s,t)=>(t=Symbol[s])?t:Symbol.for("Symbol."+s),Ct=s=>{throw TypeError(s)};var he=(s,t,a)=>t in s?pt(s,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[t]=a,T=(s,t)=>{for(var a in t||(t={}))yt.call(t,a)&&he(s,a,t[a]);if(ye)for(var a of ye(t))ht.call(t,a)&&he(s,a,t[a]);return s},M=(s,t)=>lt(s,ut(t));var bt=(s=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(s,{get:(t,a)=>(typeof require!="undefined"?require:t)[a]}):s)(function(s){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var l=(s,t,a)=>new Promise((e,d)=>{var r=p=>{try{i(a.next(p));}catch(n){d(n);}},o=p=>{try{i(a.throw(p));}catch(n){d(n);}},i=p=>p.done?e(p.value):Promise.resolve(p.value).then(r,o);i((a=a.apply(s,t)).next());}),b=function(s,t){this[0]=s,this[1]=t;},O=(s,t,a)=>{var e=(o,i,p,n)=>{try{var m=a[o](i),c=(i=m.value)instanceof b,C=m.done;Promise.resolve(c?i[0]:i).then(g=>c?e(o==="return"?o:"next",i[1]?{done:g.done,value:g.value}:g,p,n):p({value:g,done:C})).catch(g=>e("throw",g,p,n));}catch(g){n(g);}},d=o=>r[o]=i=>new Promise((p,n)=>e(o,i,p,n)),r={};return a=a.apply(s,t),r[W("asyncIterator")]=()=>r,d("next"),d("throw"),d("return"),r},Q=s=>{var t=s[W("asyncIterator")],a=!1,e,d={};return t==null?(t=s[W("iterator")](),e=r=>d[r]=o=>t[r](o)):(t=t.call(s),e=r=>d[r]=o=>{if(a){if(a=!1,r==="throw")throw o;return o}return a=!0,{done:!1,value:new b(new Promise(i=>{var p=t[r](o);p instanceof Object||Ct("Object expected"),i(p);}),1)}}),d[W("iterator")]=()=>d,e("next"),"throw"in t?e("throw"):d.throw=r=>{throw r},"return"in t&&e("return"),d},U=(s,t,a)=>(t=s[W("asyncIterator")])?t.call(s):(s=s[W("iterator")](),t={},a=(e,d)=>(d=s[e])&&(t[e]=r=>new Promise((o,i,p)=>(r=d.call(s,r),p=r.done,Promise.resolve(r.value).then(n=>o({value:n,done:p}),i)))),a("next"),a("return"),t);var w=class s extends Error{constructor(t,a=500,e){super(t),this.name="GatewayError",this.status=a,this.data=e,Error.captureStackTrace&&Error.captureStackTrace(this,s);}},gt="GatewayTelemetryError",Ce=class s extends types.GatewayBaseError{constructor({info:t,cause:a}){super({info:t,cause:a},gt),this.info=t,this.cause=a,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayTelemetryError(t){return t instanceof s}};var Rt="HttpClientError",N=class s extends types.GatewayBaseError{constructor({info:t,cause:a}){super({info:t,cause:a},Rt),this.info=t,this.cause=a,Object.setPrototypeOf(this,new.target.prototype);}static isHttpClientError(t){return t instanceof s}},wt="HttpRequestError",E=class s extends types.GatewayBaseError{constructor(t,a=500,e,d){super({info:t,cause:{status:a,headers:e,data:d}},wt),this.info=t,this.cause={status:a,headers:e,data:d},Object.setPrototypeOf(this,new.target.prototype);}static isHttpRequestError(t){return t instanceof s}};var f=class{static setTracer(t){this.tracer||(this.tracer=t||api.trace.getTracer(this.DEFAULT_TRACER_KEY));}static getTracer(){return this.tracer||api.trace.getTracer(this.DEFAULT_TRACER_KEY)}static setMeter(t){this.meter||(this.meter=t||api.metrics.getMeter(this.DEFAULT_METER_KEY));}static getMeter(){return this.meter||api.metrics.getMeter(this.DEFAULT_METER_KEY)}};f.DEFAULT_TRACER_KEY="gateway",f.DEFAULT_METER_KEY="gateway",f.tracer=void 0,f.meter=void 0;var Z=s=>{let t={};return s&&(typeof s=="object"||s instanceof Headers)&&Object.entries(s).forEach(([a,e])=>{Array.isArray(e)?t[a]=e.join(", "):typeof e=="string"?t[a]=e:t[a]="";}),t},Ee=s=>{var r,o,i;let t=(s==null?void 0:s.message)||"An unexpected error occurred",a=((r=s==null?void 0:s.response)==null?void 0:r.status)||500,e=Z((o=s==null?void 0:s.response)==null?void 0:o.headers)||{},d=((i=s==null?void 0:s.response)==null?void 0:i.data)||{};return new E(t,a,e,d)},ee=class{constructor(t){this.isNodeEnvironment=()=>typeof process!="undefined"&&process.versions!=null&&process.versions.node!=null;let{axiosInstance:a,timeoutInMilliseconds:e,enableProxyAgent:d}=t;this.client=a||ie__default.default.create();let r=zod.z.number().int().positive().optional();if(this.defaultTimeout=r.parse(e),this.client.defaults.timeout=this.defaultTimeout,this.enableProxyAgent=d!=null?d:!0,this.enableProxyAgent){let i=bt("proxy-agent");this.httpProxyAgent=new i.ProxyAgent,this.httpsProxyAgent=new i.ProxyAgent({rejectUnauthorized:!1});}let o=h.getLogger();o==null||o.debug(`IsomorphicHttpClient initialized with defaultTimeout: ${this.defaultTimeout}`);}makeRequest(o,i,p){return l(this,arguments,function*(t,a,e,d={},r){let n=h.getLogger(),m=c=>l(this,null,function*(){try{let C=T(M(T(T({},t==="get"||t==="delete"?{params:e}:{data:e}),d),{timeout:this.defaultTimeout}),this.enableProxyAgent?{httpAgent:this.httpProxyAgent,httpsAgent:this.httpsProxyAgent}:{});if(t==="get"||t==="delete"){let g=yield this.client[t](a,C);c==null||c.setStatus({code:api.SpanStatusCode.OK,message:"request successful"});let F={data:g.data,headers:Z(g.headers),status:{code:g.status,text:g.statusText}};return n==null||n.debug("IsomorphicHttpClient.makeRequest response: ",F),F}else {let g=yield this.client[t](a,C.data,M(T({},C),{params:C.params}));c==null||c.setStatus({code:api.SpanStatusCode.OK,message:"request successful"});let F={data:g.data,headers:Z(g.headers),status:{code:g.status,text:g.statusText}};return n==null||n.debug("IsomorphicHttpClient.makeRequest response: ",F),F}}catch(C){throw n==null||n.warn("IsomorphicHttpClient.makeRequest error: ",C),c==null||c.setStatus({code:api.SpanStatusCode.ERROR,message:"request failed"}),ie__default.default.isAxiosError(C)?Ee(C):new N({info:"An unexpected error occurred",cause:C})}finally{c==null||c.end();}});return r?yield api.context.with(r,()=>l(this,null,function*(){return yield f.getTracer().startActiveSpan("http.request",C=>l(this,null,function*(){return C.setAttribute(semanticConventions.ATTR_HTTP_REQUEST_METHOD,t.toUpperCase()),C.setAttribute(semanticConventions.ATTR_URL_FULL,a),yield m(C)}))})):m()})}stream(t,a,e,d,r,o){return O(this,null,function*(){let i=h.getLogger();i==null||i.debug(`IsomorphicHttpClient.STREAM request to ${t}`,{data:e,headers:d});let p=function(n){return O(this,null,function*(){let m=Date.now(),c=!1;try{if(this.isNodeEnvironment()){i==null||i.debug("IsomorphicHttpClient.stream in node environment");let y=yield new b(this.client.request({method:a,url:t,headers:d,data:e,responseType:"stream",signal:r==null?void 0:r.abortSignal}));try{for(var C=U(y.data),g,F,z;g=!(F=yield new b(C.next())).done;g=!1){let v=F.value;if(!c){let G=Date.now()-m;n==null||n.setAttribute("time-to-first-token",G),c=!0;}n==null||n.addEvent("stream.chunk",{message:"stream chunk received"});let R=v.toString();i==null||i.debug("IsomorphicHttpClient.stream chunk: ",R),yield R;}}catch(F){z=[F];}finally{try{g&&(F=C.return)&&(yield new b(F.call(C)));}finally{if(z)throw z[0]}}n==null||n.setStatus({code:api.SpanStatusCode.OK,message:"stream successful"});}else {i==null||i.debug("IsomorphicHttpClient.stream in browser environment");let y={method:a,headers:new Headers(T({},d)),body:a!=="get"?JSON.stringify(e):void 0,signal:r==null?void 0:r.abortSignal},v=yield new b(fetch(t,y));if(!v.ok){i==null||i.warn("IsomorphicHttpClient.stream response not ok: ",v),n==null||n.setStatus({code:api.SpanStatusCode.ERROR,message:"stream failed"});let R=yield new b(v.json());throw new E(`Request failed with status ${v.status}`,v.status,Z(v.headers),R)}if(v.body){let R=v.body.getReader();for(;;){let{done:G,value:j}=yield new b(R.read());if(G){if(!c&&j){let Y=Date.now()-m;n==null||n.setAttribute("time-to-first-token",Y),c=!0;}n==null||n.addEvent("stream.chunk",{message:"stream chunk received"});let D=new TextDecoder().decode(j,{stream:!0});i==null||i.debug("IsomorphicHttpClient.stream chunk: ",D),yield D;break}if(!c){let D=Date.now()-m;n==null||n.setAttribute("time-to-first-token",D),c=!0;}n==null||n.addEvent("stream.chunk",{message:"stream chunk received"});let $=new TextDecoder().decode(j,{stream:!0});i==null||i.debug("IsomorphicHttpClient.stream chunk: ",$),yield $;}n==null||n.setStatus({code:api.SpanStatusCode.OK,message:"stream successful"});}else throw i==null||i.warn("IsomorphicHttpClient.stream response has no body"),n==null||n.setStatus({code:api.SpanStatusCode.ERROR,message:"stream failed"}),new E("Cannot stream the body of the response.",500,{},v)}}catch(y){throw i==null||i.warn("IsomorphicHttpClient.stream error: ",y),n==null||n.setStatus({code:api.SpanStatusCode.ERROR,message:"stream failed"}),E.isHttpRequestError(y)?y:(y==null?void 0:y.name)==="AbortError"?new E("AbortError",408,{},{}):(y==null?void 0:y.name)==="CanceledError"?new E("AbortError",408,{},{}):ie__default.default.isAxiosError(y)?Ee(y):new N({info:"An unexpected error occurred",cause:y})}finally{n==null||n.end();}})}.bind(this);return o?yield*Q(yield new b(api.context.with(o,()=>l(this,null,function*(){return yield f.getTracer().startActiveSpan("http.stream",m=>l(this,null,function*(){return m.setAttribute(semanticConventions.ATTR_HTTP_REQUEST_METHOD,a.toUpperCase()),m.setAttribute(semanticConventions.ATTR_URL_FULL,t),yield p(m)}))})))):yield*Q(p())})}get(t,a,e,d){return l(this,null,function*(){let r=h.getLogger();return r==null||r.debug(`IsomorphicHttpClient.GET request to ${t}`,{params:a,headers:e}),this.makeRequest("get",t,a||{},{headers:e},d)})}post(t,a,e,d){return l(this,null,function*(){let r=h.getLogger();return r==null||r.debug(`IsomorphicHttpClient.POST request to ${t}`,{data:a,headers:e}),this.makeRequest("post",t,a||{},{headers:e},d)})}put(t,a,e,d){return l(this,null,function*(){let r=h.getLogger();return r==null||r.debug(`IsomorphicHttpClient.PUT request to ${t}`,{data:a,headers:e}),this.makeRequest("put",t,a||{},{headers:e},d)})}delete(t,a,e,d){return l(this,null,function*(){let r=h.getLogger();return r==null||r.debug(`IsomorphicHttpClient.DELETE request to ${t}`,{params:a,headers:e}),this.makeRequest("delete",t,a||{},{headers:e},d)})}patch(t,a,e,d){return l(this,null,function*(){let r=h.getLogger();return r==null||r.debug(`IsomorphicHttpClient.PATCH request to ${t}`,{data:a,headers:e}),this.makeRequest("patch",t,a||{},{headers:e},d)})}};var xt="QueueTaskTimeoutError",te=class s extends types.GatewayBaseError{constructor({info:t,cause:a}){super({info:t,cause:a},xt),this.info=t,this.cause=a,Object.setPrototypeOf(this,new.target.prototype);}static isQueueTaskTimeoutError(t){return t instanceof s}};var xe=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 ae=(s,t)=>vt__default.default(s+JSON.stringify(t)).toString(),I=s=>s instanceof w?s:N.isHttpClientError(s)?new w(s.message):s instanceof Error?new w(s.message):new w(s),q=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined";var qt={error:"color: red",warn:"color: yellow",info:"color: green"},St=(s,t,...a)=>{if(q())q()&&console.log(`%c[${s.toUpperCase()}] [${t}]`,qt[s],...a);else switch(s){case"error":console.error(...a);break;case"warn":console.warn(...a);break;default:console.log(...a);}},kt=(s,t,...a)=>{var e;q()||((e=process==null?void 0:process.env)==null?void 0:e.DEBUG)==="true"&&St(s,t,...a);},L=(s,t,...a)=>l(void 0,null,function*(){let e=[];s.forEach(d=>{let r=d[t];if(typeof r=="function")try{let o=r(...a);o instanceof Promise&&e.push(o);}catch(o){kt("error",`SAFELY_INVOKE_CALLBACKS:${String(t)}:`,o);}}),yield Promise.allSettled(e);}),ve=s=>new Promise(t=>setTimeout(t,s));var h=class{static setLogger(t){this.logger=t;}static getLogger(){return this.logger}};var qe=class{debug(t,...a){console.debug(t,...a);}info(t,...a){console.info(t,...a);}warn(t,...a){q()?console.warn(`%WARN: %c${t}`,"color: yellow; font-weight: bold;","",...a):console.warn(`\x1B[33mWARN:\x1B[0m ${t}`,...a);}error(t,...a){q()?console.error(`%ERROR: %c${t}`,"color: lightcoral; font-weight: bold;","",...a):console.error(`\x1B[91mERROR:\x1B[0m ${t}`,...a);}critical(t,...a){q()?console.error(`%cCRITICAL: %c${t}`,"color: red; font-weight: bold;","",...a):console.error(`\x1B[31;1mCRITICAL:\x1B[0m ${t}`,...a);}};var B=class{constructor(t){this.activeTasks=0;this.queue=[];this.options=t;}enqueue(t){let a=h.getLogger();a==null||a.debug(`SimpleQueue.enqueue invoked, id: ${t.id}`),api.context.with(t.telemetryContext,()=>l(this,null,function*(){return f.getTracer().startActiveSpan("queue.task.pickup-wait",d=>l(this,null,function*(){d.setAttribute("id",t.id),this.queue.push({task:t,taskSpan:d}),a==null||a.debug(`SimpleQueue.enqueue task enqueued, id: ${t.id}`);}))})),this.processQueue();}executeWithTimeout(t,a){let e=h.getLogger();return e==null||e.debug(`SimpleQueue.executeWithTimeout invoked with timeout: ${this.options.timeout}, id: ${t.id}`),new Promise((d,r)=>{let o=setTimeout(()=>{e==null||e.warn(`SimpleQueue.executeWithTimeout timed out, id: ${t.id}`),r(new te({info:"Queue task timeout",cause:new Error("Queue task timeout")}));},this.options.timeout);e==null||e.debug(`SimpleQueue.executeWithTimeout task executing, id: ${t.id}`),t.execute(t.request,a).then(i=>{e==null||e.debug(`SimpleQueue.executeWithTimeout task completed, id: ${t.id}`),clearTimeout(o),d(i);}).catch(i=>{e==null||e.warn(`SimpleQueue.executeWithTimeout task errored, id: ${t.id}`),clearTimeout(o),r(i);});})}executeWithRetry(t,a){return l(this,null,function*(){let e=h.getLogger();return yield api.context.with(t.telemetryContext,()=>l(this,null,function*(){let d=f.getTracer();return yield d.startActiveSpan("queue.task.execute",r=>l(this,null,function*(){e==null||e.debug(`SimpleQueue.executeWithRetry invoked, attempt: ${this.options.retryCount-a}, id: ${t.id}`),r.setAttribute("attempt",this.options.retryCount-a);try{let o=api.context.active(),i=yield this.executeWithTimeout(t,o);return r.setStatus({code:api.SpanStatusCode.OK}),r.end(),i}catch(o){if(a===0)throw e==null||e.warn(`SimpleQueue.executeWithRetry retry count reached, id: ${t.id}`),r.end(),o;let i=!0,p=this.options.retry.initialDelay*Math.pow(this.options.retry.exponentialFactor,this.options.retryCount-a);if(E.isHttpRequestError(o)){if(o.cause.status===429){e==null||e.warn(`SimpleQueue.executeWithRetry rate limiting error, id: ${t.id}`);let n=J.safeParse(t.request);if(n.success){let m=n.data.model.getRetryDelay(o.cause.headers);i=m.shouldRetry,m.delayMs>0&&(p=m.delayMs);}}o.cause.status>=500&&o.cause.status<600&&(e==null||e.warn(`SimpleQueue.executeWithRetry ${o.cause.status} error, id: ${t.id}`));}else e==null||e.warn(`SimpleQueue.executeWithRetry non http-request error, id: ${t.id}`,{error:o});if(i)return yield d.startActiveSpan("queue.task.retry-wait",n=>l(this,null,function*(){return e==null||e.debug(`SimpleQueue.executeWithRetry retry wait: ${p}ms, id: ${t.id}`),yield ve(p),n.end(),r.end(),this.executeWithRetry(t,a-1)}));throw e==null||e.warn(`SimpleQueue.executeWithRetry model returned should not retry, id: ${t.id}`),r.end(),o}finally{}}))}))})}processQueue(){return l(this,null,function*(){var r;let t=h.getLogger();if(this.activeTasks>=this.options.maxConcurrentTasks){t==null||t.debug("SimpleQueue.processQueue max concurrent tasks reached");return}let a=this.queue.shift();if(!a){t==null||t.debug("SimpleQueue.processQueue no item to process");return}let{task:e,taskSpan:d}=a;d&&d.end(),this.activeTasks+=1,t==null||t.debug(`SimpleQueue.processQueue active tasks: ${this.activeTasks}`),t==null||t.debug(`SimpleQueue.processQueue processing task, id: ${e.id}`);try{let o=yield this.executeWithRetry(e,this.options.retryCount);t==null||t.debug(`SimpleQueue.processQueue task completed, id: ${e.id}`),e.resolve(o);}catch(o){t==null||t.warn(`SimpleQueue.processQueue task errored, id: ${e.id}`),e.reject(o);}finally{this.activeTasks-=1,t==null||t.debug(`SimpleQueue.processQueue active tasks: ${this.activeTasks}`),(r=api.trace.getSpan(e.telemetryContext))==null||r.end(),this.processQueue();}})}};var X=class{constructor(t=1e3){this.cache=new lruCache.LRUCache({max:t,allowStale:!1,updateAgeOnGet:!1});let a=h.getLogger();a==null||a.debug(`LRUCache initialized with maxEntries: ${t}`);}get(t){return l(this,null,function*(){let a=h.getLogger();return a==null||a.debug(`LRUCache.get invoked, key: ${t}`),new Promise(e=>{let d=this.cache.get(t);a==null||a.debug("LRUCache.get completed, value: ",d),e(d);})})}set(t,a){return l(this,null,function*(){let e=h.getLogger();return e==null||e.debug(`LRUCache.set invoked, key: ${t}, value: `,a),new Promise(d=>{this.cache.set(t,a),e==null||e.debug("LRUCache.set completed"),d();})})}delete(t){return l(this,null,function*(){let a=h.getLogger();return a==null||a.debug(`LRUCache.delete invoked, key: ${t}`),new Promise(e=>{this.cache.delete(t),a==null||a.debug("LRUCache.delete completed"),e();})})}clear(){return l(this,null,function*(){let t=h.getLogger();return t==null||t.debug("LRUCache.clear invoked"),new Promise(a=>{this.cache.clear(),t==null||t.debug("LRUCache.clear completed"),a();})})}};var re=class{record(t,a,e){}stopRecorder(){}};var ke=()=>({node:{version:process.version,platform:Se__default.default.platform(),architecture:Se__default.default.arch()}}),Ge=()=>({browser:{version:navigator.userAgent,userAgent:navigator.userAgent}});var oe=class{constructor(){this.eventVersion="0.1";this.gatewayVersion="0.30.0";this.flushInterval=1e4;this.batchSize=1;this.maxAttempts=3;this.environment=q()?Ge():ke();this.analyticsEndpointUrl="https://j954t34pkh.execute-api.us-east-1.amazonaws.com/v0/analytics";this.events=[];}startFlushTimer(){q()?this.flushTimer=window.setInterval(()=>this.flushEvents(),this.flushInterval):this.flushTimer=setInterval(()=>this.flushEvents(),this.flushInterval);}stopFlushTimer(){q()?window.clearInterval(this.flushTimer):clearInterval(this.flushTimer);}record(t,a,e){let d={event:t,status:a,dimensions:e,timestamp:new Date().toISOString(),eventVersion:this.eventVersion,gatewayVersion:this.gatewayVersion,environment:this.environment};this.events.push({event:d,attempt:0}),this.events.length>=this.batchSize&&this.flushEvents();}flushEvents(){return l(this,null,function*(){if(this.events.length===0)return;let t=[...this.events];this.events=[],(yield this.sendEvents(t.map(e=>e.event)))||this.events.push(...t.filter(e=>e.attempt<this.maxAttempts).map(e=>({event:e.event,attempt:e.attempt+1})));})}sendEvents(t){return l(this,null,function*(){try{return (yield ie__default.default.post(this.analyticsEndpointUrl,{events:t},{headers:{"Content-Type":"application/json"}})).status===200}catch(a){return !1}})}stopRecorder(){this.stopFlushTimer(),this.flushEvents();}};var se=class{static getAnalyticsRecorder(t){return this.analytics!==void 0?this.analytics:(this.analytics=t?new oe:new re,this.analytics)}};var Ae=zod.z.object({queueOptions:zod.z.lazy(()=>xe.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(),logger:zod.z.custom().optional(),telemetry:zod.z.object({tracer:zod.z.custom().optional(),meter:zod.z.custom().optional()}).optional(),analyticsEnabled:zod.z.boolean().optional(),enableProxyAgent:zod.z.boolean().optional()}),Lt=zod.z.object({enableCache:zod.z.boolean().optional().default(!0),customHeaders:zod.z.record(zod.z.string()).optional(),metadataForCallbacks:zod.z.any().optional()}),J=zod.z.object({model:zod.z.custom(),config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional(),options:Lt.optional()}),Ot=zod.z.object({customHeaders:zod.z.record(zod.z.string()).optional(),metadataForCallbacks:zod.z.any().optional()}),Me=zod.z.object({model:zod.z.custom(),config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional(),options:Ot.optional(),abortSignal:zod.z.instanceof(AbortSignal).optional()}),Qt=zod.z.object({enableCache:zod.z.boolean().optional().default(!0),customHeaders:zod.z.record(zod.z.string()).optional(),metadataForCallbacks:zod.z.any().optional()}),me=zod.z.object({model:zod.z.custom(),config:types.Config(),embeddingRequests:types.EmbeddingRequests(),options:Qt.optional()}),pe=zod.z.object({model:zod.z.custom(),data:zod.z.any(),headers:zod.z.record(zod.z.string()),query:zod.z.record(zod.z.string()).optional()}),Le=zod.z.object({model:zod.z.custom(),data:zod.z.any(),headers:zod.z.record(zod.z.string()),query:zod.z.record(zod.z.string()).optional()}),le=zod.z.object({model:zod.z.custom(),data:zod.z.any(),headers:zod.z.record(zod.z.string()),query:zod.z.record(zod.z.string()).optional()});var $e=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(),customHeaders:zod.z.record(zod.z.string()).optional(),callbacks:zod.z.array(zod.z.custom()).nonempty().optional(),metadataForCallbacks:zod.z.any().optional()}),mr=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 ze(s,t,a){return l(this,null,function*(){let e=h.getLogger(),d=r=>l(this,null,function*(){e==null||e.debug("handleCompleteChat invoked"),e==null||e.debug("handleCompleteChat request: ",{request:s});let o=$e.parse(s),i=s.callbacks||[],p=api.context.active();try{L(i,"onChatStart",s.metadataForCallbacks);let n={config:o.config,messages:o.messages,tools:o.tools},m={url:yield o.model.getCompleteChatUrl(o.config,o.messages,o.tools),headers:yield o.model.getCompleteChatHeaders(o.config,o.messages,o.tools),data:yield o.model.getCompleteChatData(o.config,o.messages,o.tools)};q()||(m.headers=M(T({},m.headers),{source:"adaline.ai"})),o.customHeaders&&(m.headers=T(T({},m.headers),o.customHeaders)),e==null||e.debug("handleCompleteChat providerRequest: ",{providerRequest:m});let c=ae(`complete-chat:${m.url}:${o.model.modelSchema.name}`,n);if(o.enableCache){e==null||e.debug("handleCompleteChat checking cache");let y=yield s.cache.get(c);if(y)return y.cached=!0,e==null||e.debug("handleCompleteChat cached hit"),r==null||r.setAttribute("cached",!0),r==null||r.setStatus({code:api.SpanStatusCode.OK}),L(i,"onChatCached",s.metadataForCallbacks,y),e==null||e.debug("handleCompleteChat cached response: ",{cachedResponse:y}),y}e==null||e.debug("handleCompleteChat cache miss");let C=Date.now(),g=yield t.post(m.url,m.data,m.headers,p),F=Date.now()-C;e==null||e.debug("handleCompleteChat providerResponse: ",{providerResponse:g});let z={request:n,response:o.model.transformCompleteChatResponse(g.data),cached:!1,latencyInMs:F,metadataForCallbacks:s.metadataForCallbacks,provider:{request:m,response:g}};return e==null||e.debug("handleCompleteChat response: ",{response:z}),o.enableCache&&(yield s.cache.set(c,z),e==null||e.debug("handleCompleteChat response cached")),r==null||r.setAttribute("cached",!1),r==null||r.setStatus({code:api.SpanStatusCode.OK}),L(i,"onChatComplete",s.metadataForCallbacks,z),z}catch(n){e==null||e.warn("handleCompleteChat error: ",{error:n});let m;throw E.isHttpRequestError(n)||n instanceof w?m=n:m=I(n),L(i,"onChatError",s.metadataForCallbacks,m),m}finally{r==null||r.end();}});return a?yield api.context.with(a,()=>l(this,null,function*(){return yield f.getTracer().startActiveSpan("complete-chat.handler",o=>l(this,null,function*(){return yield d(o)}))})):yield d()})}var Ve=zod.z.object({cache:zod.z.custom(),model:zod.z.custom(),config:types.Config(),embeddingRequests:types.EmbeddingRequests(),enableCache:zod.z.boolean(),customHeaders:zod.z.record(zod.z.string()).optional(),callbacks:zod.z.array(zod.z.custom()).nonempty().optional(),metadataForCallbacks:zod.z.any().optional()}),Sr=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 _e(s,t,a){return l(this,null,function*(){let e=h.getLogger(),d=r=>l(this,null,function*(){e==null||e.debug("handleGetEmbeddings invoked"),e==null||e.debug("handleGetEmbeddings request: ",{request:s});let o=Ve.parse(s),i=s.callbacks||[],p=api.context.active();try{L(i,"onGetEmbeddingsStart",s.metadataForCallbacks);let n={config:o.config,embeddingRequests:o.embeddingRequests},m={url:yield o.model.getGetEmbeddingsUrl(o.config,o.embeddingRequests),headers:yield o.model.getGetEmbeddingsHeaders(o.config,o.embeddingRequests),data:yield o.model.getGetEmbeddingsData(o.config,o.embeddingRequests)};q()||(m.headers=M(T({},m.headers),{source:"adaline.ai"})),o.customHeaders&&(m.headers=T(T({},m.headers),o.customHeaders)),e==null||e.debug("handleGetEmbeddings providerRequest: ",{providerRequest:m});let c=ae(`get-embeddings:${m.url}:${o.model.modelSchema.name}`,n);if(o.enableCache){e==null||e.debug("handleGetEmbeddings checking cache");let y=yield s.cache.get(c);if(y)return y.cached=!0,e==null||e.debug("handleGetEmbeddings cached hit"),r==null||r.setAttribute("cached",!0),r==null||r.setStatus({code:api.SpanStatusCode.OK}),L(i,"onGetEmbeddingsCached",s.metadataForCallbacks,y),e==null||e.debug("handleGetEmbeddings cached response: ",{cachedResponse:y}),y}e==null||e.debug("handleGetEmbeddings cache miss");let C=Date.now(),g=yield t.post(m.url,m.data,m.headers,p),F=Date.now()-C;e==null||e.debug("handleGetEmbeddings providerResponse: ",{providerResponse:g});let z={request:n,response:o.model.transformGetEmbeddingsResponse(g.data),cached:!1,latencyInMs:F,metadataForCallbacks:s.metadataForCallbacks,provider:{request:m,response:g}};return e==null||e.debug("handleGetEmbeddings response: ",{response:z}),o.enableCache&&(yield s.cache.set(c,z),e==null||e.debug("handleGetEmbeddings response cached")),r==null||r.setAttribute("cached",!1),r==null||r.setStatus({code:api.SpanStatusCode.OK}),L(i,"onGetEmbeddingsComplete",s.metadataForCallbacks,z),z}catch(n){e==null||e.warn("handleGetEmbeddings error: ",{error:n});let m;throw E.isHttpRequestError(n)||n instanceof w?m=n:m=I(n),L(i,"onGetEmbeddingsError",s.metadataForCallbacks,m),m}finally{r==null||r.end();}});return a?yield api.context.with(a,()=>l(this,null,function*(){return yield f.getTracer().startActiveSpan("get-embeddings.handler",o=>l(this,null,function*(){return yield d(o)}))})):yield d()})}var Be=zod.z.object({model:zod.z.custom(),data:zod.z.any(),headers:zod.z.record(zod.z.string()),query:zod.z.record(zod.z.string()).optional()}),Vr=zod.z.object({request:zod.z.any(),providerRequest:zod.z.object({url:zod.z.string().url(),headers:zod.z.record(zod.z.string()),data:zod.z.any()}),providerResponse:zod.z.any(),transformedResponse:zod.z.optional(types.ChatResponse)});function Ye(s,t,a){return l(this,null,function*(){let e=h.getLogger(),d=r=>l(this,null,function*(){e==null||e.debug("handleProxyCompleteChat invoked"),e==null||e.debug("handleProxyCompleteChat request: ",{request:s});let o=Be.parse(s),i=api.context.active();try{o.headers=M(T({},o.headers),{source:"adaline.ai"});let p={url:yield o.model.getProxyCompleteChatUrl(o.data,o.headers,o.query),headers:yield o.model.getProxyCompleteChatHeaders(o.data,o.headers,o.query),data:o.data};e==null||e.debug("handleProxyCompleteChat providerRequest: ",{providerRequest:p});let n=yield t.post(p.url,p.data,p.headers,i);e==null||e.debug("handleProxyCompleteChat providerResponse: ",{providerResponse:n});let m;try{m=o.model.transformCompleteChatResponse(n.data);}catch(C){e==null||e.warn("handleProxyCompleteChat transformation error: ",{transformationError:C});}let c={request:{header:o.headers,data:o.data,query:o.query},providerRequest:p,providerResponse:n,transformedResponse:m};return e==null||e.debug("handleProxyCompleteChat response: ",{response:c}),r==null||r.setStatus({code:api.SpanStatusCode.OK}),c}catch(p){e==null||e.warn("handleProxyCompleteChat error: ",{error:p});let n;throw E.isHttpRequestError(p)||p instanceof w?n=p:n=I(p),n}finally{r==null||r.end();}});return a?yield api.context.with(a,()=>l(this,null,function*(){return yield f.getTracer().startActiveSpan("proxy-complete-chat.handler",o=>l(this,null,function*(){return yield d(o)}))})):yield d()})}var Je=zod.z.object({model:zod.z.custom(),data:zod.z.any(),headers:zod.z.record(zod.z.string()),query:zod.z.record(zod.z.string()).optional()}),oo=zod.z.object({request:zod.z.any(),providerRequest:zod.z.object({url:zod.z.string().url(),headers:zod.z.record(zod.z.string()),data:zod.z.any()}),providerResponse:zod.z.any(),transformedResponse:zod.z.optional(types.EmbeddingResponse)});function Ze(s,t,a){return l(this,null,function*(){let e=h.getLogger(),d=r=>l(this,null,function*(){e==null||e.debug("handleProxyGetEmbeddings invoked"),e==null||e.debug("handleProxyGetEmbeddings request: ",{request:s});let o=Je.parse(s),i=api.context.active();try{let p={url:yield o.model.getGetEmbeddingsUrl(),headers:o.headers,data:o.data};p.headers=M(T({},p.headers),{source:"adaline.ai"});let n=T({},p);delete n.headers.host,delete n.headers["content-length"],e==null||e.debug("handleProxyGetEmbeddings providerRequest: ",{providerRequest:p});let m=yield t.post(n.url,n.data,n.headers,i);e==null||e.debug("handleProxyGetEmbeddings providerResponse: ",{providerResponse:m});let c;try{c=o.model.transformGetEmbeddingsResponse(m.data);}catch(g){e==null||e.warn("handleProxyGetEmbeddings transformation error: ",{transformationError:g});}let C={request:p,providerRequest:n,providerResponse:m,transformedResponse:c};return e==null||e.debug("handleProxyGetEmbeddings response: ",{response:C}),r==null||r.setStatus({code:api.SpanStatusCode.OK}),C}catch(p){e==null||e.warn("handleProxyGetEmbeddings error: ",{error:p});let n;throw E.isHttpRequestError(p)||p instanceof w?n=p:n=I(p),n}finally{r==null||r.end();}});return a?yield api.context.with(a,()=>l(this,null,function*(){return yield f.getTracer().startActiveSpan("proxy-get-embeddings.handler",o=>l(this,null,function*(){return yield d(o)}))})):yield d()})}var et=zod.z.object({model:zod.z.custom(),data:zod.z.any(),headers:zod.z.record(zod.z.string()),query:zod.z.record(zod.z.string()).optional()}),go=zod.z.object({request:zod.z.any(),providerRequest:zod.z.object({url:zod.z.string().url(),headers:zod.z.record(zod.z.string()),data:zod.z.any()}),providerResponse:zod.z.any(),transformedResponse:zod.z.array(types.PartialChatResponse).optional()});function at(s,t,a){return O(this,null,function*(){let e=h.getLogger(),d=function(r){return O(this,null,function*(){e==null||e.debug("handleProxyStreamChat invoked"),e==null||e.debug("handleProxyStreamChat request: ",{request:s});let o=api.context.active(),i=et.parse(s);try{i.headers=M(T({},i.headers),{source:"adaline.ai"});let y={url:yield new b(i.model.getProxyStreamChatUrl(i.data,i.headers,i.query)),headers:yield new b(i.model.getProxyStreamChatHeaders(i.data,i.headers,i.query)),data:i.data};e==null||e.debug("handleProxyStreamChat providerRequest: ",{providerRequest:y});let v="";try{for(var C=U(t.stream(y.url,"post",y.data,y.headers,void 0,o)),g,F,z;g=!(F=yield new b(C.next())).done;g=!1){let R=F.value;let G=[];try{try{for(var p=U(i.model.transformProxyStreamChatResponseChunk(R,v,i.data,i.headers,i.query)),n,m,c;n=!(m=yield new b(p.next())).done;n=!1){let $=m.value;$.partialResponse.partialMessages.length>0?G.push($.partialResponse):v=$.buffer;}}catch(m){c=[m];}finally{try{n&&(m=p.return)&&(yield new b(m.call(p)));}finally{if(c)throw c[0]}}}catch($){e==null||e.warn("handleProxyStreamChat transformation error",{transformationError:$}),G=void 0;}let j={request:{header:i.headers,data:i.data,query:i.query},providerRequest:y,providerResponse:R,transformedResponse:G};e==null||e.debug("handleProxyStreamChat streamResponse: ",{streamResponse:j}),yield j;}}catch(F){z=[F];}finally{try{g&&(F=C.return)&&(yield new b(F.call(C)));}finally{if(z)throw z[0]}}r==null||r.setStatus({code:api.SpanStatusCode.OK});}catch(y){e==null||e.warn("handleProxyStreamChat error: ",{error:y});let v;throw E.isHttpRequestError(y)||y instanceof w?v=y:v=I(y),v}finally{r==null||r.end();}})};return a?yield*Q(yield new b(api.context.with(a,()=>l(this,null,function*(){return yield f.getTracer().startActiveSpan("proxy-stream-chat.handler",o=>l(this,null,function*(){return yield d(o)}))})))):yield*Q(d())})}var nt=zod.z.object({model:zod.z.custom(),config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional(),customHeaders:zod.z.record(zod.z.string()).optional(),callbacks:zod.z.array(zod.z.custom()).nonempty().optional(),metadataForCallbacks:zod.z.any().optional(),abortSignal:zod.z.instanceof(AbortSignal).optional()}),Mo=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 dt(s,t,a){return O(this,null,function*(){let e=h.getLogger(),d=function(r){return O(this,null,function*(){e==null||e.debug("handleStreamChat invoked"),e==null||e.debug("handleStreamChat request: ",{request:s});let o=nt.parse(s),i=s.callbacks||[],p=api.context.active(),n={config:o.config,messages:o.messages,tools:o.tools};try{L(i,"onStreamStart",s.metadataForCallbacks);let R={url:yield new b(o.model.getStreamChatUrl(o.config,o.messages,o.tools)),headers:yield new b(o.model.getStreamChatHeaders(o.config,o.messages,o.tools)),data:yield new b(o.model.getStreamChatData(o.config,o.messages,o.tools))};q()||(R.headers=M(T({},R.headers),{source:"adaline.ai"})),o.customHeaders&&(R.headers=T(T({},R.headers),o.customHeaders)),e==null||e.debug("handleStreamChat providerRequest: ",{providerRequest:R});let G="",j=!0;try{for(var F=U(t.stream(R.url,"post",R.data,R.headers,{abortSignal:s.abortSignal},p)),z,y,v;z=!(y=yield new b(F.next())).done;z=!1){let $=y.value;try{for(var m=U(o.model.transformStreamChatResponseChunk($,G)),c,C,g;c=!(C=yield new b(m.next())).done;c=!1){let D=C.value;if(D.partialResponse.partialMessages.length>0){let Y={request:n,response:D.partialResponse,metadataForCallbacks:s.metadataForCallbacks,provider:{request:R,response:$}};L(i,j?"onStreamFirstResponse":"onStreamNewResponse",s.metadataForCallbacks,Y),j&&(j=!1),e==null||e.debug("handleStreamChat streamResponse: ",{streamResponse:Y}),yield Y;}else G=D.buffer;}}catch(C){g=[C];}finally{try{c&&(C=m.return)&&(yield new b(C.call(m)));}finally{if(g)throw g[0]}}}}catch(y){v=[y];}finally{try{z&&(y=F.return)&&(yield new b(y.call(F)));}finally{if(v)throw v[0]}}r==null||r.setStatus({code:api.SpanStatusCode.OK}),L(i,"onStreamEnd",s.metadataForCallbacks);}catch(R){e==null||e.warn("handleStreamChat error: ",{error:R});let G;throw E.isHttpRequestError(R)||R instanceof w?G=R:G=I(R),L(i,"onStreamError",s.metadataForCallbacks,G),G}finally{r==null||r.end();}})};return a?yield*Q(yield new b(api.context.with(a,()=>l(this,null,function*(){return yield f.getTracer().startActiveSpan("stream-chat.handler",o=>l(this,null,function*(){return yield d(o)}))})))):yield*Q(d())})}var ue=class{constructor(t={}){var e,d,r,o,i,p,n;if(!t.dangerouslyAllowBrowser&&q())throw new w("It looks like you're running in a browser-like environment. This is disabled by default, as it risks exposing your provider secrets to attackers. If you understand the risks and have appropriate mitigation in place, you can set the `dangerouslyAllowBrowser` option to `true`.");this.options=Ae.parse(t),h.setLogger(t.logger),this.logger=t.logger,this.analytics=se.getAnalyticsRecorder(this.options.analyticsEnabled===void 0?!0:this.options.analyticsEnabled),f.setTracer((e=t.telemetry)==null?void 0:e.tracer),this.tracer=f.getTracer(),f.setMeter((d=t.telemetry)==null?void 0:d.meter),this.meter=f.getMeter();let a={maxConcurrentTasks:((r=this.options.queueOptions)==null?void 0:r.maxConcurrentTasks)||4,retryCount:((o=this.options.queueOptions)==null?void 0:o.retryCount)||3,retry:((i=this.options.queueOptions)==null?void 0:i.retry)||{initialDelay:1e3,exponentialFactor:2},timeout:((p=this.options.queueOptions)==null?void 0:p.timeout)||12e4};this.queues={completeChat:new B(a),getEmbeddings:new B(a),proxyCompleteChat:new B(a),proxyGetEmbeddings:new B(a)},this.options.enableProxyAgent===void 0||this.options.enableProxyAgent,this.httpClient=t.httpClient||new ee({timeoutInMilliseconds:a.timeout*.9,enableProxyAgent:this.options.enableProxyAgent}),this.caches={completeChat:t.completeChatCache||new X,getEmbeddings:t.getEmbeddingsCache||new X},(n=this.logger)==null||n.debug("gateway initialized");}completeChat(t){return l(this,null,function*(){var d,r;(d=this.logger)==null||d.info("gateway.completeChat invoked"),(r=this.logger)==null||r.debug("request: ",{request:t});let a=J.parse(t),e=a.model.modelSchema.name;return yield this.tracer.startActiveSpan("complete-chat",o=>l(this,null,function*(){return o.setAttribute("modelName",e),new Promise((i,p)=>{var m;let n={id:uuid.v4(),request:a,cache:this.caches.completeChat,resolve:c=>{this.analytics.record("completeChat","success",{modelName:e,usage:c.response.usage||{}}),i(c);},reject:c=>{console.log("completeChat error",c),this.analytics.record("completeChat","error",{modelName:e}),p(c);},execute:this.executeCompleteChat.bind(this),telemetryContext:api.context.active()};this.queues.completeChat.enqueue(n),(m=this.logger)==null||m.debug(`gateway.completeChat task enqueued, id: ${n.id}`);})}))})}executeCompleteChat(t,a){return l(this,null,function*(){var d,r,o,i;(d=this.logger)==null||d.debug("gateway.executeCompleteChat invoked");let e=J.parse(t);return ze({cache:this.caches.completeChat,model:e.model,config:e.config,messages:e.messages,tools:e.tools,enableCache:(o=(r=e.options)==null?void 0:r.enableCache)!=null?o:!0,callbacks:this.options.completeChatCallbacks,metadataForCallbacks:(i=e.options)==null?void 0:i.metadataForCallbacks},this.httpClient,a)})}streamChat(t){return O(this,null,function*(){var i,p,n,m;(i=this.logger)==null||i.info("gateway.streamChat invoked"),(p=this.logger)==null||p.debug("request: ",{request:t});let a=Me.parse(t),e=a.model.modelSchema.name,d="success",r=this.tracer.startSpan("stream-chat"),o=api.trace.setSpan(api.context.active(),r);try{return r.setAttribute("modelName",e),yield*Q(yield new b(api.context.with(o,()=>l(this,null,function*(){var c;return dt({model:a.model,config:a.config,messages:a.messages,tools:a.tools,callbacks:this.options.streamChatCallbacks,metadataForCallbacks:(c=a.options)==null?void 0:c.metadataForCallbacks,abortSignal:a.abortSignal},this.httpClient,o)}))))}catch(c){throw d="error",r.setStatus({code:api.SpanStatusCode.ERROR,message:"stream failed"}),(n=this.logger)==null||n.error("gateway.streamChat error: ",{error:c}),c instanceof w?c:new w(c==null?void 0:c.message,500,(m=c==null?void 0:c.response)==null?void 0:m.data)}finally{this.analytics.record("streamChat",d,{modelName:e}),r.end();}})}getEmbeddings(t){return l(this,null,function*(){var d,r;(d=this.logger)==null||d.info("gateway.getEmbeddings invoked"),(r=this.logger)==null||r.debug("request: ",{request:t});let a=me.parse(t),e=a.model.modelSchema.name;return yield this.tracer.startActiveSpan("get-embeddings",o=>l(this,null,function*(){return o.setAttribute("modelName",e),new Promise((i,p)=>{var m;let n={id:uuid.v4(),request:a,cache:this.caches.getEmbeddings,resolve:c=>{this.analytics.record("getEmbeddings","success",{modelName:e,usage:c.response.usage||{}}),i(c);},reject:c=>{this.analytics.record("getEmbeddings","error",{modelName:e}),p(c);},execute:this.executeGetEmbeddings.bind(this),telemetryContext:api.context.active()};this.queues.getEmbeddings.enqueue(n),(m=this.logger)==null||m.debug(`gateway.getEmbeddings task enqueued, id: ${n.id}`);})}))})}executeGetEmbeddings(t,a){return l(this,null,function*(){var d,r,o,i;(d=this.logger)==null||d.debug("gateway.executeGetEmbeddings invoked");let e=me.parse(t);return _e({cache:this.caches.getEmbeddings,model:e.model,config:e.config,embeddingRequests:e.embeddingRequests,enableCache:(o=(r=e.options)==null?void 0:r.enableCache)!=null?o:!0,callbacks:this.options.getEmbeddingsCallbacks,metadataForCallbacks:(i=e.options)==null?void 0:i.metadataForCallbacks},this.httpClient,a)})}proxyCompleteChat(t){return l(this,null,function*(){var d,r;(d=this.logger)==null||d.info("gateway.proxyCompleteChat invoked"),(r=this.logger)==null||r.debug("request: ",{request:t});let a=pe.parse(t),e=a.model.modelSchema.name;return yield this.tracer.startActiveSpan("proxy-complete-chat",o=>l(this,null,function*(){return o.setAttribute("modelName",e),new Promise((i,p)=>{var m;let n={id:uuid.v4(),request:a,resolve:c=>{var C;this.analytics.record("proxyCompleteChat","success",{modelName:e,usage:((C=c.transformedResponse)==null?void 0:C.usage)||{}}),i(c);},reject:c=>{console.log("proxyCompleteChat error",c),this.analytics.record("proxyCompleteChat","error",{modelName:e}),p(c);},execute:this.executeProxyCompleteChat.bind(this),telemetryContext:api.context.active()};this.queues.proxyCompleteChat.enqueue(n),(m=this.logger)==null||m.debug(`gateway.proxyCompleteChat task enqueued, id: ${n.id}`);})}))})}executeProxyCompleteChat(t,a){return l(this,null,function*(){var d;(d=this.logger)==null||d.debug("gateway.executeCompleteChat invoked");let e=pe.parse(t);return Ye({model:e.model,data:e.data,headers:e.headers,query:e.query},this.httpClient,a)})}proxyStreamChat(t){return O(this,null,function*(){var i,p,n,m;(i=this.logger)==null||i.info("gateway.proxyStreamChat invoked"),(p=this.logger)==null||p.debug("proxyStreamChat request: ",{request:t});let a=Le.parse(t),e=a.model.modelSchema.name,d="success",r=this.tracer.startSpan("proxy-stream-chat"),o=api.trace.setSpan(api.context.active(),r);try{return r.setAttribute("modelName",e),yield*Q(yield new b(api.context.with(o,()=>l(this,null,function*(){return at({model:a.model,data:a.data,headers:a.headers,query:a.query},this.httpClient,o)}))))}catch(c){throw d="error",r.setStatus({code:api.SpanStatusCode.ERROR,message:"proxy stream failed"}),(n=this.logger)==null||n.error("gateway.proxyStreamChat error: ",{error:c}),c instanceof w?c:new w(c==null?void 0:c.message,500,(m=c==null?void 0:c.response)==null?void 0:m.data)}finally{this.analytics.record("proxyStreamChat",d,{modelName:e}),r.end();}})}proxyGetEmbeddings(t){return l(this,null,function*(){var d,r;(d=this.logger)==null||d.info("gateway.proxyGetEmbeddings invoked"),(r=this.logger)==null||r.debug("request: ",{request:t});let a=le.parse(t),e=a.model.modelSchema.name;return yield this.tracer.startActiveSpan("proxy-get-embeddings",o=>l(this,null,function*(){return o.setAttribute("modelName",e),new Promise((i,p)=>{var m;let n={id:uuid.v4(),request:a,resolve:c=>{var C;this.analytics.record("proxyGetEmbeddings","success",{modelName:e,usage:((C=c.transformedResponse)==null?void 0:C.usage)||{}}),i(c);},reject:c=>{this.analytics.record("proxyGetEmbeddings","error",{modelName:e}),p(c);},execute:this.executeProxyGetEmbeddings.bind(this),telemetryContext:api.context.active()};this.queues.proxyGetEmbeddings.enqueue(n),(m=this.logger)==null||m.debug(`gateway.proxyGetEmbeddings task enqueued, id: ${n.id}`);})}))})}executeProxyGetEmbeddings(t,a){return l(this,null,function*(){var d;(d=this.logger)==null||d.debug("gateway.executeProxyGetEmbeddings invoked");let e=le.parse(t);return Ze({model:e.model,headers:e.headers,data:e.data,query:e.query},this.httpClient,a)})}};ue.GatewayError=w;
|
|
19
|
+
var pt=Object.defineProperty,lt=Object.defineProperties;var ut=Object.getOwnPropertyDescriptors;var ye=Object.getOwnPropertySymbols;var yt=Object.prototype.hasOwnProperty,ht=Object.prototype.propertyIsEnumerable;var W=(s,t)=>(t=Symbol[s])?t:Symbol.for("Symbol."+s),Ct=s=>{throw TypeError(s)};var he=(s,t,a)=>t in s?pt(s,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[t]=a,T=(s,t)=>{for(var a in t||(t={}))yt.call(t,a)&&he(s,a,t[a]);if(ye)for(var a of ye(t))ht.call(t,a)&&he(s,a,t[a]);return s},M=(s,t)=>lt(s,ut(t));var bt=(s=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(s,{get:(t,a)=>(typeof require!="undefined"?require:t)[a]}):s)(function(s){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var l=(s,t,a)=>new Promise((e,d)=>{var r=p=>{try{i(a.next(p));}catch(n){d(n);}},o=p=>{try{i(a.throw(p));}catch(n){d(n);}},i=p=>p.done?e(p.value):Promise.resolve(p.value).then(r,o);i((a=a.apply(s,t)).next());}),b=function(s,t){this[0]=s,this[1]=t;},O=(s,t,a)=>{var e=(o,i,p,n)=>{try{var m=a[o](i),c=(i=m.value)instanceof b,C=m.done;Promise.resolve(c?i[0]:i).then(g=>c?e(o==="return"?o:"next",i[1]?{done:g.done,value:g.value}:g,p,n):p({value:g,done:C})).catch(g=>e("throw",g,p,n));}catch(g){n(g);}},d=o=>r[o]=i=>new Promise((p,n)=>e(o,i,p,n)),r={};return a=a.apply(s,t),r[W("asyncIterator")]=()=>r,d("next"),d("throw"),d("return"),r},Q=s=>{var t=s[W("asyncIterator")],a=!1,e,d={};return t==null?(t=s[W("iterator")](),e=r=>d[r]=o=>t[r](o)):(t=t.call(s),e=r=>d[r]=o=>{if(a){if(a=!1,r==="throw")throw o;return o}return a=!0,{done:!1,value:new b(new Promise(i=>{var p=t[r](o);p instanceof Object||Ct("Object expected"),i(p);}),1)}}),d[W("iterator")]=()=>d,e("next"),"throw"in t?e("throw"):d.throw=r=>{throw r},"return"in t&&e("return"),d},U=(s,t,a)=>(t=s[W("asyncIterator")])?t.call(s):(s=s[W("iterator")](),t={},a=(e,d)=>(d=s[e])&&(t[e]=r=>new Promise((o,i,p)=>(r=d.call(s,r),p=r.done,Promise.resolve(r.value).then(n=>o({value:n,done:p}),i)))),a("next"),a("return"),t);var w=class s extends Error{constructor(t,a=500,e){super(t),this.name="GatewayError",this.status=a,this.data=e,Error.captureStackTrace&&Error.captureStackTrace(this,s);}},gt="GatewayTelemetryError",Ce=class s extends types.GatewayBaseError{constructor({info:t,cause:a}){super({info:t,cause:a},gt),this.info=t,this.cause=a,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayTelemetryError(t){return t instanceof s}};var Rt="HttpClientError",N=class s extends types.GatewayBaseError{constructor({info:t,cause:a}){super({info:t,cause:a},Rt),this.info=t,this.cause=a,Object.setPrototypeOf(this,new.target.prototype);}static isHttpClientError(t){return t instanceof s}},wt="HttpRequestError",E=class s extends types.GatewayBaseError{constructor(t,a=500,e,d){super({info:t,cause:{status:a,headers:e,data:d}},wt),this.info=t,this.cause={status:a,headers:e,data:d},Object.setPrototypeOf(this,new.target.prototype);}static isHttpRequestError(t){return t instanceof s}};var f=class{static setTracer(t){this.tracer||(this.tracer=t||api.trace.getTracer(this.DEFAULT_TRACER_KEY));}static getTracer(){return this.tracer||api.trace.getTracer(this.DEFAULT_TRACER_KEY)}static setMeter(t){this.meter||(this.meter=t||api.metrics.getMeter(this.DEFAULT_METER_KEY));}static getMeter(){return this.meter||api.metrics.getMeter(this.DEFAULT_METER_KEY)}};f.DEFAULT_TRACER_KEY="gateway",f.DEFAULT_METER_KEY="gateway",f.tracer=void 0,f.meter=void 0;var Z=s=>{let t={};return s&&(typeof s=="object"||s instanceof Headers)&&Object.entries(s).forEach(([a,e])=>{Array.isArray(e)?t[a]=e.join(", "):typeof e=="string"?t[a]=e:t[a]="";}),t},Ee=s=>{var r,o,i;let t=(s==null?void 0:s.message)||"An unexpected error occurred",a=((r=s==null?void 0:s.response)==null?void 0:r.status)||500,e=Z((o=s==null?void 0:s.response)==null?void 0:o.headers)||{},d=((i=s==null?void 0:s.response)==null?void 0:i.data)||{};return new E(t,a,e,d)},ee=class{constructor(t){this.isNodeEnvironment=()=>typeof process!="undefined"&&process.versions!=null&&process.versions.node!=null;let{axiosInstance:a,timeoutInMilliseconds:e,enableProxyAgent:d}=t;this.client=a||ie__default.default.create();let r=zod.z.number().int().positive().optional();if(this.defaultTimeout=r.parse(e),this.client.defaults.timeout=this.defaultTimeout,this.enableProxyAgent=d!=null?d:!0,this.enableProxyAgent){let i=bt("proxy-agent");this.httpProxyAgent=new i.ProxyAgent,this.httpsProxyAgent=new i.ProxyAgent({rejectUnauthorized:!1});}let o=h.getLogger();o==null||o.debug(`IsomorphicHttpClient initialized with defaultTimeout: ${this.defaultTimeout}`);}makeRequest(o,i,p){return l(this,arguments,function*(t,a,e,d={},r){let n=h.getLogger(),m=c=>l(this,null,function*(){try{let C=T(M(T(T({},t==="get"||t==="delete"?{params:e}:{data:e}),d),{timeout:this.defaultTimeout}),this.enableProxyAgent?{httpAgent:this.httpProxyAgent,httpsAgent:this.httpsProxyAgent}:{});if(t==="get"||t==="delete"){let g=yield this.client[t](a,C);c==null||c.setStatus({code:api.SpanStatusCode.OK,message:"request successful"});let F={data:g.data,headers:Z(g.headers),status:{code:g.status,text:g.statusText}};return n==null||n.debug("IsomorphicHttpClient.makeRequest response: ",F),F}else {let g=yield this.client[t](a,C.data,M(T({},C),{params:C.params}));c==null||c.setStatus({code:api.SpanStatusCode.OK,message:"request successful"});let F={data:g.data,headers:Z(g.headers),status:{code:g.status,text:g.statusText}};return n==null||n.debug("IsomorphicHttpClient.makeRequest response: ",F),F}}catch(C){throw n==null||n.warn("IsomorphicHttpClient.makeRequest error: ",C),c==null||c.setStatus({code:api.SpanStatusCode.ERROR,message:"request failed"}),ie__default.default.isAxiosError(C)?Ee(C):new N({info:"An unexpected error occurred",cause:C})}finally{c==null||c.end();}});return r?yield api.context.with(r,()=>l(this,null,function*(){return yield f.getTracer().startActiveSpan("http.request",C=>l(this,null,function*(){return C.setAttribute(semanticConventions.ATTR_HTTP_REQUEST_METHOD,t.toUpperCase()),C.setAttribute(semanticConventions.ATTR_URL_FULL,a),yield m(C)}))})):m()})}stream(t,a,e,d,r,o){return O(this,null,function*(){let i=h.getLogger();i==null||i.debug(`IsomorphicHttpClient.STREAM request to ${t}`,{data:e,headers:d});let p=function(n){return O(this,null,function*(){let m=Date.now(),c=!1;try{if(this.isNodeEnvironment()){i==null||i.debug("IsomorphicHttpClient.stream in node environment");let y=yield new b(this.client.request({method:a,url:t,headers:d,data:e,responseType:"stream",signal:r==null?void 0:r.abortSignal}));try{for(var C=U(y.data),g,F,z;g=!(F=yield new b(C.next())).done;g=!1){let v=F.value;if(!c){let G=Date.now()-m;n==null||n.setAttribute("time-to-first-token",G),c=!0;}n==null||n.addEvent("stream.chunk",{message:"stream chunk received"});let R=v.toString();i==null||i.debug("IsomorphicHttpClient.stream chunk: ",R),yield R;}}catch(F){z=[F];}finally{try{g&&(F=C.return)&&(yield new b(F.call(C)));}finally{if(z)throw z[0]}}n==null||n.setStatus({code:api.SpanStatusCode.OK,message:"stream successful"});}else {i==null||i.debug("IsomorphicHttpClient.stream in browser environment");let y={method:a,headers:new Headers(T({},d)),body:a!=="get"?JSON.stringify(e):void 0,signal:r==null?void 0:r.abortSignal},v=yield new b(fetch(t,y));if(!v.ok){i==null||i.warn("IsomorphicHttpClient.stream response not ok: ",v),n==null||n.setStatus({code:api.SpanStatusCode.ERROR,message:"stream failed"});let R=yield new b(v.json());throw new E(`Request failed with status ${v.status}`,v.status,Z(v.headers),R)}if(v.body){let R=v.body.getReader();for(;;){let{done:G,value:j}=yield new b(R.read());if(G){if(!c&&j){let Y=Date.now()-m;n==null||n.setAttribute("time-to-first-token",Y),c=!0;}n==null||n.addEvent("stream.chunk",{message:"stream chunk received"});let D=new TextDecoder().decode(j,{stream:!0});i==null||i.debug("IsomorphicHttpClient.stream chunk: ",D),yield D;break}if(!c){let D=Date.now()-m;n==null||n.setAttribute("time-to-first-token",D),c=!0;}n==null||n.addEvent("stream.chunk",{message:"stream chunk received"});let $=new TextDecoder().decode(j,{stream:!0});i==null||i.debug("IsomorphicHttpClient.stream chunk: ",$),yield $;}n==null||n.setStatus({code:api.SpanStatusCode.OK,message:"stream successful"});}else throw i==null||i.warn("IsomorphicHttpClient.stream response has no body"),n==null||n.setStatus({code:api.SpanStatusCode.ERROR,message:"stream failed"}),new E("Cannot stream the body of the response.",500,{},v)}}catch(y){throw i==null||i.warn("IsomorphicHttpClient.stream error: ",y),n==null||n.setStatus({code:api.SpanStatusCode.ERROR,message:"stream failed"}),E.isHttpRequestError(y)?y:(y==null?void 0:y.name)==="AbortError"?new E("AbortError",408,{},{}):(y==null?void 0:y.name)==="CanceledError"?new E("AbortError",408,{},{}):ie__default.default.isAxiosError(y)?Ee(y):new N({info:"An unexpected error occurred",cause:y})}finally{n==null||n.end();}})}.bind(this);return o?yield*Q(yield new b(api.context.with(o,()=>l(this,null,function*(){return yield f.getTracer().startActiveSpan("http.stream",m=>l(this,null,function*(){return m.setAttribute(semanticConventions.ATTR_HTTP_REQUEST_METHOD,a.toUpperCase()),m.setAttribute(semanticConventions.ATTR_URL_FULL,t),yield p(m)}))})))):yield*Q(p())})}get(t,a,e,d){return l(this,null,function*(){let r=h.getLogger();return r==null||r.debug(`IsomorphicHttpClient.GET request to ${t}`,{params:a,headers:e}),this.makeRequest("get",t,a||{},{headers:e},d)})}post(t,a,e,d){return l(this,null,function*(){let r=h.getLogger();return r==null||r.debug(`IsomorphicHttpClient.POST request to ${t}`,{data:a,headers:e}),this.makeRequest("post",t,a||{},{headers:e},d)})}put(t,a,e,d){return l(this,null,function*(){let r=h.getLogger();return r==null||r.debug(`IsomorphicHttpClient.PUT request to ${t}`,{data:a,headers:e}),this.makeRequest("put",t,a||{},{headers:e},d)})}delete(t,a,e,d){return l(this,null,function*(){let r=h.getLogger();return r==null||r.debug(`IsomorphicHttpClient.DELETE request to ${t}`,{params:a,headers:e}),this.makeRequest("delete",t,a||{},{headers:e},d)})}patch(t,a,e,d){return l(this,null,function*(){let r=h.getLogger();return r==null||r.debug(`IsomorphicHttpClient.PATCH request to ${t}`,{data:a,headers:e}),this.makeRequest("patch",t,a||{},{headers:e},d)})}};var xt="QueueTaskTimeoutError",te=class s extends types.GatewayBaseError{constructor({info:t,cause:a}){super({info:t,cause:a},xt),this.info=t,this.cause=a,Object.setPrototypeOf(this,new.target.prototype);}static isQueueTaskTimeoutError(t){return t instanceof s}};var xe=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 ae=(s,t)=>vt__default.default(s+JSON.stringify(t)).toString(),I=s=>s instanceof w?s:N.isHttpClientError(s)?new w(s.message):s instanceof Error?new w(s.message):new w(s),q=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined";var qt={error:"color: red",warn:"color: yellow",info:"color: green"},St=(s,t,...a)=>{if(q())q()&&console.log(`%c[${s.toUpperCase()}] [${t}]`,qt[s],...a);else switch(s){case"error":console.error(...a);break;case"warn":console.warn(...a);break;default:console.log(...a);}},kt=(s,t,...a)=>{var e;q()||((e=process==null?void 0:process.env)==null?void 0:e.DEBUG)==="true"&&St(s,t,...a);},L=(s,t,...a)=>l(void 0,null,function*(){let e=[];s.forEach(d=>{let r=d[t];if(typeof r=="function")try{let o=r(...a);o instanceof Promise&&e.push(o);}catch(o){kt("error",`SAFELY_INVOKE_CALLBACKS:${String(t)}:`,o);}}),yield Promise.allSettled(e);}),ve=s=>new Promise(t=>setTimeout(t,s));var h=class{static setLogger(t){this.logger=t;}static getLogger(){return this.logger}};var qe=class{debug(t,...a){console.debug(t,...a);}info(t,...a){console.info(t,...a);}warn(t,...a){q()?console.warn(`%WARN: %c${t}`,"color: yellow; font-weight: bold;","",...a):console.warn(`\x1B[33mWARN:\x1B[0m ${t}`,...a);}error(t,...a){q()?console.error(`%ERROR: %c${t}`,"color: lightcoral; font-weight: bold;","",...a):console.error(`\x1B[91mERROR:\x1B[0m ${t}`,...a);}critical(t,...a){q()?console.error(`%cCRITICAL: %c${t}`,"color: red; font-weight: bold;","",...a):console.error(`\x1B[31;1mCRITICAL:\x1B[0m ${t}`,...a);}};var B=class{constructor(t){this.activeTasks=0;this.queue=[];this.options=t;}enqueue(t){let a=h.getLogger();a==null||a.debug(`SimpleQueue.enqueue invoked, id: ${t.id}`),api.context.with(t.telemetryContext,()=>l(this,null,function*(){return f.getTracer().startActiveSpan("queue.task.pickup-wait",d=>l(this,null,function*(){d.setAttribute("id",t.id),this.queue.push({task:t,taskSpan:d}),a==null||a.debug(`SimpleQueue.enqueue task enqueued, id: ${t.id}`);}))})),this.processQueue();}executeWithTimeout(t,a){let e=h.getLogger();return e==null||e.debug(`SimpleQueue.executeWithTimeout invoked with timeout: ${this.options.timeout}, id: ${t.id}`),new Promise((d,r)=>{let o=setTimeout(()=>{e==null||e.warn(`SimpleQueue.executeWithTimeout timed out, id: ${t.id}`),r(new te({info:"Queue task timeout",cause:new Error("Queue task timeout")}));},this.options.timeout);e==null||e.debug(`SimpleQueue.executeWithTimeout task executing, id: ${t.id}`),t.execute(t.request,a).then(i=>{e==null||e.debug(`SimpleQueue.executeWithTimeout task completed, id: ${t.id}`),clearTimeout(o),d(i);}).catch(i=>{e==null||e.warn(`SimpleQueue.executeWithTimeout task errored, id: ${t.id}`),clearTimeout(o),r(i);});})}executeWithRetry(t,a){return l(this,null,function*(){let e=h.getLogger();return yield api.context.with(t.telemetryContext,()=>l(this,null,function*(){let d=f.getTracer();return yield d.startActiveSpan("queue.task.execute",r=>l(this,null,function*(){e==null||e.debug(`SimpleQueue.executeWithRetry invoked, attempt: ${this.options.retryCount-a}, id: ${t.id}`),r.setAttribute("attempt",this.options.retryCount-a);try{let o=api.context.active(),i=yield this.executeWithTimeout(t,o);return r.setStatus({code:api.SpanStatusCode.OK}),r.end(),i}catch(o){if(a===0)throw e==null||e.warn(`SimpleQueue.executeWithRetry retry count reached, id: ${t.id}`),r.end(),o;let i=!0,p=this.options.retry.initialDelay*Math.pow(this.options.retry.exponentialFactor,this.options.retryCount-a);if(E.isHttpRequestError(o)){if(o.cause.status===429){e==null||e.warn(`SimpleQueue.executeWithRetry rate limiting error, id: ${t.id}`);let n=J.safeParse(t.request);if(n.success){let m=n.data.model.getRetryDelay(o.cause.headers);i=m.shouldRetry,m.delayMs>0&&(p=m.delayMs);}}o.cause.status>=500&&o.cause.status<600&&(e==null||e.warn(`SimpleQueue.executeWithRetry ${o.cause.status} error, id: ${t.id}`));}else e==null||e.warn(`SimpleQueue.executeWithRetry non http-request error, id: ${t.id}`,{error:o});if(i)return yield d.startActiveSpan("queue.task.retry-wait",n=>l(this,null,function*(){return e==null||e.debug(`SimpleQueue.executeWithRetry retry wait: ${p}ms, id: ${t.id}`),yield ve(p),n.end(),r.end(),this.executeWithRetry(t,a-1)}));throw e==null||e.warn(`SimpleQueue.executeWithRetry model returned should not retry, id: ${t.id}`),r.end(),o}finally{}}))}))})}processQueue(){return l(this,null,function*(){var r;let t=h.getLogger();if(this.activeTasks>=this.options.maxConcurrentTasks){t==null||t.debug("SimpleQueue.processQueue max concurrent tasks reached");return}let a=this.queue.shift();if(!a){t==null||t.debug("SimpleQueue.processQueue no item to process");return}let{task:e,taskSpan:d}=a;d&&d.end(),this.activeTasks+=1,t==null||t.debug(`SimpleQueue.processQueue active tasks: ${this.activeTasks}`),t==null||t.debug(`SimpleQueue.processQueue processing task, id: ${e.id}`);try{let o=yield this.executeWithRetry(e,this.options.retryCount);t==null||t.debug(`SimpleQueue.processQueue task completed, id: ${e.id}`),e.resolve(o);}catch(o){t==null||t.warn(`SimpleQueue.processQueue task errored, id: ${e.id}`),e.reject(o);}finally{this.activeTasks-=1,t==null||t.debug(`SimpleQueue.processQueue active tasks: ${this.activeTasks}`),(r=api.trace.getSpan(e.telemetryContext))==null||r.end(),this.processQueue();}})}};var X=class{constructor(t=1e3){this.cache=new lruCache.LRUCache({max:t,allowStale:!1,updateAgeOnGet:!1});let a=h.getLogger();a==null||a.debug(`LRUCache initialized with maxEntries: ${t}`);}get(t){return l(this,null,function*(){let a=h.getLogger();return a==null||a.debug(`LRUCache.get invoked, key: ${t}`),new Promise(e=>{let d=this.cache.get(t);a==null||a.debug("LRUCache.get completed, value: ",d),e(d);})})}set(t,a){return l(this,null,function*(){let e=h.getLogger();return e==null||e.debug(`LRUCache.set invoked, key: ${t}, value: `,a),new Promise(d=>{this.cache.set(t,a),e==null||e.debug("LRUCache.set completed"),d();})})}delete(t){return l(this,null,function*(){let a=h.getLogger();return a==null||a.debug(`LRUCache.delete invoked, key: ${t}`),new Promise(e=>{this.cache.delete(t),a==null||a.debug("LRUCache.delete completed"),e();})})}clear(){return l(this,null,function*(){let t=h.getLogger();return t==null||t.debug("LRUCache.clear invoked"),new Promise(a=>{this.cache.clear(),t==null||t.debug("LRUCache.clear completed"),a();})})}};var re=class{record(t,a,e){}stopRecorder(){}};var ke=()=>({node:{version:process.version,platform:Se__default.default.platform(),architecture:Se__default.default.arch()}}),Ge=()=>({browser:{version:navigator.userAgent,userAgent:navigator.userAgent}});var oe=class{constructor(){this.eventVersion="0.1";this.gatewayVersion="0.31.0";this.flushInterval=1e4;this.batchSize=1;this.maxAttempts=3;this.environment=q()?Ge():ke();this.analyticsEndpointUrl="https://j954t34pkh.execute-api.us-east-1.amazonaws.com/v0/analytics";this.events=[];}startFlushTimer(){q()?this.flushTimer=window.setInterval(()=>this.flushEvents(),this.flushInterval):this.flushTimer=setInterval(()=>this.flushEvents(),this.flushInterval);}stopFlushTimer(){q()?window.clearInterval(this.flushTimer):clearInterval(this.flushTimer);}record(t,a,e){let d={event:t,status:a,dimensions:e,timestamp:new Date().toISOString(),eventVersion:this.eventVersion,gatewayVersion:this.gatewayVersion,environment:this.environment};this.events.push({event:d,attempt:0}),this.events.length>=this.batchSize&&this.flushEvents();}flushEvents(){return l(this,null,function*(){if(this.events.length===0)return;let t=[...this.events];this.events=[],(yield this.sendEvents(t.map(e=>e.event)))||this.events.push(...t.filter(e=>e.attempt<this.maxAttempts).map(e=>({event:e.event,attempt:e.attempt+1})));})}sendEvents(t){return l(this,null,function*(){try{return (yield ie__default.default.post(this.analyticsEndpointUrl,{events:t},{headers:{"Content-Type":"application/json"}})).status===200}catch(a){return !1}})}stopRecorder(){this.stopFlushTimer(),this.flushEvents();}};var se=class{static getAnalyticsRecorder(t){return this.analytics!==void 0?this.analytics:(this.analytics=t?new oe:new re,this.analytics)}};var Ae=zod.z.object({queueOptions:zod.z.lazy(()=>xe.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(),logger:zod.z.custom().optional(),telemetry:zod.z.object({tracer:zod.z.custom().optional(),meter:zod.z.custom().optional()}).optional(),analyticsEnabled:zod.z.boolean().optional(),enableProxyAgent:zod.z.boolean().optional()}),Lt=zod.z.object({enableCache:zod.z.boolean().optional().default(!0),customHeaders:zod.z.record(zod.z.string()).optional(),metadataForCallbacks:zod.z.any().optional()}),J=zod.z.object({model:zod.z.custom(),config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional(),options:Lt.optional()}),Ot=zod.z.object({customHeaders:zod.z.record(zod.z.string()).optional(),metadataForCallbacks:zod.z.any().optional()}),Me=zod.z.object({model:zod.z.custom(),config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional(),options:Ot.optional(),abortSignal:zod.z.instanceof(AbortSignal).optional()}),Qt=zod.z.object({enableCache:zod.z.boolean().optional().default(!0),customHeaders:zod.z.record(zod.z.string()).optional(),metadataForCallbacks:zod.z.any().optional()}),me=zod.z.object({model:zod.z.custom(),config:types.Config(),embeddingRequests:types.EmbeddingRequests(),options:Qt.optional()}),pe=zod.z.object({model:zod.z.custom(),data:zod.z.any(),headers:zod.z.record(zod.z.string()),query:zod.z.record(zod.z.string()).optional()}),Le=zod.z.object({model:zod.z.custom(),data:zod.z.any(),headers:zod.z.record(zod.z.string()),query:zod.z.record(zod.z.string()).optional()}),le=zod.z.object({model:zod.z.custom(),data:zod.z.any(),headers:zod.z.record(zod.z.string()),query:zod.z.record(zod.z.string()).optional()});var $e=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(),customHeaders:zod.z.record(zod.z.string()).optional(),callbacks:zod.z.array(zod.z.custom()).nonempty().optional(),metadataForCallbacks:zod.z.any().optional()}),mr=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 ze(s,t,a){return l(this,null,function*(){let e=h.getLogger(),d=r=>l(this,null,function*(){e==null||e.debug("handleCompleteChat invoked"),e==null||e.debug("handleCompleteChat request: ",{request:s});let o=$e.parse(s),i=s.callbacks||[],p=api.context.active();try{L(i,"onChatStart",s.metadataForCallbacks);let n={config:o.config,messages:o.messages,tools:o.tools},m={url:yield o.model.getCompleteChatUrl(o.config,o.messages,o.tools),headers:yield o.model.getCompleteChatHeaders(o.config,o.messages,o.tools),data:yield o.model.getCompleteChatData(o.config,o.messages,o.tools)};q()||(m.headers=M(T({},m.headers),{source:"adaline.ai"})),o.customHeaders&&(m.headers=T(T({},m.headers),o.customHeaders)),e==null||e.debug("handleCompleteChat providerRequest: ",{providerRequest:m});let c=ae(`complete-chat:${m.url}:${o.model.modelSchema.name}`,n);if(o.enableCache){e==null||e.debug("handleCompleteChat checking cache");let y=yield s.cache.get(c);if(y)return y.cached=!0,e==null||e.debug("handleCompleteChat cached hit"),r==null||r.setAttribute("cached",!0),r==null||r.setStatus({code:api.SpanStatusCode.OK}),L(i,"onChatCached",s.metadataForCallbacks,y),e==null||e.debug("handleCompleteChat cached response: ",{cachedResponse:y}),y}e==null||e.debug("handleCompleteChat cache miss");let C=Date.now(),g=yield t.post(m.url,m.data,m.headers,p),F=Date.now()-C;e==null||e.debug("handleCompleteChat providerResponse: ",{providerResponse:g});let z={request:n,response:o.model.transformCompleteChatResponse(g.data),cached:!1,latencyInMs:F,metadataForCallbacks:s.metadataForCallbacks,provider:{request:m,response:g}};return e==null||e.debug("handleCompleteChat response: ",{response:z}),o.enableCache&&(yield s.cache.set(c,z),e==null||e.debug("handleCompleteChat response cached")),r==null||r.setAttribute("cached",!1),r==null||r.setStatus({code:api.SpanStatusCode.OK}),L(i,"onChatComplete",s.metadataForCallbacks,z),z}catch(n){e==null||e.warn("handleCompleteChat error: ",{error:n});let m;throw E.isHttpRequestError(n)||n instanceof w?m=n:m=I(n),L(i,"onChatError",s.metadataForCallbacks,m),m}finally{r==null||r.end();}});return a?yield api.context.with(a,()=>l(this,null,function*(){return yield f.getTracer().startActiveSpan("complete-chat.handler",o=>l(this,null,function*(){return yield d(o)}))})):yield d()})}var Ve=zod.z.object({cache:zod.z.custom(),model:zod.z.custom(),config:types.Config(),embeddingRequests:types.EmbeddingRequests(),enableCache:zod.z.boolean(),customHeaders:zod.z.record(zod.z.string()).optional(),callbacks:zod.z.array(zod.z.custom()).nonempty().optional(),metadataForCallbacks:zod.z.any().optional()}),Sr=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 _e(s,t,a){return l(this,null,function*(){let e=h.getLogger(),d=r=>l(this,null,function*(){e==null||e.debug("handleGetEmbeddings invoked"),e==null||e.debug("handleGetEmbeddings request: ",{request:s});let o=Ve.parse(s),i=s.callbacks||[],p=api.context.active();try{L(i,"onGetEmbeddingsStart",s.metadataForCallbacks);let n={config:o.config,embeddingRequests:o.embeddingRequests},m={url:yield o.model.getGetEmbeddingsUrl(o.config,o.embeddingRequests),headers:yield o.model.getGetEmbeddingsHeaders(o.config,o.embeddingRequests),data:yield o.model.getGetEmbeddingsData(o.config,o.embeddingRequests)};q()||(m.headers=M(T({},m.headers),{source:"adaline.ai"})),o.customHeaders&&(m.headers=T(T({},m.headers),o.customHeaders)),e==null||e.debug("handleGetEmbeddings providerRequest: ",{providerRequest:m});let c=ae(`get-embeddings:${m.url}:${o.model.modelSchema.name}`,n);if(o.enableCache){e==null||e.debug("handleGetEmbeddings checking cache");let y=yield s.cache.get(c);if(y)return y.cached=!0,e==null||e.debug("handleGetEmbeddings cached hit"),r==null||r.setAttribute("cached",!0),r==null||r.setStatus({code:api.SpanStatusCode.OK}),L(i,"onGetEmbeddingsCached",s.metadataForCallbacks,y),e==null||e.debug("handleGetEmbeddings cached response: ",{cachedResponse:y}),y}e==null||e.debug("handleGetEmbeddings cache miss");let C=Date.now(),g=yield t.post(m.url,m.data,m.headers,p),F=Date.now()-C;e==null||e.debug("handleGetEmbeddings providerResponse: ",{providerResponse:g});let z={request:n,response:o.model.transformGetEmbeddingsResponse(g.data),cached:!1,latencyInMs:F,metadataForCallbacks:s.metadataForCallbacks,provider:{request:m,response:g}};return e==null||e.debug("handleGetEmbeddings response: ",{response:z}),o.enableCache&&(yield s.cache.set(c,z),e==null||e.debug("handleGetEmbeddings response cached")),r==null||r.setAttribute("cached",!1),r==null||r.setStatus({code:api.SpanStatusCode.OK}),L(i,"onGetEmbeddingsComplete",s.metadataForCallbacks,z),z}catch(n){e==null||e.warn("handleGetEmbeddings error: ",{error:n});let m;throw E.isHttpRequestError(n)||n instanceof w?m=n:m=I(n),L(i,"onGetEmbeddingsError",s.metadataForCallbacks,m),m}finally{r==null||r.end();}});return a?yield api.context.with(a,()=>l(this,null,function*(){return yield f.getTracer().startActiveSpan("get-embeddings.handler",o=>l(this,null,function*(){return yield d(o)}))})):yield d()})}var Be=zod.z.object({model:zod.z.custom(),data:zod.z.any(),headers:zod.z.record(zod.z.string()),query:zod.z.record(zod.z.string()).optional()}),Vr=zod.z.object({request:zod.z.any(),providerRequest:zod.z.object({url:zod.z.string().url(),headers:zod.z.record(zod.z.string()),data:zod.z.any()}),providerResponse:zod.z.any(),transformedResponse:zod.z.optional(types.ChatResponse)});function Ye(s,t,a){return l(this,null,function*(){let e=h.getLogger(),d=r=>l(this,null,function*(){e==null||e.debug("handleProxyCompleteChat invoked"),e==null||e.debug("handleProxyCompleteChat request: ",{request:s});let o=Be.parse(s),i=api.context.active();try{o.headers=M(T({},o.headers),{source:"adaline.ai"});let p={url:yield o.model.getProxyCompleteChatUrl(o.data,o.headers,o.query),headers:yield o.model.getProxyCompleteChatHeaders(o.data,o.headers,o.query),data:o.data};e==null||e.debug("handleProxyCompleteChat providerRequest: ",{providerRequest:p});let n=yield t.post(p.url,p.data,p.headers,i);e==null||e.debug("handleProxyCompleteChat providerResponse: ",{providerResponse:n});let m;try{m=o.model.transformCompleteChatResponse(n.data);}catch(C){e==null||e.warn("handleProxyCompleteChat transformation error: ",{transformationError:C});}let c={request:{header:o.headers,data:o.data,query:o.query},providerRequest:p,providerResponse:n,transformedResponse:m};return e==null||e.debug("handleProxyCompleteChat response: ",{response:c}),r==null||r.setStatus({code:api.SpanStatusCode.OK}),c}catch(p){e==null||e.warn("handleProxyCompleteChat error: ",{error:p});let n;throw E.isHttpRequestError(p)||p instanceof w?n=p:n=I(p),n}finally{r==null||r.end();}});return a?yield api.context.with(a,()=>l(this,null,function*(){return yield f.getTracer().startActiveSpan("proxy-complete-chat.handler",o=>l(this,null,function*(){return yield d(o)}))})):yield d()})}var Je=zod.z.object({model:zod.z.custom(),data:zod.z.any(),headers:zod.z.record(zod.z.string()),query:zod.z.record(zod.z.string()).optional()}),oo=zod.z.object({request:zod.z.any(),providerRequest:zod.z.object({url:zod.z.string().url(),headers:zod.z.record(zod.z.string()),data:zod.z.any()}),providerResponse:zod.z.any(),transformedResponse:zod.z.optional(types.EmbeddingResponse)});function Ze(s,t,a){return l(this,null,function*(){let e=h.getLogger(),d=r=>l(this,null,function*(){e==null||e.debug("handleProxyGetEmbeddings invoked"),e==null||e.debug("handleProxyGetEmbeddings request: ",{request:s});let o=Je.parse(s),i=api.context.active();try{let p={url:yield o.model.getGetEmbeddingsUrl(),headers:o.headers,data:o.data};p.headers=M(T({},p.headers),{source:"adaline.ai"});let n=T({},p);delete n.headers.host,delete n.headers["content-length"],e==null||e.debug("handleProxyGetEmbeddings providerRequest: ",{providerRequest:p});let m=yield t.post(n.url,n.data,n.headers,i);e==null||e.debug("handleProxyGetEmbeddings providerResponse: ",{providerResponse:m});let c;try{c=o.model.transformGetEmbeddingsResponse(m.data);}catch(g){e==null||e.warn("handleProxyGetEmbeddings transformation error: ",{transformationError:g});}let C={request:p,providerRequest:n,providerResponse:m,transformedResponse:c};return e==null||e.debug("handleProxyGetEmbeddings response: ",{response:C}),r==null||r.setStatus({code:api.SpanStatusCode.OK}),C}catch(p){e==null||e.warn("handleProxyGetEmbeddings error: ",{error:p});let n;throw E.isHttpRequestError(p)||p instanceof w?n=p:n=I(p),n}finally{r==null||r.end();}});return a?yield api.context.with(a,()=>l(this,null,function*(){return yield f.getTracer().startActiveSpan("proxy-get-embeddings.handler",o=>l(this,null,function*(){return yield d(o)}))})):yield d()})}var et=zod.z.object({model:zod.z.custom(),data:zod.z.any(),headers:zod.z.record(zod.z.string()),query:zod.z.record(zod.z.string()).optional()}),go=zod.z.object({request:zod.z.any(),providerRequest:zod.z.object({url:zod.z.string().url(),headers:zod.z.record(zod.z.string()),data:zod.z.any()}),providerResponse:zod.z.any(),transformedResponse:zod.z.array(types.PartialChatResponse).optional()});function at(s,t,a){return O(this,null,function*(){let e=h.getLogger(),d=function(r){return O(this,null,function*(){e==null||e.debug("handleProxyStreamChat invoked"),e==null||e.debug("handleProxyStreamChat request: ",{request:s});let o=api.context.active(),i=et.parse(s);try{i.headers=M(T({},i.headers),{source:"adaline.ai"});let y={url:yield new b(i.model.getProxyStreamChatUrl(i.data,i.headers,i.query)),headers:yield new b(i.model.getProxyStreamChatHeaders(i.data,i.headers,i.query)),data:i.data};e==null||e.debug("handleProxyStreamChat providerRequest: ",{providerRequest:y});let v="";try{for(var C=U(t.stream(y.url,"post",y.data,y.headers,void 0,o)),g,F,z;g=!(F=yield new b(C.next())).done;g=!1){let R=F.value;let G=[];try{try{for(var p=U(i.model.transformProxyStreamChatResponseChunk(R,v,i.data,i.headers,i.query)),n,m,c;n=!(m=yield new b(p.next())).done;n=!1){let $=m.value;$.partialResponse.partialMessages.length>0?G.push($.partialResponse):v=$.buffer;}}catch(m){c=[m];}finally{try{n&&(m=p.return)&&(yield new b(m.call(p)));}finally{if(c)throw c[0]}}}catch($){e==null||e.warn("handleProxyStreamChat transformation error",{transformationError:$}),G=void 0;}let j={request:{header:i.headers,data:i.data,query:i.query},providerRequest:y,providerResponse:R,transformedResponse:G};e==null||e.debug("handleProxyStreamChat streamResponse: ",{streamResponse:j}),yield j;}}catch(F){z=[F];}finally{try{g&&(F=C.return)&&(yield new b(F.call(C)));}finally{if(z)throw z[0]}}r==null||r.setStatus({code:api.SpanStatusCode.OK});}catch(y){e==null||e.warn("handleProxyStreamChat error: ",{error:y});let v;throw E.isHttpRequestError(y)||y instanceof w?v=y:v=I(y),v}finally{r==null||r.end();}})};return a?yield*Q(yield new b(api.context.with(a,()=>l(this,null,function*(){return yield f.getTracer().startActiveSpan("proxy-stream-chat.handler",o=>l(this,null,function*(){return yield d(o)}))})))):yield*Q(d())})}var nt=zod.z.object({model:zod.z.custom(),config:types.Config(),messages:zod.z.array(types.Message()),tools:zod.z.array(types.Tool()).optional(),customHeaders:zod.z.record(zod.z.string()).optional(),callbacks:zod.z.array(zod.z.custom()).nonempty().optional(),metadataForCallbacks:zod.z.any().optional(),abortSignal:zod.z.instanceof(AbortSignal).optional()}),Mo=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 dt(s,t,a){return O(this,null,function*(){let e=h.getLogger(),d=function(r){return O(this,null,function*(){e==null||e.debug("handleStreamChat invoked"),e==null||e.debug("handleStreamChat request: ",{request:s});let o=nt.parse(s),i=s.callbacks||[],p=api.context.active(),n={config:o.config,messages:o.messages,tools:o.tools};try{L(i,"onStreamStart",s.metadataForCallbacks);let R={url:yield new b(o.model.getStreamChatUrl(o.config,o.messages,o.tools)),headers:yield new b(o.model.getStreamChatHeaders(o.config,o.messages,o.tools)),data:yield new b(o.model.getStreamChatData(o.config,o.messages,o.tools))};q()||(R.headers=M(T({},R.headers),{source:"adaline.ai"})),o.customHeaders&&(R.headers=T(T({},R.headers),o.customHeaders)),e==null||e.debug("handleStreamChat providerRequest: ",{providerRequest:R});let G="",j=!0;try{for(var F=U(t.stream(R.url,"post",R.data,R.headers,{abortSignal:s.abortSignal},p)),z,y,v;z=!(y=yield new b(F.next())).done;z=!1){let $=y.value;try{for(var m=U(o.model.transformStreamChatResponseChunk($,G)),c,C,g;c=!(C=yield new b(m.next())).done;c=!1){let D=C.value;if(D.partialResponse.partialMessages.length>0){let Y={request:n,response:D.partialResponse,metadataForCallbacks:s.metadataForCallbacks,provider:{request:R,response:$}};L(i,j?"onStreamFirstResponse":"onStreamNewResponse",s.metadataForCallbacks,Y),j&&(j=!1),e==null||e.debug("handleStreamChat streamResponse: ",{streamResponse:Y}),yield Y;}else G=D.buffer;}}catch(C){g=[C];}finally{try{c&&(C=m.return)&&(yield new b(C.call(m)));}finally{if(g)throw g[0]}}}}catch(y){v=[y];}finally{try{z&&(y=F.return)&&(yield new b(y.call(F)));}finally{if(v)throw v[0]}}r==null||r.setStatus({code:api.SpanStatusCode.OK}),L(i,"onStreamEnd",s.metadataForCallbacks);}catch(R){e==null||e.warn("handleStreamChat error: ",{error:R});let G;throw E.isHttpRequestError(R)||R instanceof w?G=R:G=I(R),L(i,"onStreamError",s.metadataForCallbacks,G),G}finally{r==null||r.end();}})};return a?yield*Q(yield new b(api.context.with(a,()=>l(this,null,function*(){return yield f.getTracer().startActiveSpan("stream-chat.handler",o=>l(this,null,function*(){return yield d(o)}))})))):yield*Q(d())})}var ue=class{constructor(t={}){var e,d,r,o,i,p,n;if(!t.dangerouslyAllowBrowser&&q())throw new w("It looks like you're running in a browser-like environment. This is disabled by default, as it risks exposing your provider secrets to attackers. If you understand the risks and have appropriate mitigation in place, you can set the `dangerouslyAllowBrowser` option to `true`.");this.options=Ae.parse(t),h.setLogger(t.logger),this.logger=t.logger,this.analytics=se.getAnalyticsRecorder(this.options.analyticsEnabled===void 0?!0:this.options.analyticsEnabled),f.setTracer((e=t.telemetry)==null?void 0:e.tracer),this.tracer=f.getTracer(),f.setMeter((d=t.telemetry)==null?void 0:d.meter),this.meter=f.getMeter();let a={maxConcurrentTasks:((r=this.options.queueOptions)==null?void 0:r.maxConcurrentTasks)||4,retryCount:((o=this.options.queueOptions)==null?void 0:o.retryCount)||3,retry:((i=this.options.queueOptions)==null?void 0:i.retry)||{initialDelay:1e3,exponentialFactor:2},timeout:((p=this.options.queueOptions)==null?void 0:p.timeout)||12e4};this.queues={completeChat:new B(a),getEmbeddings:new B(a),proxyCompleteChat:new B(a),proxyGetEmbeddings:new B(a)},this.options.enableProxyAgent===void 0||this.options.enableProxyAgent,this.httpClient=t.httpClient||new ee({timeoutInMilliseconds:a.timeout*.9,enableProxyAgent:this.options.enableProxyAgent}),this.caches={completeChat:t.completeChatCache||new X,getEmbeddings:t.getEmbeddingsCache||new X},(n=this.logger)==null||n.debug("gateway initialized");}completeChat(t){return l(this,null,function*(){var d,r;(d=this.logger)==null||d.info("gateway.completeChat invoked"),(r=this.logger)==null||r.debug("request: ",{request:t});let a=J.parse(t),e=a.model.modelSchema.name;return yield this.tracer.startActiveSpan("complete-chat",o=>l(this,null,function*(){return o.setAttribute("modelName",e),new Promise((i,p)=>{var m;let n={id:uuid.v4(),request:a,cache:this.caches.completeChat,resolve:c=>{this.analytics.record("completeChat","success",{modelName:e,usage:c.response.usage||{}}),i(c);},reject:c=>{console.log("completeChat error",c),this.analytics.record("completeChat","error",{modelName:e}),p(c);},execute:this.executeCompleteChat.bind(this),telemetryContext:api.context.active()};this.queues.completeChat.enqueue(n),(m=this.logger)==null||m.debug(`gateway.completeChat task enqueued, id: ${n.id}`);})}))})}executeCompleteChat(t,a){return l(this,null,function*(){var d,r,o,i;(d=this.logger)==null||d.debug("gateway.executeCompleteChat invoked");let e=J.parse(t);return ze({cache:this.caches.completeChat,model:e.model,config:e.config,messages:e.messages,tools:e.tools,enableCache:(o=(r=e.options)==null?void 0:r.enableCache)!=null?o:!0,callbacks:this.options.completeChatCallbacks,metadataForCallbacks:(i=e.options)==null?void 0:i.metadataForCallbacks},this.httpClient,a)})}streamChat(t){return O(this,null,function*(){var i,p,n,m;(i=this.logger)==null||i.info("gateway.streamChat invoked"),(p=this.logger)==null||p.debug("request: ",{request:t});let a=Me.parse(t),e=a.model.modelSchema.name,d="success",r=this.tracer.startSpan("stream-chat"),o=api.trace.setSpan(api.context.active(),r);try{return r.setAttribute("modelName",e),yield*Q(yield new b(api.context.with(o,()=>l(this,null,function*(){var c;return dt({model:a.model,config:a.config,messages:a.messages,tools:a.tools,callbacks:this.options.streamChatCallbacks,metadataForCallbacks:(c=a.options)==null?void 0:c.metadataForCallbacks,abortSignal:a.abortSignal},this.httpClient,o)}))))}catch(c){throw d="error",r.setStatus({code:api.SpanStatusCode.ERROR,message:"stream failed"}),(n=this.logger)==null||n.error("gateway.streamChat error: ",{error:c}),c instanceof w?c:new w(c==null?void 0:c.message,500,(m=c==null?void 0:c.response)==null?void 0:m.data)}finally{this.analytics.record("streamChat",d,{modelName:e}),r.end();}})}getEmbeddings(t){return l(this,null,function*(){var d,r;(d=this.logger)==null||d.info("gateway.getEmbeddings invoked"),(r=this.logger)==null||r.debug("request: ",{request:t});let a=me.parse(t),e=a.model.modelSchema.name;return yield this.tracer.startActiveSpan("get-embeddings",o=>l(this,null,function*(){return o.setAttribute("modelName",e),new Promise((i,p)=>{var m;let n={id:uuid.v4(),request:a,cache:this.caches.getEmbeddings,resolve:c=>{this.analytics.record("getEmbeddings","success",{modelName:e,usage:c.response.usage||{}}),i(c);},reject:c=>{this.analytics.record("getEmbeddings","error",{modelName:e}),p(c);},execute:this.executeGetEmbeddings.bind(this),telemetryContext:api.context.active()};this.queues.getEmbeddings.enqueue(n),(m=this.logger)==null||m.debug(`gateway.getEmbeddings task enqueued, id: ${n.id}`);})}))})}executeGetEmbeddings(t,a){return l(this,null,function*(){var d,r,o,i;(d=this.logger)==null||d.debug("gateway.executeGetEmbeddings invoked");let e=me.parse(t);return _e({cache:this.caches.getEmbeddings,model:e.model,config:e.config,embeddingRequests:e.embeddingRequests,enableCache:(o=(r=e.options)==null?void 0:r.enableCache)!=null?o:!0,callbacks:this.options.getEmbeddingsCallbacks,metadataForCallbacks:(i=e.options)==null?void 0:i.metadataForCallbacks},this.httpClient,a)})}proxyCompleteChat(t){return l(this,null,function*(){var d,r;(d=this.logger)==null||d.info("gateway.proxyCompleteChat invoked"),(r=this.logger)==null||r.debug("request: ",{request:t});let a=pe.parse(t),e=a.model.modelSchema.name;return yield this.tracer.startActiveSpan("proxy-complete-chat",o=>l(this,null,function*(){return o.setAttribute("modelName",e),new Promise((i,p)=>{var m;let n={id:uuid.v4(),request:a,resolve:c=>{var C;this.analytics.record("proxyCompleteChat","success",{modelName:e,usage:((C=c.transformedResponse)==null?void 0:C.usage)||{}}),i(c);},reject:c=>{console.log("proxyCompleteChat error",c),this.analytics.record("proxyCompleteChat","error",{modelName:e}),p(c);},execute:this.executeProxyCompleteChat.bind(this),telemetryContext:api.context.active()};this.queues.proxyCompleteChat.enqueue(n),(m=this.logger)==null||m.debug(`gateway.proxyCompleteChat task enqueued, id: ${n.id}`);})}))})}executeProxyCompleteChat(t,a){return l(this,null,function*(){var d;(d=this.logger)==null||d.debug("gateway.executeCompleteChat invoked");let e=pe.parse(t);return Ye({model:e.model,data:e.data,headers:e.headers,query:e.query},this.httpClient,a)})}proxyStreamChat(t){return O(this,null,function*(){var i,p,n,m;(i=this.logger)==null||i.info("gateway.proxyStreamChat invoked"),(p=this.logger)==null||p.debug("proxyStreamChat request: ",{request:t});let a=Le.parse(t),e=a.model.modelSchema.name,d="success",r=this.tracer.startSpan("proxy-stream-chat"),o=api.trace.setSpan(api.context.active(),r);try{return r.setAttribute("modelName",e),yield*Q(yield new b(api.context.with(o,()=>l(this,null,function*(){return at({model:a.model,data:a.data,headers:a.headers,query:a.query},this.httpClient,o)}))))}catch(c){throw d="error",r.setStatus({code:api.SpanStatusCode.ERROR,message:"proxy stream failed"}),(n=this.logger)==null||n.error("gateway.proxyStreamChat error: ",{error:c}),c instanceof w?c:new w(c==null?void 0:c.message,500,(m=c==null?void 0:c.response)==null?void 0:m.data)}finally{this.analytics.record("proxyStreamChat",d,{modelName:e}),r.end();}})}proxyGetEmbeddings(t){return l(this,null,function*(){var d,r;(d=this.logger)==null||d.info("gateway.proxyGetEmbeddings invoked"),(r=this.logger)==null||r.debug("request: ",{request:t});let a=le.parse(t),e=a.model.modelSchema.name;return yield this.tracer.startActiveSpan("proxy-get-embeddings",o=>l(this,null,function*(){return o.setAttribute("modelName",e),new Promise((i,p)=>{var m;let n={id:uuid.v4(),request:a,resolve:c=>{var C;this.analytics.record("proxyGetEmbeddings","success",{modelName:e,usage:((C=c.transformedResponse)==null?void 0:C.usage)||{}}),i(c);},reject:c=>{this.analytics.record("proxyGetEmbeddings","error",{modelName:e}),p(c);},execute:this.executeProxyGetEmbeddings.bind(this),telemetryContext:api.context.active()};this.queues.proxyGetEmbeddings.enqueue(n),(m=this.logger)==null||m.debug(`gateway.proxyGetEmbeddings task enqueued, id: ${n.id}`);})}))})}executeProxyGetEmbeddings(t,a){return l(this,null,function*(){var d;(d=this.logger)==null||d.debug("gateway.executeProxyGetEmbeddings invoked");let e=le.parse(t);return Ze({model:e.model,headers:e.headers,data:e.data,query:e.query},this.httpClient,a)})}};ue.GatewayError=w;
|
|
20
20
|
|
|
21
21
|
exports.AnalyticsManager = se;
|
|
22
22
|
exports.CompleteChatHandlerRequest = $e;
|