@nexo-labs/payload-typesense 1.6.5 → 1.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -782,7 +782,8 @@ async function fetchChunkById(client, config) {
782
782
  * @returns Promise with session data or null
783
783
  */
784
784
  async function getActiveSession(payload, userId, config = {}) {
785
- const collectionName = config.collectionName || "chat-sessions";
785
+ const collectionName = config.collectionName;
786
+ if (!collectionName) throw new Error("Collection name is required to get active session");
786
787
  const windowMs = config.activeSessionWindow || 1440 * 60 * 1e3;
787
788
  const cutoffTime = new Date(Date.now() - windowMs);
788
789
  const chatSessions = await payload.find({
@@ -808,7 +809,8 @@ async function getActiveSession(payload, userId, config = {}) {
808
809
  * @returns Promise with session data or null
809
810
  */
810
811
  async function getSessionByConversationId(payload, userId, conversationId, config = {}) {
811
- const collectionName = config.collectionName || "chat-sessions";
812
+ const collectionName = config.collectionName;
813
+ if (!collectionName) throw new Error("Collection name is required to get a session by conversation ID");
812
814
  const chatSessions = await payload.find({
813
815
  collection: collectionName,
814
816
  where: { and: [{ conversation_id: { equals: conversationId } }, { user: { equals: userId } }] },
@@ -827,7 +829,8 @@ async function getSessionByConversationId(payload, userId, conversationId, confi
827
829
  * @returns Promise with updated session data or null if not found
828
830
  */
829
831
  async function closeSession(payload, userId, conversationId, config = {}) {
830
- const collectionName = config.collectionName || "chat-sessions";
832
+ const collectionName = config.collectionName;
833
+ if (!collectionName) throw new Error("Collection name is required to close a session");
831
834
  const chatSessions = await payload.find({
832
835
  collection: collectionName,
833
836
  where: { and: [{ conversation_id: { equals: conversationId } }, { user: { equals: userId } }] },
@@ -891,7 +894,7 @@ function sendSSEEvent(controller, encoder, event) {
891
894
  * @param spending - Token spending entries
892
895
  * @param collectionName - Collection name for sessions (default: 'chat-sessions')
893
896
  */
894
- async function saveChatSession(payload, userId, conversationId, userMessage, assistantMessage, sources, spending, collectionName = "chat-sessions") {
897
+ async function saveChatSession(payload, userId, conversationId, userMessage, assistantMessage, sources, spending, collectionName) {
895
898
  try {
896
899
  const existing = await payload.find({
897
900
  collection: collectionName,
@@ -1617,7 +1620,7 @@ function createRAGPayloadHandlers(config) {
1617
1620
  path: "/chat",
1618
1621
  method: "post",
1619
1622
  handler: createChatPOSTHandler({
1620
- collectionName: "chat-sessions",
1623
+ collectionName: config.collectionName,
1621
1624
  checkPermissions: callbacks.checkPermissions,
1622
1625
  typesense,
1623
1626
  rag: ragFeatureConfig,
@@ -2817,6 +2820,7 @@ function createTypesenseRAGPlugin(config) {
2817
2820
  if (config.agents && config.agents.length > 0 && config.callbacks) {
2818
2821
  const ragEndpoints = createRAGPayloadHandlers({
2819
2822
  typesense: config.typesense,
2823
+ collectionName: config.collectionName,
2820
2824
  embeddingConfig: config.embeddingConfig,
2821
2825
  agents: config.agents,
2822
2826
  callbacks: config.callbacks,