@benjamolina/pi-antigravity-guard 0.4.7 → 0.4.8

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/context.js CHANGED
@@ -26,12 +26,15 @@ export function serializeContext(input, injectedSelection, onDiagnostics) {
26
26
  const { toolChoice: _choice, ...textOptions } = isRecord(options) ? options : {};
27
27
  const text = serializeTextContext({ ...input, context: { ...textContext, messages: [{ role: "user", content: "placeholder", timestamp: 0 }] }, options: textOptions });
28
28
  const sameModel = (message) => field(message, "role") === "assistant" && entry.replay.kind === "same-public-model" && isSameProviderAndModel(message, entry.publicId);
29
- const signedToolReplay = geminiRequiresSignedToolReplay(selection.route.wireModel) ? {
30
- requireSignedToolCalls: true,
29
+ const requireSigned = geminiRequiresSignedToolReplay(selection.route.wireModel);
30
+ const includeToolCallId = entry.response.family === "claude" || entry.response.family === "gpt-oss";
31
+ const toolReplayPolicy = (requireSigned || includeToolCallId) ? {
32
+ requireSignedToolCalls: requireSigned,
31
33
  isSameModel: sameModel,
32
34
  toolCallSignature: (part, message) => sameModel(message) ? validThoughtSignature(field(part, "thoughtSignature")) : undefined,
35
+ includeToolCallId,
33
36
  } : undefined;
34
- const contents = replayToolHistory(isDenseArray(messages), (part, message) => messagePart(part, field(message, "role") === "assistant", sameModel(message)), onDiagnostics, signedToolReplay, prepared?.declarations.length ?? 0);
37
+ const contents = replayToolHistory(isDenseArray(messages), (part, message) => messagePart(part, field(message, "role") === "assistant", sameModel(message)), onDiagnostics, toolReplayPolicy, prepared?.declarations.length ?? 0);
35
38
  const { systemInstruction, generationConfig } = text.request;
36
39
  return { ...text, request: {
37
40
  contents,
@@ -20,10 +20,12 @@ export interface ToolReplayDiagnostics {
20
20
  readonly assistantToolCallBlockCount: number;
21
21
  readonly declaredToolCount: number;
22
22
  }
23
+ export declare function sanitizeToolCallId(id: string, fallbackName?: string): string;
23
24
  export interface ToolReplayPolicy {
24
25
  readonly requireSignedToolCalls: boolean;
25
26
  readonly isSameModel: (message: Record<string, unknown>) => boolean;
26
27
  readonly toolCallSignature: (part: Record<string, unknown>, message: Record<string, unknown>) => string | undefined;
28
+ readonly includeToolCallId?: boolean;
27
29
  }
28
30
  export declare function replayToolHistory(messages: unknown[], serializePart: (part: Record<string, unknown>, message: Record<string, unknown>) => WirePart, onDiagnostics?: (diagnostics: ToolReplayDiagnostics) => void, policy?: ToolReplayPolicy, declaredToolCount?: number): WireContent[];
29
31
  export {};
@@ -32,6 +32,12 @@ export function prepareToolContext(tools, choice, schemaProfile) {
32
32
  unsupportedChoice();
33
33
  return { declarations, mode: choice === "none" ? "NONE" : "AUTO" };
34
34
  }
35
+ let toolCallCounter = 0;
36
+ export function sanitizeToolCallId(id, fallbackName) {
37
+ const cleaned = id.replace(/[^a-zA-Z0-9_-]/g, "_");
38
+ const capped = cleaned.slice(0, 64);
39
+ return capped || `${fallbackName || "tool"}_${++toolCallCounter}`;
40
+ }
35
41
  export function replayToolHistory(messages, serializePart, onDiagnostics, policy, declaredToolCount = 0) {
36
42
  const output = [];
37
43
  const calls = new Set();
@@ -63,7 +69,7 @@ export function replayToolHistory(messages, serializePart, onDiagnostics, policy
63
69
  if (actual)
64
70
  return actual;
65
71
  recoveryCount.value += 1;
66
- return pending.observations ? observation(call, missingResultText()) : missingResult(call);
72
+ return pending.observations ? observation(call, missingResultText()) : missingResult(call, policy?.includeToolCallId);
67
73
  });
68
74
  if (pending.extraParts?.length) {
69
75
  turnParts.push(...pending.extraParts);
@@ -109,7 +115,7 @@ export function replayToolHistory(messages, serializePart, onDiagnostics, policy
109
115
  const text = textParts.join("\n\n");
110
116
  const outputText = text || (imageParts.length > 0 ? "[Image content]" : "");
111
117
  const response = value(current, "isError") === true ? { error: outputText } : { output: outputText };
112
- pending.results.set(id, pending.observations ? observation(call, outputText) : { functionResponse: { name: call.name, response } });
118
+ pending.results.set(id, pending.observations ? observation(call, outputText) : { functionResponse: { ...(policy?.includeToolCallId ? { id: sanitizeToolCallId(call.id, call.name) } : {}), name: call.name, response } });
113
119
  if (imageParts.length > 0) {
114
120
  if (!pending.extraParts)
115
121
  pending.extraParts = [];
@@ -174,7 +180,7 @@ export function replayToolHistory(messages, serializePart, onDiagnostics, policy
174
180
  return [part];
175
181
  if (observations)
176
182
  return [];
177
- return [{ functionCall: { name: part.call.name, args: part.call.args }, ...(part.signature ? { thoughtSignature: part.signature } : {}) }];
183
+ return [{ functionCall: { ...(policy?.includeToolCallId ? { id: sanitizeToolCallId(part.call.id, part.call.name) } : {}), name: part.call.name, args: part.call.args }, ...(part.signature ? { thoughtSignature: part.signature } : {}) }];
178
184
  }));
179
185
  pending = { calls: group, results: new Map(), observations };
180
186
  }
@@ -190,9 +196,10 @@ function observation(call, text) {
190
196
  function missingResultText() {
191
197
  return "Tool execution did not complete or its result was not recorded. Treat the call as failed; do not assume it had no side effects and do not retry it automatically.";
192
198
  }
193
- function missingResult(call) {
199
+ function missingResult(call, includeToolCallId) {
194
200
  return {
195
201
  functionResponse: {
202
+ ...(includeToolCallId ? { id: sanitizeToolCallId(call.id, call.name) } : {}),
196
203
  name: call.name,
197
204
  response: {
198
205
  error: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@benjamolina/pi-antigravity-guard",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
4
4
  "description": "Pi adapter for Antigravity Guard",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -24,7 +24,9 @@
24
24
  "README.md"
25
25
  ],
26
26
  "pi": {
27
- "extensions": ["./dist/extension.js"]
27
+ "extensions": [
28
+ "./dist/extension.js"
29
+ ]
28
30
  },
29
31
  "dependencies": {
30
32
  "@benjamolina/antigravity-guard-core": "0.1.0"