@dianshuv/copilot-api 0.2.1 → 0.2.3

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 +45 -17
  2. package/package.json +2 -2
package/dist/main.mjs CHANGED
@@ -1017,7 +1017,7 @@ const patchClaude = defineCommand({
1017
1017
 
1018
1018
  //#endregion
1019
1019
  //#region package.json
1020
- var version = "0.2.1";
1020
+ var version = "0.2.3";
1021
1021
 
1022
1022
  //#endregion
1023
1023
  //#region src/lib/adaptive-rate-limiter.ts
@@ -1406,7 +1406,7 @@ function recordResponse(id, response, durationMs) {
1406
1406
  }
1407
1407
  }
1408
1408
  function getHistory(options = {}) {
1409
- const { page = 1, limit = 50, model, endpoint, success, from, to, search, sessionId } = options;
1409
+ const { page = 1, limit = 50, model, endpoint, status, from, to, search, sessionId } = options;
1410
1410
  let filtered = [...historyState.entries];
1411
1411
  if (sessionId) filtered = filtered.filter((e) => e.sessionId === sessionId);
1412
1412
  if (model) {
@@ -1414,7 +1414,21 @@ function getHistory(options = {}) {
1414
1414
  filtered = filtered.filter((e) => e.request.model.toLowerCase().includes(modelLower) || e.response?.model.toLowerCase().includes(modelLower));
1415
1415
  }
1416
1416
  if (endpoint) filtered = filtered.filter((e) => e.endpoint === endpoint);
1417
- if (success !== void 0) filtered = filtered.filter((e) => e.response?.success === success);
1417
+ let effectiveStatus = status;
1418
+ const legacySuccess = options.success;
1419
+ if (!effectiveStatus && legacySuccess !== void 0) effectiveStatus = legacySuccess ? "success" : "error";
1420
+ switch (effectiveStatus) {
1421
+ case "success":
1422
+ filtered = filtered.filter((e) => e.response?.success === true);
1423
+ break;
1424
+ case "error":
1425
+ filtered = filtered.filter((e) => e.response !== void 0 && !e.response.success);
1426
+ break;
1427
+ case "pending":
1428
+ filtered = filtered.filter((e) => !e.response);
1429
+ break;
1430
+ default: break;
1431
+ }
1418
1432
  if (from) filtered = filtered.filter((e) => e.timestamp >= from);
1419
1433
  if (to) filtered = filtered.filter((e) => e.timestamp <= to);
1420
1434
  if (search) {
@@ -3278,6 +3292,11 @@ function handleGetEntries(c) {
3278
3292
  model: query.model || void 0,
3279
3293
  endpoint: query.endpoint,
3280
3294
  success: query.success ? query.success === "true" : void 0,
3295
+ status: [
3296
+ "success",
3297
+ "error",
3298
+ "pending"
3299
+ ].includes(query.status) ? query.status : void 0,
3281
3300
  from: query.from ? Number.parseInt(query.from, 10) : void 0,
3282
3301
  to: query.to ? Number.parseInt(query.to, 10) : void 0,
3283
3302
  search: query.search || void 0,
@@ -3554,11 +3573,11 @@ async function loadEntries() {
3554
3573
  if (currentSessionId) params.set('sessionId', currentSessionId);
3555
3574
 
3556
3575
  const endpoint = document.getElementById('filter-endpoint').value;
3557
- const success = document.getElementById('filter-success').value;
3576
+ const status = document.getElementById('filter-status').value;
3558
3577
  const search = document.getElementById('filter-search').value;
3559
3578
 
3560
3579
  if (endpoint) params.set('endpoint', endpoint);
3561
- if (success) params.set('success', success);
3580
+ if (status) params.set('status', status);
3562
3581
  if (search) params.set('search', search);
3563
3582
 
3564
3583
  try {
@@ -4311,10 +4330,11 @@ const template = `
4311
4330
  <option value="anthropic">Anthropic</option>
4312
4331
  <option value="openai">OpenAI</option>
4313
4332
  </select>
4314
- <select id="filter-success" onchange="loadEntries()">
4333
+ <select id="filter-status" onchange="loadEntries()">
4315
4334
  <option value="">All Status</option>
4316
- <option value="true">Success</option>
4317
- <option value="false">Failed</option>
4335
+ <option value="success">Success</option>
4336
+ <option value="error">Failed</option>
4337
+ <option value="pending">Pending</option>
4318
4338
  </select>
4319
4339
  </div>
4320
4340
 
@@ -4361,6 +4381,7 @@ function getHistoryUI() {
4361
4381
  <meta charset="UTF-8">
4362
4382
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
4363
4383
  <title>Copilot API - Request History</title>
4384
+ <link rel="icon" href="data:,">
4364
4385
  <style>${styles}</style>
4365
4386
  </head>
4366
4387
  <body>
@@ -6426,7 +6447,8 @@ const RESPONSES_ENDPOINT = "/responses";
6426
6447
  const handleResponses = async (c) => {
6427
6448
  const payload = await c.req.json();
6428
6449
  consola.debug("Responses request payload:", JSON.stringify(payload));
6429
- updateTrackerModel(c.get("trackingId"), payload.model);
6450
+ const trackingId = c.get("trackingId");
6451
+ updateTrackerModel(trackingId, payload.model);
6430
6452
  useFunctionApplyPatch(payload);
6431
6453
  removeWebSearchTool(payload);
6432
6454
  if (!((state.models?.data.find((model) => model.id === payload.model))?.supported_endpoints?.includes(RESPONSES_ENDPOINT) ?? false)) return c.json({ error: {
@@ -6443,14 +6465,20 @@ const handleResponses = async (c) => {
6443
6465
  consola.debug("Forwarding native Responses stream");
6444
6466
  return streamSSE(c, async (stream) => {
6445
6467
  const idTracker = createStreamIdTracker();
6446
- for await (const chunk of response) {
6447
- consola.debug("Responses stream chunk:", JSON.stringify(chunk));
6448
- const processedData = fixStreamIds(chunk.data ?? "", chunk.event, idTracker);
6449
- await stream.writeSSE({
6450
- id: chunk.id,
6451
- event: chunk.event,
6452
- data: processedData
6453
- });
6468
+ try {
6469
+ for await (const chunk of response) {
6470
+ consola.debug("Responses stream chunk:", JSON.stringify(chunk));
6471
+ const processedData = fixStreamIds(chunk.data ?? "", chunk.event, idTracker);
6472
+ await stream.writeSSE({
6473
+ id: chunk.id,
6474
+ event: chunk.event,
6475
+ data: processedData
6476
+ });
6477
+ }
6478
+ completeTracking(trackingId, 0, 0);
6479
+ } catch (error) {
6480
+ failTracking(trackingId, error);
6481
+ throw error;
6454
6482
  }
6455
6483
  });
6456
6484
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dianshuv/copilot-api",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Turn GitHub Copilot into OpenAI/Anthropic API compatible server. Usable with Claude Code!",
5
5
  "author": "dianshuv",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  "prepack": "npm run build",
20
20
  "prepare": "npm run build && (command -v bun >/dev/null 2>&1 && simple-git-hooks || true)",
21
21
  "prepublishOnly": "npm run typecheck && npm run lint:all && npm run test",
22
- "release": "npm publish --access public",
22
+ "release": "npm publish --access public --//registry.npmjs.org/:_authToken=$NPM_TOKEN",
23
23
  "start": "NODE_ENV=production bun run ./src/main.ts",
24
24
  "test": "bun test tests/*.test.ts",
25
25
  "test:all": "bun test tests/*.test.ts && bun test tests/integration/",