* Transforms raw Gemini JSONL entries into the canonical logEntries format * used by the shared generateConversationMarkdown function. * * Gemini entry types and their canonical mappings: * - "init" → {type:"system", subtype:"init", model, session_id} * - "message" (assistant, delta:true) → mer
(rawEntries)
| 118 | * @returns {Array<any>} Canonical log entries for generateConversationMarkdown |
| 119 | */ |
| 120 | function transformGeminiEntries(rawEntries) { |
| 121 | /** @type {Array<any>} */ |
| 122 | const entries = []; |
| 123 | |
| 124 | for (const raw of rawEntries) { |
| 125 | if (raw.type === "init") { |
| 126 | entries.push({ |
| 127 | type: "system", |
| 128 | subtype: "init", |
| 129 | model: raw.model, |
| 130 | session_id: raw.session_id, |
| 131 | }); |
| 132 | } else if (raw.type === "message" && raw.role === "assistant") { |
| 133 | const text = raw.content || ""; |
| 134 | if (!text.trim()) { |
| 135 | continue; |
| 136 | } |
| 137 | // Merge consecutive streaming delta chunks into one assistant text entry |
| 138 | const last = entries[entries.length - 1]; |
| 139 | if (raw.delta === true && isConsecutiveDeltaEntry(last)) { |
| 140 | last.message.content[0].text += text; |
| 141 | } else { |
| 142 | entries.push({ |
| 143 | type: "assistant", |
| 144 | message: { |
| 145 | content: [{ type: "text", text }], |
| 146 | }, |
| 147 | }); |
| 148 | } |
| 149 | } else if (raw.type === "tool_use") { |
| 150 | entries.push({ |
| 151 | type: "assistant", |
| 152 | message: { |
| 153 | content: [ |
| 154 | { |
| 155 | type: "tool_use", |
| 156 | id: raw.tool_id, |
| 157 | name: raw.tool_name, |
| 158 | input: raw.parameters || {}, |
| 159 | }, |
| 160 | ], |
| 161 | }, |
| 162 | }); |
| 163 | } else if (raw.type === "tool_result") { |
| 164 | const output = typeof raw.output === "string" ? raw.output : JSON.stringify(raw.output || ""); |
| 165 | entries.push({ |
| 166 | type: "user", |
| 167 | message: { |
| 168 | content: [ |
| 169 | { |
| 170 | type: "tool_result", |
| 171 | tool_use_id: raw.tool_id, |
| 172 | content: output, |
| 173 | is_error: raw.status !== "success", |
| 174 | }, |
| 175 | ], |
| 176 | }, |
| 177 | }); |
no test coverage detected