@heyhuynhgiabuu/pi-oauth-antigravity 0.1.5 → 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,16 @@ 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
+
8
18
  ## [0.1.5] - 2026-09-26
9
19
 
10
20
  ### 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
+ }
@@ -34,5 +34,5 @@ export declare function extractAccountValidation(text: string): AccountValidatio
34
34
  /** Exported for unit tests. */
35
35
  export declare function friendlyAntigravityError(status: number | undefined, text: string): string;
36
36
  /** Exported for unit tests. */
37
- 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>;
38
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";
@@ -496,6 +495,18 @@ 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
+ }
499
510
  /**
500
511
  * The URL is printed for the user to click, so only Google-owned https hosts are
501
512
  * allowed. A response body is untrusted input just like any other; a foreign host here
@@ -596,7 +607,7 @@ export function friendlyAntigravityError(status, text) {
596
607
  }
597
608
  if (status === 404) {
598
609
  if (/Requested entity was not found/i.test(msg)) {
599
- 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.";
600
611
  }
601
612
  return `Antigravity could not find the requested resource. Next: retry or switch models. Backend said: ${msg}`;
602
613
  }
@@ -657,7 +668,7 @@ function asToolCallArguments(args) {
657
668
  return (args ?? {});
658
669
  }
659
670
  /** Exported for unit tests. */
660
- export async function streamResponse(response, stream, output, model, sessionState) {
671
+ export async function streamResponse(response, stream, output, model, sessionState, detectRetiredGemini35 = false) {
661
672
  if (!response.body)
662
673
  throw new Error("No response body");
663
674
  const reader = response.body.getReader();
@@ -670,6 +681,9 @@ export async function streamResponse(response, stream, output, model, sessionSta
670
681
  let currentBlock = null;
671
682
  let hasContent = false;
672
683
  let lastResponseId;
684
+ let retiredNoticeCheck = detectRetiredGemini35
685
+ ? { text: "", parts: [] }
686
+ : undefined;
673
687
  const blocks = output.content;
674
688
  const blockIndex = () => blocks.length - 1;
675
689
  const ensureStarted = () => {
@@ -699,6 +713,58 @@ export async function streamResponse(response, stream, output, model, sessionSta
699
713
  }
700
714
  currentBlock = null;
701
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
+ };
702
768
  while (true) {
703
769
  const result = await reader.read();
704
770
  if (result.done)
@@ -731,45 +797,48 @@ export async function streamResponse(response, stream, output, model, sessionSta
731
797
  if (part.text !== undefined) {
732
798
  hasContent = true;
733
799
  const isThinking = part.thought === true;
734
- const type = isThinking ? "thinking" : "text";
735
- if (!currentBlock || currentBlock.type !== type) {
736
- finishCurrent();
737
- currentBlock = isThinking
738
- ? { type: "thinking", thinking: "", thinkingSignature: undefined }
739
- : { type: "text", text: "" };
740
- blocks.push(currentBlock);
741
- ensureStarted();
742
- stream.push({
743
- type: isThinking ? "thinking_start" : "text_start",
744
- contentIndex: blockIndex(),
745
- 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,
746
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();
747
824
  }
748
- if (isThinking && currentBlock.type === "thinking") {
749
- currentBlock.thinking += part.text;
750
- if (part.thoughtSignature)
751
- currentBlock.thinkingSignature = part.thoughtSignature;
752
- stream.push({
753
- type: "thinking_delta",
754
- contentIndex: blockIndex(),
755
- delta: part.text,
756
- partial: output,
825
+ else if (isThinking && noticeCheck?.parts.length) {
826
+ noticeCheck.parts.push({
827
+ type: "thinking",
828
+ text: part.text,
829
+ thoughtSignature: part.thoughtSignature,
757
830
  });
758
831
  }
759
- else if (!isThinking && currentBlock.type === "text") {
760
- currentBlock.text += part.text;
761
- if (part.thoughtSignature)
762
- currentBlock.textSignature = part.thoughtSignature;
763
- stream.push({
764
- type: "text_delta",
765
- contentIndex: blockIndex(),
766
- delta: part.text,
767
- partial: output,
768
- });
832
+ else if (isThinking) {
833
+ appendThinking(part.text, part.thoughtSignature);
834
+ }
835
+ else {
836
+ appendText(part.text, part.thoughtSignature);
769
837
  }
770
838
  }
771
839
  if (part.functionCall) {
772
840
  hasContent = true;
841
+ flushPendingRetiredNoticeParts();
773
842
  finishCurrent();
774
843
  const rawId = part.functionCall.id || "";
775
844
  const toolCall = {
@@ -827,6 +896,7 @@ export async function streamResponse(response, stream, output, model, sessionSta
827
896
  scanStart = 0;
828
897
  }
829
898
  }
899
+ flushPendingRetiredNoticeParts();
830
900
  finishCurrent();
831
901
  if (sessionState && lastResponseId) {
832
902
  sessionState.lastExecutionId = lastResponseId;
@@ -985,7 +1055,7 @@ export function streamAntigravity(model, context, options) {
985
1055
  cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
986
1056
  };
987
1057
  output.stopReason = "stop";
988
- received = await streamResponse(response, stream, output, model, sessionState);
1058
+ received = await streamResponse(response, stream, output, model, sessionState, isRetiredGemini35Runtime(runtimeModel));
989
1059
  if (received)
990
1060
  break;
991
1061
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heyhuynhgiabuu/pi-oauth-antigravity",
3
- "version": "0.1.5",
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",