u-foo 4.0.5 → 4.0.10
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/README.md +224 -19
- package/README.zh-CN.md +3 -3
- package/bin/ucode.js +10 -2
- package/bin/ufoo.js +3 -0
- package/dist/tui/darwin-arm64/ufoo-tui +0 -0
- package/dist/tui/darwin-x64/ufoo-tui +0 -0
- package/dist/tui/linux-arm64/ufoo-tui +0 -0
- package/dist/tui/linux-x64/ufoo-tui +0 -0
- package/{OBSERVABILITY.md → docs/OBSERVABILITY.md} +3 -3
- package/docs/README.md +27 -0
- package/extensions/ufoo-browser/LICENSE +152 -0
- package/extensions/ufoo-browser/NOTICE +10 -0
- package/extensions/ufoo-browser/README.md +30 -0
- package/extensions/ufoo-browser/background.js +409 -0
- package/extensions/ufoo-browser/icons/icon-128.png +0 -0
- package/extensions/ufoo-browser/icons/icon-16.png +0 -0
- package/extensions/ufoo-browser/icons/icon-256.png +0 -0
- package/extensions/ufoo-browser/icons/icon-32.png +0 -0
- package/extensions/ufoo-browser/icons/icon-48.png +0 -0
- package/extensions/ufoo-browser/icons/logo.png +0 -0
- package/extensions/ufoo-browser/icons/toolbar-16.png +0 -0
- package/extensions/ufoo-browser/icons/toolbar-32.png +0 -0
- package/extensions/ufoo-browser/icons/toolbar-logo.png +0 -0
- package/extensions/ufoo-browser/manifest.json +30 -0
- package/extensions/ufoo-browser/popup.css +71 -0
- package/extensions/ufoo-browser/popup.html +44 -0
- package/extensions/ufoo-browser/popup.js +153 -0
- package/package.json +5 -3
- package/scripts/postinstall.js +6 -0
- package/src/agents/capabilities/browser/index.js +49 -0
- package/src/agents/capabilities/coding/backgroundHooks.js +94 -0
- package/src/agents/capabilities/coding/index.js +30 -1
- package/src/agents/capabilities/index.js +5 -2
- package/src/agents/capabilities/planning/index.js +44 -5
- package/src/agents/capabilities/turnRecall/index.js +341 -0
- package/src/agents/controller/controllerToolExecutor.js +2 -2
- package/src/agents/internal/internalRunner.js +30 -8
- package/src/agents/internal/taskControl.js +107 -0
- package/src/agents/profiles/coding.js +1 -1
- package/src/agents/profiles/main.js +1 -1
- package/src/agents/prompts/mainAgent.js +1 -0
- package/src/agents/prompts/native/toolDescriptions/bash.js +7 -1
- package/src/agents/providers/claudeSessionFiles.js +1 -1
- package/src/agents/providers/codexThreadProvider.js +6 -1
- package/src/agents/providers/credentials/agy.js +171 -0
- package/src/agents/providers/directAuthStatus.js +20 -2
- package/src/agents/providers/modelsCatalog.js +26 -5
- package/src/agents/providers/nativeTransport.js +36 -20
- package/src/agents/providers/providerId.js +17 -0
- package/src/agents/providers/runtimeConfig.js +26 -19
- package/src/agents/providers/transports/antigravityTransport.js +242 -0
- package/src/agents/providers/transports/index.js +1 -0
- package/src/agents/providers/transports/openaiChatTransport.js +3 -2
- package/src/agents/providers/transports/openaiResponsesTransport.js +2 -1
- package/src/agents/providers/transports/responsesProtocol.js +119 -18
- package/src/agents/providers/transports/transportContract.js +1 -0
- package/src/agents/providers/upstreamRuntime.js +3 -1
- package/src/agents/runtime/context/contextBudget.js +1 -19
- package/src/agents/runtime/context/contextWindow.js +5 -0
- package/src/agents/runtime/context/replayHistory.js +16 -10
- package/src/agents/runtime/context/runtimeStore.js +0 -2
- package/src/agents/runtime/context/sessionJournal.js +1 -1
- package/src/agents/runtime/context/slidingWindowManager.js +792 -0
- package/src/agents/runtime/context/topicSelector.js +338 -0
- package/src/agents/runtime/context/turnAnalyzer.js +767 -0
- package/src/agents/runtime/context/turnIndexStore.js +515 -0
- package/src/agents/runtime/core/agentLoop.js +95 -32
- package/src/agents/runtime/core/executionBudget.js +2 -1
- package/src/agents/runtime/core/toolErrorGuard.js +39 -0
- package/src/agents/runtime/createAgentRuntime.js +80 -7
- package/src/agents/runtime/index.js +5 -0
- package/src/agents/runtime/protocol/materialize.js +1 -1
- package/src/agents/runtime/tasks/hooks.js +137 -0
- package/src/app/chat/ChatController.js +8 -4
- package/src/app/chat/daemonMessageRouter.js +3 -1
- package/src/app/chat/inputSubmitHandler.js +2 -2
- package/src/app/chat/transport.js +1 -1
- package/src/app/cli/browserCommands.js +340 -0
- package/src/app/cli/features/doctor.js +21 -0
- package/src/app/cli/metricsCommands.js +1 -1
- package/src/app/cli/run.js +80 -1
- package/src/app/cli/setupCommands.js +200 -0
- package/src/code/UcodeController.js +31 -1
- package/src/code/agent.js +41 -7
- package/src/code/busConsumer.js +13 -12
- package/src/code/commands.js +0 -1
- package/src/code/context/assembler.js +11 -88
- package/src/code/context/planGraphService.js +83 -9
- package/src/code/context/planProjection.js +10 -2
- package/src/code/context/reducers.js +172 -4
- package/src/code/context/stateCommit.js +0 -32
- package/src/code/context/transcript.js +7 -4
- package/src/code/internalThread.js +9 -1
- package/src/code/launcher/ucode.js +4 -2
- package/src/code/nativeRunner.js +221 -10
- package/src/code/repl.js +27 -1
- package/src/code/runtime/agentWakeup.js +20 -3
- package/src/code/runtime/backgroundWakeHost.js +45 -0
- package/src/code/runtime/taskFocusContext.js +7 -0
- package/src/code/runtime/taskLoop.js +24 -1
- package/src/code/sessionStore.js +14 -10
- package/src/code/taskDecomposer.js +13 -7
- package/src/code/tools/backgroundProcess.js +23 -0
- package/src/code/tools/bash.js +764 -12
- package/src/code/tools/executor.js +12 -4
- package/src/code/tools/specs.js +60 -3
- package/src/code/tools/taskRun.js +38 -0
- package/src/config.js +92 -6
- package/src/coordination/bus/subscriber.js +1 -1
- package/src/coordination/history/agentPerformance.js +18 -18
- package/src/coordination/history/agentTrace.js +7 -3
- package/src/coordination/state/workspaceAccess.js +3 -1
- package/src/orchestration/groups/modelConfig.js +66 -0
- package/src/orchestration/groups/validateTemplate.js +2 -0
- package/src/runtime/browser/broker.js +1027 -0
- package/src/runtime/browser/brokerClient.js +108 -0
- package/src/runtime/browser/componentInstaller.js +275 -0
- package/src/runtime/browser/installState.js +329 -0
- package/src/runtime/browser/manifest.js +145 -0
- package/src/runtime/browser/native-host-runner.js +198 -0
- package/src/runtime/browser/nativeHost.js +213 -0
- package/src/runtime/browser/nativeMessagingProtocol.js +50 -0
- package/src/runtime/browser/paths.js +134 -0
- package/src/runtime/browser/playwrightSession.js +614 -0
- package/src/runtime/daemon/agentHost.js +175 -30
- package/src/runtime/daemon/busBridge.js +2 -1
- package/src/runtime/daemon/globalDaemon.js +20 -0
- package/src/runtime/daemon/groupOrchestrator.js +20 -1
- package/src/runtime/daemon/index.js +5 -4
- package/src/runtime/daemon/ops.js +14 -8
- package/src/tools/handlers/listAgents.js +1 -1
- package/src/tools/handlers/readBusSummary.js +1 -1
- package/src/tools/handlers/routeAgent.js +122 -5
- package/src/tools/schemaFixtures.js +1 -1
- package/src/ui/agentSurface.js +26 -3
- package/src/ui/format/index.js +34 -2
- package/src/ui/rustChatHost.js +22 -7
- package/src/ui/rustMultiSession.js +14 -2
- package/src/ui/rustUcodeHost.js +246 -77
- package/src/ui/ucodeAgentSession.js +88 -0
- package/templates/groups/build-lane.json +57 -3
- package/templates/groups/build-ultra.json +114 -6
- package/templates/groups/design-system.json +57 -3
- package/templates/groups/product-discovery.json +57 -3
- package/templates/groups/ui-plan-review.json +57 -3
- package/templates/groups/ui-polish.json +57 -3
- package/templates/groups/verify-ship.json +57 -3
- package/src/agents/runtime/context/checkpointStore.js +0 -52
- package/src/agents/runtime/context/compaction.js +0 -171
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { execFile } = require("child_process");
|
|
4
|
+
const { createHash } = require("crypto");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const os = require("os");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const { promisify } = require("util");
|
|
9
|
+
|
|
10
|
+
const DEFAULT_AGY_BASE_URL = "https://daily-cloudcode-pa.googleapis.com";
|
|
11
|
+
const AGY_SETUP_HINT = "Sign in with `agy`, or set UFOO_AGY_ACCESS_TOKEN or UFOO_AGY_AUTH_PATH.";
|
|
12
|
+
const CLOUD_CODE_ORIGINS = new Set([
|
|
13
|
+
DEFAULT_AGY_BASE_URL,
|
|
14
|
+
"https://cloudcode-pa.googleapis.com",
|
|
15
|
+
"https://daily-cloudcode-pa.sandbox.googleapis.com",
|
|
16
|
+
]);
|
|
17
|
+
const KEYRING_ENCODING = "go-keyring-base64:";
|
|
18
|
+
const execFileAsync = (...args) => promisify(execFile)(...args);
|
|
19
|
+
let refreshInFlight;
|
|
20
|
+
let projectCache;
|
|
21
|
+
|
|
22
|
+
function parseLocalLogin(raw) {
|
|
23
|
+
try {
|
|
24
|
+
const text = raw.trim();
|
|
25
|
+
const entry = JSON.parse(text.startsWith(KEYRING_ENCODING)
|
|
26
|
+
? Buffer.from(text.slice(KEYRING_ENCODING.length), "base64").toString("utf8")
|
|
27
|
+
: text);
|
|
28
|
+
return { accessToken: String(entry.token?.access_token || "").trim(), expiresAt: String(entry.token?.expiry || "") };
|
|
29
|
+
} catch {
|
|
30
|
+
throw new Error("Unable to read the local agy login. Sign in again with `agy`.");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function readLocalLogin({ homeDir, platform, runCommand }) {
|
|
35
|
+
const options = { timeout: 20000, maxBuffer: 128 * 1024 };
|
|
36
|
+
if (platform === "darwin") {
|
|
37
|
+
try {
|
|
38
|
+
const { stdout } = await runCommand("/usr/bin/security", ["find-generic-password", "-s", "gemini", "-a", "antigravity", "-w"], options);
|
|
39
|
+
return { ...parseLocalLogin(stdout), source: "agy macOS Keychain" };
|
|
40
|
+
} catch (error) {
|
|
41
|
+
if (error.code !== 44) {
|
|
42
|
+
throw new Error("Unable to read the agy Keychain item. Allow access in macOS or configure UFOO_AGY_AUTH_PATH.");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (platform === "linux") {
|
|
47
|
+
try {
|
|
48
|
+
const { stdout } = await runCommand("secret-tool", ["lookup", "service", "gemini", "username", "antigravity"], options);
|
|
49
|
+
if (stdout.trim()) return { ...parseLocalLogin(stdout), source: "agy Secret Service" };
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (error.code !== "ENOENT" && error.code !== 1) {
|
|
52
|
+
throw new Error("Unable to read the agy Secret Service item. Unlock the keyring or configure UFOO_AGY_AUTH_PATH.");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
let raw;
|
|
57
|
+
try {
|
|
58
|
+
raw = await fs.promises.readFile(path.join(homeDir, ".gemini", "antigravity-cli", "antigravity-oauth-token"), "utf8");
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (error.code === "ENOENT") return null;
|
|
61
|
+
throw new Error("Cannot read the local agy auth file.");
|
|
62
|
+
}
|
|
63
|
+
return { ...parseLocalLogin(raw), source: "agy auth file" };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function expiryIsDue(expiresAt) {
|
|
67
|
+
return Date.parse(expiresAt) <= Date.now() + 30000;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function refreshLocalLogin(options) {
|
|
71
|
+
if (!refreshInFlight) {
|
|
72
|
+
const installed = path.join(options.homeDir, ".local", "bin", "agy");
|
|
73
|
+
const command = fs.existsSync(installed) ? installed : "agy";
|
|
74
|
+
refreshInFlight = Promise.resolve().then(() => options.runCommand(command, ["models"], {
|
|
75
|
+
cwd: os.tmpdir(), env: { ...options.env, AGY_CLI_DISABLE_AUTO_UPDATE: "true" },
|
|
76
|
+
timeout: 20000, maxBuffer: 256 * 1024,
|
|
77
|
+
})).catch(() => {
|
|
78
|
+
throw new Error("Antigravity login needs renewal. Open `agy` and check your sign-in.");
|
|
79
|
+
}).finally(() => { refreshInFlight = null; });
|
|
80
|
+
}
|
|
81
|
+
await refreshInFlight;
|
|
82
|
+
return readLocalLogin(options);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function buildAgyHeaders({ accessToken, userAgent }) {
|
|
86
|
+
return {
|
|
87
|
+
Authorization: `Bearer ${accessToken}`,
|
|
88
|
+
"Content-Type": "application/json",
|
|
89
|
+
"User-Agent": userAgent,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function discoverAgyProject({ baseUrl, credential, fetchImpl, signal }) {
|
|
94
|
+
const origin = new URL(baseUrl).origin;
|
|
95
|
+
const key = createHash("sha256").update(origin).update("\0").update(credential.accessToken).digest("hex");
|
|
96
|
+
if (projectCache?.key === key && projectCache.expiresAt > Date.now()) return projectCache.projectId;
|
|
97
|
+
|
|
98
|
+
const timeout = AbortSignal.timeout(8000);
|
|
99
|
+
const response = await fetchImpl(`${origin}/v1internal:loadCodeAssist`, {
|
|
100
|
+
method: "POST",
|
|
101
|
+
headers: buildAgyHeaders(credential),
|
|
102
|
+
body: JSON.stringify({ metadata: { ideType: "ANTIGRAVITY" } }),
|
|
103
|
+
signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
|
|
104
|
+
redirect: "error",
|
|
105
|
+
});
|
|
106
|
+
if (!response.ok) {
|
|
107
|
+
throw new Error(`Antigravity project lookup failed (HTTP ${response.status}). Check your sign-in with \`agy\`.`);
|
|
108
|
+
}
|
|
109
|
+
const payload = await response.json();
|
|
110
|
+
const project = payload.cloudaicompanionProject || payload.projectId || payload.project;
|
|
111
|
+
const projectId = typeof project === "string" ? project.trim() : String(project?.id || "").trim();
|
|
112
|
+
if (!projectId) throw new Error("Antigravity did not return a Cloud Code project. Open `agy` to finish account setup.");
|
|
113
|
+
projectCache = { key, projectId, expiresAt: Date.now() + 10 * 60 * 1000 };
|
|
114
|
+
return projectId;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function resolveAgyCredentials({
|
|
118
|
+
apiKey = "", env = process.env, homeDir = os.homedir(), platform = process.platform,
|
|
119
|
+
runCommand = execFileAsync, fetchImpl = global.fetch, baseUrl = env.UFOO_AGY_BASE_URL || DEFAULT_AGY_BASE_URL,
|
|
120
|
+
signal, requireProject = true,
|
|
121
|
+
} = {}) {
|
|
122
|
+
const explicitToken = String(apiKey || env.UFOO_AGY_ACCESS_TOKEN || "").trim();
|
|
123
|
+
const authPath = String(env.UFOO_AGY_AUTH_PATH || "").trim();
|
|
124
|
+
let credential;
|
|
125
|
+
let projectId = String(env.UFOO_AGY_PROJECT_ID || "").trim();
|
|
126
|
+
let storedUserAgent = "";
|
|
127
|
+
if (explicitToken) {
|
|
128
|
+
credential = { accessToken: explicitToken, expiresAt: "", source: "configured access token" };
|
|
129
|
+
} else if (authPath) {
|
|
130
|
+
let data;
|
|
131
|
+
try {
|
|
132
|
+
const file = authPath.startsWith("~/") ? path.join(homeDir, authPath.slice(2)) : authPath;
|
|
133
|
+
data = JSON.parse(await fs.promises.readFile(file, "utf8"));
|
|
134
|
+
} catch {
|
|
135
|
+
throw new Error("Cannot read Antigravity auth JSON from UFOO_AGY_AUTH_PATH.");
|
|
136
|
+
}
|
|
137
|
+
if (data?.type !== "antigravity" || data.disabled === true) {
|
|
138
|
+
throw new Error("UFOO_AGY_AUTH_PATH must point to an enabled Antigravity auth file.");
|
|
139
|
+
}
|
|
140
|
+
credential = { accessToken: String(data.access_token || "").trim(),
|
|
141
|
+
expiresAt: String(data.expired || "").trim(), source: "Antigravity auth file" };
|
|
142
|
+
projectId ||= String(data.project_id || "").trim();
|
|
143
|
+
storedUserAgent = data.user_agent;
|
|
144
|
+
} else {
|
|
145
|
+
if (!CLOUD_CODE_ORIGINS.has(new URL(baseUrl).origin)) {
|
|
146
|
+
throw new Error("Set explicit Antigravity credentials for the configured API URL.");
|
|
147
|
+
}
|
|
148
|
+
const options = { env, homeDir, platform, runCommand };
|
|
149
|
+
credential = await readLocalLogin(options);
|
|
150
|
+
if (credential?.accessToken && requireProject && expiryIsDue(credential.expiresAt)) {
|
|
151
|
+
credential = await refreshLocalLogin(options);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (!credential?.accessToken) {
|
|
155
|
+
throw Object.assign(new Error(`Antigravity API credentials are missing. ${AGY_SETUP_HINT}`),
|
|
156
|
+
{ code: "AGY_CREDENTIALS_MISSING" });
|
|
157
|
+
}
|
|
158
|
+
if (Date.parse(credential.expiresAt) <= Date.now()) {
|
|
159
|
+
throw new Error("Antigravity access token expired. Renew it with the client that manages it.");
|
|
160
|
+
}
|
|
161
|
+
credential.userAgent = String(env.UFOO_AGY_USER_AGENT || storedUserAgent || "antigravity/hub/2.32.1 darwin/arm64").trim();
|
|
162
|
+
if (!projectId && requireProject) {
|
|
163
|
+
if (!CLOUD_CODE_ORIGINS.has(new URL(baseUrl).origin)) {
|
|
164
|
+
throw new Error("Set UFOO_AGY_PROJECT_ID for the configured Antigravity API URL.");
|
|
165
|
+
}
|
|
166
|
+
projectId = await discoverAgyProject({ baseUrl, credential, fetchImpl, signal });
|
|
167
|
+
}
|
|
168
|
+
return { ...credential, projectId };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
module.exports = { DEFAULT_AGY_BASE_URL, AGY_SETUP_HINT, resolveAgyCredentials, buildAgyHeaders };
|
|
@@ -4,6 +4,7 @@ const fs = require("fs");
|
|
|
4
4
|
const os = require("os");
|
|
5
5
|
const path = require("path");
|
|
6
6
|
const { loadConfig } = require("../../config");
|
|
7
|
+
const { AGY_SETUP_HINT, resolveAgyCredentials } = require("./credentials/agy");
|
|
7
8
|
const {
|
|
8
9
|
resolveCodexAuthPaths,
|
|
9
10
|
resolveCodexUpstreamCredentials,
|
|
@@ -250,7 +251,7 @@ async function inspectAgyDirectAuth({
|
|
|
250
251
|
const classification = classifyAgyLogTail(tail);
|
|
251
252
|
const base = {
|
|
252
253
|
provider: "agy",
|
|
253
|
-
transport: "antigravity-tui",
|
|
254
|
+
transport: "antigravity-tui",
|
|
254
255
|
credentialKind: "oauth",
|
|
255
256
|
source: "google-keyring",
|
|
256
257
|
credentialPath: file || logDir || "",
|
|
@@ -371,7 +372,18 @@ async function inspectDirectAuthStatus(options = {}) {
|
|
|
371
372
|
return inspectClaudeDirectAuth(nextOptions);
|
|
372
373
|
}
|
|
373
374
|
if (selected === "agy") {
|
|
374
|
-
|
|
375
|
+
const env = options.env || process.env;
|
|
376
|
+
const base = { provider: "agy", transport: "antigravity", credentialKind: "oauth" };
|
|
377
|
+
try {
|
|
378
|
+
const { source, expiresAt } = await resolveAgyCredentials({
|
|
379
|
+
env, homeDir: options.homeDir, platform: options.platform, requireProject: false,
|
|
380
|
+
});
|
|
381
|
+
return { ...base, ok: true, state: "present", source, expiresAt };
|
|
382
|
+
} catch (error) {
|
|
383
|
+
const cli = error.code === "AGY_CREDENTIALS_MISSING" ? await inspectAgyDirectAuth(nextOptions) : null;
|
|
384
|
+
return { ...base, ok: false, errorCode: error.code || "AGY_API_CREDENTIALS",
|
|
385
|
+
error: error.message, cliAuthenticated: cli?.ok === true };
|
|
386
|
+
}
|
|
375
387
|
}
|
|
376
388
|
if (selected === "kimi") {
|
|
377
389
|
return inspectKimiDirectAuth(nextOptions);
|
|
@@ -479,6 +491,12 @@ function formatClaudeDirectAuthStatus(status = {}, options = {}) {
|
|
|
479
491
|
}
|
|
480
492
|
|
|
481
493
|
function formatAgyDirectAuthStatus(status = {}, options = {}) {
|
|
494
|
+
if (status.transport === "antigravity") {
|
|
495
|
+
return status.ok
|
|
496
|
+
? [`Agy API: credentials present · ${status.source}`]
|
|
497
|
+
: [`Agy API: ${status.error || AGY_SETUP_HINT}`,
|
|
498
|
+
...(status.cliAuthenticated ? [" The agy CLI is signed in with its keychain credentials."] : [])];
|
|
499
|
+
}
|
|
482
500
|
if (options.compact === true) {
|
|
483
501
|
if (status.ok) {
|
|
484
502
|
const details = [
|
|
@@ -13,6 +13,8 @@ const CACHE_TTL_MS = 60_000;
|
|
|
13
13
|
const { createHash } = require("crypto");
|
|
14
14
|
const { resolveCodexClientVersion, resolveCodexUserAgent, resolveGrokClientVersion } = require("./clientIdentity");
|
|
15
15
|
const { normalizeProvider } = require("./runtimeConfig");
|
|
16
|
+
const { DEFAULT_AGY_BASE_URL, resolveAgyCredentials, buildAgyHeaders } = require("./credentials/agy");
|
|
17
|
+
const { resolveAgyUrl } = require("./transports/antigravityTransport");
|
|
16
18
|
|
|
17
19
|
const OFFICIAL_MODEL_ORIGINS = Object.freeze({
|
|
18
20
|
openai: ["https://api.openai.com"],
|
|
@@ -21,6 +23,7 @@ const OFFICIAL_MODEL_ORIGINS = Object.freeze({
|
|
|
21
23
|
kimi: ["https://api.kimi.com"],
|
|
22
24
|
"grok-build": ["https://api.x.ai"],
|
|
23
25
|
xai: ["https://api.x.ai"],
|
|
26
|
+
agy: [DEFAULT_AGY_BASE_URL, "https://cloudcode-pa.googleapis.com"],
|
|
24
27
|
});
|
|
25
28
|
|
|
26
29
|
function usesCustomModelEndpoint({ provider = "", transport = "", baseUrl = "", allowUnlistedModels = false } = {}) {
|
|
@@ -72,6 +75,7 @@ function resolveAnthropicModelsUrl(baseUrl = "") {
|
|
|
72
75
|
}
|
|
73
76
|
|
|
74
77
|
function resolveModelsUrl({ transport = "", baseUrl = "", provider = "", clientVersion = "", codexHome = "" } = {}) {
|
|
78
|
+
if (transport === "antigravity") return baseUrl ? resolveAgyUrl(baseUrl, "fetchAvailableModels") : "";
|
|
75
79
|
let url;
|
|
76
80
|
if (String(transport || "") === "anthropic-messages") {
|
|
77
81
|
url = resolveAnthropicModelsUrl(baseUrl);
|
|
@@ -173,7 +177,15 @@ async function listProviderModels(options = {}) {
|
|
|
173
177
|
const timeoutMs = Math.max(1000, Number(options.timeoutMs) || DEFAULT_TIMEOUT_MS);
|
|
174
178
|
const fetchImpl = typeof options.fetchImpl === "function" ? options.fetchImpl : fetch;
|
|
175
179
|
const skipCache = options.skipCache === true;
|
|
176
|
-
const
|
|
180
|
+
const antigravity = transport === "antigravity";
|
|
181
|
+
let url = "";
|
|
182
|
+
let agy;
|
|
183
|
+
try {
|
|
184
|
+
url = resolveModelsUrl({ transport, baseUrl, provider, clientVersion: options.clientVersion, codexHome: options.codexHome });
|
|
185
|
+
if (url && antigravity) agy = await resolveAgyCredentials({ apiKey, env: options.env, baseUrl, fetchImpl });
|
|
186
|
+
} catch (error) {
|
|
187
|
+
return { ok: false, models: [], url, error: error.message, status: 0, cached: false };
|
|
188
|
+
}
|
|
177
189
|
|
|
178
190
|
if (!url) {
|
|
179
191
|
return {
|
|
@@ -186,7 +198,8 @@ async function listProviderModels(options = {}) {
|
|
|
186
198
|
};
|
|
187
199
|
}
|
|
188
200
|
|
|
189
|
-
const key = cacheKey({ transport, baseUrl, url, apiKey, provider,
|
|
201
|
+
const key = cacheKey({ transport, baseUrl, url, apiKey: agy?.accessToken || apiKey, provider,
|
|
202
|
+
requestHeaders: agy ? { project: agy.projectId, userAgent: agy.userAgent } : requestHeaders });
|
|
190
203
|
if (!skipCache) {
|
|
191
204
|
const hit = modelsCache.get(key);
|
|
192
205
|
if (hit && (Date.now() - hit.at) < CACHE_TTL_MS) {
|
|
@@ -210,7 +223,12 @@ async function listProviderModels(options = {}) {
|
|
|
210
223
|
do {
|
|
211
224
|
if (seenPages.has(nextUrl)) throw new Error("models route repeated a pagination cursor");
|
|
212
225
|
seenPages.add(nextUrl);
|
|
213
|
-
const response = await fetchImpl(nextUrl, {
|
|
226
|
+
const response = await fetchImpl(nextUrl, agy ? {
|
|
227
|
+
method: "POST",
|
|
228
|
+
headers: { Accept: "application/json", ...buildAgyHeaders(agy) },
|
|
229
|
+
body: JSON.stringify({ project: agy.projectId }),
|
|
230
|
+
signal: controller?.signal,
|
|
231
|
+
} : {
|
|
214
232
|
method: "GET",
|
|
215
233
|
headers: { ...buildListHeaders({ transport, apiKey, provider, clientVersion: options.clientVersion, codexHome: options.codexHome }), ...requestHeaders },
|
|
216
234
|
signal: controller ? controller.signal : undefined,
|
|
@@ -236,11 +254,14 @@ async function listProviderModels(options = {}) {
|
|
|
236
254
|
return result;
|
|
237
255
|
}
|
|
238
256
|
|
|
239
|
-
|
|
257
|
+
const pageModels = agy && payload?.models && typeof payload.models === "object" && !Array.isArray(payload.models)
|
|
258
|
+
? Object.keys(payload.models)
|
|
259
|
+
: extractModelIds(payload, { visibleOnly: provider.toLowerCase() === "codex" });
|
|
260
|
+
for (const id of pageModels) {
|
|
240
261
|
if (!models.includes(id)) models.push(id);
|
|
241
262
|
}
|
|
242
263
|
nextUrl = "";
|
|
243
|
-
if (payload && payload.has_more) {
|
|
264
|
+
if (!agy && payload && payload.has_more) {
|
|
244
265
|
const cursor = payload.last_id || payload.data?.at(-1)?.id;
|
|
245
266
|
if (!cursor) throw new Error("models route omitted its pagination cursor");
|
|
246
267
|
const pageUrl = new URL(url);
|
|
@@ -826,32 +826,25 @@ function extractAnthropicToolCalls(content = []) {
|
|
|
826
826
|
}));
|
|
827
827
|
}
|
|
828
828
|
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
const last = copy[lastIndex];
|
|
838
|
-
if (!last || typeof last !== "object" || Array.isArray(last)) return copy;
|
|
839
|
-
if (typeof last.content === "string") {
|
|
840
|
-
if (!last.content) return copy;
|
|
841
|
-
copy[lastIndex] = {
|
|
842
|
-
...last,
|
|
829
|
+
const STABLE_HISTORY_BOUNDARY_SYMBOL = Symbol.for("ufoo.stableHistoryBoundary");
|
|
830
|
+
|
|
831
|
+
function stampAnthropicCacheBlock(msg) {
|
|
832
|
+
if (!msg || typeof msg !== "object" || Array.isArray(msg)) return msg;
|
|
833
|
+
if (typeof msg.content === "string") {
|
|
834
|
+
if (!msg.content) return msg;
|
|
835
|
+
return {
|
|
836
|
+
...msg,
|
|
843
837
|
content: [
|
|
844
838
|
{
|
|
845
839
|
type: "text",
|
|
846
|
-
text:
|
|
840
|
+
text: msg.content,
|
|
847
841
|
cache_control: { ...ANTHROPIC_CACHE_CONTROL },
|
|
848
842
|
},
|
|
849
843
|
],
|
|
850
844
|
};
|
|
851
|
-
return copy;
|
|
852
845
|
}
|
|
853
|
-
if (Array.isArray(
|
|
854
|
-
const blocks =
|
|
846
|
+
if (Array.isArray(msg.content) && msg.content.length > 0) {
|
|
847
|
+
const blocks = msg.content.slice();
|
|
855
848
|
const blockIndex = blocks.length - 1;
|
|
856
849
|
const block = blocks[blockIndex];
|
|
857
850
|
if (block && typeof block === "object" && !Array.isArray(block)) {
|
|
@@ -859,12 +852,33 @@ function withAnthropicCacheBreakpoint(messages = []) {
|
|
|
859
852
|
...block,
|
|
860
853
|
cache_control: { ...ANTHROPIC_CACHE_CONTROL },
|
|
861
854
|
};
|
|
862
|
-
|
|
863
|
-
...
|
|
855
|
+
return {
|
|
856
|
+
...msg,
|
|
864
857
|
content: blocks,
|
|
865
858
|
};
|
|
866
859
|
}
|
|
867
860
|
}
|
|
861
|
+
return msg;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
// Mark the ShortStableSnapshot boundary (when present) and the newest message
|
|
865
|
+
// with cache breakpoints so both the cross-turn sliding window prefix and the
|
|
866
|
+
// intra-turn append-only tool loop prefix are served from the prompt cache.
|
|
867
|
+
function withAnthropicCacheBreakpoint(messages = []) {
|
|
868
|
+
if (!Array.isArray(messages) || messages.length === 0) return messages;
|
|
869
|
+
const copy = messages.slice();
|
|
870
|
+
const lastIndex = copy.length - 1;
|
|
871
|
+
let boundaryIndex = -1;
|
|
872
|
+
for (let i = lastIndex - 1; i >= 0; i -= 1) {
|
|
873
|
+
if (copy[i] && copy[i][STABLE_HISTORY_BOUNDARY_SYMBOL]) {
|
|
874
|
+
boundaryIndex = i;
|
|
875
|
+
break;
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
if (boundaryIndex >= 0) {
|
|
879
|
+
copy[boundaryIndex] = stampAnthropicCacheBlock(copy[boundaryIndex]);
|
|
880
|
+
}
|
|
881
|
+
copy[lastIndex] = stampAnthropicCacheBlock(copy[lastIndex]);
|
|
868
882
|
return copy;
|
|
869
883
|
}
|
|
870
884
|
|
|
@@ -1174,6 +1188,7 @@ const {
|
|
|
1174
1188
|
createOpenAiChatTransport,
|
|
1175
1189
|
createOpenAiResponsesTransport,
|
|
1176
1190
|
createAnthropicMessagesTransport,
|
|
1191
|
+
createAntigravityTransport,
|
|
1177
1192
|
} = require("./transports");
|
|
1178
1193
|
|
|
1179
1194
|
// Transport descriptors: wire-format only. Plan Mode / leases / policy live in the loop.
|
|
@@ -1200,6 +1215,7 @@ const TRANSPORTS = {
|
|
|
1200
1215
|
toJsonString,
|
|
1201
1216
|
clipText,
|
|
1202
1217
|
}),
|
|
1218
|
+
antigravity: createAntigravityTransport({ runSseRequest, parseSseEventBlock, toJsonString, clipText }),
|
|
1203
1219
|
};
|
|
1204
1220
|
|
|
1205
1221
|
module.exports = {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function normalizeProvider(value = "") {
|
|
4
|
+
const text = String(value || "").trim().toLowerCase();
|
|
5
|
+
if (!text) return "";
|
|
6
|
+
if (text === "custom") return "openai";
|
|
7
|
+
if (text === "codex" || text === "codex-cli" || text === "codex-code") return "codex";
|
|
8
|
+
if (text === "claude" || text === "claude-cli" || text === "claude-code") return "anthropic";
|
|
9
|
+
if (text === "agy" || text === "agy-cli" || text === "antigravity") return "agy";
|
|
10
|
+
if (text === "kimi" || text === "kimi-code" || text === "moonshot") return "kimi";
|
|
11
|
+
if (text === "grok" || text === "grok-build" || text === "grok-shell" || text === "grok-api") return "grok-build";
|
|
12
|
+
if (text === "xai") return "xai";
|
|
13
|
+
if (text === "openai" || text === "anthropic") return text;
|
|
14
|
+
return text;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = { normalizeProvider };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const { loadConfig, defaultAgentModelForProvider, sameModelProvider } = require("../../config");
|
|
3
|
+
const { loadConfig, defaultAgentModelForProvider, defaultAuxModelForProvider, sameModelProvider } = require("../../config");
|
|
4
4
|
const { readKimiAccessToken } = require("./credentials/kimi");
|
|
5
|
+
const { DEFAULT_AGY_BASE_URL } = require("./credentials/agy");
|
|
5
6
|
|
|
6
7
|
const DEFAULT_OPENAI_BASE_URL = "https://api.openai.com/v1";
|
|
7
8
|
const DEFAULT_ANTHROPIC_BASE_URL = "https://api.anthropic.com/v1";
|
|
@@ -12,18 +13,7 @@ const DEFAULT_GROK_BUILD_BASE_URL = DEFAULT_XAI_BASE_URL;
|
|
|
12
13
|
const DEFAULT_GROK_BUILD_MODEL = "grok-4.6";
|
|
13
14
|
const DEFAULT_KIMI_MODEL = "k3";
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
const text = String(value || "").trim().toLowerCase();
|
|
17
|
-
if (!text) return "";
|
|
18
|
-
if (text === "custom") return "openai";
|
|
19
|
-
if (text === "codex" || text === "codex-cli" || text === "codex-code") return "codex";
|
|
20
|
-
if (text === "claude" || text === "claude-cli" || text === "claude-code") return "anthropic";
|
|
21
|
-
if (text === "kimi" || text === "kimi-code" || text === "moonshot") return "kimi";
|
|
22
|
-
if (text === "grok" || text === "grok-build" || text === "grok-shell" || text === "grok-api") return "grok-build";
|
|
23
|
-
if (text === "xai") return "xai";
|
|
24
|
-
if (text === "openai" || text === "anthropic") return text;
|
|
25
|
-
return text;
|
|
26
|
-
}
|
|
16
|
+
const { normalizeProvider } = require("./providerId");
|
|
27
17
|
|
|
28
18
|
function normalizeKimiModel(value = "") {
|
|
29
19
|
const raw = String(value || "").trim();
|
|
@@ -50,6 +40,7 @@ function resolveTransport({ provider = "", baseUrl = "" } = {}) {
|
|
|
50
40
|
return "openai-responses";
|
|
51
41
|
}
|
|
52
42
|
if (normalizedProvider === "anthropic") return "anthropic-messages";
|
|
43
|
+
if (normalizedProvider === "agy") return "antigravity";
|
|
53
44
|
if (normalizedProvider === "kimi") return "openai-chat";
|
|
54
45
|
if (/\/responses(?:$|[/?#])/.test(url)) return "openai-responses";
|
|
55
46
|
|
|
@@ -67,9 +58,15 @@ function resolveRuntimeConfig({ workspaceRoot = process.cwd(), provider = "", mo
|
|
|
67
58
|
) || "openai";
|
|
68
59
|
const custom = selectedProvider === "openai" && config.agentProvider === "custom"
|
|
69
60
|
&& (!useCodingConfig || !(config.ucodeProvider || process.env.UFOO_UCODE_PROVIDER));
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
61
|
+
const useCodingGateway = useCodingConfig && (selectedProvider !== "agy" || normalizeProvider(config.ucodeProvider) === "agy");
|
|
62
|
+
const modelProviderMatches = sameModelProvider((useCodingConfig ? config.ucodeProvider : "") || config.agentProvider, selectedProvider);
|
|
63
|
+
function modelSetting(codingModel, agentModel) {
|
|
64
|
+
if (selectedProvider === "agy") {
|
|
65
|
+
return (useCodingGateway ? codingModel : "") || (normalizeProvider(config.agentProvider) === "agy" ? agentModel : "");
|
|
66
|
+
}
|
|
67
|
+
return modelProviderMatches ? ((useCodingConfig ? codingModel : "") || agentModel) : "";
|
|
68
|
+
}
|
|
69
|
+
const configuredModel = modelSetting(config.ucodeModel, config.agentModel);
|
|
73
70
|
|
|
74
71
|
const selectedModel = String(
|
|
75
72
|
model
|
|
@@ -94,19 +91,21 @@ function resolveRuntimeConfig({ workspaceRoot = process.cwd(), provider = "", mo
|
|
|
94
91
|
)
|
|
95
92
|
: selectedProvider === "xai"
|
|
96
93
|
? String(process.env.XAI_BASE_URL || DEFAULT_XAI_BASE_URL)
|
|
97
|
-
:
|
|
94
|
+
: selectedProvider === "agy"
|
|
95
|
+
? String(process.env.UFOO_AGY_BASE_URL || DEFAULT_AGY_BASE_URL)
|
|
96
|
+
: String(process.env.OPENAI_BASE_URL || DEFAULT_OPENAI_BASE_URL);
|
|
98
97
|
|
|
99
98
|
let baseUrl = String(
|
|
100
99
|
(custom ? process.env.UFOO_AGENT_BASE_URL || config.agentBaseUrl : "")
|
|
101
100
|
|| (useCodingConfig ? process.env.UFOO_UCODE_BASE_URL : "")
|
|
102
|
-
|| (
|
|
101
|
+
|| (useCodingGateway ? config.ucodeBaseUrl : "")
|
|
103
102
|
|| defaultBaseUrl
|
|
104
103
|
).trim();
|
|
105
104
|
if (custom) baseUrl = String(process.env.UFOO_AGENT_BASE_URL || config.agentBaseUrl || "").trim();
|
|
106
105
|
|
|
107
106
|
const explicitApiKey = String(custom ? process.env.UFOO_AGENT_API_KEY || config.agentApiKey || "" :
|
|
108
107
|
(useCodingConfig ? process.env.UFOO_UCODE_API_KEY : "")
|
|
109
|
-
|| (
|
|
108
|
+
|| (useCodingGateway ? config.ucodeApiKey : "")
|
|
110
109
|
|| ""
|
|
111
110
|
).trim();
|
|
112
111
|
let apiKey = explicitApiKey;
|
|
@@ -144,9 +143,17 @@ function resolveRuntimeConfig({ workspaceRoot = process.cwd(), provider = "", mo
|
|
|
144
143
|
baseUrl = String(process.env.OPENAI_BASE_URL || DEFAULT_OPENAI_BASE_URL).trim();
|
|
145
144
|
}
|
|
146
145
|
|
|
146
|
+
const configuredAuxModel = modelSetting(config.ucodeAuxModel, config.agentAuxModel);
|
|
147
|
+
const selectedAuxModel = String(
|
|
148
|
+
(useCodingConfig ? process.env.UFOO_UCODE_AUX_MODEL : "")
|
|
149
|
+
|| configuredAuxModel
|
|
150
|
+
|| (custom ? "" : defaultAuxModelForProvider(selectedProvider))
|
|
151
|
+
).trim();
|
|
152
|
+
|
|
147
153
|
return {
|
|
148
154
|
provider: selectedProvider,
|
|
149
155
|
model: selectedModel,
|
|
156
|
+
auxModel: selectedAuxModel,
|
|
150
157
|
baseUrl,
|
|
151
158
|
apiKey,
|
|
152
159
|
apiKeySource,
|