omp-antigravity-acp-provider 0.2.2 → 0.3.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.
Files changed (44) hide show
  1. package/AGENT_INSTALL.md +2 -2
  2. package/README.md +13 -13
  3. package/THIRD_PARTY_LICENSES.txt +70 -39
  4. package/extension/acp-compaction.ts +14 -2
  5. package/extension/acp-errors.ts +11 -3
  6. package/extension/adapter-config.ts +1 -1
  7. package/extension/ambient.d.ts +23 -0
  8. package/extension/assets/zip-archive.mjs +10839 -0
  9. package/extension/auth-sync.ts +94 -13
  10. package/extension/commands.ts +13 -16
  11. package/extension/context-settings.ts +2 -2
  12. package/extension/index.ts +74 -38
  13. package/extension/model-catalog.ts +4 -4
  14. package/extension/omp-context.ts +14 -3
  15. package/extension/omp-session-lifecycle.ts +3 -3
  16. package/extension/quota-usage.ts +3 -2
  17. package/extension/runtime/acp/bounded-stream.ts +78 -24
  18. package/extension/runtime/acp/connection.ts +18 -6
  19. package/extension/runtime/binding.ts +2 -2
  20. package/extension/runtime/config.ts +1 -1
  21. package/extension/runtime/managed.ts +2 -1
  22. package/extension/runtime/models.ts +17 -10
  23. package/extension/runtime/prompt.ts +90 -50
  24. package/extension/runtime/provider.ts +39 -11
  25. package/extension/runtime/runtime.ts +75 -45
  26. package/extension/runtime/stream/pi-events.ts +3 -3
  27. package/extension/runtime/tools/bridge.ts +20 -8
  28. package/extension/runtime/tools/relay.ts +2 -2
  29. package/extension/runtime/zip-archive.ts +1 -0
  30. package/extension/runtime.d.mts +1 -0
  31. package/extension/runtime.mjs +18314 -35379
  32. package/extension/secret-service.ts +28 -0
  33. package/extension/selectors.ts +8 -7
  34. package/extension/session-store.ts +7 -7
  35. package/extension/tier-connection.ts +39 -8
  36. package/extension/tool-policy.ts +2 -2
  37. package/extension/tool-relay-protocol.d.mts +5 -0
  38. package/extension/tool-routing.ts +40 -23
  39. package/extension/transcript-routing.ts +16 -3
  40. package/extension/turn-cancellation.ts +1 -1
  41. package/extension/usage-db.ts +42 -22
  42. package/extension/usage.ts +1 -1
  43. package/licenses/{pi-ai-1.3.0.txt → pi-mit.txt} +1 -2
  44. package/package.json +10 -8
@@ -1,22 +1,33 @@
1
+ import type { Message, Tool } from "@earendil-works/pi-ai";
2
+
1
3
  export interface OmpToolDeclaration { name: string; description?: string; parameters?: unknown }
2
4
 
3
5
  // OMP tools may be live AgentTool wrappers containing the entire session host,
4
6
  // counters, executable closures and cycles. ACP bridges declarations only;
5
7
  // tool execution still returns through OMP's own tool loop.
8
+ export function toolDeclarations(tools: readonly Tool[]): Tool[];
9
+ export function toolDeclarations(tools: readonly OmpToolDeclaration[]): OmpToolDeclaration[];
6
10
  export function toolDeclarations(tools: readonly OmpToolDeclaration[]): OmpToolDeclaration[] {
7
11
  return tools.map(tool => ({ name: tool.name, description: tool.description, parameters: tool.parameters }));
8
12
  }
9
13
 
