openai 6.48.0 → 6.49.0

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.
Files changed (159) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/azure.d.mts.map +1 -1
  3. package/azure.d.ts.map +1 -1
  4. package/azure.js +5 -1
  5. package/azure.js.map +1 -1
  6. package/azure.mjs +5 -1
  7. package/azure.mjs.map +1 -1
  8. package/helpers/standard-schema.d.mts +104 -0
  9. package/helpers/standard-schema.d.mts.map +1 -0
  10. package/helpers/standard-schema.d.ts +104 -0
  11. package/helpers/standard-schema.d.ts.map +1 -0
  12. package/helpers/standard-schema.js +320 -0
  13. package/helpers/standard-schema.js.map +1 -0
  14. package/helpers/standard-schema.mjs +314 -0
  15. package/helpers/standard-schema.mjs.map +1 -0
  16. package/helpers/zod.d.mts +26 -3
  17. package/helpers/zod.d.mts.map +1 -1
  18. package/helpers/zod.d.ts +26 -3
  19. package/helpers/zod.d.ts.map +1 -1
  20. package/helpers/zod.js +97 -7
  21. package/helpers/zod.js.map +1 -1
  22. package/helpers/zod.mjs +96 -7
  23. package/helpers/zod.mjs.map +1 -1
  24. package/lib/AbstractChatCompletionRunner.d.mts.map +1 -1
  25. package/lib/AbstractChatCompletionRunner.d.ts.map +1 -1
  26. package/lib/AbstractChatCompletionRunner.js +43 -1
  27. package/lib/AbstractChatCompletionRunner.js.map +1 -1
  28. package/lib/AbstractChatCompletionRunner.mjs +43 -1
  29. package/lib/AbstractChatCompletionRunner.mjs.map +1 -1
  30. package/lib/ChatCompletionStream.d.mts +2 -1
  31. package/lib/ChatCompletionStream.d.mts.map +1 -1
  32. package/lib/ChatCompletionStream.d.ts +2 -1
  33. package/lib/ChatCompletionStream.d.ts.map +1 -1
  34. package/lib/ChatCompletionStream.js +53 -14
  35. package/lib/ChatCompletionStream.js.map +1 -1
  36. package/lib/ChatCompletionStream.mjs +53 -14
  37. package/lib/ChatCompletionStream.mjs.map +1 -1
  38. package/lib/ResponsesParser.d.mts.map +1 -1
  39. package/lib/ResponsesParser.d.ts.map +1 -1
  40. package/lib/ResponsesParser.js +3 -5
  41. package/lib/ResponsesParser.js.map +1 -1
  42. package/lib/ResponsesParser.mjs +3 -5
  43. package/lib/ResponsesParser.mjs.map +1 -1
  44. package/lib/jsonschema.d.mts +3 -0
  45. package/lib/jsonschema.d.mts.map +1 -1
  46. package/lib/jsonschema.d.ts +3 -0
  47. package/lib/jsonschema.d.ts.map +1 -1
  48. package/lib/transform.d.mts +25 -1
  49. package/lib/transform.d.mts.map +1 -1
  50. package/lib/transform.d.ts +25 -1
  51. package/lib/transform.d.ts.map +1 -1
  52. package/lib/transform.js +1521 -82
  53. package/lib/transform.js.map +1 -1
  54. package/lib/transform.mjs +1515 -82
  55. package/lib/transform.mjs.map +1 -1
  56. package/package.json +1 -1
  57. package/resources/admin/organization/index.d.mts +1 -0
  58. package/resources/admin/organization/index.d.mts.map +1 -1
  59. package/resources/admin/organization/index.d.ts +1 -0
  60. package/resources/admin/organization/index.d.ts.map +1 -1
  61. package/resources/admin/organization/index.js +3 -1
  62. package/resources/admin/organization/index.js.map +1 -1
  63. package/resources/admin/organization/index.mjs +1 -0
  64. package/resources/admin/organization/index.mjs.map +1 -1
  65. package/resources/admin/organization/organization.d.mts +4 -0
  66. package/resources/admin/organization/organization.d.mts.map +1 -1
  67. package/resources/admin/organization/organization.d.ts +4 -0
  68. package/resources/admin/organization/organization.d.ts.map +1 -1
  69. package/resources/admin/organization/organization.js +4 -0
  70. package/resources/admin/organization/organization.js.map +1 -1
  71. package/resources/admin/organization/organization.mjs +4 -0
  72. package/resources/admin/organization/organization.mjs.map +1 -1
  73. package/resources/admin/organization/projects/index.d.mts +1 -0
  74. package/resources/admin/organization/projects/index.d.mts.map +1 -1
  75. package/resources/admin/organization/projects/index.d.ts +1 -0
  76. package/resources/admin/organization/projects/index.d.ts.map +1 -1
  77. package/resources/admin/organization/projects/index.js +3 -1
  78. package/resources/admin/organization/projects/index.js.map +1 -1
  79. package/resources/admin/organization/projects/index.mjs +1 -0
  80. package/resources/admin/organization/projects/index.mjs.map +1 -1
  81. package/resources/admin/organization/projects/projects.d.mts +4 -0
  82. package/resources/admin/organization/projects/projects.d.mts.map +1 -1
  83. package/resources/admin/organization/projects/projects.d.ts +4 -0
  84. package/resources/admin/organization/projects/projects.d.ts.map +1 -1
  85. package/resources/admin/organization/projects/projects.js +4 -0
  86. package/resources/admin/organization/projects/projects.js.map +1 -1
  87. package/resources/admin/organization/projects/projects.mjs +4 -0
  88. package/resources/admin/organization/projects/projects.mjs.map +1 -1
  89. package/resources/admin/organization/projects/spend-limit.d.mts +115 -0
  90. package/resources/admin/organization/projects/spend-limit.d.mts.map +1 -0
  91. package/resources/admin/organization/projects/spend-limit.d.ts +115 -0
  92. package/resources/admin/organization/projects/spend-limit.d.ts.map +1 -0
  93. package/resources/admin/organization/projects/spend-limit.js +67 -0
  94. package/resources/admin/organization/projects/spend-limit.js.map +1 -0
  95. package/resources/admin/organization/projects/spend-limit.mjs +63 -0
  96. package/resources/admin/organization/projects/spend-limit.mjs.map +1 -0
  97. package/resources/admin/organization/spend-limit.d.mts +108 -0
  98. package/resources/admin/organization/spend-limit.d.mts.map +1 -0
  99. package/resources/admin/organization/spend-limit.d.ts +108 -0
  100. package/resources/admin/organization/spend-limit.d.ts.map +1 -0
  101. package/resources/admin/organization/spend-limit.js +59 -0
  102. package/resources/admin/organization/spend-limit.js.map +1 -0
  103. package/resources/admin/organization/spend-limit.mjs +55 -0
  104. package/resources/admin/organization/spend-limit.mjs.map +1 -0
  105. package/resources/beta/responses/input-tokens.d.mts +6 -2
  106. package/resources/beta/responses/input-tokens.d.mts.map +1 -1
  107. package/resources/beta/responses/input-tokens.d.ts +6 -2
  108. package/resources/beta/responses/input-tokens.d.ts.map +1 -1
  109. package/resources/beta/responses/responses.d.mts +21 -11
  110. package/resources/beta/responses/responses.d.mts.map +1 -1
  111. package/resources/beta/responses/responses.d.ts +21 -11
  112. package/resources/beta/responses/responses.d.ts.map +1 -1
  113. package/resources/beta/responses/responses.js.map +1 -1
  114. package/resources/beta/responses/responses.mjs.map +1 -1
  115. package/resources/chat/completions/completions.d.mts +4 -3
  116. package/resources/chat/completions/completions.d.mts.map +1 -1
  117. package/resources/chat/completions/completions.d.ts +4 -3
  118. package/resources/chat/completions/completions.d.ts.map +1 -1
  119. package/resources/chat/completions/completions.js.map +1 -1
  120. package/resources/chat/completions/completions.mjs.map +1 -1
  121. package/resources/responses/input-tokens.d.mts +2 -1
  122. package/resources/responses/input-tokens.d.mts.map +1 -1
  123. package/resources/responses/input-tokens.d.ts +2 -1
  124. package/resources/responses/input-tokens.d.ts.map +1 -1
  125. package/resources/responses/responses.d.mts +9 -8
  126. package/resources/responses/responses.d.mts.map +1 -1
  127. package/resources/responses/responses.d.ts +9 -8
  128. package/resources/responses/responses.d.ts.map +1 -1
  129. package/resources/responses/responses.js.map +1 -1
  130. package/resources/responses/responses.mjs.map +1 -1
  131. package/resources/shared.d.mts +4 -1
  132. package/resources/shared.d.mts.map +1 -1
  133. package/resources/shared.d.ts +4 -1
  134. package/resources/shared.d.ts.map +1 -1
  135. package/src/azure.ts +5 -1
  136. package/src/helpers/standard-schema.ts +570 -0
  137. package/src/helpers/zod.ts +158 -29
  138. package/src/lib/AbstractChatCompletionRunner.ts +43 -1
  139. package/src/lib/ChatCompletionStream.ts +56 -8
  140. package/src/lib/ResponsesParser.ts +7 -5
  141. package/src/lib/jsonschema.ts +3 -0
  142. package/src/lib/transform.ts +1930 -103
  143. package/src/resources/admin/organization/index.ts +6 -0
  144. package/src/resources/admin/organization/organization.ts +16 -0
  145. package/src/resources/admin/organization/projects/index.ts +6 -0
  146. package/src/resources/admin/organization/projects/projects.ts +16 -0
  147. package/src/resources/admin/organization/projects/spend-limit.ts +156 -0
  148. package/src/resources/admin/organization/spend-limit.ts +144 -0
  149. package/src/resources/beta/responses/input-tokens.ts +6 -2
  150. package/src/resources/beta/responses/responses.ts +21 -10
  151. package/src/resources/chat/completions/completions.ts +4 -3
  152. package/src/resources/responses/input-tokens.ts +2 -1
  153. package/src/resources/responses/responses.ts +9 -7
  154. package/src/resources/shared.ts +4 -1
  155. package/src/version.ts +1 -1
  156. package/version.d.mts +1 -1
  157. package/version.d.ts +1 -1
  158. package/version.js +1 -1
  159. package/version.mjs +1 -1
@@ -0,0 +1,320 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.standardResponseFormat = standardResponseFormat;
4
+ exports.standardTextFormat = standardTextFormat;
5
+ exports.standardFunction = standardFunction;
6
+ exports.standardResponsesFunction = standardResponsesFunction;
7
+ const error_1 = require("../error.js");
8
+ const parser_1 = require("../lib/parser.js");
9
+ const ResponsesParser_1 = require("../lib/ResponsesParser.js");
10
+ const transform_1 = require("../lib/transform.js");
11
+ function isPromiseLike(value) {
12
+ return typeof value === 'object' && value !== null && 'then' in value && typeof value.then === 'function';
13
+ }
14
+ function formatStandardSchemaIssues(issues) {
15
+ return issues
16
+ .map((issue) => {
17
+ const path = issue.path
18
+ ?.map((segment) => typeof segment === 'object' && segment !== null && 'key' in segment ? segment.key : segment)
19
+ .map(String)
20
+ .join('.');
21
+ return path ? `${path}: ${issue.message}` : issue.message;
22
+ })
23
+ .join('; ');
24
+ }
25
+ const JSON_SCHEMA_TYPES = new Set(['string', 'number', 'integer', 'boolean', 'object', 'array', 'null']);
26
+ function getSchemaTypes(schema) {
27
+ if (!schema || typeof schema !== 'object' || Array.isArray(schema))
28
+ return undefined;
29
+ const type = schema['type'];
30
+ if (type === undefined) {
31
+ return getLiteralSchemaTypes(schema);
32
+ }
33
+ const types = Array.isArray(type) ? type : [type];
34
+ if (types.length === 0 ||
35
+ !types.every((value) => typeof value === 'string' && JSON_SCHEMA_TYPES.has(value))) {
36
+ return undefined;
37
+ }
38
+ return new Set(types);
39
+ }
40
+ function isJSONPrimitive(value) {
41
+ return (value === null ||
42
+ typeof value === 'string' ||
43
+ typeof value === 'boolean' ||
44
+ (typeof value === 'number' && Number.isFinite(value)));
45
+ }
46
+ function getLiteralValues(schema) {
47
+ if (!schema || typeof schema !== 'object' || Array.isArray(schema))
48
+ return undefined;
49
+ const record = schema;
50
+ if ('const' in record && isJSONPrimitive(record['const'])) {
51
+ return [record['const']];
52
+ }
53
+ const enumValues = record['enum'];
54
+ if (Array.isArray(enumValues) && enumValues.length > 0 && enumValues.every(isJSONPrimitive)) {
55
+ return enumValues;
56
+ }
57
+ return undefined;
58
+ }
59
+ function getLiteralSchemaTypes(schema) {
60
+ const literalValues = getLiteralValues(schema);
61
+ if (!literalValues)
62
+ return undefined;
63
+ return new Set(literalValues.map((value) => {
64
+ if (value === null)
65
+ return 'null';
66
+ return typeof value;
67
+ }));
68
+ }
69
+ function haveDisjointLiteralValues(left, right) {
70
+ const leftValues = getLiteralValues(left);
71
+ const rightValues = getLiteralValues(right);
72
+ if (!leftValues || !rightValues)
73
+ return false;
74
+ return leftValues.every((leftValue) => !rightValues.some((rightValue) => leftValue === rightValue));
75
+ }
76
+ function schemaTypesOverlap(left, right) {
77
+ return (left === right || (left === 'integer' && right === 'number') || (left === 'number' && right === 'integer'));
78
+ }
79
+ function isObjectOnlySchema(schema) {
80
+ const types = getSchemaTypes(schema);
81
+ return types?.size === 1 && types.has('object');
82
+ }
83
+ function haveDisjointObjectDiscriminator(left, right, root) {
84
+ if (!isObjectOnlySchema(left) || !isObjectOnlySchema(right))
85
+ return false;
86
+ const leftRecord = left;
87
+ const rightRecord = right;
88
+ const leftProperties = leftRecord['properties'];
89
+ const rightProperties = rightRecord['properties'];
90
+ const leftRequired = leftRecord['required'];
91
+ const rightRequired = rightRecord['required'];
92
+ if (!leftProperties ||
93
+ typeof leftProperties !== 'object' ||
94
+ Array.isArray(leftProperties) ||
95
+ !rightProperties ||
96
+ typeof rightProperties !== 'object' ||
97
+ Array.isArray(rightProperties) ||
98
+ !Array.isArray(leftRequired) ||
99
+ !Array.isArray(rightRequired)) {
100
+ return false;
101
+ }
102
+ for (const property of leftRequired) {
103
+ if (typeof property === 'string' &&
104
+ rightRequired.includes(property) &&
105
+ haveDisjointLiteralValues(resolveLocalRefForExclusivity(leftProperties[property], root), resolveLocalRefForExclusivity(rightProperties[property], root))) {
106
+ return true;
107
+ }
108
+ }
109
+ return false;
110
+ }
111
+ function getClosedObjectPropertySet(schema) {
112
+ if (!isObjectOnlySchema(schema))
113
+ return undefined;
114
+ const record = schema;
115
+ const properties = record['properties'];
116
+ const required = record['required'];
117
+ if (record['additionalProperties'] !== false ||
118
+ !properties ||
119
+ typeof properties !== 'object' ||
120
+ Array.isArray(properties) ||
121
+ !Array.isArray(required) ||
122
+ required.some((property) => typeof property !== 'string')) {
123
+ return undefined;
124
+ }
125
+ const propertySet = new Set(Object.keys(properties));
126
+ const requiredProperties = required;
127
+ // A required undeclared property makes a closed branch unsatisfiable, but
128
+ // the strictifier rejects that shape rather than representing it. Keep this
129
+ // exclusivity proof conservative and let the normal validation path fail.
130
+ if (requiredProperties.some((property) => !propertySet.has(property))) {
131
+ return undefined;
132
+ }
133
+ return { properties: propertySet, required: requiredProperties };
134
+ }
135
+ function haveDisjointClosedObjectPropertySets(left, right) {
136
+ const leftShape = getClosedObjectPropertySet(left);
137
+ const rightShape = getClosedObjectPropertySet(right);
138
+ if (!leftShape || !rightShape)
139
+ return false;
140
+ // If either closed branch requires a property the other branch does not
141
+ // declare, every instance satisfying the first is rejected by the second as
142
+ // an additional property. This proves oneOf exclusivity without widening
143
+ // overlapping closed shapes.
144
+ return (leftShape.required.some((property) => !rightShape.properties.has(property)) ||
145
+ rightShape.required.some((property) => !leftShape.properties.has(property)));
146
+ }
147
+ function areMutuallyExclusive(left, right, root) {
148
+ const leftTypes = getSchemaTypes(left);
149
+ const rightTypes = getSchemaTypes(right);
150
+ if (leftTypes &&
151
+ rightTypes &&
152
+ [...leftTypes].every((leftType) => [...rightTypes].every((rightType) => !schemaTypesOverlap(leftType, rightType)))) {
153
+ return true;
154
+ }
155
+ return (haveDisjointLiteralValues(left, right) ||
156
+ haveDisjointObjectDiscriminator(left, right, root) ||
157
+ haveDisjointClosedObjectPropertySets(left, right));
158
+ }
159
+ function resolveLocalRefForExclusivity(schema, root, seenRefs = new Set()) {
160
+ if (!schema || typeof schema !== 'object' || Array.isArray(schema))
161
+ return schema;
162
+ const record = schema;
163
+ const ref = record['$ref'];
164
+ if (ref !== undefined) {
165
+ // Annotation keywords do not affect Draft 7 validation, so they are safe
166
+ // to retain while proving the referenced branches are mutually exclusive.
167
+ // Keep the proof conservative for every other sibling constraint.
168
+ if (typeof ref !== 'string' || !(0, transform_1.hasOnlyRefAndAnnotations)(record)) {
169
+ return undefined;
170
+ }
171
+ if (seenRefs.has(ref))
172
+ return undefined;
173
+ const resolved = (0, transform_1.resolveLocalRef)(root, ref);
174
+ if (resolved === undefined)
175
+ return undefined;
176
+ return resolveLocalRefForExclusivity(resolved, root, new Set([...seenRefs, ref]));
177
+ }
178
+ if (record['allOf'] !== undefined) {
179
+ if (!Array.isArray(record['allOf']))
180
+ return undefined;
181
+ const normalized = (0, transform_1.normalizeObjectAllOfForExclusivity)(record, root);
182
+ if (normalized === undefined)
183
+ return undefined;
184
+ // Flattening a singleton allOf can expose a bare local ref. Feed that
185
+ // result through this same resolver so URI-fragment decoding and the
186
+ // existing local-ref cycle guard still apply before exclusivity analysis.
187
+ return resolveLocalRefForExclusivity(normalized, root, seenRefs);
188
+ }
189
+ return schema;
190
+ }
191
+ function areOneOfBranchesMutuallyExclusive(branches, root) {
192
+ for (let index = 0; index < branches.length; index++) {
193
+ for (let otherIndex = index + 1; otherIndex < branches.length; otherIndex++) {
194
+ const left = resolveLocalRefForExclusivity(branches[index], root);
195
+ const right = resolveLocalRefForExclusivity(branches[otherIndex], root);
196
+ if (left === undefined || right === undefined || !areMutuallyExclusive(left, right, root)) {
197
+ return false;
198
+ }
199
+ }
200
+ }
201
+ return true;
202
+ }
203
+ function normalizeStructuredOutputSchema(schema) {
204
+ (0, transform_1.assertNoNestedSchemaIds)(schema);
205
+ const normalizedSchema = structuredClone(schema);
206
+ const oneOfSchemas = [];
207
+ const visitedSchemas = new Set();
208
+ const visitSchema = (value) => {
209
+ if (!value || typeof value !== 'object' || Array.isArray(value))
210
+ return;
211
+ const record = value;
212
+ if (visitedSchemas.has(record))
213
+ return;
214
+ visitedSchemas.add(record);
215
+ if (record['oneOf'] !== undefined) {
216
+ if (!Array.isArray(record['oneOf'])) {
217
+ throw new error_1.OpenAIError('Standard JSON Schema generated an invalid `oneOf`, which cannot be represented in an OpenAI strict schema');
218
+ }
219
+ if (record['anyOf'] !== undefined) {
220
+ throw new error_1.OpenAIError('Standard JSON Schema generated both `anyOf` and `oneOf`, which cannot be represented in an OpenAI strict schema');
221
+ }
222
+ // `false` can never validate, so it cannot overlap another oneOf
223
+ // branch. Keep it in place until the existing anyOf normalization runs
224
+ // so local refs into surviving branch indices can be rewritten before
225
+ // the impossible alternatives are removed.
226
+ const possibleBranches = record['oneOf'].filter((branch) => branch !== false);
227
+ if (!areOneOfBranchesMutuallyExclusive(possibleBranches, normalizedSchema)) {
228
+ throw new error_1.OpenAIError('Standard JSON Schema generated a `oneOf` whose branches are not provably mutually exclusive. OpenAI strict schemas do not support `oneOf`; use `anyOf` or add a discriminator with distinct literal values.');
229
+ }
230
+ oneOfSchemas.push(record);
231
+ }
232
+ (0, transform_1.forEachJSONSchemaChild)(record, [], (child) => visitSchema(child));
233
+ };
234
+ visitSchema(normalizedSchema);
235
+ (0, transform_1.rewriteLocalRefsIntoMovedOneOfBranches)(normalizedSchema);
236
+ for (const record of oneOfSchemas) {
237
+ record['anyOf'] = record['oneOf'];
238
+ delete record['oneOf'];
239
+ }
240
+ return normalizedSchema;
241
+ }
242
+ function parseStandardSchema(standardSchema, content) {
243
+ const result = standardSchema['~standard'].validate(JSON.parse(content));
244
+ if (isPromiseLike(result)) {
245
+ void Promise.resolve(result).catch(() => undefined);
246
+ throw new error_1.OpenAIError('Standard Schema helpers only support synchronous validation. Use a schema with a synchronous `~standard.validate()` implementation.');
247
+ }
248
+ if (result.issues) {
249
+ throw new error_1.OpenAIError(`Standard Schema validation failed: ${formatStandardSchemaIssues(result.issues)}`);
250
+ }
251
+ return result.value;
252
+ }
253
+ function resolveStandardJSONSchema(standardSchema, schemaOverride) {
254
+ const schema = (schemaOverride ?? standardSchema['~standard'].jsonSchema?.input({ target: 'draft-07' }));
255
+ if (!schema) {
256
+ throw new error_1.OpenAIError('Standard Schema helpers require a JSON Schema. Pass `schema` or use a schema that implements `~standard.jsonSchema.input()`.');
257
+ }
258
+ return (0, transform_1.toStrictJsonSchema)(normalizeStructuredOutputSchema(schema));
259
+ }
260
+ /**
261
+ * Creates a chat completion `JSONSchema` response format from a Standard
262
+ * Schema validator.
263
+ *
264
+ * The helper uses `~standard.jsonSchema.input()` for the model-facing schema
265
+ * and `~standard.validate()` for parsed output. Validation must be
266
+ * synchronous because the SDK's parse helpers are synchronous.
267
+ */
268
+ function standardResponseFormat(standardSchema, name, props) {
269
+ const { schema, ...formatProps } = props ?? {};
270
+ return (0, parser_1.makeParseableResponseFormat)({
271
+ type: 'json_schema',
272
+ json_schema: {
273
+ ...formatProps,
274
+ name,
275
+ strict: true,
276
+ schema: resolveStandardJSONSchema(standardSchema, schema),
277
+ },
278
+ }, (content) => parseStandardSchema(standardSchema, content));
279
+ }
280
+ /**
281
+ * Creates a Responses API `json_schema` text format from a Standard Schema
282
+ * validator.
283
+ */
284
+ function standardTextFormat(standardSchema, name, props) {
285
+ const { schema, ...formatProps } = props ?? {};
286
+ return (0, parser_1.makeParseableTextFormat)({
287
+ type: 'json_schema',
288
+ ...formatProps,
289
+ name,
290
+ strict: true,
291
+ schema: resolveStandardJSONSchema(standardSchema, schema),
292
+ }, (content) => parseStandardSchema(standardSchema, content));
293
+ }
294
+ function standardFunction(options) {
295
+ return (0, parser_1.makeParseableTool)({
296
+ type: 'function',
297
+ function: {
298
+ name: options.name,
299
+ parameters: resolveStandardJSONSchema(options.parameters, options.schema),
300
+ strict: true,
301
+ ...(options.description ? { description: options.description } : undefined),
302
+ },
303
+ }, {
304
+ callback: options.function,
305
+ parser: (args) => parseStandardSchema(options.parameters, args),
306
+ });
307
+ }
308
+ function standardResponsesFunction(options) {
309
+ return (0, ResponsesParser_1.makeParseableResponseTool)({
310
+ type: 'function',
311
+ name: options.name,
312
+ parameters: resolveStandardJSONSchema(options.parameters, options.schema),
313
+ strict: true,
314
+ ...(options.description ? { description: options.description } : undefined),
315
+ }, {
316
+ callback: options.function,
317
+ parser: (args) => parseStandardSchema(options.parameters, args),
318
+ });
319
+ }
320
+ //# sourceMappingURL=standard-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard-schema.js","sourceRoot":"","sources":["../src/helpers/standard-schema.ts"],"names":[],"mappings":";;AAwcA,wDAmBC;AAMD,gDAiBC;AAkBD,4CAkBC;AAmBD,8DAgBC;AAzjBD,uCAAuC;AACvC,6CAOuB;AACvB,+DAA8F;AAE9F,mDAQ0B;AA4F1B,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC;AAC5G,CAAC;AAED,SAAS,0BAA0B,CAAC,MAA0C;IAC5E,OAAO,MAAM;SACV,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACb,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI;YACrB,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAChB,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAI,KAAK,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAC5F;aACA,GAAG,CAAC,MAAM,CAAC;aACX,IAAI,CAAC,GAAG,CAAC,CAAC;QACb,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,KAAK,CAAC,OA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,EAAE,EAAE,CAAC,mBAAmB,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC;KAChE,CACF,CAAC;AACJ,CAAC;AAmBD,SAAgB,yBAAyB,CACvC,OAAwC;IAExC,OAAO,IAAA,2CAAyB,EAC9B;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,UAAU,EAAE,yBAAyB,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC;QACzE,MAAM,EAAE,IAAI;QACZ,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;KAC5E,EACD;QACE,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,mBAAmB,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC;KAChE,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,314 @@
1
+ import { OpenAIError } from "../error.mjs";
2
+ import { makeParseableResponseFormat, makeParseableTextFormat, makeParseableTool, } from "../lib/parser.mjs";
3
+ import { makeParseableResponseTool } from "../lib/ResponsesParser.mjs";
4
+ import { assertNoNestedSchemaIds, forEachJSONSchemaChild, hasOnlyRefAndAnnotations, normalizeObjectAllOfForExclusivity, resolveLocalRef, rewriteLocalRefsIntoMovedOneOfBranches, toStrictJsonSchema, } from "../lib/transform.mjs";
5
+ function isPromiseLike(value) {
6
+ return typeof value === 'object' && value !== null && 'then' in value && typeof value.then === 'function';
7
+ }
8
+ function formatStandardSchemaIssues(issues) {
9
+ return issues
10
+ .map((issue) => {
11
+ const path = issue.path
12
+ ?.map((segment) => typeof segment === 'object' && segment !== null && 'key' in segment ? segment.key : segment)
13
+ .map(String)
14
+ .join('.');
15
+ return path ? `${path}: ${issue.message}` : issue.message;
16
+ })
17
+ .join('; ');
18
+ }
19
+ const JSON_SCHEMA_TYPES = new Set(['string', 'number', 'integer', 'boolean', 'object', 'array', 'null']);
20
+ function getSchemaTypes(schema) {
21
+ if (!schema || typeof schema !== 'object' || Array.isArray(schema))
22
+ return undefined;
23
+ const type = schema['type'];
24
+ if (type === undefined) {
25
+ return getLiteralSchemaTypes(schema);
26
+ }
27
+ const types = Array.isArray(type) ? type : [type];
28
+ if (types.length === 0 ||
29
+ !types.every((value) => typeof value === 'string' && JSON_SCHEMA_TYPES.has(value))) {
30
+ return undefined;
31
+ }
32
+ return new Set(types);
33
+ }
34
+ function isJSONPrimitive(value) {
35
+ return (value === null ||
36
+ typeof value === 'string' ||
37
+ typeof value === 'boolean' ||
38
+ (typeof value === 'number' && Number.isFinite(value)));
39
+ }
40
+ function getLiteralValues(schema) {
41
+ if (!schema || typeof schema !== 'object' || Array.isArray(schema))
42
+ return undefined;
43
+ const record = schema;
44
+ if ('const' in record && isJSONPrimitive(record['const'])) {
45
+ return [record['const']];
46
+ }
47
+ const enumValues = record['enum'];
48
+ if (Array.isArray(enumValues) && enumValues.length > 0 && enumValues.every(isJSONPrimitive)) {
49
+ return enumValues;
50
+ }
51
+ return undefined;
52
+ }
53
+ function getLiteralSchemaTypes(schema) {
54
+ const literalValues = getLiteralValues(schema);
55
+ if (!literalValues)
56
+ return undefined;
57
+ return new Set(literalValues.map((value) => {
58
+ if (value === null)
59
+ return 'null';
60
+ return typeof value;
61
+ }));
62
+ }
63
+ function haveDisjointLiteralValues(left, right) {
64
+ const leftValues = getLiteralValues(left);
65
+ const rightValues = getLiteralValues(right);
66
+ if (!leftValues || !rightValues)
67
+ return false;
68
+ return leftValues.every((leftValue) => !rightValues.some((rightValue) => leftValue === rightValue));
69
+ }
70
+ function schemaTypesOverlap(left, right) {
71
+ return (left === right || (left === 'integer' && right === 'number') || (left === 'number' && right === 'integer'));
72
+ }
73
+ function isObjectOnlySchema(schema) {
74
+ const types = getSchemaTypes(schema);
75
+ return types?.size === 1 && types.has('object');
76
+ }
77
+ function haveDisjointObjectDiscriminator(left, right, root) {
78
+ if (!isObjectOnlySchema(left) || !isObjectOnlySchema(right))
79
+ return false;
80
+ const leftRecord = left;
81
+ const rightRecord = right;
82
+ const leftProperties = leftRecord['properties'];
83
+ const rightProperties = rightRecord['properties'];
84
+ const leftRequired = leftRecord['required'];
85
+ const rightRequired = rightRecord['required'];
86
+ if (!leftProperties ||
87
+ typeof leftProperties !== 'object' ||
88
+ Array.isArray(leftProperties) ||
89
+ !rightProperties ||
90
+ typeof rightProperties !== 'object' ||
91
+ Array.isArray(rightProperties) ||
92
+ !Array.isArray(leftRequired) ||
93
+ !Array.isArray(rightRequired)) {
94
+ return false;
95
+ }
96
+ for (const property of leftRequired) {
97
+ if (typeof property === 'string' &&
98
+ rightRequired.includes(property) &&
99
+ haveDisjointLiteralValues(resolveLocalRefForExclusivity(leftProperties[property], root), resolveLocalRefForExclusivity(rightProperties[property], root))) {
100
+ return true;
101
+ }
102
+ }
103
+ return false;
104
+ }
105
+ function getClosedObjectPropertySet(schema) {
106
+ if (!isObjectOnlySchema(schema))
107
+ return undefined;
108
+ const record = schema;
109
+ const properties = record['properties'];
110
+ const required = record['required'];
111
+ if (record['additionalProperties'] !== false ||
112
+ !properties ||
113
+ typeof properties !== 'object' ||
114
+ Array.isArray(properties) ||
115
+ !Array.isArray(required) ||
116
+ required.some((property) => typeof property !== 'string')) {
117
+ return undefined;
118
+ }
119
+ const propertySet = new Set(Object.keys(properties));
120
+ const requiredProperties = required;
121
+ // A required undeclared property makes a closed branch unsatisfiable, but
122
+ // the strictifier rejects that shape rather than representing it. Keep this
123
+ // exclusivity proof conservative and let the normal validation path fail.
124
+ if (requiredProperties.some((property) => !propertySet.has(property))) {
125
+ return undefined;
126
+ }
127
+ return { properties: propertySet, required: requiredProperties };
128
+ }
129
+ function haveDisjointClosedObjectPropertySets(left, right) {
130
+ const leftShape = getClosedObjectPropertySet(left);
131
+ const rightShape = getClosedObjectPropertySet(right);
132
+ if (!leftShape || !rightShape)
133
+ return false;
134
+ // If either closed branch requires a property the other branch does not
135
+ // declare, every instance satisfying the first is rejected by the second as
136
+ // an additional property. This proves oneOf exclusivity without widening
137
+ // overlapping closed shapes.
138
+ return (leftShape.required.some((property) => !rightShape.properties.has(property)) ||
139
+ rightShape.required.some((property) => !leftShape.properties.has(property)));
140
+ }
141
+ function areMutuallyExclusive(left, right, root) {
142
+ const leftTypes = getSchemaTypes(left);
143
+ const rightTypes = getSchemaTypes(right);
144
+ if (leftTypes &&
145
+ rightTypes &&
146
+ [...leftTypes].every((leftType) => [...rightTypes].every((rightType) => !schemaTypesOverlap(leftType, rightType)))) {
147
+ return true;
148
+ }
149
+ return (haveDisjointLiteralValues(left, right) ||
150
+ haveDisjointObjectDiscriminator(left, right, root) ||
151
+ haveDisjointClosedObjectPropertySets(left, right));
152
+ }
153
+ function resolveLocalRefForExclusivity(schema, root, seenRefs = new Set()) {
154
+ if (!schema || typeof schema !== 'object' || Array.isArray(schema))
155
+ return schema;
156
+ const record = schema;
157
+ const ref = record['$ref'];
158
+ if (ref !== undefined) {
159
+ // Annotation keywords do not affect Draft 7 validation, so they are safe
160
+ // to retain while proving the referenced branches are mutually exclusive.
161
+ // Keep the proof conservative for every other sibling constraint.
162
+ if (typeof ref !== 'string' || !hasOnlyRefAndAnnotations(record)) {
163
+ return undefined;
164
+ }
165
+ if (seenRefs.has(ref))
166
+ return undefined;
167
+ const resolved = resolveLocalRef(root, ref);
168
+ if (resolved === undefined)
169
+ return undefined;
170
+ return resolveLocalRefForExclusivity(resolved, root, new Set([...seenRefs, ref]));
171
+ }
172
+ if (record['allOf'] !== undefined) {
173
+ if (!Array.isArray(record['allOf']))
174
+ return undefined;
175
+ const normalized = normalizeObjectAllOfForExclusivity(record, root);
176
+ if (normalized === undefined)
177
+ return undefined;
178
+ // Flattening a singleton allOf can expose a bare local ref. Feed that
179
+ // result through this same resolver so URI-fragment decoding and the
180
+ // existing local-ref cycle guard still apply before exclusivity analysis.
181
+ return resolveLocalRefForExclusivity(normalized, root, seenRefs);
182
+ }
183
+ return schema;
184
+ }
185
+ function areOneOfBranchesMutuallyExclusive(branches, root) {
186
+ for (let index = 0; index < branches.length; index++) {
187
+ for (let otherIndex = index + 1; otherIndex < branches.length; otherIndex++) {
188
+ const left = resolveLocalRefForExclusivity(branches[index], root);
189
+ const right = resolveLocalRefForExclusivity(branches[otherIndex], root);
190
+ if (left === undefined || right === undefined || !areMutuallyExclusive(left, right, root)) {
191
+ return false;
192
+ }
193
+ }
194
+ }
195
+ return true;
196
+ }
197
+ function normalizeStructuredOutputSchema(schema) {
198
+ assertNoNestedSchemaIds(schema);
199
+ const normalizedSchema = structuredClone(schema);
200
+ const oneOfSchemas = [];
201
+ const visitedSchemas = new Set();
202
+ const visitSchema = (value) => {
203
+ if (!value || typeof value !== 'object' || Array.isArray(value))
204
+ return;
205
+ const record = value;
206
+ if (visitedSchemas.has(record))
207
+ return;
208
+ visitedSchemas.add(record);
209
+ if (record['oneOf'] !== undefined) {
210
+ if (!Array.isArray(record['oneOf'])) {
211
+ throw new OpenAIError('Standard JSON Schema generated an invalid `oneOf`, which cannot be represented in an OpenAI strict schema');
212
+ }
213
+ if (record['anyOf'] !== undefined) {
214
+ throw new OpenAIError('Standard JSON Schema generated both `anyOf` and `oneOf`, which cannot be represented in an OpenAI strict schema');
215
+ }
216
+ // `false` can never validate, so it cannot overlap another oneOf
217
+ // branch. Keep it in place until the existing anyOf normalization runs
218
+ // so local refs into surviving branch indices can be rewritten before
219
+ // the impossible alternatives are removed.
220
+ const possibleBranches = record['oneOf'].filter((branch) => branch !== false);
221
+ if (!areOneOfBranchesMutuallyExclusive(possibleBranches, normalizedSchema)) {
222
+ throw new OpenAIError('Standard JSON Schema generated a `oneOf` whose branches are not provably mutually exclusive. OpenAI strict schemas do not support `oneOf`; use `anyOf` or add a discriminator with distinct literal values.');
223
+ }
224
+ oneOfSchemas.push(record);
225
+ }
226
+ forEachJSONSchemaChild(record, [], (child) => visitSchema(child));
227
+ };
228
+ visitSchema(normalizedSchema);
229
+ rewriteLocalRefsIntoMovedOneOfBranches(normalizedSchema);
230
+ for (const record of oneOfSchemas) {
231
+ record['anyOf'] = record['oneOf'];
232
+ delete record['oneOf'];
233
+ }
234
+ return normalizedSchema;
235
+ }
236
+ function parseStandardSchema(standardSchema, content) {
237
+ const result = standardSchema['~standard'].validate(JSON.parse(content));
238
+ if (isPromiseLike(result)) {
239
+ void Promise.resolve(result).catch(() => undefined);
240
+ throw new OpenAIError('Standard Schema helpers only support synchronous validation. Use a schema with a synchronous `~standard.validate()` implementation.');
241
+ }
242
+ if (result.issues) {
243
+ throw new OpenAIError(`Standard Schema validation failed: ${formatStandardSchemaIssues(result.issues)}`);
244
+ }
245
+ return result.value;
246
+ }
247
+ function resolveStandardJSONSchema(standardSchema, schemaOverride) {
248
+ const schema = (schemaOverride ?? standardSchema['~standard'].jsonSchema?.input({ target: 'draft-07' }));
249
+ if (!schema) {
250
+ throw new OpenAIError('Standard Schema helpers require a JSON Schema. Pass `schema` or use a schema that implements `~standard.jsonSchema.input()`.');
251
+ }
252
+ return toStrictJsonSchema(normalizeStructuredOutputSchema(schema));
253
+ }
254
+ /**
255
+ * Creates a chat completion `JSONSchema` response format from a Standard
256
+ * Schema validator.
257
+ *
258
+ * The helper uses `~standard.jsonSchema.input()` for the model-facing schema
259
+ * and `~standard.validate()` for parsed output. Validation must be
260
+ * synchronous because the SDK's parse helpers are synchronous.
261
+ */
262
+ export function standardResponseFormat(standardSchema, name, props) {
263
+ const { schema, ...formatProps } = props ?? {};
264
+ return makeParseableResponseFormat({
265
+ type: 'json_schema',
266
+ json_schema: {
267
+ ...formatProps,
268
+ name,
269
+ strict: true,
270
+ schema: resolveStandardJSONSchema(standardSchema, schema),
271
+ },
272
+ }, (content) => parseStandardSchema(standardSchema, content));
273
+ }
274
+ /**
275
+ * Creates a Responses API `json_schema` text format from a Standard Schema
276
+ * validator.
277
+ */
278
+ export function standardTextFormat(standardSchema, name, props) {
279
+ const { schema, ...formatProps } = props ?? {};
280
+ return makeParseableTextFormat({
281
+ type: 'json_schema',
282
+ ...formatProps,
283
+ name,
284
+ strict: true,
285
+ schema: resolveStandardJSONSchema(standardSchema, schema),
286
+ }, (content) => parseStandardSchema(standardSchema, content));
287
+ }
288
+ export function standardFunction(options) {
289
+ return makeParseableTool({
290
+ type: 'function',
291
+ function: {
292
+ name: options.name,
293
+ parameters: resolveStandardJSONSchema(options.parameters, options.schema),
294
+ strict: true,
295
+ ...(options.description ? { description: options.description } : undefined),
296
+ },
297
+ }, {
298
+ callback: options.function,
299
+ parser: (args) => parseStandardSchema(options.parameters, args),
300
+ });
301
+ }
302
+ export function standardResponsesFunction(options) {
303
+ return makeParseableResponseTool({
304
+ type: 'function',
305
+ name: options.name,
306
+ parameters: resolveStandardJSONSchema(options.parameters, options.schema),
307
+ strict: true,
308
+ ...(options.description ? { description: options.description } : undefined),
309
+ }, {
310
+ callback: options.function,
311
+ parser: (args) => parseStandardSchema(options.parameters, args),
312
+ });
313
+ }
314
+ //# sourceMappingURL=standard-schema.mjs.map