@jeffreycao/copilot-api 1.14.17 → 1.14.19

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.
@@ -1,7 +1,7 @@
1
- import { C as resolveEffectiveProviderType, E as setModelMappings, O as PATHS, T as resolveProviderAuthType, _ as isResponsesApiWebSearchEnabled, a as getExtraPromptForModel, b as listEnabledProviders, c as getModelResponsesApiCompactThreshold$1, d as getReasoningEffortForModel, f as getSmallModel, g as isMessagesApiEnabled, h as isGpt56OrAbove, i as getConfig, l as getProviderConfig, m as isContextManagementEnabledForResponses, n as getAnthropicApiKey, o as getMessageApiWebSearchModel, p as isContextManagementEnabledForMessages, r as getClaudeTokenMultiplier, s as getModelMappings, u as getRawProviderConfig, v as isResponsesApiWebSocketEnabled, w as resolveMappedModel } from "./config-DkgRPYZ6.js";
2
- import { B as HTTPError, C as prepareMessageProxyHeaders, E as compactMessageSections, F as requestContext, I as resolveTraceId$1, L as createPooledWebSocketStream, M as buildCodexRequestHeaders, N as forwardCodexResponses, O as compactSystemPromptStarts, P as generateTraceId, R as createWebSocketUrl, S as prepareInteractionHeaders, T as compactAutoContinuePromptStarts, V as forwardError, b as copilotWebSocketHeaders, d as generateRequestIdFromPayload, f as getRootSessionId, g as getCopilotUsage, h as parseUserIdMetadata, j as CODEX_API_BASE_URL, m as isNullish, p as getUUID, r as setupCodexToken, v as copilotBaseUrl, x as prepareForCompact, y as copilotHeaders, z as state } from "./token-BJ4LwqZo.js";
1
+ import { C as resolveEffectiveProviderType, E as setModelMappings, O as PATHS, T as resolveProviderAuthType, _ as isResponsesApiWebSearchEnabled, a as getExtraPromptForModel, b as listEnabledProviders, c as getModelResponsesApiCompactThreshold$1, d as getReasoningEffortForModel, f as getSmallModel, g as isMessagesApiEnabled, h as isGpt56OrAbove, i as getConfig, l as getProviderConfig, m as isContextManagementEnabledForResponses, n as getAnthropicApiKey, o as getMessageApiWebSearchModel, p as isContextManagementEnabledForMessages, r as getClaudeTokenMultiplier, s as getModelMappings, u as getRawProviderConfig, v as isResponsesApiWebSocketEnabled, w as resolveMappedModel } from "./config-BtpzjsPE.js";
2
+ import { B as HTTPError, C as prepareMessageProxyHeaders, E as compactMessageSections, F as requestContext, I as resolveTraceId$1, L as createPooledWebSocketStream, M as buildCodexRequestHeaders, N as forwardCodexResponses, O as compactSystemPromptStarts, P as generateTraceId, R as createWebSocketUrl, S as prepareInteractionHeaders, T as compactAutoContinuePromptStarts, V as forwardError, b as copilotWebSocketHeaders, d as generateRequestIdFromPayload, f as getRootSessionId, g as getCopilotUsage, h as parseUserIdMetadata, j as CODEX_API_BASE_URL, m as isNullish, p as getUUID, r as setupCodexToken, v as copilotBaseUrl, x as prepareForCompact, y as copilotHeaders, z as state } from "./token-8J7EFoNd.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-Ds1vbmGG.js";
4
- import { i as toClientModelId, r as normalizeSdkModelId, t as findEndpointModel } from "./models-DLZaxJt4.js";
4
+ import { i as toClientModelId, r as normalizeSdkModelId, t as findEndpointModel } from "./models-B_ZOfZP3.js";
5
5
  import consola from "consola";
6
6
  import { createHash } from "node:crypto";
7
7
  import fs, { readFileSync } from "node:fs";
