@jeffreycao/copilot-api 2.7.11 → 2.7.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.
Files changed (28) hide show
  1. package/README.md +2 -2
  2. package/README.zh-CN.md +2 -2
  3. package/dist/{auth-qC1GSLdS.js → auth--x4CIFvT.js} +4 -4
  4. package/dist/{auth-qC1GSLdS.js.map → auth--x4CIFvT.js.map} +1 -1
  5. package/dist/auth-1hGXVwvW.js +2 -0
  6. package/dist/{config-Cd0U5gXz.js → config-BKA4Y1t8.js} +237 -28
  7. package/dist/config-BKA4Y1t8.js.map +1 -0
  8. package/dist/{config-store-C6GAtKLz.js → config-store-CC5TNG7V.js} +2 -2
  9. package/dist/{config-store-C6GAtKLz.js.map → config-store-CC5TNG7V.js.map} +1 -1
  10. package/dist/{copilot-runtime-Dg3ywZkl.js → copilot-runtime-CW4zUahm.js} +3 -3
  11. package/dist/{copilot-runtime-Dg3ywZkl.js.map → copilot-runtime-CW4zUahm.js.map} +1 -1
  12. package/dist/{debug-CmL-V7Ov.js → debug-BPNjSHgl.js} +3 -3
  13. package/dist/{debug-CmL-V7Ov.js.map → debug-BPNjSHgl.js.map} +1 -1
  14. package/dist/main.js +4 -4
  15. package/dist/{provider-CzziTLqX.js → provider-Dg-3-rrN.js} +2 -2
  16. package/dist/{provider-CzziTLqX.js.map → provider-Dg-3-rrN.js.map} +1 -1
  17. package/dist/{provider-management-DOfLC7WX.js → provider-management-CBrc2nDg.js} +2 -2
  18. package/dist/{provider-management-DOfLC7WX.js.map → provider-management-CBrc2nDg.js.map} +1 -1
  19. package/dist/{server-Dvvc9z2P.js → server-DqfE4x5m.js} +154 -565
  20. package/dist/server-DqfE4x5m.js.map +1 -0
  21. package/dist/{start-Dqv75dA4.js → start-Mpyr_cO_.js} +7 -7
  22. package/dist/{start-Dqv75dA4.js.map → start-Mpyr_cO_.js.map} +1 -1
  23. package/dist/{token-kSGCOmTG.js → token-BdwhXP3l.js} +3 -3
  24. package/dist/{token-kSGCOmTG.js.map → token-BdwhXP3l.js.map} +1 -1
  25. package/package.json +1 -1
  26. package/dist/auth-BzYvzeW0.js +0 -2
  27. package/dist/config-Cd0U5gXz.js.map +0 -1
  28. package/dist/server-Dvvc9z2P.js.map +0 -1
@@ -1,9 +1,9 @@
1
- import { D as state, E as isGitHubCopilotEnabled, O as HTTPError, S as PATHS, a as getAnthropicApiKey, c as getConfig, d as getUpstreamTransportConfig, g as isResponsesApiWebSocketEnabled, h as isResponsesApiWebSearchEnabled, i as getAlphaSearchModel, j as forwardError, l as getMessageApiWebSearchModel, m as isMessagesApiEnabled, o as getClaudeAutoModel, p as isAlphaSearchCodexPriorityEnabled, s as getClaudeTokenMultiplier, u as getOpencodeModelContextWindow, w as GITHUB_COPILOT_PROVIDER, y as reloadConfig } from "./config-store-C6GAtKLz.js";
2
- import { C as isContextManagementEnabledForResponses, E as setModelMappings, S as isContextManagementEnabledForMessages, T as resolveMappedModel, _ as getModelMappings, b as getSmallModel, d as getOpencodeGoModelConfig, f as getOpencodeGoModelIds, g as getExtraPromptForModel, i as listEnabledProviders, l as getModelsDevModel, n as getRawProviderConfig, o as resolveEffectiveProviderType, p as getOpencodeGoModelRecords, s as resolveProviderConfigForModel, t as getProviderConfig, u as getModelsDevModelMaxOutputTokens, v as getModelResponsesApiCompactThreshold$1, w as isGpt56OrAbove, x as getSmallModelForProvider, y as getReasoningEffortForModel } from "./config-Cd0U5gXz.js";
3
- import { $ as resolveTraceId$1, C as isOpencodeOauthApp, E as prepareMessageProxyHeaders, G as XAI_API_BASE_URL, J as CODEX_API_BASE_URL, L as getXaiAccessToken, M as compactTextOnlyGuard, N as createAuthMiddleware, O as compactAutoContinuePromptStarts, P as getConfiguredAdminApiKeys, Q as requestContext, S as copilotWebSocketHeaders, T as prepareInteractionHeaders, U as readGitHubToken, W as readGitHubTokenFromEnv, X as forwardCodexResponses, Y as buildCodexRequestHeaders, Z as generateTraceId, _ as parseUserIdMetadata, at as createPooledWebSocketStream, b as copilotHeaders, ct as stripInternalRequestHeaders, d as generateRequestIdFromPayload, et as fetchUpstreamWithLifecycle, f as getRootSessionId, g as isResponsesStream, h as isNullish, it as getResponsesStreamTerminalDisposition, j as compactSystemPromptStarts, k as compactMessageSections, m as isAsyncIterable, n as invalidateCodexRuntime, nt as createResponsesSafeStream, ot as createWebSocketUrl, p as getUUID, rt as encodePoolKeyPart, s as setupCodexToken, tt as createResponsesHttpEventStream, u as stopCopilotRefreshLoop, v as getCopilotUsage, w as prepareForCompact, y as copilotBaseUrl } from "./token-kSGCOmTG.js";
1
+ import { D as state, E as isGitHubCopilotEnabled, O as HTTPError, S as PATHS, a as getAnthropicApiKey, c as getConfig, d as getUpstreamTransportConfig, g as isResponsesApiWebSocketEnabled, h as isResponsesApiWebSearchEnabled, i as getAlphaSearchModel, j as forwardError, l as getMessageApiWebSearchModel, m as isMessagesApiEnabled, o as getClaudeAutoModel, p as isAlphaSearchCodexPriorityEnabled, s as getClaudeTokenMultiplier, u as getOpencodeModelContextWindow, w as GITHUB_COPILOT_PROVIDER, y as reloadConfig } from "./config-store-CC5TNG7V.js";
2
+ import { A as resolveMappedModel, C as getModelResponsesApiCompactThreshold$1, D as isContextManagementEnabledForMessages, E as getSmallModelForProvider, O as isContextManagementEnabledForResponses, S as getModelMappings, T as getSmallModel, _ as getModelsDevModelMaxOutputTokens, d as isProviderModelVisible, f as resolveProviderModelsDevId, g as getModelsDevModel, h as getBuiltinProviderModelRecords, i as listEnabledProviders, j as setModelMappings, k as isGpt56OrAbove, l as getLocalProviderModelRecords, m as builtinProviderModelRegistry, n as getRawProviderConfig, o as resolveEffectiveProviderType, p as usesModelsDevModelCatalog, s as resolveProviderConfigForModel, t as getProviderConfig, u as getProviderModelConfig, v as getModelsDevModelPricing, w as getReasoningEffortForModel, x as getExtraPromptForModel } from "./config-BKA4Y1t8.js";
3
+ import { $ as resolveTraceId$1, C as isOpencodeOauthApp, E as prepareMessageProxyHeaders, G as XAI_API_BASE_URL, J as CODEX_API_BASE_URL, L as getXaiAccessToken, M as compactTextOnlyGuard, N as createAuthMiddleware, O as compactAutoContinuePromptStarts, P as getConfiguredAdminApiKeys, Q as requestContext, S as copilotWebSocketHeaders, T as prepareInteractionHeaders, U as readGitHubToken, W as readGitHubTokenFromEnv, X as forwardCodexResponses, Y as buildCodexRequestHeaders, Z as generateTraceId, _ as parseUserIdMetadata, at as createPooledWebSocketStream, b as copilotHeaders, ct as stripInternalRequestHeaders, d as generateRequestIdFromPayload, et as fetchUpstreamWithLifecycle, f as getRootSessionId, g as isResponsesStream, h as isNullish, it as getResponsesStreamTerminalDisposition, j as compactSystemPromptStarts, k as compactMessageSections, m as isAsyncIterable, n as invalidateCodexRuntime, nt as createResponsesSafeStream, ot as createWebSocketUrl, p as getUUID, rt as encodePoolKeyPart, s as setupCodexToken, tt as createResponsesHttpEventStream, u as stopCopilotRefreshLoop, v as getCopilotUsage, w as prepareForCompact, y as copilotBaseUrl } from "./token-BdwhXP3l.js";
4
4
  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-CcvaqM03.js";
