@anthonyhaussman/opencode-agy-auth 1.3.6-alpha.1 → 1.3.6-alpha.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/index.js +75 -11
- package/dist/index.js.map +1 -1
- package/dist/src/plugin/auth.d.ts +1 -1
- package/dist/src/plugin/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -340,7 +340,7 @@ function buildCodeAssistHeaders(accessToken, userAgentModel) {
|
|
|
340
340
|
// src/plugin/auth.ts
|
|
341
341
|
var ACCESS_TOKEN_EXPIRY_BUFFER_MS = 60 * 1e3;
|
|
342
342
|
function isOAuthAuth(auth) {
|
|
343
|
-
return auth.type === "oauth";
|
|
343
|
+
return Boolean(auth && auth.type === "oauth");
|
|
344
344
|
}
|
|
345
345
|
function parseRefreshParts(refresh) {
|
|
346
346
|
const [refreshToken = "", projectId = "", managedProjectId = ""] = (refresh ?? "").split("|");
|
|
@@ -21621,30 +21621,78 @@ async function setupOpenCodeV2(ctx) {
|
|
|
21621
21621
|
}
|
|
21622
21622
|
ctx.tool.transform(async (editor) => {
|
|
21623
21623
|
if (!editor) return;
|
|
21624
|
+
const v2Client = {
|
|
21625
|
+
auth: {
|
|
21626
|
+
set: async ({ body }) => {
|
|
21627
|
+
if (body) {
|
|
21628
|
+
saveStoredAuthToJson(body);
|
|
21629
|
+
}
|
|
21630
|
+
}
|
|
21631
|
+
}
|
|
21632
|
+
};
|
|
21633
|
+
const resolveV2Auth = () => {
|
|
21634
|
+
const connApi = ctx.integration?.connection;
|
|
21635
|
+
const stored = loadStoredAuthFromJson();
|
|
21636
|
+
if (!stored && typeof connApi?.active !== "function") {
|
|
21637
|
+
return void 0;
|
|
21638
|
+
}
|
|
21639
|
+
return async () => {
|
|
21640
|
+
if (typeof connApi?.active === "function" && typeof connApi?.resolve === "function") {
|
|
21641
|
+
try {
|
|
21642
|
+
const active = await connApi.active(AGY_PROVIDER_ID);
|
|
21643
|
+
if (active) {
|
|
21644
|
+
const resolved = await connApi.resolve(active);
|
|
21645
|
+
if (resolved?.type === "credential" && resolved.credential?.type === "oauth") {
|
|
21646
|
+
return {
|
|
21647
|
+
type: "oauth",
|
|
21648
|
+
access: resolved.credential.access,
|
|
21649
|
+
refresh: resolved.credential.refresh,
|
|
21650
|
+
expires: resolved.credential.expires
|
|
21651
|
+
};
|
|
21652
|
+
}
|
|
21653
|
+
}
|
|
21654
|
+
} catch {
|
|
21655
|
+
}
|
|
21656
|
+
}
|
|
21657
|
+
return loadStoredAuthFromJson();
|
|
21658
|
+
};
|
|
21659
|
+
};
|
|
21624
21660
|
const quotaTool = createAgyQuotaTool({
|
|
21625
|
-
client:
|
|
21626
|
-
getAuthResolver:
|
|
21661
|
+
client: v2Client,
|
|
21662
|
+
getAuthResolver: resolveV2Auth,
|
|
21627
21663
|
getConfiguredProjectId: () => void 0,
|
|
21628
21664
|
getUserAgentModel: () => void 0
|
|
21629
21665
|
});
|
|
21630
21666
|
const quotaSummaryTool = createAgyQuotaSummaryTool({
|
|
21631
|
-
client:
|
|
21632
|
-
getAuthResolver:
|
|
21667
|
+
client: v2Client,
|
|
21668
|
+
getAuthResolver: resolveV2Auth,
|
|
21633
21669
|
getConfiguredProjectId: () => void 0,
|
|
21634
21670
|
getUserAgentModel: () => void 0
|
|
21635
21671
|
});
|
|
21672
|
+
const emptyObjectSchema = {
|
|
21673
|
+
type: "object",
|
|
21674
|
+
properties: {},
|
|
21675
|
+
required: [],
|
|
21676
|
+
additionalProperties: false
|
|
21677
|
+
};
|
|
21636
21678
|
if (typeof editor.add === "function") {
|
|
21637
21679
|
editor.add({
|
|
21638
21680
|
name: AGY_QUOTA_TOOL_NAME,
|
|
21639
21681
|
description: quotaTool.description,
|
|
21640
|
-
input:
|
|
21641
|
-
execute: async (args, context) =>
|
|
21682
|
+
input: emptyObjectSchema,
|
|
21683
|
+
execute: async (args, context) => {
|
|
21684
|
+
const result = await quotaTool.execute(args, context);
|
|
21685
|
+
return typeof result === "string" ? { content: result } : result;
|
|
21686
|
+
}
|
|
21642
21687
|
});
|
|
21643
21688
|
editor.add({
|
|
21644
21689
|
name: AGY_QUOTA_SUMMARY_TOOL_NAME,
|
|
21645
21690
|
description: quotaSummaryTool.description,
|
|
21646
|
-
input:
|
|
21647
|
-
execute: async (args, context) =>
|
|
21691
|
+
input: emptyObjectSchema,
|
|
21692
|
+
execute: async (args, context) => {
|
|
21693
|
+
const result = await quotaSummaryTool.execute(args, context);
|
|
21694
|
+
return typeof result === "string" ? { content: result } : result;
|
|
21695
|
+
}
|
|
21648
21696
|
});
|
|
21649
21697
|
} else if (typeof editor.set === "function") {
|
|
21650
21698
|
editor.set(AGY_QUOTA_TOOL_NAME, quotaTool);
|
|
@@ -21673,12 +21721,28 @@ async function setupOpenCodeV2(ctx) {
|
|
|
21673
21721
|
editor.add({
|
|
21674
21722
|
name: AGY_V2_QUOTA_COMMAND,
|
|
21675
21723
|
description: "Display current Antigravity quota usage",
|
|
21676
|
-
template: AGY_V2_QUOTA_COMMAND_TEMPLATE
|
|
21724
|
+
template: AGY_V2_QUOTA_COMMAND_TEMPLATE,
|
|
21725
|
+
execute: async ({ sessionID, prompt, delivery } = {}) => {
|
|
21726
|
+
await ctx.session?.prompt?.({
|
|
21727
|
+
...prompt,
|
|
21728
|
+
sessionID,
|
|
21729
|
+
text: AGY_V2_QUOTA_COMMAND_TEMPLATE,
|
|
21730
|
+
delivery
|
|
21731
|
+
});
|
|
21732
|
+
}
|
|
21677
21733
|
});
|
|
21678
21734
|
editor.add({
|
|
21679
21735
|
name: AGY_V2_QUOTA_SUMMARY_COMMAND,
|
|
21680
21736
|
description: "Display Antigravity quota summary grouped by model family",
|
|
21681
|
-
template: AGY_V2_QUOTA_SUMMARY_COMMAND_TEMPLATE
|
|
21737
|
+
template: AGY_V2_QUOTA_SUMMARY_COMMAND_TEMPLATE,
|
|
21738
|
+
execute: async ({ sessionID, prompt, delivery } = {}) => {
|
|
21739
|
+
await ctx.session?.prompt?.({
|
|
21740
|
+
...prompt,
|
|
21741
|
+
sessionID,
|
|
21742
|
+
text: AGY_V2_QUOTA_SUMMARY_COMMAND_TEMPLATE,
|
|
21743
|
+
delivery
|
|
21744
|
+
});
|
|
21745
|
+
}
|
|
21682
21746
|
});
|
|
21683
21747
|
} else if (typeof editor.set === "function") {
|
|
21684
21748
|
editor.set(AGY_V2_QUOTA_COMMAND, commands[AGY_V2_QUOTA_COMMAND]);
|