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
package/lib/index.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { _ as defaultAuthStorePath, a as maskEmail, c as defaultCapabilityGatePath, d as ANTIGRAVITY_TOKEN_ENDPOINT, f as CredentialOperationError, g as credentialErrorMessage, h as createGoogleRevokeTransport, i as createAntigravityAuthService, l as OAuthFlowError, m as createGoogleRefreshTransport, o as createFileCapabilityGates, p as createCredentialCoordinator, r as AntigravityAuthService, s as createMemoryCapabilityGates, t as mountCapabilityLifecycle, u as ANTIGRAVITY_REVOKE_ENDPOINT } from "./capability-lifecycle--tgGKajs.js";
|
|
2
|
+
import { a as DEFAULT_PRIVATE_RESPONSE_HEADER_TIMEOUT_MS, c as assertPrivateEndpoint, d as privateStatusError, f as readPrivateBytes, i as DEFAULT_PRIVATE_RESPONSE_BYTES, l as createPrivateTransport, m as PrivateTransportError, n as DEFAULT_PRIVATE_IDLE_TIMEOUT_MS, o as DEFAULT_PRIVATE_TOTAL_TIMEOUT_MS, p as readPrivateText, r as DEFAULT_PRIVATE_REQUEST_BYTES, s as MAX_PRIVATE_REQUEST_BYTES, t as DEFAULT_PRIVATE_FRAME_BYTES, u as iteratePrivateSse } from "./private-transport-urF138qW.js";
|
|
3
|
+
import { AGY_PROVIDER_USER_AGENT, ANTIGRAVITY_WIRE_ORIGIN, ANTIGRAVITY_WIRE_ORIGINS, ANTIGRAVITY_WIRE_PATHS, DSH_ATTRIBUTION_HEADER, WireIdentityError, assertWireIdentityInvariant, buildWireIdentityHeaders, createWireIdentity } from "./wire-identity.js";
|
|
4
|
+
import { PROJECT_DISCOVERY_ENDPOINT, PROJECT_DISCOVERY_PATH, ProjectDiscoveryError, createProjectContext, createProjectDiscovery, normalizeProjectId } from "./project-context.js";
|
|
5
|
+
import { a as createStatusView, i as LLM_FAMILY_IDS, n as CAPABILITY_GATE_OUTCOMES, r as CAPABILITY_ROW_IDS, t as ANTIGRAVITY_PLUGIN_ID } from "./status-D0-em3Ru.js";
|
|
6
|
+
import { ANTIGRAVITY_QUOTA_ENDPOINT, QUOTA_REFRESH_MIN_INTERVAL_MS, QuotaNormalizationError, createQuotaService, normalizeQuotaResponse } from "./quota.js";
|
|
7
|
+
import { ANTIGRAVITY_REPLAY_VERSION, antigravityModelFamily, buildFunctionDeclarations, compatibleReplayState, createReplayState, sanitizeToolSchemas } from "./replay.js";
|
|
8
|
+
import { ANTIGRAVITY_AVAILABLE_MODELS_ENDPOINT, ANTIGRAVITY_GENERATE_ENDPOINT, ANTIGRAVITY_LLM_ROUTE, ANTIGRAVITY_PROVIDER, ANTIGRAVITY_STREAM_ENDPOINT, AntigravityAdapter, buildAntigravityGeneratePayload } from "./llm-adapter.js";
|
|
9
|
+
import { a as parseUsageResult, c as safeRpcErrorMessage, i as parseStatusResult, n as createAntigravityAuthRpcClient, o as ANTIGRAVITY_MODEL_CATALOG_STATES, r as parseModelCatalogResult, s as isSafeRpcErrorCode, t as ANTIGRAVITY_AUTH_RPC_CHANNEL } from "./rpc-contract-BFWfdKKs.js";
|
|
10
|
+
import { DEFAULT_INLINE_IMAGE_BYTES, DEFAULT_VIDEO_BYTES, IMAGE_HANDLE_PATTERN, MediaAdmissionError, admitBase64Image, admitImageBytes, admitSessionImage, admitWorkspaceImage, admitWorkspaceVideo, detectImageMediaType, imageHandle, isMp4, sessionImageCatalog } from "./media-admission.js";
|
|
11
|
+
import { LIVE_ACKNOWLEDGEMENT, LIVE_GATE_IDS, runLiveGateCli } from "./live-gates.js";
|
|
12
|
+
//#region src/rpc.ts
|
|
13
|
+
/** Dispatch closed, value-safe requests; callback URLs are never echoed. */
|
|
14
|
+
async function handleAntigravityAuthRpc(service, endpoint, payload, signal, modelCatalog) {
|
|
15
|
+
if (signal?.aborted === true) return cancelled();
|
|
16
|
+
try {
|
|
17
|
+
if (endpoint === "status") {
|
|
18
|
+
if (!isEmptyRecord(payload)) return badRequest("status expects an empty payload");
|
|
19
|
+
return {
|
|
20
|
+
ok: true,
|
|
21
|
+
value: { status: await service.status() }
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (endpoint === "models") {
|
|
25
|
+
if (!isRefreshPayload(payload)) return badRequest("models expects {} or { force: boolean }");
|
|
26
|
+
if (modelCatalog === void 0) return badRequest("model catalog is unavailable");
|
|
27
|
+
const status = await service.status();
|
|
28
|
+
return {
|
|
29
|
+
ok: true,
|
|
30
|
+
value: status.login.projectAvailable && status.capabilities.some((capability) => capability.id === "auth-llm" && capability.state === "available") ? await modelCatalog.modelCatalog(signal, payload.force) : modelCatalog.catalogSnapshot()
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (endpoint === "usage") {
|
|
34
|
+
if (!isRefreshPayload(payload)) return badRequest("usage expects {} or { force: boolean }");
|
|
35
|
+
if (service.usage === void 0) return {
|
|
36
|
+
ok: true,
|
|
37
|
+
value: { state: "protocol-drift" }
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
ok: true,
|
|
41
|
+
value: await service.usage(signal, payload.force)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (endpoint === "acknowledge-risk") {
|
|
45
|
+
if (!isAcknowledgement(payload)) return badRequest("acknowledge-risk expects { acknowledge: true }");
|
|
46
|
+
return {
|
|
47
|
+
ok: true,
|
|
48
|
+
value: await service.acknowledgeRisk()
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (endpoint === "login") {
|
|
52
|
+
if (!isEmptyRecord(payload)) return badRequest("login expects an empty payload");
|
|
53
|
+
return {
|
|
54
|
+
ok: true,
|
|
55
|
+
value: await service.startLogin()
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (endpoint === "cancel" || endpoint === "cancel-login") {
|
|
59
|
+
if (!isEmptyRecord(payload)) return badRequest("cancel expects an empty payload");
|
|
60
|
+
return {
|
|
61
|
+
ok: true,
|
|
62
|
+
value: await service.cancelLogin()
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (endpoint === "logout") {
|
|
66
|
+
if (!isEmptyRecord(payload)) return badRequest("logout expects an empty payload");
|
|
67
|
+
return {
|
|
68
|
+
ok: true,
|
|
69
|
+
value: await service.logout()
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (endpoint === "revoke") {
|
|
73
|
+
if (!isRevokePayload(payload)) return badRequest("revoke expects { confirmed: true }");
|
|
74
|
+
return {
|
|
75
|
+
ok: true,
|
|
76
|
+
value: await service.revoke(true, signal)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return badRequest("unknown Antigravity auth endpoint");
|
|
80
|
+
} catch (error) {
|
|
81
|
+
return safeFailure(error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function badRequest(message) {
|
|
85
|
+
return {
|
|
86
|
+
ok: false,
|
|
87
|
+
error: {
|
|
88
|
+
code: "bad-request",
|
|
89
|
+
message,
|
|
90
|
+
details: { issues: [] }
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function cancelled() {
|
|
95
|
+
return {
|
|
96
|
+
ok: false,
|
|
97
|
+
error: {
|
|
98
|
+
code: "cancelled",
|
|
99
|
+
message: "antigravity-auth: request cancelled",
|
|
100
|
+
details: {}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function safeFailure(error) {
|
|
105
|
+
const credentialError = error instanceof CredentialOperationError ? error : void 0;
|
|
106
|
+
const candidate = error instanceof OAuthFlowError ? error.code : credentialError?.code ?? "internal";
|
|
107
|
+
const code = isSafeRpcErrorCode(candidate) ? candidate : "internal";
|
|
108
|
+
return {
|
|
109
|
+
ok: false,
|
|
110
|
+
error: {
|
|
111
|
+
code,
|
|
112
|
+
message: credentialError === void 0 ? safeRpcErrorMessage(code) : credentialErrorMessage(credentialError.code) ?? safeRpcErrorMessage(code),
|
|
113
|
+
details: {}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function isEmptyRecord(value) {
|
|
118
|
+
return isRecord(value) && Object.keys(value).length === 0;
|
|
119
|
+
}
|
|
120
|
+
function isRefreshPayload(value) {
|
|
121
|
+
return isRecord(value) && Object.keys(value).every((key) => key === "force") && (value.force === void 0 || typeof value.force === "boolean");
|
|
122
|
+
}
|
|
123
|
+
function isAcknowledgement(value) {
|
|
124
|
+
return isRecord(value) && Object.keys(value).length === 1 && value.acknowledge === true;
|
|
125
|
+
}
|
|
126
|
+
function isRevokePayload(value) {
|
|
127
|
+
return isRecord(value) && Object.keys(value).length === 1 && value.confirmed === true;
|
|
128
|
+
}
|
|
129
|
+
function isRecord(value) {
|
|
130
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/index.ts
|
|
134
|
+
const name = "antigravity-auth";
|
|
135
|
+
const inject = [
|
|
136
|
+
"connection",
|
|
137
|
+
"llm",
|
|
138
|
+
"attachments"
|
|
139
|
+
];
|
|
140
|
+
/** Mount the Host-only OAuth service and its loopback RPC channel. */
|
|
141
|
+
function apply(ctx) {
|
|
142
|
+
const service = createAntigravityAuthService({
|
|
143
|
+
storePath: defaultAuthStorePath(),
|
|
144
|
+
autoActivateGates: true
|
|
145
|
+
});
|
|
146
|
+
const runtime = ctx;
|
|
147
|
+
const adapter = new AntigravityAdapter({
|
|
148
|
+
auth: service,
|
|
149
|
+
...runtime.attachments === void 0 ? {} : { attachments: runtime.attachments }
|
|
150
|
+
});
|
|
151
|
+
const unprovide = ctx.provide?.("antigravityAuth", service) ?? (() => {});
|
|
152
|
+
ctx.inject(["connection"], (connectionCtx) => connectionCtx.connection.rpc.handle(ANTIGRAVITY_AUTH_RPC_CHANNEL, (endpoint, payload, signal) => handleAntigravityAuthRpc(service, endpoint, payload, signal, adapter), { authority: "loopback" }));
|
|
153
|
+
mountCapabilityLifecycle({
|
|
154
|
+
ctx,
|
|
155
|
+
auth: service,
|
|
156
|
+
id: "auth-llm",
|
|
157
|
+
enabled: () => runtime.llm?.registerAdapter !== void 0,
|
|
158
|
+
register: () => {
|
|
159
|
+
if (runtime.llm?.registerAdapter === void 0) return void 0;
|
|
160
|
+
if (runtime.llm.listProviders?.().some((provider) => provider.id === "google-antigravity")) return void 0;
|
|
161
|
+
const dispose = runtime.llm.registerAdapter([ANTIGRAVITY_PROVIDER], adapter);
|
|
162
|
+
return () => {
|
|
163
|
+
try {
|
|
164
|
+
dispose();
|
|
165
|
+
} finally {
|
|
166
|
+
adapter.invalidateModelCatalog();
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
},
|
|
170
|
+
ownsAuth: true,
|
|
171
|
+
cleanup: unprovide,
|
|
172
|
+
label: "antigravity-auth: OAuth and LLM operations"
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
export { AGY_PROVIDER_USER_AGENT, ANTIGRAVITY_AUTH_RPC_CHANNEL, ANTIGRAVITY_AVAILABLE_MODELS_ENDPOINT, ANTIGRAVITY_GENERATE_ENDPOINT, ANTIGRAVITY_LLM_ROUTE, ANTIGRAVITY_MODEL_CATALOG_STATES, ANTIGRAVITY_PLUGIN_ID, ANTIGRAVITY_PROVIDER, ANTIGRAVITY_QUOTA_ENDPOINT, ANTIGRAVITY_REPLAY_VERSION, ANTIGRAVITY_REVOKE_ENDPOINT, ANTIGRAVITY_STREAM_ENDPOINT, ANTIGRAVITY_TOKEN_ENDPOINT, ANTIGRAVITY_WIRE_ORIGIN, ANTIGRAVITY_WIRE_ORIGINS, ANTIGRAVITY_WIRE_PATHS, AntigravityAdapter, AntigravityAuthService, CAPABILITY_GATE_OUTCOMES, CAPABILITY_ROW_IDS, CredentialOperationError, DEFAULT_INLINE_IMAGE_BYTES, DEFAULT_PRIVATE_FRAME_BYTES, DEFAULT_PRIVATE_IDLE_TIMEOUT_MS, DEFAULT_PRIVATE_REQUEST_BYTES, DEFAULT_PRIVATE_RESPONSE_BYTES, DEFAULT_PRIVATE_RESPONSE_HEADER_TIMEOUT_MS, DEFAULT_PRIVATE_TOTAL_TIMEOUT_MS, DEFAULT_VIDEO_BYTES, DSH_ATTRIBUTION_HEADER, IMAGE_HANDLE_PATTERN, LIVE_ACKNOWLEDGEMENT, LIVE_GATE_IDS, LLM_FAMILY_IDS, MAX_PRIVATE_REQUEST_BYTES, MediaAdmissionError, PROJECT_DISCOVERY_ENDPOINT, PROJECT_DISCOVERY_PATH, PrivateTransportError, ProjectDiscoveryError, QUOTA_REFRESH_MIN_INTERVAL_MS, QuotaNormalizationError, WireIdentityError, admitBase64Image, admitImageBytes, admitSessionImage, admitWorkspaceImage, admitWorkspaceVideo, antigravityModelFamily, apply, assertPrivateEndpoint, assertWireIdentityInvariant, buildAntigravityGeneratePayload, buildFunctionDeclarations, buildWireIdentityHeaders, compatibleReplayState, createAntigravityAuthRpcClient, createAntigravityAuthService, createCredentialCoordinator, createFileCapabilityGates, createGoogleRefreshTransport, createGoogleRevokeTransport, createMemoryCapabilityGates, createPrivateTransport, createProjectContext, createProjectDiscovery, createQuotaService, createReplayState, createStatusView, createWireIdentity, credentialErrorMessage, defaultCapabilityGatePath, detectImageMediaType, imageHandle, inject, isMp4, iteratePrivateSse, maskEmail, name, normalizeProjectId, normalizeQuotaResponse, parseModelCatalogResult, parseStatusResult, parseUsageResult, privateStatusError, readPrivateBytes, readPrivateText, runLiveGateCli, sanitizeToolSchemas, sessionImageCatalog };
|
package/lib/invariant.js
ADDED