@dianshuv/copilot-api 0.17.0 → 0.18.0

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 (3) hide show
  1. package/README.md +1 -1
  2. package/dist/main.mjs +35 -24
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -48,7 +48,7 @@ make down
48
48
  |---------|-------------|
49
49
  | `start` | Start the API server (handles auth if needed) |
50
50
  | `login` | Run GitHub authentication flow only |
51
- | `logout` | Remove stored GitHub token |
51
+ | `logout` | Remove the local GitHub token file (does not revoke authorization on GitHub) |
52
52
  | `debug` | Display diagnostic information |
53
53
 
54
54
  ### Start Command Options
package/dist/main.mjs CHANGED
@@ -997,6 +997,8 @@ async function runLogout() {
997
997
  throw error;
998
998
  }
999
999
  }
1000
+ consola.warn("This only removes the local token file. The OAuth App authorization is still active on GitHub and the token remains valid until revoked.");
1001
+ consola.info(`To fully revoke access, visit https://github.com/settings/connections/applications/${GITHUB_CLIENT_ID} and click "Revoke access".`);
1000
1002
  }
1001
1003
  const logout = defineCommand({
1002
1004
  meta: {
@@ -1010,7 +1012,7 @@ const logout = defineCommand({
1010
1012
 
1011
1013
  //#endregion
1012
1014
  //#region package.json
1013
- var version = "0.17.0";
1015
+ var version = "0.18.0";
1014
1016
 
1015
1017
  //#endregion
1016
1018
  //#region src/lib/event-loop-lag.ts
@@ -1592,6 +1594,8 @@ function captureRequest(params) {
1592
1594
  tool_count: params.toolCount
1593
1595
  };
1594
1596
  if (params.reasoningTokens !== void 0) properties.reasoning_tokens = params.reasoningTokens;
1597
+ if (params.cachedInputTokens !== void 0) properties.cached_input_tokens = params.cachedInputTokens;
1598
+ if (params.totalInputTokens !== void 0) properties.total_input_tokens = params.totalInputTokens;
1595
1599
  if (params.stopReason !== void 0) properties.stop_reason = params.stopReason;
1596
1600
  if (params.status !== void 0) properties.status = params.status;
1597
1601
  if (params.copilotErrorCode !== void 0) properties.copilot_error_code = params.copilotErrorCode;
@@ -4191,6 +4195,8 @@ function completeTracking(trackingId, inputTokens, outputTokens, queueWaitMs, re
4191
4195
  stream: analytics.stream,
4192
4196
  toolCount: analytics.toolCount ?? 0,
4193
4197
  reasoningTokens,
4198
+ cachedInputTokens: cache?.cachedInputTokens,
4199
+ totalInputTokens: cache?.totalInputTokens,
4194
4200
  stopReason: analytics.stopReason
4195
4201
  });
4196
4202
  }
@@ -4403,12 +4409,13 @@ function handleNonStreamingResponse$1(c, originalResponse, ctx, payload) {
4403
4409
  content: buildResponseContent(choice),
4404
4410
  toolCalls: extractToolCalls(choice)
4405
4411
  }, durationMs);
4412
+ const cachedInputTokens = usage ? getCachedTokensFromOpenAIUsage(usage) : void 0;
4406
4413
  if (ctx.trackingId && usage) requestTracker.updateRequest(ctx.trackingId, {
4407
4414
  inputTokens: usage.prompt_tokens,
4408
4415
  outputTokens: usage.completion_tokens,
4409
4416
  queueWaitMs: ctx.queueWaitMs,
4410
4417
  reasoningTokens,
4411
- cachedInputTokens: getCachedTokensFromOpenAIUsage(usage),
4418
+ cachedInputTokens,
4412
4419
  totalInputTokens: usage.prompt_tokens
4413
4420
  });
4414
4421
  captureRequest({
@@ -4420,6 +4427,8 @@ function handleNonStreamingResponse$1(c, originalResponse, ctx, payload) {
4420
4427
  stream: false,
4421
4428
  toolCount: payload.tools?.length ?? 0,
4422
4429
  reasoningTokens,
4430
+ cachedInputTokens,
4431
+ totalInputTokens: usage?.prompt_tokens,
4423
4432
  stopReason: choice.finish_reason
4424
4433
  });
4425
4434
  return c.json(echoResponseBody(response, ctx));
@@ -8445,17 +8454,16 @@ function handleDirectAnthropicNonStreamingResponse(c, response, ctx, truncateRes
8445
8454
  },
8446
8455
  toolCalls: extractToolCallsFromContent(response.content)
8447
8456
  }, Date.now() - ctx.startTime);
8448
- if (ctx.trackingId) {
8449
- const cacheRead = response.usage.cache_read_input_tokens ?? 0;
8450
- const cacheCreation = response.usage.cache_creation_input_tokens ?? 0;
8451
- requestTracker.updateRequest(ctx.trackingId, {
8452
- inputTokens: response.usage.input_tokens,
8453
- outputTokens: response.usage.output_tokens,
8454
- queueWaitMs: ctx.queueWaitMs,
8455
- cachedInputTokens: cacheRead,
8456
- totalInputTokens: response.usage.input_tokens + cacheRead + cacheCreation
8457
- });
8458
- }
8457
+ const cacheRead = response.usage.cache_read_input_tokens ?? 0;
8458
+ const cacheCreation = response.usage.cache_creation_input_tokens ?? 0;
8459
+ const totalInputTokens = response.usage.input_tokens + cacheRead + cacheCreation;
8460
+ if (ctx.trackingId) requestTracker.updateRequest(ctx.trackingId, {
8461
+ inputTokens: response.usage.input_tokens,
8462
+ outputTokens: response.usage.output_tokens,
8463
+ queueWaitMs: ctx.queueWaitMs,
8464
+ cachedInputTokens: cacheRead,
8465
+ totalInputTokens
8466
+ });
8459
8467
  captureRequest({
8460
8468
  model: response.model,
8461
8469
  inputTokens: response.usage.input_tokens,
@@ -8464,6 +8472,8 @@ function handleDirectAnthropicNonStreamingResponse(c, response, ctx, truncateRes
8464
8472
  success: true,
8465
8473
  stream: false,
8466
8474
  toolCount: payload.tools?.length ?? 0,
8475
+ cachedInputTokens: cacheRead,
8476
+ totalInputTokens,
8467
8477
  stopReason: response.stop_reason ?? void 0
8468
8478
  });
8469
8479
  let finalResponse = response;
@@ -8767,17 +8777,16 @@ function handleNonStreamingResponse(opts) {
8767
8777
  },
8768
8778
  toolCalls: extractToolCallsFromContent(anthropicResponse.content)
8769
8779
  }, Date.now() - ctx.startTime);
