@openai/agents-core
Version:
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
29 lines • 998 B
JavaScript
/**
* Applies persisted-history mutations and returns a new canonical item list.
*/
export function applySessionHistoryMutations(items, mutations) {
let nextItems = items.map((item) => structuredClone(item));
for (const mutation of mutations) {
if (mutation.type === 'replace_function_call') {
nextItems = applyReplaceFunctionCallMutation(nextItems, mutation);
}
}
return nextItems;
}
function applyReplaceFunctionCallMutation(items, mutation) {
const replacement = structuredClone(mutation.replacement);
const nextItems = [];
let keptReplacement = false;
for (const item of items) {
if (item.type === 'function_call' && item.callId === mutation.callId) {
if (!keptReplacement) {
nextItems.push(replacement);
keptReplacement = true;
}
continue;
}
nextItems.push(item);
}
return nextItems;
}
//# sourceMappingURL=historyMutations.mjs.map