omp-antigravity-acp-provider 0.2.2 → 0.2.4

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 (42) hide show
  1. package/README.md +9 -11
  2. package/THIRD_PARTY_LICENSES.txt +70 -39
  3. package/extension/acp-compaction.ts +14 -2
  4. package/extension/acp-errors.ts +11 -3
  5. package/extension/adapter-config.ts +1 -1
  6. package/extension/ambient.d.ts +23 -0
  7. package/extension/assets/zip-archive.mjs +10839 -0
  8. package/extension/auth-sync.ts +88 -7
  9. package/extension/commands.ts +12 -15
  10. package/extension/context-settings.ts +2 -2
  11. package/extension/index.ts +71 -35
  12. package/extension/model-catalog.ts +1 -1
  13. package/extension/omp-context.ts +14 -3
  14. package/extension/quota-usage.ts +2 -1
  15. package/extension/runtime/acp/bounded-stream.ts +78 -24
  16. package/extension/runtime/acp/connection.ts +18 -6
  17. package/extension/runtime/binding.ts +2 -2
  18. package/extension/runtime/config.ts +1 -1
  19. package/extension/runtime/managed.ts +2 -1
  20. package/extension/runtime/models.ts +15 -8
  21. package/extension/runtime/prompt.ts +90 -50
  22. package/extension/runtime/provider.ts +38 -10
  23. package/extension/runtime/runtime.ts +74 -44
  24. package/extension/runtime/stream/pi-events.ts +3 -3
  25. package/extension/runtime/tools/bridge.ts +20 -8
  26. package/extension/runtime/tools/relay.ts +2 -2
  27. package/extension/runtime/zip-archive.ts +1 -0
  28. package/extension/runtime.d.mts +1 -0
  29. package/extension/runtime.mjs +18311 -35376
  30. package/extension/secret-service.ts +28 -0
  31. package/extension/selectors.ts +8 -7
  32. package/extension/session-store.ts +7 -7
  33. package/extension/tier-connection.ts +39 -8
  34. package/extension/tool-policy.ts +2 -2
  35. package/extension/tool-relay-protocol.d.mts +5 -0
  36. package/extension/tool-routing.ts +40 -23
  37. package/extension/transcript-routing.ts +16 -3
  38. package/extension/turn-cancellation.ts +1 -1
  39. package/extension/usage-db.ts +42 -22
  40. package/extension/usage.ts +1 -1
  41. package/licenses/{pi-ai-1.3.0.txt → pi-mit.txt} +1 -2
  42. package/package.json +10 -8
@@ -2,25 +2,53 @@ import type {
2
2
  Api,
3
3
  ApiStreamOptions,
4
4
  AssistantMessageEventStream,
5
+ Context,
5
6
  TranscriptContext,
6
7
  Model,
7
8
  Provider,
8
9
  RefreshModelsContext,
9
- SimpleStreamOptions,
10
+ StreamOptions,
10
11
  } from "@earendil-works/pi-ai";
11
12
 
12
13
  import { hasAntigravityAuth } from "./acp/antigravity.ts";
13
- import { FALLBACK_MODELS, projectModels, PROVIDER_ID } from "./models.ts";
14
+ import { type AntigravityModel, FALLBACK_MODELS, projectModels, PROVIDER_ID } from "./models.ts";
14
15
  import { AntigravityRuntime, MANAGED_AUTH_MARKER, type OmpStreamOptions } from "./runtime.ts";
15
16
 
17
+ export interface AntigravityProvider extends Omit<Provider<"antigravity-acp">, "auth" | "streamSimple"> {
18
+ auth: NonNullable<Provider<"antigravity-acp">["auth"]> & {
19
+ oauth: {
20
+ name: string;
21
+ loginLabel: string;
22
+ login(interaction: {
23
+ signal?: AbortSignal;
24
+ notify: (event: { type?: "progress" | "info"; message?: string; links?: Array<{ url: string; label?: string }> }) => void;
25
+ prompt: (prompt: { type?: "secret" | "text" | "manual_code"; message: string; placeholder?: string; signal?: AbortSignal }) => Promise<string>;
26
+ }): Promise<{
27
+ type: "oauth";
28
+ refresh: string;
29
+ access: string;
30
+ expires: number;
31
+ [key: string]: unknown;
32
+ }>;
33
+ refresh<T>(credential: T, signal?: AbortSignal): Promise<T>;
34
+ toAuth(): Promise<{ apiKey: string }>;
35
+ };
36
+ };
37
+ streamSimple(
38
+ model: AntigravityModel,
39
+ context: Context | TranscriptContext,
40
+ options?: OmpStreamOptions,
41
+ ): AssistantMessageEventStream;
42
+ }
43
+
16
44
  export interface AntigravityProviderBundle {
17
- provider: Provider<"antigravity-acp">;
45
+ provider: AntigravityProvider;
18
46
  runtime: AntigravityRuntime;
19
47
  }
