(deps: ServerDependencies, triggerDrainAndClose: () => void)
| 726 | } |
| 727 | }; |
| 728 | } |
| 729 | |
| 730 | /** |
| 731 | * The interactions this session currently waits on, as the Worker's |
| 732 | * `getPendingInteractions` read needs them: the same Kilo state the `connected` |
| 733 | * snapshot replays, filtered to this session's root Kilo session. |
| 734 | * |
| 735 | * A legacy `agent_*` Cloud Agent session keeps no pending set of its own — its |
| 736 | * Durable Object is only told about `question.asked`/`permission.asked` as |
| 737 | * events — so the wrapper is the only place that read can come from. A session |
| 738 | * with no bound Kilo session yet has nothing pending. |
| 739 | */ |
| 740 | export function createPendingInteractionsHandler(deps: ServerDependencies) { |
| 741 | return async (): Promise<Response> => { |
| 742 | const { state, kiloClient } = deps; |
| 743 | |
| 744 | if (!state.hasSession) { |
| 745 | return errorResponse('NO_SESSION', 'No session context', 400); |
| 746 | } |
| 747 | |
| 748 | const kiloSessionId = state.currentSession?.kiloSessionId; |
| 749 | if (!kiloSessionId) { |
| 750 | return jsonResponse({ questions: [], permissions: [] }); |
| 751 | } |
| 752 | |
| 753 | try { |
| 754 | const [questions, permissions] = await Promise.all([ |
| 755 | kiloClient.getQuestions(), |
| 756 | kiloClient.getPermissions(), |
| 757 | ]); |
| 758 | return jsonResponse({ |
| 759 | questions: questions.filter(question => question.sessionID === kiloSessionId), |
| 760 | permissions: permissions.filter(permission => permission.sessionID === kiloSessionId), |
| 761 | }); |
no test coverage detected