Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 84 additions & 38 deletions apps/server/src/provider/Layers/AntigravityAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,23 @@ export function resolveAntigravitySpawnCommand(
if (!binary.includes("\\") && !binary.includes("/")) {
const localAppData = env.LOCALAPPDATA?.trim();
const userProfile = env.USERPROFILE?.trim();
const appData = env.APPDATA?.trim();
if (localAppData && NodeFS.existsSync(`${localAppData}\\agy\\bin\\agy.exe`)) {
resolvedBinary = `${localAppData}\\agy\\bin\\agy.exe`;
} else if (
userProfile &&
NodeFS.existsSync(`${userProfile}\\.gemini\\antigravity\\bin\\agy.exe`)
) {
resolvedBinary = `${userProfile}\\.gemini\\antigravity\\bin\\agy.exe`;
} else if (
localAppData &&
NodeFS.existsSync(`${localAppData}\\Programs\\Antigravity\\bin\\agy.exe`)
) {
resolvedBinary = `${localAppData}\\Programs\\Antigravity\\bin\\agy.exe`;
} else if (appData && NodeFS.existsSync(`${appData}\\Antigravity\\bin\\agy.exe`)) {
resolvedBinary = `${appData}\\Antigravity\\bin\\agy.exe`;
} else if (appData && NodeFS.existsSync(`${appData}\\Roaming\\Antigravity\\bin\\agy.exe`)) {
resolvedBinary = `${appData}\\Roaming\\Antigravity\\bin\\agy.exe`;
}
}

Expand Down Expand Up @@ -279,7 +289,10 @@ export function makeAntigravityAdapter(
const selectedModel =
input.modelSelection?.model ?? ctx.currentModelId ?? "gemini-3.7-flash";
const effortOption = input.modelSelection?.options?.find((opt) => opt.id === "effort");
const effortValue = typeof effortOption?.value === "string" ? effortOption.value : "medium";
const rawEffort =
typeof effortOption?.value === "string" ? effortOption.value.trim().toLowerCase() : "";
const validEfforts = ["low", "medium", "high"];
const effortValue = validEfforts.includes(rawEffort) ? rawEffort : "medium";

let spawnCommand: { command: string; args: Array<string>; shell: boolean };

Expand Down Expand Up @@ -475,7 +488,28 @@ export function makeAntigravityAdapter(
conversationId: ctx.agyConversationId,
};
}
if (typeof res.response === "string" && !fullText) {
if (res.status === "ERROR" || res.error) {
const errorMsg = String(
res.error || res.response || "Antigravity turn error",
);
if (!fullText) {
fullText = `Error: ${errorMsg}`;
yield* emitEvent({
eventId: makeEventId("content.delta", input.threadId, turnId),
provider: PROVIDER,
providerInstanceId: instanceId,
threadId: input.threadId,
turnId,
itemId,
createdAt: new Date().toISOString(),
type: "content.delta",
payload: {
streamKind: "assistant_text",
delta: `\n\n**Error:** ${errorMsg}\n`,
},
});
}
} else if (typeof res.response === "string" && !fullText) {
fullText = res.response;
yield* emitEvent({
eventId: makeEventId("content.delta", input.threadId, turnId),
Expand Down Expand Up @@ -546,26 +580,30 @@ export function makeAntigravityAdapter(

yield* Effect.all(
[
Stream.runForEach(child.stdout, (chunk) =>
Effect.gen(function* () {
const text = new TextDecoder().decode(chunk);
yield* Effect.logInfo("antigravity.stdout.chunk", { textLength: text.length });
stdoutBuffer += text;

const lines = stdoutBuffer.split("\n");
stdoutBuffer = lines.pop() ?? "";

for (const line of lines) {
yield* processLine(line);
}
}),
child.stdout.pipe(
Stream.decodeText(),
Stream.runForEach((text) =>
Effect.gen(function* () {
yield* Effect.logInfo("antigravity.stdout.chunk", { textLength: text.length });
stdoutBuffer += text;

const lines = stdoutBuffer.split("\n");
stdoutBuffer = lines.pop() ?? "";

for (const line of lines) {
yield* processLine(line);
}
}),
),
),
Stream.runForEach(child.stderr, (chunk) =>
Effect.gen(function* () {
const errChunk = new TextDecoder().decode(chunk);
stderrText += errChunk;
yield* Effect.logWarning("antigravity.stderr.chunk", { text: errChunk });
}),
child.stderr.pipe(
Stream.decodeText(),
Stream.runForEach((errChunk) =>
Effect.gen(function* () {
stderrText += errChunk;
yield* Effect.logWarning("antigravity.stderr.chunk", { text: errChunk });
}),
),
),
],
{ concurrency: "unbounded" },
Expand All @@ -583,23 +621,30 @@ export function makeAntigravityAdapter(
agyConversationId: ctx.agyConversationId,
});

if (exitCode !== 0 && stderrText.trim() && !fullText) {
const errMessage = stderrText.trim();
fullText = `Error: ${errMessage}`;
yield* emitEvent({
eventId: makeEventId("content.delta", input.threadId, turnId),
provider: PROVIDER,
providerInstanceId: instanceId,
threadId: input.threadId,
turnId,
itemId,
createdAt: new Date().toISOString(),
type: "content.delta",
payload: {
streamKind: "assistant_text",
delta: fullText,
},
});
let errorMessage: string | undefined;
if (exitCode !== 0) {
errorMessage =
stderrText.trim() ||
(fullText.startsWith("Error:")
? fullText
: `Antigravity process exited with non-zero status (${exitCode}).`);
if (!fullText) {
fullText = `Error: ${errorMessage}`;
yield* emitEvent({
eventId: makeEventId("content.delta", input.threadId, turnId),
provider: PROVIDER,
providerInstanceId: instanceId,
threadId: input.threadId,
turnId,
itemId,
createdAt: new Date().toISOString(),
type: "content.delta",
payload: {
streamKind: "assistant_text",
delta: `\n\n**Error:** ${errorMessage}\n`,
},
});
}
}

ctx.turns.push({ id: turnId, items: [{ prompt: textPrompt, response: fullText }] });
Expand Down Expand Up @@ -631,6 +676,7 @@ export function makeAntigravityAdapter(
type: "turn.completed",
payload: {
state: exitCode === 0 ? "completed" : "failed",
...(errorMessage ? { errorMessage } : {}),
...(ctx.agyConversationId ? { providerThreadId: ctx.agyConversationId } : {}),
...(ctx.session.resumeCursor !== undefined
? { resumeCursor: ctx.session.resumeCursor }
Expand Down
5 changes: 5 additions & 0 deletions apps/server/src/provider/scripts/antigravity_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import os
import sys

if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8")
if hasattr(sys.stderr, "reconfigure"):
sys.stderr.reconfigure(encoding="utf-8")

def emit_event(event_type: str, data: dict):
payload = {"type": event_type, **data}
sys.stdout.write(json.dumps(payload) + "\n")
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading