* Extract transform callbacks from a system message config and prepare the wire payload. * Function-valued actions are replaced with `{ action: "transform" }` for serialization, * and the original callbacks are returned in a separate map.
(systemMessage: SessionConfig["systemMessage"])
| 301 | * and the original callbacks are returned in a separate map. |
| 302 | */ |
| 303 | function extractTransformCallbacks(systemMessage: SessionConfig["systemMessage"]): { |
| 304 | wirePayload: SessionConfig["systemMessage"]; |
| 305 | transformCallbacks: Map<string, SectionTransformFn> | undefined; |
| 306 | } { |
| 307 | if (!systemMessage || systemMessage.mode !== "customize" || !systemMessage.sections) { |
| 308 | return { wirePayload: systemMessage, transformCallbacks: undefined }; |
| 309 | } |
| 310 | |
| 311 | const transformCallbacks = new Map<string, SectionTransformFn>(); |
| 312 | const wireSections: Record<string, { action: string; content?: string }> = {}; |
| 313 | |
| 314 | for (const [sectionId, override] of Object.entries(systemMessage.sections)) { |
| 315 | if (!override) continue; |
| 316 | |
| 317 | if (typeof override.action === "function") { |
| 318 | transformCallbacks.set(sectionId, override.action); |
| 319 | wireSections[sectionId] = { action: "transform" }; |
| 320 | } else { |
| 321 | wireSections[sectionId] = { action: override.action, content: override.content }; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | if (transformCallbacks.size === 0) { |
| 326 | return { wirePayload: systemMessage, transformCallbacks: undefined }; |
| 327 | } |
| 328 | |
| 329 | const wirePayload: SystemMessageCustomizeConfig = { |
| 330 | ...systemMessage, |
| 331 | sections: wireSections as SystemMessageCustomizeConfig["sections"], |
| 332 | }; |
| 333 | |
| 334 | return { wirePayload, transformCallbacks }; |
| 335 | } |
| 336 | |
| 337 | function getNodeExecPath(): string { |
| 338 | if (process.versions.bun) { |
no test coverage detected
searching dependent graphs…