purra-openai 0.5.0 → 0.5.1
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/structured.d.ts +2 -0
- package/dist/structured.js +49 -0
- package/package.json +2 -2
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { StructuredOutputError } from "purra";
|
|
2
|
+
const allowed = new Set(["type", "properties", "required", "additionalProperties", "items", "enum", "description", "title"]);
|
|
3
|
+
export function validateOutput(request, capabilities) {
|
|
4
|
+
const output = request.outputContract;
|
|
5
|
+
if (output === undefined || output.mode === "local")
|
|
6
|
+
return undefined;
|
|
7
|
+
function reject() { throw new StructuredOutputError("structured_output_mode_unsupported", "nativeDialect"); }
|
|
8
|
+
if (request.tools.length || capabilities.protocol.jsonSchemaLevel !== "json_schema"
|
|
9
|
+
|| request.capabilitySnapshot?.protocol.jsonSchemaLevel !== "json_schema")
|
|
10
|
+
reject();
|
|
11
|
+
let enumCount = 0, propertyCount = 0;
|
|
12
|
+
function visit(node, depth) {
|
|
13
|
+
if (depth > 8 || Object.keys(node).some(key => !allowed.has(key)))
|
|
14
|
+
reject();
|
|
15
|
+
let kind = node.type;
|
|
16
|
+
if (typeof kind !== "string") {
|
|
17
|
+
if (!Array.isArray(kind) || kind.length !== 2 || !kind.includes("null"))
|
|
18
|
+
reject();
|
|
19
|
+
kind = kind.find(t => t !== "null");
|
|
20
|
+
}
|
|
21
|
+
if (kind === "object") {
|
|
22
|
+
const props = (node.properties ?? {});
|
|
23
|
+
propertyCount += Object.keys(props).length;
|
|
24
|
+
const required = (node.required ?? []);
|
|
25
|
+
if (propertyCount > 100 || node.additionalProperties !== false || !Array.isArray(required)
|
|
26
|
+
|| required.length !== Object.keys(props).length
|
|
27
|
+
|| Object.keys(props).some(key => !required.includes(key)))
|
|
28
|
+
reject();
|
|
29
|
+
for (const child of Object.values(props))
|
|
30
|
+
visit(child, depth + 1);
|
|
31
|
+
}
|
|
32
|
+
else if (["properties", "required", "additionalProperties"].some(key => key in node))
|
|
33
|
+
reject();
|
|
34
|
+
if (kind === "array") {
|
|
35
|
+
if (!node.items || typeof node.items !== "object" || Array.isArray(node.items))
|
|
36
|
+
reject();
|
|
37
|
+
visit(node.items, depth + 1);
|
|
38
|
+
}
|
|
39
|
+
else if ("items" in node)
|
|
40
|
+
reject();
|
|
41
|
+
if (Array.isArray(node.enum)) {
|
|
42
|
+
enumCount += node.enum.length;
|
|
43
|
+
if (enumCount > 100 || node.enum.some(v => v !== null && typeof v === "object"))
|
|
44
|
+
reject();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
visit(output.schema, 0);
|
|
48
|
+
return "purra.openai-json-schema/v1";
|
|
49
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "purra-openai",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Official OpenAI Responses and Chat Completions SDK adapter for PurrA",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"openai": "7.9.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"purra": "0.5.
|
|
23
|
+
"purra": "0.5.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"purra": "file:../../../typescript",
|