dsh-antigravity-auth 0.1.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/CHANGELOG.md +28 -0
- package/LICENSE +21 -0
- package/README.md +168 -0
- package/README.zh.md +159 -0
- package/cordis.patch.yml +12 -0
- package/lib/capability-lifecycle--tgGKajs.js +1896 -0
- package/lib/client.cjs +2123 -0
- package/lib/client.cjs.map +1 -0
- package/lib/image.js +564 -0
- package/lib/index.js +176 -0
- package/lib/invariant.js +2 -0
- package/lib/live-gate-runner.js +542 -0
- package/lib/live-gates.js +97 -0
- package/lib/llm-adapter.js +916 -0
- package/lib/media-admission.js +206 -0
- package/lib/private-failure-B9vzUkQ7.js +23 -0
- package/lib/private-transport-urF138qW.js +641 -0
- package/lib/private-transport.js +2 -0
- package/lib/project-context.js +133 -0
- package/lib/quota.js +283 -0
- package/lib/replay.js +156 -0
- package/lib/rpc-contract-BFWfdKKs.js +491 -0
- package/lib/rpc-contract.js +2 -0
- package/lib/safe-text-AlEyN8q_.js +12 -0
- package/lib/search.js +259 -0
- package/lib/status-D0-em3Ru.js +125 -0
- package/lib/types/auth-service.d.ts +64 -0
- package/lib/types/auth-service.d.ts.map +1 -0
- package/lib/types/auth-store.d.ts +45 -0
- package/lib/types/auth-store.d.ts.map +1 -0
- package/lib/types/bootstrap-service.d.ts +6 -0
- package/lib/types/bootstrap-service.d.ts.map +1 -0
- package/lib/types/capability-gates.d.ts +19 -0
- package/lib/types/capability-gates.d.ts.map +1 -0
- package/lib/types/capability-lifecycle.d.ts +26 -0
- package/lib/types/capability-lifecycle.d.ts.map +1 -0
- package/lib/types/client/AntigravityAuthSettings.d.ts +19 -0
- package/lib/types/client/AntigravityAuthSettings.d.ts.map +1 -0
- package/lib/types/client/index.d.ts +18 -0
- package/lib/types/client/index.d.ts.map +1 -0
- package/lib/types/client/locales.d.ts +121 -0
- package/lib/types/client/locales.d.ts.map +1 -0
- package/lib/types/client/styles.d.ts +4 -0
- package/lib/types/client/styles.d.ts.map +1 -0
- package/lib/types/credential-coordinator.d.ts +84 -0
- package/lib/types/credential-coordinator.d.ts.map +1 -0
- package/lib/types/image.d.ts +39 -0
- package/lib/types/image.d.ts.map +1 -0
- package/lib/types/index.d.ts +21 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/invariant.d.ts +3 -0
- package/lib/types/invariant.d.ts.map +1 -0
- package/lib/types/live-gate-attachments.d.ts +6 -0
- package/lib/types/live-gate-attachments.d.ts.map +1 -0
- package/lib/types/live-gate-auth.d.ts +5 -0
- package/lib/types/live-gate-auth.d.ts.map +1 -0
- package/lib/types/live-gate-image.d.ts +5 -0
- package/lib/types/live-gate-image.d.ts.map +1 -0
- package/lib/types/live-gate-llm.d.ts +10 -0
- package/lib/types/live-gate-llm.d.ts.map +1 -0
- package/lib/types/live-gate-outcome.d.ts +8 -0
- package/lib/types/live-gate-outcome.d.ts.map +1 -0
- package/lib/types/live-gate-runner.d.ts +15 -0
- package/lib/types/live-gate-runner.d.ts.map +1 -0
- package/lib/types/live-gate-search.d.ts +5 -0
- package/lib/types/live-gate-search.d.ts.map +1 -0
- package/lib/types/live-gate-video.d.ts +8 -0
- package/lib/types/live-gate-video.d.ts.map +1 -0
- package/lib/types/live-gates.d.ts +25 -0
- package/lib/types/live-gates.d.ts.map +1 -0
- package/lib/types/llm-adapter.d.ts +65 -0
- package/lib/types/llm-adapter.d.ts.map +1 -0
- package/lib/types/login-types.d.ts +36 -0
- package/lib/types/login-types.d.ts.map +1 -0
- package/lib/types/media-admission.d.ts +54 -0
- package/lib/types/media-admission.d.ts.map +1 -0
- package/lib/types/model-catalog.d.ts +19 -0
- package/lib/types/model-catalog.d.ts.map +1 -0
- package/lib/types/oauth-flow.d.ts +87 -0
- package/lib/types/oauth-flow.d.ts.map +1 -0
- package/lib/types/private-failure.d.ts +6 -0
- package/lib/types/private-failure.d.ts.map +1 -0
- package/lib/types/private-transport-error.d.ts +13 -0
- package/lib/types/private-transport-error.d.ts.map +1 -0
- package/lib/types/private-transport.d.ts +48 -0
- package/lib/types/private-transport.d.ts.map +1 -0
- package/lib/types/project-context.d.ts +30 -0
- package/lib/types/project-context.d.ts.map +1 -0
- package/lib/types/quota.d.ts +43 -0
- package/lib/types/quota.d.ts.map +1 -0
- package/lib/types/raw-http.d.ts +11 -0
- package/lib/types/raw-http.d.ts.map +1 -0
- package/lib/types/replay.d.ts +30 -0
- package/lib/types/replay.d.ts.map +1 -0
- package/lib/types/rpc-contract.d.ts +33 -0
- package/lib/types/rpc-contract.d.ts.map +1 -0
- package/lib/types/rpc-vocabulary.d.ts +7 -0
- package/lib/types/rpc-vocabulary.d.ts.map +1 -0
- package/lib/types/rpc.d.ts +11 -0
- package/lib/types/rpc.d.ts.map +1 -0
- package/lib/types/safe-text.d.ts +3 -0
- package/lib/types/safe-text.d.ts.map +1 -0
- package/lib/types/search.d.ts +42 -0
- package/lib/types/search.d.ts.map +1 -0
- package/lib/types/status.d.ts +62 -0
- package/lib/types/status.d.ts.map +1 -0
- package/lib/types/video.d.ts +42 -0
- package/lib/types/video.d.ts.map +1 -0
- package/lib/types/wire-identity.d.ts +49 -0
- package/lib/types/wire-identity.d.ts.map +1 -0
- package/lib/video.js +320 -0
- package/lib/wire-identity.js +162 -0
- package/package.json +189 -0
- package/scripts/live-gates.mjs +4 -0
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import { t as isBoundedSafeText } from "./safe-text-AlEyN8q_.js";
|
|
2
|
+
import { r as CAPABILITY_ROW_IDS } from "./status-D0-em3Ru.js";
|
|
3
|
+
//#region src/login-types.ts
|
|
4
|
+
/** Browser-safe login state shared by the Host OAuth flow and settings RPC. */
|
|
5
|
+
const LOGIN_PHASES = [
|
|
6
|
+
"idle",
|
|
7
|
+
"pending",
|
|
8
|
+
"success",
|
|
9
|
+
"cancelled",
|
|
10
|
+
"expired",
|
|
11
|
+
"port-conflict",
|
|
12
|
+
"failed"
|
|
13
|
+
];
|
|
14
|
+
const LOGIN_ERROR_CODES = [
|
|
15
|
+
"invalid-method",
|
|
16
|
+
"invalid-path",
|
|
17
|
+
"invalid-host",
|
|
18
|
+
"duplicate-parameter",
|
|
19
|
+
"invalid-parameters",
|
|
20
|
+
"missing-state",
|
|
21
|
+
"state-mismatch",
|
|
22
|
+
"missing-code",
|
|
23
|
+
"oauth-error",
|
|
24
|
+
"no-pending-flow",
|
|
25
|
+
"expired",
|
|
26
|
+
"cancelled",
|
|
27
|
+
"port-conflict",
|
|
28
|
+
"token-exchange-failed",
|
|
29
|
+
"project-unavailable",
|
|
30
|
+
"project-authentication-failed",
|
|
31
|
+
"project-forbidden",
|
|
32
|
+
"project-rate-limited",
|
|
33
|
+
"project-offline",
|
|
34
|
+
"project-malformed",
|
|
35
|
+
"project-protocol-drift",
|
|
36
|
+
"project-validation-failed",
|
|
37
|
+
"persistence-failed",
|
|
38
|
+
"credential-conflict",
|
|
39
|
+
"invalid-callback-url",
|
|
40
|
+
"risk-acknowledgement-required",
|
|
41
|
+
"internal"
|
|
42
|
+
];
|
|
43
|
+
function isLoginPhase(value) {
|
|
44
|
+
return typeof value === "string" && LOGIN_PHASES.includes(value);
|
|
45
|
+
}
|
|
46
|
+
function isLoginErrorCode(value) {
|
|
47
|
+
return typeof value === "string" && LOGIN_ERROR_CODES.includes(value);
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/rpc-vocabulary.ts
|
|
51
|
+
/** Closed, browser-safe RPC error vocabulary shared by Host and client. */
|
|
52
|
+
const OPERATION_ERROR_CODES = [
|
|
53
|
+
"invalid-grant",
|
|
54
|
+
"network",
|
|
55
|
+
"timeout",
|
|
56
|
+
"rate-limited",
|
|
57
|
+
"server-error",
|
|
58
|
+
"http-error",
|
|
59
|
+
"invalid-response",
|
|
60
|
+
"conflict",
|
|
61
|
+
"storage"
|
|
62
|
+
];
|
|
63
|
+
const SAFE_RPC_ERROR_CODES = [
|
|
64
|
+
"bad-request",
|
|
65
|
+
...LOGIN_ERROR_CODES,
|
|
66
|
+
...OPERATION_ERROR_CODES
|
|
67
|
+
];
|
|
68
|
+
const SAFE_RPC_ERROR_MESSAGES = Object.freeze({
|
|
69
|
+
"bad-request": "antigravity-auth: invalid request",
|
|
70
|
+
cancelled: "The operation was cancelled",
|
|
71
|
+
"risk-acknowledgement-required": "Risk acknowledgement is required before login",
|
|
72
|
+
"port-conflict": "The fixed OAuth callback port is already in use",
|
|
73
|
+
"invalid-method": "The OAuth callback method is not accepted",
|
|
74
|
+
"invalid-path": "The OAuth callback path is not accepted",
|
|
75
|
+
"invalid-host": "The OAuth callback host is not accepted",
|
|
76
|
+
"duplicate-parameter": "The OAuth callback contains duplicate parameters",
|
|
77
|
+
"invalid-parameters": "The OAuth callback parameters are not accepted",
|
|
78
|
+
"missing-state": "The OAuth callback state is missing",
|
|
79
|
+
"state-mismatch": "The OAuth callback state was not accepted",
|
|
80
|
+
"missing-code": "The OAuth callback code is missing",
|
|
81
|
+
"oauth-error": "The OAuth provider rejected authorization",
|
|
82
|
+
expired: "The OAuth login expired",
|
|
83
|
+
"no-pending-flow": "There is no pending OAuth login",
|
|
84
|
+
"project-unavailable": "No usable project is available for this account",
|
|
85
|
+
"project-authentication-failed": "The Antigravity project probe requires authentication",
|
|
86
|
+
"project-forbidden": "The Antigravity project probe was forbidden",
|
|
87
|
+
"project-rate-limited": "The Antigravity project probe is rate-limited",
|
|
88
|
+
"project-offline": "The Antigravity project probe is offline",
|
|
89
|
+
"project-malformed": "The Antigravity project response was malformed",
|
|
90
|
+
"project-protocol-drift": "The Antigravity project protocol changed",
|
|
91
|
+
"project-validation-failed": "Project validation failed",
|
|
92
|
+
"credential-conflict": "The login changed while it was completing",
|
|
93
|
+
"persistence-failed": "The login could not be saved",
|
|
94
|
+
"token-exchange-failed": "The authorization code could not be exchanged",
|
|
95
|
+
"invalid-callback-url": "The callback URL is invalid",
|
|
96
|
+
"invalid-grant": "The account must be authenticated again",
|
|
97
|
+
network: "The operation could not reach the provider",
|
|
98
|
+
timeout: "The operation timed out",
|
|
99
|
+
"rate-limited": "The operation is rate-limited",
|
|
100
|
+
"server-error": "The provider is unavailable",
|
|
101
|
+
"http-error": "The provider rejected the operation",
|
|
102
|
+
"invalid-response": "The provider response was not accepted",
|
|
103
|
+
conflict: "The account changed while the operation was running",
|
|
104
|
+
storage: "The local account state could not be updated"
|
|
105
|
+
});
|
|
106
|
+
function isSafeRpcErrorCode(value) {
|
|
107
|
+
return typeof value === "string" && SAFE_RPC_ERROR_CODES.includes(value);
|
|
108
|
+
}
|
|
109
|
+
function safeRpcErrorMessage(code) {
|
|
110
|
+
return SAFE_RPC_ERROR_MESSAGES[code] ?? "antigravity-auth: operation failed";
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/model-catalog.ts
|
|
114
|
+
/** Browser-safe advisory model-catalog state shared by Host RPC and settings. */
|
|
115
|
+
const ANTIGRAVITY_MODEL_CATALOG_STATES = [
|
|
116
|
+
"snapshot",
|
|
117
|
+
"live-available",
|
|
118
|
+
"refresh-failed",
|
|
119
|
+
"protocol-drift"
|
|
120
|
+
];
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/rpc-contract.ts
|
|
123
|
+
const ANTIGRAVITY_AUTH_RPC_CHANNEL = "/antigravity-auth";
|
|
124
|
+
/** Build the browser face over the plugin-owned loopback channel. */
|
|
125
|
+
function createAntigravityAuthRpcClient(rpc) {
|
|
126
|
+
return {
|
|
127
|
+
status: (signal) => callValidated(rpc, "status", {}, signal, (value) => {
|
|
128
|
+
const status = parseStatusResult(value);
|
|
129
|
+
return status === void 0 ? void 0 : { status };
|
|
130
|
+
}),
|
|
131
|
+
acknowledgeRisk: (signal) => callValidated(rpc, "acknowledge-risk", { acknowledge: true }, signal, parseAcknowledgementResult),
|
|
132
|
+
login: (signal) => callValidated(rpc, "login", {}, signal, parseLoginResult),
|
|
133
|
+
cancelLogin: (signal) => callValidated(rpc, "cancel", {}, signal, parseActionResult),
|
|
134
|
+
logout: (signal) => callValidated(rpc, "logout", {}, signal, parseLogoutResult),
|
|
135
|
+
revoke: (signal) => callValidated(rpc, "revoke", { confirmed: true }, signal, parseRevokeResult),
|
|
136
|
+
models: (signal, force = false) => callValidated(rpc, "models", { force }, signal, parseModelCatalogResult),
|
|
137
|
+
usage: (signal, force = false) => callValidated(rpc, "usage", { force }, signal, parseUsageResult)
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
async function callValidated(rpc, endpoint, payload, signal, parse) {
|
|
141
|
+
let result;
|
|
142
|
+
try {
|
|
143
|
+
result = await rpc.call(ANTIGRAVITY_AUTH_RPC_CHANNEL, endpoint, payload, signal);
|
|
144
|
+
} catch {
|
|
145
|
+
return invalidResponse(endpoint);
|
|
146
|
+
}
|
|
147
|
+
if (!result.ok) return sanitizeFailure(result, endpoint);
|
|
148
|
+
const value = parse(result.value);
|
|
149
|
+
return value === void 0 ? invalidResponse(endpoint) : {
|
|
150
|
+
ok: true,
|
|
151
|
+
value
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function sanitizeFailure(result, endpoint) {
|
|
155
|
+
const error = result.error;
|
|
156
|
+
if (!isRecord(error) || !hasExactKeys(error, [
|
|
157
|
+
"code",
|
|
158
|
+
"message",
|
|
159
|
+
"details"
|
|
160
|
+
]) || !isSafeRpcErrorCode(error.code) || typeof error.message !== "string" || !isBoundedSafeText(error.message, 512) || !isSafeErrorDetails(error.details)) return invalidResponse(endpoint);
|
|
161
|
+
return {
|
|
162
|
+
ok: false,
|
|
163
|
+
error: {
|
|
164
|
+
code: error.code,
|
|
165
|
+
message: safeRpcErrorMessage(error.code),
|
|
166
|
+
details: {}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function isSafeErrorDetails(value) {
|
|
171
|
+
if (!isRecord(value)) return false;
|
|
172
|
+
if (Object.keys(value).length === 0) return true;
|
|
173
|
+
return hasExactKeys(value, ["issues"]) && Array.isArray(value.issues) && value.issues.length === 0;
|
|
174
|
+
}
|
|
175
|
+
/** Parse a closed, value-safe advisory model catalog received by the browser. */
|
|
176
|
+
function parseModelCatalogResult(value) {
|
|
177
|
+
if (!isRecord(value) || !hasExactKeys(value, [
|
|
178
|
+
"state",
|
|
179
|
+
"models",
|
|
180
|
+
...value.checkedAt === void 0 ? [] : ["checkedAt"]
|
|
181
|
+
]) || !ANTIGRAVITY_MODEL_CATALOG_STATES.includes(value.state) || !Array.isArray(value.models) || value.models.length === 0 || value.models.length > 64 || value.checkedAt !== void 0 && !isIsoTime(value.checkedAt)) return void 0;
|
|
182
|
+
const models = [];
|
|
183
|
+
const ids = /* @__PURE__ */ new Set();
|
|
184
|
+
for (const model of value.models) {
|
|
185
|
+
if (!isRecord(model) || !hasExactKeys(model, [
|
|
186
|
+
"id",
|
|
187
|
+
"name",
|
|
188
|
+
"state"
|
|
189
|
+
]) || !isBoundedSafeText(model.id, 256) || !isBoundedSafeText(model.name, 256) || model.state !== "snapshot" && model.state !== "live-available" && model.state !== "unavailable" || ids.has(model.id)) return void 0;
|
|
190
|
+
if (value.state === "live-available" ? model.state === "snapshot" : model.state !== "snapshot") return void 0;
|
|
191
|
+
ids.add(model.id);
|
|
192
|
+
models.push({
|
|
193
|
+
id: model.id,
|
|
194
|
+
name: model.name,
|
|
195
|
+
state: model.state
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
state: value.state,
|
|
200
|
+
models,
|
|
201
|
+
...typeof value.checkedAt === "string" ? { checkedAt: value.checkedAt } : {}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/** Parse a value-safe, normalized quota envelope received by the browser. */
|
|
205
|
+
function parseUsageResult(value) {
|
|
206
|
+
if (!isRecord(value) || !hasExactKeys(value, [
|
|
207
|
+
"state",
|
|
208
|
+
...value.checkedAt === void 0 ? [] : ["checkedAt"],
|
|
209
|
+
...value.groups === void 0 ? [] : ["groups"]
|
|
210
|
+
])) return void 0;
|
|
211
|
+
if (!isQuotaState(value.state)) return void 0;
|
|
212
|
+
if (value.checkedAt !== void 0 && !isIsoTime(value.checkedAt)) return void 0;
|
|
213
|
+
if (value.state === "available" && value.groups === void 0) return void 0;
|
|
214
|
+
if (value.groups !== void 0) {
|
|
215
|
+
if (!Array.isArray(value.groups) || value.groups.length === 0 || value.groups.length > 2) return void 0;
|
|
216
|
+
const groups = [];
|
|
217
|
+
const groupNames = /* @__PURE__ */ new Set();
|
|
218
|
+
for (const rawGroup of value.groups) {
|
|
219
|
+
if (!isRecord(rawGroup) || !hasExactKeys(rawGroup, [
|
|
220
|
+
"group",
|
|
221
|
+
"modelCount",
|
|
222
|
+
"windows"
|
|
223
|
+
]) || rawGroup.group !== "gemini" && rawGroup.group !== "non-gemini" || !Number.isSafeInteger(rawGroup.modelCount) || rawGroup.modelCount < 0 || !Array.isArray(rawGroup.windows)) return void 0;
|
|
224
|
+
if (groupNames.has(rawGroup.group)) return void 0;
|
|
225
|
+
groupNames.add(rawGroup.group);
|
|
226
|
+
const modelCount = rawGroup.modelCount;
|
|
227
|
+
if (rawGroup.windows.length === 0 || rawGroup.windows.length > 2) return void 0;
|
|
228
|
+
const windows = [];
|
|
229
|
+
const windowKinds = /* @__PURE__ */ new Set();
|
|
230
|
+
for (const rawWindow of rawGroup.windows) {
|
|
231
|
+
if (!isRecord(rawWindow) || !hasExactKeys(rawWindow, [
|
|
232
|
+
"window",
|
|
233
|
+
"remainingFraction",
|
|
234
|
+
"resetTime"
|
|
235
|
+
]) || rawWindow.window !== "5h" && rawWindow.window !== "weekly" || windowKinds.has(rawWindow.window) || typeof rawWindow.remainingFraction !== "number" || !Number.isFinite(rawWindow.remainingFraction) || rawWindow.remainingFraction < 0 || rawWindow.remainingFraction > 1 || !isIsoTime(rawWindow.resetTime)) return void 0;
|
|
236
|
+
windowKinds.add(rawWindow.window);
|
|
237
|
+
windows.push({
|
|
238
|
+
window: rawWindow.window,
|
|
239
|
+
remainingFraction: rawWindow.remainingFraction,
|
|
240
|
+
resetTime: rawWindow.resetTime
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
groups.push({
|
|
244
|
+
group: rawGroup.group,
|
|
245
|
+
modelCount,
|
|
246
|
+
windows
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
state: value.state,
|
|
251
|
+
...typeof value.checkedAt === "string" ? { checkedAt: value.checkedAt } : {},
|
|
252
|
+
groups
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
state: value.state,
|
|
257
|
+
...typeof value.checkedAt === "string" ? { checkedAt: value.checkedAt } : {}
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/** Parse the closed status envelope received by the browser. */
|
|
261
|
+
function parseStatusResult(value) {
|
|
262
|
+
if (!isRecord(value) || !hasExactKeys(value, ["status"])) return void 0;
|
|
263
|
+
return parseStatus(value.status);
|
|
264
|
+
}
|
|
265
|
+
function parseStatus(value) {
|
|
266
|
+
if (!isRecord(value) || !hasAllowedKeys(value, [
|
|
267
|
+
"pluginId",
|
|
268
|
+
"phase",
|
|
269
|
+
"privateSelfUse",
|
|
270
|
+
"singleAccount",
|
|
271
|
+
"riskAcknowledgementRequired",
|
|
272
|
+
"riskAcknowledged",
|
|
273
|
+
"login",
|
|
274
|
+
"credential",
|
|
275
|
+
"revoke",
|
|
276
|
+
"capabilities"
|
|
277
|
+
]) || value.pluginId !== "dsh-antigravity-auth" || value.phase !== "bootstrap" || value.privateSelfUse !== true || value.singleAccount !== true || value.riskAcknowledgementRequired !== true || typeof value.riskAcknowledged !== "boolean" || !Array.isArray(value.capabilities)) return void 0;
|
|
278
|
+
const login = parseLoginStatus(value.login);
|
|
279
|
+
if (login === void 0) return void 0;
|
|
280
|
+
const credential = value.credential === void 0 ? void 0 : parseCredentialStatus(value.credential);
|
|
281
|
+
if (value.credential !== void 0 && credential === void 0) return void 0;
|
|
282
|
+
const revoke = value.revoke === void 0 ? void 0 : parseRevokeStatus(value.revoke);
|
|
283
|
+
if (value.revoke !== void 0 && revoke === void 0) return void 0;
|
|
284
|
+
const seen = /* @__PURE__ */ new Set();
|
|
285
|
+
const capabilities = [];
|
|
286
|
+
for (const capability of value.capabilities) {
|
|
287
|
+
const parsed = parseCapability(capability);
|
|
288
|
+
if (parsed === void 0 || seen.has(parsed.id)) return void 0;
|
|
289
|
+
seen.add(parsed.id);
|
|
290
|
+
capabilities.push(parsed);
|
|
291
|
+
}
|
|
292
|
+
if (seen.size !== CAPABILITY_ROW_IDS.length || CAPABILITY_ROW_IDS.some((id) => !seen.has(id))) return void 0;
|
|
293
|
+
return {
|
|
294
|
+
pluginId: "dsh-antigravity-auth",
|
|
295
|
+
phase: "bootstrap",
|
|
296
|
+
privateSelfUse: true,
|
|
297
|
+
singleAccount: true,
|
|
298
|
+
riskAcknowledgementRequired: true,
|
|
299
|
+
riskAcknowledged: value.riskAcknowledged,
|
|
300
|
+
login,
|
|
301
|
+
...credential === void 0 ? {} : { credential },
|
|
302
|
+
...revoke === void 0 ? {} : { revoke },
|
|
303
|
+
capabilities
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
function parseCredentialStatus(value) {
|
|
307
|
+
if (!isRecord(value) || typeof value.state !== "string" || !isCredentialState(value.state) || typeof value.configured !== "boolean" || !hasAllowedKeys(value, [
|
|
308
|
+
"state",
|
|
309
|
+
"configured",
|
|
310
|
+
"expiresAt",
|
|
311
|
+
"lastRefreshAt",
|
|
312
|
+
"errorCode"
|
|
313
|
+
])) return void 0;
|
|
314
|
+
if (value.expiresAt !== void 0 && !isIsoTime(value.expiresAt)) return void 0;
|
|
315
|
+
if (value.lastRefreshAt !== void 0 && !isIsoTime(value.lastRefreshAt)) return void 0;
|
|
316
|
+
if (value.errorCode !== void 0 && (typeof value.errorCode !== "string" || !isCredentialErrorCode(value.errorCode))) return void 0;
|
|
317
|
+
return {
|
|
318
|
+
state: value.state,
|
|
319
|
+
configured: value.configured,
|
|
320
|
+
...typeof value.expiresAt === "string" ? { expiresAt: value.expiresAt } : {},
|
|
321
|
+
...typeof value.lastRefreshAt === "string" ? { lastRefreshAt: value.lastRefreshAt } : {},
|
|
322
|
+
...typeof value.errorCode === "string" ? { errorCode: value.errorCode } : {}
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
function parseRevokeStatus(value) {
|
|
326
|
+
if (!isRecord(value) || typeof value.state !== "string" || !isRevokeState(value.state) || !hasAllowedKeys(value, ["state", "errorCode"])) return void 0;
|
|
327
|
+
if (value.errorCode !== void 0 && (typeof value.errorCode !== "string" || !isRevokeErrorCode(value.errorCode))) return void 0;
|
|
328
|
+
return {
|
|
329
|
+
state: value.state,
|
|
330
|
+
...typeof value.errorCode === "string" ? { errorCode: value.errorCode } : {}
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function parseLoginStatus(value) {
|
|
334
|
+
if (!isRecord(value) || typeof value.phase !== "string" || !isLoginPhase(value.phase) || typeof value.configured !== "boolean" || typeof value.projectAvailable !== "boolean") return void 0;
|
|
335
|
+
const allowed = [
|
|
336
|
+
"phase",
|
|
337
|
+
"configured",
|
|
338
|
+
"projectAvailable",
|
|
339
|
+
"authorizationUrl",
|
|
340
|
+
"expiresAt",
|
|
341
|
+
"maskedEmail",
|
|
342
|
+
"errorCode"
|
|
343
|
+
];
|
|
344
|
+
if (Object.keys(value).some((key) => !allowed.includes(key))) return void 0;
|
|
345
|
+
if (value.authorizationUrl !== void 0 && !isSafeAuthorizationUrl(value.authorizationUrl)) return void 0;
|
|
346
|
+
if (value.expiresAt !== void 0 && !isIsoTime(value.expiresAt)) return void 0;
|
|
347
|
+
if (value.maskedEmail !== void 0 && (typeof value.maskedEmail !== "string" || !isMaskedEmail(value.maskedEmail))) return void 0;
|
|
348
|
+
if (value.errorCode !== void 0 && !isLoginErrorCode(value.errorCode)) return void 0;
|
|
349
|
+
if (isErrorPhase(value.phase) ? typeof value.errorCode !== "string" : value.errorCode !== void 0) return void 0;
|
|
350
|
+
if (value.phase === "pending" ? typeof value.authorizationUrl !== "string" || typeof value.expiresAt !== "string" : value.authorizationUrl !== void 0) return void 0;
|
|
351
|
+
return {
|
|
352
|
+
phase: value.phase,
|
|
353
|
+
configured: value.configured,
|
|
354
|
+
projectAvailable: value.projectAvailable,
|
|
355
|
+
...typeof value.authorizationUrl === "string" ? { authorizationUrl: value.authorizationUrl } : {},
|
|
356
|
+
...typeof value.expiresAt === "string" ? { expiresAt: value.expiresAt } : {},
|
|
357
|
+
...typeof value.maskedEmail === "string" ? { maskedEmail: value.maskedEmail } : {},
|
|
358
|
+
...typeof value.errorCode === "string" ? { errorCode: value.errorCode } : {}
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
function parseCapability(value) {
|
|
362
|
+
if (!isRecord(value) || !hasExactKeys(value, [
|
|
363
|
+
"id",
|
|
364
|
+
"state",
|
|
365
|
+
"reasonCode"
|
|
366
|
+
])) return void 0;
|
|
367
|
+
if (!isCapabilityRowId(value.id) || !isCapabilityGateState(value.state) || !isCapabilityReasonCode(value.reasonCode)) return;
|
|
368
|
+
return {
|
|
369
|
+
id: value.id,
|
|
370
|
+
state: value.state,
|
|
371
|
+
reasonCode: value.reasonCode
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
function parseAcknowledgementResult(value) {
|
|
375
|
+
return isRecord(value) && hasExactKeys(value, ["acknowledged"]) && value.acknowledged === true ? { acknowledged: true } : void 0;
|
|
376
|
+
}
|
|
377
|
+
function parseLoginResult(value) {
|
|
378
|
+
return isRecord(value) && hasExactKeys(value, [
|
|
379
|
+
"started",
|
|
380
|
+
"phase",
|
|
381
|
+
"authorizationUrl",
|
|
382
|
+
"expiresAt"
|
|
383
|
+
]) && value.started === true && value.phase === "pending" && isSafeAuthorizationUrl(value.authorizationUrl) && isIsoTime(value.expiresAt) ? {
|
|
384
|
+
started: true,
|
|
385
|
+
phase: "pending",
|
|
386
|
+
authorizationUrl: value.authorizationUrl,
|
|
387
|
+
expiresAt: value.expiresAt
|
|
388
|
+
} : void 0;
|
|
389
|
+
}
|
|
390
|
+
function parseActionResult(value) {
|
|
391
|
+
if (!isRecord(value) || typeof value.phase !== "string" || !isLoginPhase(value.phase)) return void 0;
|
|
392
|
+
if (Object.keys(value).some((key) => key !== "phase" && key !== "errorCode")) return void 0;
|
|
393
|
+
if (value.errorCode !== void 0 && !isLoginErrorCode(value.errorCode)) return void 0;
|
|
394
|
+
return {
|
|
395
|
+
phase: value.phase,
|
|
396
|
+
...typeof value.errorCode === "string" ? { errorCode: value.errorCode } : {}
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
function parseLogoutResult(value) {
|
|
400
|
+
return isRecord(value) && hasExactKeys(value, ["state"]) && value.state === "logged-out" ? { state: "logged-out" } : void 0;
|
|
401
|
+
}
|
|
402
|
+
function parseRevokeResult(value) {
|
|
403
|
+
if (!isRecord(value) || typeof value.state !== "string") return void 0;
|
|
404
|
+
if (value.state === "confirmation-required" || value.state === "revoked" || value.state === "logged-out" || value.state === "superseded") return hasExactKeys(value, ["state"]) ? { state: value.state } : void 0;
|
|
405
|
+
if (value.state === "failed" && hasExactKeys(value, ["state", "errorCode"]) && typeof value.errorCode === "string" && isRevokeErrorCode(value.errorCode)) return {
|
|
406
|
+
state: "failed",
|
|
407
|
+
errorCode: value.errorCode
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
function isSafeAuthorizationUrl(value) {
|
|
411
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 8192) return false;
|
|
412
|
+
try {
|
|
413
|
+
const parsed = new URL(value);
|
|
414
|
+
const allowed = /* @__PURE__ */ new Set([
|
|
415
|
+
"client_id",
|
|
416
|
+
"response_type",
|
|
417
|
+
"redirect_uri",
|
|
418
|
+
"scope",
|
|
419
|
+
"code_challenge",
|
|
420
|
+
"code_challenge_method",
|
|
421
|
+
"state",
|
|
422
|
+
"access_type",
|
|
423
|
+
"prompt"
|
|
424
|
+
]);
|
|
425
|
+
for (const [key, parameter] of parsed.searchParams) if (!allowed.has(key) || parsed.searchParams.getAll(key).length !== 1 || !isBoundedSafeText(parameter, 4096)) return false;
|
|
426
|
+
const state = parsed.searchParams.get("state");
|
|
427
|
+
const clientId = parsed.searchParams.get("client_id");
|
|
428
|
+
const challenge = parsed.searchParams.get("code_challenge");
|
|
429
|
+
return parsed.protocol === "https:" && parsed.hostname === "accounts.google.com" && parsed.port === "" && parsed.username === "" && parsed.password === "" && parsed.pathname === "/o/oauth2/v2/auth" && parsed.hash.length === 0 && typeof state === "string" && /^[A-Za-z0-9_-]{43}$/u.test(state) && (clientId === null || clientId.length <= 256 && clientId.endsWith(".apps.googleusercontent.com")) && (challenge === null || /^[A-Za-z0-9_-]{43}$/u.test(challenge)) && (parsed.searchParams.get("response_type") === null || parsed.searchParams.get("response_type") === "code") && (parsed.searchParams.get("redirect_uri") === null || parsed.searchParams.get("redirect_uri") === "http://localhost:51121/oauth-callback") && (parsed.searchParams.get("code_challenge_method") === null || parsed.searchParams.get("code_challenge_method") === "S256") && (parsed.searchParams.get("access_type") === null || parsed.searchParams.get("access_type") === "offline") && (parsed.searchParams.get("prompt") === null || parsed.searchParams.get("prompt") === "consent");
|
|
430
|
+
} catch {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
function isMaskedEmail(value) {
|
|
435
|
+
return isBoundedSafeText(value, 256) && /^.[*]{3}[^@]*@[^@\s]+$/u.test(value);
|
|
436
|
+
}
|
|
437
|
+
function isErrorPhase(value) {
|
|
438
|
+
return value === "cancelled" || value === "expired" || value === "port-conflict" || value === "failed";
|
|
439
|
+
}
|
|
440
|
+
function isQuotaState(value) {
|
|
441
|
+
return value === "available" || value === "unauthenticated" || value === "forbidden" || value === "rate-limited" || value === "offline" || value === "timeout" || value === "protocol-drift";
|
|
442
|
+
}
|
|
443
|
+
function isIsoTime(value) {
|
|
444
|
+
if (typeof value !== "string" || value.length > 64) return false;
|
|
445
|
+
const timestamp = Date.parse(value);
|
|
446
|
+
return Number.isFinite(timestamp) && new Date(timestamp).toISOString() === value;
|
|
447
|
+
}
|
|
448
|
+
function isCapabilityRowId(value) {
|
|
449
|
+
return typeof value === "string" && CAPABILITY_ROW_IDS.includes(value);
|
|
450
|
+
}
|
|
451
|
+
function isCapabilityGateState(value) {
|
|
452
|
+
return value === "available" || value === "disabled" || value === "poc-pending" || value === "protocol-drift";
|
|
453
|
+
}
|
|
454
|
+
function isCapabilityReasonCode(value) {
|
|
455
|
+
return value === "gate-not-run" || value === "project-unavailable" || value === "capability-ready" || value === "unauthenticated" || value === "rate-limited" || value === "cancelled" || value === "gate-0-failed" || value === "gate-failed" || value === "unsupported-video" || value === "protocol-drift";
|
|
456
|
+
}
|
|
457
|
+
function isCredentialState(value) {
|
|
458
|
+
return value === "logged-out" || value === "logged-in" || value === "refreshing" || value === "refresh-failed" || value === "re-login-required";
|
|
459
|
+
}
|
|
460
|
+
function isCredentialErrorCode(value) {
|
|
461
|
+
return value === "invalid-grant" || value === "network" || value === "timeout" || value === "rate-limited" || value === "server-error" || value === "http-error" || value === "invalid-response" || value === "conflict" || value === "storage" || value === "cancelled";
|
|
462
|
+
}
|
|
463
|
+
function isRevokeState(value) {
|
|
464
|
+
return value === "idle" || value === "pending" || value === "confirmation-required" || value === "revoked" || value === "logged-out" || value === "failed" || value === "superseded";
|
|
465
|
+
}
|
|
466
|
+
function isRevokeErrorCode(value) {
|
|
467
|
+
return value === "network" || value === "timeout" || value === "rate-limited" || value === "server-error" || value === "http-error" || value === "invalid-response" || value === "storage";
|
|
468
|
+
}
|
|
469
|
+
function hasAllowedKeys(value, allowed) {
|
|
470
|
+
return Object.keys(value).every((key) => allowed.includes(key));
|
|
471
|
+
}
|
|
472
|
+
function hasExactKeys(value, expected) {
|
|
473
|
+
const keys = Object.keys(value).sort();
|
|
474
|
+
const sortedExpected = [...expected].sort();
|
|
475
|
+
return keys.length === sortedExpected.length && keys.every((key, index) => key === sortedExpected[index]);
|
|
476
|
+
}
|
|
477
|
+
function invalidResponse(endpoint) {
|
|
478
|
+
return {
|
|
479
|
+
ok: false,
|
|
480
|
+
error: {
|
|
481
|
+
code: "internal",
|
|
482
|
+
message: `antigravity-auth: invalid ${endpoint} response from Host`,
|
|
483
|
+
details: {}
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
function isRecord(value) {
|
|
488
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
489
|
+
}
|
|
490
|
+
//#endregion
|
|
491
|
+
export { parseUsageResult as a, safeRpcErrorMessage as c, parseStatusResult as i, createAntigravityAuthRpcClient as n, ANTIGRAVITY_MODEL_CATALOG_STATES as o, parseModelCatalogResult as r, isSafeRpcErrorCode as s, ANTIGRAVITY_AUTH_RPC_CHANNEL as t };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as parseUsageResult, i as parseStatusResult, n as createAntigravityAuthRpcClient, r as parseModelCatalogResult, t as ANTIGRAVITY_AUTH_RPC_CHANNEL } from "./rpc-contract-BFWfdKKs.js";
|
|
2
|
+
export { ANTIGRAVITY_AUTH_RPC_CHANNEL, createAntigravityAuthRpcClient, parseModelCatalogResult, parseStatusResult, parseUsageResult };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/safe-text.ts
|
|
2
|
+
/** Shared bounded text predicate for Host trust-boundary values. */
|
|
3
|
+
function isBoundedSafeText(value, maxLength, minLength = 1) {
|
|
4
|
+
if (typeof value !== "string" || !Number.isSafeInteger(maxLength) || !Number.isSafeInteger(minLength) || minLength < 0 || maxLength < minLength || value.length < minLength || value.length > maxLength) return false;
|
|
5
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
6
|
+
const codePoint = value.charCodeAt(index);
|
|
7
|
+
if (codePoint < 32 || codePoint === 127) return false;
|
|
8
|
+
}
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { isBoundedSafeText as t };
|