(config: ServerConfig, deps: ServerDependencies)
| 512 | } catch (error) { |
| 513 | const msg = error instanceof Error ? error.message : String(error); |
| 514 | logToFile(`job/prompt: failed to materialize attachments: ${msg}`); |
| 515 | acknowledgeDelivery('failed'); |
| 516 | return errorResponse('SEND_ERROR', `Failed to materialize attachments: ${msg}`, 500); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | const attributionError = await applyCommitAttribution( |
| 521 | config.workspacePath, |
| 522 | prompt.finalization?.commitCoAuthor, |
| 523 | deps.configureCommitCoAuthor ?? configureCommitCoAuthorHook |
| 524 | ); |
| 525 | if (attributionError) { |
| 526 | acknowledgeDelivery('failed'); |
| 527 | return attributionError; |
| 528 | } |
| 529 | |
| 530 | if (!state.isConnected) { |
| 531 | try { |
| 532 | await openConnection(); |
| 533 | logToFile('job/prompt: subscription confirmed, connection opened'); |
| 534 | } catch (error) { |
| 535 | const msg = error instanceof Error ? error.message : String(error); |
| 536 | logToFile(`job/prompt: failed to open connection: ${msg}`); |
| 537 | acknowledgeDelivery('failed'); |
| 538 | return errorResponse('CONNECTION_ERROR', `Failed to open connection: ${msg}`, 500); |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | const addedMessage = state.acceptMessage(messageId, { |
| 543 | autoCommit: prompt.finalization?.autoCommit ?? false, |
| 544 | condenseOnComplete: prompt.finalization?.condenseOnComplete ?? false, |
| 545 | model: prompt.agent?.model?.modelID, |
| 546 | upstreamBranch: binding?.upstreamBranch, |
| 547 | ...(prompt.finalization?.commitCoAuthor |
| 548 | ? { commitCoAuthor: prompt.finalization.commitCoAuthor } |
| 549 | : {}), |
| 550 | }); |
| 551 | |
| 552 | try { |
| 553 | const snapshotInitialization = snapshotInitializationForPlatform(session.platform); |
| 554 | await kiloClient.sendPromptAsync({ |
| 555 | sessionId: session.kiloSessionId, |
| 556 | messageId, |
| 557 | parts: prompt.message.parts, |
| 558 | prompt: prompt.message.prompt, |
| 559 | variant: prompt.agent?.variant, |
| 560 | agent: prompt.agent?.mode, |
| 561 | model: prompt.agent?.model, |
| 562 | system: prompt.agent?.system, |
| 563 | tools: prompt.agent?.tools, |
| 564 | ...(snapshotInitialization ? { snapshotInitialization } : {}), |
| 565 | }); |
| 566 | logToFile(`job/prompt: sent messageId=${messageId}`); |
| 567 | acknowledgeDelivery('async-prompt'); |
| 568 | } catch (error) { |
| 569 | if (addedMessage) state.removeMessage(messageId); |
| 570 | acknowledgeDelivery('failed'); |
| 571 | const msg = error instanceof Error ? error.message : String(error); |
no test coverage detected