@nodetool-ai/runtime 0.8.3 → 0.8.4-a13.1
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/dist/.nodetool-build-stamp +1 -1
- package/dist/canvas-codec.d.ts +3 -0
- package/dist/canvas-codec.d.ts.map +1 -0
- package/dist/canvas-codec.js +12 -0
- package/dist/canvas-codec.js.map +1 -0
- package/dist/context-packer.d.ts +1 -1
- package/dist/context-packer.js +1 -1
- package/dist/context.d.ts +3 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +13 -3
- package/dist/context.js.map +1 -1
- package/dist/host-binaries.d.ts.map +1 -1
- package/dist/host-binaries.js +4 -3
- package/dist/host-binaries.js.map +1 -1
- package/dist/http-client-spans.d.ts +9 -0
- package/dist/http-client-spans.d.ts.map +1 -0
- package/dist/http-client-spans.js +88 -0
- package/dist/http-client-spans.js.map +1 -0
- package/dist/image-codec.d.ts +6 -3
- package/dist/image-codec.d.ts.map +1 -1
- package/dist/image-codec.js +17 -17
- package/dist/image-codec.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/media-ref-bytes.d.ts.map +1 -1
- package/dist/media-ref-bytes.js +31 -6
- package/dist/media-ref-bytes.js.map +1 -1
- package/dist/otlp-json-trace-exporter.d.ts +89 -0
- package/dist/otlp-json-trace-exporter.d.ts.map +1 -0
- package/dist/otlp-json-trace-exporter.js +155 -0
- package/dist/otlp-json-trace-exporter.js.map +1 -0
- package/dist/providers/antigravity-provider.d.ts +113 -0
- package/dist/providers/antigravity-provider.d.ts.map +1 -0
- package/dist/providers/antigravity-provider.js +527 -0
- package/dist/providers/antigravity-provider.js.map +1 -0
- package/dist/providers/azure-openai-provider.d.ts +69 -0
- package/dist/providers/azure-openai-provider.d.ts.map +1 -0
- package/dist/providers/azure-openai-provider.js +233 -0
- package/dist/providers/azure-openai-provider.js.map +1 -0
- package/dist/providers/base-provider.d.ts.map +1 -1
- package/dist/providers/base-provider.js +19 -1
- package/dist/providers/base-provider.js.map +1 -1
- package/dist/providers/bedrock-provider.d.ts +52 -0
- package/dist/providers/bedrock-provider.d.ts.map +1 -0
- package/dist/providers/bedrock-provider.js +648 -0
- package/dist/providers/bedrock-provider.js.map +1 -0
- package/dist/providers/bedrock-transport.d.ts +37 -0
- package/dist/providers/bedrock-transport.d.ts.map +1 -0
- package/dist/providers/bedrock-transport.js +186 -0
- package/dist/providers/bedrock-transport.js.map +1 -0
- package/dist/providers/chatgpt-provider.d.ts.map +1 -1
- package/dist/providers/chatgpt-provider.js +77 -32
- package/dist/providers/chatgpt-provider.js.map +1 -1
- package/dist/providers/claude-agent-provider.d.ts +29 -51
- package/dist/providers/claude-agent-provider.d.ts.map +1 -1
- package/dist/providers/claude-agent-provider.js +144 -202
- package/dist/providers/claude-agent-provider.js.map +1 -1
- package/dist/providers/claude-cli.d.ts +265 -0
- package/dist/providers/claude-cli.d.ts.map +1 -0
- package/dist/providers/claude-cli.js +488 -0
- package/dist/providers/claude-cli.js.map +1 -0
- package/dist/providers/codex-provider.d.ts +9 -2
- package/dist/providers/codex-provider.d.ts.map +1 -1
- package/dist/providers/codex-provider.js +25 -11
- package/dist/providers/codex-provider.js.map +1 -1
- package/dist/providers/core-tools.d.ts +4 -1
- package/dist/providers/core-tools.d.ts.map +1 -1
- package/dist/providers/core-tools.js +5 -3
- package/dist/providers/core-tools.js.map +1 -1
- package/dist/providers/dreamina-pending.d.ts +22 -0
- package/dist/providers/dreamina-pending.d.ts.map +1 -0
- package/dist/providers/dreamina-pending.js +86 -0
- package/dist/providers/dreamina-pending.js.map +1 -0
- package/dist/providers/dreamina-provider.d.ts +5 -0
- package/dist/providers/dreamina-provider.d.ts.map +1 -1
- package/dist/providers/dreamina-provider.js +88 -19
- package/dist/providers/dreamina-provider.js.map +1 -1
- package/dist/providers/extension-tab.d.ts +18 -5
- package/dist/providers/extension-tab.d.ts.map +1 -1
- package/dist/providers/extension-tab.js +71 -15
- package/dist/providers/extension-tab.js.map +1 -1
- package/dist/providers/gemini-web-provider.d.ts +14 -14
- package/dist/providers/gemini-web-provider.d.ts.map +1 -1
- package/dist/providers/gemini-web-provider.js +264 -189
- package/dist/providers/gemini-web-provider.js.map +1 -1
- package/dist/providers/http-transport.d.ts.map +1 -1
- package/dist/providers/http-transport.js +2 -0
- package/dist/providers/http-transport.js.map +1 -1
- package/dist/providers/index.d.ts +8 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +30 -7
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/node-llama-cpp-provider.d.ts.map +1 -1
- package/dist/providers/node-llama-cpp-provider.js +2 -4
- package/dist/providers/node-llama-cpp-provider.js.map +1 -1
- package/dist/providers/openai-provider.d.ts +2 -0
- package/dist/providers/openai-provider.d.ts.map +1 -1
- package/dist/providers/openai-provider.js +9 -5
- package/dist/providers/openai-provider.js.map +1 -1
- package/dist/providers/safe-url.d.ts.map +1 -1
- package/dist/providers/safe-url.js +8 -0
- package/dist/providers/safe-url.js.map +1 -1
- package/dist/providers/vgenv-provider.d.ts +33 -0
- package/dist/providers/vgenv-provider.d.ts.map +1 -0
- package/dist/providers/vgenv-provider.js +261 -0
- package/dist/providers/vgenv-provider.js.map +1 -0
- package/dist/python-graph-resolver.d.ts.map +1 -1
- package/dist/python-graph-resolver.js +12 -2
- package/dist/python-graph-resolver.js.map +1 -1
- package/dist/python-stdio-bridge.d.ts.map +1 -1
- package/dist/python-stdio-bridge.js +33 -10
- package/dist/python-stdio-bridge.js.map +1 -1
- package/dist/run-trace-processor.d.ts +3 -0
- package/dist/run-trace-processor.d.ts.map +1 -1
- package/dist/run-trace-processor.js +56 -40
- package/dist/run-trace-processor.js.map +1 -1
- package/dist/telemetry.d.ts +2 -2
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +33 -34
- package/dist/telemetry.js.map +1 -1
- package/dist/token-counter.d.ts +4 -13
- package/dist/token-counter.d.ts.map +1 -1
- package/dist/token-counter.js +68 -18
- package/dist/token-counter.js.map +1 -1
- package/dist/trace-context-manager.d.ts +12 -0
- package/dist/trace-context-manager.d.ts.map +1 -0
- package/dist/trace-context-manager.js +30 -0
- package/dist/trace-context-manager.js.map +1 -0
- package/dist/trace-exporters.d.ts +1 -1
- package/dist/trace-exporters.d.ts.map +1 -1
- package/dist/trace-exporters.js +4 -5
- package/dist/trace-exporters.js.map +1 -1
- package/dist/trace-semantic-conventions.d.ts +2 -0
- package/dist/trace-semantic-conventions.d.ts.map +1 -0
- package/dist/trace-semantic-conventions.js +2 -0
- package/dist/trace-semantic-conventions.js.map +1 -0
- package/dist/tracing-module.d.ts +3 -0
- package/dist/tracing-module.d.ts.map +1 -0
- package/dist/tracing-module.js +12 -0
- package/dist/tracing-module.js.map +1 -0
- package/package.json +35 -18
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AntigravityProvider — models reached through Google's Antigravity CLI
|
|
3
|
+
* (`agy`) in headless mode, on the machine's signed-in Antigravity account.
|
|
4
|
+
*
|
|
5
|
+
* There is no API key: `agy` authenticates with credentials cached by an
|
|
6
|
+
* earlier interactive `agy` session. Each turn spawns
|
|
7
|
+
* `agy --input-format stream-json --output-format stream-json`, writes the
|
|
8
|
+
* prompt as one `user` event on stdin, closes stdin, and reads the NDJSON event
|
|
9
|
+
* stream (`init`, `step_update`, `result`). See
|
|
10
|
+
* https://antigravity.google/docs/cli/headless/.
|
|
11
|
+
*
|
|
12
|
+
* The CLI runs its own agent with its own tools, so NodeTool tools are not
|
|
13
|
+
* offered to it. It runs in a dedicated empty scratch directory, never the
|
|
14
|
+
* server's working directory, because headless runs auto-allow file reads and
|
|
15
|
+
* writes inside the active workspace. Shell commands stay soft-denied: the
|
|
16
|
+
* provider never passes `--dangerously-skip-permissions`.
|
|
17
|
+
*/
|
|
18
|
+
import { createLogger, importNodeBuiltin } from "@nodetool-ai/config";
|
|
19
|
+
import { PROVIDER_IDS, isString } from "@nodetool-ai/protocol";
|
|
20
|
+
import { z } from "zod";
|
|
21
|
+
import { BaseProvider } from "./base-provider.js";
|
|
22
|
+
import { hashSystemPrompt } from "./provider-session.js";
|
|
23
|
+
import { isProviderMessageEvent, isProviderSessionUpdate, isProviderStop } from "./types.js";
|
|
24
|
+
const log = createLogger("nodetool.runtime.providers.antigravity");
|
|
25
|
+
/** The executable name the official installer puts on PATH. */
|
|
26
|
+
const DEFAULT_COMMAND = "agy";
|
|
27
|
+
/** Where the official installer places `agy` on macOS and Linux. */
|
|
28
|
+
const INSTALLER_BIN_DIR = [".local", "bin"];
|
|
29
|
+
/** How long a finished run may take to exit before it is stopped. */
|
|
30
|
+
const RESULT_EXIT_GRACE_MS = 30_000;
|
|
31
|
+
const INSTALL_HINT = "Install the Antigravity CLI (agy), then run `agy` once in a terminal to sign in.";
|
|
32
|
+
/** A field the CLI may omit or change shape on. Unexpected values read as absent. */
|
|
33
|
+
const lenient = (schema) => schema.optional().catch(undefined);
|
|
34
|
+
/** The fields of a `stream-json` event this provider reads. Others are ignored. */
|
|
35
|
+
const cliEventSchema = z.object({
|
|
36
|
+
event: lenient(z.string()),
|
|
37
|
+
conversation_id: lenient(z.string()),
|
|
38
|
+
step_type: lenient(z.string()),
|
|
39
|
+
text_delta: lenient(z.string()),
|
|
40
|
+
status: lenient(z.string()),
|
|
41
|
+
response: lenient(z.string()),
|
|
42
|
+
error: lenient(z.union([z.string(), z.object({ message: lenient(z.string()) })])),
|
|
43
|
+
structured_output: lenient(z.record(z.string(), z.unknown())),
|
|
44
|
+
usage: lenient(z.object({
|
|
45
|
+
input_tokens: lenient(z.number()),
|
|
46
|
+
output_tokens: lenient(z.number()),
|
|
47
|
+
thinking_tokens: lenient(z.number()),
|
|
48
|
+
cache_read_tokens: lenient(z.number())
|
|
49
|
+
}))
|
|
50
|
+
});
|
|
51
|
+
/** A failed `agy` run. Its message names the remedy. */
|
|
52
|
+
class AntigravityCliError extends Error {
|
|
53
|
+
constructor(message) {
|
|
54
|
+
super(message);
|
|
55
|
+
this.name = "AntigravityCliError";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export class AntigravityProvider extends BaseProvider {
|
|
59
|
+
static requiredSecrets() {
|
|
60
|
+
// Auth lives in the CLI's own credential cache, not in a NodeTool secret.
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
runCli;
|
|
64
|
+
/**
|
|
65
|
+
* Within-process cache of the active conversation per thread. The persisted
|
|
66
|
+
* `provider_session` column is the source of truth; this only covers callers
|
|
67
|
+
* that do not thread a session token in (the CLI chat).
|
|
68
|
+
*/
|
|
69
|
+
sessions = new Map();
|
|
70
|
+
modelsCache = null;
|
|
71
|
+
constructor(_secrets = {}, options = {}) {
|
|
72
|
+
super(PROVIDER_IDS.ANTIGRAVITY);
|
|
73
|
+
this.runCli = options.runCli ?? spawnAgy;
|
|
74
|
+
}
|
|
75
|
+
/** The CLI's credentials never leave this process. */
|
|
76
|
+
getContainerEnv() {
|
|
77
|
+
return {};
|
|
78
|
+
}
|
|
79
|
+
/** `agy` runs its own tools. NodeTool tools are not forwarded to it. */
|
|
80
|
+
async hasToolSupport() {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
async unavailableReason() {
|
|
84
|
+
try {
|
|
85
|
+
const run = await this.runCli(["--version"], { stdin: "", cwd: null });
|
|
86
|
+
await readLines(run);
|
|
87
|
+
const { code, stderr } = await run.exit;
|
|
88
|
+
if (code === 0)
|
|
89
|
+
return null;
|
|
90
|
+
return `The Antigravity CLI failed to start (exit ${code}): ${stderr.trim() || "no output"}`;
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
return err instanceof Error ? err.message : String(err);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The slugs `agy models` prints. Effort is part of the slug (for example
|
|
98
|
+
* `gemini-3.1-pro-high`). Empty when the CLI is missing or signed out.
|
|
99
|
+
*/
|
|
100
|
+
async getAvailableLanguageModels() {
|
|
101
|
+
this.modelsCache ??= this.listModels().catch((err) => {
|
|
102
|
+
log.warn("Listing Antigravity models failed", { error: err.message });
|
|
103
|
+
this.modelsCache = null;
|
|
104
|
+
return [];
|
|
105
|
+
});
|
|
106
|
+
return this.modelsCache;
|
|
107
|
+
}
|
|
108
|
+
async listModels() {
|
|
109
|
+
const run = await this.runCli(["models"], { stdin: "", cwd: null });
|
|
110
|
+
const lines = await readLines(run);
|
|
111
|
+
const { code, stderr } = await run.exit;
|
|
112
|
+
if (code !== 0) {
|
|
113
|
+
throw new AntigravityCliError(`agy models exited ${code}: ${stderr.trim() || "no output"}`);
|
|
114
|
+
}
|
|
115
|
+
return parseModelSlugs(lines).map((id) => ({
|
|
116
|
+
id,
|
|
117
|
+
name: modelDisplayName(id),
|
|
118
|
+
provider: PROVIDER_IDS.ANTIGRAVITY
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
async *generateMessages(args) {
|
|
122
|
+
// A single forced tool is how callers ask for structured output. `agy`
|
|
123
|
+
// enforces a JSON schema natively, so the result comes back as that call.
|
|
124
|
+
const resultTool = args.tools?.length === 1 && args.toolChoice === args.tools[0].name
|
|
125
|
+
? args.tools[0]
|
|
126
|
+
: undefined;
|
|
127
|
+
const systemPrompt = extractSystemPrompt(args.messages);
|
|
128
|
+
const systemHash = hashSystemPrompt(systemPrompt);
|
|
129
|
+
const threadId = args.threadId ?? null;
|
|
130
|
+
const prior = args.providerSession ??
|
|
131
|
+
(threadId ? (this.sessions.get(threadId) ?? null) : null);
|
|
132
|
+
const canResume = prior != null &&
|
|
133
|
+
prior.providerId === this.provider &&
|
|
134
|
+
prior.model === args.model &&
|
|
135
|
+
(prior.systemHash == null || prior.systemHash === systemHash) &&
|
|
136
|
+
args.messages.length > prior.checkpoint;
|
|
137
|
+
const turn = {
|
|
138
|
+
model: args.model,
|
|
139
|
+
checkpoint: args.messages.length,
|
|
140
|
+
systemHash,
|
|
141
|
+
threadId,
|
|
142
|
+
cacheSession: args.providerSession == null,
|
|
143
|
+
effort: args.effort,
|
|
144
|
+
resultTool,
|
|
145
|
+
signal: args.signal
|
|
146
|
+
};
|
|
147
|
+
// Resuming is best-effort: the CLI may have pruned the conversation. A
|
|
148
|
+
// resume that fails before any content reached the consumer falls back to
|
|
149
|
+
// a fresh conversation primed with the full history.
|
|
150
|
+
const emitted = { content: false };
|
|
151
|
+
if (canResume && prior) {
|
|
152
|
+
try {
|
|
153
|
+
yield* this.runTurn({
|
|
154
|
+
...turn,
|
|
155
|
+
prompt: buildResumeDelta(args.messages, prior.checkpoint),
|
|
156
|
+
conversation: prior.token,
|
|
157
|
+
emitted
|
|
158
|
+
});
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
if (emitted.content || args.signal?.aborted)
|
|
163
|
+
throw err;
|
|
164
|
+
log.warn("Antigravity conversation resume failed; starting fresh", {
|
|
165
|
+
error: err instanceof Error ? err.message : String(err)
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const history = args.loadFullHistory
|
|
170
|
+
? await args.loadFullHistory()
|
|
171
|
+
: args.messages;
|
|
172
|
+
yield* this.runTurn({
|
|
173
|
+
...turn,
|
|
174
|
+
prompt: buildFreshPrompt(history, systemPrompt),
|
|
175
|
+
conversation: null,
|
|
176
|
+
emitted
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/** Run one `agy` turn and translate its event stream into stream items. */
|
|
180
|
+
async *runTurn(plan) {
|
|
181
|
+
if (plan.signal?.aborted)
|
|
182
|
+
return;
|
|
183
|
+
const cliArgs = buildCliArgs(plan);
|
|
184
|
+
this.recordRequestPayload({ args: cliArgs, prompt: plan.prompt });
|
|
185
|
+
const cwd = await scratchWorkspace();
|
|
186
|
+
const run = await this.runCli(cliArgs, {
|
|
187
|
+
stdin: `${JSON.stringify({ event: "user", message: { content: plan.prompt } })}\n`,
|
|
188
|
+
cwd
|
|
189
|
+
});
|
|
190
|
+
const onAbort = () => run.kill();
|
|
191
|
+
plan.signal?.addEventListener("abort", onAbort, { once: true });
|
|
192
|
+
let sessionSent = false;
|
|
193
|
+
let result = null;
|
|
194
|
+
try {
|
|
195
|
+
for await (const line of run.lines) {
|
|
196
|
+
const event = parseEvent(line);
|
|
197
|
+
if (!event)
|
|
198
|
+
continue;
|
|
199
|
+
const conversationId = event.conversation_id;
|
|
200
|
+
if (!sessionSent && conversationId) {
|
|
201
|
+
sessionSent = true;
|
|
202
|
+
if (plan.threadId) {
|
|
203
|
+
const session = {
|
|
204
|
+
providerId: this.provider,
|
|
205
|
+
model: plan.model,
|
|
206
|
+
token: conversationId,
|
|
207
|
+
checkpoint: plan.checkpoint,
|
|
208
|
+
systemHash: plan.systemHash
|
|
209
|
+
};
|
|
210
|
+
if (plan.cacheSession)
|
|
211
|
+
this.sessions.set(plan.threadId, session);
|
|
212
|
+
yield { type: "session", session };
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (event.event === "step_update") {
|
|
216
|
+
const delta = event.text_delta;
|
|
217
|
+
if (event.step_type === "agent_response" && delta && !plan.resultTool) {
|
|
218
|
+
plan.emitted.content = true;
|
|
219
|
+
yield { type: "chunk", content: delta, done: false };
|
|
220
|
+
}
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (event.event === "result") {
|
|
224
|
+
// The provider sends one prompt and closed stdin, so the first
|
|
225
|
+
// result ends the turn and `agy` exits on its own.
|
|
226
|
+
result = event;
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
finally {
|
|
232
|
+
plan.signal?.removeEventListener("abort", onAbort);
|
|
233
|
+
// Stop the process only when the turn did not finish: the consumer
|
|
234
|
+
// stopped early, the run was aborted, or a parse step threw. A finished
|
|
235
|
+
// run is left to exit so it can save the conversation for a resume.
|
|
236
|
+
if (result) {
|
|
237
|
+
// A run that never exits after its result would leak a process.
|
|
238
|
+
setTimeout(() => run.kill(), RESULT_EXIT_GRACE_MS).unref?.();
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
run.kill();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (plan.signal?.aborted)
|
|
245
|
+
return;
|
|
246
|
+
if (!result) {
|
|
247
|
+
const { code, stderr } = await run.exit;
|
|
248
|
+
throw cliFailure(`agy exited (${code ?? "signal"}) without a result`, stderr);
|
|
249
|
+
}
|
|
250
|
+
this.trackResultUsage(plan.model, result.usage);
|
|
251
|
+
if (result.status !== "SUCCESS") {
|
|
252
|
+
const error = result.error;
|
|
253
|
+
const detail = isString(error) ? error : (error?.message ?? "");
|
|
254
|
+
throw cliFailure(`agy returned ${result.status ?? "no status"}`, detail);
|
|
255
|
+
}
|
|
256
|
+
if (plan.resultTool) {
|
|
257
|
+
if (!result.structured_output) {
|
|
258
|
+
throw new AntigravityCliError(`agy returned no structured output for ${plan.resultTool.name}`);
|
|
259
|
+
}
|
|
260
|
+
yield {
|
|
261
|
+
id: `result_${result.conversation_id ?? Date.now()}`,
|
|
262
|
+
name: plan.resultTool.name,
|
|
263
|
+
args: result.structured_output
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
else if (!plan.emitted.content && result.response) {
|
|
267
|
+
// No deltas streamed (for example an older CLI): use the final text.
|
|
268
|
+
plan.emitted.content = true;
|
|
269
|
+
yield { type: "chunk", content: result.response, done: false };
|
|
270
|
+
}
|
|
271
|
+
yield { type: "chunk", content: "", done: true };
|
|
272
|
+
}
|
|
273
|
+
trackResultUsage(model, usage) {
|
|
274
|
+
if (!usage)
|
|
275
|
+
return;
|
|
276
|
+
this.trackUsage(model, {
|
|
277
|
+
inputTokens: usage.input_tokens ?? 0,
|
|
278
|
+
outputTokens: (usage.output_tokens ?? 0) + (usage.thinking_tokens ?? 0),
|
|
279
|
+
cachedTokens: usage.cache_read_tokens ?? 0
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
async generateMessage(args) {
|
|
283
|
+
let content = "";
|
|
284
|
+
const toolCalls = [];
|
|
285
|
+
for await (const item of this.generateMessages(args)) {
|
|
286
|
+
if (isProviderSessionUpdate(item) ||
|
|
287
|
+
isProviderMessageEvent(item) ||
|
|
288
|
+
isProviderStop(item)) {
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
if ("args" in item) {
|
|
292
|
+
toolCalls.push(item);
|
|
293
|
+
}
|
|
294
|
+
else if (!item.thinking && isString(item.content)) {
|
|
295
|
+
content += item.content;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
role: "assistant",
|
|
300
|
+
content: content || null,
|
|
301
|
+
toolCalls: toolCalls.length ? toolCalls : null
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/** The `agy` flags for one headless turn. */
|
|
306
|
+
export function buildCliArgs(plan) {
|
|
307
|
+
const args = [
|
|
308
|
+
"--input-format",
|
|
309
|
+
"stream-json",
|
|
310
|
+
"--output-format",
|
|
311
|
+
"stream-json"
|
|
312
|
+
];
|
|
313
|
+
if (plan.model)
|
|
314
|
+
args.push("--model", plan.model);
|
|
315
|
+
if (plan.conversation)
|
|
316
|
+
args.push("--conversation", plan.conversation);
|
|
317
|
+
if (plan.effort)
|
|
318
|
+
args.push("--effort", cliEffort(plan.effort));
|
|
319
|
+
if (plan.resultTool) {
|
|
320
|
+
args.push("--json-schema", JSON.stringify(plan.resultTool.inputSchema ?? { type: "object" }));
|
|
321
|
+
}
|
|
322
|
+
return args;
|
|
323
|
+
}
|
|
324
|
+
/** Every stdout line of a short-lived `agy` command. */
|
|
325
|
+
async function readLines(run) {
|
|
326
|
+
const lines = [];
|
|
327
|
+
for await (const line of run.lines)
|
|
328
|
+
lines.push(line);
|
|
329
|
+
return lines;
|
|
330
|
+
}
|
|
331
|
+
/** `agy --effort` accepts only low, medium and high. */
|
|
332
|
+
function cliEffort(effort) {
|
|
333
|
+
return effort === "xhigh" || effort === "max" ? "high" : effort;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Model slugs from `agy models` output. The CLI prints one model per line,
|
|
337
|
+
* possibly with a bullet or a trailing description, so this keeps the first
|
|
338
|
+
* token of each line that looks like a slug. Every slug carries a version
|
|
339
|
+
* number, which separates slugs from header words.
|
|
340
|
+
*/
|
|
341
|
+
export function parseModelSlugs(lines) {
|
|
342
|
+
const slugs = [];
|
|
343
|
+
for (const raw of lines) {
|
|
344
|
+
const token = raw.trim().replace(/^[-*•]\s*/, "").split(/\s+/)[0] ?? "";
|
|
345
|
+
if (!/^[a-z][a-z0-9._-]*$/i.test(token) || !/\d/.test(token))
|
|
346
|
+
continue;
|
|
347
|
+
if (!slugs.includes(token))
|
|
348
|
+
slugs.push(token);
|
|
349
|
+
}
|
|
350
|
+
return slugs;
|
|
351
|
+
}
|
|
352
|
+
/** `gemini-3.1-pro-high` → `Gemini 3.1 Pro High`. */
|
|
353
|
+
function modelDisplayName(slug) {
|
|
354
|
+
return slug
|
|
355
|
+
.split("-")
|
|
356
|
+
.map((part) => (part ? part[0].toUpperCase() + part.slice(1) : part))
|
|
357
|
+
.join(" ");
|
|
358
|
+
}
|
|
359
|
+
/** One stdout line as an event, or null for a line that is not one. */
|
|
360
|
+
function parseEvent(line) {
|
|
361
|
+
const trimmed = line.trim();
|
|
362
|
+
if (!trimmed.startsWith("{"))
|
|
363
|
+
return null;
|
|
364
|
+
let json;
|
|
365
|
+
try {
|
|
366
|
+
json = JSON.parse(trimmed);
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
log.debug("Skipping non-JSON agy output line");
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
const parsed = cliEventSchema.safeParse(json);
|
|
373
|
+
return parsed.success ? parsed.data : null;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* An Error for a failed run. It carries no HTTP status on purpose: the generic
|
|
377
|
+
* 401 remedy points at Settings, and `agy` is signed in from a terminal.
|
|
378
|
+
*/
|
|
379
|
+
function cliFailure(summary, detail) {
|
|
380
|
+
const text = detail.trim();
|
|
381
|
+
if (/auth|sign[ -]?in|log[ -]?in|credential/i.test(text)) {
|
|
382
|
+
return new AntigravityCliError(`Antigravity sign-in required: ${text}. Run \`agy\` once in a terminal to sign in.`);
|
|
383
|
+
}
|
|
384
|
+
return new AntigravityCliError(text ? `${summary}: ${text}` : summary);
|
|
385
|
+
}
|
|
386
|
+
/** Flatten a message's content to plain text (text blocks only). */
|
|
387
|
+
function textOf(content) {
|
|
388
|
+
if (content == null)
|
|
389
|
+
return "";
|
|
390
|
+
if (isString(content))
|
|
391
|
+
return content;
|
|
392
|
+
return content
|
|
393
|
+
.filter((c) => c.type === "text")
|
|
394
|
+
.map((c) => c.text)
|
|
395
|
+
.join("");
|
|
396
|
+
}
|
|
397
|
+
/** `agy` accepts only text prompts. Refuse images rather than drop them. */
|
|
398
|
+
function assertTextOnly(messages) {
|
|
399
|
+
const withMedia = messages.some((m) => Array.isArray(m.content) && m.content.some((c) => c.type !== "text"));
|
|
400
|
+
if (withMedia) {
|
|
401
|
+
throw new AntigravityCliError("The Antigravity CLI accepts text prompts only. Remove the attached images or media, or pick another provider.");
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
function extractSystemPrompt(messages) {
|
|
405
|
+
return messages
|
|
406
|
+
.filter((m) => m.role === "system")
|
|
407
|
+
.map((m) => textOf(m.content))
|
|
408
|
+
.filter(Boolean)
|
|
409
|
+
.join("\n\n");
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* The user messages added since the checkpoint. Assistant turns in the slice
|
|
413
|
+
* came from the resumed conversation itself, so they are not replayed.
|
|
414
|
+
*/
|
|
415
|
+
export function buildResumeDelta(messages, checkpoint) {
|
|
416
|
+
const delta = messages.slice(checkpoint).filter((m) => m.role === "user");
|
|
417
|
+
assertTextOnly(delta);
|
|
418
|
+
return delta
|
|
419
|
+
.map((m) => textOf(m.content))
|
|
420
|
+
.filter(Boolean)
|
|
421
|
+
.join("\n\n");
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* The prompt for a fresh conversation. `agy` has no system-prompt flag and
|
|
425
|
+
* cannot import earlier turns, so instructions and prior history are sent as
|
|
426
|
+
* delimited blocks ahead of the new user turn.
|
|
427
|
+
*/
|
|
428
|
+
export function buildFreshPrompt(messages, systemPrompt) {
|
|
429
|
+
const convo = messages.filter((m) => m.role === "user" || m.role === "assistant");
|
|
430
|
+
assertTextOnly(convo);
|
|
431
|
+
const last = convo[convo.length - 1];
|
|
432
|
+
const newTurn = last?.role === "user" ? textOf(last.content) : "";
|
|
433
|
+
const prior = last?.role === "user" ? convo.slice(0, -1) : convo;
|
|
434
|
+
const transcript = prior
|
|
435
|
+
.map((m) => {
|
|
436
|
+
const text = textOf(m.content);
|
|
437
|
+
return text ? `${m.role === "assistant" ? "Assistant" : "User"}: ${text}` : "";
|
|
438
|
+
})
|
|
439
|
+
.filter(Boolean)
|
|
440
|
+
.join("\n\n");
|
|
441
|
+
return [
|
|
442
|
+
systemPrompt ? `<instructions>\n${systemPrompt}\n</instructions>` : "",
|
|
443
|
+
transcript ? `<conversation_so_far>\n${transcript}\n</conversation_so_far>` : "",
|
|
444
|
+
newTurn
|
|
445
|
+
]
|
|
446
|
+
.filter(Boolean)
|
|
447
|
+
.join("\n\n");
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* The empty directory `agy` runs in. Headless runs may read and write inside
|
|
451
|
+
* their workspace, so it must never be the server's own working directory.
|
|
452
|
+
*/
|
|
453
|
+
async function scratchWorkspace() {
|
|
454
|
+
const [fs, os, path] = await Promise.all([
|
|
455
|
+
importNodeBuiltin("node:fs/promises"),
|
|
456
|
+
importNodeBuiltin("node:os"),
|
|
457
|
+
importNodeBuiltin("node:path")
|
|
458
|
+
]);
|
|
459
|
+
if (!fs || !os || !path)
|
|
460
|
+
return null;
|
|
461
|
+
const dir = path.join(os.tmpdir(), "nodetool-antigravity");
|
|
462
|
+
await fs.mkdir(dir, { recursive: true });
|
|
463
|
+
return dir;
|
|
464
|
+
}
|
|
465
|
+
/** The real runner: spawns `agy` with `~/.local/bin` appended to PATH. */
|
|
466
|
+
const spawnAgy = async (args, options) => {
|
|
467
|
+
const [cp, os, path, readline] = await Promise.all([
|
|
468
|
+
importNodeBuiltin("node:child_process"),
|
|
469
|
+
importNodeBuiltin("node:os"),
|
|
470
|
+
importNodeBuiltin("node:path"),
|
|
471
|
+
importNodeBuiltin("node:readline")
|
|
472
|
+
]);
|
|
473
|
+
if (!cp || !os || !path || !readline) {
|
|
474
|
+
throw new AntigravityCliError("The Antigravity provider requires Node.js");
|
|
475
|
+
}
|
|
476
|
+
// A desktop app launched outside a shell often lacks the installer's bin
|
|
477
|
+
// directory on PATH.
|
|
478
|
+
const installerBin = path.join(os.homedir(), ...INSTALLER_BIN_DIR);
|
|
479
|
+
const env = {
|
|
480
|
+
...process.env,
|
|
481
|
+
PATH: [process.env["PATH"], installerBin].filter(Boolean).join(path.delimiter)
|
|
482
|
+
};
|
|
483
|
+
const child = cp.spawn(DEFAULT_COMMAND, args, {
|
|
484
|
+
cwd: options.cwd ?? undefined,
|
|
485
|
+
env,
|
|
486
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
487
|
+
windowsHide: true
|
|
488
|
+
});
|
|
489
|
+
let stderr = "";
|
|
490
|
+
child.stderr.setEncoding("utf8");
|
|
491
|
+
child.stderr.on("data", (data) => {
|
|
492
|
+
// Keep the tail. It holds the failure reason.
|
|
493
|
+
stderr = (stderr + data).slice(-8192);
|
|
494
|
+
});
|
|
495
|
+
const exit = new Promise((resolve, reject) => {
|
|
496
|
+
child.once("error", (err) => {
|
|
497
|
+
reject(err.code === "ENOENT"
|
|
498
|
+
? new AntigravityCliError(`Antigravity CLI (agy) not found. ${INSTALL_HINT}`)
|
|
499
|
+
: err);
|
|
500
|
+
});
|
|
501
|
+
child.once("close", (code) => resolve({ code, stderr }));
|
|
502
|
+
});
|
|
503
|
+
// A caller that stops early never awaits `exit`. Mark it handled.
|
|
504
|
+
exit.catch(() => undefined);
|
|
505
|
+
// Surface a spawn failure here, before the caller waits on stdout.
|
|
506
|
+
await Promise.race([
|
|
507
|
+
exit.then(() => undefined),
|
|
508
|
+
new Promise((resolve) => child.once("spawn", () => resolve()))
|
|
509
|
+
]);
|
|
510
|
+
child.stdin.on("error", () => {
|
|
511
|
+
// The process may exit before reading stdin; its exit code reports why.
|
|
512
|
+
});
|
|
513
|
+
child.stdin.end(options.stdin);
|
|
514
|
+
const lines = readline.createInterface({
|
|
515
|
+
input: child.stdout,
|
|
516
|
+
crlfDelay: Infinity
|
|
517
|
+
});
|
|
518
|
+
return {
|
|
519
|
+
lines,
|
|
520
|
+
exit,
|
|
521
|
+
kill: () => {
|
|
522
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
523
|
+
child.kill();
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
};
|
|
527
|
+
//# sourceMappingURL=antigravity-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"antigravity-provider.js","sourceRoot":"","sources":["../../src/providers/antigravity-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACL,YAAY,EACZ,iBAAiB,EAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EASf,MAAM,YAAY,CAAC;AAEpB,MAAM,GAAG,GAAG,YAAY,CAAC,wCAAwC,CAAC,CAAC;AAEnE,+DAA+D;AAC/D,MAAM,eA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AAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;KACrE,CAAC,CAAC;IAEH,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;QAC3B,wEAAwE;IAC1E,CAAC,CAAC,CAAC;IACH,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/B,MAAM,KAAK,GAAG,QAAQ,CAAC,eAAe,CAAC;QACrC,KAAK,EAAE,KAAK,CAAC,MAAM;QACnB,SAAS,EAAE,QAAQ;KACpB,CAAC,CAAC;IACH,OAAO;QACL,KAAK;QACL,IAAI;QACJ,IAAI,EAAE,GAAG,EAAE;YACT,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,IAAI,KAAK,CAAC,UAAU,KAAK,IAAI;gBAAE,KAAK,CAAC,IAAI,EAAE,CAAC;QACzE,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
import type { ProviderCapability } from "./base-provider.js";
|
|
3
|
+
import { OpenAIProvider } from "./openai-provider.js";
|
|
4
|
+
import type { ASRModel, EmbeddingModel, ImageModel, LanguageModel, TTSModel } from "./types.js";
|
|
5
|
+
/** What a deployment serves. Azure does not report it, so it comes from config or the name. */
|
|
6
|
+
export type AzureDeploymentKind = "chat" | "image" | "tts" | "asr" | "embedding";
|
|
7
|
+
export interface AzureDeployment {
|
|
8
|
+
id: string;
|
|
9
|
+
kind: AzureDeploymentKind;
|
|
10
|
+
model?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The kind a deployment name implies. Azure deployments default to the name of
|
|
14
|
+
* the model they serve, so `gpt-image-2`, `tts-hd`, `whisper` and
|
|
15
|
+
* `text-embedding-3-large` classify themselves. Anything else is a chat model.
|
|
16
|
+
*/
|
|
17
|
+
export declare function inferAzureDeploymentKind(name: string): AzureDeploymentKind;
|
|
18
|
+
/**
|
|
19
|
+
* Parse `AZURE_OPENAI_DEPLOYMENTS`: a comma-separated list of deployment
|
|
20
|
+
* names. A name may carry an explicit kind after a colon
|
|
21
|
+
* (`my-painter:image`) when the name does not reveal it. Append `=model`
|
|
22
|
+
* to resolve capabilities independently of the deployment routing name.
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseAzureDeployments(raw: string | undefined): AzureDeployment[];
|
|
25
|
+
/**
|
|
26
|
+
* The resource root of an Azure OpenAI or Microsoft Foundry endpoint. Accepts
|
|
27
|
+
* the forms the Azure portal shows: with or without a trailing `/openai` or
|
|
28
|
+
* `/openai/v1`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function azureOpenAIResourceRoot(endpoint: string): string;
|
|
31
|
+
interface AzureOpenAIProviderOptions {
|
|
32
|
+
client?: OpenAI;
|
|
33
|
+
fetchFn?: typeof fetch;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Azure OpenAI Service and Microsoft Foundry. The wire format is OpenAI's, so
|
|
37
|
+
* chat, image, speech, transcription and embedding calls reuse
|
|
38
|
+
* {@link OpenAIProvider}. Models are the deployments the user lists, because
|
|
39
|
+
* Azure addresses a model by its deployment name.
|
|
40
|
+
*
|
|
41
|
+
* Without `AZURE_OPENAI_API_VERSION` (or with `v1`) requests go to the v1 API
|
|
42
|
+
* at `<resource>/openai/v1`. With a dated version they go to the classic
|
|
43
|
+
* `<resource>/openai/deployments/<name>?api-version=<version>` routes.
|
|
44
|
+
*/
|
|
45
|
+
export declare class AzureOpenAIProvider extends OpenAIProvider {
|
|
46
|
+
static requiredSecrets(): string[];
|
|
47
|
+
readonly endpoint: string;
|
|
48
|
+
readonly apiVersion: string;
|
|
49
|
+
readonly deployments: AzureDeployment[];
|
|
50
|
+
constructor(secrets: {
|
|
51
|
+
AZURE_OPENAI_API_KEY?: string;
|
|
52
|
+
AZURE_OPENAI_ENDPOINT?: string;
|
|
53
|
+
AZURE_OPENAI_DEPLOYMENTS?: string;
|
|
54
|
+
AZURE_OPENAI_API_VERSION?: string;
|
|
55
|
+
}, options?: AzureOpenAIProviderOptions);
|
|
56
|
+
protected mediaModelIdentity(model: string): string;
|
|
57
|
+
getContainerEnv(): Record<string, string>;
|
|
58
|
+
hasToolSupport(_model: string): Promise<boolean>;
|
|
59
|
+
private deploymentsOf;
|
|
60
|
+
protected declaredCapabilities(): readonly ProviderCapability[];
|
|
61
|
+
getAvailableLanguageModels(): Promise<LanguageModel[]>;
|
|
62
|
+
getAvailableImageModels(): Promise<ImageModel[]>;
|
|
63
|
+
getAvailableTTSModels(): Promise<TTSModel[]>;
|
|
64
|
+
getAvailableASRModels(): Promise<ASRModel[]>;
|
|
65
|
+
getAvailableEmbeddingModels(): Promise<EmbeddingModel[]>;
|
|
66
|
+
getAvailableVideoModels(): Promise<never[]>;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=azure-openai-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"azure-openai-provider.d.ts","sourceRoot":"","sources":["../../src/providers/azure-openai-provider.ts"],"names":[],"mappings":"AAAA,OAAO,MAAuB,MAAM,QAAQ,CAAC;AAO7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,UAAU,EACV,aAAa,EACb,QAAQ,EACT,MAAM,YAAY,CAAC;AAEpB,+FAA+F;AAC/F,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,GAAG,WAAW,CAAC;AAEjF,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,mBAAmB,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC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