@linxiraos/pi-catalog 1.0.0 → 1.0.2

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 (86) hide show
  1. package/CHANGELOG.md +88 -6
  2. package/package.json +98 -99
  3. package/src/build.ts +3 -3
  4. package/src/compat/openai.ts +0 -6
  5. package/src/discovery/antigravity.ts +5 -1
  6. package/src/discovery/openai-compatible.ts +21 -4
  7. package/src/identity/classify.ts +32 -9
  8. package/src/identity/family.ts +18 -4
  9. package/src/model-manager.ts +13 -2
  10. package/src/model-thinking.ts +15 -7
  11. package/src/models.json +7999 -2099
  12. package/src/models.ts +28 -14
  13. package/src/provider-models/bundled-references.ts +4 -2
  14. package/src/provider-models/openai-compat.ts +379 -301
  15. package/src/types.ts +24 -16
  16. package/src/variant-collapse.ts +34 -17
  17. package/src/wire/gemini-headers.ts +79 -18
  18. package/dist/types/build.d.ts +0 -14
  19. package/dist/types/compat/anthropic.d.ts +0 -18
  20. package/dist/types/compat/apply.d.ts +0 -7
  21. package/dist/types/compat/bedrock.d.ts +0 -3
  22. package/dist/types/compat/devin.d.ts +0 -9
  23. package/dist/types/compat/openai.d.ts +0 -26
  24. package/dist/types/discovery/antigravity.d.ts +0 -70
  25. package/dist/types/discovery/codex.d.ts +0 -36
  26. package/dist/types/discovery/cursor-gen/agent_pb.d.ts +0 -16769
  27. package/dist/types/discovery/cursor.d.ts +0 -23
  28. package/dist/types/discovery/devin-gen/buf/validate/validate_pb.d.ts +0 -1715
  29. package/dist/types/discovery/devin-gen/exa/analytics_pb/analytics_pb.d.ts +0 -693
  30. package/dist/types/discovery/devin-gen/exa/api_server_pb/api_server_pb.d.ts +0 -9158
  31. package/dist/types/discovery/devin-gen/exa/auth_pb/auth_pb.d.ts +0 -52
  32. package/dist/types/discovery/devin-gen/exa/auto_cascade_common_pb/auto_cascade_common_pb.d.ts +0 -276
  33. package/dist/types/discovery/devin-gen/exa/bug_checker_pb/bug_checker_pb.d.ts +0 -78
  34. package/dist/types/discovery/devin-gen/exa/cascade_plugins_pb/cascade_plugins_pb.d.ts +0 -999
  35. package/dist/types/discovery/devin-gen/exa/chat_pb/chat_pb.d.ts +0 -1704
  36. package/dist/types/discovery/devin-gen/exa/code_edit/code_edit_pb/code_edit_pb.d.ts +0 -656
  37. package/dist/types/discovery/devin-gen/exa/codeium_common_pb/codeium_common_pb.d.ts +0 -15014
  38. package/dist/types/discovery/devin-gen/exa/context_module_pb/context_module_pb.d.ts +0 -607
  39. package/dist/types/discovery/devin-gen/exa/cortex_pb/cortex_pb.d.ts +0 -11830
  40. package/dist/types/discovery/devin-gen/exa/diff_action_pb/diff_action_pb.d.ts +0 -248
  41. package/dist/types/discovery/devin-gen/exa/index_pb/index_pb.d.ts +0 -1747
  42. package/dist/types/discovery/devin-gen/exa/knowledge_base_pb/knowledge_base_pb.d.ts +0 -509
  43. package/dist/types/discovery/devin-gen/exa/language_server_pb/language_server_pb.d.ts +0 -9048
  44. package/dist/types/discovery/devin-gen/exa/opensearch_clients_pb/opensearch_clients_pb.d.ts +0 -1760
  45. package/dist/types/discovery/devin-gen/exa/prompt_pb/prompt_pb.d.ts +0 -286
  46. package/dist/types/discovery/devin-gen/exa/reactive_component_pb/reactive_component_pb.d.ts +0 -405
  47. package/dist/types/discovery/devin-gen/exa/trust_pb/trust_pb.d.ts +0 -582
  48. package/dist/types/discovery/devin.d.ts +0 -24
  49. package/dist/types/discovery/gemini.d.ts +0 -25
  50. package/dist/types/discovery/gitlab-duo-workflow.d.ts +0 -30
  51. package/dist/types/discovery/index.d.ts +0 -5
  52. package/dist/types/discovery/openai-compatible.d.ts +0 -74
  53. package/dist/types/effort.d.ts +0 -10
  54. package/dist/types/fireworks-model-id.d.ts +0 -23
  55. package/dist/types/hosts.d.ts +0 -164
  56. package/dist/types/identity/bundled.d.ts +0 -3
  57. package/dist/types/identity/classify.d.ts +0 -69
  58. package/dist/types/identity/dialect.d.ts +0 -3
  59. package/dist/types/identity/family.d.ts +0 -181
  60. package/dist/types/identity/id.d.ts +0 -12
  61. package/dist/types/identity/index.d.ts +0 -8
  62. package/dist/types/identity/markers.d.ts +0 -4
  63. package/dist/types/identity/priority.d.ts +0 -1
  64. package/dist/types/identity/reference.d.ts +0 -29
  65. package/dist/types/index.d.ts +0 -17
  66. package/dist/types/model-cache.d.ts +0 -23
  67. package/dist/types/model-manager.d.ts +0 -77
  68. package/dist/types/model-thinking.d.ts +0 -66
  69. package/dist/types/models.d.ts +0 -12
  70. package/dist/types/provider-models/bundled-references.d.ts +0 -13
  71. package/dist/types/provider-models/cache-provider-id.d.ts +0 -9
  72. package/dist/types/provider-models/descriptor-types.d.ts +0 -76
  73. package/dist/types/provider-models/descriptors.d.ts +0 -504
  74. package/dist/types/provider-models/google.d.ts +0 -27
  75. package/dist/types/provider-models/index.d.ts +0 -7
  76. package/dist/types/provider-models/ollama.d.ts +0 -22
  77. package/dist/types/provider-models/openai-compat.d.ts +0 -599
  78. package/dist/types/provider-models/special.d.ts +0 -53
  79. package/dist/types/types.d.ts +0 -811
  80. package/dist/types/utils.d.ts +0 -20
  81. package/dist/types/variant-collapse.d.ts +0 -133
  82. package/dist/types/wire/alibaba-token-plan.d.ts +0 -22
  83. package/dist/types/wire/codex.d.ts +0 -42
  84. package/dist/types/wire/coreweave.d.ts +0 -12
  85. package/dist/types/wire/gemini-headers.d.ts +0 -37
  86. package/dist/types/wire/github-copilot.d.ts +0 -39