8770
- if (ctx.trackingId) {
8771
- const cacheRead = anthropicResponse.usage.cache_read_input_tokens ?? 0;
8772
- const cacheCreation = anthropicResponse.usage.cache_creation_input_tokens ?? 0;
8773
- requestTracker.updateRequest(ctx.trackingId, {
8774
- inputTokens: anthropicResponse.usage.input_tokens,
8775
- outputTokens: anthropicResponse.usage.output_tokens,
8776
- queueWaitMs: ctx.queueWaitMs,
8777
- cachedInputTokens: cacheRead,
8778
- totalInputTokens: anthropicResponse.usage.input_tokens + cacheRead + cacheCreation
8779
- });
8780
- }
8780
+ const cacheRead = anthropicResponse.usage.cache_read_input_tokens ?? 0;
8781
+ const cacheCreation = anthropicResponse.usage.cache_creation_input_tokens ?? 0;
8782
+ const totalInputTokens = anthropicResponse.usage.input_tokens + cacheRead + cacheCreation;
8783
+ if (ctx.trackingId) requestTracker.updateRequest(ctx.trackingId, {
8784
+ inputTokens: anthropicResponse.usage.input_tokens,
8785
+ outputTokens: anthropicResponse.usage.output_tokens,
8786
+ queueWaitMs: ctx.queueWaitMs,
8787
+ cachedInputTokens: cacheRead,
8788
+ totalInputTokens
8789
+ });
8781
8790
  captureRequest({
8782
8791
  model: anthropicResponse.model,
8783
8792
  inputTokens: anthropicResponse.usage.input_tokens,
@@ -8786,6 +8795,8 @@ function handleNonStreamingResponse(opts) {
8786
8795
  success: true,
8787
8796
  stream: false,
8788
8797
  toolCount: anthropicPayload.tools?.length ?? 0,
8798
+ cachedInputTokens: cacheRead,
8799
+ totalInputTokens,
8789
8800
  stopReason: anthropicResponse.stop_reason ?? void 0
8790
8801
  });
8791
8802
  return c.json(echoResponseBody(anthropicResponse, ctx));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dianshuv/copilot-api",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "Turn GitHub Copilot into OpenAI/Anthropic API compatible server. Usable with Claude Code!",
5
5
  "author": "dianshuv",
6
6
  "type": "module",