@anthonyhaussman/opencode-agy-auth 1.2.3-alpha.2 → 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 +141 -48
- package/dist/index.js.map +1 -1
- package/dist/src/plugin/types.d.ts +6 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20695,6 +20695,8 @@ async function setupOpenCodeV2(ctx) {
|
|
|
20695
20695
|
p.activation = "enabled";
|
|
20696
20696
|
p.package = "aisdk:@ai-sdk/google";
|
|
20697
20697
|
p.description = "Google Gemini Antigravity Code Assist OAuth provider";
|
|
20698
|
+
p.settings = { ...p.settings || {}, apiKey: "dummy" };
|
|
20699
|
+
p.integrationID = AGY_PROVIDER_ID;
|
|
20698
20700
|
});
|
|
20699
20701
|
if (typeof editor?.model?.update === "function") {
|
|
20700
20702
|
for (const [modelId, simple] of Object.entries(STATIC_MODELS_SIMPLE)) {
|
|
@@ -20728,9 +20730,20 @@ async function setupOpenCodeV2(ctx) {
|
|
|
20728
20730
|
id: AGY_PROVIDER_ID,
|
|
20729
20731
|
name: "Antigravity CLI",
|
|
20730
20732
|
npm: "aisdk:@ai-sdk/google",
|
|
20733
|
+
settings: { apiKey: "dummy" },
|
|
20734
|
+
integrationID: AGY_PROVIDER_ID,
|
|
20731
20735
|
models: { ...catalog.providers[AGY_PROVIDER_ID]?.models || {} },
|
|
20732
20736
|
...catalog.providers[AGY_PROVIDER_ID]
|
|
20733
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;
|
|
20734
20747
|
const targetModels = catalog.providers[AGY_PROVIDER_ID].models;
|
|
20735
20748
|
for (const [modelId, simple] of Object.entries(STATIC_MODELS_SIMPLE)) {
|
|
20736
20749
|
const isClaude = modelId.startsWith("claude-");
|
|
@@ -20827,61 +20840,141 @@ async function setupOpenCodeV2(ctx) {
|
|
|
20827
20840
|
editor[AGY_V2_QUOTA_SUMMARY_COMMAND] = commands[AGY_V2_QUOTA_SUMMARY_COMMAND];
|
|
20828
20841
|
}
|
|
20829
20842
|
});
|
|
20830
|
-
ctx.
|
|
20831
|
-
if (!
|
|
20832
|
-
|
|
20833
|
-
|
|
20834
|
-
|
|
20835
|
-
|
|
20836
|
-
|
|
20837
|
-
|
|
20838
|
-
|
|
20839
|
-
|
|
20840
|
-
|
|
20841
|
-
|
|
20842
|
-
|
|
20843
|
-
|
|
20844
|
-
|
|
20845
|
-
|
|
20846
|
-
|
|
20847
|
-
|
|
20848
|
-
}
|
|
20849
|
-
} else {
|
|
20850
|
-
if (!event.headers["User-Agent"] && !event.headers["user-agent"]) {
|
|
20851
|
-
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
|
+
};
|
|
20852
20861
|
}
|
|
20853
|
-
}
|
|
20854
|
-
});
|
|
20855
|
-
ctx.session.hook("http.response", async (event) => {
|
|
20856
|
-
if (!event) return;
|
|
20857
|
-
if (event.response?.status === 429) {
|
|
20858
|
-
return;
|
|
20859
|
-
}
|
|
20862
|
+
});
|
|
20860
20863
|
});
|
|
20861
|
-
ctx.session.hook(
|
|
20862
|
-
|
|
20863
|
-
|
|
20864
|
-
|
|
20865
|
-
|
|
20866
|
-
|
|
20867
|
-
|
|
20868
|
-
|
|
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");
|
|
20869
20882
|
} else {
|
|
20870
|
-
|
|
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
|
+
}
|
|
20871
20925
|
}
|
|
20872
20926
|
}
|
|
20873
|
-
|
|
20874
|
-
|
|
20875
|
-
(
|
|
20876
|
-
|
|
20877
|
-
|
|
20878
|
-
|
|
20879
|
-
if (
|
|
20880
|
-
event.
|
|
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;
|
|
20881
20935
|
}
|
|
20882
20936
|
}
|
|
20883
|
-
}
|
|
20884
|
-
|
|
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
|
+
);
|
|
20885
20978
|
}
|
|
20886
20979
|
var v2PluginDefinition = defineOpenCodeV2Plugin({
|
|
20887
20980
|
id: AGY_PROVIDER_ID,
|