@@ -1255,28 +1255,28 @@ const BUILTIN_PROVIDER_PRICING = {
1255
1255
  output: 45
1256
1256
  }] },
1257
1257
  "gpt-5.6-terra": { tiers: [{
1258
- cacheCreationInput: 3.125,
1259
- cachedInput: .25,
1260
- input: 2.5,
1258
+ cacheCreationInput: 2.5,
1259
+ cachedInput: .2,
1260
+ input: 2,
1261
1261
  maxInputTokens: 272e3,
1262
- output: 15
1262
+ output: 12
1263
1263
  }, {
1264
- cacheCreationInput: 6.25,
1265
- cachedInput: .5,
1266
- input: 5,
1267
- output: 22.5
1264
+ cacheCreationInput: 5,
1265
+ cachedInput: .4,
1266
+ input: 4,
1267
+ output: 18
1268
1268
  }] },
1269
1269
  "gpt-5.6-luna": { tiers: [{
1270
- cacheCreationInput: 1.25,
1271
- cachedInput: .1,
1272
- input: 1,
1270
+ cacheCreationInput: .25,
1271
+ cachedInput: .02,
1272
+ input: .2,
1273
1273
  maxInputTokens: 272e3,
1274
- output: 6
1274
+ output: 1.2
1275
1275
  }, {
1276
- cacheCreationInput: 2.5,
1277
- cachedInput: .2,
1278
- input: 2,
1279
- output: 9
1276
+ cacheCreationInput: .5,
1277
+ cachedInput: .04,
1278
+ input: .4,
1279
+ output: 1.8
1280
1280
  }] }
1281
1281
  },
1282
1282
  dashscope: {
@@ -1338,6 +1338,23 @@ const BUILTIN_PROVIDER_PRICING = {
1338
1338
  }
1339
1339
  },
