@jeffreycao/copilot-api 2.0.0 → 2.0.2

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/dist/main.js CHANGED
@@ -25,7 +25,7 @@ bindElectronFetch();
25
25
  const { auth } = await import("./auth-DH-ThnhJ.js");
26
26
  const { debug } = await import("./debug-D2giR-Kj.js");
27
27
  const { mcp } = await import("./mcp-BG6fpi6q.js");
28
- const { start } = await import("./start-CS27P3z1.js");
28
+ const { start } = await import("./start-CtwcJQT5.js");
29
29
  await runMain(defineCommand({
30
30
  meta: {
31
31
  name: "copilot-api",
@@ -2562,9 +2562,11 @@ async function forwardCodexAlphaSearchRequest(request) {
2562
2562
  return createProviderProxyResponse(upstreamResponse);
2563
2563
  }
2564
2564
  function createAlphaSearchRequest(request, payload) {
2565
- return new Request(request, {
2565
+ return new Request(request.url, {
2566
2566
  body: JSON.stringify(payload),
2567
- method: "post"
2567
+ headers: request.headers,
2568
+ method: request.method,
2569
+ signal: request.signal
2568
2570
  });
2569
2571
  }
2570
2572
  async function handleCodexRequest(c, request, resolvedProviderConfig) {
@@ -2609,7 +2611,10 @@ async function handleAlphaSearchRequest(c, resolvedProviderConfig) {
2609
2611
  if (providerModelAlias.provider === "codex") return await handleCodexRequest(c, createAlphaSearchRequest(c.req.raw, payload));
2610
2612
  }
2611
2613
  if (isAlphaSearchCodexPriorityEnabled()) {
2612
- if (await resolveProviderConfig("codex")) return await forwardCodexAlphaSearchRequest(createAlphaSearchRequest(c.req.raw, payload));
2614
+ if (await resolveProviderConfig("codex")) {
2615
+ if (!payload.model.startsWith("gpt")) payload.model = "gpt-5.6-luna";
2616
+ return await forwardCodexAlphaSearchRequest(createAlphaSearchRequest(c.req.raw, payload));
2617
+ }
2613
2618
  }
2614
2619
  const messagesBackedModel = await isMessagesBackedModel(resolvedRequestedModel);
2615
2620
  if (messagesBackedModel) {
@@ -7561,17 +7566,11 @@ async function handleMergedCodexModels(c, candidatesRequest, options = {}) {
7561
7566
  const slug = `codex/${model.slug}`;
7562
7567
  if (seenSlugs.has(slug)) return [];
7563
7568
  seenSlugs.add(slug);
7564
- return [{
7565
- ...model,
7566
- slug
7567
- }];
7569
+ return [createCatalogAlias(model, slug, options.codexProviderName)];
7568
7570
  }) : [];
7569
7571
  const syntheticModels = candidates.filter((candidate) => !seenSlugs.has(candidate.slug)).flatMap((candidate, index) => {
7570
7572
  const catalogModel = candidate.catalogSlug ? catalogModelsBySlug.get(candidate.catalogSlug) : void 0;
7571
- if (catalogModel) return [{
7572
- ...catalogModel,
7573
- slug: candidate.slug
7574
- }];
7573
+ if (catalogModel) return [createCatalogAlias(catalogModel, candidate.slug, candidate.providerName)];
7575
7574
  if (candidate.catalogMatchRequired) return [];
7576
7575
  return [createSyntheticCodexModel(candidate, template, upstreamModels.length + index)];
7577
7576
  });
@@ -7591,6 +7590,18 @@ async function handleMergedCodexModels(c, candidatesRequest, options = {}) {
7591
7590
  });
7592
7591
  return c.json(response);
7593
7592
  }
7593
+ function createCatalogAlias(model, slug, providerName) {
7594
+ const alias = {
7595
+ ...model,
7596
+ slug
7597
+ };
7598
+ const prefix = providerName?.trim();
7599
+ if (!prefix || typeof alias.display_name !== "string" || alias.display_name.startsWith(`${prefix} `)) return alias;
7600
+ return {
7601
+ ...alias,
7602
+ display_name: `${prefix} ${alias.display_name}`
7603
+ };
7604
+ }
7594
7605
  function createSyntheticCodexModel(candidate, template, priority) {
7595
7606
  const reasoningEfforts = candidate.reasoningEfforts.length > 0 ? candidate.reasoningEfforts : DEFAULT_REASONING_EFFORTS;
7596
7607
  const defaultReasoningEffort = reasoningEfforts.includes(candidate.defaultReasoningEffort) ? candidate.defaultReasoningEffort : reasoningEfforts[0];
@@ -7880,6 +7891,7 @@ function createProviderCodexCandidate(providerConfig, modelId, remoteModel, mode
7880
7891
  slug: `${providerConfig.name}/${modelId}`,
7881
7892
  catalogSlug: modelId,
7882
7893
  catalogMatchRequired: effectiveType === "openai-responses",
7894
+ providerName: providerConfig.name,
7883
7895
  displayName: `${displayName} (${providerConfig.name})`,
7884
7896
  description: `${displayName} through the ${providerConfig.name} ${adapterName} adapter.`,
7885
7897
  contextWindow: positiveNumber(codexConfig?.contextWindow ?? getFirstPositiveNumber(remoteModel, [
@@ -7940,7 +7952,11 @@ modelRoutes.get("/", async (c) => {
7940
7952
  try {
7941
7953
  if (isCodexUserAgent(c.req.header("user-agent"))) {
7942
7954
  const enabledProviders = listEnabledProviders();
7943
- return await handleMergedCodexModels(c, getSyntheticCodexModels(c.req.raw.headers, enabledProviders), { includeCodexProviderAliases: enabledProviders.includes("codex") });
7955
+ const codexProviderName = enabledProviders.find((provider) => provider === "codex");
7956
+ return await handleMergedCodexModels(c, getSyntheticCodexModels(c.req.raw.headers, enabledProviders), {
7957
+ includeCodexProviderAliases: codexProviderName !== void 0,
7958
+ codexProviderName
7959
+ });
7944
7960
  }
7945
7961
  const models = await getAggregatedModels(c.req.raw.headers);
7946
7962
  return c.json({
@@ -8761,6 +8777,9 @@ var CustomToolInputStreamDecoder = class {
8761
8777
  prefixTokenOffset = 0;
8762
8778
  safeInputLength = 0;
8763
8779
  state = "prefix";
8780
+ trailingDepth = 0;
8781
+ trailingEscaped = false;
8782
+ trailingInString = false;
8764
8783
  unicodeDigitsRemaining = 0;
8765
8784
  append(partialJson) {
8766
8785
  if (this.failed) return this.fail("decoder is already in a failed state");
@@ -8796,8 +8815,42 @@ var CustomToolInputStreamDecoder = class {
8796
8815
  }
8797
8816
  if (this.state === "suffix") {
8798
8817
  if (isJsonWhitespace(char)) return;
8799
- if (char !== "}") return this.fail("expected \"}\" after the input string");
8800
- this.state = "done";
8818
+ if (char === "}") {
8819
+ this.state = "done";
8820
+ return;
8821
+ }
8822
+ if (char === ",") {
8823
+ this.state = "trailing";
8824
+ this.trailingDepth = 1;
8825
+ return;
8826
+ }
8827
+ return this.fail("expected \"}\" or \",\" after the input string");
8828
+ }
8829
+ if (this.state === "trailing") {
8830
+ if (this.trailingInString) {
8831
+ if (this.trailingEscaped) {
8832
+ this.trailingEscaped = false;
8833
+ return;
8834
+ }
8835
+ if (char === "\\") {
8836
+ this.trailingEscaped = true;
8837
+ return;
8838
+ }
8839
+ if (char === "\"") this.trailingInString = false;
8840
+ return;
8841
+ }
8842
+ if (char === "\"") {
8843
+ this.trailingInString = true;
8844
+ return;
8845
+ }
8846
+ if (char === "{" || char === "[") {
8847
+ this.trailingDepth += 1;
8848
+ return;
8849
+ }
8850
+ if (char === "}" || char === "]") {
8851
+ this.trailingDepth -= 1;
8852
+ if (this.trailingDepth === 0) this.state = "done";
8853
+ }
8801
8854
  return;
8802
8855
  }
8803
8856
  if (this.state === "done") {
@@ -10051,4 +10104,4 @@ server.route("/:provider/images", providerImageRoutes);
10051
10104
  //#endregion
10052
10105
  export { server };
10053
10106
 
10054
- //# sourceMappingURL=server-npfFvUzR.js.map
10107
+ //# sourceMappingURL=server-0udg5DWI.js.map