From 9f78d4e73407ad48cf05e4d09f3e7569f703e04d Mon Sep 17 00:00:00 2001 From: Alexander Piskun Date: Tue, 17 Feb 2026 19:53:03 +0200 Subject: [PATCH] fix: normalize millisecond timestamps in chat API Third-party clients may send timestamps in milliseconds instead of seconds. Detect and convert them in newSession() and newMessage() to prevent inconsistent formatting in the chat UI. Closes #452 Signed-off-by: Alexander Piskun --- lib/Controller/ChattyLLMController.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Controller/ChattyLLMController.php b/lib/Controller/ChattyLLMController.php index 3de4b83d..3931abad 100644 --- a/lib/Controller/ChattyLLMController.php +++ b/lib/Controller/ChattyLLMController.php @@ -121,6 +121,9 @@ private function improveAgencyActionNames(array $actions): array { #[NoAdminRequired] #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT, tags: ['chat_api'])] public function newSession(int $timestamp, ?string $title = null): JSONResponse { + if ($timestamp > 10_000_000_000) { + $timestamp = intdiv($timestamp, 1000); + } if ($this->userId === null) { return new JSONResponse(['error' => $this->l10n->t('User not logged in')], Http::STATUS_UNAUTHORIZED); } @@ -334,6 +337,9 @@ public function getSessions(): JSONResponse { public function newMessage( int $sessionId, string $role, string $content, int $timestamp, ?array $attachments = null, bool $firstHumanMessage = false, ): JSONResponse { + if ($timestamp > 10_000_000_000) { + $timestamp = intdiv($timestamp, 1000); + } if ($this->userId === null) { return new JSONResponse(['error' => $this->l10n->t('User not logged in')], Http::STATUS_UNAUTHORIZED); }