(app, options = {})
| 86 | sync: options.syncServiceImpl || globalThis.syncService || null |
| 87 | }; |
| 88 | } |
| 89 | |
| 90 | export function createModelPickerInterface(app, options = {}) { |
| 91 | const db = options.chatDBImpl || chatDB; |
| 92 | const elements = pickElements(app, [ |
| 93 | 'modelPickerBtn', |
| 94 | 'modelPickerModal', |
| 95 | 'closeModalBtn', |
| 96 | 'modelsList', |
| 97 | 'modelSearch', |
| 98 | 'modelListScrollArea', |
| 99 | 'messageInput' |
| 100 | ]); |
| 101 | |
| 102 | return { |
| 103 | elements, |
| 104 | state: app.state, |
| 105 | presentation: options.presentation || null, |
| 106 | get reasoningEnabled() { |
| 107 | return app.reasoningEnabled; |
| 108 | }, |
| 109 | get cachedModelDisplayMetadata() { |
| 110 | return app.cachedModelDisplayMetadata; |
| 111 | }, |
| 112 | getCurrentSession: () => app.getCurrentSession(), |
| 113 | getDefaultModelName: () => app.getDefaultModelName(), |
| 114 | normalizeModelName: (modelName) => app.normalizeModelName(modelName), |
| 115 | getPrimaryModelName: () => { |
| 116 | if (app.chatInput?.getPrimaryModelName) { |
| 117 | return app.chatInput.getPrimaryModelName(); |
| 118 | } |
| 119 | const session = app.getCurrentSession(); |
| 120 | const rawModelName = session?.model || app.state.pendingModelName || null; |
| 121 | return rawModelName ? (app.normalizeModelName(rawModelName) || rawModelName) : null; |
| 122 | }, |
| 123 | getCouncilSecondaryModelName: () => app.chatInput?.getSelectedCouncilSecondaryModelName?.() || '', |
| 124 | getCouncilSynthesisModelName: () => app.chatInput?.getCouncilSynthesisModelForSelection?.() || '', |
| 125 | renderCurrentModel: () => app.renderCurrentModel(), |
| 126 | refreshEditModelPickerButton: () => app.chatArea?.updateEditModelPickerButton?.(), |
| 127 | actions: { |
| 128 | async selectModel(modelName) { |
| 129 | const normalizedModelName = app.normalizeModelName(modelName); |
| 130 | const session = app.getCurrentSession(); |
| 131 | const reservation = session ? app.beginSessionMutation?.(session.id) : null; |
| 132 | if (session && app.beginSessionMutation && !reservation) { |
| 133 | await app.acknowledgeSessionMutationBusy?.(session.id); |
no test coverage detected