@anthonyhaussman/opencode-agy-auth 1.2.2 → 1.2.3-alpha.0

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 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
- declare const _default: {
4
- id: string;
5
- server: typeof AgyCLIOAuthPlugin;
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,178 @@ 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 (catalog) => {
20681
+ if (!catalog) return;
20682
+ catalog.providers = catalog.providers || {};
20683
+ catalog.providers[AGY_PROVIDER_ID] = {
20684
+ id: AGY_PROVIDER_ID,
20685
+ name: "Antigravity CLI",
20686
+ npm: "@ai-sdk/google",
20687
+ models: { ...catalog.providers[AGY_PROVIDER_ID]?.models || {} },
20688
+ ...catalog.providers[AGY_PROVIDER_ID]
20689
+ };
20690
+ const targetModels = catalog.providers[AGY_PROVIDER_ID].models;
20691
+ for (const [modelId, simple] of Object.entries(STATIC_MODELS_SIMPLE)) {
20692
+ const isClaude = modelId.startsWith("claude-");
20693
+ const isGpt = modelId.startsWith("gpt-");
20694
+ targetModels[modelId] = {
20695
+ id: modelId,
20696
+ providerID: AGY_PROVIDER_ID,
20697
+ name: simple.name,
20698
+ description: simple.description,
20699
+ family: modelId.includes("gemini") ? "gemini" : isClaude ? "claude" : isGpt ? "gpt" : "unknown",
20700
+ reasoning: simple.reasoning,
20701
+ attachment: simple.attachment,
20702
+ tool_call: simple.toolCall,
20703
+ limit: {
20704
+ context: simple.maxTokens,
20705
+ output: simple.maxOutputTokens
20706
+ },
20707
+ cost: simple.cost || { input: 0, output: 0 },
20708
+ ...targetModels[modelId] || {}
20709
+ };
20710
+ }
20711
+ });
20712
+ ctx.tool.transform(async (editor) => {
20713
+ if (!editor) return;
20714
+ const quotaTool = createAgyQuotaTool({
20715
+ client: void 0,
20716
+ getAuthResolver: () => void 0,
20717
+ getConfiguredProjectId: () => void 0,
20718
+ getUserAgentModel: () => void 0
20719
+ });
20720
+ const quotaSummaryTool = createAgyQuotaSummaryTool({
20721
+ client: void 0,
20722
+ getAuthResolver: () => void 0,
20723
+ getConfiguredProjectId: () => void 0,
20724
+ getUserAgentModel: () => void 0
20725
+ });
20726
+ if (typeof editor.set === "function") {
20727
+ editor.set(AGY_QUOTA_TOOL_NAME, quotaTool);
20728
+ editor.set(AGY_QUOTA_SUMMARY_TOOL_NAME, quotaSummaryTool);
20729
+ } else if (editor.tools && typeof editor.tools === "object") {
20730
+ editor.tools[AGY_QUOTA_TOOL_NAME] = quotaTool;
20731
+ editor.tools[AGY_QUOTA_SUMMARY_TOOL_NAME] = quotaSummaryTool;
20732
+ } else if (typeof editor === "object") {
20733
+ editor[AGY_QUOTA_TOOL_NAME] = quotaTool;
20734
+ editor[AGY_QUOTA_SUMMARY_TOOL_NAME] = quotaSummaryTool;
20735
+ }
20736
+ });
20737
+ ctx.command.transform(async (editor) => {
20738
+ if (!editor) return;
20739
+ const commands = {
20740
+ [AGY_V2_QUOTA_COMMAND]: {
20741
+ description: "Show Agy Code Assist quota usage",
20742
+ template: AGY_V2_QUOTA_COMMAND_TEMPLATE
20743
+ },
20744
+ [AGY_V2_QUOTA_SUMMARY_COMMAND]: {
20745
+ description: "Show Agy Code Assist quota summary with weekly and 5-hour limits",
20746
+ template: AGY_V2_QUOTA_SUMMARY_COMMAND_TEMPLATE
20747
+ }
20748
+ };
20749
+ if (typeof editor.set === "function") {
20750
+ editor.set(AGY_V2_QUOTA_COMMAND, commands[AGY_V2_QUOTA_COMMAND]);
20751
+ editor.set(AGY_V2_QUOTA_SUMMARY_COMMAND, commands[AGY_V2_QUOTA_SUMMARY_COMMAND]);
20752
+ } else if (editor.commands && typeof editor.commands === "object") {
20753
+ editor.commands[AGY_V2_QUOTA_COMMAND] = commands[AGY_V2_QUOTA_COMMAND];
20754
+ editor.commands[AGY_V2_QUOTA_SUMMARY_COMMAND] = commands[AGY_V2_QUOTA_SUMMARY_COMMAND];
20755
+ } else if (typeof editor === "object") {
20756
+ editor[AGY_V2_QUOTA_COMMAND] = commands[AGY_V2_QUOTA_COMMAND];
20757
+ editor[AGY_V2_QUOTA_SUMMARY_COMMAND] = commands[AGY_V2_QUOTA_SUMMARY_COMMAND];
20758
+ }
20759
+ });
20760
+ ctx.session.hook("http.request", async (event) => {
20761
+ if (!event) return;
20762
+ const url2 = typeof event.url === "string" ? event.url : event.request?.url || "";
20763
+ const isGL = isGenerativeLanguageRequest(url2);
20764
+ const isInternal = url2.includes("cloudcode-pa.googleapis.com");
20765
+ if (!isGL && !isInternal) {
20766
+ return;
20767
+ }
20768
+ event.headers = event.headers || {};
20769
+ let modelName;
20770
+ if (isGL) {
20771
+ const parsed = parseGenerativeLanguageRequest(url2);
20772
+ modelName = parsed?.effectiveModel;
20773
+ }
20774
+ const userAgent = buildAgyCliUserAgent(modelName);
20775
+ if (typeof event.headers.set === "function") {
20776
+ if (!event.headers.get("User-Agent")) {
20777
+ event.headers.set("User-Agent", userAgent);
20778
+ }
20779
+ } else {
20780
+ if (!event.headers["User-Agent"] && !event.headers["user-agent"]) {
20781
+ event.headers["User-Agent"] = userAgent;
20782
+ }
20783
+ }
20784
+ });
20785
+ ctx.session.hook("http.response", async (event) => {
20786
+ if (!event) return;
20787
+ if (event.response?.status === 429) {
20788
+ return;
20789
+ }
20790
+ });
20791
+ ctx.session.hook("retry", async (event) => {
20792
+ if (!event) return;
20793
+ const response = event.response;
20794
+ if (response instanceof Response) {
20795
+ if (response.status === 429 || response.status === 503) {
20796
+ const quota = await classifyQuotaResponse(response);
20797
+ if (quota?.retryDelayMs) {
20798
+ event.retryDelayMs = quota.retryDelayMs;
20799
+ } else {
20800
+ event.retryDelayMs = await resolveRetryDelayMs(response, event.attempt || 1);
20801
+ }
20802
+ }
20803
+ } else if (event.details && Array.isArray(event.details)) {
20804
+ const retryInfo = event.details.find(
20805
+ (d) => d && d["@type"] === "type.googleapis.com/google.rpc.RetryInfo"
20806
+ );
20807
+ if (retryInfo?.retryDelay) {
20808
+ const delayMs = retryInternals.parseRetryDelayValue(retryInfo.retryDelay);
20809
+ if (delayMs !== null) {
20810
+ event.retryDelayMs = delayMs;
20811
+ }
20812
+ }
20813
+ }
20814
+ });
20815
+ }
20816
+ var v2PluginDefinition = defineOpenCodeV2Plugin({
20817
+ id: AGY_PROVIDER_ID,
20818
+ setup: setupOpenCodeV2
20819
+ });
20820
+
20655
20821
  // index.ts
20656
- var index_default = {
20657
- id: "@anthonyhaussman/opencode-agy-auth",
20822
+ var dualPlugin = {
20823
+ ...v2PluginDefinition,
20658
20824
  server: AgyCLIOAuthPlugin
20659
20825
  };
20826
+ var index_default = dualPlugin;
20660
20827
  export {
20661
20828
  AgyCLIOAuthPlugin,
20662
20829
  GoogleOAuthPlugin,
20663
- index_default as default
20830
+ index_default as default,
20831
+ defineOpenCodeV2Plugin,
20832
+ setupOpenCodeV2,
20833
+ v2PluginDefinition
20664
20834
  };
20665
20835
  //# sourceMappingURL=index.js.map