@anthonyhaussman/opencode-agy-auth 1.2.2 → 1.2.3-alpha.1
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/README.md +1 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +227 -3
- package/dist/index.js.map +1 -1
- package/dist/src/plugin/types.d.ts +26 -0
- package/dist/src/plugin/v2.d.ts +14 -0
- package/dist/src/plugin.d.ts +23 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ An [OpenCode](https://opencode.ai/) authentication plugin that enables seamless
|
|
|
8
8
|
- **Dynamic Model Retrieval**: Fetches available models based on user tier and current allocations.
|
|
9
9
|
- **Quota Tracking**: Injects the `agy_quota` tool into OpenCode to check usage limits directly.
|
|
10
10
|
- **Traffic Simulation**: Maintains background heartbeat with `agy` servers.
|
|
11
|
+
- **Dual OpenCode Compatibility**: Fully supports both OpenCode v1 (>= 1.18.29) and OpenCode v2 seamlessly without breaking changes.
|
|
11
12
|
|
|
12
13
|
## Installation
|
|
13
14
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { AgyCLIOAuthPlugin, GoogleOAuthPlugin } from "./src/plugin";
|
|
2
|
+
import { setupOpenCodeV2, v2PluginDefinition } from "./src/plugin/v2";
|
|
3
|
+
import type { DualOpenCodePlugin } from "./src/plugin/types";
|
|
2
4
|
export { AgyCLIOAuthPlugin, GoogleOAuthPlugin };
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export default _default;
|
|
5
|
+
export { setupOpenCodeV2, v2PluginDefinition };
|
|
6
|
+
export * from "./src/plugin/types";
|
|
7
|
+
declare const dualPlugin: DualOpenCodePlugin;
|
|
8
|
+
export default dualPlugin;
|
package/dist/index.js
CHANGED
|
@@ -579,6 +579,12 @@ async function resolveQuotaResetDelay(accessToken, projectId, model, userAgentMo
|
|
|
579
579
|
return null;
|
|
580
580
|
}
|
|
581
581
|
}
|
|
582
|
+
var retryInternals = {
|
|
583
|
+
parseRetryDelayValue,
|
|
584
|
+
parseRetryDelayFromMessage,
|
|
585
|
+
findResetTimeForModel,
|
|
586
|
+
resolveQuotaResetDelay
|
|
587
|
+
};
|
|
582
588
|
|
|
583
589
|
// src/sdk/retry/helpers.ts
|
|
584
590
|
var DEFAULT_MAX_ATTEMPTS = 3;
|
|
@@ -20652,14 +20658,232 @@ function toUrlString(value) {
|
|
|
20652
20658
|
return value.toString();
|
|
20653
20659
|
}
|
|
20654
20660
|
|
|
20661
|
+
// src/plugin/types.ts
|
|
20662
|
+
function defineOpenCodeV2Plugin(def) {
|
|
20663
|
+
return def;
|
|
20664
|
+
}
|
|
20665
|
+
|
|
20666
|
+
// src/plugin/v2.ts
|
|
20667
|
+
var AGY_V2_QUOTA_COMMAND = "agy-quota";
|
|
20668
|
+
var AGY_V2_QUOTA_SUMMARY_COMMAND = "agy-quota-summary";
|
|
20669
|
+
var AGY_V2_QUOTA_COMMAND_TEMPLATE = `Retrieve Agy Code Assist quota usage for the current authenticated account.
|
|
20670
|
+
|
|
20671
|
+
Immediately call \`${AGY_QUOTA_TOOL_NAME}\` with no arguments and return its output verbatim.
|
|
20672
|
+
Do not call other tools.
|
|
20673
|
+
`;
|
|
20674
|
+
var AGY_V2_QUOTA_SUMMARY_COMMAND_TEMPLATE = `Retrieve Agy Code Assist quota summary (weekly and 5-hour limits by model group) for the current authenticated account.
|
|
20675
|
+
|
|
20676
|
+
Immediately call \`${AGY_QUOTA_SUMMARY_TOOL_NAME}\` with no arguments and return its output verbatim.
|
|
20677
|
+
Do not call other tools.
|
|
20678
|
+
`;
|
|
20679
|
+
async function setupOpenCodeV2(ctx) {
|
|
20680
|
+
ctx.catalog.transform(async (editor) => {
|
|
20681
|
+
if (!editor) return;
|
|
20682
|
+
if (typeof editor?.provider?.update === "function") {
|
|
20683
|
+
editor.provider.update(AGY_PROVIDER_ID, (p) => {
|
|
20684
|
+
p.name = "Antigravity CLI";
|
|
20685
|
+
p.activation = "enabled";
|
|
20686
|
+
p.package = "@ai-sdk/google";
|
|
20687
|
+
p.description = "Google Gemini Antigravity Code Assist OAuth provider";
|
|
20688
|
+
});
|
|
20689
|
+
if (typeof editor?.model?.update === "function") {
|
|
20690
|
+
for (const [modelId, simple] of Object.entries(STATIC_MODELS_SIMPLE)) {
|
|
20691
|
+
editor.model.update(AGY_PROVIDER_ID, modelId, (m) => {
|
|
20692
|
+
m.name = simple.name;
|
|
20693
|
+
m.capabilities = {
|
|
20694
|
+
tools: true,
|
|
20695
|
+
input: ["text", "image"],
|
|
20696
|
+
output: ["text"]
|
|
20697
|
+
};
|
|
20698
|
+
m.limit = {
|
|
20699
|
+
context: simple.maxTokens,
|
|
20700
|
+
output: simple.maxOutputTokens
|
|
20701
|
+
};
|
|
20702
|
+
m.family = "gemini";
|
|
20703
|
+
if (simple.cost) {
|
|
20704
|
+
m.cost = simple.cost;
|
|
20705
|
+
}
|
|
20706
|
+
});
|
|
20707
|
+
}
|
|
20708
|
+
}
|
|
20709
|
+
return;
|
|
20710
|
+
}
|
|
20711
|
+
const catalog = editor;
|
|
20712
|
+
catalog.providers = catalog.providers || {};
|
|
20713
|
+
catalog.providers[AGY_PROVIDER_ID] = {
|
|
20714
|
+
id: AGY_PROVIDER_ID,
|
|
20715
|
+
name: "Antigravity CLI",
|
|
20716
|
+
npm: "@ai-sdk/google",
|
|
20717
|
+
models: { ...catalog.providers[AGY_PROVIDER_ID]?.models || {} },
|
|
20718
|
+
...catalog.providers[AGY_PROVIDER_ID]
|
|
20719
|
+
};
|
|
20720
|
+
const targetModels = catalog.providers[AGY_PROVIDER_ID].models;
|
|
20721
|
+
for (const [modelId, simple] of Object.entries(STATIC_MODELS_SIMPLE)) {
|
|
20722
|
+
const isClaude = modelId.startsWith("claude-");
|
|
20723
|
+
const isGpt = modelId.startsWith("gpt-");
|
|
20724
|
+
targetModels[modelId] = {
|
|
20725
|
+
id: modelId,
|
|
20726
|
+
providerID: AGY_PROVIDER_ID,
|
|
20727
|
+
name: simple.name,
|
|
20728
|
+
description: simple.description,
|
|
20729
|
+
family: modelId.includes("gemini") ? "gemini" : isClaude ? "claude" : isGpt ? "gpt" : "unknown",
|
|
20730
|
+
reasoning: simple.reasoning,
|
|
20731
|
+
attachment: simple.attachment,
|
|
20732
|
+
tool_call: simple.toolCall,
|
|
20733
|
+
limit: {
|
|
20734
|
+
context: simple.maxTokens,
|
|
20735
|
+
output: simple.maxOutputTokens
|
|
20736
|
+
},
|
|
20737
|
+
cost: simple.cost || { input: 0, output: 0 },
|
|
20738
|
+
...targetModels[modelId] || {}
|
|
20739
|
+
};
|
|
20740
|
+
}
|
|
20741
|
+
});
|
|
20742
|
+
ctx.tool.transform(async (editor) => {
|
|
20743
|
+
if (!editor) return;
|
|
20744
|
+
const quotaTool = createAgyQuotaTool({
|
|
20745
|
+
client: void 0,
|
|
20746
|
+
getAuthResolver: () => void 0,
|
|
20747
|
+
getConfiguredProjectId: () => void 0,
|
|
20748
|
+
getUserAgentModel: () => void 0
|
|
20749
|
+
});
|
|
20750
|
+
const quotaSummaryTool = createAgyQuotaSummaryTool({
|
|
20751
|
+
client: void 0,
|
|
20752
|
+
getAuthResolver: () => void 0,
|
|
20753
|
+
getConfiguredProjectId: () => void 0,
|
|
20754
|
+
getUserAgentModel: () => void 0
|
|
20755
|
+
});
|
|
20756
|
+
if (typeof editor.add === "function") {
|
|
20757
|
+
editor.add({
|
|
20758
|
+
name: AGY_QUOTA_TOOL_NAME,
|
|
20759
|
+
description: quotaTool.description,
|
|
20760
|
+
input: {},
|
|
20761
|
+
execute: async (args, context) => quotaTool.execute(args, context)
|
|
20762
|
+
});
|
|
20763
|
+
editor.add({
|
|
20764
|
+
name: AGY_QUOTA_SUMMARY_TOOL_NAME,
|
|
20765
|
+
description: quotaSummaryTool.description,
|
|
20766
|
+
input: {},
|
|
20767
|
+
execute: async (args, context) => quotaSummaryTool.execute(args, context)
|
|
20768
|
+
});
|
|
20769
|
+
} else if (typeof editor.set === "function") {
|
|
20770
|
+
editor.set(AGY_QUOTA_TOOL_NAME, quotaTool);
|
|
20771
|
+
editor.set(AGY_QUOTA_SUMMARY_TOOL_NAME, quotaSummaryTool);
|
|
20772
|
+
} else if (editor.tools && typeof editor.tools === "object") {
|
|
20773
|
+
editor.tools[AGY_QUOTA_TOOL_NAME] = quotaTool;
|
|
20774
|
+
editor.tools[AGY_QUOTA_SUMMARY_TOOL_NAME] = quotaSummaryTool;
|
|
20775
|
+
} else if (typeof editor === "object") {
|
|
20776
|
+
editor[AGY_QUOTA_TOOL_NAME] = quotaTool;
|
|
20777
|
+
editor[AGY_QUOTA_SUMMARY_TOOL_NAME] = quotaSummaryTool;
|
|
20778
|
+
}
|
|
20779
|
+
});
|
|
20780
|
+
ctx.command.transform(async (editor) => {
|
|
20781
|
+
if (!editor) return;
|
|
20782
|
+
const commands = {
|
|
20783
|
+
[AGY_V2_QUOTA_COMMAND]: {
|
|
20784
|
+
description: "Show Agy Code Assist quota usage",
|
|
20785
|
+
template: AGY_V2_QUOTA_COMMAND_TEMPLATE
|
|
20786
|
+
},
|
|
20787
|
+
[AGY_V2_QUOTA_SUMMARY_COMMAND]: {
|
|
20788
|
+
description: "Show Agy Code Assist quota summary with weekly and 5-hour limits",
|
|
20789
|
+
template: AGY_V2_QUOTA_SUMMARY_COMMAND_TEMPLATE
|
|
20790
|
+
}
|
|
20791
|
+
};
|
|
20792
|
+
if (typeof editor.add === "function") {
|
|
20793
|
+
editor.add({
|
|
20794
|
+
name: AGY_V2_QUOTA_COMMAND,
|
|
20795
|
+
description: "Display current Antigravity quota usage",
|
|
20796
|
+
template: AGY_V2_QUOTA_COMMAND_TEMPLATE
|
|
20797
|
+
});
|
|
20798
|
+
editor.add({
|
|
20799
|
+
name: AGY_V2_QUOTA_SUMMARY_COMMAND,
|
|
20800
|
+
description: "Display Antigravity quota summary grouped by model family",
|
|
20801
|
+
template: AGY_V2_QUOTA_SUMMARY_COMMAND_TEMPLATE
|
|
20802
|
+
});
|
|
20803
|
+
} else if (typeof editor.set === "function") {
|
|
20804
|
+
editor.set(AGY_V2_QUOTA_COMMAND, commands[AGY_V2_QUOTA_COMMAND]);
|
|
20805
|
+
editor.set(AGY_V2_QUOTA_SUMMARY_COMMAND, commands[AGY_V2_QUOTA_SUMMARY_COMMAND]);
|
|
20806
|
+
} else if (editor.commands && typeof editor.commands === "object") {
|
|
20807
|
+
editor.commands[AGY_V2_QUOTA_COMMAND] = commands[AGY_V2_QUOTA_COMMAND];
|
|
20808
|
+
editor.commands[AGY_V2_QUOTA_SUMMARY_COMMAND] = commands[AGY_V2_QUOTA_SUMMARY_COMMAND];
|
|
20809
|
+
} else if (typeof editor === "object") {
|
|
20810
|
+
editor[AGY_V2_QUOTA_COMMAND] = commands[AGY_V2_QUOTA_COMMAND];
|
|
20811
|
+
editor[AGY_V2_QUOTA_SUMMARY_COMMAND] = commands[AGY_V2_QUOTA_SUMMARY_COMMAND];
|
|
20812
|
+
}
|
|
20813
|
+
});
|
|
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;
|
|
20836
|
+
}
|
|
20837
|
+
}
|
|
20838
|
+
});
|
|
20839
|
+
ctx.session.hook("http.response", async (event) => {
|
|
20840
|
+
if (!event) return;
|
|
20841
|
+
if (event.response?.status === 429) {
|
|
20842
|
+
return;
|
|
20843
|
+
}
|
|
20844
|
+
});
|
|
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;
|
|
20853
|
+
} else {
|
|
20854
|
+
event.retryDelayMs = await resolveRetryDelayMs(response, event.attempt || 1);
|
|
20855
|
+
}
|
|
20856
|
+
}
|
|
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;
|
|
20865
|
+
}
|
|
20866
|
+
}
|
|
20867
|
+
}
|
|
20868
|
+
});
|
|
20869
|
+
}
|
|
20870
|
+
var v2PluginDefinition = defineOpenCodeV2Plugin({
|
|
20871
|
+
id: AGY_PROVIDER_ID,
|
|
20872
|
+
setup: setupOpenCodeV2
|
|
20873
|
+
});
|
|
20874
|
+
|
|
20655
20875
|
// index.ts
|
|
20656
|
-
var
|
|
20657
|
-
|
|
20876
|
+
var dualPlugin = {
|
|
20877
|
+
...v2PluginDefinition,
|
|
20658
20878
|
server: AgyCLIOAuthPlugin
|
|
20659
20879
|
};
|
|
20880
|
+
var index_default = dualPlugin;
|
|
20660
20881
|
export {
|
|
20661
20882
|
AgyCLIOAuthPlugin,
|
|
20662
20883
|
GoogleOAuthPlugin,
|
|
20663
|
-
index_default as default
|
|
20884
|
+
index_default as default,
|
|
20885
|
+
defineOpenCodeV2Plugin,
|
|
20886
|
+
setupOpenCodeV2,
|
|
20887
|
+
v2PluginDefinition
|
|
20664
20888
|
};
|
|
20665
20889
|
//# sourceMappingURL=index.js.map
|