copilot-api-plus 1.0.27 → 1.0.28

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 CHANGED
@@ -1312,7 +1312,10 @@ function convertMessages$1(messages) {
1312
1312
  * Build system instruction from content
1313
1313
  */
1314
1314
  function buildSystemInstruction(content) {
1315
- return { parts: [{ text: typeof content === "string" ? content : content.map((c) => c.text || "").join("") }] };
1315
+ return {
1316
+ role: "system",
1317
+ parts: [{ text: typeof content === "string" ? content : content.map((c) => c.text || "").join("") }]
1318
+ };
1316
1319
  }
1317
1320
  /**
1318
1321
  * Build message parts from content
@@ -1343,6 +1346,7 @@ function parseBase64Image(url) {
1343
1346
  * Clean and convert JSON schema to Gemini format
1344
1347
  * - Removes unsupported fields like $schema, additionalProperties
1345
1348
  * - Converts type values to uppercase (string -> STRING)
1349
+ * - Ensures properties format is correct for Google API
1346
1350
  */
1347
1351
  function cleanJsonSchema$1(schema) {
1348
1352
  if (!schema || typeof schema !== "object") return schema;
@@ -1363,12 +1367,31 @@ function cleanJsonSchema$1(schema) {
1363
1367
  "minimum",
1364
1368
  "maximum",
1365
1369
  "pattern",
1366
- "format"
1370
+ "format",
1371
+ "const",
1372
+ "allOf",
1373
+ "anyOf",
1374
+ "oneOf",
1375
+ "not"
1376
+ ]);
1377
+ const allowedFields = new Set([
1378
+ "type",
1379
+ "description",
1380
+ "properties",
1381
+ "required",
1382
+ "items",
1383
+ "enum"
1367
1384
  ]);
1368
1385
  for (const [key, value] of Object.entries(obj)) {
1369
1386
  if (unsupportedFields.has(key)) continue;
1387
+ if (!allowedFields.has(key)) continue;
1370
1388
  if (key === "type" && typeof value === "string") cleaned[key] = value.toUpperCase();
1371
- else if (typeof value === "object" && value !== null) cleaned[key] = cleanJsonSchema$1(value);
1389
+ else if (key === "properties" && typeof value === "object" && value !== null) {
1390
+ const props = value;
1391
+ const cleanedProps = {};
1392
+ for (const [propKey, propValue] of Object.entries(props)) cleanedProps[propKey] = cleanJsonSchema$1(propValue);
1393
+ cleaned[key] = cleanedProps;
1394
+ } else if (typeof value === "object" && value !== null) cleaned[key] = cleanJsonSchema$1(value);
1372
1395
  else cleaned[key] = value;
1373
1396
  }
1374
1397
  return cleaned;
@@ -1855,7 +1878,10 @@ const ANTIGRAVITY_USER_AGENT = "antigravity/1.11.3 windows/amd64";
1855
1878
  function convertMessages(messages, system) {
1856
1879
  const contents = [];
1857
1880
  let systemInstruction;
1858
- if (system) systemInstruction = { parts: [{ text: system }] };
1881
+ if (system) systemInstruction = {
1882
+ role: "system",
1883
+ parts: [{ text: system }]
1884
+ };
1859
1885
  for (const message of messages) {
1860
1886
  const role = message.role === "assistant" ? "model" : "user";
1861
1887
  const parts = buildParts(message.content);
@@ -1886,6 +1912,7 @@ function buildParts(content) {
1886
1912
  * Clean and convert JSON schema to Gemini format
1887
1913
  * - Removes unsupported fields like $schema, additionalProperties
1888
1914
  * - Converts type values to uppercase (string -> STRING)
1915
+ * - Ensures properties format is correct for Google API
1889
1916
  */
1890
1917
  function cleanJsonSchema(schema) {
1891
1918
  if (!schema || typeof schema !== "object") return schema;
@@ -1906,12 +1933,31 @@ function cleanJsonSchema(schema) {
1906
1933
  "minimum",
1907
1934
  "maximum",
1908
1935
  "pattern",
1909
- "format"
1936
+ "format",
1937
+ "const",
1938
+ "allOf",
1939
+ "anyOf",
1940
+ "oneOf",
1941
+ "not"
1942
+ ]);
1943
+ const allowedFields = new Set([
1944
+ "type",
1945
+ "description",
1946
+ "properties",
1947
+ "required",
1948
+ "items",
1949
+ "enum"
1910
1950
  ]);
1911
1951
  for (const [key, value] of Object.entries(obj)) {
1912
1952
  if (unsupportedFields.has(key)) continue;
1953
+ if (!allowedFields.has(key)) continue;
1913
1954
  if (key === "type" && typeof value === "string") cleaned[key] = value.toUpperCase();
1914
- else if (typeof value === "object" && value !== null) cleaned[key] = cleanJsonSchema(value);
1955
+ else if (key === "properties" && typeof value === "object" && value !== null) {
1956
+ const props = value;
1957
+ const cleanedProps = {};
1958
+ for (const [propKey, propValue] of Object.entries(props)) cleanedProps[propKey] = cleanJsonSchema(propValue);
1959
+ cleaned[key] = cleanedProps;
1960
+ } else if (typeof value === "object" && value !== null) cleaned[key] = cleanJsonSchema(value);
1915
1961
  else cleaned[key] = value;
1916
1962
  }
1917
1963
  return cleaned;