package/src/models.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { buildModel } from "./build";
2
2
  import MODELS from "./models.json" with { type: "json" };
3
- import type { Api, KnownProvider, Model, ModelSpec, Usage } from "./types";
3
+ import type { Api, KnownProvider, Model, ModelSpec, TokenCost, Usage } from "./types";
4
4
 
5
5
  /**
6
6
  * Static bundled model registry loaded from `models.json`.
@@ -42,13 +42,27 @@ export function getBundledModels(provider: GeneratedProvider): Model<Api>[] {
42
42
  const models = getProviderModels(provider);
43
43
  return models ? (Array.from(models.values()) as Model<Api>[]) : [];
44
44
  }
45
+ function resolveTokenCost(cost: Model["cost"], promptInputTokens: number): TokenCost {
46
+ const longContext = cost.longContext;
47
+ if (!longContext) return cost;
48
+ return promptInputTokens > longContext.inputThreshold ? longContext : cost;
49
+ }
50
+
51
+ /** Price a prompt as fully uncached input under its active context-length tier. */
52
+ export function calculateUncachedInputCost(cost: Model["cost"], promptInputTokens: number): number {
53
+ const rates = resolveTokenCost(cost, promptInputTokens);
54
+ return (rates.input / 1_000_000) * promptInputTokens;
55
+ }
45
56
 