5
- import { n as isProviderAgentModelVisible, t as getProviderAgentModels } from "./provider-management-DOfLC7WX.js";
6
- import { n as stopModelsRefreshLoop, t as setupCopilotRuntime } from "./copilot-runtime-Dg3ywZkl.js";
5
+ import { n as isProviderAgentModelVisible, t as getProviderAgentModels } from "./provider-management-CBrc2nDg.js";
6
+ import { n as stopModelsRefreshLoop, t as setupCopilotRuntime } from "./copilot-runtime-CW4zUahm.js";
7
7
  import consola from "consola";
8
8
  import { createHash, randomUUID } from "node:crypto";
9
9
  import fs, { createWriteStream, readFileSync, rmSync } from "node:fs";
@@ -469,441 +469,6 @@ var EventBus = class {
469
469
  }
470
470
  };
471
471
  //#endregion
472
- //#region src/lib/token-usage/peak-windows.ts
473
- const deepseekPeakWindows = [{
474
- endMinuteUtc: 240,
475
- startMinuteUtc: 60,
476
- weekdays: [
477
- 1,
478
- 2,
479
- 3,
480
- 4,
481
- 5
482
- ]
483
- }, {
484
- endMinuteUtc: 600,
485
- startMinuteUtc: 360,
486
- weekdays: [
487
- 1,
488
- 2,
489
- 3,
490
- 4,
491
- 5
492
- ]
493
- }];
494
- const dashscopePeakWindows = [{
495
- endMinuteUtc: 840,
496
- startMinuteUtc: 0
497
- }];
498
- //#endregion
499
- //#region src/lib/builtin-provider-models.ts
500
- const CODEX_LUNA_PRICING = { tiers: [{
501
- cacheCreationInput: .125,
502
- cachedInput: .01,
503
- input: .1,
504
- maxInputTokens: 272e3,
505
- output: .5
506
- }, {
507
- cacheCreationInput: .25,
508
- cachedInput: .02,
509
- input: .2,
510
- output: .75
511
- }] };
512
- const builtinProviderModelRegistry = new class BuiltinProviderModelRegistry {
513
- static providerDefaults = {
514
- codex: { supportPdf: true },
515
- xai: { supportPdf: true }
516
- };
517
- static catalog = {
518
- xai: { "grok-4.7": {
519
- contextWindow: 5e5,
520
- maxOutputTokens: 5e5,
521
- inputModalities: ["text", "image"],
522
- reasoningEfforts: [
523
- "low",
524
- "medium",
525
- "high",
526
- "xhigh"
527
- ],
528
- defaultReasoningEffort: "high",
529
- pricing: { tiers: [{
530
- cachedInput: .5,
531
- input: 2,
532
- output: 6,
533
- maxInputTokens: 2e5
534
- }, {
535
- cachedInput: 1,
536
- input: 4,
537
- output: 12
538
- }] }
539
- } },
540
- codex: {
541
- "codex-auto-review": { pricing: CODEX_LUNA_PRICING },
542
- "gpt-reserve": { pricing: CODEX_LUNA_PRICING },
543
- "gpt-5.5": { pricing: { tiers: [{
544
- cachedInput: .5,
545
- input: 5,
546
- maxInputTokens: 272e3,
547
- output: 30
548
- }, {
549
- cachedInput: 1,
550
- input: 10,
551
- output: 45
552
- }] } },
553
- "gpt-5.6-sol": { pricing: { tiers: [{
554
- cacheCreationInput: 5,
555
- cachedInput: .4,
556
- input: 4,
557
- maxInputTokens: 272e3,
558
- output: 20
559
- }, {
560
- cacheCreationInput: 10,
561
- cachedInput: .8,
562
- input: 8,
563
- output: 30
564
- }] } },
565
- "gpt-5.6-terra": { pricing: { tiers: [{
566
- cacheCreationInput: 2.5,
567
- cachedInput: .2,
568
- input: 2,
569
- maxInputTokens: 272e3,
570
- output: 12
571
- }, {
572
- cacheCreationInput: 5,
573
- cachedInput: .4,
574
- input: 4,
575
- output: 18
576
- }] } },
577
- "gpt-5.6-luna": { pricing: { tiers: [{
578
- cacheCreationInput: .25,
579
- cachedInput: .02,
580
- input: .2,
581
- maxInputTokens: 272e3,
582
- output: 1.2
583
- }, {
584
- cacheCreationInput: .5,
585
- cachedInput: .04,
586
- input: .4,
587
- output: 1.8
588
- }] } },
589
- "gpt-6-astra": { pricing: { tiers: [{
590
- cacheCreationInput: 12.5,
591
- cachedInput: 1,
592
- input: 10,
593
- maxInputTokens: 272e3,
594
- output: 50
595
- }, {
596
- cacheCreationInput: 25,
597
- cachedInput: 2,
598
- input: 20,
599
- output: 75
600
- }] } },
601
- "gpt-6-luna": { pricing: CODEX_LUNA_PRICING },
602
- "gpt-6-sol": { pricing: { tiers: [{
603
- cacheCreationInput: 2.5,
604
- cachedInput: .2,
605
- input: 2,
606
- maxInputTokens: 272e3,
607
- output: 10
608
- }, {
609
- cacheCreationInput: 5,
610
- cachedInput: .4,
611
- input: 4,
612
- output: 15
613
- }] } },
614
- "gpt-6.1-sol": { pricing: { tiers: [{
615
- cacheCreationInput: 2.5,
616
- cachedInput: .1,
617
- input: 2,
618
- maxInputTokens: 272e3,
619
- output: 10
620
- }, {
621
- cacheCreationInput: 5,
622
- cachedInput: .2,
623
- input: 4,
624
- output: 15
625
- }] } }
626
- },
627
- dashscope: {
628
- "glm-5.3": {
629
- contextWindow: 1e6,
630
- inputModalities: ["text"],
631
- maxOutputTokens: 64e3,
632
- pricing: {
633
- cachedInput: 2,
634
- input: 8,
635
- output: 28
636
- },
637
- reasoningEfforts: [
638
- "low",
639
- "high",
640
- "max"
641
- ]
642
- },
643
- "deepseek-v4.1-flash": {
644
- contextWindow: 1e6,
645
- defaultReasoningEffort: "high",
646
- inputModalities: ["text", "image"],
647
- maxOutputTokens: 393216,
648
- pricing: {
649
- cachedInput: .2,
650
- input: 2,
651
- offPeak: {
652
- cachedInput: .1,
653
- input: 1,
654
- output: 4
655
- },
656
- output: 8,
657
- peakWindows: dashscopePeakWindows
658
- },
659
- reasoningEfforts: [
660
- "low",
661
- "high",
662
- "max"
663
- ]
664
- },
665
- "qwen3.8-max": {
666
- contextWindow: 1e6,
667
- defaultReasoningEffort: "xhigh",
668
- inputModalities: ["text", "image"],
669
- maxOutputTokens: 64e3,
670
- pricing: {
671
- cachedInput: 1.5,
672
- cacheCreationInput: 15,
673
- explicitCachedInput: 1,
674
- input: 12,
675
- output: 36
676
- },
677
- reasoningEfforts: [
678
- "low",
679
- "medium",
680
- "xhigh"
681
- ]
682
- },
683
- "qwen3.8-max-0902": {
684
- contextWindow: 1e6,
685
- defaultReasoningEffort: "xhigh",
686
- inputModalities: ["text", "image"],
687
- maxOutputTokens: 131072,
688
- pricing: {
689
- cachedInput: 1.5,
690
- cacheCreationInput: 15,
691
- explicitCachedInput: 1,
692
- input: 12,
693
- output: 36
694
- },
695
- reasoningEfforts: [
696
- "low",
697
- "medium",
698
- "xhigh"
699
- ]
700
- },
701
- "qwen3.8-flash": {
702
- contextWindow: 1e6,
703
- defaultReasoningEffort: "xhigh",
704
- inputModalities: ["text", "image"],
705
- maxOutputTokens: 131072,
706
- pricing: {
707
- cachedInput: .1,
708
- cacheCreationInput: 1.25,
709
- explicitCachedInput: .1,
710
- input: .8,
711
- output: 2.7
712
- },
713
- reasoningEfforts: [
714
- "low",
715
- "medium",
716
- "xhigh"
717
- ]
718
- },
719
- "qwen3.7-plus": {
720
- contextWindow: 1e6,
721
- defaultReasoningEffort: "xhigh",
722
- inputModalities: ["text", "image"],
723
- maxOutputTokens: 64e3,
724
- pricing: { tiers: [{
725
- cachedInput: .4,
726
- cacheCreationInput: 2.5,
727
- explicitCachedInput: .2,
728
- input: 2,
729
- maxInputTokens: 256e3,
730
- output: 8
731
- }, {
732
- cachedInput: 1.2,
733
- cacheCreationInput: 7.5,
734
- explicitCachedInput: .6,
735
- input: 6,
736
- maxInputTokens: 1e6,
737
- output: 24
738
- }] },
739
- reasoningEfforts: [
740
- "low",
741
- "medium",
742
- "xhigh"
743
- ]
744
- },
745
- "kimi/kimi-k3": {
746
- contextWindow: 1048576,
747
- defaultReasoningEffort: "max",
748
- inputModalities: ["text", "image"],
749
- maxOutputTokens: 64e3,
750
- pricing: {
751
- cachedInput: 2,
752
- input: 20,
753
- output: 100
754
- },
755
- reasoningEfforts: ["max"]
756
- },
757
- "ZHIPU/GLM-5.3": {
758
- contextWindow: 1048576,
759
- inputModalities: ["text"],
760
- maxOutputTokens: 131072,
761
- pricing: {
762
- cachedInput: 2,
763
- input: 8,
764
- output: 28
765
- },
766
- reasoningEfforts: [
767
- "low",
768
- "high",
769
- "max"
770
- ]
771
- },
772
- "ZHIPU/GLM-5.3-Flash": {
773
- contextWindow: 1048576,
774
- inputModalities: ["text", "image"],
775
- maxOutputTokens: 131072,
776
- pricing: {
777
- cachedInput: .23,
778
- input: .8,
779
- output: 2.8
780
- },
781
- reasoningEfforts: [
782
- "low",
783
- "high",
784
- "max"
785
- ]
786
- },
787
- "ZHIPU/GLM-5.3-FlashX": {
788
- contextWindow: 1048576,
789
- inputModalities: ["text", "image"],
790
- maxOutputTokens: 131072,
791
- pricing: {
792
- cachedInput: .57,
793
- input: 2,
794
- output: 7
795
- },
796
- reasoningEfforts: [
797
- "low",
798
- "high",
799
- "max"
800
- ]
801
- }
802
- },
803
- deepseek: {
804
- "deepseek-flash": {
805
- contextWindow: 1e6,
806
- inputModalities: ["text", "image"],
807
- maxOutputTokens: 384e3,
808
- pricing: {
809
- cachedInput: .04,
810
- input: 2,
811
- offPeak: {
812
- cachedInput: .02,
813
- input: 1,
814
- output: 4
815
- },
816
- output: 8,
817
- peakWindows: deepseekPeakWindows
818
- },
819
- reasoningEfforts: [
820
- "low",
821
- "high",
822
- "max"
823
- ]
824
- },
825
- "deepseek-v4-pro": {
826
- contextWindow: 1e6,
827
- inputModalities: ["text"],
828
- maxOutputTokens: 64e3,
829
- pricing: {
830
- cachedInput: .3,
831
- input: 9,
832
- offPeak: {
833
- cachedInput: .15,
834
- input: 4.5,
835
- output: 13.5
836
- },
837
- output: 27,
838
- peakWindows: deepseekPeakWindows
839
- },
840
- reasoningEfforts: [
841
- "low",
842
- "high",
843
- "max"
844
- ]
845
- }
846
- },
847
- kimi: {
848
- k3: {
849
- contextWindow: 1048576,
850
- inputModalities: ["text", "image"],
851
- maxOutputTokens: 64e3,
852
- pricing: {
853
- cachedInput: .3,
854
- input: 3,
855
- output: 15
856
- }
857
- },
858
- "k3-256k": {
859
- contextWindow: 262144,
860
- inputModalities: ["text", "image"],
861
- maxOutputTokens: 64e3,
862
- pricing: {
863
- cachedInput: .3,
864
- input: 3,
865
- output: 15
866
- }
867
- }
868
- }
869
- };
870
- modelCatalog;
871
- constructor() {
872
- this.modelCatalog = BuiltinProviderModelRegistry.catalog;
873
- }
874
- getModelConfig(providerName, modelName) {
875
- const provider = this.normalizeKey(providerName);
876
- if (provider === "opencode-go") return getOpencodeGoModelConfig(modelName);
877
- const models = this.modelCatalog[provider];
878
- return models?.[modelName.trim()] ?? models?.[this.normalizeKey(modelName)];
879
- }
880
- getModelIds(providerName) {
881
- const provider = this.normalizeKey(providerName);
882
- if (provider === "opencode-go") return getOpencodeGoModelIds();
883
- return Object.keys(this.modelCatalog[provider] ?? {});
884
- }
885
- getProviderDefaults(providerName) {
886
- return BuiltinProviderModelRegistry.providerDefaults[this.normalizeKey(providerName)];
887
- }
888
- normalizeKey(value) {
889
- return value.trim().toLowerCase();
890
- }
891
- }();
892
- function getBuiltinProviderModelRecords(provider) {
893
- return builtinProviderModelRegistry.getModelIds(provider).map((id) => {
894
- const config = builtinProviderModelRegistry.getModelConfig(provider, id);
895
- return {
896
- id,
897
- name: id,
898
- object: "model",
899
- context_window: config?.contextWindow,
900
- max_output_tokens: config?.maxOutputTokens,
901
- input_modalities: config?.inputModalities,
902
- reasoning_efforts: config?.reasoningEfforts
903
- };
904
- });
905
- }
906
- //#endregion
907
472
  //#region src/lib/sqlite.ts