1340
1340
  "opencode-go": {
1341
+ hy3: {
1342
+ cachedInput: .035,
1343
+ input: .14,
1344
+ output: .58
1345
+ },
1346
+ "gpt-5.6-luna": { tiers: [{
1347
+ cacheCreationInput: .125,
1348
+ cachedInput: .01,
1349
+ input: .1,
1350
+ maxInputTokens: 272e3,
1351
+ output: .6
1352
+ }, {
1353
+ cacheCreationInput: .25,
1354
+ cachedInput: .02,
1355
+ input: .2,
1356
+ output: .9
1357
+ }] },
1341
1358
  "glm-5.2": {
1342
1359
  cachedInput: .26,
1343
1360
  input: 1.4,
@@ -1421,6 +1438,10 @@ const BUILTIN_PROVIDER_PRICING = {
1421
1438
  }
1422
1439
  };
1423
1440
  function resolveTokenUsageCost(input) {
1441
+ if (input.source === "provider" && input.providerName?.trim().toLowerCase() === "openrouter") {
1442
+ const reportedCost = resolveReportedProviderCost(input);
1443
+ if (reportedCost) return reportedCost;
1444
+ }
1424
1445
  if (input.source === "copilot") return resolveCopilotCost(input);
1425
1446
  const providerName = input.providerName?.trim();
1426
1447
  if (!providerName) return null;
@@ -1441,6 +1462,17 @@ function resolveTokenUsageCost(input) {
1441
1462
  total_cost_nanos: totalCostNanos
1442
1463
  };
1443
1464
  }
1465
+ function resolveReportedProviderCost(input) {
1466
+ const cost = normalizeReportedCost(input.cost);
1467
+ if (cost === null) return null;
1468
+ const totalCostNanos = Math.round(cost * COST_NANOS_PER_UNIT);
1469
+ if (totalCostNanos <= 0) return null;
1470
+ return {
1471
+ currency: input.pricingCurrency?.trim().toUpperCase() || "USD",
1472
+ source: "upstream",
1473
+ total_cost_nanos: totalCostNanos
1474
+ };
1475
+ }
1444
1476
  function resolveCopilotCost(input) {
1445
1477
  const totalNanoAiu = normalizeToken(input.total_nano_aiu);
1446
1478
  if (totalNanoAiu <= 0) return null;
@@ -1482,6 +1514,9 @@ function getInputTokenTotal(input) {
1482
1514
  function normalizePrice(value) {
1483
1515
  return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : null;
1484
1516
  }
1517
+ function normalizeReportedCost(value) {
1518
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : null;
1519
+ }
1485
1520
  function resolveProviderCurrency(providerName, configuredCurrency) {
1486
1521
  return configuredCurrency?.trim().toUpperCase() || BUILTIN_PROVIDER_CURRENCIES[providerName.toLowerCase()] || null;
1487
1522
  }
@@ -1600,6 +1635,7 @@ function normalizeAnthropicUsage(usage) {
1600
1635
  return {
1601
1636
  cache_creation_input_tokens: normalizeOptionalToken(usage?.cache_creation_input_tokens),
1602
1637
  cache_read_input_tokens: normalizeOptionalToken(usage?.cache_read_input_tokens),
1638
+ cost: normalizeOptionalCost(usage?.cost),
1603
1639
  input_tokens: normalizeOptionalToken(usage?.input_tokens),
1604
1640
  output_tokens: normalizeOptionalToken(usage?.output_tokens),
1605
1641
  total_tokens: normalizeOptionalToken(usage?.total_tokens)
@@ -1609,12 +1645,16 @@ function mergeAnthropicUsage(current, next) {
1609
1645
  return {
1610
1646
  cache_creation_input_tokens: next.cache_creation_input_tokens ?? current.cache_creation_input_tokens,
1611
1647
  cache_read_input_tokens: next.cache_read_input_tokens ?? current.cache_read_input_tokens,
1648
+ cost: next.cost ?? current.cost,
1612
1649
  input_tokens: next.input_tokens ?? current.input_tokens,
1613
1650
  output_tokens: next.output_tokens ?? current.output_tokens,
1614
1651
  total_nano_aiu: next.total_nano_aiu ?? current.total_nano_aiu,
1615
1652
  total_tokens: next.total_tokens ?? current.total_tokens
1616
1653
  };
1617
1654
  }
1655
+ function normalizeOptionalCost(value) {
1656
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
1657
+ }
1618
1658
  //#endregion
1619
1659
  //#region src/lib/dashscope.ts
1620
1660
  const OPENAI_COMPATIBLE_CONTEXT_CACHE_MARKER_LIMIT = 4;
@@ -4370,7 +4410,7 @@ const handleOutputItemDone$1 = (rawEvent, state) => {
4370
4410
  index: blockIndex,
4371
4411
  delta: {
4372
4412
  type: "thinking_delta",
4373
- thinking: THINKING_TEXT
4413
+ thinking: ""
4374
4414
  }
4375
4415
  });
4376
4416
  events.push({
@@ -4396,7 +4436,7 @@ const handleOutputItemDone$1 = (rawEvent, state) => {
4396
4436
  index: blockIndex,
4397
4437
  delta: {
4398
4438
  type: "thinking_delta",
4399
- thinking: THINKING_TEXT
4439
+ thinking: ""
4400
4440
  }
4401
4441
  });
4402
4442
  events.push({
@@ -5740,6 +5780,10 @@ const streamProviderMessages = ({ c, modelConfig, payload, pricingCurrency, prov
5740
5780
  const recordUsage = createProviderMessagesUsageRecorder(payload, provider, modelConfig, pricingCurrency);
5741
5781
  return streamSSE(c, async (stream) => {
5742
5782
  let usage = {};
5783
+ const openRouterThinkingState = {
5784
+ signedThinkingBlockIndexes: /* @__PURE__ */ new Set(),
5785
+ thinkingBlockIndexes: /* @__PURE__ */ new Set()
5786
+ };
5743
5787
  for await (const chunk of events(upstreamResponse)) {
5744
5788
  logger$9.debug("provider.messages.raw_stream_event:", chunk.data);
5745
5789
  const eventName = chunk.event;
@@ -5758,9 +5802,13 @@ const streamProviderMessages = ({ c, modelConfig, payload, pricingCurrency, prov
5758
5802
  usage = mergeAnthropicUsage(usage, parsed.usage);
5759
5803
  data = parsed.data;
5760
5804
  }
5761
- await stream.writeSSE({
5762
- event: eventName,
5763
- data
5805
+ const streamEvents = provider === "openrouter" ? normalizeOpenRouterStreamEvents(eventName, data, openRouterThinkingState) : [{
5806
+ data,
5807
+ event: eventName
5808
+ }];
5809
+ for (const streamEvent of streamEvents) await stream.writeSSE({
5810
+ event: streamEvent.event,
5811
+ data: streamEvent.data
5764
5812
  });
5765
5813
  }
5766
5814
  recordUsage(usage);
@@ -5909,9 +5957,61 @@ const parseProviderStreamEvent = (data) => {
5909
5957
  return null;
5910
5958
  }
5911
5959
  };
5960
+ const normalizeOpenRouterThinkingSignatures = (body) => {
5961
+ for (const block of body.content) if (block.type === "thinking") block.signature ??= "";
5962
+ };
5963
+ const normalizeOpenRouterStreamEvents = (eventName, data, state) => {
5964
+ let event;
5965
+ try {
5966
+ event = JSON.parse(data);
5967
+ } catch {
5968
+ return [{
5969
+ data,
5970
+ event: eventName
5971
+ }];
5972
+ }
5973
+ if (event.type === "content_block_start" && event.content_block.type === "thinking") {
5974
+ const { index } = event;
5975
+ state.thinkingBlockIndexes.add(index);
5976
+ state.signedThinkingBlockIndexes.delete(index);
5977
+ }
5978
+ if (event.type === "content_block_delta" && event.delta.type === "signature_delta") {
5979
+ const { index } = event;
5980
+ state.signedThinkingBlockIndexes.add(index);
5981
+ }
5982
+ if (event.type === "content_block_stop") {
5983
+ const { index } = event;
5984
+ if (!state.thinkingBlockIndexes.has(index)) return [{
5985
+ data,
5986
+ event: eventName
5987
+ }];
5988
+ const hasSignature = state.signedThinkingBlockIndexes.has(index);
5989
+ state.thinkingBlockIndexes.delete(index);
5990
+ state.signedThinkingBlockIndexes.delete(index);
5991
+ if (!hasSignature) return [{
5992
+ data: JSON.stringify({
5993
+ delta: {
5994
+ signature: "",
5995
+ type: "signature_delta"
5996
+ },
5997
+ index,
5998
+ type: "content_block_delta"
5999
+ }),
6000
+ event: "content_block_delta"
6001
+ }, {
6002
+ data,
6003
+ event: eventName
6004
+ }];
6005
+ }
6006
+ return [{
6007
+ data,
6008
+ event: eventName
6009
+ }];
6010
+ };
5912
6011
  const respondProviderMessagesJson = (c, options) => {
5913
6012
  const { body, modelConfig, payload, pricingCurrency, provider } = options;
5914
6013
  createProviderMessagesUsageRecorder(payload, provider, modelConfig, pricingCurrency)(normalizeAnthropicUsage(body.usage));
6014
+ if (provider === "openrouter") normalizeOpenRouterThinkingSignatures(body);
5915
6015
  debugJson(logger$9, "provider.messages.no_stream result:", body);
5916
6016
  return c.json(body);
5917
6017
  };
@@ -7117,4 +7217,4 @@ server.route("/:provider/images", providerImageRoutes);
7117
7217
  //#endregion
7118
7218
  export { server };
7119
7219
 
7120
- //# sourceMappingURL=server-DhmRDx8F.js.map
7220
+ //# sourceMappingURL=server-d5b6HQB2.js.map