fix: improve logs (#2018)
Browse files- src/lib/jobs/refresh-conversation-stats.ts +5 -3
- src/lib/migrations/migrations.ts +1 -2
- src/lib/server/abortedGenerations.ts +1 -1
- src/lib/server/api/routes/groups/user.ts +1 -1
- src/lib/server/auth.ts +2 -2
- src/lib/server/database.ts +98 -33
- src/lib/server/exitHandler.ts +2 -2
- src/lib/server/textGeneration/generate.ts +2 -2
- src/lib/server/textGeneration/title.ts +2 -2
- src/routes/admin/stats/compute/+server.ts +1 -1
- src/routes/api/fetch-url/+server.ts +4 -4
- src/routes/conversation/[id]/+server.ts +1 -1
src/lib/jobs/refresh-conversation-stats.ts
CHANGED
|
@@ -19,12 +19,14 @@ async function shouldComputeStats(): Promise<boolean> {
|
|
| 19 |
export async function computeAllStats() {
|
| 20 |
for (const span of ["day", "week", "month"] as const) {
|
| 21 |
computeStats({ dateField: "updatedAt", type: "conversation", span }).catch((e) =>
|
| 22 |
-
logger.error(e)
|
| 23 |
);
|
| 24 |
computeStats({ dateField: "createdAt", type: "conversation", span }).catch((e) =>
|
| 25 |
-
logger.error(e)
|
|
|
|
|
|
|
|
|
|
| 26 |
);
|
| 27 |
-
computeStats({ dateField: "createdAt", type: "message", span }).catch((e) => logger.error(e));
|
| 28 |
}
|
| 29 |
}
|
| 30 |
|
|
|
|
| 19 |
export async function computeAllStats() {
|
| 20 |
for (const span of ["day", "week", "month"] as const) {
|
| 21 |
computeStats({ dateField: "updatedAt", type: "conversation", span }).catch((e) =>
|
| 22 |
+
logger.error(e, "Error computing conversation stats for updatedAt")
|
| 23 |
);
|
| 24 |
computeStats({ dateField: "createdAt", type: "conversation", span }).catch((e) =>
|
| 25 |
+
logger.error(e, "Error computing conversation stats for createdAt")
|
| 26 |
+
);
|
| 27 |
+
computeStats({ dateField: "createdAt", type: "message", span }).catch((e) =>
|
| 28 |
+
logger.error(e, "Error computing message stats for createdAt")
|
| 29 |
);
|
|
|
|
| 30 |
}
|
| 31 |
}
|
| 32 |
|
src/lib/migrations/migrations.ts
CHANGED
|
@@ -92,8 +92,7 @@ export async function checkAndRunMigrations() {
|
|
| 92 |
result = await migration.up(await Database.getInstance());
|
| 93 |
});
|
| 94 |
} catch (e) {
|
| 95 |
-
logger.
|
| 96 |
-
logger.error(e);
|
| 97 |
} finally {
|
| 98 |
await session.endSession();
|
| 99 |
}
|
|
|
|
| 92 |
result = await migration.up(await Database.getInstance());
|
| 93 |
});
|
| 94 |
} catch (e) {
|
| 95 |
+
logger.error(e, `[MIGRATIONS] "${migration.name}" failed!`);
|
|
|
|
| 96 |
} finally {
|
| 97 |
await session.endSession();
|
| 98 |
}
|
src/lib/server/abortedGenerations.ts
CHANGED
|
@@ -36,7 +36,7 @@ export class AbortedGenerations {
|
|
| 36 |
aborts.map((abort) => [abort.conversationId.toString(), abort.createdAt])
|
| 37 |
);
|
| 38 |
} catch (err) {
|
| 39 |
-
logger.error(err);
|
| 40 |
}
|
| 41 |
}
|
| 42 |
}
|
|
|
|
| 36 |
aborts.map((abort) => [abort.conversationId.toString(), abort.createdAt])
|
| 37 |
);
|
| 38 |
} catch (err) {
|
| 39 |
+
logger.error(err, "Error updating aborted generations list");
|
| 40 |
}
|
| 41 |
}
|
| 42 |
}
|
src/lib/server/api/routes/groups/user.ts
CHANGED
|
@@ -197,7 +197,7 @@ export const userGroup = new Elysia()
|
|
| 197 |
currentBillingOrg: isCurrentOrgValid ? currentBillingOrg : undefined,
|
| 198 |
};
|
| 199 |
} catch (err) {
|
| 200 |
-
logger.error("Error fetching billing orgs:"
|
| 201 |
set.status = 500;
|
| 202 |
return { error: "Internal server error" };
|
| 203 |
}
|
|
|
|
| 197 |
currentBillingOrg: isCurrentOrgValid ? currentBillingOrg : undefined,
|
| 198 |
};
|
| 199 |
} catch (err) {
|
| 200 |
+
logger.error(err, "Error fetching billing orgs:");
|
| 201 |
set.status = 500;
|
| 202 |
return { error: "Internal server error" };
|
| 203 |
}
|
src/lib/server/auth.ts
CHANGED
|
@@ -153,7 +153,7 @@ export async function findUser(
|
|
| 153 |
|
| 154 |
session.oauth = updatedOAuth;
|
| 155 |
} catch (err) {
|
| 156 |
-
logger.error("Error during token refresh:"
|
| 157 |
return { user: null, invalidateSession: true };
|
| 158 |
} finally {
|
| 159 |
await releaseLock(lockKey, lockId);
|
|
@@ -374,7 +374,7 @@ export async function validateAndParseCsrfToken(
|
|
| 374 |
return { redirectUrl: data.redirectUrl, next: sanitizeReturnPath(data.next) };
|
| 375 |
}
|
| 376 |
} catch (e) {
|
| 377 |
-
logger.error(e);
|
| 378 |
}
|
| 379 |
return null;
|
| 380 |
}
|
|
|
|
| 153 |
|
| 154 |
session.oauth = updatedOAuth;
|
| 155 |
} catch (err) {
|
| 156 |
+
logger.error(err, "Error during token refresh:");
|
| 157 |
return { user: null, invalidateSession: true };
|
| 158 |
} finally {
|
| 159 |
await releaseLock(lockKey, lockId);
|
|
|
|
| 374 |
return { redirectUrl: data.redirectUrl, next: sanitizeReturnPath(data.next) };
|
| 375 |
}
|
| 376 |
} catch (e) {
|
| 377 |
+
logger.error(e, "Error validating and parsing CSRF token");
|
| 378 |
}
|
| 379 |
return null;
|
| 380 |
}
|
src/lib/server/database.ts
CHANGED
|
@@ -72,7 +72,7 @@ export class Database {
|
|
| 72 |
this.client.db(config.MONGODB_DB_NAME + (import.meta.env.MODE === "test" ? "-test" : ""));
|
| 73 |
await this.initDatabase();
|
| 74 |
} catch (err) {
|
| 75 |
-
logger.error(err, "
|
| 76 |
process.exit(1);
|
| 77 |
}
|
| 78 |
|
|
@@ -182,24 +182,32 @@ export class Database {
|
|
| 182 |
{ sessionId: 1, updatedAt: -1 },
|
| 183 |
{ partialFilterExpression: { sessionId: { $exists: true } } }
|
| 184 |
)
|
| 185 |
-
.catch((e) =>
|
|
|
|
|
|
|
| 186 |
conversations
|
| 187 |
.createIndex(
|
| 188 |
{ userId: 1, updatedAt: -1 },
|
| 189 |
{ partialFilterExpression: { userId: { $exists: true } } }
|
| 190 |
)
|
| 191 |
-
.catch((e) =>
|
|
|
|
|
|
|
| 192 |
conversations
|
| 193 |
.createIndex(
|
| 194 |
{ "message.id": 1, "message.ancestors": 1 },
|
| 195 |
{ partialFilterExpression: { userId: { $exists: true } } }
|
| 196 |
)
|
| 197 |
-
.catch((e) =>
|
|
|
|
|
|
|
| 198 |
// Not strictly necessary, could use _id, but more convenient. Also for stats
|
| 199 |
// To do stats on conversation messages
|
| 200 |
conversations
|
| 201 |
.createIndex({ "messages.createdAt": 1 }, { sparse: true })
|
| 202 |
-
.catch((e) =>
|
|
|
|
|
|
|
| 203 |
// Unique index for stats
|
| 204 |
conversationStats
|
| 205 |
.createIndex(
|
|
@@ -212,7 +220,12 @@ export class Database {
|
|
| 212 |
},
|
| 213 |
{ unique: true }
|
| 214 |
)
|
| 215 |
-
.catch((e) =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
// Allow easy check of last computed stat for given type/dateField
|
| 217 |
conversationStats
|
| 218 |
.createIndex({
|
|
@@ -220,57 +233,103 @@ export class Database {
|
|
| 220 |
"date.field": 1,
|
| 221 |
"date.at": 1,
|
| 222 |
})
|
| 223 |
-
.catch((e) => logger.error(e));
|
| 224 |
abortedGenerations
|
| 225 |
.createIndex({ updatedAt: 1 }, { expireAfterSeconds: 30 })
|
| 226 |
-
.catch((e) =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
abortedGenerations
|
| 228 |
.createIndex({ conversationId: 1 }, { unique: true })
|
| 229 |
-
.catch((e) =>
|
|
|
|
|
|
|
| 230 |
sharedConversations.createIndex({ hash: 1 }, { unique: true }).catch((e) => logger.error(e));
|
| 231 |
settings
|
| 232 |
.createIndex({ sessionId: 1 }, { unique: true, sparse: true })
|
| 233 |
-
.catch((e) => logger.error(e));
|
| 234 |
settings
|
| 235 |
.createIndex({ userId: 1 }, { unique: true, sparse: true })
|
| 236 |
-
.catch((e) => logger.error(e));
|
| 237 |
-
settings
|
| 238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
users
|
| 240 |
.createIndex({ sessionId: 1 }, { unique: true, sparse: true })
|
| 241 |
-
.catch((e) => logger.error(e));
|
| 242 |
// No unicity because due to renames & outdated info from oauth provider, there may be the same username on different users
|
| 243 |
-
users
|
|
|
|
|
|
|
| 244 |
messageEvents
|
| 245 |
.createIndex({ expiresAt: 1 }, { expireAfterSeconds: 1 })
|
| 246 |
-
.catch((e) => logger.error(e));
|
| 247 |
sessions.createIndex({ expiresAt: 1 }, { expireAfterSeconds: 0 }).catch((e) => logger.error(e));
|
| 248 |
-
sessions
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
assistants
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
assistants
|
| 256 |
.createIndex({ last24HoursUseCount: -1, useCount: -1, _id: 1 })
|
| 257 |
-
.catch((e) =>
|
|
|
|
|
|
|
| 258 |
assistantStats
|
| 259 |
// Order of keys is important for the queries
|
| 260 |
.createIndex({ "date.span": 1, "date.at": 1, assistantId: 1 }, { unique: true })
|
| 261 |
-
.catch((e) =>
|
| 262 |
-
|
| 263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
| 265 |
// Unique index for semaphore and migration results
|
| 266 |
semaphores.createIndex({ key: 1 }, { unique: true }).catch((e) => logger.error(e));
|
| 267 |
semaphores
|
| 268 |
.createIndex({ deleteAt: 1 }, { expireAfterSeconds: 1 })
|
| 269 |
-
.catch((e) => logger.error(e));
|
| 270 |
tokenCaches
|
| 271 |
.createIndex({ createdAt: 1 }, { expireAfterSeconds: 5 * 60 })
|
| 272 |
-
.catch((e) => logger.error(e));
|
| 273 |
-
tokenCaches
|
|
|
|
|
|
|
| 274 |
// Tools removed: skipping tools indexes
|
| 275 |
|
| 276 |
conversations
|
|
@@ -278,16 +337,22 @@ export class Database {
|
|
| 278 |
"messages.from": 1,
|
| 279 |
createdAt: 1,
|
| 280 |
})
|
| 281 |
-
.catch((e) =>
|
|
|
|
|
|
|
| 282 |
|
| 283 |
conversations
|
| 284 |
.createIndex({
|
| 285 |
userId: 1,
|
| 286 |
sessionId: 1,
|
| 287 |
})
|
| 288 |
-
.catch((e) =>
|
|
|
|
|
|
|
| 289 |
|
| 290 |
-
config
|
|
|
|
|
|
|
| 291 |
}
|
| 292 |
}
|
| 293 |
|
|
|
|
| 72 |
this.client.db(config.MONGODB_DB_NAME + (import.meta.env.MODE === "test" ? "-test" : ""));
|
| 73 |
await this.initDatabase();
|
| 74 |
} catch (err) {
|
| 75 |
+
logger.error(err, "Error connecting to database");
|
| 76 |
process.exit(1);
|
| 77 |
}
|
| 78 |
|
|
|
|
| 182 |
{ sessionId: 1, updatedAt: -1 },
|
| 183 |
{ partialFilterExpression: { sessionId: { $exists: true } } }
|
| 184 |
)
|
| 185 |
+
.catch((e) =>
|
| 186 |
+
logger.error(e, "Error creating index for conversations by sessionId and updatedAt")
|
| 187 |
+
);
|
| 188 |
conversations
|
| 189 |
.createIndex(
|
| 190 |
{ userId: 1, updatedAt: -1 },
|
| 191 |
{ partialFilterExpression: { userId: { $exists: true } } }
|
| 192 |
)
|
| 193 |
+
.catch((e) =>
|
| 194 |
+
logger.error(e, "Error creating index for conversations by userId and updatedAt")
|
| 195 |
+
);
|
| 196 |
conversations
|
| 197 |
.createIndex(
|
| 198 |
{ "message.id": 1, "message.ancestors": 1 },
|
| 199 |
{ partialFilterExpression: { userId: { $exists: true } } }
|
| 200 |
)
|
| 201 |
+
.catch((e) =>
|
| 202 |
+
logger.error(e, "Error creating index for conversations by messageId and ancestors")
|
| 203 |
+
);
|
| 204 |
// Not strictly necessary, could use _id, but more convenient. Also for stats
|
| 205 |
// To do stats on conversation messages
|
| 206 |
conversations
|
| 207 |
.createIndex({ "messages.createdAt": 1 }, { sparse: true })
|
| 208 |
+
.catch((e) =>
|
| 209 |
+
logger.error(e, "Error creating index for conversations by messages createdAt")
|
| 210 |
+
);
|
| 211 |
// Unique index for stats
|
| 212 |
conversationStats
|
| 213 |
.createIndex(
|
|
|
|
| 220 |
},
|
| 221 |
{ unique: true }
|
| 222 |
)
|
| 223 |
+
.catch((e) =>
|
| 224 |
+
logger.error(
|
| 225 |
+
e,
|
| 226 |
+
"Error creating index for conversationStats by type, date.field and date.span"
|
| 227 |
+
)
|
| 228 |
+
);
|
| 229 |
// Allow easy check of last computed stat for given type/dateField
|
| 230 |
conversationStats
|
| 231 |
.createIndex({
|
|
|
|
| 233 |
"date.field": 1,
|
| 234 |
"date.at": 1,
|
| 235 |
})
|
| 236 |
+
.catch((e) => logger.error(e, "Error creating index for abortedGenerations by updatedAt"));
|
| 237 |
abortedGenerations
|
| 238 |
.createIndex({ updatedAt: 1 }, { expireAfterSeconds: 30 })
|
| 239 |
+
.catch((e) =>
|
| 240 |
+
logger.error(
|
| 241 |
+
e,
|
| 242 |
+
"Error creating index for abortedGenerations by updatedAt and expireAfterSeconds"
|
| 243 |
+
)
|
| 244 |
+
);
|
| 245 |
abortedGenerations
|
| 246 |
.createIndex({ conversationId: 1 }, { unique: true })
|
| 247 |
+
.catch((e) =>
|
| 248 |
+
logger.error(e, "Error creating index for abortedGenerations by conversationId")
|
| 249 |
+
);
|
| 250 |
sharedConversations.createIndex({ hash: 1 }, { unique: true }).catch((e) => logger.error(e));
|
| 251 |
settings
|
| 252 |
.createIndex({ sessionId: 1 }, { unique: true, sparse: true })
|
| 253 |
+
.catch((e) => logger.error(e, "Error creating index for settings by sessionId"));
|
| 254 |
settings
|
| 255 |
.createIndex({ userId: 1 }, { unique: true, sparse: true })
|
| 256 |
+
.catch((e) => logger.error(e, "Error creating index for settings by userId"));
|
| 257 |
+
settings
|
| 258 |
+
.createIndex({ assistants: 1 })
|
| 259 |
+
.catch((e) => logger.error(e, "Error creating index for settings by assistants"));
|
| 260 |
+
users
|
| 261 |
+
.createIndex({ hfUserId: 1 }, { unique: true })
|
| 262 |
+
.catch((e) => logger.error(e, "Error creating index for users by hfUserId"));
|
| 263 |
users
|
| 264 |
.createIndex({ sessionId: 1 }, { unique: true, sparse: true })
|
| 265 |
+
.catch((e) => logger.error(e, "Error creating index for users by sessionId"));
|
| 266 |
// No unicity because due to renames & outdated info from oauth provider, there may be the same username on different users
|
| 267 |
+
users
|
| 268 |
+
.createIndex({ username: 1 })
|
| 269 |
+
.catch((e) => logger.error(e, "Error creating index for users by username"));
|
| 270 |
messageEvents
|
| 271 |
.createIndex({ expiresAt: 1 }, { expireAfterSeconds: 1 })
|
| 272 |
+
.catch((e) => logger.error(e, "Error creating index for messageEvents by expiresAt"));
|
| 273 |
sessions.createIndex({ expiresAt: 1 }, { expireAfterSeconds: 0 }).catch((e) => logger.error(e));
|
| 274 |
+
sessions
|
| 275 |
+
.createIndex({ sessionId: 1 }, { unique: true })
|
| 276 |
+
.catch((e) => logger.error(e, "Error creating index for sessions by sessionId"));
|
| 277 |
+
assistants
|
| 278 |
+
.createIndex({ createdById: 1, userCount: -1 })
|
| 279 |
+
.catch((e) =>
|
| 280 |
+
logger.error(e, "Error creating index for assistants by createdById and userCount")
|
| 281 |
+
);
|
| 282 |
+
assistants
|
| 283 |
+
.createIndex({ userCount: 1 })
|
| 284 |
+
.catch((e) => logger.error(e, "Error creating index for assistants by userCount"));
|
| 285 |
+
assistants
|
| 286 |
+
.createIndex({ review: 1, userCount: -1 })
|
| 287 |
+
.catch((e) => logger.error(e, "Error creating index for assistants by review and userCount"));
|
| 288 |
+
assistants
|
| 289 |
+
.createIndex({ modelId: 1, userCount: -1 })
|
| 290 |
+
.catch((e) =>
|
| 291 |
+
logger.error(e, "Error creating index for assistants by modelId and userCount")
|
| 292 |
+
);
|
| 293 |
+
assistants
|
| 294 |
+
.createIndex({ searchTokens: 1 })
|
| 295 |
+
.catch((e) => logger.error(e, "Error creating index for assistants by searchTokens"));
|
| 296 |
+
assistants
|
| 297 |
+
.createIndex({ last24HoursCount: 1 })
|
| 298 |
+
.catch((e) => logger.error(e, "Error creating index for assistants by last24HoursCount"));
|
| 299 |
assistants
|
| 300 |
.createIndex({ last24HoursUseCount: -1, useCount: -1, _id: 1 })
|
| 301 |
+
.catch((e) =>
|
| 302 |
+
logger.error(e, "Error creating index for assistants by last24HoursUseCount and useCount")
|
| 303 |
+
);
|
| 304 |
assistantStats
|
| 305 |
// Order of keys is important for the queries
|
| 306 |
.createIndex({ "date.span": 1, "date.at": 1, assistantId: 1 }, { unique: true })
|
| 307 |
+
.catch((e) =>
|
| 308 |
+
logger.error(
|
| 309 |
+
e,
|
| 310 |
+
"Error creating index for assistantStats by date.span and date.at and assistantId"
|
| 311 |
+
)
|
| 312 |
+
);
|
| 313 |
+
reports
|
| 314 |
+
.createIndex({ assistantId: 1 })
|
| 315 |
+
.catch((e) => logger.error(e, "Error creating index for reports by assistantId"));
|
| 316 |
+
reports
|
| 317 |
+
.createIndex({ createdBy: 1, assistantId: 1 })
|
| 318 |
+
.catch((e) =>
|
| 319 |
+
logger.error(e, "Error creating index for reports by createdBy and assistantId")
|
| 320 |
+
);
|
| 321 |
|
| 322 |
// Unique index for semaphore and migration results
|
| 323 |
semaphores.createIndex({ key: 1 }, { unique: true }).catch((e) => logger.error(e));
|
| 324 |
semaphores
|
| 325 |
.createIndex({ deleteAt: 1 }, { expireAfterSeconds: 1 })
|
| 326 |
+
.catch((e) => logger.error(e, "Error creating index for semaphores by deleteAt"));
|
| 327 |
tokenCaches
|
| 328 |
.createIndex({ createdAt: 1 }, { expireAfterSeconds: 5 * 60 })
|
| 329 |
+
.catch((e) => logger.error(e, "Error creating index for tokenCaches by createdAt"));
|
| 330 |
+
tokenCaches
|
| 331 |
+
.createIndex({ tokenHash: 1 })
|
| 332 |
+
.catch((e) => logger.error(e, "Error creating index for tokenCaches by tokenHash"));
|
| 333 |
// Tools removed: skipping tools indexes
|
| 334 |
|
| 335 |
conversations
|
|
|
|
| 337 |
"messages.from": 1,
|
| 338 |
createdAt: 1,
|
| 339 |
})
|
| 340 |
+
.catch((e) =>
|
| 341 |
+
logger.error(e, "Error creating index for conversations by messages from and createdAt")
|
| 342 |
+
);
|
| 343 |
|
| 344 |
conversations
|
| 345 |
.createIndex({
|
| 346 |
userId: 1,
|
| 347 |
sessionId: 1,
|
| 348 |
})
|
| 349 |
+
.catch((e) =>
|
| 350 |
+
logger.error(e, "Error creating index for conversations by userId and sessionId")
|
| 351 |
+
);
|
| 352 |
|
| 353 |
+
config
|
| 354 |
+
.createIndex({ key: 1 }, { unique: true })
|
| 355 |
+
.catch((e) => logger.error(e, "Error creating index for config by key"));
|
| 356 |
}
|
| 357 |
}
|
| 358 |
|
src/lib/server/exitHandler.ts
CHANGED
|
@@ -38,7 +38,7 @@ export function initExitHandler() {
|
|
| 38 |
process.kill(process.pid, "SIGKILL");
|
| 39 |
} else {
|
| 40 |
exitHandler().catch((err) => {
|
| 41 |
-
logger.error("
|
| 42 |
process.kill(process.pid, "SIGKILL");
|
| 43 |
});
|
| 44 |
}
|
|
@@ -51,7 +51,7 @@ export function initExitHandler() {
|
|
| 51 |
process.kill(process.pid, "SIGKILL");
|
| 52 |
} else {
|
| 53 |
exitHandler().catch((err) => {
|
| 54 |
-
logger.error("
|
| 55 |
process.kill(process.pid, "SIGKILL");
|
| 56 |
});
|
| 57 |
}
|
|
|
|
| 38 |
process.kill(process.pid, "SIGKILL");
|
| 39 |
} else {
|
| 40 |
exitHandler().catch((err) => {
|
| 41 |
+
logger.error(err, "Error in exit handler on SIGINT:");
|
| 42 |
process.kill(process.pid, "SIGKILL");
|
| 43 |
});
|
| 44 |
}
|
|
|
|
| 51 |
process.kill(process.pid, "SIGKILL");
|
| 52 |
} else {
|
| 53 |
exitHandler().catch((err) => {
|
| 54 |
+
logger.error(err, "Error in exit handler on SIGTERM:");
|
| 55 |
process.kill(process.pid, "SIGKILL");
|
| 56 |
});
|
| 57 |
}
|
src/lib/server/textGeneration/generate.ts
CHANGED
|
@@ -125,7 +125,7 @@ export async function* generate(
|
|
| 125 |
};
|
| 126 |
} catch (e) {
|
| 127 |
finalAnswer = text;
|
| 128 |
-
logger.error(e);
|
| 129 |
}
|
| 130 |
} else if (modelReasoning && modelReasoning.type === "tokens") {
|
| 131 |
// Remove the reasoning segment from final answer to avoid duplication
|
|
@@ -216,7 +216,7 @@ export async function* generate(
|
|
| 216 |
status = summary;
|
| 217 |
});
|
| 218 |
} catch (e) {
|
| 219 |
-
logger.error(e);
|
| 220 |
}
|
| 221 |
}
|
| 222 |
|
|
|
|
| 125 |
};
|
| 126 |
} catch (e) {
|
| 127 |
finalAnswer = text;
|
| 128 |
+
logger.error(e, "Error generating summary of reasoning");
|
| 129 |
}
|
| 130 |
} else if (modelReasoning && modelReasoning.type === "tokens") {
|
| 131 |
// Remove the reasoning segment from final answer to avoid duplication
|
|
|
|
| 216 |
status = summary;
|
| 217 |
});
|
| 218 |
} catch (e) {
|
| 219 |
+
logger.error(e, "Error generating summary of reasoning");
|
| 220 |
}
|
| 221 |
}
|
| 222 |
|
src/lib/server/textGeneration/title.ts
CHANGED
|
@@ -23,7 +23,7 @@ export async function* generateTitleForConversation(
|
|
| 23 |
title,
|
| 24 |
};
|
| 25 |
} catch (cause) {
|
| 26 |
-
logger.error(
|
| 27 |
}
|
| 28 |
}
|
| 29 |
|
|
@@ -74,7 +74,7 @@ Return only the title text.`,
|
|
| 74 |
return trimmed || firstFive;
|
| 75 |
})
|
| 76 |
.catch((e) => {
|
| 77 |
-
logger.error(e);
|
| 78 |
const firstFive = prompt.split(/\s+/g).slice(0, 5).join(" ");
|
| 79 |
return firstFive;
|
| 80 |
});
|
|
|
|
| 23 |
title,
|
| 24 |
};
|
| 25 |
} catch (cause) {
|
| 26 |
+
logger.error(cause, "Failed while generating title for conversation");
|
| 27 |
}
|
| 28 |
}
|
| 29 |
|
|
|
|
| 74 |
return trimmed || firstFive;
|
| 75 |
})
|
| 76 |
.catch((e) => {
|
| 77 |
+
logger.error(e, "Error generating title");
|
| 78 |
const firstFive = prompt.split(/\s+/g).slice(0, 5).join(" ");
|
| 79 |
return firstFive;
|
| 80 |
});
|
src/routes/admin/stats/compute/+server.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { computeAllStats } from "$lib/jobs/refresh-conversation-stats";
|
|
| 6 |
// curl -X POST "http://localhost:5173/chat/admin/stats/compute" -H "Authorization: Bearer <ADMIN_API_SECRET>"
|
| 7 |
|
| 8 |
export async function POST() {
|
| 9 |
-
computeAllStats().catch((e) => logger.error(e));
|
| 10 |
return json(
|
| 11 |
{
|
| 12 |
message: "Stats job started",
|
|
|
|
| 6 |
// curl -X POST "http://localhost:5173/chat/admin/stats/compute" -H "Authorization: Bearer <ADMIN_API_SECRET>"
|
| 7 |
|
| 8 |
export async function POST() {
|
| 9 |
+
computeAllStats().catch((e) => logger.error(e, "Error computing all stats"));
|
| 10 |
return json(
|
| 11 |
{
|
| 12 |
message: "Stats job started",
|
src/routes/api/fetch-url/+server.ts
CHANGED
|
@@ -40,7 +40,7 @@ export async function GET({ url }) {
|
|
| 40 |
}).finally(() => clearTimeout(timeoutId));
|
| 41 |
|
| 42 |
if (!response.ok) {
|
| 43 |
-
logger.error({ targetUrl, response },
|
| 44 |
throw error(response.status, `Failed to fetch: ${response.statusText}`);
|
| 45 |
}
|
| 46 |
|
|
@@ -75,14 +75,14 @@ export async function GET({ url }) {
|
|
| 75 |
} catch (err) {
|
| 76 |
if (err instanceof Error) {
|
| 77 |
if (err.name === "AbortError") {
|
| 78 |
-
logger.error(err,
|
| 79 |
throw error(504, "Request timeout");
|
| 80 |
}
|
| 81 |
|
| 82 |
-
logger.error(err,
|
| 83 |
throw error(500, `Failed to fetch URL: ${err.message}`);
|
| 84 |
}
|
| 85 |
-
logger.error(err,
|
| 86 |
throw error(500, "Failed to fetch URL.");
|
| 87 |
}
|
| 88 |
}
|
|
|
|
| 40 |
}).finally(() => clearTimeout(timeoutId));
|
| 41 |
|
| 42 |
if (!response.ok) {
|
| 43 |
+
logger.error({ targetUrl, response }, "Error fetching URL. Response not ok.");
|
| 44 |
throw error(response.status, `Failed to fetch: ${response.statusText}`);
|
| 45 |
}
|
| 46 |
|
|
|
|
| 75 |
} catch (err) {
|
| 76 |
if (err instanceof Error) {
|
| 77 |
if (err.name === "AbortError") {
|
| 78 |
+
logger.error(err, "Request timeout");
|
| 79 |
throw error(504, "Request timeout");
|
| 80 |
}
|
| 81 |
|
| 82 |
+
logger.error(err, "Error fetching URL");
|
| 83 |
throw error(500, `Failed to fetch URL: ${err.message}`);
|
| 84 |
}
|
| 85 |
+
logger.error(err, "Error fetching URL");
|
| 86 |
throw error(500, "Failed to fetch URL.");
|
| 87 |
}
|
| 88 |
}
|
src/routes/conversation/[id]/+server.ts
CHANGED
|
@@ -602,7 +602,7 @@ export async function POST({ request, locals, params, getClientAddress }) {
|
|
| 602 |
message: err.message,
|
| 603 |
...(statusCode && { statusCode }),
|
| 604 |
});
|
| 605 |
-
logger.error(err);
|
| 606 |
}
|
| 607 |
} finally {
|
| 608 |
// check if no output was generated
|
|
|
|
| 602 |
message: err.message,
|
| 603 |
...(statusCode && { statusCode }),
|
| 604 |
});
|
| 605 |
+
logger.error(err, "Error in conversation stream");
|
| 606 |
}
|
| 607 |
} finally {
|
| 608 |
// check if no output was generated
|