46
57
  export function calculateCost<TApi extends Api>(model: Model<TApi>, usage: Usage): Usage["cost"] {
47
58
  const orchestration = usage.orchestration;
48
- usage.cost.input = (model.cost.input / 1000000) * (usage.input + (orchestration?.input ?? 0));
49
- usage.cost.output = (model.cost.output / 1000000) * (usage.output + (orchestration?.output ?? 0));
50
- usage.cost.cacheRead = (model.cost.cacheRead / 1000000) * (usage.cacheRead + (orchestration?.cacheRead ?? 0));
51
- usage.cost.cacheWrite = cacheWriteCost(model, usage);
59
+ const promptInputTokens =
60
+ usage.input + usage.cacheRead + usage.cacheWrite + (orchestration?.input ?? 0) + (orchestration?.cacheRead ?? 0);
61
+ const rates = resolveTokenCost(model.cost, promptInputTokens);
62
+ usage.cost.input = (rates.input / 1000000) * (usage.input + (orchestration?.input ?? 0));
63
+ usage.cost.output = (rates.output / 1000000) * (usage.output + (orchestration?.output ?? 0));
64
+ usage.cost.cacheRead = (rates.cacheRead / 1000000) * (usage.cacheRead + (orchestration?.cacheRead ?? 0));
65
+ usage.cost.cacheWrite = cacheWriteCost(rates, usage);
52
66
  usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
53
67
  return usage.cost;
54
68
  }
@@ -56,12 +70,12 @@ export function calculateCost<TApi extends Api>(model: Model<TApi>, usage: Usage
56
70
  /**
57
71
  * Price cache-write tokens, honoring the TTL breakdown when the provider reports one.
58
72
  *
59
- * `model.cost.cacheWrite` is the 5-minute write rate (Anthropic bills 5m writes at
60
- * 1.25x base input). When `usage.cttl` is present the write mixes 5m and 1h
61
- * breakpoints — omp defaults to 1h retention on first-party Anthropic, and 1h writes
62
- * bill at 2x base input — so each component is priced at its own rate instead of the
63
- * flat 5m rate. Deriving 1h from `input * 2` (Anthropic's published multiplier) is
64
- * model-independent and stays correct even for legacy entries whose stored
73
+ * `rates.cacheWrite` is the 5-minute write rate (Anthropic bills 5m writes at
74
+ * 1.25x base input). When `usage.cttl` is present the write can mix 5m and 1h
75
+ * breakpoints, and 1h writes bill at 2x base input, so each component is
76
+ * priced at its own rate instead of the flat 5m rate. Deriving 1h from
77
+ * `input * 2` (Anthropic's published multiplier) is model-independent and
78
+ * stays correct even for legacy entries whose stored
65
79
  * `cacheWrite` scalar drifts from 1.25x input. Providers that omit `cttl`
66
80
  * (everyone but Anthropic) keep the flat-rate calculation.
67
81
  *
@@ -70,14 +84,14 @@ export function calculateCost<TApi extends Api>(model: Model<TApi>, usage: Usage
70
84
  * so any unattributed remainder is priced at the flat rate instead of being dropped:
71
85
  * a partial or stale breakdown must never make write tokens free.
72
86
  */
73
- function cacheWriteCost<TApi extends Api>(model: Model<TApi>, usage: Usage): number {
74
- const rate5m = model.cost.cacheWrite / 1000000;
87
+ function cacheWriteCost(rates: TokenCost, usage: Usage): number {
88
+ const rate5m = rates.cacheWrite / 1000000;
75
89
  const cttl = usage.cttl;
76
90
  if (!cttl) return rate5m * usage.cacheWrite;
77
91
  const fiveMinute = cttl.ephemeral5m ?? 0;
78
92
  const oneHour = cttl.ephemeral1h ?? 0;
79
93
  const residual = Math.max(0, usage.cacheWrite - fiveMinute - oneHour);
80
- return rate5m * (fiveMinute + residual) + ((model.cost.input * 2) / 1000000) * oneHour;
94
+ return rate5m * (fiveMinute + residual) + ((rates.input * 2) / 1000000) * oneHour;
81
95
  }
82
96
 
83
97
  /**
@@ -67,9 +67,11 @@ export function createReferenceResolver<TApi extends Api>(
67
67
  ? () => (lazyProviderReferences ??= providerReferenceSource())
68
68
  : () => providerReferenceSource;
69
69
  return (modelId: string) => {
70
- const providerRef = getProviderReferences().get(modelId);
70
+ const providerRefs = getProviderReferences();
71
+ const globalRefs = getGlobalReferences();
72
+ const providerRef = providerRefs.get(modelId);
71
73
  if (providerRef) return providerRef;
72
- const globalRef = getGlobalReferences().get(modelId);
74
+ const globalRef = globalRefs.get(modelId);
73
75
  return globalRef ? toModelSpec(globalRef as Model<TApi>) : undefined;
74
76
  };
75
77
  }