@tuturuuu/ui 0.3.2 → 0.4.0

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.
@@ -0,0 +1,28 @@
1
+ 'use client';
2
+
3
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
4
+ import {
5
+ type CreateChatIntegrationPayload,
6
+ createChatIntegration,
7
+ } from '@tuturuuu/internal-api';
8
+ import { ROOT_WORKSPACE_ID } from '@tuturuuu/utils/constants';
9
+ import { chatQueryKeys } from './query-keys';
10
+
11
+ const AGENT_DETAILS_QUERY_KEY = ['chat', 'infrastructure-ai-agents'] as const;
12
+
13
+ export function useCreateChatIntegration() {
14
+ const queryClient = useQueryClient();
15
+
16
+ return useMutation({
17
+ mutationFn: (payload: CreateChatIntegrationPayload) =>
18
+ createChatIntegration(payload),
19
+ onSuccess: () => {
20
+ queryClient.invalidateQueries({
21
+ queryKey: [...chatQueryKeys.all(ROOT_WORKSPACE_ID), 'conversations'],
22
+ });
23
+ queryClient.invalidateQueries({
24
+ queryKey: AGENT_DETAILS_QUERY_KEY,
25
+ });
26
+ },
27
+ });
28
+ }
@@ -3,6 +3,7 @@ export * from './hooks-attachments';
3
3
  export * from './hooks-conversations';
4
4
  export * from './hooks-directory';
5
5
  export * from './hooks-friends';
6
+ export * from './hooks-integrations';
6
7
  export * from './hooks-messages';
7
8
  export * from './hooks-realtime';
8
9
  export * from './hooks-shared-content';
@@ -0,0 +1,74 @@
1
+ 'use client';
2
+
3
+ type SearchParamsLike = {
4
+ toString: () => string;
5
+ };
6
+
7
+ type RouterLike = {
8
+ replace: (href: string, options?: { scroll?: boolean }) => void;
9
+ };
10
+
11
+ export type ChatDetailsTarget = 'agent' | null;
12
+
13
+ export function buildChatSelectionHref({
14
+ conversationId,
15
+ details = null,
16
+ pathname,
17
+ searchParams,
18
+ }: {
19
+ conversationId: string | null;
20
+ details?: ChatDetailsTarget;
21
+ pathname: string;
22
+ searchParams: SearchParamsLike;
23
+ }) {
24
+ const nextParams = new URLSearchParams(searchParams.toString());
25
+
26
+ if (conversationId) {
27
+ nextParams.set('conversationId', conversationId);
28
+ } else {
29
+ nextParams.delete('conversationId');
30
+ }
31
+
32
+ if (details) {
33
+ nextParams.set('details', details);
34
+ } else {
35
+ nextParams.delete('details');
36
+ }
37
+
38
+ const nextQuery = nextParams.toString();
39
+ return nextQuery ? `${pathname}?${nextQuery}` : pathname;
40
+ }
41
+
42
+ export function replaceChatSelection({
43
+ conversationId,
44
+ details,
45
+ pathname,
46
+ router,
47
+ searchParams,
48
+ storageKey,
49
+ }: {
50
+ conversationId: string | null;
51
+ details?: ChatDetailsTarget;
52
+ pathname: string;
53
+ router: RouterLike;
54
+ searchParams: SearchParamsLike;
55
+ storageKey?: string | null;
56
+ }) {
57
+ if (storageKey && typeof window !== 'undefined') {
58
+ if (conversationId) {
59
+ window.localStorage.setItem(storageKey, conversationId);
60
+ } else {
61
+ window.localStorage.removeItem(storageKey);
62
+ }
63
+ }
64
+
65
+ router.replace(
66
+ buildChatSelectionHref({
67
+ conversationId,
68
+ details,
69
+ pathname,
70
+ searchParams,
71
+ }),
72
+ { scroll: false }
73
+ );
74
+ }
@@ -25,6 +25,10 @@ export function normalizeChatConversationScope(
25
25
  export function getChatConversationScope(
26
26
  conversation: Pick<ChatConversation, 'metadata' | 'type'>
27
27
  ): ChatConversationScope {
28
+ if (conversation.metadata?.scope === 'personal') {
29
+ return 'personal';
30
+ }
31
+
28
32
  if (conversation.type === 'direct' || conversation.type === 'group') {
29
33
  return 'personal';
30
34
  }
@@ -59,7 +63,9 @@ export function isChatConversation(value: unknown): value is ChatConversation {
59
63
  export function getChatConversationTypesForScope(
60
64
  scope: ChatConversationScope
61
65
  ): ChatConversationType[] {
62
- return scope === 'personal' ? ['direct', 'group', 'ai'] : ['channel', 'ai'];
66
+ return scope === 'personal'
67
+ ? ['direct', 'group', 'channel', 'ai']
68
+ : ['channel', 'ai'];
63
69
  }
64
70
 
65
71
  export function filterChatConversationsByScope(