mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 22:21:10 +02:00
fix(matrix-bots): resolve TypeScript strict null check errors
- Fix parseInt undefined errors in configuration files - Add fallbacks for Matrix client constructor parameters - Fix possibly undefined data accesses with non-null assertions - Update setCurrentConversation to accept null Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
f07387d12c
commit
004fe85799
15 changed files with 44 additions and 44 deletions
|
|
@ -33,8 +33,8 @@ export class MatrixService implements OnModuleInit {
|
|||
return;
|
||||
}
|
||||
|
||||
const storage = new SimpleFsStorageProvider(storagePath);
|
||||
this.client = new MatrixClient(homeserverUrl, accessToken, storage);
|
||||
const storage = new SimpleFsStorageProvider(storagePath || './data/bot-storage.json');
|
||||
this.client = new MatrixClient(homeserverUrl || 'http://localhost:8008', accessToken, storage);
|
||||
AutojoinRoomsMixin.setupOnClient(this.client);
|
||||
|
||||
this.client.on('room.message', this.handleMessage.bind(this));
|
||||
|
|
@ -245,9 +245,9 @@ export class MatrixService implements OnModuleInit {
|
|||
return `Fehler: ${result.error}`;
|
||||
}
|
||||
|
||||
let response = result.data.content;
|
||||
if (result.data.usage) {
|
||||
response += `\n\n_Tokens: ${result.data.usage.total_tokens}_`;
|
||||
let response = result.data!.content;
|
||||
if (result.data!.usage) {
|
||||
response += `\n\n_Tokens: ${result.data!.usage.total_tokens}_`;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
|
@ -279,8 +279,8 @@ export class MatrixService implements OnModuleInit {
|
|||
return `Fehler: ${result.error}`;
|
||||
}
|
||||
|
||||
this.sessionService.setCurrentConversation(sender, result.data.id);
|
||||
return `Neues Gespraech erstellt: **${result.data.title}**\nNutze \`!senden [nachricht]\` um zu chatten.`;
|
||||
this.sessionService.setCurrentConversation(sender, result.data!.id);
|
||||
return `Neues Gespraech erstellt: **${result.data!.title}**\nNutze \`!senden [nachricht]\` um zu chatten.`;
|
||||
}
|
||||
|
||||
private async handleListConversations(sender: string): Promise<string> {
|
||||
|
|
@ -342,7 +342,7 @@ export class MatrixService implements OnModuleInit {
|
|||
return `Fehler: ${result.error}`;
|
||||
}
|
||||
|
||||
return this.formatConversationDetails(result.data);
|
||||
return this.formatConversationDetails(result.data!);
|
||||
}
|
||||
|
||||
const number = parseInt(numberStr, 10);
|
||||
|
|
@ -361,7 +361,7 @@ export class MatrixService implements OnModuleInit {
|
|||
}
|
||||
|
||||
this.sessionService.setCurrentConversation(sender, conversationId);
|
||||
return `Gespraech ausgewaehlt: **${result.data.title}**\n\n${this.formatConversationDetails(result.data)}`;
|
||||
return `Gespraech ausgewaehlt: **${result.data!.title}**\n\n${this.formatConversationDetails(result.data!)}`;
|
||||
}
|
||||
|
||||
private formatConversationDetails(conv: Conversation): string {
|
||||
|
|
@ -413,17 +413,17 @@ Nutze \`!senden [nachricht]\` um zu chatten oder \`!verlauf\` fuer den Nachricht
|
|||
}));
|
||||
|
||||
// Get AI response
|
||||
const completionResult = await this.chatService.createCompletion(token, messages, convResult.data.modelId);
|
||||
const completionResult = await this.chatService.createCompletion(token, messages, convResult.data!.modelId);
|
||||
if (completionResult.error) {
|
||||
return `Fehler bei AI-Antwort: ${completionResult.error}`;
|
||||
}
|
||||
|
||||
// Save assistant response
|
||||
await this.chatService.addMessage(token, conversationId, completionResult.data.content, 'assistant');
|
||||
await this.chatService.addMessage(token, conversationId, completionResult.data!.content, 'assistant');
|
||||
|
||||
let response = completionResult.data.content;
|
||||
if (completionResult.data.usage) {
|
||||
response += `\n\n_Tokens: ${completionResult.data.usage.total_tokens}_`;
|
||||
let response = completionResult.data!.content;
|
||||
if (completionResult.data!.usage) {
|
||||
response += `\n\n_Tokens: ${completionResult.data!.usage.total_tokens}_`;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
|
@ -499,7 +499,7 @@ Nutze \`!senden [nachricht]\` um zu chatten oder \`!verlauf\` fuer den Nachricht
|
|||
return `Fehler: ${result.error}`;
|
||||
}
|
||||
|
||||
return `Titel geaendert zu: **${result.data.title}**`;
|
||||
return `Titel geaendert zu: **${result.data!.title}**`;
|
||||
}
|
||||
|
||||
private async handleArchive(sender: string, numberStr: string): Promise<string> {
|
||||
|
|
@ -527,7 +527,7 @@ Nutze \`!senden [nachricht]\` um zu chatten oder \`!verlauf\` fuer den Nachricht
|
|||
return `Fehler: ${result.error}`;
|
||||
}
|
||||
|
||||
return `Gespraech **${result.data.title}** archiviert.`;
|
||||
return `Gespraech **${result.data!.title}** archiviert.`;
|
||||
}
|
||||
|
||||
private async handleListArchived(sender: string): Promise<string> {
|
||||
|
|
@ -586,7 +586,7 @@ Nutze \`!senden [nachricht]\` um zu chatten oder \`!verlauf\` fuer den Nachricht
|
|||
return `Fehler: ${result.error}`;
|
||||
}
|
||||
|
||||
return `Gespraech **${result.data.title}** wiederhergestellt.`;
|
||||
return `Gespraech **${result.data!.title}** wiederhergestellt.`;
|
||||
}
|
||||
|
||||
private async handlePin(sender: string, numberStr: string): Promise<string> {
|
||||
|
|
@ -614,7 +614,7 @@ Nutze \`!senden [nachricht]\` um zu chatten oder \`!verlauf\` fuer den Nachricht
|
|||
return `Fehler: ${result.error}`;
|
||||
}
|
||||
|
||||
return `Gespraech **${result.data.title}** angepinnt. 📌`;
|
||||
return `Gespraech **${result.data!.title}** angepinnt. 📌`;
|
||||
}
|
||||
|
||||
private async handleUnpin(sender: string, numberStr: string): Promise<string> {
|
||||
|
|
@ -642,7 +642,7 @@ Nutze \`!senden [nachricht]\` um zu chatten oder \`!verlauf\` fuer den Nachricht
|
|||
return `Fehler: ${result.error}`;
|
||||
}
|
||||
|
||||
return `Pin fuer **${result.data.title}** entfernt.`;
|
||||
return `Pin fuer **${result.data!.title}** entfernt.`;
|
||||
}
|
||||
|
||||
private async handleDelete(sender: string, numberStr: string): Promise<string> {
|
||||
|
|
@ -728,8 +728,8 @@ Nutze \`!senden [nachricht]\` um zu chatten oder \`!verlauf\` fuer den Nachricht
|
|||
return 'Ausgewaehltes Modell nicht gefunden.';
|
||||
}
|
||||
|
||||
const icon = BRANCH_ICONS[result.data.provider] || BRANCH_ICONS.default;
|
||||
return `Aktuelles Modell: ${icon} **${result.data.name}**`;
|
||||
const icon = BRANCH_ICONS[result.data!.provider] || BRANCH_ICONS.default;
|
||||
return `Aktuelles Modell: ${icon} **${result.data!.name}**`;
|
||||
}
|
||||
|
||||
const number = parseInt(numberStr, 10);
|
||||
|
|
@ -748,7 +748,7 @@ Nutze \`!senden [nachricht]\` um zu chatten oder \`!verlauf\` fuer den Nachricht
|
|||
}
|
||||
|
||||
this.sessionService.setSelectedModel(sender, modelId);
|
||||
const icon = BRANCH_ICONS[result.data.provider] || BRANCH_ICONS.default;
|
||||
return `Modell gewaehlt: ${icon} **${result.data.name}**\nWird fuer neue Gespraeche und Quick-Chat verwendet.`;
|
||||
const icon = BRANCH_ICONS[result.data!.provider] || BRANCH_ICONS.default;
|
||||
return `Modell gewaehlt: ${icon} **${result.data!.name}**\nWird fuer neue Gespraeche und Quick-Chat verwendet.`;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export default () => ({
|
||||
port: parseInt(process.env.PORT, 10) || 3327,
|
||||
port: parseInt(process.env.PORT || '3327', 10),
|
||||
matrix: {
|
||||
homeserverUrl: process.env.MATRIX_HOMESERVER_URL || 'http://localhost:8008',
|
||||
accessToken: process.env.MATRIX_ACCESS_TOKEN,
|
||||
|
|
|
|||
|
|
@ -93,10 +93,10 @@ export class SessionService {
|
|||
}
|
||||
|
||||
// Current conversation management
|
||||
setCurrentConversation(matrixUserId: string, conversationId: string): void {
|
||||
setCurrentConversation(matrixUserId: string, conversationId: string | null): void {
|
||||
const session = this.sessions.get(matrixUserId);
|
||||
if (session) {
|
||||
session.currentConversationId = conversationId;
|
||||
session.currentConversationId = conversationId || undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ export class MatrixService implements OnModuleInit {
|
|||
return;
|
||||
}
|
||||
|
||||
const storage = new SimpleFsStorageProvider(storagePath);
|
||||
this.client = new MatrixClient(homeserverUrl, accessToken, storage);
|
||||
const storage = new SimpleFsStorageProvider(storagePath || './data/bot-storage.json');
|
||||
this.client = new MatrixClient(homeserverUrl || 'http://localhost:8008', accessToken, storage);
|
||||
|
||||
AutojoinRoomsMixin.setupOnClient(this.client);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export default () => ({
|
||||
port: parseInt(process.env.PORT, 10) || 3321,
|
||||
port: parseInt(process.env.PORT || '3321', 10),
|
||||
matrix: {
|
||||
homeserverUrl: process.env.MATRIX_HOMESERVER_URL || 'http://localhost:8008',
|
||||
accessToken: process.env.MATRIX_ACCESS_TOKEN,
|
||||
|
|
|
|||
|
|
@ -55,8 +55,8 @@ export class MatrixService implements OnModuleInit {
|
|||
return;
|
||||
}
|
||||
|
||||
const storage = new SimpleFsStorageProvider(storagePath);
|
||||
this.client = new MatrixClient(homeserverUrl, accessToken, storage);
|
||||
const storage = new SimpleFsStorageProvider(storagePath || './data/bot-storage.json');
|
||||
this.client = new MatrixClient(homeserverUrl || 'http://localhost:8008', accessToken, storage);
|
||||
|
||||
AutojoinRoomsMixin.setupOnClient(this.client);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export default () => ({
|
||||
port: parseInt(process.env.PORT, 10) || 3322,
|
||||
port: parseInt(process.env.PORT || '3322', 10),
|
||||
matrix: {
|
||||
homeserverUrl: process.env.MATRIX_HOMESERVER_URL || 'http://localhost:8008',
|
||||
accessToken: process.env.MATRIX_ACCESS_TOKEN,
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ export class MatrixService implements OnModuleInit {
|
|||
return;
|
||||
}
|
||||
|
||||
const storage = new SimpleFsStorageProvider(storagePath);
|
||||
this.client = new MatrixClient(homeserverUrl, accessToken, storage);
|
||||
const storage = new SimpleFsStorageProvider(storagePath || './data/bot-storage.json');
|
||||
this.client = new MatrixClient(homeserverUrl || 'http://localhost:8008', accessToken, storage);
|
||||
|
||||
AutojoinRoomsMixin.setupOnClient(this.client);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export default () => ({
|
||||
port: parseInt(process.env.PORT, 10) || 3325,
|
||||
port: parseInt(process.env.PORT || '3325', 10),
|
||||
matrix: {
|
||||
homeserverUrl: process.env.MATRIX_HOMESERVER_URL || 'http://localhost:8008',
|
||||
accessToken: process.env.MATRIX_ACCESS_TOKEN,
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ export class MatrixService implements OnModuleInit {
|
|||
return;
|
||||
}
|
||||
|
||||
const storage = new SimpleFsStorageProvider(storagePath);
|
||||
this.client = new MatrixClient(homeserverUrl, accessToken, storage);
|
||||
const storage = new SimpleFsStorageProvider(storagePath || './data/bot-storage.json');
|
||||
this.client = new MatrixClient(homeserverUrl || 'http://localhost:8008', accessToken, storage);
|
||||
|
||||
AutojoinRoomsMixin.setupOnClient(this.client);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export default () => ({
|
||||
port: parseInt(process.env.PORT, 10) || 3324,
|
||||
port: parseInt(process.env.PORT || '3324', 10),
|
||||
matrix: {
|
||||
homeserverUrl: process.env.MATRIX_HOMESERVER_URL || 'http://localhost:8008',
|
||||
accessToken: process.env.MATRIX_ACCESS_TOKEN,
|
||||
|
|
|
|||
|
|
@ -60,8 +60,8 @@ export class MatrixService implements OnModuleInit {
|
|||
return;
|
||||
}
|
||||
|
||||
const storage = new SimpleFsStorageProvider(storagePath);
|
||||
this.client = new MatrixClient(homeserverUrl, accessToken, storage);
|
||||
const storage = new SimpleFsStorageProvider(storagePath || './data/bot-storage.json');
|
||||
this.client = new MatrixClient(homeserverUrl || 'http://localhost:8008', accessToken, storage);
|
||||
|
||||
AutojoinRoomsMixin.setupOnClient(this.client);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export default () => ({
|
||||
port: parseInt(process.env.PORT, 10) || 3326,
|
||||
port: parseInt(process.env.PORT || '3326', 10),
|
||||
matrix: {
|
||||
homeserverUrl: process.env.MATRIX_HOMESERVER_URL || 'http://localhost:8008',
|
||||
accessToken: process.env.MATRIX_ACCESS_TOKEN,
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ export class MatrixService implements OnModuleInit {
|
|||
return;
|
||||
}
|
||||
|
||||
const storage = new SimpleFsStorageProvider(storagePath);
|
||||
this.client = new MatrixClient(homeserverUrl, accessToken, storage);
|
||||
const storage = new SimpleFsStorageProvider(storagePath || './data/bot-storage.json');
|
||||
this.client = new MatrixClient(homeserverUrl || 'http://localhost:8008', accessToken, storage);
|
||||
|
||||
AutojoinRoomsMixin.setupOnClient(this.client);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export default () => ({
|
||||
port: parseInt(process.env.PORT, 10) || 3323,
|
||||
port: parseInt(process.env.PORT || '3323', 10),
|
||||
matrix: {
|
||||
homeserverUrl: process.env.MATRIX_HOMESERVER_URL || 'http://localhost:8008',
|
||||
accessToken: process.env.MATRIX_ACCESS_TOKEN,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue