@openai/agents-core
Version:
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
40 lines • 1.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.stableJsonStringify = stableJsonStringify;
exports.stableJsonPrettyStringify = stableJsonPrettyStringify;
exports.stableJsonValue = stableJsonValue;
function stableJsonStringify(value, options = {}) {
return JSON.stringify(stableJsonValue(value, options));
}
function stableJsonPrettyStringify(value, options = {}) {
return JSON.stringify(stableJsonValue(value, options), null, 2).replace(/": /g, '":');
}
function stableJsonValue(value, options = {}) {
if (value instanceof Uint8Array) {
return options.encodeBytes
? options.encodeBytes(value)
: { type: 'Uint8Array', data: Array.from(value) };
}
if (Array.isArray(value)) {
return value.map((entry) => stableJsonValue(entry, options));
}
if (typeof value === 'function') {
return options.encodeFunction
? options.encodeFunction(value)
: value;
}
if (!value || typeof value !== 'object') {
return value;
}
if (options.encodeNonPlainObject && !isPlainRecord(value)) {
return options.encodeNonPlainObject(value);
}
return Object.fromEntries(Object.entries(value)
.sort(([left], [right]) => left.localeCompare(right))
.map(([key, entry]) => [key, stableJsonValue(entry, options)]));
}
function isPlainRecord(value) {
const prototype = Object.getPrototypeOf(value);
return prototype === Object.prototype || prototype === null;
}
//# sourceMappingURL=stableJson.js.map