@heyhuynhgiabuu/pi-oauth-antigravity 0.1.4 → 0.1.6

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 CHANGED
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.6] - 2026-10-01
11
+
12
+ ### Fixed
13
+ - Kept the provider loadable in packaged Pi runtimes by moving pi-ai subpath helpers into a local module, matched to the resolved pi-ai 0.86.0 implementation.
14
+ - Excluded Gemini 3.5 Flash from the selectable catalog and added a pre-stream guard for the reported retirement notice so it is not emitted as assistant text.
15
+ - Defaulted image generation to `gemini-3.1-flash-image` while retaining older image models as explicit fallbacks.
16
+ - Made image path assertions portable across Windows and POSIX systems.
17
+
18
+ ## [0.1.5] - 2026-09-26
19
+
20
+ ### Fixed
21
+ - **`403 VALIDATION_REQUIRED` now reports the account verification Google actually requires.** When an account is blocked pending identity/phone verification, the error details carry a `validation_url` that the provider previously discarded, so users were told to "re-login or try another model" — neither of which can clear an account-level block. The message now links Google's verification flow, states that re-login and model switching will not help, and points at `/login antigravity` with another personal Google account as the alternative. Supplied links are rendered only when they are `https` URLs on Google-owned hosts, so a compromised or proxied response body cannot turn the error into a phishing link.
22
+
8
23
  ## [0.1.4] - 2026-09-20
9
24
 
10
25
  ### Fixed
