@anthonyhaussman/opencode-agy-auth 1.2.3-alpha.1 → 1.2.3-alpha.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.
package/dist/index.js CHANGED
@@ -20679,12 +20679,24 @@ Do not call other tools.
20679
20679
  async function setupOpenCodeV2(ctx) {
20680
20680
  ctx.catalog.transform(async (editor) => {
20681
20681
  if (!editor) return;
20682
+ const resolveVariants = (modelId) => {
20683
+ const mapping = TIER_MAPPING[modelId];
20684
+ if (!mapping) return void 0;
20685
+ const variants = [];
20686
+ if (mapping.minimal !== void 0) variants.push({ id: "minimal" });
20687
+ if (mapping.low !== void 0) variants.push({ id: "low" });
20688
+ if (mapping.medium !== void 0) variants.push({ id: "medium" });
20689
+ if (mapping.high !== void 0) variants.push({ id: "high" });
20690
+ return variants.length > 0 ? variants : void 0;
20691
+ };
20682
20692
  if (typeof editor?.provider?.update === "function") {
20683
20693
  editor.provider.update(AGY_PROVIDER_ID, (p) => {
20684
20694
  p.name = "Antigravity CLI";
20685
20695
  p.activation = "enabled";
20686
- p.package = "@ai-sdk/google";
20696
+ p.package = "aisdk:@ai-sdk/google";
20687
20697
  p.description = "Google Gemini Antigravity Code Assist OAuth provider";
20698
+ p.settings = { ...p.settings || {}, apiKey: "dummy" };
20699
+ p.integrationID = AGY_PROVIDER_ID;
20688
20700
  });
20689
20701
  if (typeof editor?.model?.update === "function") {
20690
20702
  for (const [modelId, simple] of Object.entries(STATIC_MODELS_SIMPLE)) {
@@ -20703,6 +20715,10 @@ async function setupOpenCodeV2(ctx) {
20703
20715
  if (simple.cost) {
20704
20716
  m.cost = simple.cost;
20705
20717
  }
20718
+ const variants = resolveVariants(modelId);
20719
+ if (variants) {
20720
+ m.variants = variants;
20721
+ }
20706
20722
  });
20707
20723
  }
20708
20724
  }
@@ -20713,14 +20729,26 @@ async function setupOpenCodeV2(ctx) {
20713
20729
  catalog.providers[AGY_PROVIDER_ID] = {
20714
20730
  id: AGY_PROVIDER_ID,
20715
20731
  name: "Antigravity CLI",
20716
- npm: "@ai-sdk/google",
20732
+ npm: "aisdk:@ai-sdk/google",
20733
+ settings: { apiKey: "dummy" },
20734
+ integrationID: AGY_PROVIDER_ID,
20717
20735
  models: { ...catalog.providers[AGY_PROVIDER_ID]?.models || {} },
20718
20736
  ...catalog.providers[AGY_PROVIDER_ID]
20719
20737
  };
20738
+ if (catalog.providers[AGY_PROVIDER_ID].settings) {
20739
+ catalog.providers[AGY_PROVIDER_ID].settings = {
20740
+ ...catalog.providers[AGY_PROVIDER_ID].settings,
20741
+ apiKey: "dummy"
20742
+ };
20743
+ } else {
20744
+ catalog.providers[AGY_PROVIDER_ID].settings = { apiKey: "dummy" };
20745
+ }
20746
+ catalog.providers[AGY_PROVIDER_ID].integrationID = AGY_PROVIDER_ID;
20720
20747
  const targetModels = catalog.providers[AGY_PROVIDER_ID].models;
20721
20748
  for (const [modelId, simple] of Object.entries(STATIC_MODELS_SIMPLE)) {
20722
20749
  const isClaude = modelId.startsWith("claude-");
20723
20750
  const isGpt = modelId.startsWith("gpt-");
20751
+ const variants = resolveVariants(modelId);
20724
20752
  targetModels[modelId] = {
20725
20753
  id: modelId,
20726
20754
  providerID: AGY_PROVIDER_ID,
@@ -20735,6 +20763,7 @@ async function setupOpenCodeV2(ctx) {
20735
20763
  output: simple.maxOutputTokens
20736
20764
  },
20737
20765
  cost: simple.cost || { input: 0, output: 0 },
20766
+ ...variants ? { variants } : {},
20738
20767
  ...targetModels[modelId] || {}
20739
20768
  };
20740
20769
  }
@@ -20811,61 +20840,141 @@ async function setupOpenCodeV2(ctx) {
20811
20840
  editor[AGY_V2_QUOTA_SUMMARY_COMMAND] = commands[AGY_V2_QUOTA_SUMMARY_COMMAND];
20812
20841
  }
20813
20842
  });
20814
- ctx.session.hook("http.request", async (event) => {
20815
- if (!event) return;
20816
- const url2 = typeof event.url === "string" ? event.url : event.request?.url || "";
20817
- const isGL = isGenerativeLanguageRequest(url2);
20818
- const isInternal = url2.includes("cloudcode-pa.googleapis.com");
20819
- if (!isGL && !isInternal) {
20820
- return;
20821
- }
20822
- event.headers = event.headers || {};
20823
- let modelName;
20824
- if (isGL) {
20825
- const parsed = parseGenerativeLanguageRequest(url2);
20826
- modelName = parsed?.effectiveModel;
20827
- }
20828
- const userAgent = buildAgyCliUserAgent(modelName);
20829
- if (typeof event.headers.set === "function") {
20830
- if (!event.headers.get("User-Agent")) {
20831
- event.headers.set("User-Agent", userAgent);
20832
- }
20833
- } else {
20834
- if (!event.headers["User-Agent"] && !event.headers["user-agent"]) {
20835
- event.headers["User-Agent"] = userAgent;
20843
+ ctx.integration?.transform?.((editor) => {
20844
+ if (!editor) return;
20845
+ editor.update?.(AGY_PROVIDER_ID, (integration) => {
20846
+ integration.name = "Antigravity CLI (plugin)";
20847
+ });
20848
+ editor.method?.update?.({
20849
+ integrationID: AGY_PROVIDER_ID,
20850
+ method: {
20851
+ id: "oauth",
20852
+ type: "oauth",
20853
+ label: "Antigravity CLI (OAuth)"
20854
+ },
20855
+ authorize: async () => {
20856
+ return {
20857
+ mode: "auto",
20858
+ url: "https://accounts.google.com/o/oauth2/auth",
20859
+ instructions: "Login with Google Cloud / Antigravity CLI credentials"
20860
+ };
20836
20861
  }
20837
- }
20838
- });
20839
- ctx.session.hook("http.response", async (event) => {
20840
- if (!event) return;
20841
- if (event.response?.status === 429) {
20842
- return;
20843
- }
20862
+ });
20844
20863
  });
20845
- ctx.session.hook("retry", async (event) => {
20846
- if (!event) return;
20847
- const response = event.response;
20848
- if (response instanceof Response) {
20849
- if (response.status === 429 || response.status === 503) {
20850
- const quota = await classifyQuotaResponse(response);
20851
- if (quota?.retryDelayMs) {
20852
- event.retryDelayMs = quota.retryDelayMs;
20864
+ ctx.session.hook(
20865
+ "http.request",
20866
+ async (event) => {
20867
+ if (!event) return;
20868
+ const rawUrl = typeof event.url === "string" ? event.url : event.request?.url || "";
20869
+ const isGL = isGenerativeLanguageRequest(rawUrl);
20870
+ const isInternal = rawUrl.includes("cloudcode-pa.googleapis.com");
20871
+ if (!isGL && !isInternal) {
20872
+ return;
20873
+ }
20874
+ event.headers = event.headers || {};
20875
+ let modelName;
20876
+ if (isGL) {
20877
+ const parsed = parseGenerativeLanguageRequest(rawUrl);
20878
+ modelName = parsed?.effectiveModel;
20879
+ if (typeof event.headers.delete === "function") {
20880
+ event.headers.delete("x-goog-api-key");
20881
+ event.headers.delete("api-key");
20853
20882
  } else {
20854
- event.retryDelayMs = await resolveRetryDelayMs(response, event.attempt || 1);
20883
+ for (const key of Object.keys(event.headers)) {
20884
+ const lower = key.toLowerCase();
20885
+ if (lower === "x-goog-api-key" || lower === "api-key") {
20886
+ delete event.headers[key];
20887
+ }
20888
+ }
20889
+ }
20890
+ try {
20891
+ const parsedUrl = new URL(rawUrl);
20892
+ let urlChanged = false;
20893
+ for (const param of ["key", "x-goog-api-key", "api-key"]) {
20894
+ if (parsedUrl.searchParams.has(param)) {
20895
+ parsedUrl.searchParams.delete(param);
20896
+ urlChanged = true;
20897
+ }
20898
+ }
20899
+ if (urlChanged) {
20900
+ const cleanedUrl = parsedUrl.toString();
20901
+ if (typeof event.url === "string") {
20902
+ event.url = cleanedUrl;
20903
+ }
20904
+ if (event.request && typeof event.request === "object") {
20905
+ if (typeof event.request.url === "string") {
20906
+ event.request.url = cleanedUrl;
20907
+ }
20908
+ }
20909
+ }
20910
+ } catch {
20911
+ }
20912
+ const hasAuth = typeof event.headers.get === "function" ? !!event.headers.get("Authorization") : Object.keys(event.headers).some((k) => k.toLowerCase() === "authorization");
20913
+ if (!hasAuth) {
20914
+ let token;
20915
+ if (typeof event.auth?.access === "string" && event.auth.access) {
20916
+ token = event.auth.access;
20917
+ } else if (typeof event.auth?.token === "string" && event.auth.token) {
20918
+ token = event.auth.token;
20919
+ }
20920
+ if (typeof event.headers.set === "function") {
20921
+ event.headers.set("Authorization", `Bearer ${token || "dummy"}`);
20922
+ } else {
20923
+ event.headers["Authorization"] = `Bearer ${token || "dummy"}`;
20924
+ }
20855
20925
  }
20856
20926
  }
20857
- } else if (event.details && Array.isArray(event.details)) {
20858
- const retryInfo = event.details.find(
20859
- (d) => d && d["@type"] === "type.googleapis.com/google.rpc.RetryInfo"
20860
- );
20861
- if (retryInfo?.retryDelay) {
20862
- const delayMs = retryInternals.parseRetryDelayValue(retryInfo.retryDelay);
20863
- if (delayMs !== null) {
20864
- event.retryDelayMs = delayMs;
20927
+ const userAgent = buildAgyCliUserAgent(modelName);
20928
+ if (typeof event.headers.set === "function") {
20929
+ if (!event.headers.get("User-Agent")) {
20930
+ event.headers.set("User-Agent", userAgent);
20931
+ }
20932
+ } else {
20933
+ if (!event.headers["User-Agent"] && !event.headers["user-agent"]) {
20934
+ event.headers["User-Agent"] = userAgent;
20865
20935
  }
20866
20936
  }
20867
- }
20868
- });
20937
+ },
20938
+ { providerID: AGY_PROVIDER_ID }
20939
+ );
20940
+ ctx.session.hook(
20941
+ "http.response",
20942
+ async (event) => {
20943
+ if (!event) return;
20944
+ if (event.response?.status === 429) {
20945
+ return;
20946
+ }
20947
+ },
20948
+ { providerID: AGY_PROVIDER_ID }
20949
+ );
20950
+ ctx.session.hook(
20951
+ "retry",
20952
+ async (event) => {
20953
+ if (!event) return;
20954
+ const response = event.response;
20955
+ if (response instanceof Response) {
20956
+ if (response.status === 429 || response.status === 503) {
20957
+ const quota = await classifyQuotaResponse(response);
20958
+ if (quota?.retryDelayMs) {
20959
+ event.retryDelayMs = quota.retryDelayMs;
20960
+ } else {
20961
+ event.retryDelayMs = await resolveRetryDelayMs(response, event.attempt || 1);
20962
+ }
20963
+ }
20964
+ } else if (event.details && Array.isArray(event.details)) {
20965
+ const retryInfo = event.details.find(
20966
+ (d) => d && d["@type"] === "type.googleapis.com/google.rpc.RetryInfo"
20967
+ );
20968
+ if (retryInfo?.retryDelay) {
20969
+ const delayMs = retryInternals.parseRetryDelayValue(retryInfo.retryDelay);
20970
+ if (delayMs !== null) {
20971
+ event.retryDelayMs = delayMs;
20972
+ }
20973
+ }
20974
+ }
20975
+ },
20976
+ { providerID: AGY_PROVIDER_ID }
20977
+ );
20869
20978
  }
20870
20979
  var v2PluginDefinition = defineOpenCodeV2Plugin({
20871
20980
  id: AGY_PROVIDER_ID,