@jaypie/llm 1.2.24 → 1.2.25
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/cjs/index.cjs +60 -10
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/providers/gemini/types.d.ts +1 -0
- package/dist/cjs/util/index.d.ts +1 -0
- package/dist/cjs/util/jsonSchemaToOpenApi3.d.ts +10 -0
- package/dist/esm/index.js +60 -10
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/providers/gemini/types.d.ts +1 -0
- package/dist/esm/util/index.d.ts +1 -0
- package/dist/esm/util/jsonSchemaToOpenApi3.d.ts +10 -0
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -554,6 +554,50 @@ function formatOperateInput(input, options) {
|
|
|
554
554
|
return [input];
|
|
555
555
|
}
|
|
556
556
|
|
|
557
|
+
/**
|
|
558
|
+
* Converts a JSON Schema (Draft 2020-12) object to the OpenAPI 3.0 schema subset
|
|
559
|
+
* that Gemini's `responseSchema` accepts. This constrains generation (not just validation)
|
|
560
|
+
* and avoids the `items`-keyword leakage bug in `responseJsonSchema`.
|
|
561
|
+
*
|
|
562
|
+
* Strips: $schema, additionalProperties, $defs, $ref (inlines where possible), const
|
|
563
|
+
* Preserves: type, properties, required, items, enum, description, nullable
|
|
564
|
+
*/
|
|
565
|
+
function jsonSchemaToOpenApi3(schema) {
|
|
566
|
+
if (typeof schema !== "object" || schema === null || Array.isArray(schema)) {
|
|
567
|
+
return schema;
|
|
568
|
+
}
|
|
569
|
+
const result = {};
|
|
570
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
571
|
+
// Strip JSON Schema keywords not in OpenAPI 3.0 subset
|
|
572
|
+
if (key === "$schema" ||
|
|
573
|
+
key === "$defs" ||
|
|
574
|
+
key === "additionalProperties" ||
|
|
575
|
+
key === "const" ||
|
|
576
|
+
key === "$ref") {
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
if (key === "properties" &&
|
|
580
|
+
typeof value === "object" &&
|
|
581
|
+
value !== null &&
|
|
582
|
+
!Array.isArray(value)) {
|
|
583
|
+
const convertedProps = {};
|
|
584
|
+
for (const [propKey, propValue] of Object.entries(value)) {
|
|
585
|
+
convertedProps[propKey] = jsonSchemaToOpenApi3(propValue);
|
|
586
|
+
}
|
|
587
|
+
result[key] = convertedProps;
|
|
588
|
+
}
|
|
589
|
+
else if (key === "items" &&
|
|
590
|
+
typeof value === "object" &&
|
|
591
|
+
value !== null) {
|
|
592
|
+
result[key] = jsonSchemaToOpenApi3(value);
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
result[key] = value;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
return result;
|
|
599
|
+
}
|
|
600
|
+
|
|
557
601
|
const getLogger$5 = () => log$1.log.lib({ lib: kit.JAYPIE.LIB.LLM });
|
|
558
602
|
|
|
559
603
|
// Turn policy constants
|
|
@@ -1540,11 +1584,21 @@ class GeminiAdapter extends BaseProviderAdapter {
|
|
|
1540
1584
|
// Gemini doesn't support combining function calling with responseMimeType: 'application/json'
|
|
1541
1585
|
// When tools are present, structured output is handled via the structured_output tool
|
|
1542
1586
|
if (request.format && !(request.tools && request.tools.length > 0)) {
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1587
|
+
const useJsonSchema = request.providerOptions?.useJsonSchema === true;
|
|
1588
|
+
if (useJsonSchema) {
|
|
1589
|
+
geminiRequest.config = {
|
|
1590
|
+
...geminiRequest.config,
|
|
1591
|
+
responseMimeType: "application/json",
|
|
1592
|
+
responseJsonSchema: request.format,
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1595
|
+
else {
|
|
1596
|
+
geminiRequest.config = {
|
|
1597
|
+
...geminiRequest.config,
|
|
1598
|
+
responseMimeType: "application/json",
|
|
1599
|
+
responseSchema: jsonSchemaToOpenApi3(request.format),
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1548
1602
|
}
|
|
1549
1603
|
// When format is specified with tools, add instruction to use structured_output tool
|
|
1550
1604
|
if (request.format && request.tools && request.tools.length > 0) {
|
|
@@ -1612,11 +1666,7 @@ class GeminiAdapter extends BaseProviderAdapter {
|
|
|
1612
1666
|
: naturalZodSchema(schema);
|
|
1613
1667
|
jsonSchema = v4.z.toJSONSchema(zodSchema);
|
|
1614
1668
|
}
|
|
1615
|
-
|
|
1616
|
-
if (jsonSchema.$schema) {
|
|
1617
|
-
delete jsonSchema.$schema;
|
|
1618
|
-
}
|
|
1619
|
-
return jsonSchema;
|
|
1669
|
+
return jsonSchemaToOpenApi3(jsonSchema);
|
|
1620
1670
|
}
|
|
1621
1671
|
//
|
|
1622
1672
|
// API Execution
|