koishi-plugin-chatluna-google-gemini-adapter 1.2.0-alpha.3 → 1.2.0-alpha.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.
package/lib/index.cjs CHANGED
@@ -286,29 +286,27 @@ function formatToolToGeminiAITool(tool) {
286
286
  }
287
287
  __name(formatToolToGeminiAITool, "formatToolToGeminiAITool");
288
288
  function removeAdditionalProperties(schema) {
289
- const updatedSchema = { ...schema };
290
- if (Object.hasOwn(updatedSchema, "additionalProperties")) {
291
- delete updatedSchema["additionalProperties"];
292
- }
293
- if (Object.hasOwn(updatedSchema, "$schema")) {
294
- delete updatedSchema["$schema"];
295
- }
296
- if (updatedSchema["properties"]) {
297
- const keys = Object.keys(updatedSchema["properties"]);
298
- removeProperties(updatedSchema["properties"], keys, 0);
289
+ if (!schema || typeof schema !== "object") return schema;
290
+ const stack = [[schema, null]];
291
+ while (stack.length > 0) {
292
+ const [current] = stack.pop();
293
+ if (typeof current !== "object" || current === null) continue;
294
+ if (Object.hasOwn(current, "additionalProperties")) {
295
+ delete current["additionalProperties"];
296
+ }
297
+ if (Object.hasOwn(current, "$schema")) {
298
+ delete current["$schema"];
299
+ }
300
+ for (const key of Object.keys(current)) {
301
+ const value = current[key];
302
+ if (value && typeof value === "object") {
303
+ stack.push([value, key]);
304
+ }
305
+ }
299
306
  }
300
- return updatedSchema;
307
+ return schema;
301
308
  }
302
309
  __name(removeAdditionalProperties, "removeAdditionalProperties");
303
- function removeProperties(properties, keys, index) {
304
- if (index >= keys.length) {
305
- return;
306
- }
307
- const key = keys[index];
308
- properties[key] = removeAdditionalProperties(properties[key]);
309
- removeProperties(properties, keys, index + 1);
310
- }
311
- __name(removeProperties, "removeProperties");
312
310
  function messageTypeToGeminiRole(type) {
313
311
  switch (type) {
314
312
  case "system":
package/lib/index.mjs CHANGED
@@ -269,29 +269,27 @@ function formatToolToGeminiAITool(tool) {
269
269
  }
270
270
  __name(formatToolToGeminiAITool, "formatToolToGeminiAITool");
271
271
  function removeAdditionalProperties(schema) {
272
- const updatedSchema = { ...schema };
273
- if (Object.hasOwn(updatedSchema, "additionalProperties")) {
274
- delete updatedSchema["additionalProperties"];
275
- }
276
- if (Object.hasOwn(updatedSchema, "$schema")) {
277
- delete updatedSchema["$schema"];
278
- }
279
- if (updatedSchema["properties"]) {
280
- const keys = Object.keys(updatedSchema["properties"]);
281
- removeProperties(updatedSchema["properties"], keys, 0);
272
+ if (!schema || typeof schema !== "object") return schema;
273
+ const stack = [[schema, null]];
274
+ while (stack.length > 0) {
275
+ const [current] = stack.pop();
276
+ if (typeof current !== "object" || current === null) continue;
277
+ if (Object.hasOwn(current, "additionalProperties")) {
278
+ delete current["additionalProperties"];
279
+ }
280
+ if (Object.hasOwn(current, "$schema")) {
281
+ delete current["$schema"];
282
+ }
283
+ for (const key of Object.keys(current)) {
284
+ const value = current[key];
285
+ if (value && typeof value === "object") {
286
+ stack.push([value, key]);
287
+ }
288
+ }
282
289
  }
283
- return updatedSchema;
290
+ return schema;
284
291
  }
285
292
  __name(removeAdditionalProperties, "removeAdditionalProperties");
286
- function removeProperties(properties, keys, index) {
287
- if (index >= keys.length) {
288
- return;
289
- }
290
- const key = keys[index];
291
- properties[key] = removeAdditionalProperties(properties[key]);
292
- removeProperties(properties, keys, index + 1);
293
- }
294
- __name(removeProperties, "removeProperties");
295
293
  function messageTypeToGeminiRole(type) {
296
294
  switch (type) {
297
295
  case "system":
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-chatluna-google-gemini-adapter",
3
3
  "description": "google-gemini adapter for chatluna",
4
- "version": "1.2.0-alpha.3",
4
+ "version": "1.2.0-alpha.4",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.mjs",
7
7
  "typings": "lib/index.d.ts",