copilot-api-plus 1.0.30 → 1.0.31
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/main.js +93 -77
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1339,6 +1339,38 @@ function parseBase64Image(url) {
|
|
|
1339
1339
|
data: match[2]
|
|
1340
1340
|
};
|
|
1341
1341
|
}
|
|
1342
|
+
const GEMINI_ALLOWED_FIELDS$1 = new Set([
|
|
1343
|
+
"type",
|
|
1344
|
+
"description",
|
|
1345
|
+
"properties",
|
|
1346
|
+
"required",
|
|
1347
|
+
"items",
|
|
1348
|
+
"enum",
|
|
1349
|
+
"nullable"
|
|
1350
|
+
]);
|
|
1351
|
+
/**
|
|
1352
|
+
* Convert type value to Gemini format
|
|
1353
|
+
* Handles both string and array types (for nullable)
|
|
1354
|
+
*/
|
|
1355
|
+
function convertTypeValue$1(value) {
|
|
1356
|
+
if (typeof value === "string") return { type: value.toUpperCase() };
|
|
1357
|
+
if (Array.isArray(value)) {
|
|
1358
|
+
const nonNullType = value.find((t) => typeof t === "string" && t !== "null");
|
|
1359
|
+
if (nonNullType) return {
|
|
1360
|
+
type: nonNullType.toUpperCase(),
|
|
1361
|
+
nullable: true
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
return null;
|
|
1365
|
+
}
|
|
1366
|
+
/**
|
|
1367
|
+
* Clean properties object recursively
|
|
1368
|
+
*/
|
|
1369
|
+
function cleanProperties$1(props) {
|
|
1370
|
+
const cleanedProps = {};
|
|
1371
|
+
for (const [propKey, propValue] of Object.entries(props)) cleanedProps[propKey] = cleanJsonSchema$1(propValue);
|
|
1372
|
+
return cleanedProps;
|
|
1373
|
+
}
|
|
1342
1374
|
/**
|
|
1343
1375
|
* Clean and convert JSON schema to Gemini format
|
|
1344
1376
|
* - Removes unsupported fields like $schema, additionalProperties
|
|
@@ -1350,45 +1382,16 @@ function cleanJsonSchema$1(schema) {
|
|
|
1350
1382
|
if (Array.isArray(schema)) return schema.map((item) => cleanJsonSchema$1(item));
|
|
1351
1383
|
const obj = schema;
|
|
1352
1384
|
const cleaned = {};
|
|
1353
|
-
const unsupportedFields = new Set([
|
|
1354
|
-
"$schema",
|
|
1355
|
-
"$id",
|
|
1356
|
-
"$ref",
|
|
1357
|
-
"additionalProperties",
|
|
1358
|
-
"default",
|
|
1359
|
-
"examples",
|
|
1360
|
-
"minItems",
|
|
1361
|
-
"maxItems",
|
|
1362
|
-
"minLength",
|
|
1363
|
-
"maxLength",
|
|
1364
|
-
"minimum",
|
|
1365
|
-
"maximum",
|
|
1366
|
-
"pattern",
|
|
1367
|
-
"format",
|
|
1368
|
-
"const",
|
|
1369
|
-
"allOf",
|
|
1370
|
-
"anyOf",
|
|
1371
|
-
"oneOf",
|
|
1372
|
-
"not"
|
|
1373
|
-
]);
|
|
1374
|
-
const allowedFields = new Set([
|
|
1375
|
-
"type",
|
|
1376
|
-
"description",
|
|
1377
|
-
"properties",
|
|
1378
|
-
"required",
|
|
1379
|
-
"items",
|
|
1380
|
-
"enum"
|
|
1381
|
-
]);
|
|
1382
1385
|
for (const [key, value] of Object.entries(obj)) {
|
|
1383
|
-
if (
|
|
1384
|
-
if (
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1386
|
+
if (!GEMINI_ALLOWED_FIELDS$1.has(key)) continue;
|
|
1387
|
+
if (key === "type") {
|
|
1388
|
+
const result = convertTypeValue$1(value);
|
|
1389
|
+
if (result) {
|
|
1390
|
+
cleaned.type = result.type;
|
|
1391
|
+
if (result.nullable) cleaned.nullable = true;
|
|
1392
|
+
}
|
|
1393
|
+
} else if (key === "properties" && typeof value === "object" && value) cleaned.properties = cleanProperties$1(value);
|
|
1394
|
+
else if (typeof value === "object" && value !== null) cleaned[key] = cleanJsonSchema$1(value);
|
|
1392
1395
|
else cleaned[key] = value;
|
|
1393
1396
|
}
|
|
1394
1397
|
return cleaned;
|
|
@@ -1870,12 +1873,22 @@ const ANTIGRAVITY_STREAM_URL = `https://${ANTIGRAVITY_API_HOST}/v1internal:strea
|
|
|
1870
1873
|
const ANTIGRAVITY_NO_STREAM_URL = `https://${ANTIGRAVITY_API_HOST}/v1internal:generateContent`;
|
|
1871
1874
|
const ANTIGRAVITY_USER_AGENT = "antigravity/1.11.3 windows/amd64";
|
|
1872
1875
|
/**
|
|
1876
|
+
* Extract text from system content (can be string or array)
|
|
1877
|
+
*/
|
|
1878
|
+
function extractSystemText(system) {
|
|
1879
|
+
if (typeof system === "string") return system;
|
|
1880
|
+
return system.filter((block) => block.type === "text" && block.text).map((block) => block.text).join("\n\n");
|
|
1881
|
+
}
|
|
1882
|
+
/**
|
|
1873
1883
|
* Convert Anthropic messages to Antigravity format
|
|
1874
1884
|
*/
|
|
1875
1885
|
function convertMessages(messages, system) {
|
|
1876
1886
|
const contents = [];
|
|
1877
1887
|
let systemInstruction;
|
|
1878
|
-
if (system)
|
|
1888
|
+
if (system) {
|
|
1889
|
+
const systemText = extractSystemText(system);
|
|
1890
|
+
if (systemText) systemInstruction = { parts: [{ text: systemText }] };
|
|
1891
|
+
}
|
|
1879
1892
|
for (const message of messages) {
|
|
1880
1893
|
const role = message.role === "assistant" ? "model" : "user";
|
|
1881
1894
|
const parts = buildParts(message.content);
|
|
@@ -1902,6 +1915,38 @@ function buildParts(content) {
|
|
|
1902
1915
|
} });
|
|
1903
1916
|
return parts;
|
|
1904
1917
|
}
|
|
1918
|
+
const GEMINI_ALLOWED_FIELDS = new Set([
|
|
1919
|
+
"type",
|
|
1920
|
+
"description",
|
|
1921
|
+
"properties",
|
|
1922
|
+
"required",
|
|
1923
|
+
"items",
|
|
1924
|
+
"enum",
|
|
1925
|
+
"nullable"
|
|
1926
|
+
]);
|
|
1927
|
+
/**
|
|
1928
|
+
* Convert type value to Gemini format
|
|
1929
|
+
* Handles both string and array types (for nullable)
|
|
1930
|
+
*/
|
|
1931
|
+
function convertTypeValue(value) {
|
|
1932
|
+
if (typeof value === "string") return { type: value.toUpperCase() };
|
|
1933
|
+
if (Array.isArray(value)) {
|
|
1934
|
+
const nonNullType = value.find((t) => typeof t === "string" && t !== "null");
|
|
1935
|
+
if (nonNullType) return {
|
|
1936
|
+
type: nonNullType.toUpperCase(),
|
|
1937
|
+
nullable: true
|
|
1938
|
+
};
|
|
1939
|
+
}
|
|
1940
|
+
return null;
|
|
1941
|
+
}
|
|
1942
|
+
/**
|
|
1943
|
+
* Clean properties object recursively
|
|
1944
|
+
*/
|
|
1945
|
+
function cleanProperties(props) {
|
|
1946
|
+
const cleanedProps = {};
|
|
1947
|
+
for (const [propKey, propValue] of Object.entries(props)) cleanedProps[propKey] = cleanJsonSchema(propValue);
|
|
1948
|
+
return cleanedProps;
|
|
1949
|
+
}
|
|
1905
1950
|
/**
|
|
1906
1951
|
* Clean and convert JSON schema to Gemini format
|
|
1907
1952
|
* - Removes unsupported fields like $schema, additionalProperties
|
|
@@ -1913,45 +1958,16 @@ function cleanJsonSchema(schema) {
|
|
|
1913
1958
|
if (Array.isArray(schema)) return schema.map((item) => cleanJsonSchema(item));
|
|
1914
1959
|
const obj = schema;
|
|
1915
1960
|
const cleaned = {};
|
|
1916
|
-
const unsupportedFields = new Set([
|
|
1917
|
-
"$schema",
|
|
1918
|
-
"$id",
|
|
1919
|
-
"$ref",
|
|
1920
|
-
"additionalProperties",
|
|
1921
|
-
"default",
|
|
1922
|
-
"examples",
|
|
1923
|
-
"minItems",
|
|
1924
|
-
"maxItems",
|
|
1925
|
-
"minLength",
|
|
1926
|
-
"maxLength",
|
|
1927
|
-
"minimum",
|
|
1928
|
-
"maximum",
|
|
1929
|
-
"pattern",
|
|
1930
|
-
"format",
|
|
1931
|
-
"const",
|
|
1932
|
-
"allOf",
|
|
1933
|
-
"anyOf",
|
|
1934
|
-
"oneOf",
|
|
1935
|
-
"not"
|
|
1936
|
-
]);
|
|
1937
|
-
const allowedFields = new Set([
|
|
1938
|
-
"type",
|
|
1939
|
-
"description",
|
|
1940
|
-
"properties",
|
|
1941
|
-
"required",
|
|
1942
|
-
"items",
|
|
1943
|
-
"enum"
|
|
1944
|
-
]);
|
|
1945
1961
|
for (const [key, value] of Object.entries(obj)) {
|
|
1946
|
-
if (
|
|
1947
|
-
if (
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1962
|
+
if (!GEMINI_ALLOWED_FIELDS.has(key)) continue;
|
|
1963
|
+
if (key === "type") {
|
|
1964
|
+
const result = convertTypeValue(value);
|
|
1965
|
+
if (result) {
|
|
1966
|
+
cleaned.type = result.type;
|
|
1967
|
+
if (result.nullable) cleaned.nullable = true;
|
|
1968
|
+
}
|
|
1969
|
+
} else if (key === "properties" && typeof value === "object" && value) cleaned.properties = cleanProperties(value);
|
|
1970
|
+
else if (typeof value === "object" && value !== null) cleaned[key] = cleanJsonSchema(value);
|
|
1955
1971
|
else cleaned[key] = value;
|
|
1956
1972
|
}
|
|
1957
1973
|
return cleaned;
|