Răsfoiți Sursa

Guest thread ids break on .

Aleksandr Trofimov 3 săptămâni în urmă
părinte
comite
782bc53954
2 a modificat fișierele cu 16 adăugiri și 16 ștergeri
  1. 11 11
      inc/classes/BxDolAiChat.php
  2. 5 5
      inc/classes/BxDolAiQuery.php

+ 11 - 11
inc/classes/BxDolAiChat.php

@@ -42,7 +42,7 @@ class BxDolAiChat
 
     /**
      * Optional `?chat=` partition. Not identity — owner stays profile id / session id.
-     * `{owner}.{chat}` so parseThreadId does not treat the nonce as a context pid.
+     * `{owner}#{chat}` so parseThreadId does not treat the nonce as a context pid.
      */
     public static function sanitizeChatQueryId($s)
     {
@@ -53,14 +53,14 @@ class BxDolAiChat
     }
 
     /**
-     * Owner (profile id or guest session id) of a `{owner}` / `{owner}.{chat}` subindex.
+     * Owner (profile id or guest session id) of a `{owner}` / `{owner}#{chat}` subindex.
      */
     public static function chatHistoryOwnerFromSubindex($sSub)
     {
         $sSub = (string)$sSub;
         if ($sSub === '')
             return '';
-        $i = strpos($sSub, '.');
+        $i = strpos($sSub, '#');
         return $i === false ? $sSub : substr($sSub, 0, $i);
     }
 
@@ -96,7 +96,7 @@ class BxDolAiChat
             $sOwner = (string)$iProfileId;
             return [
                 'sender_profile_id' => $iProfileId,
-                'chat_history_subindex' => $sChat !== '' ? ($sOwner . '.' . $sChat) : $sOwner,
+                'chat_history_subindex' => $sChat !== '' ? ($sOwner . '#' . $sChat) : $sOwner,
             ];
         }
 
@@ -112,14 +112,14 @@ class BxDolAiChat
         $sOwner = (string)$oSession->getId();
         return [
             'sender_profile_id' => 0,
-            'chat_history_subindex' => $sChat !== '' ? ($sOwner . '.' . $sChat) : $sOwner,
+            'chat_history_subindex' => $sChat !== '' ? ($sOwner . '#' . $sChat) : $sOwner,
         ];
     }
 
     /**
      * `{trigger}:{agentId}:{contextPid}:{userSubindex}`.
      * Context is omitted when 0 so existing site-wide threads still load.
-     * User suffix (session id or profile id, optionally `.{chat}`) stays last so adopt can replace it.
+     * User suffix (session id or profile id, optionally `#{chat}`) stays last so adopt can replace it.
      */
     public static function threadId($aAgent, $aParams = [])
     {
@@ -186,13 +186,13 @@ class BxDolAiChat
      * or the base thread). Otherwise a block without `allow_new` would keep talking
      * to a base thread the agent closed days ago, while Studio shows a newer chat.
      *
-     * Explicit `?chat=` (subindex with a dot) is left alone. Falls back to the base
+     * Explicit `?chat=` (subindex with a #) is left alone. Falls back to the base
      * thread when nothing is open.
      */
     public function resolveCurrentChatThread($aAgent, $aParams)
     {
         $sSub = (string)($aParams['chat_history_subindex'] ?? '');
-        if ($sSub === '' || strpos($sSub, '.') !== false)
+        if ($sSub === '' || strpos($sSub, '#') !== false)
             return $aParams;
 
         $sCurrent = $this->_oDb->getCurrentOpenChatThreadId($aAgent, $sSub, (int)($aParams['chat_history_context_pid'] ?? 0));
@@ -219,7 +219,7 @@ class BxDolAiChat
     public function openPartitionedChatThread($aAgent, $aParams)
     {
         $sSub = (string)($aParams['chat_history_subindex'] ?? '');
-        if (strpos($sSub, '.') === false)
+        if (strpos($sSub, '#') === false)
             return 0;
 
         $sThreadId = self::threadId($aAgent, $aParams);
@@ -372,7 +372,7 @@ class BxDolAiChat
 
             $aUi = $this->_oUi->storedChatJsonToUiMessages($aRow['messages'] ?? '');
             // A `?chat=` thread is listed even before its first message (it was opened on purpose).
-            $bPartition = strpos((string)$aParsed['chat_history_subindex'], '.') !== false;
+            $bPartition = strpos((string)$aParsed['chat_history_subindex'], '#') !== false;
             if (!$aUi && $sThreadId !== $sMyDefault && !$bPartition)
                 continue;
 
@@ -658,7 +658,7 @@ class BxDolAiChat
         }
 
         $sSub = (string)$aParsed['chat_history_subindex'];
-        $iDot = strpos($sSub, '.');
+        $iDot = strpos($sSub, '#');
         $sChat = $iDot === false ? '' : substr($sSub, $iDot + 1);
 
         $sTitle = trim((string)($aRow['title'] ?? ''));

+ 5 - 5
inc/classes/BxDolAiQuery.php

@@ -303,9 +303,9 @@ class BxDolAiQuery extends BxDolDb
             ORDER BY `updated_at` DESC, `id` DESC
             LIMIT " . (int)$iLimit, [
             'site' => $sPrefix . ':' . $sOwner,
-            'site_chat' => $sPrefix . ':' . $sOwnerLike . '.%',
+            'site_chat' => $sPrefix . ':' . $sOwnerLike . '#%',
             'ctx' => $sPrefix . ':%:' . $sOwnerLike,
-            'ctx_chat' => $sPrefix . ':%:' . $sOwnerLike . '.%',
+            'ctx_chat' => $sPrefix . ':%:' . $sOwnerLike . '#%',
         ]);
     }
 
@@ -330,13 +330,13 @@ class BxDolAiQuery extends BxDolDb
         return (string)$this->getOne("
             SELECT `thread_id`
             FROM `sys_agents_chat_history`
-            WHERE (`thread_id` = :exact OR `thread_id` LIKE :dot)
+            WHERE (`thread_id` = :exact OR `thread_id` LIKE :hash)
               AND (`closed_reason` = '' OR `closed_reason` IS NULL)
             ORDER BY `updated_at` DESC, `id` DESC
             LIMIT 1
         ", [
             'exact' => $sBase,
-            'dot' => $sBase . '.%',
+            'hash' => $sBase . '#%',
         ]);
     }
 
@@ -563,7 +563,7 @@ class BxDolAiQuery extends BxDolDb
     }
 
     /**
-     * Rename this agent's guest threads (`…:{sessionId}` or `…:{sessionId}.{chat}`) onto a profile id.
+     * Rename this agent's guest threads (`…:{sessionId}` or `…:{sessionId}#{chat}`) onto a profile id.
      * If the member thread already has messages, drop the guest copy.
      */
     public function adoptGuestChatHistory($aAgent, $sSessionId, $iProfileId)