UNPKG

@openai/agents-core

Version:

The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.

35 lines • 1.35 kB
export function stableJsonStringify(value, options = {}) { return JSON.stringify(stableJsonValue(value, options)); } export function stableJsonPrettyStringify(value, options = {}) { return JSON.stringify(stableJsonValue(value, options), null, 2).replace(/": /g, '":'); } export 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.mjs.map