forked from NoeFabris/opencode-antigravity-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
111 lines (93 loc) · 2.45 KB
/
Copy pathtypes.ts
File metadata and controls
111 lines (93 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import type { PluginInput } from "@opencode-ai/plugin";
import type { AntigravityTokenExchangeResult } from "../antigravity/oauth";
export interface OAuthAuthDetails {
type: "oauth";
refresh: string;
access?: string;
expires?: number;
}
export interface ApiKeyAuthDetails {
type: "api_key";
key: string;
}
export interface NonOAuthAuthDetails {
type: string;
[key: string]: unknown;
}
export type AuthDetails = OAuthAuthDetails | ApiKeyAuthDetails | NonOAuthAuthDetails;
export type GetAuth = () => Promise<AuthDetails>;
export interface ProviderModel {
cost?: {
input: number;
output: number;
};
[key: string]: unknown;
}
export interface Provider {
models?: Record<string, ProviderModel>;
}
export interface LoaderResult {
apiKey: string;
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
}
export type PluginClient = PluginInput["client"];
export interface PluginContext {
client: PluginClient;
directory: string;
}
export type AuthPrompt =
| {
type: "text";
key: string;
message: string;
placeholder?: string;
validate?: (value: string) => string | undefined;
condition?: (inputs: Record<string, string>) => boolean;
}
| {
type: "select";
key: string;
message: string;
options: Array<{ label: string; value: string; hint?: string }>;
condition?: (inputs: Record<string, string>) => boolean;
};
export type OAuthAuthorizationResult = { url: string; instructions: string } & (
| {
method: "auto";
callback: () => Promise<AntigravityTokenExchangeResult>;
}
| {
method: "code";
callback: (code: string) => Promise<AntigravityTokenExchangeResult>;
}
);
export interface AuthMethod {
provider?: string;
label: string;
type: "oauth" | "api";
prompts?: AuthPrompt[];
authorize?: (inputs?: Record<string, string>) => Promise<OAuthAuthorizationResult>;
}
export interface PluginEventPayload {
event: {
type: string;
properties?: unknown;
};
}
export interface PluginResult {
auth: {
provider: string;
loader: (getAuth: GetAuth, provider: Provider) => Promise<LoaderResult | Record<string, unknown>>;
methods: AuthMethod[];
};
event?: (payload: PluginEventPayload) => void;
}
export interface RefreshParts {
refreshToken: string;
projectId?: string;
managedProjectId?: string;
}
export interface ProjectContextResult {
auth: OAuthAuthDetails;
effectiveProjectId: string;
}