908
473
  const MINIMUM_NODE_SQLITE_VERSION = "22.13.0";
909
474
  const isBunRuntime = () => Boolean(globalThis.Bun);
@@ -1620,7 +1185,7 @@ function resolveTokenUsageCost(input) {
1620
1185
  const resolvedPricing = resolveProviderPricing(providerName, input.model, input.pricing);
1621
1186
  if (!resolvedPricing) return null;
1622
1187
  const pricing = resolvePricingTier(resolvedPricing.pricing, getInputTokenTotal(input), resolvePricingTime(input.at));
1623
- const currency = resolveProviderCurrency(providerName, input.pricingCurrency);
1188
+ const currency = resolvedPricing.currency ?? resolveProviderCurrency(providerName, input.pricingCurrency);
1624
1189
  if (!currency) return null;
1625
1190
  const inputPrice = normalizePrice(pricing.input);
1626
1191
  const outputPrice = normalizePrice(pricing.output);
@@ -1671,6 +1236,14 @@ function resolveProviderPricing(providerName, model, configuredPricing) {
1671
1236
  pricing: configuredPricing,
1672
1237
  source: "config"
1673
1238
  };
1239
+ if (usesModelsDevModelCatalog(providerName)) {
1240
+ const pricing = getModelsDevModelPricing(resolveProviderModelsDevId(providerName), model);
1241
+ if (pricing) return {
1242
+ pricing,
1243
+ source: "models.dev",
1244
+ currency: "USD"
1245
+ };
1246
+ }
1674
1247
  const pricingModel = providerName.toLowerCase() === "codex" && model.trim().toLowerCase() === "gpt-5.6" ? "gpt-5.6-sol" : model;
1675
1248
  const builtinPricing = builtinProviderModelRegistry.getModelConfig(providerName, pricingModel)?.pricing;
1676
1249
  if (!builtinPricing) return null;
@@ -3274,7 +2847,7 @@ const applyMissingExtraBody = (payload, options) => {
3274
2847
  const normalizeProviderResponsesReasoningEffort = (payload, providerConfig) => {
3275
2848
  if (!payload.reasoning || typeof payload.reasoning.effort !== "string") return;
3276
2849
  const modelConfig = providerConfig.models?.[payload.model];
3277
- const builtinModelConfig = builtinProviderModelRegistry.getModelConfig(providerConfig.name, payload.model);
2850
+ const builtinModelConfig = getProviderModelConfig(providerConfig.name, payload.model, providerConfig);
3278
2851
  const configuredEfforts = modelConfig?.reasoningEfforts;
3279
2852
  const supportedEfforts = configuredEfforts && configuredEfforts.length > 0 ? configuredEfforts : builtinModelConfig?.reasoningEfforts;
3280
2853
  const resolvedEffort = resolveSupportedReasoningEffort(payload.reasoning.effort, supportedEfforts);
@@ -4098,7 +3671,7 @@ function resolveModelPdfSupport(provider, options) {
4098
3671
  function getProviderModelPdfSupport(modelId, provider, selectedModel) {
4099
3672
  const rawId = selectedModel?.id ?? modelId;
4100
3673
  const modelConfig = provider.models?.[rawId] ?? provider.models?.[modelId];
4101
- const catalogProvider = provider.modelsDevProviderId || provider.name;
3674
+ const catalogProvider = resolveProviderModelsDevId(provider.name, provider);
4102
3675
  const catalog = getModelsDevModel(catalogProvider, rawId) ?? getModelsDevModel(catalogProvider, modelId);
4103
3676
  const builtin = builtinProviderModelRegistry.getModelConfig(provider.name, rawId);
4104
3677
  return resolveModelPdfSupport(provider.name, {
@@ -6907,8 +6480,8 @@ function translateResponsesToMessages(payload, options) {
6907
6480
  function resolveDefaultMaxOutputTokens(model) {
6908
6481
  const alias = parseProviderModelAlias(model);
6909
6482
  const providerConfig = alias ? getRawProviderConfig(alias.provider) : null;
6910
- const catalogMaxOutputTokens = alias ? getModelsDevModelMaxOutputTokens(providerConfig?.modelsDevProviderId || alias.provider, alias.model) : void 0;
6911
- const builtinModelConfig = alias ? builtinProviderModelRegistry.getModelConfig(alias.provider, alias.model) : void 0;
6483
+ const catalogMaxOutputTokens = alias ? getModelsDevModelMaxOutputTokens(resolveProviderModelsDevId(alias.provider, providerConfig), alias.model) : void 0;
6484
+ const builtinModelConfig = alias ? getProviderModelConfig(alias.provider, alias.model, providerConfig) : void 0;
6912
6485
  return (alias && (providerConfig || builtinModelConfig || catalogMaxOutputTokens) ? [
6913
6486
  providerConfig?.models?.[alias.model]?.maxOutputTokens,
6914
6487
  catalogMaxOutputTokens,
@@ -7615,6 +7188,22 @@ const REDACTED_IMAGE_PLACEHOLDER_DATA_URL = "data:image/png;base64," + [
7615
7188
  "OAuj2SEAAAAASUVORK5CYII="
7616
7189
  ].join("");
7617
7190
  const COPILOT_UNSUPPORTED_INPUT_ITEM_FIELDS = ["internal_chat_message_metadata_passthrough"];
7191
+ const isInputAgentMessage = (item) => item.type === "agent_message";
7192
+ const normalizeGuardianAgentMessages = (payload) => {
7193
+ if (!payload.prompt_cache_key?.startsWith("guardia") || payload.text?.format?.type !== "json_schema" || !Array.isArray(payload.input)) return 0;
7194
+ let normalizedCount = 0;
7195
+ payload.input = payload.input.map((item) => {
7196
+ if (!isInputAgentMessage(item)) return item;
7197
+ const agentMessage = item;
7198
+ normalizedCount += 1;
7199
+ return {
7200
+ type: "message",
7201
+ role: "user",
7202
+ content: agentMessage.content.filter((part) => part.type !== "encrypted_content")
7203
+ };
7204
+ });
7205
+ return normalizedCount;
7206
+ };
7618
7207
  const sanitizeUnsupportedInputFields = (payload) => {
7619
7208
  if (!Array.isArray(payload.input)) return 0;
7620
7209
  let removedFieldCount = 0;
@@ -8580,7 +8169,7 @@ const applyMiMoThinking = (payload, source) => {
8580
8169
  if (shouldEnableThinking) payload.thinking = { type: "enabled" };
8581
8170
  };
8582
8171
  const normalizeOpenAICompatibleReasoningContent = (payload, options) => {
8583
- const reasoningField = options.modelConfig?.reasoningField ?? builtinProviderModelRegistry.getModelConfig(options.providerConfig.name, payload.model)?.reasoningField ?? "reasoning_content";
8172
+ const reasoningField = options.modelConfig?.reasoningField ?? getProviderModelConfig(options.providerConfig.name, payload.model, options.providerConfig)?.reasoningField ?? "reasoning_content";
8584
8173
  for (const message of payload.messages) {
8585
8174
  if (message.role !== "assistant") continue;
8586
8175
  const reasoningText = message.reasoning_text ?? message.reasoning_content ?? message.reasoning;
@@ -8920,7 +8509,9 @@ const allowedAnthropicBetas = /* @__PURE__ */ new Set([
8920
8509
  INTERLEAVED_THINKING_BETA,
8921
8510
  "context-management-2025-06-27",
8922
8511
  "advanced-tool-use-2025-11-20",
8923
- "extended-cache-ttl-2025-04-11"
8512
+ "extended-cache-ttl-2025-04-11",
8513
+ "mid-conversation-output-config-2026-07-01",
8514
+ "per-turn-control-2026-07-01"
8924
8515
  ]);
8925
8516
  const buildAnthropicBetaHeader = (anthropicBetaHeader, thinking, _model) => {
8926
8517
  const isAdaptiveThinking = thinking?.type === "adaptive";
@@ -9452,11 +9043,27 @@ const EPOCH_ISO = (/* @__PURE__ */ new Date(0)).toISOString();
9452
9043
  function isRecord(value) {
9453
9044
  return typeof value === "object" && value !== null && !Array.isArray(value);
9454
9045
  }
9046
+ function firstPositiveInteger(...values) {
9047
+ for (const value of values) if (typeof value === "number" && Number.isFinite(value) && value >= 1) return Math.floor(value);
9048
+ }
9049
+ function normalizeModelCapabilities(model) {
9050
+ if (!isRecord(model.capabilities)) return model;
9051
+ const limits = getRecordField(model.capabilities, "limits");
9052
+ const supports = getRecordField(model.capabilities, "supports");
9053
+ return {
9054
+ context_window: firstPositiveInteger(limits?.max_context_window_tokens, limits?.max_prompt_tokens),
9055
+ max_output_tokens: limits?.max_output_tokens,
9056
+ input_limit: limits?.max_prompt_tokens,
9057
+ input_modalities: typeof supports?.vision === "boolean" ? ["text", ...supports.vision ? ["image"] : []] : void 0,
9058
+ reasoning_efforts: supports?.reasoning_effort,
9059
+ ...model
9060
+ };
9061
+ }
9455
9062
  function normalizeCopilotModel(model) {
9456
9063
  const clientId = toClientModelId(model.id);
9457
9064
  return {
9458
9065
  claude_model_id: `${clientId}[1m]`,
9459
- ...withModelDisplayName(model, GITHUB_COPILOT_PROVIDER),
9066
+ ...withModelDisplayName(normalizeModelCapabilities(model), GITHUB_COPILOT_PROVIDER),
9460
9067
  id: clientId,
9461
9068
  object: "model",
9462
9069
  type: "model",
@@ -9473,15 +9080,13 @@ function getRecordField(model, field) {
9473
9080
  const value = model?.[field];
9474
9081
  return isRecord(value) ? value : void 0;
9475
9082
  }
9476
- function getFirstPositiveNumber(model, fields) {
9477
- if (!model) return void 0;
9478
- for (const field of fields) {
9479
- const value = model[field];
9480
- if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
9481
- }
9083
+ function getStringList(value) {
9084
+ if (!Array.isArray(value)) return void 0;
9085
+ const strings = [...new Set(value.filter((item) => typeof item === "string"))];
9086
+ return strings.length > 0 ? strings : void 0;
9482
9087
  }
9483
9088
  function getFallbackProviderModelRecords(provider, reason, details = {}) {
9484
- const fallbackModels = getBuiltinProviderModelRecords(provider);
9089
+ const fallbackModels = getLocalProviderModelRecords(provider, getRawProviderConfig(provider)) ?? getBuiltinProviderModelRecords(provider);
9485
9090
  logger$9.warn(`models.provider.fallback_${reason}`, {
9486
9091
  provider,
9487
9092
  ...details,
@@ -9489,10 +9094,10 @@ function getFallbackProviderModelRecords(provider, reason, details = {}) {
9489
9094
  });
9490
9095
  return fallbackModels;
9491
9096
  }
9492
- function normalizeProviderModel(provider, model) {
9097
+ function normalizeProviderModel(provider, model, config) {
9493
9098
  if (!isRecord(model)) return null;
9494
9099
  const rawId = getStringField(model, "id");
9495
- if (!rawId) return null;
9100
+ if (!rawId || !isProviderModelVisible(provider, rawId, config)) return null;
9496
9101
  const id = `${provider}/${rawId}`;
9497
9102
  const ownedBy = getStringField(model, "owned_by") ?? getStringField(model, "vendor") ?? provider;
9498
9103
  return {
@@ -9505,18 +9110,18 @@ function normalizeProviderModel(provider, model) {
9505
9110
  owned_by: ownedBy
9506
9111
  };
9507
9112
  }
9508
- function normalizeProviderModels(provider, models) {
9509
- return models.map((model) => normalizeProviderModel(provider, model)).filter((model) => model !== null);
9113
+ function normalizeProviderModels(provider, models, config) {
9114
+ return models.map((model) => normalizeProviderModel(provider, model, config)).filter((model) => model !== null);
9510
9115
  }
9511
9116
  async function getProviderModelRecords(providerConfig, requestHeaders) {
9512
- if (providerConfig.name === "opencode-go") return getOpencodeGoModelRecords();
9513
- if (providerConfig.name === "xai" && providerConfig.authType === "oauth2") return getBuiltinProviderModelRecords("xai");
9117
+ const localModels = getLocalProviderModelRecords(providerConfig.name, providerConfig);
9118
+ if (localModels !== void 0) return localModels;
9514
9119
  try {
9515
9120
  const response = await forwardProviderModels(providerConfig, requestHeaders);
9516
9121
  if (!response.ok) return getFallbackProviderModelRecords(providerConfig.name, "non_ok", { statusCode: response.status });
9517
9122
  const body = await response.json();
9518
9123
  if (!isRecord(body) || !Array.isArray(body.data)) return getFallbackProviderModelRecords(providerConfig.name, "invalid_body");
9519
- return body.data.filter(isRecord);
9124
+ return body.data.filter(isRecord).map(normalizeModelCapabilities);
9520
9125
  } catch (error) {
9521
9126
  return getFallbackProviderModelRecords(providerConfig.name, "error", { error });
9522
9127
  }
@@ -9544,8 +9149,8 @@ async function getProviderModels(provider, requestHeaders, selectModels) {
9544
9149
  try {
9545
9150
  const providerConfig = await resolveProviderConfig(provider);
9546
9151
  if (!providerConfig) return [];
9547
- const models = providerConfig.name === "codex" ? getModels().data : await getProviderModelRecords(providerConfig, requestHeaders);
9548
- return normalizeProviderModels(providerConfig.name, selectModels?.(providerConfig, models) ?? models);
9152
+ const models = providerConfig.name === "codex" ? getModels().data.map(normalizeModelCapabilities) : await getProviderModelRecords(providerConfig, requestHeaders);
9153
+ return normalizeProviderModels(providerConfig.name, selectModels?.(providerConfig, models) ?? models, providerConfig);
9549
9154
  } catch (error) {
9550
9155
  if (provider === "codex") {
9551
9156
  logger$9.warn("models.provider.skip_error", {
@@ -9555,7 +9160,8 @@ async function getProviderModels(provider, requestHeaders, selectModels) {
9555
9160
  return [];
9556
9161
  }
9557
9162
  const fallbackModels = getFallbackProviderModelRecords(provider, "error", { error });
9558
- return normalizeProviderModels(provider, selectModels?.(getRawProviderConfig(provider), fallbackModels) ?? fallbackModels);
9163
+ const providerConfig = getRawProviderConfig(provider);
9164
+ return normalizeProviderModels(provider, selectModels?.(providerConfig, fallbackModels) ?? fallbackModels, providerConfig);
9559
9165
  }
9560
9166
  }
9561
9167
  async function getAggregatedModels(requestHeaders, selectors = {}) {
@@ -9663,6 +9269,53 @@ function serializeCodexModelCatalog(response, options) {
9663
9269
  });
9664
9270
  }
9665
9271
  //#endregion
9272
+ //#region src/routes/models/model-metadata.ts
9273
+ function normalizeMetadata(fields) {
9274
+ const contextWindow = firstPositiveInteger(fields?.contextWindow);
9275
+ const maxOutputTokens = firstPositiveInteger(fields?.maxOutputTokens);
9276
+ const inputModalities = getStringList(fields?.inputModalities);
9277
+ const reasoningEfforts = getStringList(fields?.reasoningEfforts);
9278
+ return {
9279
+ ...contextWindow && { contextWindow },
9280
+ ...maxOutputTokens && { maxOutputTokens },
9281
+ ...inputModalities && { inputModalities },
9282
+ ...reasoningEfforts && { reasoningEfforts },
9283
+ ...fields?.defaultReasoningEffort && { defaultReasoningEffort: fields.defaultReasoningEffort }
9284
+ };
9285
+ }
9286
+ function getModelMetadata(provider, modelId, model, config) {
9287
+ const clientId = getStringField(model, "id") ?? modelId;
9288
+ const modelConfig = config?.models?.[modelId] ?? config?.models?.[clientId];
9289
+ const catalogProvider = resolveProviderModelsDevId(provider, config);
9290
+ const catalog = getModelsDevModel(catalogProvider, modelId) ?? getModelsDevModel(catalogProvider, clientId);
9291
+ const defaults = getProviderModelConfig(provider, modelId, config) ?? getProviderModelConfig(provider, clientId, config);
9292
+ const capabilities = getRecordField(model, "capabilities");
9293
+ const supports = getRecordField(capabilities, "supports");
9294
+ const limits = getRecordField(capabilities, "limits");
9295
+ const metadata = {
9296
+ ...defaults,
9297
+ ...normalizeMetadata({
9298
+ contextWindow: model.context_window,
9299
+ maxOutputTokens: model.max_output_tokens,
9300
+ inputModalities: model.input_modalities,
9301
+ reasoningEfforts: model.reasoning_efforts
9302
+ }),
9303
+ ...normalizeMetadata(modelConfig)
9304
+ };
9305
+ return {
9306
+ modelConfig,
9307
+ catalog,
9308
+ defaults,
9309
+ capabilities,
9310
+ supports,
9311
+ limits,
9312
+ ...metadata,
9313
+ inputLimit: firstPositiveInteger(model.input_limit, catalog?.limit?.input),
9314
+ inputModalities: metadata.inputModalities ?? ["text"],
9315
+ reasoningEfforts: metadata.reasoningEfforts ?? []
9316
+ };
9317
+ }
9318
+ //#endregion
9666
9319
  //#region src/routes/models/codex-model-candidates.ts
9667
9320
  const logger$8 = createHandlerLogger("models-handler");
9668
9321
  const RESPONSES_ENDPOINTS = /* @__PURE__ */ new Set(["/responses", "ws:/responses"]);
@@ -9724,14 +9377,14 @@ async function getProviderCodexCandidates(provider, requestHeaders) {
9724
9377
  try {
9725
9378
  const providerConfig = await resolveProviderConfig(provider);
9726
9379
  if (!providerConfig || providerConfig.name === "codex") return [];
9727
- const remoteById = getModelsById(await getProviderModelRecords(providerConfig, requestHeaders));
9728
- const modelIds = /* @__PURE__ */ new Set([...remoteById.keys(), ...providerConfig.name === "xai" && providerConfig.authType === "oauth2" ? [] : Object.keys(providerConfig.models ?? {})]);
9380
+ const modelsById = getModelsById(await getProviderModelRecords(providerConfig, requestHeaders));
9381
+ const modelIds = /* @__PURE__ */ new Set([...modelsById.keys(), ...Object.keys(providerConfig.models ?? {})]);
9729
9382
  const candidates = [];
9730
9383
  for (const modelId of modelIds) {
9384
+ if (!isProviderModelVisible(provider, modelId, providerConfig)) continue;
9731
9385
  const effectiveType = resolveEffectiveProviderType(providerConfig, modelId);
9732
9386
  if (!isMessagesFallbackProviderType(effectiveType) && effectiveType !== "openai-responses") continue;
9733
- const modelConfig = providerConfig.models?.[modelId];
9734
- candidates.push(createProviderCodexCandidate(providerConfig, modelId, remoteById.get(modelId), modelConfig, effectiveType));
9387
+ candidates.push(createProviderCodexCandidate(providerConfig, modelId, modelsById.get(modelId), effectiveType));
9735
9388
  }
9736
9389
  return candidates;
9737
9390
  } catch (error) {
@@ -9750,15 +9403,9 @@ function describeProviderAdapter(type) {
9750
9403
  if (type === "openai-responses") return "Messages-to-Responses";
9751
9404
  return "Messages-to-Chat";
9752
9405
  }
9753
- function createProviderCodexCandidate(providerConfig, modelId, remoteModel, modelConfig, effectiveType) {
9754
- const builtinModelConfig = builtinProviderModelRegistry.getModelConfig(providerConfig.name, modelId);
9755
- const configuredReasoningEfforts = normalizeReasoningEfforts(modelConfig?.reasoningEfforts);
9756
- const remoteReasoningEfforts = normalizeRemoteReasoningEfforts(remoteModel);
9757
- const builtinReasoningEfforts = normalizeReasoningEfforts(builtinModelConfig?.reasoningEfforts);
9758
- const reasoningEfforts = configuredReasoningEfforts.length > 0 ? configuredReasoningEfforts : remoteReasoningEfforts.length > 0 ? remoteReasoningEfforts : builtinReasoningEfforts;
9759
- const configuredModalities = normalizeInputModalities(modelConfig?.inputModalities);
9760
- const remoteModalities = normalizeInputModalities(remoteModel?.input_modalities ?? remoteModel?.modalities ?? getRecordField(remoteModel, "architecture")?.input_modalities);
9761
- const builtinModalities = normalizeInputModalities(builtinModelConfig?.inputModalities);
9406
+ function createProviderCodexCandidate(providerConfig, modelId, remoteModel, effectiveType) {
9407
+ const metadata = getModelMetadata(providerConfig.name, modelId, remoteModel ?? {}, providerConfig);
9408
+ const reasoningEfforts = normalizeReasoningEfforts(metadata.reasoningEfforts);
9762
9409
  const displayName = getStringField(remoteModel ?? {}, "display_name") ?? getStringField(remoteModel ?? {}, "name") ?? modelId;
9763
9410
  const adapterName = describeProviderAdapter(effectiveType);
9764
9411
  const requiresCatalogMatch = effectiveType === "openai-responses" && modelId.startsWith("gpt");
@@ -9769,41 +9416,20 @@ function createProviderCodexCandidate(providerConfig, modelId, remoteModel, mode
9769
9416
  providerName: providerConfig.name,
9770
9417
  displayName: `${displayName} (${providerConfig.name})`,
9771
9418
  description: `${displayName} through the ${providerConfig.name} ${adapterName} adapter.`,
9772
- contextWindow: positiveNumber(modelConfig?.contextWindow ?? getFirstPositiveNumber(remoteModel, [
9773
- "context_window",
9774
- "context_length",
9775
- "max_context_length",
9776
- "max_model_len"
9777
- ]) ?? builtinModelConfig?.contextWindow, 256e3),
9778
- maxOutputTokens: positiveNumber(modelConfig?.maxOutputTokens ?? getFirstPositiveNumber(remoteModel, ["max_output_tokens"]) ?? getModelsDevModelMaxOutputTokens(providerConfig.modelsDevProviderId || providerConfig.name, modelId) ?? builtinModelConfig?.maxOutputTokens, 32e3),
9779
- inputModalities: resolveInputModalities(providerConfig.name, configuredModalities, remoteModalities, builtinModalities),
9419
+ contextWindow: metadata.contextWindow ?? 256e3,
9420
+ maxOutputTokens: metadata.maxOutputTokens ?? 32e3,
9421
+ inputModalities: normalizeInputModalities(metadata.inputModalities),
9780
9422
  reasoningEfforts,
9781
- defaultReasoningEffort: selectDefaultReasoningEffort(reasoningEfforts, modelConfig?.defaultReasoningEffort ?? builtinModelConfig?.defaultReasoningEffort)
9423
+ defaultReasoningEffort: selectDefaultReasoningEffort(reasoningEfforts, metadata.defaultReasoningEffort)
9782
9424
  };
9783
9425
  }
9784
- function normalizeRemoteReasoningEfforts(model) {
9785
- if (!model) return [];
9786
- const value = model.reasoning_efforts ?? model.supported_reasoning_levels;
9787
- if (!Array.isArray(value)) return [];
9788
- return normalizeReasoningEfforts(value.map((entry) => isRecord(entry) && typeof entry.effort === "string" ? entry.effort : entry));
9789
- }
9790
9426
  function normalizeReasoningEfforts(value) {
9791
9427
  if (!Array.isArray(value)) return [];
9792
9428
  return [...new Set(value.filter((effort) => typeof effort === "string" && CODEX_REASONING_EFFORTS.has(effort)))];
9793
9429
  }
9794
9430
  function normalizeInputModalities(value) {
9795
- if (!Array.isArray(value)) return [];
9796
- return [...new Set(value.filter((modality) => modality === "text" || modality === "image"))];
9797
- }
9798
- function fallbackModalities(remoteModalities, builtinModalities) {
9799
- if (remoteModalities.length > 0) return remoteModalities;
9800
- return builtinModalities.length > 0 ? builtinModalities : ["text"];
9801
- }
9802
- function resolveInputModalities(providerName, configuredModalities, remoteModalities, builtinModalities) {
9803
- if (configuredModalities.length > 0) return configuredModalities;
9804
- const modalities = fallbackModalities(remoteModalities, builtinModalities);
9805
- if (providerName === "kimi") return [.../* @__PURE__ */ new Set([...modalities, "image"])];
9806
- return modalities;
9431
+ const modalities = [...new Set(value.filter((modality) => modality === "text" || modality === "image"))];
9432
+ return modalities.length > 0 ? modalities : ["text"];
9807
9433
  }
9808
9434
  function selectDefaultReasoningEffort(efforts, configured) {
9809
9435
  if (configured && efforts.includes(configured)) return configured;
@@ -11480,15 +11106,12 @@ function createCodexCatalogResponse(c, response, explicitSlugs, fallback) {
11480
11106
  });
11481
11107
  }
11482
11108
  function createCatalogAlias(model, slug, providerName) {
11483
- const alias = {
11484
- ...model,
11485
- slug
11486
- };
11487
- const prefix = providerName?.trim();
11488
- if (!prefix || typeof alias.display_name !== "string" || alias.display_name.startsWith(`${prefix} `)) return alias;
11109
+ const provider = providerName?.trim();
11110
+ const shouldSuffix = provider && typeof model.display_name === "string" && !model.display_name.endsWith(` (${provider})`);
11489
11111
  return {
11490
- ...alias,
11491
- display_name: `${prefix} ${alias.display_name}`
11112
+ ...model,
11113
+ slug,
11114
+ ...shouldSuffix && { display_name: `${model.display_name} (${provider})` }
11492
11115
  };
11493
11116
  }
11494
11117
  function createSyntheticCodexModel(candidate, template, priority) {
@@ -11643,15 +11266,6 @@ function mapConfiguredCost(pricing, rate) {
11643
11266
  size: (tiers[index - 1].maxInputTokens ?? 0) + 1
11644
11267
  } : void 0));
11645
11268
  }
11646
- function positiveInteger(...values) {
11647
- const value = values.find((value) => typeof value === "number" && Number.isFinite(value) && value >= 1);
11648
- return Math.floor(value ?? 0);
11649
- }
11650
- function stringList(value) {
11651
- if (!Array.isArray(value)) return void 0;
11652
- const strings = [...new Set(value.filter((item) => typeof item === "string"))];
11653
- return strings.length > 0 ? strings : void 0;
11654
- }
11655
11269
  const RESPONSES_EFFORTS = /* @__PURE__ */ new Set([
11656
11270
  "none",
11657
11271
  "minimal",
@@ -11665,50 +11279,28 @@ function normalizeEffortValues(values) {
11665
11279
  const efforts = (values ?? []).filter((value) => RESPONSES_EFFORTS.has(value));
11666
11280
  return [...new Set(efforts)];
11667
11281
  }
11668
- function catalogEffortValues(catalog) {
11669
- const options = catalog?.reasoning_options;
11670
- if (!Array.isArray(options)) return void 0;
11671
- const values = [];
11672
- for (const option of options) {
11673
- if (!isRecord(option) || option.type !== "effort") continue;
11674
- const optionValues = option.values;
11675
- if (!Array.isArray(optionValues)) continue;
11676
- for (const value of optionValues) if (typeof value === "string") values.push(value);
11677
- }
11678
- return stringList(values);
11679
- }
11680
11282
  function toOpencodeModel(model, contextWindow) {
11681
11283
  const separator = model.id.indexOf("/");
11682
11284
  const provider = separator < 0 ? GITHUB_COPILOT_PROVIDER : model.id.slice(0, separator);
11683
11285
  const rawId = separator < 0 ? findEndpointModel(model.id)?.id ?? model.id : model.id.slice(separator + 1);
11684
11286
  const config = getRawProviderConfig(provider);
11685
- const modelConfig = config?.models?.[rawId] ?? config?.models?.[model.id];
11686
- const builtin = builtinProviderModelRegistry.getModelConfig(provider, rawId);
11687
- const catalogProvider = config?.modelsDevProviderId || provider;
11688
- const catalog = getModelsDevModel(catalogProvider, rawId) ?? getModelsDevModel(catalogProvider, model.id);
11689
- const capabilities = getRecordField(model, "capabilities");
11690
- const supports = getRecordField(capabilities, "supports");
11691
- const limits = getRecordField(capabilities, "limits");
11692
- const context = positiveInteger(modelConfig?.contextWindow, getFirstPositiveNumber(limits, ["max_context_window_tokens", "max_prompt_tokens"]), getFirstPositiveNumber(model, [
11693
- "context_window",
11694
- "context_length",
11695
- "max_context_length",
11696
- "max_model_len"
11697
- ]), catalog?.limit?.context, builtin?.contextWindow, 2e5);
11698
- const inputLimit = positiveInteger(getFirstPositiveNumber(limits, ["max_prompt_tokens"]), catalog?.limit?.input);
11699
- const supportedMediaTypes = stringList(getRecordField(limits, "vision")?.supported_media_types);
11287
+ const metadata = getModelMetadata(provider, rawId, model, config);
11288
+ const { modelConfig, defaults, catalog, capabilities, supports, limits } = metadata;
11289
+ const context = metadata.contextWindow ?? 256e3;
11290
+ const inputLimit = metadata.inputLimit ?? 0;
11291
+ const supportedMediaTypes = getStringList(getRecordField(limits, "vision")?.supported_media_types);
11700
11292
  const supportPdf = resolveModelPdfSupport(provider, {
11701
11293
  supportPdf: modelConfig?.supportPdf,
11702
11294
  supportedMediaTypes,
11703
11295
  catalogInputModalities: catalog?.modalities?.input,
11704
- builtinSupportPdf: builtin?.supportPdf ?? builtinProviderModelRegistry.getProviderDefaults(provider)?.supportPdf
11296
+ builtinSupportPdf: defaults?.supportPdf ?? builtinProviderModelRegistry.getProviderDefaults(provider)?.supportPdf
11705
11297
  });
11706
- const input = [...stringList(modelConfig?.inputModalities) ?? stringList(model.input_modalities ?? getRecordField(model, "modalities")?.input ?? model.modalities ?? getRecordField(model, "architecture")?.input_modalities) ?? (typeof supports?.vision === "boolean" ? ["text", ...supports.vision ? ["image"] : []] : void 0) ?? catalog?.modalities?.input ?? builtin?.inputModalities ?? ["text"]].filter((modality) => modality !== "pdf" || supportPdf);
11298
+ const input = metadata.inputModalities.filter((modality) => modality !== "pdf" || supportPdf);
11707
11299
  if (supportPdf && !input.includes("pdf")) input.push("pdf");
11708
- const efforts = normalizeEffortValues(stringList(modelConfig?.reasoningEfforts ?? model.reasoning_efforts ?? supports?.reasoning_effort) ?? catalogEffortValues(catalog) ?? builtin?.reasoningEfforts);
11300
+ const efforts = normalizeEffortValues(metadata.reasoningEfforts);
11709
11301
  const configuredRate = resolveUsdRate(resolveProviderCurrency(provider, config?.pricingCurrency));
11710
11302
  const builtinRate = resolveUsdRate(resolveProviderCurrency(provider, void 0));
11711
- const cost = modelConfig?.pricing && configuredRate !== void 0 ? mapConfiguredCost(modelConfig.pricing, configuredRate) : catalog?.cost ? mapCatalogCost(catalog.cost) : builtin?.pricing && builtinRate !== void 0 ? mapConfiguredCost(builtin.pricing, builtinRate) : [];
11303
+ const cost = modelConfig?.pricing && configuredRate !== void 0 ? mapConfiguredCost(modelConfig.pricing, configuredRate) : catalog?.cost ? mapCatalogCost(catalog.cost) : defaults?.pricing && builtinRate !== void 0 ? mapConfiguredCost(defaults.pricing, builtinRate) : [];
11712
11304
  const released = Date.parse(catalog?.release_date ?? "");
11713
11305
  return {
11714
11306
  id: model.id,
@@ -11733,7 +11325,7 @@ function toOpencodeModel(model, contextWindow) {
11733
11325
  limit: {
11734
11326
  context: Math.min(context, contextWindow),
11735
11327
  ...inputLimit > 0 && { input: Math.min(inputLimit, context, contextWindow) },
11736
- output: Math.min(context, positiveInteger(modelConfig?.maxOutputTokens, getFirstPositiveNumber(limits, ["max_output_tokens"]), getFirstPositiveNumber(model, ["max_output_tokens"]), catalog?.limit?.output, builtin?.maxOutputTokens, 32e3))
11328
+ output: Math.min(context, metadata.maxOutputTokens ?? 32e3)
11737
11329
  }
11738
11330
  };
11739
11331
  }
@@ -11861,23 +11453,18 @@ providerModelRoutes.get("/", async (c) => {
11861
11453
  has_more: false
11862
11454
  });
11863
11455
  }
11864
- if (providerConfig.name === "opencode-go") {
11865
- const models = getOpencodeGoModelRecords();
11866
- if (models.length === 0) return c.json({ error: {
11867
- message: "OpenCode Go model catalog is unavailable",
11456
+ const localModels = getLocalProviderModelRecords(providerConfig.name, providerConfig);
11457
+ if (localModels !== void 0) {
11458
+ if (localModels.length === 0) return c.json({ error: {
11459
+ message: `${providerConfig.name} model catalog is unavailable`,
11868
11460
  type: "service_unavailable"
11869
11461
  } }, 503);
11870
11462
  return c.json({
11871
11463
  object: "list",
11872
- data: models.map((model) => withModelDisplayName(model, providerConfig.name)),
11464
+ data: localModels.map((model) => withModelDisplayName(model, providerConfig.name)),
11873
11465
  has_more: false
11874
11466
  });
11875
11467
  }
11876
- if (providerConfig.name === "xai" && providerConfig.authType === "oauth2") return c.json({
11877
- object: "list",
11878
- data: getBuiltinProviderModelRecords("xai").map((model) => withModelDisplayName(model, providerConfig.name)),
11879
- has_more: false
11880
- });
11881
11468
  const upstreamResponse = await forwardProviderModels(providerConfig, c.req.raw.headers);
11882
11469
  logger$4.debug("provider.models.response", {
11883
11470
  provider,
@@ -13135,6 +12722,8 @@ const handleResponses = async (c) => {
13135
12722
  fallbackSessionId,
13136
12723
  model: payload.model
13137
12724
  });
12725
+ const normalizedAgentMessageCount = normalizeGuardianAgentMessages(payload);
12726
+ if (normalizedAgentMessageCount > 0) logger$1.debug(`Translated ${normalizedAgentMessageCount} Guardian agent message(s) to user messages before forwarding to Copilot Responses`);
13138
12727
  const sanitizedUnsupportedFieldCount = sanitizeUnsupportedInputFields(payload);
13139
12728
  if (sanitizedUnsupportedFieldCount > 0) logger$1.debug(`Removed ${sanitizedUnsupportedFieldCount} unsupported input field(s) before forwarding to Copilot Responses`);
13140
12729
  const normalizedImageDetailCount = normalizeInputImageDetails(payload);
@@ -13411,4 +13000,4 @@ createServer();
13411
13000
  //#endregion
13412
13001
  export { createServer };
13413
13002
 
13414
- //# sourceMappingURL=server-Dvvc9z2P.js.map
13003
+ //# sourceMappingURL=server-DqfE4x5m.js.map