@dianshuv/copilot-api 0.17.0 → 0.19.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.
- package/README.md +1 -1
- package/dist/main.mjs +61 -31
- 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
|
|
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.
|
|
1015
|
+
var version = "0.19.0";
|
|
1014
1016
|
|
|
1015
1017
|
//#endregion
|
|
1016
1018
|
//#region src/lib/event-loop-lag.ts
|
|
@@ -1592,6 +1594,9 @@ 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.cacheCreationInputTokens !== void 0) properties.cache_creation_input_tokens = params.cacheCreationInputTokens;
|
|
1599
|
+
if (params.totalInputTokens !== void 0) properties.total_input_tokens = params.totalInputTokens;
|
|
1595
1600
|
if (params.stopReason !== void 0) properties.stop_reason = params.stopReason;
|
|
1596
1601
|
if (params.status !== void 0) properties.status = params.status;
|
|
1597
1602
|
if (params.copilotErrorCode !== void 0) properties.copilot_error_code = params.copilotErrorCode;
|
|
@@ -2998,6 +3003,7 @@ var RequestTracker = class {
|
|
|
2998
3003
|
if (update.outputTokens !== void 0) request.outputTokens = update.outputTokens;
|
|
2999
3004
|
if (update.reasoningTokens !== void 0) request.reasoningTokens = update.reasoningTokens;
|
|
3000
3005
|
if (update.cachedInputTokens !== void 0) request.cachedInputTokens = update.cachedInputTokens;
|
|
3006
|
+
if (update.cacheCreationInputTokens !== void 0) request.cacheCreationInputTokens = update.cacheCreationInputTokens;
|
|
3001
3007
|
if (update.totalInputTokens !== void 0) request.totalInputTokens = update.totalInputTokens;
|
|
3002
3008
|
if (update.error !== void 0) request.error = update.error;
|
|
3003
3009
|
if (update.queuePosition !== void 0) request.queuePosition = update.queuePosition;
|
|
@@ -4174,6 +4180,7 @@ function completeTracking(trackingId, inputTokens, outputTokens, queueWaitMs, re
|
|
|
4174
4180
|
queueWaitMs,
|
|
4175
4181
|
reasoningTokens,
|
|
4176
4182
|
cachedInputTokens: cache?.cachedInputTokens,
|
|
4183
|
+
cacheCreationInputTokens: cache?.cacheCreationInputTokens,
|
|
4177
4184
|
totalInputTokens: cache?.totalInputTokens,
|
|
4178
4185
|
...timingsToUpdate(timings)
|
|
4179
4186
|
});
|
|
@@ -4191,6 +4198,9 @@ function completeTracking(trackingId, inputTokens, outputTokens, queueWaitMs, re
|
|
|
4191
4198
|
stream: analytics.stream,
|
|
4192
4199
|
toolCount: analytics.toolCount ?? 0,
|
|
4193
4200
|
reasoningTokens,
|
|
4201
|
+
cachedInputTokens: cache?.cachedInputTokens,
|
|
4202
|
+
cacheCreationInputTokens: cache?.cacheCreationInputTokens,
|
|
4203
|
+
totalInputTokens: cache?.totalInputTokens,
|
|
4194
4204
|
stopReason: analytics.stopReason
|
|
4195
4205
|
});
|
|
4196
4206
|
}
|
|
@@ -4403,23 +4413,29 @@ function handleNonStreamingResponse$1(c, originalResponse, ctx, payload) {
|
|
|
4403
4413
|
content: buildResponseContent(choice),
|
|
4404
4414
|
toolCalls: extractToolCalls(choice)
|
|
4405
4415
|
}, durationMs);
|
|
4416
|
+
const cachedInputTokens = usage ? getCachedTokensFromOpenAIUsage(usage) : void 0;
|
|
4417
|
+
const freshInputTokens = usage ? usage.prompt_tokens - (cachedInputTokens ?? 0) : 0;
|
|
4406
4418
|
if (ctx.trackingId && usage) requestTracker.updateRequest(ctx.trackingId, {
|
|
4407
|
-
inputTokens:
|
|
4419
|
+
inputTokens: freshInputTokens,
|
|
4408
4420
|
outputTokens: usage.completion_tokens,
|
|
4409
4421
|
queueWaitMs: ctx.queueWaitMs,
|
|
4410
4422
|
reasoningTokens,
|
|
4411
|
-
cachedInputTokens
|
|
4423
|
+
cachedInputTokens,
|
|
4424
|
+
cacheCreationInputTokens: 0,
|
|
4412
4425
|
totalInputTokens: usage.prompt_tokens
|
|
4413
4426
|
});
|
|
4414
4427
|
captureRequest({
|
|
4415
4428
|
model: response.model,
|
|
4416
|
-
inputTokens:
|
|
4429
|
+
inputTokens: freshInputTokens,
|
|
4417
4430
|
outputTokens: usage?.completion_tokens ?? 0,
|
|
4418
4431
|
durationMs,
|
|
4419
4432
|
success: true,
|
|
4420
4433
|
stream: false,
|
|
4421
4434
|
toolCount: payload.tools?.length ?? 0,
|
|
4422
4435
|
reasoningTokens,
|
|
4436
|
+
cachedInputTokens,
|
|
4437
|
+
cacheCreationInputTokens: 0,
|
|
4438
|
+
totalInputTokens: usage?.prompt_tokens,
|
|
4423
4439
|
stopReason: choice.finish_reason
|
|
4424
4440
|
});
|
|
4425
4441
|
return c.json(echoResponseBody(response, ctx));
|
|
@@ -4488,7 +4504,7 @@ async function handleStreamingResponse$1(opts) {
|
|
|
4488
4504
|
await accumulateAndEchoChunk(chunk, acc, checkRepetition, ctx, stream);
|
|
4489
4505
|
}
|
|
4490
4506
|
recordStreamSuccess(acc, payload.model, ctx);
|
|
4491
|
-
completeTracking(ctx.trackingId, acc.inputTokens, acc.outputTokens, ctx.queueWaitMs, acc.reasoningTokens, {
|
|
4507
|
+
completeTracking(ctx.trackingId, acc.inputTokens - acc.cachedTokens, acc.outputTokens, ctx.queueWaitMs, acc.reasoningTokens, {
|
|
4492
4508
|
model: acc.model || payload.model,
|
|
4493
4509
|
stream: true,
|
|
4494
4510
|
durationMs: Date.now() - ctx.startTime,
|
|
@@ -4496,6 +4512,7 @@ async function handleStreamingResponse$1(opts) {
|
|
|
4496
4512
|
toolCount: payload.tools?.length ?? 0
|
|
4497
4513
|
}, ctx.timings, {
|
|
4498
4514
|
cachedInputTokens: acc.cachedTokens,
|
|
4515
|
+
cacheCreationInputTokens: 0,
|
|
4499
4516
|
totalInputTokens: acc.inputTokens
|
|
4500
4517
|
});
|
|
4501
4518
|
} catch (error) {
|
|
@@ -8445,17 +8462,17 @@ function handleDirectAnthropicNonStreamingResponse(c, response, ctx, truncateRes
|
|
|
8445
8462
|
},
|
|
8446
8463
|
toolCalls: extractToolCallsFromContent(response.content)
|
|
8447
8464
|
}, Date.now() - ctx.startTime);
|
|
8448
|
-
|
|
8449
|
-
|
|
8450
|
-
|
|
8451
|
-
|
|
8452
|
-
|
|
8453
|
-
|
|
8454
|
-
|
|
8455
|
-
|
|
8456
|
-
|
|
8457
|
-
|
|
8458
|
-
}
|
|
8465
|
+
const cacheRead = response.usage.cache_read_input_tokens ?? 0;
|
|
8466
|
+
const cacheCreation = response.usage.cache_creation_input_tokens ?? 0;
|
|
8467
|
+
const totalInputTokens = response.usage.input_tokens + cacheRead + cacheCreation;
|
|
8468
|
+
if (ctx.trackingId) requestTracker.updateRequest(ctx.trackingId, {
|
|
8469
|
+
inputTokens: response.usage.input_tokens,
|
|
8470
|
+
outputTokens: response.usage.output_tokens,
|
|
8471
|
+
queueWaitMs: ctx.queueWaitMs,
|
|
8472
|
+
cachedInputTokens: cacheRead,
|
|
8473
|
+
cacheCreationInputTokens: cacheCreation,
|
|
8474
|
+
totalInputTokens
|
|
8475
|
+
});
|
|
8459
8476
|
captureRequest({
|
|
8460
8477
|
model: response.model,
|
|
8461
8478
|
inputTokens: response.usage.input_tokens,
|
|
@@ -8464,6 +8481,9 @@ function handleDirectAnthropicNonStreamingResponse(c, response, ctx, truncateRes
|
|
|
8464
8481
|
success: true,
|
|
8465
8482
|
stream: false,
|
|
8466
8483
|
toolCount: payload.tools?.length ?? 0,
|
|
8484
|
+
cachedInputTokens: cacheRead,
|
|
8485
|
+
cacheCreationInputTokens: cacheCreation,
|
|
8486
|
+
totalInputTokens,
|
|
8467
8487
|
stopReason: response.stop_reason ?? void 0
|
|
8468
8488
|
});
|
|
8469
8489
|
let finalResponse = response;
|
|
@@ -8551,6 +8571,7 @@ async function handleDirectAnthropicStreamingResponse(opts) {
|
|
|
8551
8571
|
toolCount: anthropicPayload.tools?.length ?? 0
|
|
8552
8572
|
}, ctx.timings, {
|
|
8553
8573
|
cachedInputTokens: acc.cacheReadInputTokens,
|
|
8574
|
+
cacheCreationInputTokens: acc.cacheCreationInputTokens,
|
|
8554
8575
|
totalInputTokens: acc.inputTokens + acc.cacheReadInputTokens + acc.cacheCreationInputTokens
|
|
8555
8576
|
});
|
|
8556
8577
|
} catch (error) {
|
|
@@ -8767,17 +8788,17 @@ function handleNonStreamingResponse(opts) {
|
|
|
8767
8788
|
},
|
|
8768
8789
|
toolCalls: extractToolCallsFromContent(anthropicResponse.content)
|
|
8769
8790
|
}, Date.now() - ctx.startTime);
|
|
8770
|
-
|
|
8771
|
-
|
|
8772
|
-
|
|
8773
|
-
|
|
8774
|
-
|
|
8775
|
-
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
}
|
|
8791
|
+
const cacheRead = anthropicResponse.usage.cache_read_input_tokens ?? 0;
|
|
8792
|
+
const cacheCreation = anthropicResponse.usage.cache_creation_input_tokens ?? 0;
|
|
8793
|
+
const totalInputTokens = anthropicResponse.usage.input_tokens + cacheRead + cacheCreation;
|
|
8794
|
+
if (ctx.trackingId) requestTracker.updateRequest(ctx.trackingId, {
|
|
8795
|
+
inputTokens: anthropicResponse.usage.input_tokens,
|
|
8796
|
+
outputTokens: anthropicResponse.usage.output_tokens,
|
|
8797
|
+
queueWaitMs: ctx.queueWaitMs,
|
|
8798
|
+
cachedInputTokens: cacheRead,
|
|
8799
|
+
cacheCreationInputTokens: cacheCreation,
|
|
8800
|
+
totalInputTokens
|
|
8801
|
+
});
|
|
8781
8802
|
captureRequest({
|
|
8782
8803
|
model: anthropicResponse.model,
|
|
8783
8804
|
inputTokens: anthropicResponse.usage.input_tokens,
|
|
@@ -8786,6 +8807,9 @@ function handleNonStreamingResponse(opts) {
|
|
|
8786
8807
|
success: true,
|
|
8787
8808
|
stream: false,
|
|
8788
8809
|
toolCount: anthropicPayload.tools?.length ?? 0,
|
|
8810
|
+
cachedInputTokens: cacheRead,
|
|
8811
|
+
cacheCreationInputTokens: cacheCreation,
|
|
8812
|
+
totalInputTokens,
|
|
8789
8813
|
stopReason: anthropicResponse.stop_reason ?? void 0
|
|
8790
8814
|
});
|
|
8791
8815
|
return c.json(echoResponseBody(anthropicResponse, ctx));
|
|
@@ -8824,6 +8848,7 @@ async function handleStreamingResponse(opts) {
|
|
|
8824
8848
|
toolCount: anthropicPayload.tools?.length ?? 0
|
|
8825
8849
|
}, ctx.timings, {
|
|
8826
8850
|
cachedInputTokens: acc.cacheReadInputTokens,
|
|
8851
|
+
cacheCreationInputTokens: acc.cacheCreationInputTokens,
|
|
8827
8852
|
totalInputTokens: acc.inputTokens + acc.cacheReadInputTokens + acc.cacheCreationInputTokens
|
|
8828
8853
|
});
|
|
8829
8854
|
} catch (error) {
|
|
@@ -9453,13 +9478,15 @@ const handleResponses = async (c) => {
|
|
|
9453
9478
|
if (finalResult) {
|
|
9454
9479
|
recordResponseResult(finalResult, model, historyId, startTime);
|
|
9455
9480
|
const usage = finalResult.usage;
|
|
9456
|
-
|
|
9481
|
+
const cachedInputTokens = usage?.input_tokens_details?.cached_tokens ?? 0;
|
|
9482
|
+
completeTracking(trackingId, (usage?.input_tokens ?? 0) - cachedInputTokens, usage?.output_tokens ?? 0, queueWaitMs, usage?.output_tokens_details?.reasoning_tokens, {
|
|
9457
9483
|
model: finalResult.model || model,
|
|
9458
9484
|
stream: true,
|
|
9459
9485
|
durationMs: Date.now() - startTime,
|
|
9460
9486
|
toolCount: tools.length
|
|
9461
9487
|
}, ctx.timings, {
|
|
9462
|
-
cachedInputTokens
|
|
9488
|
+
cachedInputTokens,
|
|
9489
|
+
cacheCreationInputTokens: 0,
|
|
9463
9490
|
totalInputTokens: usage?.input_tokens ?? 0
|
|
9464
9491
|
});
|
|
9465
9492
|
} else if (streamErrorMessage) {
|
|
@@ -9506,14 +9533,17 @@ const handleResponses = async (c) => {
|
|
|
9506
9533
|
}
|
|
9507
9534
|
const result = response;
|
|
9508
9535
|
const usage = result.usage;
|
|
9536
|
+
const cachedInputTokens = usage?.input_tokens_details?.cached_tokens ?? 0;
|
|
9537
|
+
const freshInputTokens = (usage?.input_tokens ?? 0) - cachedInputTokens;
|
|
9509
9538
|
recordResponseResult(result, model, historyId, startTime);
|
|
9510
|
-
completeTracking(trackingId,
|
|
9539
|
+
completeTracking(trackingId, freshInputTokens, usage?.output_tokens ?? 0, ctx.queueWaitMs, usage?.output_tokens_details?.reasoning_tokens, {
|
|
9511
9540
|
model: result.model || model,
|
|
9512
9541
|
stream: false,
|
|
9513
9542
|
durationMs: Date.now() - startTime,
|
|
9514
9543
|
toolCount: tools.length
|
|
9515
9544
|
}, ctx.timings, {
|
|
9516
|
-
cachedInputTokens
|
|
9545
|
+
cachedInputTokens,
|
|
9546
|
+
cacheCreationInputTokens: 0,
|
|
9517
9547
|
totalInputTokens: usage?.input_tokens ?? 0
|
|
9518
9548
|
});
|
|
9519
9549
|
consola.debug("Forwarding native Responses result:", JSON.stringify(result).slice(-400));
|