@anthonyhaussman/opencode-agy-auth 1.1.1 → 1.1.2-beta.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/dist/index.d.ts +4 -18
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/src/constants.d.ts +7 -0
- package/dist/src/fetch.d.ts +1 -0
- package/dist/src/plugin/auth.d.ts +14 -0
- package/dist/src/plugin/cache.d.ts +28 -0
- package/dist/src/plugin/notify.d.ts +9 -0
- package/dist/src/plugin/oauth-authorize.d.ts +15 -0
- package/dist/src/plugin/project/context.d.ts +13 -0
- package/dist/src/plugin/project/index.d.ts +2 -0
- package/dist/src/plugin/project/types.d.ts +84 -0
- package/dist/src/plugin/project/utils.d.ts +35 -0
- package/dist/src/plugin/provider.d.ts +12 -0
- package/dist/src/plugin/quota-summary.d.ts +14 -0
- package/dist/src/plugin/quota-utils.d.ts +5 -0
- package/dist/src/plugin/quota.d.ts +14 -0
- package/dist/src/plugin/token.d.ts +2 -0
- package/dist/src/plugin/traffic.d.ts +47 -0
- package/dist/src/plugin/types.d.ts +31 -0
- package/dist/src/plugin.d.ts +6 -0
- package/dist/src/sdk/activity-request-id.d.ts +5 -0
- package/dist/src/sdk/agy-cli-version.d.ts +1 -0
- package/dist/src/sdk/cache/signature-cache.d.ts +130 -0
- package/dist/src/sdk/chat-logger.d.ts +8 -0
- package/dist/src/sdk/fetch_models.d.ts +47 -0
- package/dist/src/sdk/fetch_project.d.ts +9 -0
- package/dist/src/sdk/fetch_quota.d.ts +9 -0
- package/dist/src/sdk/oauth.d.ts +26 -0
- package/dist/src/sdk/request/identifiers.d.ts +16 -0
- package/dist/src/sdk/request/index.d.ts +11 -0
- package/dist/src/sdk/request/openai.d.ts +16 -0
- package/dist/src/sdk/request/prepare.d.ts +14 -0
- package/dist/src/sdk/request/response.d.ts +5 -0
- package/dist/src/sdk/request/shared.d.ts +20 -0
- package/dist/src/sdk/request/thinking.d.ts +129 -0
- package/dist/src/sdk/request/turn-state-tracker.d.ts +21 -0
- package/dist/src/sdk/request-helpers/errors.d.ts +9 -0
- package/dist/src/sdk/request-helpers/index.d.ts +4 -0
- package/dist/src/sdk/request-helpers/parsing.d.ts +9 -0
- package/dist/src/sdk/request-helpers/thinking.d.ts +5 -0
- package/dist/src/sdk/request-helpers/types.d.ts +65 -0
- package/dist/src/sdk/retry/cooldown-store.d.ts +14 -0
- package/dist/src/sdk/retry/helpers.d.ts +19 -0
- package/dist/src/sdk/retry/index.d.ts +9 -0
- package/dist/src/sdk/retry/quota.d.ts +28 -0
- package/dist/src/sdk/terminal-hyperlink.d.ts +3 -0
- package/dist/src/sdk/user-agent.d.ts +5 -0
- package/package.json +5 -5
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const AGY_PROVIDER_ID = "google-agy";
|
|
2
|
+
export declare const AGY_CLIENT_ID = "1071006060591-tmhssin2h21lcre235vtolojh4g403ep.apps.googleusercontent.com";
|
|
3
|
+
export declare const AGY_CLIENT_SECRET = "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";
|
|
4
|
+
export declare const AGY_SCOPES: readonly string[];
|
|
5
|
+
export declare const AGY_REDIRECT_URI = "https://antigravity.google/oauth-callback";
|
|
6
|
+
export declare const AGY_CODE_ASSIST_ENDPOINT: string;
|
|
7
|
+
export declare const AGY_GENERATIVE_LANGUAGE_ENDPOINT = "https://generativelanguage.googleapis.com/v1beta";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function agyFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AuthDetails, OAuthAuthDetails, RefreshParts } from './types';
|
|
2
|
+
export declare function isOAuthAuth(auth: AuthDetails): auth is OAuthAuthDetails;
|
|
3
|
+
/**
|
|
4
|
+
* Splits the packed refresh string into the corresponding refresh token and project ID.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseRefreshParts(refresh: string): RefreshParts;
|
|
7
|
+
/**
|
|
8
|
+
* Serializes the parts of a refresh token into the stored string format.
|
|
9
|
+
*/
|
|
10
|
+
export declare function formatRefreshParts(parts: RefreshParts): string;
|
|
11
|
+
/**
|
|
12
|
+
* Determines whether the access token has expired or is missing, with a buffer for clock skew.
|
|
13
|
+
*/
|
|
14
|
+
export declare function accessTokenExpired(auth: OAuthAuthDetails): boolean;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { OAuthAuthDetails } from "./types";
|
|
2
|
+
import { SignatureCache, type SignatureCacheConfig } from "../sdk/cache/signature-cache";
|
|
3
|
+
/**
|
|
4
|
+
* Extracts valid OAuthAuthDetails from cache. Reuses an available and unexpired Token if present, otherwise prioritizes the latest provided value.
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolveCachedAuth(auth: OAuthAuthDetails): OAuthAuthDetails;
|
|
7
|
+
/**
|
|
8
|
+
* Explicitly updates or saves authorized token details to the cache.
|
|
9
|
+
*/
|
|
10
|
+
export declare function storeCachedAuth(auth: OAuthAuthDetails): void;
|
|
11
|
+
/**
|
|
12
|
+
* Clears cached login authorization details. If no refresh token is provided, clears the global cache.
|
|
13
|
+
*/
|
|
14
|
+
export declare function clearCachedAuth(refresh?: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* Initializes the disk-level signature storage manager.
|
|
17
|
+
*/
|
|
18
|
+
export declare function initDiskSignatureCache(config: SignatureCacheConfig | undefined): SignatureCache | null;
|
|
19
|
+
/**
|
|
20
|
+
* Caches a thought chain fragment and its corresponding service signature, synchronously saving it to disk.
|
|
21
|
+
*/
|
|
22
|
+
export declare function cacheSignature(sessionId: string, text: string, signature: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Recovers and retrieves the most recently cached signature for a session (supports signature recovery).
|
|
25
|
+
*/
|
|
26
|
+
export declare function getLatestSignature(sessionId: string): string | undefined;
|
|
27
|
+
export type { SignatureCache } from "../sdk/cache/signature-cache";
|
|
28
|
+
export type { SignatureCacheConfig } from "../sdk/cache/signature-cache";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PluginClient } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Shows a Toast notification to the user when the server-side Agy model capacity is exhausted.
|
|
4
|
+
*/
|
|
5
|
+
export declare function maybeShowAgyCapacityToast(client: PluginClient, response: Response, projectId: string, requestedModel?: string): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* Temporary smoke test Toast, only enabled when OPENCODE_AGY_TEST_TOAST=1.
|
|
8
|
+
*/
|
|
9
|
+
export declare function maybeShowAgyTestToast(client: PluginClient, projectId: string): Promise<void>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AgyTokenExchangeResult } from '../sdk/oauth';
|
|
2
|
+
import type { PluginClient } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Builds the OAuth authorization callback for the plugin authentication method.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createOAuthAuthorizeMethod(options?: {
|
|
7
|
+
client?: PluginClient;
|
|
8
|
+
getConfiguredProjectId?: () => Promise<string | undefined> | string | undefined;
|
|
9
|
+
getUserAgentModel?: () => Promise<string | undefined> | string | undefined;
|
|
10
|
+
}): () => Promise<{
|
|
11
|
+
url: string;
|
|
12
|
+
instructions: string;
|
|
13
|
+
method: 'code';
|
|
14
|
+
callback: (callbackUrl: string) => Promise<AgyTokenExchangeResult>;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { OAuthAuthDetails, PluginClient, ProjectContextResult } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Clears cached project context results and pending Promises.
|
|
4
|
+
*/
|
|
5
|
+
export declare function invalidateProjectContextCache(refresh?: string): void;
|
|
6
|
+
/**
|
|
7
|
+
* Resolves the project context corresponding to the access token, optionally persisting updated auth details.
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveProjectContextFromAccessToken(auth: OAuthAuthDetails, accessToken: string, configuredProjectId?: string, persistAuth?: (auth: OAuthAuthDetails) => Promise<void>, userAgentModel?: string): Promise<ProjectContextResult>;
|
|
10
|
+
/**
|
|
11
|
+
* Resolves the effective project ID for the current auth state and caches the result by refresh token.
|
|
12
|
+
*/
|
|
13
|
+
export declare function ensureProjectContext(auth: OAuthAuthDetails, client: PluginClient, configuredProjectId?: string, userAgentModel?: string): Promise<ProjectContextResult>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export declare const FREE_TIER_ID = "free-tier";
|
|
2
|
+
export declare const LEGACY_TIER_ID = "legacy-tier";
|
|
3
|
+
export declare const CODE_ASSIST_METADATA: {
|
|
4
|
+
readonly ideType: "ANTIGRAVITY";
|
|
5
|
+
};
|
|
6
|
+
export interface AgyUserTier {
|
|
7
|
+
id?: string;
|
|
8
|
+
isDefault?: boolean;
|
|
9
|
+
userDefinedCloudaicompanionProject?: boolean;
|
|
10
|
+
name?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface CloudAiCompanionProject {
|
|
14
|
+
id?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface AgyIneligibleTier {
|
|
17
|
+
reasonCode?: string;
|
|
18
|
+
reasonMessage?: string;
|
|
19
|
+
validationUrl?: string;
|
|
20
|
+
validationLearnMoreUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface LoadCodeAssistPayload {
|
|
23
|
+
cloudaicompanionProject?: string | CloudAiCompanionProject;
|
|
24
|
+
currentTier?: {
|
|
25
|
+
id?: string;
|
|
26
|
+
name?: string;
|
|
27
|
+
};
|
|
28
|
+
allowedTiers?: AgyUserTier[];
|
|
29
|
+
ineligibleTiers?: AgyIneligibleTier[];
|
|
30
|
+
}
|
|
31
|
+
export interface OnboardUserPayload {
|
|
32
|
+
name?: string;
|
|
33
|
+
done?: boolean;
|
|
34
|
+
response?: {
|
|
35
|
+
cloudaicompanionProject?: {
|
|
36
|
+
id?: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface RetrieveUserQuotaBucket {
|
|
41
|
+
remainingAmount?: string;
|
|
42
|
+
remainingFraction?: number;
|
|
43
|
+
resetTime?: string;
|
|
44
|
+
tokenType?: string;
|
|
45
|
+
modelId?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface RetrieveUserQuotaResponse {
|
|
48
|
+
buckets?: RetrieveUserQuotaBucket[];
|
|
49
|
+
}
|
|
50
|
+
export interface QuotaSummaryBucket {
|
|
51
|
+
bucketId?: string;
|
|
52
|
+
displayName?: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
window?: string;
|
|
55
|
+
remaining?: string;
|
|
56
|
+
remainingFraction?: number;
|
|
57
|
+
remainingAmount?: string;
|
|
58
|
+
disabled?: boolean;
|
|
59
|
+
resetTime?: string;
|
|
60
|
+
}
|
|
61
|
+
export interface QuotaSummaryGroup {
|
|
62
|
+
displayName?: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
buckets?: QuotaSummaryBucket[];
|
|
65
|
+
}
|
|
66
|
+
export interface RetrieveUserQuotaSummaryResponse {
|
|
67
|
+
groups?: QuotaSummaryGroup[];
|
|
68
|
+
buckets?: QuotaSummaryBucket[];
|
|
69
|
+
description?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Thrown during Gemini enablement if the required Google Cloud project is missing.
|
|
73
|
+
*/
|
|
74
|
+
export declare class ProjectIdRequiredError extends Error {
|
|
75
|
+
constructor();
|
|
76
|
+
}
|
|
77
|
+
export declare class ProjectAccessDeniedError extends Error {
|
|
78
|
+
constructor(projectId: string | undefined, backendMessage: string | undefined);
|
|
79
|
+
}
|
|
80
|
+
export declare class AccountValidationRequiredError extends Error {
|
|
81
|
+
validationUrl?: string;
|
|
82
|
+
validationLearnMoreUrl?: string;
|
|
83
|
+
constructor(message: string, validationUrl?: string, validationLearnMoreUrl?: string);
|
|
84
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { OAuthAuthDetails } from "../types";
|
|
2
|
+
import { type CloudAiCompanionProject, type AgyIneligibleTier, type AgyUserTier } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Builds the metadata headers required for the Code Assist API.
|
|
5
|
+
*/
|
|
6
|
+
export declare function buildMetadata(projectId?: string, includeDuetProject?: boolean): Record<string, string>;
|
|
7
|
+
/**
|
|
8
|
+
* Normalizes project identifiers from API payloads or configuration.
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizeProjectId(value?: string | CloudAiCompanionProject): string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Selects the default hierarchy ID from the allowed hierarchy list.
|
|
13
|
+
*/
|
|
14
|
+
export declare function pickOnboardTier(allowedTiers?: AgyUserTier[]): AgyUserTier;
|
|
15
|
+
/**
|
|
16
|
+
* Builds a concise error message for non-compliant hierarchy payloads.
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildIneligibleTierMessage(tiers?: AgyIneligibleTier[]): string | undefined;
|
|
19
|
+
export declare function throwIfValidationRequired(tiers?: AgyIneligibleTier[]): void;
|
|
20
|
+
/**
|
|
21
|
+
* Detects VPC-SC errors from Cloud Code responses.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isVpcScError(payload: unknown): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Safely parses JSON, returning null on failure.
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseJsonSafe(text: string): unknown;
|
|
28
|
+
/**
|
|
29
|
+
* Promise-based delay utility.
|
|
30
|
+
*/
|
|
31
|
+
export declare function wait(ms: number): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Generates a cache key for the project context based on the refresh token.
|
|
34
|
+
*/
|
|
35
|
+
export declare function getCacheKey(auth: OAuthAuthDetails): string | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Config } from "./types";
|
|
2
|
+
import type { PluginClient, Provider } from "./types";
|
|
3
|
+
interface ResolveConfiguredProjectIdInput {
|
|
4
|
+
provider?: Provider | null;
|
|
5
|
+
config?: Config | null;
|
|
6
|
+
configProjectId?: string;
|
|
7
|
+
env?: NodeJS.ProcessEnv;
|
|
8
|
+
}
|
|
9
|
+
export declare function resolveConfiguredProjectId(input?: ResolveConfiguredProjectIdInput): string | undefined;
|
|
10
|
+
export declare function resolveConfiguredProjectIdFromConfig(config: Config | null | undefined): string | undefined;
|
|
11
|
+
export declare function resolveConfiguredProjectIdFromClient(client: PluginClient | null | undefined): Promise<string | undefined>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GetAuth, PluginClient } from "./types";
|
|
2
|
+
export declare const AGY_QUOTA_SUMMARY_TOOL_NAME = "agy_quota_summary";
|
|
3
|
+
interface AgyQuotaSummaryToolDependencies {
|
|
4
|
+
client: PluginClient;
|
|
5
|
+
getAuthResolver: () => GetAuth | undefined;
|
|
6
|
+
getConfiguredProjectId: () => string | undefined;
|
|
7
|
+
getUserAgentModel: () => string | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare function createAgyQuotaSummaryTool({ client, getAuthResolver, getConfiguredProjectId, getUserAgentModel, }: AgyQuotaSummaryToolDependencies): {
|
|
10
|
+
description: string;
|
|
11
|
+
args: {};
|
|
12
|
+
execute(args: Record<string, never>, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
2
|
+
export declare function pad(value: string, width: number): string;
|
|
3
|
+
export declare function buildProgressBar(fraction: number, width?: number): string;
|
|
4
|
+
export declare function formatRemainingAmount(value: string | undefined): string | undefined;
|
|
5
|
+
export declare function formatRelativeResetTime(resetTime: string | undefined): string | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GetAuth, PluginClient } from "./types";
|
|
2
|
+
export declare const AGY_QUOTA_TOOL_NAME = "agy_quota";
|
|
3
|
+
interface AgyQuotaToolDependencies {
|
|
4
|
+
client: PluginClient;
|
|
5
|
+
getAuthResolver: () => GetAuth | undefined;
|
|
6
|
+
getConfiguredProjectId: () => string | undefined;
|
|
7
|
+
getUserAgentModel: () => string | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare function createAgyQuotaTool({ client, getAuthResolver, getConfiguredProjectId, getUserAgentModel, }: AgyQuotaToolDependencies): {
|
|
10
|
+
description: string;
|
|
11
|
+
args: {};
|
|
12
|
+
execute(args: Record<string, never>, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simulates the experimental fetch and metric telemetry traffic sent periodically by the official Agy client in the background to prevent API bans or anomaly detection.
|
|
3
|
+
*/
|
|
4
|
+
export declare function simulateClientBackgroundTraffic(accessToken: string, projectId: string, userAgentModel?: string): void;
|
|
5
|
+
export declare function buildTrajectoryAnalyticsBody(cascadeId?: `${string}-${string}-${string}-${string}-${string}`, platform?: string): {
|
|
6
|
+
trajectory: {
|
|
7
|
+
cascadeId: `${string}-${string}-${string}-${string}-${string}`;
|
|
8
|
+
executorMetadatas: {
|
|
9
|
+
cascadeConfig: {
|
|
10
|
+
agentApiConfig: {
|
|
11
|
+
enabled: boolean;
|
|
12
|
+
};
|
|
13
|
+
checkpointConfig: {
|
|
14
|
+
checkpointModel: string;
|
|
15
|
+
strategy: string;
|
|
16
|
+
maxTokenLimit: string;
|
|
17
|
+
tokenThreshold: string;
|
|
18
|
+
maxOverheadRatio: string;
|
|
19
|
+
movingWindowSize: string;
|
|
20
|
+
enabled: boolean;
|
|
21
|
+
maxOutputTokens: string;
|
|
22
|
+
useLastPlannerModel: boolean;
|
|
23
|
+
isSync: boolean;
|
|
24
|
+
maxUserRequests: number;
|
|
25
|
+
includeLastUserMessage: boolean;
|
|
26
|
+
includeConversationLog: boolean;
|
|
27
|
+
includeRunningTaskSnapshots: boolean;
|
|
28
|
+
includeSubagentSnapshots: boolean;
|
|
29
|
+
includeArtifactSnapshots: boolean;
|
|
30
|
+
retryConfig: {
|
|
31
|
+
maxRetries: number;
|
|
32
|
+
initialSleepDurationMs: number;
|
|
33
|
+
exponentialMultiplier: number;
|
|
34
|
+
includeErrorFeedback: boolean;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}[];
|
|
39
|
+
};
|
|
40
|
+
mendelExperimentIds: never[];
|
|
41
|
+
metadata: {
|
|
42
|
+
ideType: string;
|
|
43
|
+
ideVersion: string;
|
|
44
|
+
platform: string;
|
|
45
|
+
};
|
|
46
|
+
startStepIndex: string;
|
|
47
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { OpencodeClient, Auth } from '@opencode-ai/sdk';
|
|
2
|
+
import type { Provider as ProviderV1 } from '@opencode-ai/sdk';
|
|
3
|
+
import type { Model as ModelV2 } from '@opencode-ai/sdk/v2';
|
|
4
|
+
import type { Hooks, Config as PluginConfig } from '@opencode-ai/plugin';
|
|
5
|
+
export type OAuthAuthDetails = Extract<Auth, {
|
|
6
|
+
type: 'oauth';
|
|
7
|
+
}>;
|
|
8
|
+
export type AuthDetails = Auth;
|
|
9
|
+
export type GetAuth = () => Promise<AuthDetails>;
|
|
10
|
+
export type Provider = ProviderV1;
|
|
11
|
+
export type ProviderModel = ModelV2;
|
|
12
|
+
export type Config = PluginConfig;
|
|
13
|
+
export interface LoaderResult {
|
|
14
|
+
apiKey: string;
|
|
15
|
+
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
|
|
16
|
+
}
|
|
17
|
+
export type PluginClient = OpencodeClient;
|
|
18
|
+
export interface PluginContext {
|
|
19
|
+
client: PluginClient;
|
|
20
|
+
}
|
|
21
|
+
export type PluginResult = Hooks;
|
|
22
|
+
export interface RefreshParts {
|
|
23
|
+
refreshToken: string;
|
|
24
|
+
projectId?: string;
|
|
25
|
+
managedProjectId?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ProjectContextResult {
|
|
28
|
+
auth: OAuthAuthDetails;
|
|
29
|
+
effectiveProjectId: string;
|
|
30
|
+
}
|
|
31
|
+
export type { Provider as ProviderV2, Model as ModelV2 } from '@opencode-ai/sdk/v2';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PluginContext, PluginResult } from './plugin/types';
|
|
2
|
+
/**
|
|
3
|
+
* Registers the Agy OAuth provider for Opencode.
|
|
4
|
+
*/
|
|
5
|
+
export declare const AgyCLIOAuthPlugin: ({ client }: PluginContext) => Promise<PluginResult>;
|
|
6
|
+
export declare const GoogleOAuthPlugin: typeof AgyCLIOAuthPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const AGY_CLI_VERSION = "1.1.2";
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NOTE: Special Design - Cross-turn signature disk-level persistent cache
|
|
3
|
+
* Google Agy / Gemini 2.5/3 thinking models introduce strict "Thought Signature Validation" restrictions:
|
|
4
|
+
* In multi-turn dialogues (especially with Tool calls), the next request must carry a context signature (thoughtSignature) exactly matching the previous API response.
|
|
5
|
+
* To avoid conversation crashes caused by the following:
|
|
6
|
+
* 1. IDE-side session lifecycle rebuilds, causing loss of in-memory signature states.
|
|
7
|
+
* 2. Concurrent packets from multi-turn Tool interactions disrupting the memory cache of signatures.
|
|
8
|
+
* We implement a disk cache layer here with a background thread that periodically flushes to disk. Using a combination of session ID (sessionId) and historical thought chain hash digest as the Key,
|
|
9
|
+
* it persists the signatures and thought chains. Even if the IDE restarts or turns split, it can pull back the latest matching signature to fulfill official validation constraints.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Signature cache configuration options
|
|
13
|
+
*/
|
|
14
|
+
export interface SignatureCacheConfig {
|
|
15
|
+
/** Whether to enable caching */
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
/** In-memory cache time-to-live (seconds) */
|
|
18
|
+
memory_ttl_seconds: number;
|
|
19
|
+
/** Disk cache time-to-live (seconds) */
|
|
20
|
+
disk_ttl_seconds: number;
|
|
21
|
+
/** Auto-save interval to disk (seconds) */
|
|
22
|
+
write_interval_seconds: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Cache runtime state and statistics
|
|
26
|
+
*/
|
|
27
|
+
interface CacheStats {
|
|
28
|
+
/** Memory hit count */
|
|
29
|
+
memoryHits: number;
|
|
30
|
+
/** Disk hit count */
|
|
31
|
+
diskHits: number;
|
|
32
|
+
/** Miss count */
|
|
33
|
+
misses: number;
|
|
34
|
+
/** Disk write count */
|
|
35
|
+
writes: number;
|
|
36
|
+
/** Total number of entries currently in memory */
|
|
37
|
+
memoryEntries: number;
|
|
38
|
+
/** Whether the cache is dirty (has unsaved data) */
|
|
39
|
+
dirty: boolean;
|
|
40
|
+
/** Whether disk storage is enabled */
|
|
41
|
+
diskEnabled: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Retrieve full thought chain cache data structure
|
|
45
|
+
*/
|
|
46
|
+
export interface ThinkingCacheData {
|
|
47
|
+
/** Thought chain text */
|
|
48
|
+
text: string;
|
|
49
|
+
/** Signature */
|
|
50
|
+
signature: string;
|
|
51
|
+
/** Associated tool ID list */
|
|
52
|
+
toolIds?: string[];
|
|
53
|
+
}
|
|
54
|
+
export declare class SignatureCache {
|
|
55
|
+
private cache;
|
|
56
|
+
private memoryTtlMs;
|
|
57
|
+
private diskTtlMs;
|
|
58
|
+
private writeIntervalMs;
|
|
59
|
+
private cacheFilePath;
|
|
60
|
+
private enabled;
|
|
61
|
+
private dirty;
|
|
62
|
+
private writeTimer;
|
|
63
|
+
private cleanupTimer;
|
|
64
|
+
private stats;
|
|
65
|
+
constructor(config: SignatureCacheConfig);
|
|
66
|
+
/**
|
|
67
|
+
* Generates a unique cache key based on session ID and model ID
|
|
68
|
+
*/
|
|
69
|
+
static makeKey(sessionId: string, modelId: string): string;
|
|
70
|
+
/**
|
|
71
|
+
* Stores a signature in cache (marks as dirty, awaits background disk write)
|
|
72
|
+
*/
|
|
73
|
+
store(key: string, signature: string): void;
|
|
74
|
+
/**
|
|
75
|
+
* Retrieves a signature from cache and updates hit stats
|
|
76
|
+
* Returns null if expired or missing
|
|
77
|
+
*/
|
|
78
|
+
retrieve(key: string): string | null;
|
|
79
|
+
/**
|
|
80
|
+
* Checks if a key is valid and unexpired in cache (without affecting stats)
|
|
81
|
+
*/
|
|
82
|
+
has(key: string): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Caches the full thought chain text content and signature
|
|
85
|
+
* Allows self-healing and recovery of historical thought blocks even if the context is subsequently compressed.
|
|
86
|
+
*/
|
|
87
|
+
storeThinking(key: string, thinkingText: string, signature: string, toolIds?: string[]): void;
|
|
88
|
+
/**
|
|
89
|
+
* Extracts full thought chain info from cache
|
|
90
|
+
*/
|
|
91
|
+
retrieveThinking(key: string): ThinkingCacheData | null;
|
|
92
|
+
/**
|
|
93
|
+
* Checks if full thought chain content exists for a key
|
|
94
|
+
*/
|
|
95
|
+
hasThinking(key: string): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Gets current cache stats and memory footprint
|
|
98
|
+
*/
|
|
99
|
+
getStats(): CacheStats;
|
|
100
|
+
/**
|
|
101
|
+
* Manually triggers immediate save to disk
|
|
102
|
+
*/
|
|
103
|
+
flush(): Promise<boolean>;
|
|
104
|
+
/**
|
|
105
|
+
* Graceful shutdown: stops all timers and flushes unsaved data to disk
|
|
106
|
+
*/
|
|
107
|
+
shutdown(): void;
|
|
108
|
+
/**
|
|
109
|
+
* Loads signature cache from disk and validates TTL state
|
|
110
|
+
*/
|
|
111
|
+
private loadFromDisk;
|
|
112
|
+
/**
|
|
113
|
+
* Synchronously saves memory cache to disk (using atomic write: temp file then rename)
|
|
114
|
+
* Merges with existing unexpired entries on disk during write
|
|
115
|
+
*/
|
|
116
|
+
private saveToDisk;
|
|
117
|
+
/**
|
|
118
|
+
* Starts timers for auto-saving and auto-cleaning expired memory entries
|
|
119
|
+
*/
|
|
120
|
+
private startBackgroundTasks;
|
|
121
|
+
/**
|
|
122
|
+
* Removes memory cache entries exceeding their TTL
|
|
123
|
+
*/
|
|
124
|
+
private cleanupExpired;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Instantiates signature cache object based on config. Returns null if disabled.
|
|
128
|
+
*/
|
|
129
|
+
export declare function createSignatureCache(config: SignatureCacheConfig | undefined): SignatureCache | null;
|
|
130
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface ChatLogger {
|
|
2
|
+
logRequest(url: string, method: string, headers: HeadersInit | undefined, body: BodyInit | null | undefined): void;
|
|
3
|
+
logResponseHeaders(status: number, statusText: string, headers: Headers): void;
|
|
4
|
+
logResponseBody(body: string): void;
|
|
5
|
+
createLoggingTransformStream(): TransformStream<Uint8Array, Uint8Array>;
|
|
6
|
+
close(): void;
|
|
7
|
+
}
|
|
8
|
+
export declare function createChatLogger(): ChatLogger | null;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export interface AvailableModelDetails {
|
|
2
|
+
displayName: string;
|
|
3
|
+
supportsImages?: boolean;
|
|
4
|
+
supportsThinking?: boolean;
|
|
5
|
+
thinkingBudget?: number;
|
|
6
|
+
minThinkingBudget?: number;
|
|
7
|
+
recommended?: boolean;
|
|
8
|
+
maxTokens?: number;
|
|
9
|
+
maxOutputTokens?: number;
|
|
10
|
+
tokenizerType?: string;
|
|
11
|
+
quotaInfo?: {
|
|
12
|
+
remainingFraction?: number;
|
|
13
|
+
resetTime?: string;
|
|
14
|
+
};
|
|
15
|
+
model?: string;
|
|
16
|
+
apiProvider?: string;
|
|
17
|
+
modelProvider?: string;
|
|
18
|
+
supportsVideo?: boolean;
|
|
19
|
+
supportedMimeTypes?: Record<string, boolean>;
|
|
20
|
+
modelExperiments?: Record<string, unknown>;
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
export interface FetchAvailableModelsResponse {
|
|
24
|
+
models?: Record<string, AvailableModelDetails>;
|
|
25
|
+
defaultAgentModelId?: string;
|
|
26
|
+
agentModelSorts?: Array<{
|
|
27
|
+
displayName: string;
|
|
28
|
+
groups: Array<{
|
|
29
|
+
modelIds: string[];
|
|
30
|
+
}>;
|
|
31
|
+
}>;
|
|
32
|
+
commandModelIds?: string[];
|
|
33
|
+
tabModelIds?: string[];
|
|
34
|
+
imageGenerationModelIds?: string[];
|
|
35
|
+
mqueryModelIds?: string[];
|
|
36
|
+
webSearchModelIds?: string[];
|
|
37
|
+
deprecatedModelIds?: Record<string, unknown>;
|
|
38
|
+
commitMessageModelIds?: string[];
|
|
39
|
+
audioTranscriptionModelIds?: string[];
|
|
40
|
+
experimentIds?: number[];
|
|
41
|
+
tieredModelIds?: Record<string, string[]>;
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Fetches the list of available models for the current account under the specified project from the Agy server.
|
|
46
|
+
*/
|
|
47
|
+
export declare function fetchAvailableModels(accessToken: string, projectId: string, userAgentModel?: string): Promise<FetchAvailableModelsResponse>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type LoadCodeAssistPayload } from '../plugin/project/types';
|
|
2
|
+
/**
|
|
3
|
+
* Loads hosted project information for a given access token and optional project.
|
|
4
|
+
*/
|
|
5
|
+
export declare function loadManagedProject(accessToken: string, projectId?: string, userAgentModel?: string): Promise<LoadCodeAssistPayload | null>;
|
|
6
|
+
/**
|
|
7
|
+
* Enables a hosted project for the user, optionally retrying until complete.
|
|
8
|
+
*/
|
|
9
|
+
export declare function onboardManagedProject(accessToken: string, tierId: string, projectId?: string, userAgentModel?: string, attempts?: number, delayMs?: number): Promise<string | undefined>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RetrieveUserQuotaResponse, RetrieveUserQuotaSummaryResponse } from '../plugin/project/types';
|
|
2
|
+
/**
|
|
3
|
+
* Fetches the Code Assist quota bucket information, which contains the model IDs visible to the current account/project.
|
|
4
|
+
*/
|
|
5
|
+
export declare function retrieveUserQuota(accessToken: string, projectId: string, userAgentModel?: string): Promise<RetrieveUserQuotaResponse | null>;
|
|
6
|
+
/**
|
|
7
|
+
* Fetches the Code Assist quota summary, grouped by model family with window-based buckets.
|
|
8
|
+
*/
|
|
9
|
+
export declare function retrieveUserQuotaSummary(accessToken: string, projectId: string, userAgentModel?: string): Promise<RetrieveUserQuotaSummaryResponse | null>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface AgyAuthorization {
|
|
2
|
+
url: string;
|
|
3
|
+
verifier: string;
|
|
4
|
+
state: string;
|
|
5
|
+
}
|
|
6
|
+
interface AgyTokenExchangeSuccess {
|
|
7
|
+
type: 'success';
|
|
8
|
+
refresh: string;
|
|
9
|
+
access: string;
|
|
10
|
+
expires: number;
|
|
11
|
+
email?: string;
|
|
12
|
+
}
|
|
13
|
+
interface AgyTokenExchangeFailure {
|
|
14
|
+
type: 'failed';
|
|
15
|
+
error: string;
|
|
16
|
+
}
|
|
17
|
+
export type AgyTokenExchangeResult = AgyTokenExchangeSuccess | AgyTokenExchangeFailure;
|
|
18
|
+
/**
|
|
19
|
+
* Builds the Agy OAuth authorization URL with PKCE.
|
|
20
|
+
*/
|
|
21
|
+
export declare function authorizeAgy(): Promise<AgyAuthorization>;
|
|
22
|
+
/**
|
|
23
|
+
* Exchanges the authorization code for Agy using a known PKCE verifier.
|
|
24
|
+
*/
|
|
25
|
+
export declare function exchangeAgyWithVerifier(code: string, verifier: string): Promise<AgyTokenExchangeResult>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies canonical identifiers for wrapped Code Assist payloads.
|
|
3
|
+
*/
|
|
4
|
+
export declare function normalizeWrappedIdentifiers(wrapped: Record<string, unknown>): {
|
|
5
|
+
userPromptId: string;
|
|
6
|
+
sessionId: string;
|
|
7
|
+
requestId: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Applies canonical identifiers for unwrapped request payloads prior to wrapping.
|
|
11
|
+
*/
|
|
12
|
+
export declare function normalizeRequestPayloadIdentifiers(payload: Record<string, unknown>): {
|
|
13
|
+
userPromptId: string;
|
|
14
|
+
sessionId: string;
|
|
15
|
+
requestId: string;
|
|
16
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NOTE: The request module here handles serialization, deserialization, and streaming data conversion between the standard OpenAI protocol and Agy's native Gemini protocol.
|
|
3
|
+
* Though normally an app/adapter layer responsibility, it's highly coupled with Agy's exclusive SSE streaming deduplication and multi-turn signature caching,
|
|
4
|
+
* so to ensure a simple and clean external interface, we package it as a built-in SDK capability, shielding the upper layer from all protocol conversion internal complexities.
|
|
5
|
+
*/
|
|
6
|
+
export { prepareAgyRequest } from "./prepare";
|
|
7
|
+
export type { ThinkingConfigDefaults } from "./prepare";
|
|
8
|
+
export { transformAgyResponse } from "./response";
|
|
9
|
+
export { isGenerativeLanguageRequest, parseGenerativeLanguageRequest } from "./shared";
|
|
10
|
+
export { initTurnStateTracker, getTurnStateTracker, shutdownTurnStateTracker, TurnStateTracker } from "./turn-state-tracker";
|
|
11
|
+
export type { TurnState } from "./turn-state-tracker";
|