opencode-antigravity-auth 1.0.1 → 1.0.2
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 +1 -1
- package/package.json +1 -1
- package/src/plugin/request.ts +113 -35
package/README.md
CHANGED
package/package.json
CHANGED
package/src/plugin/request.ts
CHANGED
|
@@ -160,41 +160,86 @@ export function prepareAntigravityRequest(
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
// Normalize tools. For Claude models,
|
|
163
|
+
// Normalize tools. For Claude models, keep full function declarations (names + schemas).
|
|
164
164
|
if (Array.isArray(requestPayload.tools)) {
|
|
165
165
|
if (isClaudeModel) {
|
|
166
|
-
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
166
|
+
const functionDeclarations: any[] = [];
|
|
167
|
+
const passthroughTools: any[] = [];
|
|
168
|
+
|
|
169
|
+
const normalizeSchema = (schema: any) => {
|
|
170
|
+
if (schema && typeof schema === "object") {
|
|
171
|
+
return schema;
|
|
172
|
+
}
|
|
173
|
+
toolDebugMissing += 1;
|
|
174
|
+
return { type: "object", properties: {} };
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
requestPayload.tools.forEach((tool: any, idx: number) => {
|
|
178
|
+
const pushDeclaration = (decl: any, source: string) => {
|
|
179
|
+
const schema =
|
|
180
|
+
decl?.parameters ||
|
|
181
|
+
decl?.input_schema ||
|
|
182
|
+
decl?.inputSchema ||
|
|
183
|
+
tool.parameters ||
|
|
184
|
+
tool.input_schema ||
|
|
185
|
+
tool.inputSchema ||
|
|
186
|
+
tool.function?.parameters ||
|
|
187
|
+
tool.function?.input_schema ||
|
|
188
|
+
tool.function?.inputSchema ||
|
|
189
|
+
tool.custom?.parameters ||
|
|
190
|
+
tool.custom?.input_schema;
|
|
191
|
+
|
|
192
|
+
const name =
|
|
193
|
+
decl?.name ||
|
|
194
|
+
tool.name ||
|
|
195
|
+
tool.function?.name ||
|
|
196
|
+
tool.custom?.name ||
|
|
197
|
+
`tool-${functionDeclarations.length}`;
|
|
198
|
+
|
|
199
|
+
const description =
|
|
200
|
+
decl?.description ||
|
|
201
|
+
tool.description ||
|
|
202
|
+
tool.function?.description ||
|
|
203
|
+
tool.custom?.description ||
|
|
204
|
+
"";
|
|
205
|
+
|
|
206
|
+
functionDeclarations.push({
|
|
207
|
+
name,
|
|
208
|
+
description,
|
|
209
|
+
parameters: normalizeSchema(schema),
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
toolDebugSummaries.push(
|
|
213
|
+
`decl=${name},src=${source},hasSchema=${schema ? "y" : "n"}`,
|
|
214
|
+
);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
if (Array.isArray(tool.functionDeclarations) && tool.functionDeclarations.length > 0) {
|
|
218
|
+
tool.functionDeclarations.forEach((decl: any) => pushDeclaration(decl, "functionDeclarations"));
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Fall back to function/custom style definitions.
|
|
223
|
+
if (
|
|
224
|
+
tool.function ||
|
|
225
|
+
tool.custom ||
|
|
172
226
|
tool.parameters ||
|
|
173
227
|
tool.input_schema ||
|
|
174
|
-
tool.inputSchema
|
|
175
|
-
|
|
176
|
-
tool.custom
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
`tool-${idx}`;
|
|
183
|
-
const description =
|
|
184
|
-
tool.description || tool.function?.description || tool.custom?.description || "";
|
|
185
|
-
|
|
186
|
-
return {
|
|
187
|
-
functionDeclarations: [
|
|
188
|
-
{
|
|
189
|
-
name,
|
|
190
|
-
description,
|
|
191
|
-
parameters: schema,
|
|
192
|
-
},
|
|
193
|
-
],
|
|
194
|
-
};
|
|
228
|
+
tool.inputSchema
|
|
229
|
+
) {
|
|
230
|
+
pushDeclaration(tool.function ?? tool.custom ?? tool, "function/custom");
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Preserve any non-function tool entries (e.g., codeExecution) untouched.
|
|
235
|
+
passthroughTools.push(tool);
|
|
195
236
|
});
|
|
196
237
|
|
|
197
|
-
|
|
238
|
+
const finalTools: any[] = [];
|
|
239
|
+
if (functionDeclarations.length > 0) {
|
|
240
|
+
finalTools.push({ functionDeclarations });
|
|
241
|
+
}
|
|
242
|
+
requestPayload.tools = finalTools.concat(passthroughTools);
|
|
198
243
|
} else {
|
|
199
244
|
// Default normalization for non-Claude models
|
|
200
245
|
requestPayload.tools = requestPayload.tools.map((tool: any, toolIndex: number) => {
|
|
@@ -263,6 +308,45 @@ export function prepareAntigravityRequest(
|
|
|
263
308
|
}
|
|
264
309
|
}
|
|
265
310
|
|
|
311
|
+
// For Claude models, ensure functionCall/tool use parts carry IDs (required by Anthropic).
|
|
312
|
+
if (isClaudeModel && Array.isArray(requestPayload.contents)) {
|
|
313
|
+
let toolCallCounter = 0;
|
|
314
|
+
const lastCallIdByName = new Map<string, string>();
|
|
315
|
+
|
|
316
|
+
requestPayload.contents = requestPayload.contents.map((content: any) => {
|
|
317
|
+
if (!content || !Array.isArray(content.parts)) {
|
|
318
|
+
return content;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const newParts = content.parts.map((part: any) => {
|
|
322
|
+
if (part && typeof part === "object" && part.functionCall) {
|
|
323
|
+
const call = { ...part.functionCall };
|
|
324
|
+
if (!call.id) {
|
|
325
|
+
call.id = `tool-call-${++toolCallCounter}`;
|
|
326
|
+
}
|
|
327
|
+
const nameKey = typeof call.name === "string" ? call.name : `tool-${toolCallCounter}`;
|
|
328
|
+
lastCallIdByName.set(nameKey, call.id);
|
|
329
|
+
return { ...part, functionCall: call };
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (part && typeof part === "object" && part.functionResponse) {
|
|
333
|
+
const resp = { ...part.functionResponse };
|
|
334
|
+
if (!resp.id && typeof resp.name === "string") {
|
|
335
|
+
const linkedId = lastCallIdByName.get(resp.name);
|
|
336
|
+
if (linkedId) {
|
|
337
|
+
resp.id = linkedId;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return { ...part, functionResponse: resp };
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return part;
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
return { ...content, parts: newParts };
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
|
|
266
350
|
if ("model" in requestPayload) {
|
|
267
351
|
delete requestPayload.model;
|
|
268
352
|
}
|
|
@@ -286,12 +370,6 @@ export function prepareAntigravityRequest(
|
|
|
286
370
|
}
|
|
287
371
|
|
|
288
372
|
body = JSON.stringify(wrappedBody);
|
|
289
|
-
|
|
290
|
-
if (wrappedBody.request && typeof wrappedBody.request === 'object') {
|
|
291
|
-
(wrappedBody.request as any).sessionId = "-" + Math.floor(Math.random() * 9000000000000000000).toString();
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
body = JSON.stringify(wrappedBody);
|
|
295
373
|
}
|
|
296
374
|
} catch (error) {
|
|
297
375
|
throw error;
|