package/README.md CHANGED
@@ -26,7 +26,6 @@ Google Antigravity OAuth provider extension for [Pi](https://pi.dev). Connects P
26
26
  | `antigravity/gemini-3.7-flash` | `gemini-3.7-flash-{low,medium,high}` | 65,536 | 1,048,576 |
27
27
  | `antigravity/gemini-3.7-flash-thinking` | `gemini-3.7-flash-thinking` | 65,536 | 1,048,576 |
28
28
  | `antigravity/gemini-3.6-flash` | `gemini-3.6-flash-{low,medium,high}` | 65,536 | 1,048,576 |
29
- | `antigravity/gemini-3.5-flash` | `gemini-3.5-flash` | 8,192 | 1,048,576 |
30
29
  | `antigravity/gemini-3.1-pro` | `gemini-3.1-pro` | 65,536 | 1,048,576 |
31
30
  | `antigravity/claude-sonnet-4-6` | `claude-sonnet-4-6` | 64,000 | 200,000 |
32
31
  | `antigravity/claude-opus-4-6` | `claude-opus-4-6` | 64,000 | 200,000 |
@@ -208,9 +208,6 @@ function buildModelMatchRegex(requestedId) {
208
208
  // gemini-3.6-flash-low → "Gemini 3.6 Flash (Low)"
209
209
  // gemini-3.6-flash-medium → "Gemini 3.6 Flash (Medium)"
210
210
  // gemini-3.6-flash-high → "Gemini 3.6 Flash (High)"
211
- // gemini-3.5-flash-extra-low → "Gemini 3.5 Flash (Low)"
212
- // gemini-3.5-flash-low → "Gemini 3.5 Flash (Medium)"
213
- // gemini-3-flash-agent → "Gemini 3.5 Flash (High)"
214
211
  if (req === "gemini-3.8-flash-low")
215
212
  return /gemini[- ]3\.8[- ]flash \(low\)/i;
216
213
  if (req === "gemini-3.8-flash-medium")
@@ -229,12 +226,6 @@ function buildModelMatchRegex(requestedId) {
229
226
  return /gemini[- ]3\.6[- ]flash \(medium\)/i;
230
227
  if (req === "gemini-3.6-flash-high")
231
228
  return /gemini[- ]3\.6[- ]flash \(high\)/i;
232
- if (req === "gemini-3.5-flash-extra-low")
233
- return /gemini[- ]3\.5[- ]flash \(low\)/i;
234
- if (req === "gemini-3.5-flash-low" || req === "gemini-3.5-flash-medium")
235
- return /gemini[- ]3\.5[- ]flash \(medium\)/i;
236
- if (req === "gemini-3.5-flash-high" || req === "gemini-3-flash-agent")
237
- return /gemini[- ]3\.5[- ]flash \(high\)/i;
238
229
  if (req.includes("claude-opus-4-6"))
239
230
  return /claude.*opus.*4\.6/i;
240
231
  if (req.includes("claude-sonnet-4-6"))
@@ -1,5 +1,5 @@
1
1
  import { AntigravityRequestType, AntigravityUserAgent, GeminiRole } from "../types/enums.js";
2
- export declare const DEFAULT_IMAGE_MODEL = "gemini-3-pro-image";
2
+ export declare const DEFAULT_IMAGE_MODEL = "gemini-3.1-flash-image";
3
3
  export declare const IMAGE_ASPECT_RATIOS: readonly ["1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9"];
4
4
  export type ImageAspectRatio = (typeof IMAGE_ASPECT_RATIOS)[number];
5
5
  export type GeneratedImage = {
@@ -5,7 +5,7 @@ import { AntigravityRequestType, AntigravityUserAgent, GeminiRole } from "../typ
5
5
  import { antigravityFetch } from "../utils/http.js";
6
6
  import { safeError } from "../utils/security.js";
7
7
  import { antigravityRequestEnvelope, sanitizeText } from "../utils/util.js";
8
- export const DEFAULT_IMAGE_MODEL = "gemini-3-pro-image";
8
+ export const DEFAULT_IMAGE_MODEL = "gemini-3.1-flash-image";
9
9
  export const IMAGE_ASPECT_RATIOS = [
10
10
  "1:1",
11
11
  "2:3",
@@ -20,7 +20,7 @@ export const IMAGE_ASPECT_RATIOS = [
20
20
  ];
21
21
  const IMAGE_MODEL_FALLBACKS = [
22
22
  DEFAULT_IMAGE_MODEL,
23
- "gemini-3.1-flash-image",
23
+ "gemini-3-pro-image",
24
24
  "gemini-3-pro-image-preview",
25
25
  ];
26
26
  const IMAGE_SYSTEM_INSTRUCTION = "You are an AI image generator. Generate images based on user descriptions. Focus on creating high-quality, visually appealing images that match the user's request.";
package/dist/index.js CHANGED
@@ -102,7 +102,7 @@ export default function (pi) {
102
102
  handler: async (args, ctx) => {
103
103
  const parsed = parseImageCommandArgs(args || "");
104
104
  if (!parsed.prompt) {
105
- emitCommandOutput(ctx, "Usage: /antigravity.image [--ratio 16:9] [--model gemini-3-pro-image] [--path file.png] <prompt>", "warning");
105
+ emitCommandOutput(ctx, "Usage: /antigravity.image [--ratio 16:9] [--model gemini-3.1-flash-image] [--path file.png] <prompt>", "warning");
106
106
  return;
107
107
  }
108
108
  try {
@@ -9,14 +9,15 @@ export declare const PROVIDER_NAME = "Antigravity";
9
9
  * - Gemini 3.8 Flash (Low / Medium / High)
10
10
  * - Gemini 3.7 Flash (Low / Medium / High)
11
11
  * - Gemini 3.6 Flash (Low / Medium / High)
12
- * - Gemini 3.5 Flash (Low / Medium / High)
13
12
  * - Gemini 3.1 Pro (Low / High)
14
13
  * - Claude Sonnet 4.6 (Thinking)
15
14
  * - Claude Opus 4.6 (Thinking)
16
15
  * - GPT-OSS 120B (Medium)
17
16
  *
18
- * Pi exposes those as public model IDs and only surfaces the exact thinking levels
19
- * advertised by the backend for each model.
17
+ * Gemini 3.5 Flash is intentionally omitted from the selectable catalog; the
18
+ * stream handler recognizes the reported retirement notice for old model IDs.
19
+ * Pi exposes the remaining models as public IDs and surfaces the exact thinking
20
+ * levels advertised by the backend for each model.
20
21
  */
21
22
  export declare const ANTIGRAVITY_ROUTING: Record<string, AntigravityRouting>;
22
23
  /**
@@ -8,14 +8,15 @@ export const PROVIDER_NAME = "Antigravity";
8
8
  * - Gemini 3.8 Flash (Low / Medium / High)
9
9
  * - Gemini 3.7 Flash (Low / Medium / High)
10
10
  * - Gemini 3.6 Flash (Low / Medium / High)
11
- * - Gemini 3.5 Flash (Low / Medium / High)
12
11
  * - Gemini 3.1 Pro (Low / High)
13
12
  * - Claude Sonnet 4.6 (Thinking)
14
13
  * - Claude Opus 4.6 (Thinking)
15
14
  * - GPT-OSS 120B (Medium)
16
15
  *
17
- * Pi exposes those as public model IDs and only surfaces the exact thinking levels
18
- * advertised by the backend for each model.
16
+ * Gemini 3.5 Flash is intentionally omitted from the selectable catalog; the
17
+ * stream handler recognizes the reported retirement notice for old model IDs.
18
+ * Pi exposes the remaining models as public IDs and surfaces the exact thinking
19
+ * levels advertised by the backend for each model.
19
20
  */
20
21
  export const ANTIGRAVITY_ROUTING = {
21
22
  "gemini-3.8-flash": {
@@ -86,17 +87,6 @@ export const ANTIGRAVITY_ROUTING = {
86
87
  },
87
88
  defaultRequestId: "gemini-3.6-flash-low",
88
89
  },
89
- "gemini-3.5-flash": {
90
- off: "gemini-3.5-flash-extra-low",
91
- routing: {
92
- minimal: "gemini-3.5-flash-extra-low",
93
- low: "gemini-3.5-flash-extra-low",
94
- medium: "gemini-3.5-flash-low",
95
- high: "gemini-3-flash-agent",
96
- xhigh: "gemini-3-flash-agent",
97
- },
98
- defaultRequestId: "gemini-3.5-flash-extra-low",
99
- },
100
90
  "gpt-oss-120b": {
101
91
  off: "gpt-oss-120b-medium",
102
92
  routing: {
@@ -128,10 +118,6 @@ export const RUNTIME_MAX_OUTPUT_TOKENS = {
128
118
  "gemini-3.6-flash-low": 65536,
129
119
  "gemini-3.6-flash-medium": 65536,
130
120
  "gemini-3.6-flash-high": 65536,
131
- "gemini-3.5-flash": 65536,
132
- "gemini-3.5-flash-extra-low": 65536,
133
- "gemini-3.5-flash-low": 65536,
134
- "gemini-3-flash-agent": 65536,
135
121
  "gemini-3.1-pro": 65535,
136
122
  "gemini-3.1-pro-low": 65535,
137
123
  "gemini-3.1-pro-high": 65535,
@@ -268,16 +254,6 @@ export const ANTIGRAVITY_MODELS = [
268
254
  contextWindow: 1048576,
269
255
  maxTokens: 65535,
270
256
  },
271
- {
272
- id: "gemini-3.5-flash",
273
- name: "Gemini 3.5 Flash (Antigravity)",
274
- reasoning: true,
275
- thinkingLevelMap: thinkingLevelMaps.lowMediumHigh,
276
- input: ["text", "image"],
277
- cost: geminiFlashCost,
278
- contextWindow: 1048576,
279
- maxTokens: 65536,
280
- },
281
257
  {
282
258
  id: "gpt-oss-120b",
283
259
  name: "GPT-OSS 120B (Antigravity)",
@@ -340,9 +316,6 @@ export function getFallbackRuntimeModel(runtimeModel, effort) {
340
316
  return undefined;
341
317
  }
342
318
  export const ANTIGRAVITY_MODEL_ENUM = {
343
- "gemini-3.5-flash-extra-low": "MODEL_PLACEHOLDER_M187",
344
- "gemini-3.5-flash-low": "MODEL_PLACEHOLDER_M20",
345
- "gemini-3-flash-agent": "MODEL_PLACEHOLDER_M132",
346
319
  "gemini-3.1-pro-low": "MODEL_PLACEHOLDER_M36",
347
320
  "gemini-pro-agent": "MODEL_PLACEHOLDER_M16",
348
321
  };
@@ -359,12 +332,6 @@ export function getThinkingConfig(modelId, effort) {
359
332
  modelId === "gemini-3.8-flash") {
360
333
  return { includeThoughts: true, thinkingLevel: googleLevel(effort) };
361
334
  }
362
- if (modelId === "gemini-3.5-flash") {
363
- if (!effort || effort === "off")
364
- return { includeThoughts: false, thinkingBudget: 0 };
365
- const thinkingBudget = effort === "high" || effort === "xhigh" ? 10_000 : effort === "medium" ? 4_000 : 1_000;
366
- return { includeThoughts: true, thinkingBudget };
367
- }
368
335
  if (modelId === "gemini-3.1-pro") {
369
336
  if (!effort || effort === "off")
370
337
  return { includeThoughts: false, thinkingBudget: 0 };
@@ -0,0 +1,4 @@
1
+ import type { Tool } from "@earendil-works/pi-ai";
2
+ export declare function getJsonSchemaToolParameters(tool: Tool, strict: boolean | undefined): unknown;
3
+ export declare function resolveJsonSchemaStrictSampling(tool: Tool, supportsStrictMode: boolean): boolean | undefined;
4
+ export declare function requiresToolCallId(modelId: string): boolean;
@@ -0,0 +1,149 @@
1
+ class UnsupportedStrictJsonSchemaError extends Error {
2
+ }
3
+ const UNSUPPORTED_STRICT_SCHEMA_KEYS = [
4
+ "$ref",
5
+ "$defs",
6
+ "definitions",
7
+ "allOf",
8
+ "oneOf",
9
+ "patternProperties",
10
+ "dependentSchemas",
11
+ "dependencies",
12
+ "unevaluatedProperties",
13
+ "propertyNames",
14
+ "contains",
15
+ "prefixItems",
16
+ "not",
17
+ "if",
18
+ "then",
19
+ "else",
20
+ ];
21
+ function isJsonSchemaObject(value) {
22
+ return typeof value === "object" && value !== null && !Array.isArray(value);
23
+ }
24
+ function isStructuredSchema(schema) {
25
+ if (!isJsonSchemaObject(schema))
26
+ return false;
27
+ const types = typeof schema.type === "string" ? [schema.type] : Array.isArray(schema.type) ? schema.type : [];
28
+ return (types.includes("object") ||
29
+ types.includes("array") ||
30
+ schema.properties !== undefined ||
31
+ schema.items !== undefined);
32
+ }
33
+ function schemaAllowsNull(schema) {
34
+ if (!isJsonSchemaObject(schema))
35
+ return false;
36
+ if (schema.type === "null" || (Array.isArray(schema.type) && schema.type.includes("null"))) {
37
+ return true;
38
+ }
39
+ if (schema.const === null || (Array.isArray(schema.enum) && schema.enum.includes(null))) {
40
+ return true;
41
+ }
42
+ return Array.isArray(schema.anyOf) && schema.anyOf.some((variant) => schemaAllowsNull(variant));
43
+ }
44
+ function makeJsonSchemaNodeStrict(schema) {
45
+ if (!isJsonSchemaObject(schema)) {
46
+ throw new UnsupportedStrictJsonSchemaError("boolean schemas are unsupported");
47
+ }
48
+ for (const key of UNSUPPORTED_STRICT_SCHEMA_KEYS) {
49
+ if (schema[key] !== undefined) {
50
+ throw new UnsupportedStrictJsonSchemaError(`${key} schemas are unsupported`);
51
+ }
52
+ }
53
+ if (schema.anyOf !== undefined) {
54
+ if (!Array.isArray(schema.anyOf) || schema.anyOf.length === 0) {
55
+ throw new UnsupportedStrictJsonSchemaError("anyOf must contain at least one schema");
56
+ }
57
+ for (const variant of schema.anyOf) {
58
+ if (isStructuredSchema(variant)) {
59
+ throw new UnsupportedStrictJsonSchemaError("object and array unions are unsupported");
60
+ }
61
+ makeJsonSchemaNodeStrict(variant);
62
+ }
63
+ }
64
+ if (schema.items !== undefined) {
65
+ if (Array.isArray(schema.items)) {
66
+ throw new UnsupportedStrictJsonSchemaError("tuple schemas are unsupported");
67
+ }
68
+ makeJsonSchemaNodeStrict(schema.items);
69
+ }
70
+ const isObjectSchema = schema.type === "object";
71
+ if (schema.properties !== undefined && !isObjectSchema) {
72
+ throw new UnsupportedStrictJsonSchemaError("properties require type object");
73
+ }
74
+ if (!isObjectSchema)
75
+ return;
76
+ if (schema.additionalProperties !== undefined && schema.additionalProperties !== false) {
77
+ throw new UnsupportedStrictJsonSchemaError("schema-valued or true additionalProperties is unsupported");
78
+ }
79
+ if (schema.properties !== undefined && !isJsonSchemaObject(schema.properties)) {
80
+ throw new UnsupportedStrictJsonSchemaError("object properties must be a schema map");
81
+ }
82
+ if (schema.required !== undefined &&
83
+ (!Array.isArray(schema.required) || schema.required.some((key) => typeof key !== "string"))) {
84
+ throw new UnsupportedStrictJsonSchemaError("object required must be a string array");
85
+ }
86
+ const properties = (schema.properties ?? {});
87
+ const propertyNames = Object.keys(properties);
88
+ const required = new Set(Array.isArray(schema.required) ? schema.required : []);
89
+ if ([...required].some((key) => !propertyNames.includes(key))) {
90
+ throw new UnsupportedStrictJsonSchemaError("required contains an unknown property");
91
+ }
92
+ for (const [key, property] of Object.entries(properties)) {
93
+ makeJsonSchemaNodeStrict(property);
94
+ if (!required.has(key) && !schemaAllowsNull(property)) {
95
+ properties[key] = { anyOf: [property, { type: "null" }] };
96
+ }
97
+ }
98
+ schema.required = propertyNames;
99
+ schema.additionalProperties = false;
100
+ }
101
+ /** Convert a tool schema to the strict subset expected by pi-ai 0.86.0. */
102
+ function makeStrictJsonSchema(schema) {
103
+ const cloned = structuredClone(schema);
104
+ if (!isJsonSchemaObject(cloned)) {
105
+ throw new UnsupportedStrictJsonSchemaError("root schema must have type object");
106
+ }
107
+ makeJsonSchemaNodeStrict(cloned);
108
+ if (cloned.type !== "object") {
109
+ throw new UnsupportedStrictJsonSchemaError("root schema must have type object");
110
+ }
111
+ return cloned;
112
+ }
113
+ export function getJsonSchemaToolParameters(tool, strict) {
114
+ const parameters = tool.parameters;
115
+ if (strict !== true)
116
+ return parameters;
117
+ return makeStrictJsonSchema(parameters);
118
+ }
119
+ export function resolveJsonSchemaStrictSampling(tool, supportsStrictMode) {
120
+ const samplingTool = tool;
121
+ const config = samplingTool.constrainedSampling;
122
+ if (!config || config.type !== "json_schema")
123
+ return undefined;
124
+ if (supportsStrictMode) {
125
+ try {
126
+ makeStrictJsonSchema(samplingTool.parameters);
127
+ return true;
128
+ }
129
+ catch (error) {
130
+ if (!(error instanceof UnsupportedStrictJsonSchemaError))
131
+ throw error;
132
+ if (config.strict !== "require")
133
+ return undefined;
134
+ throw new Error(`Tool "${tool.name}" requires JSON-schema constrained sampling, but ${error.message}.`);
135
+ }
136
+ }
137
+ if (config.strict === "require") {
138
+ throw new Error(`Tool "${tool.name}" requires JSON-schema constrained sampling, but strict tools are unsupported.`);
139
+ }
140
+ return undefined;
141
+ }
142
+ export function requiresToolCallId(modelId) {
143
+ if (modelId.startsWith("claude-") || modelId.startsWith("gpt-oss-"))
144
+ return true;
145
+ const match = modelId.toLowerCase().match(/^gemini(?:-live)?-(\d+)/);
146
+ if (!match)
147
+ return false;
148
+ return Number.parseInt(match[1], 10) >= 3;
149
+ }
@@ -19,8 +19,20 @@ export declare function convertTools(tools: Tool[] | undefined, useLegacyParamet
19
19
  export declare function buildRequest(model: Model<Api>, context: TranscriptContext, projectId: string, options: AntigravityStreamOptions, runtimeModel: string, sessionState?: AntigravitySessionState): AntigravityGenerateRequest;
20
20
  /** Exported for unit tests. */
21
21
  export declare function mapStopReason(reason: string | undefined): StopReason;
22
+ /**
23
+ * Google blocks an entire account — not one model — with 403 VALIDATION_REQUIRED until
24
+ * the account owner completes identity/phone verification. Neither re-login nor a model
25
+ * switch clears it, so the actionable `validation_url` in the error details has to reach
26
+ * the user instead of the generic "re-login or try another model" advice.
27
+ */
28
+ export interface AccountValidation {
29
+ message: string;
30
+ url?: string;
31
+ }
32
+ /** Exported for unit tests. */
33
+ export declare function extractAccountValidation(text: string): AccountValidation | undefined;
22
34
  /** Exported for unit tests. */
23
35
  export declare function friendlyAntigravityError(status: number | undefined, text: string): string;
24
36
  /** Exported for unit tests. */
25
- export declare function streamResponse(response: Response, stream: AssistantMessageEventStream, output: AssistantMessage, model?: Model<Api>, sessionState?: AntigravitySessionState): Promise<boolean>;
37
+ export declare function streamResponse(response: Response, stream: AssistantMessageEventStream, output: AssistantMessage, model?: Model<Api>, sessionState?: AntigravitySessionState, detectRetiredGemini35?: boolean): Promise<boolean>;
26
38
  export declare function streamAntigravity(model: Model<Api>, context: TranscriptContext, options?: AntigravityStreamOptions): AssistantMessageEventStream;
@@ -1,6 +1,5 @@
1
1
  import { calculateCost, createAssistantMessageEventStream, } from "@earendil-works/pi-ai";
2
- import { getJsonSchemaToolParameters, resolveJsonSchemaStrictSampling } from "@earendil-works/pi-ai/api/constrained-sampling";
3
- import { requiresToolCallId } from "@earendil-works/pi-ai/api/google-shared";
2
+ import { getJsonSchemaToolParameters, requiresToolCallId, resolveJsonSchemaStrictSampling, } from "./provider-helpers.js";
4
3
  import { getCurrentSystemPrompt, getCurrentTools } from "./transcript.js";
5
4
  import { antigravityHeaders, endpointCandidates, fetchAvailableRuntimeModel, formatRequestDiagnostics, jsonOrTextError, loadCodeAssist, parseApiKey, resolveProjectId, } from "../client/client.js";
6
5
  import { getCurrentEndpoint, runWithDiagnostics, setLastEndpoint, setLastError, setLastLatencyMs, setLastProjectId, setLastResolvedRuntimeModel, setLastStatus, } from "../diagnostics/diagnostics.js";
@@ -8,7 +7,7 @@ import { AntigravityRequestType, AntigravityUserAgent, GeminiRole, GeminiToolCal
8
7
  import { ANTIGRAVITY_ROUTING, getMaxOutputTokens, getAntigravityRequestModelId, getFallbackRuntimeModel, getThinkingConfig, PROVIDER_ID, } from "../models/models.js";
9
8
  import { redactSecrets, safeError } from "../utils/security.js";
10
9
  import { ANTIGRAVITY_API, } from "../types/types.js";
11
- import { antigravityEnv, antigravityRequestEnvelope, deriveAntigravitySessionId, getOrCreateAntigravitySession, isRecord, persistAntigravitySessions, sanitizeText, } from "../utils/util.js";
10
+ import { antigravityEnv, antigravityRequestEnvelope, asString, deriveAntigravitySessionId, getOrCreateAntigravitySession, isRecord, persistAntigravitySessions, sanitizeText, } from "../utils/util.js";
12
11
  import { antigravityFetch } from "../utils/http.js";
13
12
  export { ANTIGRAVITY_API };
14
13
  const ANTIGRAVITY_SYSTEM_INSTRUCTION = "You are Antigravity, a powerful agentic AI coding assistant designed by Google DeepMind. " +
@@ -496,6 +495,82 @@ export function mapStopReason(reason) {
496
495
  return StopReason.Length;
497
496
  return reason ? StopReason.Error : StopReason.Stop;
498
497
  }
498
+ const RETIRED_GEMINI_35_NOTICE_PREFIX = "gemini 3.5 flash is no longer available. please switch to";
499
+ function isRetiredGemini35Runtime(runtimeModel) {
500
+ return /^(?:gemini-3\.5-flash(?:-|$)|gemini-3-flash-agent$)/i.test(runtimeModel);
501
+ }
502
+ function retiredNoticePrefixState(text) {
503
+ const normalized = text.trimStart().replace(/\s+/g, " ").toLowerCase();
504
+ if (normalized.startsWith(RETIRED_GEMINI_35_NOTICE_PREFIX))
505
+ return "match";
506
+ if (RETIRED_GEMINI_35_NOTICE_PREFIX.startsWith(normalized))
507
+ return "possible";
508
+ return "no-match";
509
+ }
510
+ /**
511
+ * The URL is printed for the user to click, so only Google-owned https hosts are
512
+ * allowed. A response body is untrusted input just like any other; a foreign host here
513
+ * would be a ready-made phishing link.
514
+ */
515
+ function safeValidationUrl(raw) {
516
+ const trimmed = asString(raw)?.trim();
517
+ if (!trimmed)
518
+ return undefined;
519
+ let url;
520
+ try {
521
+ url = new URL(trimmed);
522
+ }
523
+ catch {
524
+ return undefined;
525
+ }
526
+ if (url.protocol !== "https:")
527
+ return undefined;
528
+ const host = url.hostname.toLowerCase();
529
+ const googleOwned = host === "google.com" ||
530
+ host.endsWith(".google.com") ||
531
+ host === "googleapis.com" ||
532
+ host.endsWith(".googleapis.com");
533
+ if (!googleOwned)
534
+ return undefined;
535
+ // Return the backend's exact string (not url.toString()) so Google's params survive
536
+ // verbatim; redactSecrets is the belt-and-braces check that no token rode along.
537
+ return redactSecrets(trimmed);
538
+ }
539
+ /** Exported for unit tests. */
540
+ export function extractAccountValidation(text) {
541
+ let parsed;
542
+ try {
543
+ parsed = JSON.parse(text);
544
+ }
545
+ catch {
546
+ return undefined;
547
+ }
548
+ const error = isRecord(parsed) ? parsed.error : undefined;
549
+ if (!isRecord(error) || !Array.isArray(error.details))
550
+ return undefined;
551
+ for (const detail of error.details) {
552
+ if (!isRecord(detail) || detail.reason !== "VALIDATION_REQUIRED")
553
+ continue;
554
+ const metadata = isRecord(detail.metadata) ? detail.metadata : {};
555
+ // Both candidates are response-body fields, so both are redacted like the rest of
556
+ // the backend text that reaches the user; neither can smuggle a token out.
557
+ const message = asString(metadata.validation_error_message) ?? asString(error.message) ?? "";
558
+ return {
559
+ message: redactSecrets(message).trim().slice(0, 200),
560
+ url: safeValidationUrl(metadata.validation_url),
561
+ };
562
+ }
563
+ return undefined;
564
+ }
565
+ function formatAccountValidation(validation) {
566
+ const next = validation.url
567
+ ? `complete verification at ${validation.url}`
568
+ : "complete Google account verification";
569
+ return ("Antigravity denied this account pending Google account verification (VALIDATION_REQUIRED). " +
570
+ `Re-login and switching models will not clear it. Next: ${next}, ` +
571
+ "or /login antigravity with another personal Google account." +
572
+ (validation.message ? ` Backend said: ${validation.message}` : ""));
573
+ }
499
574
  /** Exported for unit tests. */
500
575
  export function friendlyAntigravityError(status, text) {
501
576
  const full = redactSecrets(jsonOrTextError(text));
@@ -516,6 +591,15 @@ export function friendlyAntigravityError(status, text) {
516
591
  return "Antigravity authentication failed. Next: run /login antigravity, then retry.";
517
592
  }
518
593
  if (status === 403) {
594
+ // Account-level eligibility block. Checked before the generic permission test
595
+ // because a body can carry both signals and only this one is user-fixable.
596
+ const validation = extractAccountValidation(text);
597
+ if (validation)
598
+ return formatAccountValidation(validation);
599
+ // Fallback for gateways that strip `details` but keep the message.
600
+ if (/verify your account|VALIDATION_REQUIRED/i.test(msg)) {
601
+ return formatAccountValidation({ message: msg });
602
+ }
519
603
  if (/permission|forbidden|access/i.test(msg)) {
520
604
  return "Antigravity access was denied for this account or project. Next: try another model, re-login, or use an account with access.";
521
605
  }
@@ -523,7 +607,7 @@ export function friendlyAntigravityError(status, text) {
523
607
  }
524
608
  if (status === 404) {
525
609
  if (/Requested entity was not found/i.test(msg)) {
526
- return "This model is not available right now. Next: switch to gemini-3.7-flash, gemini-3.6-flash, gemini-3.5-flash, gemini-3.1-pro, or another working model.";
610
+ return "This model is not available right now. Next: switch to gemini-3.8-flash, gemini-3.7-flash, gemini-3.6-flash, gemini-3.1-pro, or another working model.";
527
611
  }
528
612
  return `Antigravity could not find the requested resource. Next: retry or switch models. Backend said: ${msg}`;
529
613
  }
@@ -584,7 +668,7 @@ function asToolCallArguments(args) {
584
668
  return (args ?? {});
585
669
  }
586
670
  /** Exported for unit tests. */
587
- export async function streamResponse(response, stream, output, model, sessionState) {
671
+ export async function streamResponse(response, stream, output, model, sessionState, detectRetiredGemini35 = false) {
588
672
  if (!response.body)
589
673
  throw new Error("No response body");
590
674
  const reader = response.body.getReader();
@@ -597,6 +681,9 @@ export async function streamResponse(response, stream, output, model, sessionSta
597
681
  let currentBlock = null;
598
682
  let hasContent = false;
599
683
  let lastResponseId;
684
+ let retiredNoticeCheck = detectRetiredGemini35
685
+ ? { text: "", parts: [] }
686
+ : undefined;
600
687
  const blocks = output.content;
601
688
  const blockIndex = () => blocks.length - 1;
602
689
  const ensureStarted = () => {
@@ -626,6 +713,58 @@ export async function streamResponse(response, stream, output, model, sessionSta
626
713
  }
627
714
  currentBlock = null;
628
715
  };
716
+ const appendText = (text, thoughtSignature) => {
717
+ if (!currentBlock || currentBlock.type !== "text") {
718
+ finishCurrent();
719
+ currentBlock = { type: "text", text: "" };
720
+ blocks.push(currentBlock);
721
+ ensureStarted();
722
+ stream.push({ type: "text_start", contentIndex: blockIndex(), partial: output });
723
+ }
724
+ if (currentBlock.type === "text") {
725
+ currentBlock.text += text;
726
+ if (thoughtSignature)
727
+ currentBlock.textSignature = thoughtSignature;
728
+ stream.push({
729
+ type: "text_delta",
730
+ contentIndex: blockIndex(),
731
+ delta: text,
732
+ partial: output,
733
+ });
734
+ }
735
+ };
736
+ const appendThinking = (text, thoughtSignature) => {
737
+ if (!currentBlock || currentBlock.type !== "thinking") {
738
+ finishCurrent();
739
+ currentBlock = { type: "thinking", thinking: "", thinkingSignature: undefined };
740
+ blocks.push(currentBlock);
741
+ ensureStarted();
742
+ stream.push({ type: "thinking_start", contentIndex: blockIndex(), partial: output });
743
+ }
744
+ if (currentBlock.type === "thinking") {
745
+ currentBlock.thinking += text;
746
+ if (thoughtSignature)
747
+ currentBlock.thinkingSignature = thoughtSignature;
748
+ stream.push({
749
+ type: "thinking_delta",
750
+ contentIndex: blockIndex(),
751
+ delta: text,
752
+ partial: output,
753
+ });
754
+ }
755
+ };
756
+ const flushPendingRetiredNoticeParts = () => {
757
+ if (!retiredNoticeCheck?.parts.length)
758
+ return;
759
+ const pendingParts = retiredNoticeCheck.parts;
760
+ retiredNoticeCheck = undefined;
761
+ for (const part of pendingParts) {
762
+ if (part.type === "thinking")
763
+ appendThinking(part.text, part.thoughtSignature);
764
+ else
765
+ appendText(part.text, part.thoughtSignature);
766
+ }
767
+ };
629
768
  while (true) {
630
769
  const result = await reader.read();
631
770
  if (result.done)
@@ -658,45 +797,48 @@ export async function streamResponse(response, stream, output, model, sessionSta
658
797
  if (part.text !== undefined) {
659
798
  hasContent = true;
660
799
  const isThinking = part.thought === true;
661
- const type = isThinking ? "thinking" : "text";
662
- if (!currentBlock || currentBlock.type !== type) {
663
- finishCurrent();
664
- currentBlock = isThinking
665
- ? { type: "thinking", thinking: "", thinkingSignature: undefined }
666
- : { type: "text", text: "" };
667
- blocks.push(currentBlock);
668
- ensureStarted();
669
- stream.push({
670
- type: isThinking ? "thinking_start" : "text_start",
671
- contentIndex: blockIndex(),
672
- partial: output,
800
+ const noticeCheck = retiredNoticeCheck;
801
+ if (!isThinking &&
802
+ noticeCheck &&
803
+ (part.text.length > 0 || noticeCheck.parts.length > 0)) {
804
+ noticeCheck.parts.push({
805
+ type: "text",
806
+ text: part.text,
807
+ thoughtSignature: part.thoughtSignature,
673
808
  });
809
+ noticeCheck.text += part.text;
810
+ const noticeState = retiredNoticePrefixState(noticeCheck.text);
811
+ if (noticeState === "match") {
812
+ try {
813
+ await reader.cancel();
814
+ }
815
+ catch {
816
+ // The response is being discarded; cancellation is best-effort.
817
+ }
818
+ reader.releaseLock();
819
+ throw new Error("Antigravity reports that Gemini 3.5 Flash is no longer available. " +
820
+ "Next: switch to gemini-3.8-flash, gemini-3.7-flash, or another catalog model.");
821
+ }
822
+ if (noticeState !== "possible")
823
+ flushPendingRetiredNoticeParts();
674
824
  }
675
- if (isThinking && currentBlock.type === "thinking") {
676
- currentBlock.thinking += part.text;
677
- if (part.thoughtSignature)
678
- currentBlock.thinkingSignature = part.thoughtSignature;
679
- stream.push({
680
- type: "thinking_delta",
681
- contentIndex: blockIndex(),
682
- delta: part.text,
683
- partial: output,
825
+ else if (isThinking && noticeCheck?.parts.length) {
826
+ noticeCheck.parts.push({
827
+ type: "thinking",
828
+ text: part.text,
829
+ thoughtSignature: part.thoughtSignature,
684
830
  });
685
831
  }
686
- else if (!isThinking && currentBlock.type === "text") {
687
- currentBlock.text += part.text;
688
- if (part.thoughtSignature)
689
- currentBlock.textSignature = part.thoughtSignature;
690
- stream.push({
691
- type: "text_delta",
692
- contentIndex: blockIndex(),
693
- delta: part.text,
694
- partial: output,
695
- });
832
+ else if (isThinking) {
833
+ appendThinking(part.text, part.thoughtSignature);
834
+ }
835
+ else {
836
+ appendText(part.text, part.thoughtSignature);
696
837
  }
697
838
  }
698
839
  if (part.functionCall) {
699
840
  hasContent = true;
841
+ flushPendingRetiredNoticeParts();
700
842
  finishCurrent();
701
843
  const rawId = part.functionCall.id || "";
702
844
  const toolCall = {
@@ -754,6 +896,7 @@ export async function streamResponse(response, stream, output, model, sessionSta
754
896
  scanStart = 0;
755
897
  }
756
898
  }
899
+ flushPendingRetiredNoticeParts();
757
900
  finishCurrent();
758
901
  if (sessionState && lastResponseId) {
759
902
  sessionState.lastExecutionId = lastResponseId;
@@ -912,7 +1055,7 @@ export function streamAntigravity(model, context, options) {
912
1055
  cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
913
1056
  };
914
1057
  output.stopReason = "stop";
915
- received = await streamResponse(response, stream, output, model, sessionState);
1058
+ received = await streamResponse(response, stream, output, model, sessionState, isRetiredGemini35Runtime(runtimeModel));
916
1059
  if (received)
917
1060
  break;
918
1061
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heyhuynhgiabuu/pi-oauth-antigravity",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Google Antigravity OAuth provider extension for Pi with Gemini 3.8, prompt cache session affinity, and trajectory chaining.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",