14
+ export function normalizeOmpSystemDeltas(messages: Message[]): Message[];
15
+ export function normalizeOmpSystemDeltas(messages: unknown[]): unknown[];
10
16
  export function normalizeOmpSystemDeltas(messages: unknown[]): unknown[] {
11
17
  if (!messages.some(message => message && typeof message === "object" && "role" in message && message.role === "system")) {
12
18
  return messages;
13
19
  }
14
20
  return messages.map(message => {
15
21
  if (!message || typeof message !== "object" || !("role" in message) || message.role !== "system") return message;
16
- const system = message as { toolsAdded?: OmpToolDeclaration[]; toolsRemoved?: Array<{ name: string }> };
22
+ const toolsAdded = "toolsAdded" in message && Array.isArray(message.toolsAdded)
23
+ ? toolDeclarations(message.toolsAdded)
24
+ : undefined;
25
+ const toolsRemoved = "toolsRemoved" in message && Array.isArray(message.toolsRemoved)
26
+ ? message.toolsRemoved.map((tool: { name: string }) => ({ name: tool.name }))
27
+ : undefined;
17
28
  return { ...message,
18
- ...(system.toolsAdded ? { toolsAdded: toolDeclarations(system.toolsAdded) } : {}),
19
- ...(system.toolsRemoved ? { toolsRemoved: system.toolsRemoved.map(tool => ({ name: tool.name })) } : {}),
29
+ ...(toolsAdded ? { toolsAdded } : {}),
30
+ ...(toolsRemoved ? { toolsRemoved } : {}),
20
31
  };
21
32
  });
22
33
  }
