@herbertgao/pi-extensions 2026.11.18 → 2026.11.19
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 +12 -0
- package/README.md +3 -3
- package/THIRD_PARTY_NOTICES.md +2 -23
- package/node_modules/@estebanforge/pi-antigravity-bridge/CHANGELOG.md +956 -0
- package/node_modules/{pi-antigravity → @estebanforge/pi-antigravity-bridge}/LICENSE +1 -1
- package/node_modules/@estebanforge/pi-antigravity-bridge/README.md +240 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/extensions/index.ts +2117 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/package.json +61 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/connection.ts +644 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/driver.ts +1043 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/events.ts +323 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/home.ts +145 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/jsonrpc.ts +243 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/setup.ts +107 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/usage-estimate.ts +61 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agents.ts +64 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-install.ts +93 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-paths.ts +30 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-setup.ts +81 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-version.ts +289 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-detect.ts +161 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-gate.ts +233 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-hook.ts +325 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts-ui.ts +88 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts.ts +144 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/ask-tool.ts +1221 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/background-watch.ts +225 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/bridge-catalog.ts +197 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/config.ts +523 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/daily-log.ts +196 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/dialog-lock.ts +48 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/diff-render.ts +207 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver-types.ts +168 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver.ts +907 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/engine-picker.ts +160 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/frame-guard.ts +38 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/handoff-toast.ts +21 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-registration.ts +376 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-server.ts +618 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/models.ts +404 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/native-tools.ts +104 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/parked-turn.ts +125 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/patch-cleanup.ts +523 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/poll-fold.ts +55 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/prompt-images.ts +92 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/provider.ts +2214 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/queued-messages.ts +152 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/quota-notice.ts +40 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/redact.ts +27 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/sessions.ts +197 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/skills.ts +207 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-events.ts +161 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-sanitizer.ts +180 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/subagent-roster.ts +245 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/sysprompt-agent.ts +130 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks-ui.ts +90 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks.ts +174 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/usage.ts +174 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/web-tools.ts +320 -0
- package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/prompt-editor.ts +3 -1
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +1 -1
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +317 -105
- package/node_modules/@herbertgao/pi-subagents/SECURITY.md +2 -2
- package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +240 -36
- package/node_modules/@herbertgao/pi-subagents/docs/translations.md +63 -0
- package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +1 -1
- package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
- package/node_modules/@herbertgao/pi-subagents/src/agent-file-toggle.ts +2 -0
- package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +89 -6
- package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +6 -2
- package/node_modules/@herbertgao/pi-subagents/src/agent-types.ts +20 -11
- package/node_modules/@herbertgao/pi-subagents/src/cache-retention.ts +39 -0
- package/node_modules/@herbertgao/pi-subagents/src/completion-outbox.ts +5 -0
- package/node_modules/@herbertgao/pi-subagents/src/cross-extension-rpc.ts +185 -44
- package/node_modules/@herbertgao/pi-subagents/src/custom-agents.ts +7 -0
- package/node_modules/@herbertgao/pi-subagents/src/group-join.ts +9 -0
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +126 -116
- package/node_modules/@herbertgao/pi-subagents/src/mention-clone.ts +3 -2
- package/node_modules/@herbertgao/pi-subagents/src/settings.ts +21 -0
- package/node_modules/@herbertgao/pi-subagents/src/subagent-info.ts +115 -0
- package/node_modules/@herbertgao/pi-subagents/src/types.ts +11 -7
- package/node_modules/@herbertgao/pi-subagents/src/ui/agent-widget.ts +2 -3
- package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +1 -1
- package/node_modules/@herbertgao/pi-subagents/src/workflow/meta.ts +2 -2
- package/node_modules/@herbertgao/pi-subagents/src/workflow-info.ts +184 -0
- package/node_modules/pi-commandcode-provider/CHANGELOG.md +10 -0
- package/node_modules/pi-commandcode-provider/README.md +3 -2
- package/node_modules/pi-commandcode-provider/index.ts +120 -13
- package/node_modules/pi-commandcode-provider/package.json +4 -3
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +11 -2
- package/node_modules/pi-commandcode-provider/src/pricing.ts +17 -1
- package/node_modules/pi-commandcode-provider/src/quota-command.ts +3 -2
- package/node_modules/pi-commandcode-provider/src/zdr.ts +163 -0
- package/package.json +11 -14
- package/node_modules/pi-antigravity/README.md +0 -298
- package/node_modules/pi-antigravity/docs/reader-guarantees.md +0 -35
- package/node_modules/pi-antigravity/package.json +0 -87
- package/node_modules/pi-antigravity/src/auth/accounts.ts +0 -327
- package/node_modules/pi-antigravity/src/auth/index.ts +0 -23
- package/node_modules/pi-antigravity/src/auth/oauth.ts +0 -445
- package/node_modules/pi-antigravity/src/client/client.ts +0 -602
- package/node_modules/pi-antigravity/src/client/enterprise.ts +0 -150
- package/node_modules/pi-antigravity/src/client/index.ts +0 -2
- package/node_modules/pi-antigravity/src/diagnostics/diagnostics.ts +0 -104
- package/node_modules/pi-antigravity/src/diagnostics/index.ts +0 -1
- package/node_modules/pi-antigravity/src/features/generate-image.ts +0 -132
- package/node_modules/pi-antigravity/src/features/google-search.ts +0 -72
- package/node_modules/pi-antigravity/src/features/read-url-content.ts +0 -124
- package/node_modules/pi-antigravity/src/image/image.ts +0 -427
- package/node_modules/pi-antigravity/src/image/index.ts +0 -1
- package/node_modules/pi-antigravity/src/image/native.ts +0 -69
- package/node_modules/pi-antigravity/src/index.ts +0 -547
- package/node_modules/pi-antigravity/src/models/discovery.ts +0 -176
- package/node_modules/pi-antigravity/src/models/grouping.ts +0 -487
- package/node_modules/pi-antigravity/src/models/index.ts +0 -3
- package/node_modules/pi-antigravity/src/models/models.ts +0 -647
- package/node_modules/pi-antigravity/src/search/index.ts +0 -1
- package/node_modules/pi-antigravity/src/search/search.ts +0 -967
- package/node_modules/pi-antigravity/src/stream/index.ts +0 -1
- package/node_modules/pi-antigravity/src/stream/stream.ts +0 -1961
- package/node_modules/pi-antigravity/src/types/enums.ts +0 -52
- package/node_modules/pi-antigravity/src/types/index.ts +0 -2
- package/node_modules/pi-antigravity/src/types/types.ts +0 -329
- package/node_modules/pi-antigravity/src/usage/index.ts +0 -1
- package/node_modules/pi-antigravity/src/usage/usage.ts +0 -437
- package/node_modules/pi-antigravity/src/utils/address.ts +0 -180
- package/node_modules/pi-antigravity/src/utils/credits.ts +0 -149
- package/node_modules/pi-antigravity/src/utils/html.ts +0 -31
- package/node_modules/pi-antigravity/src/utils/http.ts +0 -96
- package/node_modules/pi-antigravity/src/utils/index.ts +0 -5
- package/node_modules/pi-antigravity/src/utils/security.ts +0 -278
- package/node_modules/pi-antigravity/src/utils/text.ts +0 -66
- package/node_modules/pi-antigravity/src/utils/util.ts +0 -217
- package/node_modules/pi-antigravity/src/web-fetch/document.ts +0 -83
- package/node_modules/pi-antigravity/src/web-fetch/fences.ts +0 -24
- package/node_modules/pi-antigravity/src/web-fetch/header.ts +0 -97
- package/node_modules/pi-antigravity/src/web-fetch/index.ts +0 -3
- package/node_modules/pi-antigravity/src/web-fetch/inspect.ts +0 -328
- package/node_modules/pi-antigravity/src/web-fetch/limits.ts +0 -4
- package/node_modules/pi-antigravity/src/web-fetch/markdown.ts +0 -744
- package/node_modules/pi-antigravity/src/web-fetch/mdn.ts +0 -164
- package/node_modules/pi-antigravity/src/web-fetch/media.ts +0 -11
- package/node_modules/pi-antigravity/src/web-fetch/metadata.ts +0 -9
- package/node_modules/pi-antigravity/src/web-fetch/representation.ts +0 -93
- package/node_modules/pi-antigravity/src/web-fetch/save.ts +0 -71
- package/node_modules/pi-antigravity/src/web-fetch/sites.ts +0 -138
- package/node_modules/pi-antigravity/src/web-fetch/vendor.d.ts +0 -9
- package/node_modules/pi-antigravity/src/web-fetch/web-fetch.ts +0 -957
- package/node_modules/pi-antigravity/tsconfig.json +0 -21
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
3
|
-
antigravityHeaders,
|
|
4
|
-
endpointCandidates,
|
|
5
|
-
extractProjectId,
|
|
6
|
-
fetchAvailableModelsCatalog,
|
|
7
|
-
parseApiKey,
|
|
8
|
-
resolveProjectId,
|
|
9
|
-
} from "../client/client.js";
|
|
10
|
-
import {
|
|
11
|
-
setLastEndpoint,
|
|
12
|
-
setLastError,
|
|
13
|
-
setLastProjectId,
|
|
14
|
-
setLastStatus,
|
|
15
|
-
} from "../diagnostics/diagnostics.js";
|
|
16
|
-
import { isRecord } from "../utils/util.js";
|
|
17
|
-
import { getCreditsStatus } from "../utils/credits.js";
|
|
18
|
-
import { safeError } from "../utils/security.js";
|
|
19
|
-
import { antigravityFetch } from "../utils/http.js";
|
|
20
|
-
import { extractRecommendedModelIds } from "../models/grouping.js";
|
|
21
|
-
import type {
|
|
22
|
-
AccountUsage,
|
|
23
|
-
ApiErrorBody,
|
|
24
|
-
AvailableModelsRaw,
|
|
25
|
-
CreditBalanceInfo,
|
|
26
|
-
LoadCodeAssistRaw,
|
|
27
|
-
ModelQuotaRow,
|
|
28
|
-
QuotaBucket,
|
|
29
|
-
QuotaGroup,
|
|
30
|
-
QuotaSummaryRaw,
|
|
31
|
-
TierInfo,
|
|
32
|
-
TierRaw,
|
|
33
|
-
} from "../types/types.js";
|
|
34
|
-
|
|
35
|
-
function clampFraction(value: unknown): number | undefined {
|
|
36
|
-
if (typeof value !== "number" || !Number.isFinite(value)) return undefined;
|
|
37
|
-
if (value < 0) return 0;
|
|
38
|
-
if (value > 1) return 1;
|
|
39
|
-
return value;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function remainingPercent(remaining?: number): number | undefined {
|
|
43
|
-
if (remaining === undefined) return undefined;
|
|
44
|
-
return Math.round(remaining * 1000) / 10;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function progressBar(remaining?: number, width = 20): string {
|
|
48
|
-
if (remaining === undefined) return `[${"?".repeat(width)}]`;
|
|
49
|
-
const filled = Math.max(0, Math.min(width, Math.round(remaining * width)));
|
|
50
|
-
return `[${"#".repeat(filled)}${"-".repeat(width - filled)}]`;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function formatReset(resetTime?: string): string {
|
|
54
|
-
if (!resetTime) return "n/a";
|
|
55
|
-
const ts = Date.parse(resetTime);
|
|
56
|
-
if (!Number.isFinite(ts)) return resetTime;
|
|
57
|
-
const delta = ts - Date.now();
|
|
58
|
-
if (delta <= 0) return "now";
|
|
59
|
-
const totalMin = Math.round(delta / 60000);
|
|
60
|
-
const days = Math.floor(totalMin / (60 * 24));
|
|
61
|
-
const hours = Math.floor((totalMin % (60 * 24)) / 60);
|
|
62
|
-
const mins = totalMin % 60;
|
|
63
|
-
if (days > 0) return `${days}d ${hours}h`;
|
|
64
|
-
if (hours > 0) return `${hours}h ${mins}m`;
|
|
65
|
-
return `${mins}m`;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function jsonHeaders(token: string): Record<string, string> {
|
|
69
|
-
return {
|
|
70
|
-
...antigravityHeaders(token),
|
|
71
|
-
Accept: "application/json",
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async function postJson(
|
|
76
|
-
path: string,
|
|
77
|
-
token: string,
|
|
78
|
-
body: Record<string, unknown>,
|
|
79
|
-
): Promise<{ endpoint: string; status: number; data: unknown }> {
|
|
80
|
-
let lastErrorText = "";
|
|
81
|
-
for (const endpoint of endpointCandidates()) {
|
|
82
|
-
try {
|
|
83
|
-
const res = await antigravityFetch(`${endpoint}${path}`, {
|
|
84
|
-
method: "POST",
|
|
85
|
-
headers: jsonHeaders(token),
|
|
86
|
-
body: JSON.stringify(body),
|
|
87
|
-
});
|
|
88
|
-
setLastEndpoint(endpoint);
|
|
89
|
-
setLastStatus(res.status);
|
|
90
|
-
const text = await res.text();
|
|
91
|
-
let data: unknown;
|
|
92
|
-
try {
|
|
93
|
-
data = JSON.parse(text) as unknown;
|
|
94
|
-
} catch {
|
|
95
|
-
data = { raw: text } satisfies ApiErrorBody;
|
|
96
|
-
}
|
|
97
|
-
if (!res.ok) {
|
|
98
|
-
const errorBody = isRecord(data) ? (data as ApiErrorBody) : undefined;
|
|
99
|
-
lastErrorText =
|
|
100
|
-
typeof errorBody?.error?.message === "string" ? errorBody.error.message : text;
|
|
101
|
-
if (![403, 404, 429, 500, 502, 503, 504].includes(res.status)) {
|
|
102
|
-
throw new Error(`${path} failed (${String(res.status)}): ${lastErrorText.slice(0, 300)}`);
|
|
103
|
-
}
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
return { endpoint, status: res.status, data };
|
|
107
|
-
} catch (error) {
|
|
108
|
-
lastErrorText = safeError(error);
|
|
109
|
-
setLastError(lastErrorText);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
throw new Error(`${path} failed: ${lastErrorText || "no endpoint available"}`);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function parseQuotaSummary(data: unknown): { groups: QuotaGroup[]; description?: string } {
|
|
116
|
-
const summary = (isRecord(data) ? data : {}) as QuotaSummaryRaw;
|
|
117
|
-
const groups: QuotaGroup[] = [];
|
|
118
|
-
for (const group of summary.groups || []) {
|
|
119
|
-
const buckets: QuotaBucket[] = [];
|
|
120
|
-
for (const bucket of group.buckets || []) {
|
|
121
|
-
const remaining = clampFraction(bucket.remainingFraction);
|
|
122
|
-
if (remaining === undefined && !bucket.bucketId) continue;
|
|
123
|
-
buckets.push({
|
|
124
|
-
bucketId: String(bucket.bucketId || bucket.displayName || "unknown"),
|
|
125
|
-
displayName: String(bucket.displayName || bucket.bucketId || "Limit"),
|
|
126
|
-
window: bucket.window ? String(bucket.window) : undefined,
|
|
127
|
-
resetTime: bucket.resetTime ? String(bucket.resetTime) : undefined,
|
|
128
|
-
description: bucket.description ? String(bucket.description) : undefined,
|
|
129
|
-
remainingFraction: remaining ?? 0,
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
if (!buckets.length && !group.displayName) continue;
|
|
133
|
-
groups.push({
|
|
134
|
-
displayName: String(group.displayName || "Quota group"),
|
|
135
|
-
description: group.description ? String(group.description) : undefined,
|
|
136
|
-
buckets,
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
groups,
|
|
141
|
-
description: summary.description ? String(summary.description) : undefined,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function parseModels(data: unknown): {
|
|
146
|
-
models: ModelQuotaRow[];
|
|
147
|
-
defaultAgentModelId?: string;
|
|
148
|
-
agentModelSorts?: unknown;
|
|
149
|
-
} {
|
|
150
|
-
const raw = (isRecord(data) ? data : {}) as AvailableModelsRaw;
|
|
151
|
-
const modelsObj = raw.models && isRecord(raw.models) ? raw.models : {};
|
|
152
|
-
const models: ModelQuotaRow[] = [];
|
|
153
|
-
const recommendedIds = extractRecommendedModelIds(raw.agentModelSorts);
|
|
154
|
-
for (const [modelId, info] of Object.entries(modelsObj)) {
|
|
155
|
-
if (!info || !isRecord(info)) continue;
|
|
156
|
-
if (info.isInternal || String(modelId).startsWith("chat_")) continue;
|
|
157
|
-
const qi = isRecord(info.quotaInfo) ? info.quotaInfo : {};
|
|
158
|
-
models.push({
|
|
159
|
-
modelId,
|
|
160
|
-
displayName:
|
|
161
|
-
typeof info.displayName === "string"
|
|
162
|
-
? info.displayName
|
|
163
|
-
: typeof info.label === "string"
|
|
164
|
-
? info.label
|
|
165
|
-
: typeof info.modelName === "string"
|
|
166
|
-
? info.modelName
|
|
167
|
-
: undefined,
|
|
168
|
-
remainingFraction: clampFraction(qi.remainingFraction),
|
|
169
|
-
resetTime: qi.resetTime ? String(qi.resetTime) : undefined,
|
|
170
|
-
modelProvider:
|
|
171
|
-
typeof info.modelProvider === "string"
|
|
172
|
-
? info.modelProvider
|
|
173
|
-
: typeof info.apiProvider === "string"
|
|
174
|
-
? info.apiProvider
|
|
175
|
-
: undefined,
|
|
176
|
-
supportsThinking: !!info.supportsThinking,
|
|
177
|
-
supportsImages: !!info.supportsImages,
|
|
178
|
-
recommended: !!info.recommended || (recommendedIds?.has(modelId) ?? false),
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
models.sort((a, b) => a.modelId.localeCompare(b.modelId));
|
|
182
|
-
return {
|
|
183
|
-
models,
|
|
184
|
-
defaultAgentModelId:
|
|
185
|
-
raw.defaultAgentModelId || raw.defaultAgentModel
|
|
186
|
-
? String(raw.defaultAgentModelId || raw.defaultAgentModel)
|
|
187
|
-
: undefined,
|
|
188
|
-
agentModelSorts: raw.agentModelSorts,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export function parseCredits(list: unknown): CreditBalanceInfo[] | undefined {
|
|
193
|
-
if (!Array.isArray(list)) return undefined;
|
|
194
|
-
const result: CreditBalanceInfo[] = [];
|
|
195
|
-
for (const item of list) {
|
|
196
|
-
if (!item || !isRecord(item)) continue;
|
|
197
|
-
const amt = item.creditAmount ?? item.credit_amount;
|
|
198
|
-
const min = item.minimumCreditAmountForUsage ?? item.minimum_credit_amount_for_usage;
|
|
199
|
-
const typ = item.creditType ?? item.credit_type;
|
|
200
|
-
const num = typeof amt === "number" ? amt : typeof amt === "string" ? Number(amt) : undefined;
|
|
201
|
-
if (num !== undefined && Number.isFinite(num)) {
|
|
202
|
-
result.push({
|
|
203
|
-
creditType: typeof typ === "string" ? typ : "GOOGLE_ONE_AI",
|
|
204
|
-
creditAmount: num,
|
|
205
|
-
minimumCreditAmountForUsage:
|
|
206
|
-
typeof min === "number" ? min : typeof min === "string" ? Number(min) : undefined,
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return result.length ? result : undefined;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function parseTier(value: unknown): TierInfo | undefined {
|
|
214
|
-
if (!isRecord(value)) return undefined;
|
|
215
|
-
const tier = value as TierRaw;
|
|
216
|
-
if (!tier.id && !tier.name) return undefined;
|
|
217
|
-
const credits = parseCredits(tier.availableCredits ?? tier.available_credits);
|
|
218
|
-
return {
|
|
219
|
-
id: tier.id ? String(tier.id) : undefined,
|
|
220
|
-
name: tier.name ? String(tier.name) : undefined,
|
|
221
|
-
description: tier.description ? String(tier.description) : undefined,
|
|
222
|
-
availableCredits: credits,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
async function loadCodeAssistSafe(token: string) {
|
|
227
|
-
try {
|
|
228
|
-
return await postJson("/v1internal:loadCodeAssist", token, {
|
|
229
|
-
metadata: {
|
|
230
|
-
ideType: "ANTIGRAVITY",
|
|
231
|
-
platform: "PLATFORM_UNSPECIFIED",
|
|
232
|
-
pluginType: "GEMINI",
|
|
233
|
-
},
|
|
234
|
-
});
|
|
235
|
-
} catch {
|
|
236
|
-
return null;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* The user-quota-summary RPC is gated behind a paid subscription: free-tier
|
|
242
|
-
* accounts get 403 SUBSCRIPTION_REQUIRED (#3501). It is best-effort diagnostics
|
|
243
|
-
* only — never let it block the rest of the account data (models, tier, project).
|
|
244
|
-
*/
|
|
245
|
-
async function fetchQuotaSummarySafe(token: string): Promise<
|
|
246
|
-
| { ok: true; result: { endpoint: string; status: number; data: unknown } }
|
|
247
|
-
| {
|
|
248
|
-
ok: false;
|
|
249
|
-
error: string;
|
|
250
|
-
}
|
|
251
|
-
> {
|
|
252
|
-
try {
|
|
253
|
-
return { ok: true, result: await postJson("/v1internal:retrieveUserQuotaSummary", token, {}) };
|
|
254
|
-
} catch (error) {
|
|
255
|
-
const msg = safeError(error);
|
|
256
|
-
setLastError(msg);
|
|
257
|
-
return { ok: false, error: msg };
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
export async function fetchAccountUsage(apiKeyRaw?: string): Promise<AccountUsage> {
|
|
262
|
-
const creds = parseApiKey(apiKeyRaw);
|
|
263
|
-
const initialProjectId =
|
|
264
|
-
creds.projectId ||
|
|
265
|
-
resolveProjectId({
|
|
266
|
-
token: creds.token,
|
|
267
|
-
credentialProjectId: creds.projectId,
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
// Fetch loadCodeAssist, quota summary, and available models all in parallel
|
|
271
|
-
// to minimize command execution latency.
|
|
272
|
-
const [assistResult, summaryRes, available] = await Promise.all([
|
|
273
|
-
loadCodeAssistSafe(creds.token),
|
|
274
|
-
fetchQuotaSummarySafe(creds.token),
|
|
275
|
-
fetchAvailableModelsCatalog(creds.token, initialProjectId),
|
|
276
|
-
]);
|
|
277
|
-
|
|
278
|
-
// Derive project ID from the loadCodeAssist response or stored project ID.
|
|
279
|
-
const discoveredProject = assistResult ? extractProjectId(assistResult.data) : undefined;
|
|
280
|
-
const projectId = resolveProjectId({
|
|
281
|
-
token: creds.token,
|
|
282
|
-
warmedProject: discoveredProject ?? null,
|
|
283
|
-
credentialProjectId: creds.projectId,
|
|
284
|
-
});
|
|
285
|
-
setLastProjectId(projectId);
|
|
286
|
-
|
|
287
|
-
const summary = summaryRes.ok ? summaryRes.result : null;
|
|
288
|
-
const quotaSummaryError = summaryRes.ok ? undefined : summaryRes.error;
|
|
289
|
-
const { groups, description } = summary
|
|
290
|
-
? parseQuotaSummary(summary.data)
|
|
291
|
-
: { groups: [], description: undefined };
|
|
292
|
-
const { models, defaultAgentModelId, agentModelSorts } = parseModels(available.data);
|
|
293
|
-
|
|
294
|
-
const assistData = (isRecord(assistResult?.data) ? assistResult.data : {}) as LoadCodeAssistRaw;
|
|
295
|
-
const productTier = parseTier(assistData.currentTier);
|
|
296
|
-
const paidTier = parseTier(assistData.paidTier);
|
|
297
|
-
const availableCredits =
|
|
298
|
-
paidTier?.availableCredits ??
|
|
299
|
-
productTier?.availableCredits ??
|
|
300
|
-
parseCredits(assistData.availableCredits ?? assistData.available_credits);
|
|
301
|
-
|
|
302
|
-
// Google returns currentTier=free-tier even for Google AI Pro accounts.
|
|
303
|
-
// The real subscription lives in paidTier (e.g. g1-pro-tier / Google AI Pro).
|
|
304
|
-
const planLabel = paidTier?.name
|
|
305
|
-
? `${paidTier.name}${paidTier.id ? ` (${paidTier.id})` : ""}`
|
|
306
|
-
: productTier?.name
|
|
307
|
-
? `${productTier.name}${productTier.id ? ` (${productTier.id})` : ""}`
|
|
308
|
-
: undefined;
|
|
309
|
-
|
|
310
|
-
return {
|
|
311
|
-
projectId,
|
|
312
|
-
endpoint: summary?.endpoint ?? available.endpoint ?? assistResult?.endpoint,
|
|
313
|
-
productTier,
|
|
314
|
-
paidTier,
|
|
315
|
-
planLabel,
|
|
316
|
-
availableCredits,
|
|
317
|
-
groups,
|
|
318
|
-
groupDescription: description,
|
|
319
|
-
quotaSummaryError,
|
|
320
|
-
models,
|
|
321
|
-
defaultAgentModelId,
|
|
322
|
-
agentModelSorts,
|
|
323
|
-
fetchedAt: Date.now(),
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
function quotaErrorNote(msg: string): string {
|
|
328
|
-
if (/SUBSCRIPTION_REQUIRED|#3501|(?:lack|missing).*license/i.test(msg)) {
|
|
329
|
-
return "Aggregate quota summary needs a paid subscription (free-tier can't use that endpoint). Per-model usage is still available via /antigravity.models.";
|
|
330
|
-
}
|
|
331
|
-
return `Aggregate quota summary unavailable: ${msg.slice(0, 160)}`;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
export function formatUsageSummary(usage: AccountUsage): string {
|
|
335
|
-
const lines: string[] = [];
|
|
336
|
-
|
|
337
|
-
if (usage.planLabel) lines.push(usage.planLabel);
|
|
338
|
-
|
|
339
|
-
if (!usage.groups.length) {
|
|
340
|
-
if (usage.quotaSummaryError) {
|
|
341
|
-
lines.push(quotaErrorNote(usage.quotaSummaryError));
|
|
342
|
-
} else {
|
|
343
|
-
lines.push("No quota groups returned.");
|
|
344
|
-
}
|
|
345
|
-
return lines.join("\n");
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
for (const group of usage.groups) {
|
|
349
|
-
if (lines.length) lines.push("");
|
|
350
|
-
lines.push(group.displayName);
|
|
351
|
-
for (const bucket of group.buckets) {
|
|
352
|
-
const rem = remainingPercent(bucket.remainingFraction);
|
|
353
|
-
lines.push(
|
|
354
|
-
` ${progressBar(bucket.remainingFraction)} ${bucket.displayName}: ${rem ?? "?"}% left · resets ${formatReset(bucket.resetTime)}`,
|
|
355
|
-
);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
return lines.join("\n").trimEnd();
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
export async function fetchRemainingCredits(apiKeyRaw?: string): Promise<{
|
|
363
|
-
availableCredits?: CreditBalanceInfo[];
|
|
364
|
-
overagesEnabled: boolean;
|
|
365
|
-
planLabel?: string;
|
|
366
|
-
}> {
|
|
367
|
-
const creds = parseApiKey(apiKeyRaw);
|
|
368
|
-
const assistResult = await loadCodeAssistSafe(creds.token);
|
|
369
|
-
const assistData = (isRecord(assistResult?.data) ? assistResult.data : {}) as LoadCodeAssistRaw;
|
|
370
|
-
const productTier = parseTier(assistData.currentTier);
|
|
371
|
-
const paidTier = parseTier(assistData.paidTier);
|
|
372
|
-
const availableCredits =
|
|
373
|
-
paidTier?.availableCredits ??
|
|
374
|
-
productTier?.availableCredits ??
|
|
375
|
-
parseCredits(assistData.availableCredits ?? assistData.available_credits);
|
|
376
|
-
const status = getCreditsStatus();
|
|
377
|
-
const planLabel = paidTier?.name
|
|
378
|
-
? `${paidTier.name}${paidTier.id ? ` (${paidTier.id})` : ""}`
|
|
379
|
-
: productTier?.name
|
|
380
|
-
? `${productTier.name}${productTier.id ? ` (${productTier.id})` : ""}`
|
|
381
|
-
: undefined;
|
|
382
|
-
|
|
383
|
-
return {
|
|
384
|
-
availableCredits,
|
|
385
|
-
overagesEnabled: status.enabled,
|
|
386
|
-
planLabel,
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
export function formatModelsList(usage: AccountUsage, opts?: { all?: boolean }): string {
|
|
391
|
-
const lines: string[] = [];
|
|
392
|
-
lines.push("Antigravity available models");
|
|
393
|
-
lines.push(`project=${usage.projectId}`);
|
|
394
|
-
if (usage.defaultAgentModelId) lines.push(`defaultAgentModel=${usage.defaultAgentModelId}`);
|
|
395
|
-
lines.push("");
|
|
396
|
-
|
|
397
|
-
const recommendedIds = extractRecommendedModelIds(usage.agentModelSorts);
|
|
398
|
-
const rows = opts?.all
|
|
399
|
-
? usage.models
|
|
400
|
-
: recommendedIds && recommendedIds.size > 0
|
|
401
|
-
? usage.models.filter((m) => recommendedIds.has(m.modelId))
|
|
402
|
-
: usage.models.filter((m) => !/tab_|chat_/i.test(m.modelId));
|
|
403
|
-
|
|
404
|
-
if (!rows.length) {
|
|
405
|
-
lines.push("No models returned.");
|
|
406
|
-
return lines.join("\n");
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
const maxId = Math.max(...rows.map((m) => m.modelId.length), 8);
|
|
410
|
-
for (const m of rows) {
|
|
411
|
-
const rem = remainingPercent(m.remainingFraction);
|
|
412
|
-
const flags = [
|
|
413
|
-
m.recommended ? "recommended" : "",
|
|
414
|
-
m.supportsThinking ? "thinking" : "",
|
|
415
|
-
m.supportsImages ? "images" : "",
|
|
416
|
-
]
|
|
417
|
-
.filter(Boolean)
|
|
418
|
-
.join(",");
|
|
419
|
-
const name = m.displayName && m.displayName !== m.modelId ? ` ${m.displayName}` : "";
|
|
420
|
-
lines.push(
|
|
421
|
-
`${m.modelId.padEnd(maxId)} rem ${rem === undefined ? " ?" : String(rem).padStart(5)}% reset ${formatReset(m.resetTime).padEnd(8)}${flags ? ` [${flags}]` : ""}${name}`,
|
|
422
|
-
);
|
|
423
|
-
}
|
|
424
|
-
lines.push("");
|
|
425
|
-
lines.push("Note: remaining % is pool-shared (not a private per-model budget).");
|
|
426
|
-
return lines.join("\n");
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
export async function resolveApiKeyFromContext(
|
|
430
|
-
ctx: ExtensionCommandContext,
|
|
431
|
-
): Promise<string | undefined> {
|
|
432
|
-
try {
|
|
433
|
-
return await ctx.modelRegistry.getApiKeyForProvider("antigravity");
|
|
434
|
-
} catch {
|
|
435
|
-
return undefined;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Which URLs the extension may ask anyone to fetch.
|
|
3
|
-
*
|
|
4
|
-
* One predicate serves two consumers with different consequences: the URL reader
|
|
5
|
-
* refuses a URL that fails it, and the search feature skips a source that fails it
|
|
6
|
-
* (and also checks DNS, because it contacts the site itself).
|
|
7
|
-
*
|
|
8
|
-
* Address literals are filtered against special-purpose IPv4 ranges and global IPv6
|
|
9
|
-
* space. This conservative filter is not a claim about DNS or future allocations.
|
|
10
|
-
*/
|
|
11
|
-
import { isIP } from "node:net";
|
|
12
|
-
|
|
13
|
-
/** Normalised URLs longer than this are refused rather than echoed or requested. */
|
|
14
|
-
const MAX_URL_LENGTH = 2_048;
|
|
15
|
-
|
|
16
|
-
/** IPv4 ranges outside the global unicast space (IANA special-purpose registry). */
|
|
17
|
-
const IPV4_NOT_GLOBAL: Array<[string, number]> = [
|
|
18
|
-
["0.0.0.0", 8],
|
|
19
|
-
["10.0.0.0", 8],
|
|
20
|
-
["100.64.0.0", 10],
|
|
21
|
-
["127.0.0.0", 8],
|
|
22
|
-
["169.254.0.0", 16],
|
|
23
|
-
["172.16.0.0", 12],
|
|
24
|
-
["192.0.0.0", 24],
|
|
25
|
-
["192.0.2.0", 24],
|
|
26
|
-
["192.88.99.0", 24],
|
|
27
|
-
["192.168.0.0", 16],
|
|
28
|
-
["198.18.0.0", 15],
|
|
29
|
-
["198.51.100.0", 24],
|
|
30
|
-
["203.0.113.0", 24],
|
|
31
|
-
["224.0.0.0", 4],
|
|
32
|
-
["240.0.0.0", 4],
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
/** Special-purpose blocks inside 2000::/3 that are not globally reachable. */
|
|
36
|
-
const IPV6_NOT_GLOBAL: Array<[number[], number]> = [
|
|
37
|
-
[[0x2001, 0x0000], 23],
|
|
38
|
-
[[0x2001, 0x0db8], 32],
|
|
39
|
-
[[0x2002], 16],
|
|
40
|
-
[[0x3fff, 0x0000], 20],
|
|
41
|
-
];
|
|
42
|
-
|
|
43
|
-
function ipv4Number(address: string): number {
|
|
44
|
-
return address.split(".").reduce((value, part) => value * 256 + Number(part), 0);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function inIpv4Range(value: number, [base, prefix]: [string, number]): boolean {
|
|
48
|
-
const size = 2 ** (32 - prefix);
|
|
49
|
-
const start = ipv4Number(base);
|
|
50
|
-
return value >= start && value < start + size;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function isGlobalIpv4(address: string): boolean {
|
|
54
|
-
const value = ipv4Number(address);
|
|
55
|
-
return value !== 0xffffffff && !IPV4_NOT_GLOBAL.some((range) => inIpv4Range(value, range));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Expand an IPv6 literal to eight 16-bit words, or undefined if it does not parse. */
|
|
59
|
-
function ipv6Words(address: string): number[] | undefined {
|
|
60
|
-
let canonical: string;
|
|
61
|
-
try {
|
|
62
|
-
// The URL parser canonicalises every spelling, including embedded dotted IPv4.
|
|
63
|
-
canonical = new URL(`http://[${address}]/`).hostname.slice(1, -1);
|
|
64
|
-
} catch {
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
const halves = canonical.split("::");
|
|
68
|
-
if (halves.length > 2) return undefined;
|
|
69
|
-
const left = halves[0] ? halves[0].split(":") : [];
|
|
70
|
-
const right = halves.length === 2 && halves[1] ? halves[1].split(":") : [];
|
|
71
|
-
const missing = 8 - left.length - right.length;
|
|
72
|
-
if (missing < 0 || (halves.length === 1 && missing !== 0)) return undefined;
|
|
73
|
-
const words = [...left, ...Array<string>(missing).fill("0"), ...right].map((word) =>
|
|
74
|
-
Number.parseInt(word, 16),
|
|
75
|
-
);
|
|
76
|
-
return words.every((word) => Number.isInteger(word) && word >= 0 && word <= 0xffff)
|
|
77
|
-
? words
|
|
78
|
-
: undefined;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function inIpv6Block(words: number[], [base, prefix]: [number[], number]): boolean {
|
|
82
|
-
for (let bit = 0; bit < prefix; bit += 16) {
|
|
83
|
-
const index = bit / 16;
|
|
84
|
-
const width = Math.min(16, prefix - bit);
|
|
85
|
-
const mask = (0xffff << (16 - width)) & 0xffff;
|
|
86
|
-
if ((words[index] & mask) !== ((base[index] ?? 0) & mask)) return false;
|
|
87
|
-
}
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function isGlobalIpv6(address: string): boolean {
|
|
92
|
-
const words = ipv6Words(address);
|
|
93
|
-
if (!words) return false;
|
|
94
|
-
// IPv4-mapped (::ffff:a.b.c.d) and IPv4-translated (::ffff:0:a.b.c.d) forms carry an
|
|
95
|
-
// IPv4 destination: judge that address, so public IPv4 stays reachable.
|
|
96
|
-
const mapped = words.slice(0, 5).every((word) => word === 0) && words[5] === 0xffff;
|
|
97
|
-
const translated =
|
|
98
|
-
words.slice(0, 4).every((word) => word === 0) && words[4] === 0xffff && words[5] === 0;
|
|
99
|
-
if (mapped || translated) {
|
|
100
|
-
return isGlobalIpv4([words[6] >> 8, words[6] & 255, words[7] >> 8, words[7] & 255].join("."));
|
|
101
|
-
}
|
|
102
|
-
if ((words[0] & 0xe000) !== 0x2000) return false; // global unicast is 2000::/3
|
|
103
|
-
return !IPV6_NOT_GLOBAL.some((block) => inIpv6Block(words, block));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/** Strip URL brackets and an interface zone (`fe80::1%eth0`). */
|
|
107
|
-
function bareAddress(address: string): string {
|
|
108
|
-
const bare = address.startsWith("[") && address.endsWith("]") ? address.slice(1, -1) : address;
|
|
109
|
-
return bare.split("%")[0];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** Whether an IP literal is globally routable. Names are not addresses: false. */
|
|
113
|
-
function isGloballyRoutable(address: string): boolean {
|
|
114
|
-
const bare = bareAddress(address);
|
|
115
|
-
const version = isIP(bare);
|
|
116
|
-
if (version === 4) return isGlobalIpv4(bare);
|
|
117
|
-
if (version === 6) return isGlobalIpv6(bare);
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/** True for an IP literal outside the global space. Host names return false. */
|
|
122
|
-
export function isPrivateAddress(address: string): boolean {
|
|
123
|
-
const bare = bareAddress(address);
|
|
124
|
-
return isIP(bare) !== 0 && !isGloballyRoutable(bare);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** Special-use names that only resolve on a local network (RFC 6761 and later). */
|
|
128
|
-
const LOCAL_NAME_SUFFIXES = [
|
|
129
|
-
"localhost",
|
|
130
|
-
"local",
|
|
131
|
-
"localdomain",
|
|
132
|
-
"internal",
|
|
133
|
-
"home.arpa",
|
|
134
|
-
"invalid",
|
|
135
|
-
"test",
|
|
136
|
-
"onion",
|
|
137
|
-
"alt",
|
|
138
|
-
];
|
|
139
|
-
|
|
140
|
-
/** Whether a host name or literal can only mean the local machine or network. */
|
|
141
|
-
function isLocalHost(hostname: string): boolean {
|
|
142
|
-
const host = hostname.toLowerCase().replace(/\.$/, "");
|
|
143
|
-
if (!host) return true;
|
|
144
|
-
if (isIP(bareAddress(host))) return !isGloballyRoutable(host);
|
|
145
|
-
// Decimal, hex, and short dotted forms (127.1, 0x7f000001) are IP literals too.
|
|
146
|
-
// Node's URL parser does not always canonicalise them into dotted quads.
|
|
147
|
-
if (/^(?:0x[0-9a-f]+|\d+)$/i.test(host)) return true;
|
|
148
|
-
if (/^(?:\d{1,3}|0x[0-9a-f]{1,2})(?:\.(?:\d{1,3}|0x[0-9a-f]{1,2})){1,3}$/i.test(host)) {
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
// A single-label name resolves through a local search domain, never on the internet.
|
|
152
|
-
if (!host.includes(".")) return true;
|
|
153
|
-
return LOCAL_NAME_SUFFIXES.some((suffix) => host === suffix || host.endsWith(`.${suffix}`));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export type UrlCheck =
|
|
157
|
-
| { ok: true; url: string }
|
|
158
|
-
| { ok: false; reason: "missing" | "invalid" | "scheme" | "credentials" | "local" | "too-long" };
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* May this URL be requested on the user's behalf? The answer is about the URL alone:
|
|
162
|
-
* a public http(s) address with no embedded credentials and a bounded length.
|
|
163
|
-
*/
|
|
164
|
-
export function checkPublicUrl(raw: string): UrlCheck {
|
|
165
|
-
const trimmed = typeof raw === "string" ? raw.trim() : "";
|
|
166
|
-
if (!trimmed) return { ok: false, reason: "missing" };
|
|
167
|
-
let parsed: URL;
|
|
168
|
-
try {
|
|
169
|
-
parsed = new URL(trimmed);
|
|
170
|
-
} catch {
|
|
171
|
-
return { ok: false, reason: "invalid" };
|
|
172
|
-
}
|
|
173
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
|
|
174
|
-
return { ok: false, reason: "scheme" };
|
|
175
|
-
if (parsed.username || parsed.password) return { ok: false, reason: "credentials" };
|
|
176
|
-
if (isLocalHost(parsed.hostname)) return { ok: false, reason: "local" };
|
|
177
|
-
const url = parsed.toString();
|
|
178
|
-
if (url.length > MAX_URL_LENGTH) return { ok: false, reason: "too-long" };
|
|
179
|
-
return { ok: true, url };
|
|
180
|
-
}
|