@jeffreycao/copilot-api 2.6.11 → 2.6.13
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 +12 -6
- package/README.zh-CN.md +13 -7
- package/dist/auth-B0w9MzMB.js +2 -0
- package/dist/{auth-aGQ_vPFn.js → auth-B1iccyyN.js} +47 -9
- package/dist/auth-B1iccyyN.js.map +1 -0
- package/dist/{config-g8kEbc0j.js → config-B_pC8QXv.js} +421 -10
- package/dist/config-B_pC8QXv.js.map +1 -0
- package/dist/{debug-DXGZGaoU.js → debug-C4rsL806.js} +2 -2
- package/dist/{debug-DXGZGaoU.js.map → debug-C4rsL806.js.map} +1 -1
- package/dist/main.js +3 -3
- package/dist/{models-C1H-ahM4.js → models-NNzBeGzA.js} +2 -2
- package/dist/{models-C1H-ahM4.js.map → models-NNzBeGzA.js.map} +1 -1
- package/dist/{server-Biyjjk2W.js → server-w3-DhBM0.js} +119 -297
- package/dist/server-w3-DhBM0.js.map +1 -0
- package/dist/{start-CYq2v7cu.js → start-B2vhz_qK.js} +7 -6
- package/dist/{start-CYq2v7cu.js.map → start-B2vhz_qK.js.map} +1 -1
- package/dist/{token-SzcMtW4G.js → token-3SWNt25T.js} +2 -2
- package/dist/{token-SzcMtW4G.js.map → token-3SWNt25T.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-Biyjjk2W.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
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 { B as PATHS, C as resolveMappedModel, D as getAnthropicApiKey, E as getAlphaSearchModel, F as isResponsesApiWebSearchEnabled, I as isResponsesApiWebSocketEnabled, M as getUpstreamTransportConfig, N as isAlphaSearchCodexPriorityEnabled, O as getClaudeAutoModel, P as isMessagesApiEnabled, S as isGpt56OrAbove, _ as getReasoningEffortForModel, b as isContextManagementEnabledForMessages, d as getOpencodeGoModelRecords, g as getModelResponsesApiCompactThreshold$1, h as getModelMappings, i as listEnabledProviders, j as getMessageApiWebSearchModel, k as getClaudeTokenMultiplier, l as getOpencodeGoModelConfig, m as getExtraPromptForModel, n as getRawProviderConfig, o as resolveEffectiveProviderType, s as resolveProviderConfigForModel, t as getProviderConfig, u as getOpencodeGoModelIds, v as getSmallModel, w as setModelMappings, x as isContextManagementEnabledForResponses, y as getSmallModelForProvider } from "./config-B_pC8QXv.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-3SWNt25T.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-NNzBeGzA.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`);
|
|
@@ -3262,10 +3052,9 @@ const resolveSupportedReasoningEffort = (requestedEffort, supportedEfforts) => {
|
|
|
3262
3052
|
//#region src/routes/provider/utils.ts
|
|
3263
3053
|
const forwardProviderResponseHeaders = (c, upstreamHeaders) => {
|
|
3264
3054
|
const headers = createProviderProxyResponseHeaders(upstreamHeaders);
|
|
3265
|
-
const setCookies = headers.getSetCookie();
|
|
3266
3055
|
headers.delete("set-cookie");
|
|
3056
|
+
headers.delete("x-models-etag");
|
|
3267
3057
|
for (const [headerName, headerValue] of headers) c.header(headerName, headerValue);
|
|
3268
|
-
for (const setCookie of setCookies) c.header("set-cookie", setCookie, { append: true });
|
|
3269
3058
|
};
|
|
3270
3059
|
const applyModelDefaults = (payload, modelConfig) => {
|
|
3271
3060
|
payload.temperature ??= modelConfig?.temperature;
|
|
@@ -3295,8 +3084,9 @@ const normalizeProviderResponsesReasoningEffort = (payload, providerConfig) => {
|
|
|
3295
3084
|
const logger$15 = createHandlerLogger("provider-chat-completions-handler");
|
|
3296
3085
|
async function handleProviderChatCompletionsForProvider(c, options) {
|
|
3297
3086
|
const { payload, provider } = options;
|
|
3298
|
-
const
|
|
3299
|
-
|
|
3087
|
+
const configuredProvider = await resolveProviderConfig(provider);
|
|
3088
|
+
const providerConfig = configuredProvider && resolveProviderConfigForModel(configuredProvider, payload.model);
|
|
3089
|
+
if (!providerConfig || providerConfig.type !== "openai-compatible") return c.json({ error: {
|
|
3300
3090
|
message: `Provider '${provider}' does not support the /v1/chat/completions endpoint`,
|
|
3301
3091
|
type: "invalid_request_error"
|
|
3302
3092
|
} }, 400);
|
|
@@ -5571,6 +5361,7 @@ const translateAnthropicMessagesToResponsesPayload = (payload, subagentAgentId)
|
|
|
5571
5361
|
};
|
|
5572
5362
|
if (translatedTools && translatedTools.length > 0) responsesPayload.tool_choice = toolChoice;
|
|
5573
5363
|
if (hasOriginalTools) responsesPayload.prompt_cache_key = promptCacheKey;
|
|
5364
|
+
if (responsesPayload.model.includes("grok")) delete responsesPayload.metadata;
|
|
5574
5365
|
return responsesPayload;
|
|
5575
5366
|
};
|
|
5576
5367
|
const encodeCompactionCarrierSignature = (compaction) => {
|
|
@@ -8029,10 +7820,6 @@ function getModels() {
|
|
|
8029
7820
|
//#region src/routes/provider/messages/handler.ts
|
|
8030
7821
|
const logger$10 = createHandlerLogger("provider-messages-handler");
|
|
8031
7822
|
const providerMessagesHandlerDependencies = { resolveProviderConfig };
|
|
8032
|
-
const resolveOverrideProviderAuthType = (providerConfig, effectiveType) => {
|
|
8033
|
-
if (providerConfig.authType === "azure-entra" || providerConfig.authType === "oauth2") return providerConfig.authType;
|
|
8034
|
-
return resolveProviderAuthType(providerConfig.name, void 0, effectiveType);
|
|
8035
|
-
};
|
|
8036
7823
|
async function handleProviderMessages(c) {
|
|
8037
7824
|
const provider = c.req.param("provider");
|
|
8038
7825
|
const payload = await c.req.json();
|
|
@@ -8048,14 +7835,15 @@ async function handleProviderMessages(c) {
|
|
|
8048
7835
|
}
|
|
8049
7836
|
async function handleProviderMessagesForProvider(c, options) {
|
|
8050
7837
|
const { payload, provider, usageEndpoint } = options;
|
|
8051
|
-
const
|
|
8052
|
-
if (!
|
|
7838
|
+
const configuredProvider = await providerMessagesHandlerDependencies.resolveProviderConfig(provider);
|
|
7839
|
+
if (!configuredProvider) return c.json({ error: {
|
|
8053
7840
|
message: `Provider '${provider}' not found or disabled`,
|
|
8054
7841
|
type: "invalid_request_error"
|
|
8055
7842
|
} }, 404);
|
|
8056
7843
|
try {
|
|
7844
|
+
const providerConfig = resolveProviderConfigForModel(configuredProvider, payload.model);
|
|
8057
7845
|
const modelConfig = providerConfig.models?.[payload.model];
|
|
8058
|
-
const effectiveType =
|
|
7846
|
+
const effectiveType = providerConfig.type;
|
|
8059
7847
|
debugJson(logger$10, "provider.messages.request", {
|
|
8060
7848
|
payload,
|
|
8061
7849
|
provider
|
|
@@ -8096,11 +7884,7 @@ async function handleProviderMessagesForProvider(c, options) {
|
|
|
8096
7884
|
payload,
|
|
8097
7885
|
provider
|
|
8098
7886
|
});
|
|
8099
|
-
const upstreamResponse = await forwardProviderMessages(
|
|
8100
|
-
...providerConfig,
|
|
8101
|
-
type: effectiveType,
|
|
8102
|
-
authType: resolveOverrideProviderAuthType(providerConfig, effectiveType)
|
|
8103
|
-
}, 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 });
|
|
8104
7888
|
if (!upstreamResponse.ok) {
|
|
8105
7889
|
logger$10.error("Failed to create responses", upstreamResponse);
|
|
8106
7890
|
throw new HTTPError("Failed to create responses", upstreamResponse);
|
|
@@ -9133,7 +8917,11 @@ async function handleCompletionPayload(c, anthropicPayload, dispatchOptions = {}
|
|
|
9133
8917
|
if (!state.tokenBasedBilling && !shouldUseClaudeAutoModel) {
|
|
9134
8918
|
const tools = anthropicPayload.tools;
|
|
9135
8919
|
const noTools = !tools || tools.length === 0;
|
|
9136
|
-
if (anthropicBeta && noTools && compactType === 0)
|
|
8920
|
+
if (anthropicBeta && noTools && compactType === 0) {
|
|
8921
|
+
const smallModel = getSmallModel();
|
|
8922
|
+
consola.debug(`Claude Code warmup small model: ${anthropicPayload.model} -> ${smallModel}`);
|
|
8923
|
+
anthropicPayload.model = smallModel;
|
|
8924
|
+
}
|
|
9137
8925
|
}
|
|
9138
8926
|
if (compactType) logger$9.debug("Compact request type:", compactType);
|
|
9139
8927
|
if (!state.tokenBasedBilling) {
|
|
@@ -10874,6 +10662,7 @@ function normalizeProviderModels(provider, models) {
|
|
|
10874
10662
|
return models.map((model) => normalizeProviderModel(provider, model)).filter((model) => model !== null);
|
|
10875
10663
|
}
|
|
10876
10664
|
async function getProviderModelRecords(providerConfig, requestHeaders) {
|
|
10665
|
+
if (providerConfig.name === "opencode-go") return getOpencodeGoModelRecords();
|
|
10877
10666
|
try {
|
|
10878
10667
|
const response = await forwardProviderModels(providerConfig, requestHeaders);
|
|
10879
10668
|
if (!response.ok) return getFallbackProviderModelRecords(providerConfig.name, "non_ok", { statusCode: response.status });
|
|
@@ -11200,6 +10989,18 @@ providerModelRoutes.get("/", async (c) => {
|
|
|
11200
10989
|
has_more: false
|
|
11201
10990
|
});
|
|
11202
10991
|
}
|
|
10992
|
+
if (providerConfig.name === "opencode-go") {
|
|
10993
|
+
const models = getOpencodeGoModelRecords();
|
|
10994
|
+
if (models.length === 0) return c.json({ error: {
|
|
10995
|
+
message: "OpenCode Go model catalog is unavailable",
|
|
10996
|
+
type: "service_unavailable"
|
|
10997
|
+
} }, 503);
|
|
10998
|
+
return c.json({
|
|
10999
|
+
object: "list",
|
|
11000
|
+
data: models,
|
|
11001
|
+
has_more: false
|
|
11002
|
+
});
|
|
11003
|
+
}
|
|
11203
11004
|
const upstreamResponse = await forwardProviderModels(providerConfig, c.req.raw.headers);
|
|
11204
11005
|
logger$4.debug("provider.models.response", {
|
|
11205
11006
|
provider,
|
|
@@ -12149,28 +11950,46 @@ function isAnthropicResponse(value) {
|
|
|
12149
11950
|
return typeof value === "object" && value !== null && "type" in value && value.type === "message" && "content" in value && Array.isArray(value.content);
|
|
12150
11951
|
}
|
|
12151
11952
|
//#endregion
|
|
11953
|
+
//#region src/routes/responses/task-title.ts
|
|
11954
|
+
const TASK_TITLE_PROMPT_PREFIX = "Generate a concise, single-line task title of at most 36 characters and under five words where possible.";
|
|
11955
|
+
const taskTitleDependencies = { getSmallModelForProvider };
|
|
11956
|
+
const getCodexTaskTitleModel = (userAgent, input, provider) => {
|
|
11957
|
+
if (!isCodexUserAgent(userAgent) || !Array.isArray(input)) return void 0;
|
|
11958
|
+
if (!input.slice(-2).some((item) => {
|
|
11959
|
+
const message = item;
|
|
11960
|
+
return message?.role === "user" && Array.isArray(message.content) && message.content.some((part) => part?.type === "input_text" && typeof part.text === "string" && part.text.startsWith(TASK_TITLE_PROMPT_PREFIX));
|
|
11961
|
+
})) return void 0;
|
|
11962
|
+
const model = taskTitleDependencies.getSmallModelForProvider(provider);
|
|
11963
|
+
if (model) consola.debug(`Codex task title small model: ${provider} -> ${model}`);
|
|
11964
|
+
return model;
|
|
11965
|
+
};
|
|
11966
|
+
//#endregion
|
|
12152
11967
|
//#region src/routes/provider/responses/handler.ts
|
|
12153
11968
|
const logger$2 = createHandlerLogger("provider-responses-handler");
|
|
12154
11969
|
const providerResponsesHandlerDependencies = { resolveProviderConfig };
|
|
12155
11970
|
async function handleProviderResponsesForProvider(c, options) {
|
|
12156
11971
|
const { payload, provider } = options;
|
|
11972
|
+
const taskTitleModel = getCodexTaskTitleModel(c.req.header("user-agent"), payload.input, provider);
|
|
11973
|
+
if (taskTitleModel) payload.model = taskTitleModel;
|
|
11974
|
+
const publicModel = taskTitleModel ?? options.publicModel ?? payload.model;
|
|
12157
11975
|
debugJson(logger$2, "Responses request payload:", {
|
|
12158
11976
|
payload,
|
|
12159
11977
|
provider
|
|
12160
11978
|
});
|
|
12161
|
-
const
|
|
11979
|
+
const configuredProvider = await providerResponsesHandlerDependencies.resolveProviderConfig(provider);
|
|
11980
|
+
const providerConfig = configuredProvider && resolveProviderConfigForModel(configuredProvider, payload.model);
|
|
12162
11981
|
if (!providerConfig) return c.json({ error: {
|
|
12163
11982
|
message: `Provider '${provider}' does not support the /v1/responses endpoint`,
|
|
12164
11983
|
type: "invalid_request_error"
|
|
12165
11984
|
} }, 400);
|
|
12166
|
-
const effectiveType =
|
|
11985
|
+
const effectiveType = providerConfig.type;
|
|
12167
11986
|
const normalizedReasoningEffort = normalizeProviderResponsesReasoningEffort(payload, providerConfig);
|
|
12168
11987
|
if (normalizedReasoningEffort) logger$2.debug(`Normalized reasoning effort from ${normalizedReasoningEffort.from} to ${normalizedReasoningEffort.to} based on the provider model configuration`);
|
|
12169
11988
|
if (shouldFallbackToMessages$1(c, payload.model, effectiveType)) {
|
|
12170
11989
|
filterReasoningForTransport(payload, true);
|
|
12171
11990
|
return await handleResponsesViaMessages(c, {
|
|
12172
11991
|
payload,
|
|
12173
|
-
publicModel
|
|
11992
|
+
publicModel,
|
|
12174
11993
|
targetModel: `${provider}/${payload.model}`
|
|
12175
11994
|
});
|
|
12176
11995
|
}
|
|
@@ -12382,6 +12201,9 @@ const handleResponses = async (c) => {
|
|
|
12382
12201
|
publicModel: requestedModel
|
|
12383
12202
|
});
|
|
12384
12203
|
}
|
|
12204
|
+
const taskTitleModel = getCodexTaskTitleModel(c.req.header("user-agent"), payload.input, "copilot");
|
|
12205
|
+
if (taskTitleModel) payload.model = taskTitleModel;
|
|
12206
|
+
const publicModel = taskTitleModel ?? requestedModel;
|
|
12385
12207
|
debugJson(logger$1, "Responses request payload:", payload);
|
|
12386
12208
|
const subagentMarker = getCodexResponsesSubagentMarker(c);
|
|
12387
12209
|
if (subagentMarker) debugJson(logger$1, "Detected Codex subagent headers:", subagentMarker);
|
|
@@ -12400,7 +12222,7 @@ const handleResponses = async (c) => {
|
|
|
12400
12222
|
filterReasoningForTransport(payload, true);
|
|
12401
12223
|
return await handleResponsesViaMessages(c, {
|
|
12402
12224
|
payload,
|
|
12403
|
-
publicModel
|
|
12225
|
+
publicModel,
|
|
12404
12226
|
targetModel: payload.model,
|
|
12405
12227
|
subagentMarker,
|
|
12406
12228
|
requestId,
|
|
@@ -12693,4 +12515,4 @@ createServer();
|
|
|
12693
12515
|
//#endregion
|
|
12694
12516
|
export { createServer };
|
|
12695
12517
|
|
|
12696
|
-
//# sourceMappingURL=server-
|
|
12518
|
+
//# sourceMappingURL=server-w3-DhBM0.js.map
|