@@ -49,16 +49,16 @@ export class OmpSessionLifecycle {
49
49
  let scope = this.fallback, replaced: Scope | undefined;
50
50
  if (host) {
51
51
  const previous = this.scopes.get(host);
52
- if (previous && !previous.closed && host.get("antigravity-acp") === previous) scope = previous;
52
+ if (previous && !previous.closed && host.get("antigravity-acp-provider") === previous) scope = previous;
53
53
  else {
54
54
  replaced = previous;
55
55
  let predecessor: Promise<void> | undefined;
56
56
  try {
57
- const existing = host.get("antigravity-acp");
57
+ const existing = host.get("antigravity-acp-provider");
58
58
  if (existing) predecessor = Promise.resolve(existing.close());
59
59
  } catch (error) { predecessor = Promise.reject(error); }
60
60
  scope = this.newScope(predecessor);
61
- this.scopes.set(host, scope); host.set("antigravity-acp", scope);
61
+ this.scopes.set(host, scope); host.set("antigravity-acp-provider", scope);
62
62
  }
63
63
  }
64
64
  let ticket = scope.sessions.get(id);
@@ -67,7 +67,7 @@ export interface QuotaUsageProvider {
67
67
  fetchUsage(params: QuotaUsageProviderParams, ctx: QuotaUsageProviderContext): Promise<QuotaUsageReport | null>;
68
68
  }
69
69
 
70
- const DEFAULT_PROVIDER = "antigravity-acp";
70
+ const DEFAULT_PROVIDER = "antigravity-acp-provider";
71
71
  const WEEK_MS = 604_800_000;
72
72
  const FIVE_HOURS_MS = 18_000_000;
73
73
  const DAY_MS = 86_400_000;
@@ -199,7 +199,8 @@ export function createQuotaUsageProvider(options: {
199
199
  let shared = inFlight;
200
200
  if (!shared) {
201
201
  const controller = new AbortController();
202
- const load = (async () => {
202
+ let load: Promise<QuotaUsageReport | null> | undefined;
203
+ load = (async () => {
203
204
  try {
204
205
  const snapshot = await options.loadSnapshot(controller.signal);
205
206
  if (!snapshot || controller.signal.aborted) return null;
@@ -27,8 +27,12 @@ export function boundedNdjsonStream(
27
27
  const encoder = new TextEncoder();
28
28
  const decoder = new TextDecoder("utf-8", { fatal: true });
29
29
  let reader: ReadableStreamDefaultReader<Uint8Array> | undefined;
30
- let pending: Uint8Array<ArrayBufferLike> = new Uint8Array(0);
30
+ let chunks: Uint8Array<ArrayBufferLike>[] = [];
31
+ let chunkBytes = 0;
31
32
  let closed = false;
33
+ let inputDone = false;
34
+ const queuedFrames: Uint8Array<ArrayBufferLike>[] = [];
35
+ let queuedIndex = 0;
32
36
  let released = false;
33
37
  const releaseReader = () => {
34
38
  if (!reader || released) return;
@@ -43,41 +47,86 @@ export function boundedNdjsonStream(
43
47
  if (closed) return;
44
48
  try {
45
49
  for (;;) {
46
- if (closed) return;
47
- let newline: number;
48
- while ((newline = pending.indexOf(0x0a)) >= 0) {
49
- const frame = pending.subarray(0, newline);
50
- pending = pending.slice(newline + 1);
50
+ while (queuedIndex < queuedFrames.length) {
51
+ const frame = queuedFrames[queuedIndex++]!;
51
52
  if (frame.byteLength > maxFrameBytes) {
52
53
  throw new Error(`ACP frame exceeds ${maxFrameBytes} bytes`);
53
54
  }
54
55
  enqueueFrame(frame, decoder, controller, options.onCompatibilityNoise);
55
56
  if (controller.desiredSize !== null && controller.desiredSize <= 0) return;
56
57
  }
58
+ queuedFrames.length = 0;
59
+ queuedIndex = 0;
60
+ if (inputDone) {
61
+ closed = true;
62
+ controller.close();
63
+ releaseReader();
64
+ return;
65
+ }
57
66
  const { value, done } = await reader!.read();
58
67
  if (closed) return;
59
68
  if (done) {
60
- if (pending.byteLength > 0) {
61
- if (pending.byteLength > maxFrameBytes) {
69
+ if (chunkBytes > 0) {
70
+ if (chunkBytes > maxFrameBytes) {
62
71
  throw new Error(`ACP frame exceeds ${maxFrameBytes} bytes`);
63
72
  }
64
- enqueueFrame(pending, decoder, controller, options.onCompatibilityNoise);
65
- pending = new Uint8Array(0);
73
+ const frame = chunks.length === 1 ? chunks[0]! : joinChunks(chunks, chunkBytes);
74
+ chunks = [];
75
+ chunkBytes = 0;
76
+ queuedFrames.push(frame);
66
77
  }
67
- closed = true;
68
- controller.close();
69
- releaseReader();
70
- return;
78
+ inputDone = true;
79
+ continue;
71
80
  }
72
81
  if (!value || value.byteLength === 0) continue;
73
- pending = appendBytes(pending, value);
74
- if (pending.byteLength > maxFrameBytes && pending.indexOf(0x0a) < 0) {
75
- throw new Error(`ACP frame exceeds ${maxFrameBytes} bytes`);
82
+ let offset = 0;
83
+ let newline = value.indexOf(0x0a, offset);
84
+ if (newline < 0) {
85
+ if (chunkBytes + value.byteLength > maxFrameBytes) {
86
+ throw new Error(`ACP frame exceeds ${maxFrameBytes} bytes`);
87
+ }
88
+ chunks.push(value.slice());
89
+ chunkBytes += value.byteLength;
90
+ continue;
91
+ }
92
+ while (newline >= 0) {
93
+ const tail = value.subarray(offset, newline);
94
+ const frameLength = chunkBytes + tail.byteLength;
95
+ if (frameLength > maxFrameBytes) {
96
+ throw new Error(`ACP frame exceeds ${maxFrameBytes} bytes`);
97
+ }
98
+ let frame: Uint8Array<ArrayBufferLike>;
99
+ if (chunks.length === 0) {
100
+ frame = tail;
101
+ } else {
102
+ frame = new Uint8Array(frameLength);
103
+ let cursor = 0;
104
+ for (const part of chunks) {
105
+ frame.set(part, cursor);
106
+ cursor += part.byteLength;
107
+ }
108
+ if (tail.byteLength > 0) frame.set(tail, cursor);
109
+ chunks = [];
110
+ chunkBytes = 0;
111
+ }
112
+ queuedFrames.push(frame);
113
+ offset = newline + 1;
114
+ newline = offset < value.byteLength ? value.indexOf(0x0a, offset) : -1;
115
+ }
116
+ if (offset < value.byteLength) {
117
+ const rest = value.subarray(offset);
118
+ if (rest.byteLength > maxFrameBytes) {
119
+ throw new Error(`ACP frame exceeds ${maxFrameBytes} bytes`);
120
+ }
121
+ chunks.push(rest.slice());
122
+ chunkBytes = rest.byteLength;
76
123
  }
77
124
  }
78
125
  } catch (cause) {
79
126
  if (closed) return;
80
127
  closed = true;
128
+ queuedFrames.length = 0;
129
+ queuedIndex = 0;
81
130
  const error = cause instanceof Error ? cause : new Error(String(cause));
82
131
  options.onProtocolError?.(error);
83
132
  // ACP SDK 0.16.1 starts its receive loop without observing the
@@ -90,6 +139,8 @@ export function boundedNdjsonStream(
90
139
  },
91
140
  async cancel(reason) {
92
141
  closed = true;
142
+ queuedFrames.length = 0;
143
+ queuedIndex = 0;
93
144
  try { await reader?.cancel(reason); } catch { /* The input is already gone. */ }
94
145
  releaseReader();
95
146
  },
@@ -121,14 +172,17 @@ export function boundedNdjsonStream(
121
172
  return { readable, writable };
122
173
  }
123
174
 
124
- function appendBytes(
125
- left: Uint8Array<ArrayBufferLike>,
126
- right: Uint8Array<ArrayBufferLike>,
175
+ function joinChunks(
176
+ chunks: Uint8Array<ArrayBufferLike>[],
177
+ totalBytes: number,
127
178
  ): Uint8Array<ArrayBufferLike> {
128
- if (left.byteLength === 0) return right.slice();
129
- const joined = new Uint8Array(left.byteLength + right.byteLength);
130
- joined.set(left);
131
- joined.set(right, left.byteLength);
179
+ if (chunks.length === 1) return chunks[0]!;
180
+ const joined = new Uint8Array(totalBytes);
181
+ let cursor = 0;
182
+ for (const chunk of chunks) {
183
+ joined.set(chunk, cursor);
184
+ cursor += chunk.byteLength;
185
+ }
132
186
  return joined;
133
187
  }
134
188
 
@@ -118,15 +118,16 @@ export class AntigravityAcpConnection {
118
118
  } else if (notification.update.sessionUpdate === "current_mode_update") {
119
119
  const state = this.getSessionState(notification.sessionId);
120
120
  const modeSelector = findSessionSelector(state, "mode");
121
+ const currentModeId = notification.update.currentModeId;
121
122
  this.sessions.set(notification.sessionId, {
122
123
  ...state,
123
124
  ...(state.modes
124
- ? { modes: { ...state.modes, currentModeId: notification.update.currentModeId } }
125
+ ? { modes: { ...state.modes, currentModeId } }
125
126
  : {}),
126
127
  ...(modeSelector && state.configOptions
127
128
  ? { configOptions: state.configOptions.map(option =>
128
129
  option.type === "select" && option.id === modeSelector.id
129
- ? { ...option, currentValue: notification.update.currentModeId }
130
+ ? { ...option, currentValue: currentModeId }
130
131
  : option) }
131
132
  : {}),
132
133
  });
@@ -368,6 +369,14 @@ export class AntigravityAcpConnection {
368
369
  await this.closePromise;
369
370
  }
370
371
 
372
+ async discardSession(_sessionId: string): Promise<void> {}
373
+
374
+ muteSteerChunks(_sessionId: string): void {}
375
+
376
+ async confirmReplacement(_key: string, _sessionId: string): Promise<void> {}
377
+
378
+ async retireForReplacement(_key: string, _sessionId: string): Promise<void> {}
379
+
371
380
  private updateSessionState(sessionId: string, response: unknown): SessionState {
372
381
  const commands = (response as { availableCommands?: AvailableCommand[] | null }).availableCommands;
373
382
  const state = { ...this.sessions.get(sessionId), ...decodeSessionState(response), ...(commands === undefined ? {} : { availableCommands: commands }) };
@@ -375,13 +384,15 @@ export class AntigravityAcpConnection {
375
384
  return state;
376
385
  }
377
386
 
378
- private async setSelector(
387
+ protected async setSelector(
379
388
  sessionId: string,
380
- category: "model" | "mode" | "thought_level",
389
+ category: string,
381
390
  value: string,
382
391
  signal?: AbortSignal,
383
392
  ): Promise<boolean> {
384
- const selector = findSessionSelector(this.sessions.get(sessionId) ?? {}, category);
393
+ const selector = this.sessions.get(sessionId)?.configOptions?.find(
394
+ option => option.type === "select" && (option.category === category || option.id === category),
395
+ );
385
396
  if (!selector) return false;
386
397
  const response = await this.withAbort(
387
398
  this.withDeadline(
@@ -392,7 +403,8 @@ export class AntigravityAcpConnection {
392
403
  signal,
393
404
  );
394
405
  const state = this.updateSessionState(sessionId, response);
395
- if (findSessionSelector(state, category)?.currentValue !== value) {
406
+ const updated = state.configOptions?.find(option => option.id === selector.id);
407
+ if (!updated || updated.type !== "select" || updated.currentValue !== value) {
396
408
  throw new AntigravityAcpError("protocol", `Antigravity did not confirm the requested ${category} selection`);
397
409
  }
398
410
  return true;
@@ -120,7 +120,7 @@ function matches(value: unknown, saved: unknown, budget = { nodes: 0 }): boolean
120
120
  Object.getPrototypeOf(value) !== (array ? Array.prototype : Object.prototype)) return false;
121
121
  const keys = Object.keys(value);
122
122
  if (keys.length > MAX_MESSAGE_NODES || keys.length !== Object.keys(saved).length ||
123
- (array && (value.length !== saved.length || Object.getOwnPropertyNames(value).length !== keys.length + 1))) return false;
123
+ (Array.isArray(value) && Array.isArray(saved) && (value.length !== saved.length || Object.getOwnPropertyNames(value).length !== keys.length + 1))) return false;
124
124
  for (const key of keys) {
125
125
  const descriptor = Object.getOwnPropertyDescriptor(value, key)!;
126
126
  if (!Object.hasOwn(descriptor, "value") || !Object.hasOwn(saved, key) ||
@@ -136,7 +136,7 @@ export function createHistoryFingerprintMemo() {
136
136
  if (previous && matches(value, previous.value)) return previous.digest;
137
137
  // Drop stale strings even if canonical serialization subsequently throws.
138
138
  if (previous) entries.delete(message);
139
- if (!worthCaching(Reflect.get(value, "content"))) return compute();
139
+ if (!value || typeof value !== "object" || !worthCaching(Reflect.get(value, "content"))) return compute();
140
140
  const saved = snapshot(value);
141
141
  const digest = compute();
142
142
  if (saved !== UNSUPPORTED) entries.set(message, { value: saved, digest });
@@ -3,7 +3,7 @@ import fs from "node:fs";
3
3
  import os from "node:os";
4
4
  import path from "node:path";
5
5
 
6
- export type PermissionMode = "default" | "auto_edit" | "yolo";
6
+ export type PermissionMode = "default" | "auto_edit" | "accept-edits" | "yolo";
7
7
  export type RuntimeUpdateMode = "automatic" | "notify" | "manual";
8
8
 
9
9
  export interface AntigravityAcpConfig {
@@ -5,7 +5,7 @@ import os from "node:os";
5
5
  import path from "node:path";
6
6
  import { pipeline } from "node:stream/promises";
7
7
  import { promisify } from "node:util";
8
- import { Open, type File as ZipFile } from "unzipper";
8
+ import type { File as ZipFile } from "unzipper";
9
9
 
10
10
  import { loadConfig, type RuntimeUpdateMode } from "./config.ts";
11
11
  import { resolveAntigravityAcpDirectory, resolveAntigravityAcpLaunch, type AntigravityLaunch } from "./acp/antigravity.ts";
@@ -447,6 +447,7 @@ async function extractRuntimeArchive(
447
447
  destination: string,
448
448
  release: ResolvedRuntimeRelease,
449
449
  ): Promise<void> {
450
+ const { Open } = await import("./zip-archive.ts");
450
451
  const archive = await Open.file(archivePath);
451
452
  validateRuntimeArchiveEntries(archive.files, release);
452
453
  const expected = new Map<string, number>([
@@ -1,18 +1,25 @@
1
1
  import type { AcpModelInfo } from "./acp/session-state.ts";
2
+ import type { ContextOptions } from "../context-settings.ts";
2
3
  import type {
3
4
  Model,
4
5
  ThinkingLevel,
5
6
  ThinkingLevelMap,
6
7
  } from "@earendil-works/pi-ai";
7
8
 
8
- export const PROVIDER_ID = "antigravity-acp";
9
- export const API_ID = "antigravity-acp";
9
+ export const PROVIDER_ID = "antigravity-acp-provider";
10
+ export const API_ID = "antigravity-acp-provider";
11
+
12
+ export interface AntigravityModel extends Omit<Model<typeof API_ID>, "baseUrl" | "input" | "compat"> {
13
+ baseUrl?: string;
14
+ input: readonly string[];
15
+ ompContextPolicy?: ContextOptions;
16
+ }
10
17
 
11
18
  const ZERO_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } as const;
12
19
  type Effort = "low" | "medium" | "high";
13
20
  type Variants = Partial<Record<Effort, string>>;
14
21
 
15
- export const FALLBACK_MODELS: readonly Model<typeof API_ID>[] = [
22
+ export const FALLBACK_MODELS: readonly (Model<typeof API_ID> & { provider: typeof PROVIDER_ID })[] = [
16
23
  reasoningModel("gemini-3.8-flash", "Gemini 3.8 Flash", {
17
24
  low: "gemini-3.8-flash-low",
18
25
  medium: "gemini-3.8-flash-medium",
@@ -37,7 +44,7 @@ export const FALLBACK_MODELS: readonly Model<typeof API_ID>[] = [
37
44
  /** Collapse Antigravity's effort-qualified ACP IDs into one Pi model. The
38
45
  * exact server IDs live in thinkingLevelMap, allowing Shift+Tab to select the
39
46
  * corresponding low/medium/high variant without cluttering /model. */
40
- export function projectModels(models: readonly AcpModelInfo[]): Model<typeof API_ID>[] {
47
+ export function projectModels(models: readonly AcpModelInfo[]): (Model<typeof API_ID> & { provider: typeof PROVIDER_ID })[] {
41
48
  const safe = models.filter((candidate) => validModelId(candidate.modelId.trim()));
42
49
  const groups = new Map<
43
50
  string,
@@ -57,7 +64,7 @@ export function projectModels(models: readonly AcpModelInfo[]): Model<typeof API
57
64
 
58
65
  const emittedGroups = new Set<string>();
59
66
  const emittedIds = new Set<string>();
60
- const projected: Model<typeof API_ID>[] = [];
67
+ const projected: (Model<typeof API_ID> & { provider: typeof PROVIDER_ID })[] = [];
61
68
  for (const candidate of safe) {
62
69
  const id = candidate.modelId.trim();
63
70
  if (emittedIds.has(id)) continue;
@@ -88,8 +95,8 @@ export function projectModels(models: readonly AcpModelInfo[]): Model<typeof API
88
95
  /** Resolve Pi's current reasoning level to the exact model ID advertised by
89
96
  * Antigravity. Unsupported programmatic levels clamp to the nearest tier. */
90
97
  export function resolveAcpModelId(
91
- model: Model<typeof API_ID>,
92
- reasoning: ThinkingLevel | undefined,
98
+ model: Pick<Model<typeof API_ID>, "id" | "reasoning" | "thinkingLevelMap">,
99
+ reasoning: ThinkingLevel | string | undefined,
93
100
  ): string {
94
101
  const map = model.thinkingLevelMap;
95
102
  if (!model.reasoning || !map) return model.id;
@@ -116,7 +123,7 @@ function reasoningModel(
116
123
  id: string,
117
124
  name: string,
118
125
  variants: Variants,
119
- ): Model<typeof API_ID> {
126
+ ): Model<typeof API_ID> & { provider: typeof PROVIDER_ID } {
120
127
  const thinkingLevelMap: ThinkingLevelMap = {
121
128
  off: null,
122
129
  minimal: null,
@@ -129,7 +136,7 @@ function reasoningModel(
129
136
  return baseModel(id, name, true, thinkingLevelMap);
130
137
  }
131
138
 
132
- function fixedModel(id: string, name: string): Model<typeof API_ID> {
139
+ function fixedModel(id: string, name: string): Model<typeof API_ID> & { provider: typeof PROVIDER_ID } {
133
140
  return baseModel(id, name, false);
134
141
  }
135
142
 
@@ -138,7 +145,7 @@ function baseModel(
138
145
  name: string,
139
146
  reasoning: boolean,
140
147
  thinkingLevelMap?: ThinkingLevelMap,
141
- ): Model<typeof API_ID> {
148
+ ): Model<typeof API_ID> & { provider: typeof PROVIDER_ID } {
142
149
  return {
143
150
  id,
144
151
  name,