MCPcopy
hub / github.com/7836246/cursor2api / mergeConsecutiveRoles

Function mergeConsecutiveRoles

test/unit-openai-compat.mjs:89–103  ·  view source on GitHub ↗
(messages)

Source from the content-addressed store, hash-verified

87}
88
89function mergeConsecutiveRoles(messages) {
90 if (messages.length <= 1) return messages;
91 const merged = [];
92 for (const msg of messages) {
93 const last = merged[merged.length - 1];
94 if (last && last.role === msg.role) {
95 const lastBlocks = toBlocks(last.content);
96 const newBlocks = toBlocks(msg.content);
97 last.content = [...lastBlocks, ...newBlocks];
98 } else {
99 merged.push({ ...msg });
100 }
101 }
102 return merged;
103}
104
105// ─── 内联 responsesToChatCompletions(与 src/openai-handler.ts 保持同步)
106function responsesToChatCompletions(body) {

Callers 1

Calls 2

pushMethod · 0.80
toBlocksFunction · 0.70

Tested by

no test coverage detected