MCPcopy Create free account
hub / github.com/chieapp/chie / loadService

Method loadService

src/view/chat-view.ts:158–218  ·  view source on GitHub ↗
(service: BaseChatService)

Source from the content-addressed store, hash-verified

156 }
157
158 async loadService(service: BaseChatService) {
159 if (!(service instanceof BaseChatService))
160 throw new Error('ChatView can only be used with BaseChatService.');
161 if (!await super.loadService(service))
162 return false;
163
164 // Delay loading until the service is ready.
165 await service.load();
166 // Load messages.
167 this.#markdown = null;
168 this.messagesView.loadChatService(service);
169 this.onNewTitle.emit();
170 this.#updateSwitchButton();
171
172 // Connect signals.
173 this.serviceConnections.add(service.onNewTitle.connect(
174 this.onNewTitle.emit.bind(this.onNewTitle)));
175 this.serviceConnections.add(service.onChangeName.connect(
176 this.#onChangeName.bind(this)));
177 this.serviceConnections.add(service.onChangeIcon.connect(
178 this.#onChangeIcon.bind(this)));
179 this.serviceConnections.add(service.onUserMessage.connect(
180 this.#onUserMessage.bind(this)));
181 this.serviceConnections.add(service.onClearError.connect(
182 this.#onClearError.bind(this)));
183 this.serviceConnections.add(service.onMessageBegin.connect(
184 this.#onMessageBegin.bind(this)));
185 this.serviceConnections.add(service.onMessageDelta.connect(
186 this.#onMessageDelta.bind(this)));
187 this.serviceConnections.add(service.onExecuteToolError.connect(
188 this.#onMessageError.bind(this)));
189 this.serviceConnections.add(service.onMessageError.connect(
190 this.#onMessageError.bind(this)));
191 this.serviceConnections.add(service.onMessage.connect(
192 this.#onMessageEnd.bind(this)));
193 this.serviceConnections.add(service.onRemoveMessagesAfter.connect(
194 this.messagesView.removeMessagesAfter.bind(this.messagesView)));
195 this.serviceConnections.add(service.onUpdateMessage.connect(
196 this.messagesView.updateMessage.bind(this.messagesView, this.service)));
197 this.serviceConnections.add(service.onClearMessages.connect(() => {
198 this.messagesView.clearMessages();
199 this.#resetUIState();
200 }));
201 if (this.service.pending) {
202 // When the we have started recieving message but there is no pending
203 // message in the messagesView, append one.
204 if (!this.messagesView.hasPendingMessage)
205 this.#onMessageBegin();
206 // Load pending message.
207 if (this.service.pendingMessage)
208 this.#onMessageDelta(this.service.pendingMessage, {pending: true});
209 if (this.service.lastError)
210 this.#onMessageError(this.service.lastError);
211 this.#resetUIState();
212 } else {
213 // If last message is from user, add a resend button.
214 if (this.service.getLastMessage()?.role == ChatRole.User)
215 this.messagesView.setReplyActions(['resend']);

Callers 4

chat-view-test.tsFile · 0.45
constructorMethod · 0.45

Calls 8

#updateSwitchButtonMethod · 0.95
#resetUIStateMethod · 0.95
#onMessageBeginMethod · 0.95
#onMessageDeltaMethod · 0.95
#onMessageErrorMethod · 0.95
loadChatServiceMethod · 0.80
clearMessagesMethod · 0.80
setReplyActionsMethod · 0.80

Tested by

no test coverage detected