@jeffreycao/copilot-api 2.6.10 → 2.6.12
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/README.md +7 -4
- package/README.zh-CN.md +8 -5
- package/dist/auth--lP6X6CT.js +2 -0
- package/dist/{auth-aGQ_vPFn.js → auth-BmwqHw2M.js} +47 -9
- package/dist/auth-BmwqHw2M.js.map +1 -0
- package/dist/{config-g8kEbc0j.js → config-DrIQvPh1.js} +410 -8
- package/dist/config-DrIQvPh1.js.map +1 -0
- package/dist/{debug-DXGZGaoU.js → debug-CsnBCL0y.js} +2 -2
- package/dist/{debug-DXGZGaoU.js.map → debug-CsnBCL0y.js.map} +1 -1
- package/dist/main.js +3 -3
- package/dist/{models-C1H-ahM4.js → models-DBLluNx2.js} +2 -2
- package/dist/{models-C1H-ahM4.js.map → models-DBLluNx2.js.map} +1 -1
- package/dist/{server-YjTkYHJ4.js → server-DDx3vRfk.js} +104 -299
- package/dist/server-DDx3vRfk.js.map +1 -0
- package/dist/{start-BeVQ_Cd1.js → start-lV093nRP.js} +7 -6
- package/dist/{start-BeVQ_Cd1.js.map → start-lV093nRP.js.map} +1 -1
- package/dist/{token-SzcMtW4G.js → token-BffZVEF7.js} +2 -2
- package/dist/{token-SzcMtW4G.js.map → token-BffZVEF7.js.map} +1 -1
- package/package.json +2 -1
- package/dist/auth-BTdaexGw.js +0 -2
- package/dist/auth-aGQ_vPFn.js.map +0 -1
- package/dist/config-g8kEbc0j.js.map +0 -1
- package/dist/server-YjTkYHJ4.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { $ as forwardError, B as forwardCodexResponses, C as copilotWebSocketHeaders, E as prepareMessageProxyHeaders, G as createResponsesHttpEventStream, H as requestContext, J as getResponsesStreamTerminalDisposition, K as createResponsesSafeStream, M as compactTextOnlyGuard, N as createAuthMiddleware, O as compactAutoContinuePromptStarts, P as getConfiguredAdminApiKeys, Q as HTTPError, R as CODEX_API_BASE_URL, T as prepareInteractionHeaders, U as resolveTraceId$1, V as generateTraceId, W as fetchUpstreamWithLifecycle, X as createWebSocketUrl, Y as createPooledWebSocketStream, Z as state, b as copilotBaseUrl, d as getUUID, f as isAsyncIterable, g as getCopilotUsage, h as parseUserIdMetadata, j as compactSystemPromptStarts, k as compactMessageSections, l as generateRequestIdFromPayload, m as isResponsesStream, o as setupCodexToken, p as isNullish, q as encodePoolKeyPart, u as getRootSessionId, w as prepareForCompact, x as copilotHeaders, z as buildCodexRequestHeaders } from "./token-
|
|
1
|
+
import { A as getMessageApiWebSearchModel, C as setModelMappings, D as getClaudeAutoModel, E as getAnthropicApiKey, F as isResponsesApiWebSocketEnabled, M as isAlphaSearchCodexPriorityEnabled, N as isMessagesApiEnabled, O as getClaudeTokenMultiplier, P as isResponsesApiWebSearchEnabled, S as resolveMappedModel, T as getAlphaSearchModel, _ as getReasoningEffortForModel, b as isContextManagementEnabledForResponses, d as getOpencodeGoModelRecords, g as getModelResponsesApiCompactThreshold$1, h as getModelMappings, i as listEnabledProviders, j as getUpstreamTransportConfig, l as getOpencodeGoModelConfig, m as getExtraPromptForModel, n as getRawProviderConfig, o as resolveEffectiveProviderType, s as resolveProviderConfigForModel, t as getProviderConfig, u as getOpencodeGoModelIds, v as getSmallModel, x as isGpt56OrAbove, y as isContextManagementEnabledForMessages, z as PATHS } from "./config-DrIQvPh1.js";
|
|
2
|
+
import { $ as forwardError, B as forwardCodexResponses, C as copilotWebSocketHeaders, E as prepareMessageProxyHeaders, G as createResponsesHttpEventStream, H as requestContext, J as getResponsesStreamTerminalDisposition, K as createResponsesSafeStream, M as compactTextOnlyGuard, N as createAuthMiddleware, O as compactAutoContinuePromptStarts, P as getConfiguredAdminApiKeys, Q as HTTPError, R as CODEX_API_BASE_URL, T as prepareInteractionHeaders, U as resolveTraceId$1, V as generateTraceId, W as fetchUpstreamWithLifecycle, X as createWebSocketUrl, Y as createPooledWebSocketStream, Z as state, b as copilotBaseUrl, d as getUUID, f as isAsyncIterable, g as getCopilotUsage, h as parseUserIdMetadata, j as compactSystemPromptStarts, k as compactMessageSections, l as generateRequestIdFromPayload, m as isResponsesStream, o as setupCodexToken, p as isNullish, q as encodePoolKeyPart, u as getRootSessionId, w as prepareForCompact, x as copilotHeaders, z as buildCodexRequestHeaders } from "./token-BffZVEF7.js";
|
|
3
3
|
import { a as isDeferredToolName, c as parseMcpToolSearchSentinel, d as shouldEnableResponsesToolSearch, i as isBridgeToolSearchName, l as resolveBridgeToolSearchName, o as listDeferredToolNames, r as formatToolSearchBridgeArguments, s as normalizeToolSearchBridgeArguments, t as BRIDGE_TOOL_SEARCH_NAME, u as selectDeferredToolsByNames } from "./tool-search-BgFcDbNQ.js";
|
|
4
|
-
import { i as toClientModelId, r as normalizeSdkModelId, t as findEndpointModel } from "./models-
|
|
4
|
+
import { i as toClientModelId, r as normalizeSdkModelId, t as findEndpointModel } from "./models-DBLluNx2.js";
|
|
5
5
|
import consola from "consola";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
import fs, { createWriteStream, readFileSync, rmSync } from "node:fs";
|
|
@@ -550,50 +550,21 @@ const builtinProviderModelRegistry = new class BuiltinProviderModelRegistry {
|
|
|
550
550
|
"max"
|
|
551
551
|
]
|
|
552
552
|
},
|
|
553
|
-
"
|
|
554
|
-
contextWindow:
|
|
555
|
-
inputModalities: ["text"],
|
|
556
|
-
maxOutputTokens: 131072,
|
|
557
|
-
pricing: {
|
|
558
|
-
cachedInput: 2,
|
|
559
|
-
input: 8,
|
|
560
|
-
output: 28
|
|
561
|
-
},
|
|
562
|
-
reasoningEfforts: [
|
|
563
|
-
"low",
|
|
564
|
-
"high",
|
|
565
|
-
"max"
|
|
566
|
-
]
|
|
567
|
-
},
|
|
568
|
-
"ZHIPU/GLM-5.3-Flash": {
|
|
569
|
-
contextWindow: 1048576,
|
|
570
|
-
inputModalities: ["text", "image"],
|
|
571
|
-
maxOutputTokens: 131072,
|
|
572
|
-
pricing: {
|
|
573
|
-
cachedInput: .23,
|
|
574
|
-
input: .8,
|
|
575
|
-
output: 2.8
|
|
576
|
-
},
|
|
577
|
-
reasoningEfforts: [
|
|
578
|
-
"low",
|
|
579
|
-
"high",
|
|
580
|
-
"max"
|
|
581
|
-
]
|
|
582
|
-
},
|
|
583
|
-
"ZHIPU/GLM-5.3-FlashX": {
|
|
584
|
-
contextWindow: 1048576,
|
|
553
|
+
"deepseek-v4.1-flash": {
|
|
554
|
+
contextWindow: 1e6,
|
|
585
555
|
inputModalities: ["text", "image"],
|
|
586
|
-
maxOutputTokens:
|
|
556
|
+
maxOutputTokens: 393216,
|
|
587
557
|
pricing: {
|
|
588
|
-
cachedInput: .
|
|
558
|
+
cachedInput: .2,
|
|
589
559
|
input: 2,
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
560
|
+
offPeak: {
|
|
561
|
+
cachedInput: .1,
|
|
562
|
+
input: 1,
|
|
563
|
+
output: 4
|
|
564
|
+
},
|
|
565
|
+
output: 8,
|
|
566
|
+
peakWindows: dashscopePeakWindows
|
|
567
|
+
}
|
|
597
568
|
},
|
|
598
569
|
"qwen3.8-max": {
|
|
599
570
|
contextWindow: 1e6,
|
|
@@ -631,22 +602,6 @@ const builtinProviderModelRegistry = new class BuiltinProviderModelRegistry {
|
|
|
631
602
|
output: 2.7
|
|
632
603
|
}
|
|
633
604
|
},
|
|
634
|
-
"deepseek-v4.1-flash": {
|
|
635
|
-
contextWindow: 1e6,
|
|
636
|
-
inputModalities: ["text", "image"],
|
|
637
|
-
maxOutputTokens: 393216,
|
|
638
|
-
pricing: {
|
|
639
|
-
cachedInput: .2,
|
|
640
|
-
input: 2,
|
|
641
|
-
offPeak: {
|
|
642
|
-
cachedInput: .1,
|
|
643
|
-
input: 1,
|
|
644
|
-
output: 4
|
|
645
|
-
},
|
|
646
|
-
output: 8,
|
|
647
|
-
peakWindows: dashscopePeakWindows
|
|
648
|
-
}
|
|
649
|
-
},
|
|
650
605
|
"qwen3.7-plus": {
|
|
651
606
|
contextWindow: 1e6,
|
|
652
607
|
inputModalities: ["text", "image"],
|
|
@@ -676,95 +631,30 @@ const builtinProviderModelRegistry = new class BuiltinProviderModelRegistry {
|
|
|
676
631
|
input: 20,
|
|
677
632
|
output: 100
|
|
678
633
|
}
|
|
679
|
-
}
|
|
680
|
-
},
|
|
681
|
-
deepseek: {
|
|
682
|
-
"deepseek-flash": {
|
|
683
|
-
contextWindow: 1e6,
|
|
684
|
-
inputModalities: ["text", "image"],
|
|
685
|
-
maxOutputTokens: 384e3,
|
|
686
|
-
pricing: {
|
|
687
|
-
cachedInput: .04,
|
|
688
|
-
input: 2,
|
|
689
|
-
offPeak: {
|
|
690
|
-
cachedInput: .02,
|
|
691
|
-
input: 1,
|
|
692
|
-
output: 4
|
|
693
|
-
},
|
|
694
|
-
output: 8,
|
|
695
|
-
peakWindows: deepseekPeakWindows
|
|
696
|
-
},
|
|
697
|
-
reasoningEfforts: [
|
|
698
|
-
"low",
|
|
699
|
-
"high",
|
|
700
|
-
"max"
|
|
701
|
-
]
|
|
702
634
|
},
|
|
703
|
-
"
|
|
704
|
-
contextWindow:
|
|
635
|
+
"ZHIPU/GLM-5.3": {
|
|
636
|
+
contextWindow: 1048576,
|
|
705
637
|
inputModalities: ["text"],
|
|
706
|
-
maxOutputTokens:
|
|
638
|
+
maxOutputTokens: 131072,
|
|
707
639
|
pricing: {
|
|
708
|
-
cachedInput:
|
|
709
|
-
input:
|
|
710
|
-
|
|
711
|
-
cachedInput: .15,
|
|
712
|
-
input: 4.5,
|
|
713
|
-
output: 13.5
|
|
714
|
-
},
|
|
715
|
-
output: 27,
|
|
716
|
-
peakWindows: deepseekPeakWindows
|
|
640
|
+
cachedInput: 2,
|
|
641
|
+
input: 8,
|
|
642
|
+
output: 28
|
|
717
643
|
},
|
|
718
644
|
reasoningEfforts: [
|
|
719
645
|
"low",
|
|
720
646
|
"high",
|
|
721
647
|
"max"
|
|
722
648
|
]
|
|
723
|
-
}
|
|
724
|
-
},
|
|
725
|
-
"opencode-go": {
|
|
726
|
-
"hy4-preview": {
|
|
727
|
-
contextWindow: 1024e3,
|
|
728
|
-
inputModalities: ["text"],
|
|
729
|
-
maxOutputTokens: 64e3,
|
|
730
|
-
pricing: {
|
|
731
|
-
cachedInput: .042,
|
|
732
|
-
input: .834,
|
|
733
|
-
output: 2.501
|
|
734
|
-
},
|
|
735
|
-
reasoningEfforts: ["high"],
|
|
736
|
-
reasoningField: "reasoning"
|
|
737
649
|
},
|
|
738
|
-
"
|
|
739
|
-
|
|
740
|
-
cachedInput: .01,
|
|
741
|
-
input: .1,
|
|
742
|
-
maxInputTokens: 272e3,
|
|
743
|
-
output: .5
|
|
744
|
-
}, {
|
|
745
|
-
cacheCreationInput: .25,
|
|
746
|
-
cachedInput: .02,
|
|
747
|
-
input: .2,
|
|
748
|
-
output: .75
|
|
749
|
-
}] } },
|
|
750
|
-
"glm-5.3": {
|
|
751
|
-
contextWindow: 1e6,
|
|
752
|
-
inputModalities: ["text"],
|
|
753
|
-
maxOutputTokens: 64e3,
|
|
754
|
-
pricing: {
|
|
755
|
-
cachedInput: .26,
|
|
756
|
-
input: 1.4,
|
|
757
|
-
output: 4.4
|
|
758
|
-
}
|
|
759
|
-
},
|
|
760
|
-
"glm-5.3-flash": {
|
|
761
|
-
contextWindow: 1e6,
|
|
650
|
+
"ZHIPU/GLM-5.3-Flash": {
|
|
651
|
+
contextWindow: 1048576,
|
|
762
652
|
inputModalities: ["text", "image"],
|
|
763
653
|
maxOutputTokens: 131072,
|
|
764
654
|
pricing: {
|
|
765
|
-
cachedInput: .
|
|
766
|
-
input: .
|
|
767
|
-
output: .
|
|
655
|
+
cachedInput: .23,
|
|
656
|
+
input: .8,
|
|
657
|
+
output: 2.8
|
|
768
658
|
},
|
|
769
659
|
reasoningEfforts: [
|
|
770
660
|
"low",
|
|
@@ -772,58 +662,36 @@ const builtinProviderModelRegistry = new class BuiltinProviderModelRegistry {
|
|
|
772
662
|
"max"
|
|
773
663
|
]
|
|
774
664
|
},
|
|
775
|
-
"
|
|
665
|
+
"ZHIPU/GLM-5.3-FlashX": {
|
|
776
666
|
contextWindow: 1048576,
|
|
777
667
|
inputModalities: ["text", "image"],
|
|
778
668
|
maxOutputTokens: 131072,
|
|
779
669
|
pricing: {
|
|
780
|
-
cachedInput: .
|
|
781
|
-
input: .1,
|
|
782
|
-
output: .2
|
|
783
|
-
},
|
|
784
|
-
reasoningEfforts: [
|
|
785
|
-
"minimal",
|
|
786
|
-
"low",
|
|
787
|
-
"medium",
|
|
788
|
-
"high",
|
|
789
|
-
"xhigh"
|
|
790
|
-
]
|
|
791
|
-
},
|
|
792
|
-
"grok-4.7": {
|
|
793
|
-
contextWindow: 5e5,
|
|
794
|
-
defaultReasoningEffort: "high",
|
|
795
|
-
inputModalities: ["text", "image"],
|
|
796
|
-
maxOutputTokens: 64e3,
|
|
797
|
-
pricing: { tiers: [{
|
|
798
|
-
cachedInput: .5,
|
|
670
|
+
cachedInput: .57,
|
|
799
671
|
input: 2,
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
}, {
|
|
803
|
-
cachedInput: 1,
|
|
804
|
-
input: 4,
|
|
805
|
-
output: 12
|
|
806
|
-
}] },
|
|
672
|
+
output: 7
|
|
673
|
+
},
|
|
807
674
|
reasoningEfforts: [
|
|
808
675
|
"low",
|
|
809
|
-
"medium",
|
|
810
676
|
"high",
|
|
811
|
-
"
|
|
677
|
+
"max"
|
|
812
678
|
]
|
|
813
|
-
}
|
|
814
|
-
|
|
679
|
+
}
|
|
680
|
+
},
|
|
681
|
+
deepseek: {
|
|
682
|
+
"deepseek-flash": {
|
|
815
683
|
contextWindow: 1e6,
|
|
816
684
|
inputModalities: ["text", "image"],
|
|
817
685
|
maxOutputTokens: 384e3,
|
|
818
686
|
pricing: {
|
|
819
|
-
cachedInput: .
|
|
820
|
-
input:
|
|
687
|
+
cachedInput: .04,
|
|
688
|
+
input: 2,
|
|
821
689
|
offPeak: {
|
|
822
|
-
cachedInput: .
|
|
823
|
-
input:
|
|
824
|
-
output:
|
|
690
|
+
cachedInput: .02,
|
|
691
|
+
input: 1,
|
|
692
|
+
output: 4
|
|
825
693
|
},
|
|
826
|
-
output:
|
|
694
|
+
output: 8,
|
|
827
695
|
peakWindows: deepseekPeakWindows
|
|
828
696
|
},
|
|
829
697
|
reasoningEfforts: [
|
|
@@ -837,107 +705,21 @@ const builtinProviderModelRegistry = new class BuiltinProviderModelRegistry {
|
|
|
837
705
|
inputModalities: ["text"],
|
|
838
706
|
maxOutputTokens: 64e3,
|
|
839
707
|
pricing: {
|
|
840
|
-
cachedInput: .
|
|
841
|
-
input:
|
|
708
|
+
cachedInput: .3,
|
|
709
|
+
input: 9,
|
|
842
710
|
offPeak: {
|
|
843
|
-
cachedInput: .
|
|
844
|
-
input: .
|
|
845
|
-
output:
|
|
711
|
+
cachedInput: .15,
|
|
712
|
+
input: 4.5,
|
|
713
|
+
output: 13.5
|
|
846
714
|
},
|
|
847
|
-
output:
|
|
715
|
+
output: 27,
|
|
848
716
|
peakWindows: deepseekPeakWindows
|
|
849
|
-
}
|
|
850
|
-
},
|
|
851
|
-
"kimi-k3": {
|
|
852
|
-
contextWindow: 1048576,
|
|
853
|
-
inputModalities: ["text", "image"],
|
|
854
|
-
maxOutputTokens: 64e3,
|
|
855
|
-
pricing: {
|
|
856
|
-
cachedInput: .3,
|
|
857
|
-
input: 3,
|
|
858
|
-
output: 15
|
|
859
|
-
}
|
|
860
|
-
},
|
|
861
|
-
"mimo-v2.6-flash": {
|
|
862
|
-
contextWindow: 1048576,
|
|
863
|
-
inputModalities: ["text", "image"],
|
|
864
|
-
maxOutputTokens: 131072,
|
|
865
|
-
pricing: {
|
|
866
|
-
cachedInput: .0028,
|
|
867
|
-
input: .14,
|
|
868
|
-
output: .28
|
|
869
|
-
}
|
|
870
|
-
},
|
|
871
|
-
"mimo-v2.6-pro": {
|
|
872
|
-
contextWindow: 1048576,
|
|
873
|
-
inputModalities: ["text", "image"],
|
|
874
|
-
maxOutputTokens: 131072,
|
|
875
|
-
pricing: {
|
|
876
|
-
cachedInput: .003625,
|
|
877
|
-
input: .435,
|
|
878
|
-
output: .87
|
|
879
|
-
}
|
|
880
|
-
},
|
|
881
|
-
"qwen3.7-plus": {
|
|
882
|
-
contextWindow: 1e6,
|
|
883
|
-
inputModalities: ["text", "image"],
|
|
884
|
-
maxOutputTokens: 64e3,
|
|
885
|
-
pricing: { tiers: [{
|
|
886
|
-
cacheCreationInput: .5,
|
|
887
|
-
cachedInput: .04,
|
|
888
|
-
input: .4,
|
|
889
|
-
maxInputTokens: 2e5,
|
|
890
|
-
output: 1.6
|
|
891
|
-
}, {
|
|
892
|
-
cacheCreationInput: 1.5,
|
|
893
|
-
cachedInput: .12,
|
|
894
|
-
input: 1.2,
|
|
895
|
-
maxInputTokens: 256e3,
|
|
896
|
-
output: 4.8
|
|
897
|
-
}] }
|
|
898
|
-
},
|
|
899
|
-
"qwen3.8-max": {
|
|
900
|
-
contextWindow: 1e6,
|
|
901
|
-
inputModalities: ["text", "image"],
|
|
902
|
-
maxOutputTokens: 64e3,
|
|
903
|
-
pricing: {
|
|
904
|
-
cacheCreationInput: 2.5,
|
|
905
|
-
cachedInput: .25,
|
|
906
|
-
input: 2,
|
|
907
|
-
output: 6
|
|
908
|
-
}
|
|
909
|
-
},
|
|
910
|
-
"qwen3.8-flash": {
|
|
911
|
-
contextWindow: 1e6,
|
|
912
|
-
inputModalities: ["text", "image"],
|
|
913
|
-
maxOutputTokens: 131072,
|
|
914
|
-
pricing: {
|
|
915
|
-
cacheCreationInput: .2,
|
|
916
|
-
cachedInput: .016,
|
|
917
|
-
input: .15,
|
|
918
|
-
output: .47
|
|
919
717
|
},
|
|
920
718
|
reasoningEfforts: [
|
|
921
719
|
"low",
|
|
922
|
-
"
|
|
923
|
-
"
|
|
720
|
+
"high",
|
|
721
|
+
"max"
|
|
924
722
|
]
|
|
925
|
-
},
|
|
926
|
-
"minimax-m3": {
|
|
927
|
-
contextWindow: 1e6,
|
|
928
|
-
inputModalities: ["text", "image"],
|
|
929
|
-
maxOutputTokens: 64e3,
|
|
930
|
-
pricing: { tiers: [{
|
|
931
|
-
cachedInput: .06,
|
|
932
|
-
input: .3,
|
|
933
|
-
maxInputTokens: 2e5,
|
|
934
|
-
output: 1.2
|
|
935
|
-
}, {
|
|
936
|
-
cachedInput: .12,
|
|
937
|
-
input: .6,
|
|
938
|
-
maxInputTokens: 512e3,
|
|
939
|
-
output: 2.4
|
|
940
|
-
}] }
|
|
941
723
|
}
|
|
942
724
|
},
|
|
943
725
|
kimi: {
|
|
@@ -968,11 +750,15 @@ const builtinProviderModelRegistry = new class BuiltinProviderModelRegistry {
|
|
|
968
750
|
this.modelCatalog = BuiltinProviderModelRegistry.catalog;
|
|
969
751
|
}
|
|
970
752
|
getModelConfig(providerName, modelName) {
|
|
971
|
-
const
|
|
753
|
+
const provider = this.normalizeKey(providerName);
|
|
754
|
+
if (provider === "opencode-go") return getOpencodeGoModelConfig(modelName);
|
|
755
|
+
const models = this.modelCatalog[provider];
|
|
972
756
|
return models?.[modelName.trim()] ?? models?.[this.normalizeKey(modelName)];
|
|
973
757
|
}
|
|
974
758
|
getModelIds(providerName) {
|
|
975
|
-
|
|
759
|
+
const provider = this.normalizeKey(providerName);
|
|
760
|
+
if (provider === "opencode-go") return getOpencodeGoModelIds();
|
|
761
|
+
return Object.keys(this.modelCatalog[provider] ?? {});
|
|
976
762
|
}
|
|
977
763
|
normalizeKey(value) {
|
|
978
764
|
return value.trim().toLowerCase();
|
|
@@ -2356,6 +2142,9 @@ const STRIPPED_RESPONSE_HEADERS = [
|
|
|
2356
2142
|
"transfer-encoding",
|
|
2357
2143
|
"upgrade"
|
|
2358
2144
|
];
|
|
2145
|
+
function resolveProviderEndpointUrl(providerConfig, endpoint) {
|
|
2146
|
+
return `${providerConfig.modelsDevProviderId ? providerConfig.baseUrl.replace(/\/(?:chat\/completions|responses)$/u, "") : `${providerConfig.baseUrl}/v1`}/${endpoint}`;
|
|
2147
|
+
}
|
|
2359
2148
|
function buildProviderUpstreamHeaders(providerConfig, requestHeaders) {
|
|
2360
2149
|
const authHeaders = {};
|
|
2361
2150
|
if (providerConfig.authType === "x-api-key") authHeaders["x-api-key"] = providerConfig.apiKey;
|
|
@@ -2370,6 +2159,7 @@ function buildProviderUpstreamHeaders(providerConfig, requestHeaders) {
|
|
|
2370
2159
|
if (headerValue) headers[headerName] = headerValue;
|
|
2371
2160
|
}
|
|
2372
2161
|
if (providerConfig.type !== "anthropic") return headers;
|
|
2162
|
+
if (providerConfig.modelsDevProviderId) headers["anthropic-version"] = "2023-06-01";
|
|
2373
2163
|
for (const headerName of ANTHROPIC_FORWARDABLE_HEADERS) {
|
|
2374
2164
|
const headerValue = requestHeaders.get(headerName);
|
|
2375
2165
|
if (headerValue) headers[headerName] = headerValue;
|
|
@@ -2407,7 +2197,7 @@ async function forwardProviderMessages(providerConfig, payload, requestHeaders,
|
|
|
2407
2197
|
const headers = buildProviderUpstreamHeaders(providerConfig, requestHeaders);
|
|
2408
2198
|
applyOpencodeSessionHeader(providerConfig, headers, resolveOpencodeMessagesSession(payload));
|
|
2409
2199
|
const transportConfig = getUpstreamTransportConfig();
|
|
2410
|
-
return await fetchUpstreamWithLifecycle(
|
|
2200
|
+
return await fetchUpstreamWithLifecycle(resolveProviderEndpointUrl(providerConfig, "messages"), {
|
|
2411
2201
|
method: "POST",
|
|
2412
2202
|
headers,
|
|
2413
2203
|
body: JSON.stringify(payload)
|
|
@@ -2422,7 +2212,7 @@ async function forwardProviderChatCompletions(providerConfig, payload, requestHe
|
|
|
2422
2212
|
const headers = buildProviderUpstreamHeaders(providerConfig, requestHeaders);
|
|
2423
2213
|
applyOpencodeSessionHeader(providerConfig, headers, payload.prompt_cache_key?.trim() || void 0);
|
|
2424
2214
|
const transportConfig = getUpstreamTransportConfig();
|
|
2425
|
-
return await fetchUpstreamWithLifecycle(
|
|
2215
|
+
return await fetchUpstreamWithLifecycle(resolveProviderEndpointUrl(providerConfig, "chat/completions"), {
|
|
2426
2216
|
method: "POST",
|
|
2427
2217
|
headers,
|
|
2428
2218
|
body: JSON.stringify(payload)
|
|
@@ -2437,7 +2227,7 @@ async function forwardProviderResponses(providerConfig, payload, requestHeaders,
|
|
|
2437
2227
|
const transportConfig = getUpstreamTransportConfig();
|
|
2438
2228
|
const headers = buildProviderUpstreamHeaders(providerConfig, requestHeaders);
|
|
2439
2229
|
applyOpencodeSessionHeader(providerConfig, headers, payload.prompt_cache_key?.trim() || void 0);
|
|
2440
|
-
return await fetchUpstreamWithLifecycle(
|
|
2230
|
+
return await fetchUpstreamWithLifecycle(resolveProviderEndpointUrl(providerConfig, "responses"), {
|
|
2441
2231
|
method: "POST",
|
|
2442
2232
|
headers,
|
|
2443
2233
|
body: JSON.stringify(payload)
|
|
@@ -2449,7 +2239,7 @@ async function forwardProviderResponses(providerConfig, payload, requestHeaders,
|
|
|
2449
2239
|
}
|
|
2450
2240
|
const PROVIDER_MODELS_TIMEOUT_MS = 15e3;
|
|
2451
2241
|
async function forwardProviderModels(providerConfig, requestHeaders) {
|
|
2452
|
-
return await fetch(
|
|
2242
|
+
return await fetch(resolveProviderEndpointUrl(providerConfig, "models"), {
|
|
2453
2243
|
method: "GET",
|
|
2454
2244
|
headers: buildProviderUpstreamHeaders(providerConfig, requestHeaders),
|
|
2455
2245
|
signal: AbortSignal.timeout(PROVIDER_MODELS_TIMEOUT_MS)
|
|
@@ -2459,7 +2249,7 @@ async function forwardProviderModels(providerConfig, requestHeaders) {
|
|
|
2459
2249
|
const PROVIDER_IMAGES_TIMEOUT_MS = 9e5;
|
|
2460
2250
|
const providerImagesDispatcher = createTimeoutDispatcher(PROVIDER_IMAGES_TIMEOUT_MS);
|
|
2461
2251
|
function resolveProviderRequestUrl(providerConfig, requestUrl, path) {
|
|
2462
|
-
const upstreamUrl = new URL(
|
|
2252
|
+
const upstreamUrl = new URL(resolveProviderEndpointUrl(providerConfig, path.replace(/^\/v1\//u, "")));
|
|
2463
2253
|
upstreamUrl.search = new URL(requestUrl, "http://localhost").search;
|
|
2464
2254
|
return upstreamUrl.toString();
|
|
2465
2255
|
}
|
|
@@ -2831,7 +2621,7 @@ async function resolveRemoteModel(c, request, provider) {
|
|
|
2831
2621
|
if (alphaSearchResponsesDependencies.resolveEffectiveProviderType(providerConfig, model) !== "openai-responses") return invalidRequest$1(c, `Provider '${provider}' does not support the /v1/responses endpoint required for alpha search`);
|
|
2832
2622
|
return {
|
|
2833
2623
|
model,
|
|
2834
|
-
providerConfig
|
|
2624
|
+
providerConfig: resolveProviderConfigForModel(providerConfig, model)
|
|
2835
2625
|
};
|
|
2836
2626
|
}
|
|
2837
2627
|
if (!alphaSearchResponsesDependencies.findEndpointModel(model)?.supported_endpoints?.includes("/responses")) return invalidRequest$1(c, `Model '${model}' does not support the Copilot Responses endpoint required for alpha search`);
|
|
@@ -3295,8 +3085,9 @@ const normalizeProviderResponsesReasoningEffort = (payload, providerConfig) => {
|
|
|
3295
3085
|
const logger$15 = createHandlerLogger("provider-chat-completions-handler");
|
|
3296
3086
|
async function handleProviderChatCompletionsForProvider(c, options) {
|
|
3297
3087
|
const { payload, provider } = options;
|
|
3298
|
-
const
|
|
3299
|
-
|
|
3088
|
+
const configuredProvider = await resolveProviderConfig(provider);
|
|
3089
|
+
const providerConfig = configuredProvider && resolveProviderConfigForModel(configuredProvider, payload.model);
|
|
3090
|
+
if (!providerConfig || providerConfig.type !== "openai-compatible") return c.json({ error: {
|
|
3300
3091
|
message: `Provider '${provider}' does not support the /v1/chat/completions endpoint`,
|
|
3301
3092
|
type: "invalid_request_error"
|
|
3302
3093
|
} }, 400);
|
|
@@ -5338,7 +5129,7 @@ function handleReasoningOpaqueInToolCalls(state, events, delta) {
|
|
|
5338
5129
|
function handleContent(delta, state, events) {
|
|
5339
5130
|
if (delta.content && delta.content.length > 0) {
|
|
5340
5131
|
closeThinkingBlockIfOpen(state, events);
|
|
5341
|
-
if (isToolBlockOpen(state)
|
|
5132
|
+
if (isToolBlockOpen(state)) {
|
|
5342
5133
|
state.deferredContent = `${state.deferredContent ?? ""}${delta.content}`;
|
|
5343
5134
|
return;
|
|
5344
5135
|
}
|
|
@@ -5378,9 +5169,6 @@ function handleContent(delta, state, events) {
|
|
|
5378
5169
|
state.thinkingBlockOpen = false;
|
|
5379
5170
|
}
|
|
5380
5171
|
}
|
|
5381
|
-
function hasToolCallDelta(delta) {
|
|
5382
|
-
return Boolean(delta.tool_calls && delta.tool_calls.length > 0);
|
|
5383
|
-
}
|
|
5384
5172
|
function flushDeferredContent(state, events) {
|
|
5385
5173
|
if (!state.deferredContent) return;
|
|
5386
5174
|
if (!state.contentBlockOpen) {
|
|
@@ -8032,10 +7820,6 @@ function getModels() {
|
|
|
8032
7820
|
//#region src/routes/provider/messages/handler.ts
|
|
8033
7821
|
const logger$10 = createHandlerLogger("provider-messages-handler");
|
|
8034
7822
|
const providerMessagesHandlerDependencies = { resolveProviderConfig };
|
|
8035
|
-
const resolveOverrideProviderAuthType = (providerConfig, effectiveType) => {
|
|
8036
|
-
if (providerConfig.authType === "azure-entra" || providerConfig.authType === "oauth2") return providerConfig.authType;
|
|
8037
|
-
return resolveProviderAuthType(providerConfig.name, void 0, effectiveType);
|
|
8038
|
-
};
|
|
8039
7823
|
async function handleProviderMessages(c) {
|
|
8040
7824
|
const provider = c.req.param("provider");
|
|
8041
7825
|
const payload = await c.req.json();
|
|
@@ -8051,14 +7835,15 @@ async function handleProviderMessages(c) {
|
|
|
8051
7835
|
}
|
|
8052
7836
|
async function handleProviderMessagesForProvider(c, options) {
|
|
8053
7837
|
const { payload, provider, usageEndpoint } = options;
|
|
8054
|
-
const
|
|
8055
|
-
if (!
|
|
7838
|
+
const configuredProvider = await providerMessagesHandlerDependencies.resolveProviderConfig(provider);
|
|
7839
|
+
if (!configuredProvider) return c.json({ error: {
|
|
8056
7840
|
message: `Provider '${provider}' not found or disabled`,
|
|
8057
7841
|
type: "invalid_request_error"
|
|
8058
7842
|
} }, 404);
|
|
8059
7843
|
try {
|
|
7844
|
+
const providerConfig = resolveProviderConfigForModel(configuredProvider, payload.model);
|
|
8060
7845
|
const modelConfig = providerConfig.models?.[payload.model];
|
|
8061
|
-
const effectiveType =
|
|
7846
|
+
const effectiveType = providerConfig.type;
|
|
8062
7847
|
debugJson(logger$10, "provider.messages.request", {
|
|
8063
7848
|
payload,
|
|
8064
7849
|
provider
|
|
@@ -8099,11 +7884,7 @@ async function handleProviderMessagesForProvider(c, options) {
|
|
|
8099
7884
|
payload,
|
|
8100
7885
|
provider
|
|
8101
7886
|
});
|
|
8102
|
-
const upstreamResponse = await forwardProviderMessages(
|
|
8103
|
-
...providerConfig,
|
|
8104
|
-
type: effectiveType,
|
|
8105
|
-
authType: resolveOverrideProviderAuthType(providerConfig, effectiveType)
|
|
8106
|
-
}, payload, c.req.raw.headers, { clientSignal: c.req.raw.signal });
|
|
7887
|
+
const upstreamResponse = await forwardProviderMessages(providerConfig, payload, c.req.raw.headers, { clientSignal: c.req.raw.signal });
|
|
8107
7888
|
if (!upstreamResponse.ok) {
|
|
8108
7889
|
logger$10.error("Failed to create responses", upstreamResponse);
|
|
8109
7890
|
throw new HTTPError("Failed to create responses", upstreamResponse);
|
|
@@ -10651,10 +10432,11 @@ async function handleCodexModelsProxy(c, resolvedProviderConfig) {
|
|
|
10651
10432
|
return createProviderProxyResponse(await forwardCodexModels(c.req.url, c.req.raw.headers));
|
|
10652
10433
|
}
|
|
10653
10434
|
async function handleMergedCodexModels(c, candidatesRequest, options = {}) {
|
|
10654
|
-
const [
|
|
10435
|
+
const [upstreamCatalogResult, candidates] = await Promise.all([tryGetCodexCatalog(c), Promise.resolve(candidatesRequest).catch((error) => {
|
|
10655
10436
|
logger$8.warn("models.codex.candidates_error", { error });
|
|
10656
10437
|
return [];
|
|
10657
10438
|
})]);
|
|
10439
|
+
const upstreamCatalog = upstreamCatalogResult?.catalog;
|
|
10658
10440
|
const upstreamModels = upstreamCatalog?.models ?? FALLBACK_CODEX_MODELS;
|
|
10659
10441
|
const template = selectTemplate(upstreamModels);
|
|
10660
10442
|
const catalogModelsBySlug = new Map(upstreamModels.map((model) => [model.slug, model]));
|
|
@@ -10687,7 +10469,12 @@ async function handleMergedCodexModels(c, candidatesRequest, options = {}) {
|
|
|
10687
10469
|
...upstreamCatalog ?? {},
|
|
10688
10470
|
models
|
|
10689
10471
|
};
|
|
10690
|
-
|
|
10472
|
+
const result = c.json(response);
|
|
10473
|
+
if (upstreamCatalogResult?.etag) {
|
|
10474
|
+
result.headers.set("ETag", upstreamCatalogResult.etag);
|
|
10475
|
+
result.headers.set("Cache-Control", "private, no-store");
|
|
10476
|
+
}
|
|
10477
|
+
return result;
|
|
10691
10478
|
}
|
|
10692
10479
|
function createCatalogAlias(model, slug, providerName) {
|
|
10693
10480
|
const alias = {
|
|
@@ -10775,7 +10562,10 @@ async function tryGetCodexCatalog(c) {
|
|
|
10775
10562
|
logger$8.warn("models.codex.catalog_invalid");
|
|
10776
10563
|
return null;
|
|
10777
10564
|
}
|
|
10778
|
-
return
|
|
10565
|
+
return {
|
|
10566
|
+
catalog: body,
|
|
10567
|
+
etag: response.headers.get("ETag")
|
|
10568
|
+
};
|
|
10779
10569
|
} catch (error) {
|
|
10780
10570
|
logger$8.warn("models.codex.catalog_error", { error });
|
|
10781
10571
|
return null;
|
|
@@ -10868,6 +10658,7 @@ function normalizeProviderModels(provider, models) {
|
|
|
10868
10658
|
return models.map((model) => normalizeProviderModel(provider, model)).filter((model) => model !== null);
|
|
10869
10659
|
}
|
|
10870
10660
|
async function getProviderModelRecords(providerConfig, requestHeaders) {
|
|
10661
|
+
if (providerConfig.name === "opencode-go") return getOpencodeGoModelRecords();
|
|
10871
10662
|
try {
|
|
10872
10663
|
const response = await forwardProviderModels(providerConfig, requestHeaders);
|
|
10873
10664
|
if (!response.ok) return getFallbackProviderModelRecords(providerConfig.name, "non_ok", { statusCode: response.status });
|
|
@@ -11194,6 +10985,18 @@ providerModelRoutes.get("/", async (c) => {
|
|
|
11194
10985
|
has_more: false
|
|
11195
10986
|
});
|
|
11196
10987
|
}
|
|
10988
|
+
if (providerConfig.name === "opencode-go") {
|
|
10989
|
+
const models = getOpencodeGoModelRecords();
|
|
10990
|
+
if (models.length === 0) return c.json({ error: {
|
|
10991
|
+
message: "OpenCode Go model catalog is unavailable",
|
|
10992
|
+
type: "service_unavailable"
|
|
10993
|
+
} }, 503);
|
|
10994
|
+
return c.json({
|
|
10995
|
+
object: "list",
|
|
10996
|
+
data: models,
|
|
10997
|
+
has_more: false
|
|
10998
|
+
});
|
|
10999
|
+
}
|
|
11197
11000
|
const upstreamResponse = await forwardProviderModels(providerConfig, c.req.raw.headers);
|
|
11198
11001
|
logger$4.debug("provider.models.response", {
|
|
11199
11002
|
provider,
|
|
@@ -12078,6 +11881,7 @@ const logger$3 = createHandlerLogger("responses-messages-handler");
|
|
|
12078
11881
|
const responsesMessagesDependencies = { handleCompletionPayload };
|
|
12079
11882
|
async function handleResponsesViaMessages(c, options) {
|
|
12080
11883
|
try {
|
|
11884
|
+
if (isCodexUserAgent(c.req.header("user-agent")) && options.targetModel.toLowerCase().includes("mimo-v2.6")) throw new ResponsesMessagesTranslationError("MiMo v2.6 cannot return valid Codex custom tool responses. Please switch models.");
|
|
12081
11885
|
const translation = translateResponsesToMessages({
|
|
12082
11886
|
...options.payload,
|
|
12083
11887
|
model: options.publicModel
|
|
@@ -12151,12 +11955,13 @@ async function handleProviderResponsesForProvider(c, options) {
|
|
|
12151
11955
|
payload,
|
|
12152
11956
|
provider
|
|
12153
11957
|
});
|
|
12154
|
-
const
|
|
11958
|
+
const configuredProvider = await providerResponsesHandlerDependencies.resolveProviderConfig(provider);
|
|
11959
|
+
const providerConfig = configuredProvider && resolveProviderConfigForModel(configuredProvider, payload.model);
|
|
12155
11960
|
if (!providerConfig) return c.json({ error: {
|
|
12156
11961
|
message: `Provider '${provider}' does not support the /v1/responses endpoint`,
|
|
12157
11962
|
type: "invalid_request_error"
|
|
12158
11963
|
} }, 400);
|
|
12159
|
-
const effectiveType =
|
|
11964
|
+
const effectiveType = providerConfig.type;
|
|
12160
11965
|
const normalizedReasoningEffort = normalizeProviderResponsesReasoningEffort(payload, providerConfig);
|
|
12161
11966
|
if (normalizedReasoningEffort) logger$2.debug(`Normalized reasoning effort from ${normalizedReasoningEffort.from} to ${normalizedReasoningEffort.to} based on the provider model configuration`);
|
|
12162
11967
|
if (shouldFallbackToMessages$1(c, payload.model, effectiveType)) {
|
|
@@ -12686,4 +12491,4 @@ createServer();
|
|
|
12686
12491
|
//#endregion
|
|
12687
12492
|
export { createServer };
|
|
12688
12493
|
|
|
12689
|
-
//# sourceMappingURL=server-
|
|
12494
|
+
//# sourceMappingURL=server-DDx3vRfk.js.map
|