20
48
 
21
49
  export function createAntigravityProvider(runtime = new AntigravityRuntime()): AntigravityProviderBundle {
22
50
  let models = [...FALLBACK_MODELS];
23
- const provider: Provider<"antigravity-acp"> = {
51
+ const provider: AntigravityProvider = {
24
52
  id: PROVIDER_ID,
25
53
  name: "Google Antigravity (ACP)",
26
54
  auth: {
@@ -58,7 +86,7 @@ export function createAntigravityProvider(runtime = new AntigravityRuntime()): A
58
86
  expires: Number.MAX_SAFE_INTEGER,
59
87
  };
60
88
  },
61
- async refresh(credential) {
89
+ async refresh<T>(credential: T) {
62
90
  return credential;
63
91
  },
64
92
  async toAuth() {
@@ -127,7 +155,7 @@ export function createAntigravityProvider(runtime = new AntigravityRuntime()): A
127
155
  },
128
156
  });
129
157
  },
130
- stream(model, context, options) {
158
+ stream(model, context, options: StreamOptions | undefined) {
131
159
  return stream(runtime, model, context, options);
132
160
  },
133
161
  streamSimple(model, context, options) {
@@ -139,11 +167,11 @@ export function createAntigravityProvider(runtime = new AntigravityRuntime()): A
139
167
 
140
168
  function stream(
141
169
  runtime: AntigravityRuntime,
142
- model: Model<"antigravity-acp">,
143
- context: TranscriptContext,
144
- options: ApiStreamOptions<"antigravity-acp"> | SimpleStreamOptions | undefined,
170
+ model: AntigravityModel,
171
+ context: Context | TranscriptContext,
172
+ options: OmpStreamOptions | undefined,
145
173
  ): AssistantMessageEventStream {
146
- return runtime.stream(model, context, options as OmpStreamOptions | undefined).stream;
174
+ return runtime.stream(model, context, options).stream;
147
175
  }
148
176
 
149
177
  export const ANTIGRAVITY_ACP_API = "antigravity-acp" satisfies Api;
@@ -9,6 +9,7 @@ import { ompToolGuidance, type NativeToolMode, type SessionRoutingKind } from ".
9
9
  import type {
10
10
  ContentBlock,
11
11
  InitializeResponse,
12
+ PromptCapabilities,
12
13
  PromptResponse,
13
14
  RequestPermissionRequest,
14
15
  RequestPermissionResponse,
@@ -20,15 +21,17 @@ import {
20
21
  getCurrentTools,
21
22
  normalizeContext,
22
23
  type Context,
23
- type Model,
24
24
  type SimpleStreamOptions,
25
+ type ThinkingLevel,
25
26
  type ToolResultMessage,
26
- type JsonValue,
27
27
  type TextContent,
28
28
  type ToolCall,
29
29
  } from "@earendil-works/pi-ai";
30
30
  import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
31
31
  import { createHash } from "node:crypto";
32
+ import { mkdirSync } from "node:fs";
33
+ import { tmpdir } from "node:os";
34
+ import { join } from "node:path";
32
35
 
33
36
  import {
34
37
  clearAntigravityCredentials,
@@ -59,13 +62,21 @@ import {
59
62
  type PiToolInvocation,
60
63
  } from "./tools/bridge.ts";
61
64
  import type { PermissionMode } from "./config.ts";
62
- import { resolveAcpModelId } from "./models.ts";
63
- import { type PromptParts, buildPromptParts, currentSystemInstructions, stableSystemInstructions, estimateContextTokens } from "./prompt.ts";
65
+ import { type AntigravityModel, resolveAcpModelId } from "./models.ts";
66
+ import { type PromptParts, type TransferBlock, buildPromptParts, currentSystemInstructions, stableSystemInstructions, estimateContextTokens } from "./prompt.ts";
67
+ import { isJsonObject } from "./stream/json.ts";
64
68
  import { resolveSessionRoute, type SessionRoute } from "./routing.ts";
65
69
  import { PiEventWriter } from "./stream/pi-events.ts";
66
70
  import { usageFromPrompt, type PromptUsageResult } from "../usage.ts";
67
71
  import { RuntimeMetrics } from "./status.ts";
68
72
 
73
+ const QUOTA_WORKDIR = join(tmpdir(), "omp-antigravity-acp-quota");
74
+
75
+ function quotaWorkingDirectory(): string {
76
+ try { mkdirSync(QUOTA_WORKDIR, { recursive: true, mode: 0o700 }); } catch { /* The ACP server reports an unusable cwd. */ }
77
+ return QUOTA_WORKDIR;
78
+ }
79
+
69
80
  const ompMessageFingerprintMemo = createHistoryFingerprintMemo();
70
81
 
71
82
  interface OmpQuotaRequest {
@@ -83,11 +94,10 @@ const TOOL_BATCH_MS = 100;
83
94
  // This adapter's provider name is not in the table, so it gets the floor.
84
95
  const OMP_PROVIDER_IMAGE_BUDGET = 5;
85
96
 
86
- type AntigravityModel = Model<"antigravity-acp">;
87
-
88
97
  // OMP passes its routing identity beside the Pi stream options. The complete Pi
89
98
  // option object stays intact; only these adapter-only fields are read here.
90
- export interface OmpStreamOptions extends SimpleStreamOptions {
99
+ export interface OmpStreamOptions extends Omit<SimpleStreamOptions, "reasoning"> {
100
+ reasoning?: ThinkingLevel | string;
91
101
  /** Owning main routing id for an OMP side (`/btw`) request. */
92
102
  parentSessionId?: string;
93
103
  /** OMP prompt cache key; carried through unchanged. */
@@ -174,22 +184,6 @@ function contextControlMembership(names: readonly string[]): string {
174
184
  return ["context_notes", "new_context"].filter(name => names.includes(name)).join(",");
175
185
  }
176
186
 
177
- function isJsonValue(value: unknown, ancestors = new Set<object>()): value is JsonValue {
178
- if (value === null || typeof value === "string" || typeof value === "boolean") return true;
179
- if (typeof value === "number") return Number.isFinite(value);
180
- if (typeof value !== "object" || ancestors.has(value)) return false;
181
- const prototype = Object.getPrototypeOf(value);
182
- if (prototype !== Object.prototype && prototype !== Array.prototype && prototype !== null) return false;
183
- // Track the current recursion path only: the same object may appear twice in
184
- // valid JSON data (encoding duplicates it), while a cycle must fail.
185
- ancestors.add(value);
186
- const valid = Array.isArray(value)
187
- ? value.every(item => isJsonValue(item, ancestors))
188
- : Object.values(value).every(item => isJsonValue(item, ancestors));
189
- ancestors.delete(value);
190
- return valid;
191
- }
192
-
193
187
  function normalizeBoundaryContentBlock(block: unknown): Array<TextContent | ToolCall> {
194
188
  if (typeof block !== "object" || block === null) return [];
195
189
  const type = Reflect.get(block, "type");
@@ -199,7 +193,7 @@ function normalizeBoundaryContentBlock(block: unknown): Array<TextContent | Tool
199
193
  }
200
194
  if (type === "toolCall") {
201
195
  const id = Reflect.get(block, "id"), name = Reflect.get(block, "name"), args = Reflect.get(block, "arguments");
202
- if (typeof id !== "string" || typeof name !== "string" || !isJsonValue(args) || typeof args !== "object" || args === null || Array.isArray(args)) return [];
196
+ if (typeof id !== "string" || typeof name !== "string" || !isJsonObject(args)) return [];
203
197
  return [{ type: "toolCall", id, name, arguments: args }];
204
198
  }
205
199
  return [];
@@ -526,7 +520,8 @@ export class AntigravityRuntime {
526
520
  this.assertEpoch(epoch);
527
521
  let sessionId: string | undefined;
528
522
  let text = "";
529
- const quotaOptions = { cwd: process.cwd(), ompPurpose: "quota" as const };
523
+ const quotaCwd = quotaWorkingDirectory();
524
+ const quotaOptions = { cwd: quotaCwd, ompPurpose: "quota" as const };
530
525
  const connection = this.createConnection({
531
526
  ...quotaOptions,
532
527
  promptIdleTimeoutMs: 30_000,
@@ -542,7 +537,7 @@ export class AntigravityRuntime {
542
537
  this.assertEpoch(epoch);
543
538
  await authenticateForCredential(connection, initialize, apiKey, signal);
544
539
  this.assertEpoch(epoch);
545
- const session = await connection.newSession(process.cwd(), signal);
540
+ const session = await connection.newSession(quotaCwd, signal);
546
541
  sessionId = session.sessionId;
547
542
  this.assertEpoch(epoch);
548
543
  const currentModel = sessionModels(session)?.currentModelId;
@@ -792,7 +787,7 @@ export class AntigravityRuntime {
792
787
  private async runQueued(
793
788
  model: AntigravityModel,
794
789
  context: Context,
795
- options: SimpleStreamOptions,
790
+ options: OmpStreamOptions,
796
791
  writer: PiEventWriter,
797
792
  ): Promise<void> {
798
793
  this.assertActive();
@@ -853,7 +848,7 @@ export class AntigravityRuntime {
853
848
  } else {
854
849
  const drained = prefixMatches && await drainCancelledTurn(binding, () => abortTurn(binding), options.signal);
855
850
  if (!drained || !binding.connection.process.alive || binding.needsReconstruction ||
856
- !['cancelled', 'end_turn', 'max_turn_requests', 'max_tokens'].includes(binding.ompTerminalStopReason)) {
851
+ !binding.ompTerminalStopReason || !['cancelled', 'end_turn', 'max_turn_requests', 'max_tokens'].includes(binding.ompTerminalStopReason)) {
857
852
  await this.invalidateBinding(binding);
858
853
  }
859
854
  if (drained && prefixMatches) {
@@ -1051,14 +1046,15 @@ export class AntigravityRuntime {
1051
1046
  completeTurn = resolve;
1052
1047
  });
1053
1048
  if (options.signal) {
1049
+ const turnSignal = options.signal;
1054
1050
  const promptBinding = binding;
1055
1051
  onTurnAbort = () => {
1056
- if (steerMode() === 'queue' && isSteerAbort(options.signal) && !promptBinding.ompSeeding) {
1052
+ if (steerMode() === 'queue' && isSteerAbort(turnSignal) && !promptBinding.ompSeeding) {
1057
1053
  promptBinding.connection.muteSteerChunks?.(promptBinding.session.sessionId);
1058
1054
  } else abortTurn(promptBinding);
1059
1055
  };
1060
- options.signal.addEventListener("abort", onTurnAbort, { once: true });
1061
- if (options.signal.aborted) onTurnAbort();
1056
+ turnSignal.addEventListener("abort", onTurnAbort, { once: true });
1057
+ if (turnSignal.aborted) onTurnAbort();
1062
1058
  }
1063
1059
  if (options.signal?.aborted) throw abortError();
1064
1060
  binding.ompInFlight = true;
@@ -1155,7 +1151,7 @@ export class AntigravityRuntime {
1155
1151
  if (isAbort(error) || binding.abortRequested) {
1156
1152
  abortTurn(binding);
1157
1153
  if (binding.connection.process.alive && !binding.ompInvalidated && !binding.needsReconstruction && !binding.ompSeeding &&
1158
- ['cancelled', 'end_turn', 'max_turn_requests', 'max_tokens'].includes(binding.ompTerminalStopReason)) {
1154
+ binding.ompTerminalStopReason !== undefined && ['cancelled', 'end_turn', 'max_turn_requests', 'max_tokens'].includes(binding.ompTerminalStopReason)) {
1159
1155
  const ompWasWarm = binding.messageCount > 0;
1160
1156
  binding.messageCount = binding.pendingContextCount;
1161
1157
  binding.historyFingerprint = binding.pendingContextFingerprint;
@@ -1339,7 +1335,7 @@ export class AntigravityRuntime {
1339
1335
 
1340
1336
  private async promptShadowSeedSteps(
1341
1337
  binding: Binding,
1342
- steps: NonNullable<PromptParts["seedSteps"]>,
1338
+ steps: ContentBlock[][],
1343
1339
  signal?: AbortSignal,
1344
1340
  ): Promise<PromptUsageResult | undefined> {
1345
1341
  const savedWriter = binding.writer;
@@ -1895,21 +1891,53 @@ export async function authenticateForCredential(
1895
1891
  await connection.authenticate({ methodId: method.id, _meta: { "api-key": key } }, signal);
1896
1892
  }
1897
1893
 
1898
- function adaptPromptToCapabilities(parts: PromptParts, initialize: InitializeResponse): PromptParts {
1899
- const capabilities = initialize.agentCapabilities?.promptCapabilities;
1894
+ interface AcpPromptParts {
1895
+ prompt: ContentBlock[];
1896
+ seedSteps?: ContentBlock[][];
1897
+ messageCount: number;
1898
+ estimatedContextTokens: number;
1899
+ }
1900
+
1901
+ function adaptPromptBlocks(blocks: readonly TransferBlock[], capabilities: PromptCapabilities | undefined): ContentBlock[] {
1900
1902
  const output: ContentBlock[] = [];
1901
- for (const block of parts.prompt) {
1902
- if (block.type === "image" && capabilities?.image !== true) {
1903
- throw new AntigravityAcpError("invalid_input", "This Antigravity ACP runtime did not advertise image input");
1903
+ for (const block of blocks) {
1904
+ if (block.type === "image") {
1905
+ if (capabilities?.image !== true) {
1906
+ throw new AntigravityAcpError("invalid_input", "This Antigravity ACP runtime did not advertise image input");
1907
+ }
1908
+ if (typeof block.data !== "string" || typeof block.mimeType !== "string") {
1909
+ throw new AntigravityAcpError("invalid_input", "ACP image prompt block is missing data or mimeType");
1910
+ }
1911
+ output.push({ type: "image", data: block.data, mimeType: block.mimeType });
1912
+ continue;
1904
1913
  }
1905
- if (block.type === "resource" && capabilities?.embeddedContext !== true) {
1914
+ if (block.type === "resource") {
1906
1915
  const resource = block.resource;
1907
- if ("text" in resource) output.push({ type: "text", text: resource.text });
1916
+ if (!resource) continue;
1917
+ if (capabilities?.embeddedContext !== true) {
1918
+ if ("text" in resource) output.push({ type: "text", text: resource.text });
1919
+ continue;
1920
+ }
1921
+ output.push({ type: "resource", resource });
1922
+ continue;
1923
+ }
1924
+ if (block.type === "text" && typeof block.text === "string") {
1925
+ output.push({ type: "text", text: block.text });
1908
1926
  continue;
1909
1927
  }
1910
- output.push(block);
1928
+ throw new AntigravityAcpError("invalid_input", `Unsupported ACP prompt block type '${block.type}'`);
1911
1929
  }
1912
- return { ...parts, prompt: output, ...(parts.seedSteps ? { seedSteps: parts.seedSteps.map(step => adaptPromptToCapabilities({ prompt: step, messageCount: parts.messageCount, estimatedContextTokens: parts.estimatedContextTokens }, initialize).prompt) } : {}) };
1930
+ return output;
1931
+ }
1932
+
1933
+ function adaptPromptToCapabilities(parts: PromptParts, initialize: InitializeResponse): AcpPromptParts {
1934
+ const capabilities = initialize.agentCapabilities?.promptCapabilities;
1935
+ return {
1936
+ messageCount: parts.messageCount,
1937
+ estimatedContextTokens: parts.estimatedContextTokens,
1938
+ prompt: adaptPromptBlocks(parts.prompt, capabilities),
1939
+ seedSteps: parts.seedSteps ? parts.seedSteps.map(step => adaptPromptBlocks(step, capabilities)) : undefined,
1940
+ };
1913
1941
  }
1914
1942
 
1915
1943
  function hasUsableLocalAuth(health: AntigravityAuthHealth): boolean {
@@ -1969,12 +1997,14 @@ function findPermissionResult(context: Context, requestId: string): PermissionTo
1969
1997
  return undefined;
1970
1998
  }
1971
1999
 
1972
- function messagesFingerprint(messages: Context["messages"], systemMemo?: any): string {
2000
+ type FingerprintMemo = (value: unknown, compute: () => string) => string;
2001
+
2002
+ function messagesFingerprint(messages: Context["messages"], systemMemo?: FingerprintMemo): string {
1973
2003
  const fingerprints = messages.map(message => messageFingerprint(message, systemMemo));
1974
2004
  return createHash("sha256").update(fingerprints.join("\n")).digest("hex");
1975
2005
  }
1976
2006
 
1977
- function messageFingerprint(message: Context["messages"][number], systemMemo?: any): string {
2007
+ function messageFingerprint(message: Context["messages"][number], systemMemo?: FingerprintMemo): string {
1978
2008
  let value: unknown;
1979
2009
  if (message.role === "user") {
1980
2010
  value = { role: message.role, content: message.content };
@@ -24,13 +24,13 @@ export class PiEventWriter {
24
24
  return this.terminal;
25
25
  }
26
26
 
27
- constructor(model: Model<Api>) {
27
+ constructor(model: Pick<Model<Api>, "id"> & Partial<Pick<Model<Api>, "api" | "provider">>) {
28
28
  this.stream = createAssistantMessageEventStream();
29
29
  this.message = {
30
30
  role: "assistant",
31
31
  content: [],
32
- api: model.api,
33
- provider: model.provider,
32
+ api: model.api ?? "antigravity-acp",
33
+ provider: model.provider ?? "antigravity-acp",
34
34
  model: model.id,
35
35
  usage: emptyUsage(),
36
36
  stopReason: "pending",
@@ -21,9 +21,17 @@ const BODY_LIMIT = 1024 * 1024;
21
21
  const MAX_TOOLS = 64;
22
22
  export const OMP_TASK_TOOL_NAME = "task";
23
23
 
24
+ export interface ToolProjectionInput {
25
+ name: string;
26
+ description?: string;
27
+ parameters?: unknown;
28
+ }
29
+
24
30
  const CONTEXT_CONTROL_TOOLS = new Set(["context_notes", "new_context"]);
25
31
 
26
- export function bridgeExecutionSchema(tool: Pick<Tool, "name" | "parameters">): Tool["parameters"] {
32
+ export function bridgeExecutionSchema(tool: Pick<Tool, "name" | "parameters">): Tool["parameters"];
33
+ export function bridgeExecutionSchema(tool: ToolProjectionInput): unknown;
34
+ export function bridgeExecutionSchema(tool: ToolProjectionInput): unknown {
27
35
  const parameters = tool.parameters;
28
36
  if (!CONTEXT_CONTROL_TOOLS.has(tool.name) || parameters === null || typeof parameters !== "object" || Array.isArray(parameters)) {
29
37
  return parameters;
@@ -49,7 +57,7 @@ export function bridgeExecutionSchema(tool: Pick<Tool, "name" | "parameters">):
49
57
  }
50
58
  // These two native tools receive OMP's injected intent as call metadata,
51
59
  // not as an execute argument. Keep the property and supplied value intact.
52
- return { ...schema, required: required.filter(key => key !== "i") } as Tool["parameters"];
60
+ return { ...schema, required: required.filter(key => key !== "i") };
53
61
  }
54
62
 
55
63
  interface BridgeTool {
@@ -86,13 +94,13 @@ function projectionFingerprint(tools: BridgeTool[], omissions: ToolOmission[]):
86
94
  return JSON.stringify([tools.map((tool) => [tool.mcpName, tool.description, tool.inputSchema]), omissions]);
87
95
  }
88
96
 
89
- export function planToolProjection(tools: readonly Tool[]): ToolOmission[] {
97
+ export function planToolProjection(tools: readonly ToolProjectionInput[]): ToolOmission[] {
90
98
  const omissions: ToolOmission[] = [];
91
99
  projectTools(tools, omissions);
92
100
  return omissions;
93
101
  }
94
102
 
95
- export function planProjectedToolNames(tools: readonly Tool[]): readonly string[] {
103
+ export function planProjectedToolNames(tools: readonly ToolProjectionInput[]): readonly string[] {
96
104
  return projectTools(tools, []).map(tool => tool.piName);
97
105
  }
98
106
 
@@ -235,7 +243,9 @@ export class PiMcpBridge {
235
243
  }
236
244
  }
237
245
 
238
- function projectTool(tool: Tool, names: Set<string>): BridgeTool | ToolOmission {
246
+ function projectTool(tool: Tool, names: Set<string>): BridgeTool | ToolOmission;
247
+ function projectTool(tool: ToolProjectionInput, names: Set<string>): (Omit<BridgeTool, "originalSchema"> & { originalSchema: unknown }) | ToolOmission;
248
+ function projectTool(tool: ToolProjectionInput, names: Set<string>): (Omit<BridgeTool, "originalSchema"> & { originalSchema: unknown }) | ToolOmission {
239
249
  const mcpName = projectedMcpName(tool.name);
240
250
  if (!mcpName || names.has(mcpName)) {
241
251
  return { name: tool.name, reason: "duplicate or invalid projected name" };
@@ -249,7 +259,7 @@ function projectTool(tool: Tool, names: Set<string>): BridgeTool | ToolOmission
249
259
  return {
250
260
  mcpName,
251
261
  piName: tool.name,
252
- description: tool.description,
262
+ description: tool.description ?? "",
253
263
  inputSchema: projected.schema,
254
264
  originalSchema,
255
265
  };
@@ -258,8 +268,10 @@ function projectTool(tool: Tool, names: Set<string>): BridgeTool | ToolOmission
258
268
  // Keep the first 64 projectable tools in OMP's input order. When `task` would
259
269
  // fall beyond that boundary, hold one slot open so the delegated-work
260
270
  // declaration survives without moving any retained tool.
261
- function projectTools(tools: readonly Tool[], omissions: ToolOmission[]): BridgeTool[] {
262
- const selected = new Map<number, BridgeTool>();
271
+ function projectTools(tools: readonly Tool[], omissions: ToolOmission[]): BridgeTool[];
272
+ function projectTools(tools: readonly ToolProjectionInput[], omissions: ToolOmission[]): Array<Omit<BridgeTool, "originalSchema"> & { originalSchema: unknown }>;
273
+ function projectTools(tools: readonly ToolProjectionInput[], omissions: ToolOmission[]): Array<Omit<BridgeTool, "originalSchema"> & { originalSchema: unknown }> {
274
+ const selected = new Map<number, Omit<BridgeTool, "originalSchema"> & { originalSchema: unknown }>();
263
275
  const rejected = new Map<number, string>();
264
276
  const limitSkipped = new Set<number>();
265
277
  const names = new Set<string>();
@@ -143,7 +143,7 @@ export class ToolRelay {
143
143
  () => this.settle(record, relayError("The original tool call failed before returning a result")),
144
144
  );
145
145
  const outcome = await this.wait(Promise.race([promise, record.cancellation]), this.config.thresholdMs);
146
- if (record.state === "cancelled") return record.result ?? relayError("The original tool call returned no result");
146
+ if (this.records.get(callId)?.state === "cancelled") return record.result ?? relayError("The original tool call returned no result");
147
147
  if (outcome.timedOut) {
148
148
  if (record.state === "pending") record.state = "relayed";
149
149
  return relayNoticeResult(callId);
@@ -161,7 +161,7 @@ export class ToolRelay {
161
161
  return record.result ?? relayError("The original tool call has no result");
162
162
  }
163
163
  const outcome = await this.wait(Promise.race([record.promise, record.cancellation]), this.config.thresholdMs);
164
- if (record.state === "cancelled") return record.result ?? relayError("The original tool call returned no result");
164
+ if (this.records.get(callId)?.state === "cancelled") return record.result ?? relayError("The original tool call returned no result");
165
165
  if (outcome.timedOut) {
166
166
  if (record.state === "pending") record.state = "relayed";
167
167
  return relayNoticeResult(callId);
@@ -0,0 +1 @@
1
+ export { Open } from "unzipper";
@@ -0,0 +1 @@
1
+ export * from "./runtime/index.ts";