@dianshuv/copilot-api 0.7.7 → 0.7.8

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 (2) hide show
  1. package/dist/main.mjs +44 -11
  2. package/package.json +1 -1
package/dist/main.mjs CHANGED
@@ -1213,7 +1213,7 @@ const patchClaude = defineCommand({
1213
1213
 
1214
1214
  //#endregion
1215
1215
  //#region package.json
1216
- var version = "0.7.7";
1216
+ var version = "0.7.8";
1217
1217
 
1218
1218
  //#endregion
1219
1219
  //#region src/lib/adaptive-rate-limiter.ts
@@ -2277,6 +2277,11 @@ function captureRequest(params) {
2277
2277
  if (params.errorPhase !== void 0) properties.error_phase = params.errorPhase;
2278
2278
  if (params.endpoint !== void 0) properties.endpoint = params.endpoint;
2279
2279
  if (params.attempt !== void 0) properties.attempt = params.attempt;
2280
+ if (params.errorName !== void 0) properties.error_name = params.errorName;
2281
+ if (params.errorCode !== void 0) properties.error_code = params.errorCode;
2282
+ if (params.causeName !== void 0) properties.cause_name = params.causeName;
2283
+ if (params.causeCode !== void 0) properties.cause_code = params.causeCode;
2284
+ if (params.errorMessage !== void 0) properties.error_message = params.errorMessage;
2280
2285
  client.capture({
2281
2286
  distinctId,
2282
2287
  event: "copilot_api_request",
@@ -3639,12 +3644,42 @@ async function autoTruncateOpenAI(payload, model, config = {}) {
3639
3644
 
3640
3645
  //#endregion
3641
3646
  //#region src/lib/error-metrics.ts
3647
+ function safeString(value, max = 200) {
3648
+ try {
3649
+ if (typeof value !== "string") return void 0;
3650
+ return value.length > max ? value.slice(0, max) : value;
3651
+ } catch {
3652
+ return;
3653
+ }
3654
+ }
3655
+ function getStringProp(obj, key, max = 200) {
3656
+ try {
3657
+ if (typeof obj !== "object" || obj === null) return void 0;
3658
+ return safeString(obj[key], max);
3659
+ } catch {
3660
+ return;
3661
+ }
3662
+ }
3642
3663
  function extractErrorMetrics(error) {
3643
- if (!(error instanceof HTTPError)) return {};
3644
- const metrics = { status: error.status };
3664
+ if (error instanceof HTTPError) {
3665
+ const metrics = { status: error.status };
3666
+ try {
3667
+ const parsed = JSON.parse(error.responseText);
3668
+ if (parsed.error?.code) metrics.copilotErrorCode = parsed.error.code;
3669
+ } catch {}
3670
+ return metrics;
3671
+ }
3672
+ if (!(error instanceof Error)) return {};
3673
+ const metrics = {};
3645
3674
  try {
3646
- const parsed = JSON.parse(error.responseText);
3647
- if (parsed.error?.code) metrics.copilotErrorCode = parsed.error.code;
3675
+ metrics.errorName = getStringProp(error, "name");
3676
+ metrics.errorMessage = getStringProp(error, "message");
3677
+ metrics.errorCode = getStringProp(error, "code");
3678
+ const cause = error.cause;
3679
+ if (cause !== void 0 && cause !== null) {
3680
+ metrics.causeName = getStringProp(cause, "name");
3681
+ metrics.causeCode = getStringProp(cause, "code");
3682
+ }
3648
3683
  } catch {}
3649
3684
  return metrics;
3650
3685
  }
@@ -3687,7 +3722,7 @@ function recordErrorResponse(ctx, model, error, endpoint, stream) {
3687
3722
  content: null
3688
3723
  }, Date.now() - ctx.startTime);
3689
3724
  if (endpoint !== void 0) {
3690
- const { status, copilotErrorCode } = extractErrorMetrics(error);
3725
+ const metrics = extractErrorMetrics(error);
3691
3726
  captureRequest({
3692
3727
  model,
3693
3728
  inputTokens: 0,
@@ -3696,8 +3731,7 @@ function recordErrorResponse(ctx, model, error, endpoint, stream) {
3696
3731
  success: false,
3697
3732
  stream: stream ?? false,
3698
3733
  toolCount: 0,
3699
- status,
3700
- copilotErrorCode,
3734
+ ...metrics,
3701
3735
  errorPhase: stream ? "pre_stream" : "non_stream",
3702
3736
  endpoint,
3703
3737
  attempt: 1
@@ -3774,7 +3808,7 @@ function recordStreamError(opts) {
3774
3808
  content: null
3775
3809
  }, Date.now() - ctx.startTime);
3776
3810
  if (endpoint !== void 0) {
3777
- const { status, copilotErrorCode } = extractErrorMetrics(error);
3811
+ const metrics = extractErrorMetrics(error);
3778
3812
  captureRequest({
3779
3813
  model,
3780
3814
  inputTokens: acc.inputTokens ?? 0,
@@ -3783,8 +3817,7 @@ function recordStreamError(opts) {
3783
3817
  success: false,
3784
3818
  stream: true,
3785
3819
  toolCount: 0,
3786
- status,
3787
- copilotErrorCode,
3820
+ ...metrics,
3788
3821
  errorPhase: "mid_stream",
3789
3822
  endpoint,
3790
3823
  attempt: 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dianshuv/copilot-api",
3
- "version": "0.7.7",
3
+ "version": "0.7.8",
4
4
  "description": "Turn GitHub Copilot into OpenAI/Anthropic API compatible server. Usable with Claude Code!",
5
5
  "author": "dianshuv",
6
6
  "type": "module",