@swiss-ai-hub/web 0.290.11
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/LICENSE +661 -0
- package/README.md +479 -0
- package/app.config.ts +1 -0
- package/app.vue +52 -0
- package/assets/css/main.css +4 -0
- package/assets/images/logo.png +0 -0
- package/components/Agent/Avatar.vue +40 -0
- package/components/Agent/Card.vue +139 -0
- package/components/Agent/Configuration.vue +20 -0
- package/components/Agent/CreateModal.vue +287 -0
- package/components/Agent/EmptyCard.vue +35 -0
- package/components/Agent/List.vue +85 -0
- package/components/Agent/TemplateCard.vue +58 -0
- package/components/AppLoader.vue +55 -0
- package/components/Chat/Message.vue +90 -0
- package/components/Chat/SourceNodes.vue +120 -0
- package/components/Chat/Thread.vue +134 -0
- package/components/Costs/Table.vue +56 -0
- package/components/Dashboard/Component/BarChart.vue +46 -0
- package/components/Dashboard/Component/LineChart.vue +138 -0
- package/components/Dashboard/Component/Number.vue +31 -0
- package/components/Dashboard/Grid.vue +214 -0
- package/components/Dashboard/Item.vue +75 -0
- package/components/Dashboard/Trend.vue +34 -0
- package/components/Display/List/DisplayList.vue +93 -0
- package/components/Evaluation/Dataset/Card.vue +70 -0
- package/components/Evaluation/Dataset/Create.vue +81 -0
- package/components/Evaluation/Dataset/Edit.vue +132 -0
- package/components/Event/Display/AddMemoryToChatHistoryEvent.vue +60 -0
- package/components/Event/Display/AgentInTheLoopRequestEvent.vue +56 -0
- package/components/Event/Display/AgentInTheLoopResponseEvent.vue +17 -0
- package/components/Event/Display/Base.vue +125 -0
- package/components/Event/Display/BaseRetrieveMemoryEvent.vue +101 -0
- package/components/Event/Display/BaseStoreMemoryEvent.vue +182 -0
- package/components/Event/Display/ChunkEvent.vue +40 -0
- package/components/Event/Display/EmbeddingEvent.vue +25 -0
- package/components/Event/Display/ExceptionEvent.vue +21 -0
- package/components/Event/Display/GuardAcceptEvent.vue +25 -0
- package/components/Event/Display/GuardEvent.vue +17 -0
- package/components/Event/Display/GuardRejectionEvent.vue +25 -0
- package/components/Event/Display/HumanInTheLoopRequestEvent.vue +53 -0
- package/components/Event/Display/HumanInTheLoopResponseEvent.vue +40 -0
- package/components/Event/Display/LLMCostEvent.vue +25 -0
- package/components/Event/Display/LLMEvent.vue +92 -0
- package/components/Event/Display/LimitChatHistoryEvent.vue +60 -0
- package/components/Event/Display/RAGFailureStopEvent.vue +28 -0
- package/components/Event/Display/RAGStartEvent.vue +77 -0
- package/components/Event/Display/RAGSuccessStopEvent.vue +16 -0
- package/components/Event/Display/RawDataContent.vue +69 -0
- package/components/Event/Display/RerankerEvent.vue +39 -0
- package/components/Event/Display/RetrieverEvent.vue +22 -0
- package/components/Event/Display/RouterEvent.vue +54 -0
- package/components/Event/Display/StandaloneQuestionCondenserEvent.vue +38 -0
- package/components/Event/Display/StopEvent.vue +16 -0
- package/components/Event/Display/ThoughtEvent.vue +20 -0
- package/components/Event/Display/ToolEvent.vue +38 -0
- package/components/Event/Display/UnknownEvent.vue +17 -0
- package/components/Event/Display/UserMessageEvent.vue +35 -0
- package/components/Event/List/EventList.vue +249 -0
- package/components/Event/Statistics.vue +49 -0
- package/components/Event/Timeseries.vue +224 -0
- package/components/FormKit/AgentSelector.vue +307 -0
- package/components/FormKit/ChipsInput.vue +62 -0
- package/components/FormKit/DynamicConfiguration.vue +155 -0
- package/components/FormKit/IconSelector.vue +72 -0
- package/components/FormKit/KnowledgeDatabaseSelector.vue +92 -0
- package/components/FormKit/LocaleInput.vue +150 -0
- package/components/FormKit/ModelSelect.vue +110 -0
- package/components/FormKit/Repeater.vue +93 -0
- package/components/FormKit/VectorStoreInput.vue +247 -0
- package/components/Knowledge/Document/List.vue +140 -0
- package/components/Knowledge/Document/Overview.vue +28 -0
- package/components/Knowledge/Document/UploadModal.vue +298 -0
- package/components/Knowledge/Document/WithNodes.vue +105 -0
- package/components/Knowledge/Namespace/Card.vue +108 -0
- package/components/Knowledge/Namespace/CreateModal.vue +203 -0
- package/components/Knowledge/Namespace/EditModal.vue +134 -0
- package/components/Knowledge/Namespace/EmptyCard.vue +35 -0
- package/components/Knowledge/Node/Content.vue +71 -0
- package/components/Markdown/Renderer.vue +87 -0
- package/components/Memory/DetailPage.vue +48 -0
- package/components/Memory/Edit.vue +241 -0
- package/components/Memory/Graph.vue +318 -0
- package/components/Memory/List.vue +155 -0
- package/components/Memory/MemoryManagementPage.vue +178 -0
- package/components/Memory/OpenWebUIContent.vue +96 -0
- package/components/Memory/PageLayout.vue +72 -0
- package/components/Models/ModelDetailsPanel.vue +250 -0
- package/components/Models/NamespaceCard.vue +79 -0
- package/components/Navigation/Left.vue +85 -0
- package/components/Navigation/Top.vue +31 -0
- package/components/Notification/Item.vue +88 -0
- package/components/Notification/NotificationsOverlay.vue +164 -0
- package/components/Process/Card.vue +119 -0
- package/components/Process/Configuration.vue +20 -0
- package/components/Process/CreateModal.vue +276 -0
- package/components/Process/EmptyCard.vue +35 -0
- package/components/Process/Form.vue +153 -0
- package/components/Process/Starts.vue +44 -0
- package/components/Process/Walkthrough/List.vue +162 -0
- package/components/Role/AccessRulesEditor.vue +132 -0
- package/components/Role/Card.vue +68 -0
- package/components/Role/Create.vue +55 -0
- package/components/Role/Edit.vue +82 -0
- package/components/Role/UsageLimitsEditor.vue +225 -0
- package/components/Service/Selection.vue +148 -0
- package/components/Structural/Column.vue +74 -0
- package/components/Structural/Screen.vue +10 -0
- package/components/Structural/Substructure.vue +5 -0
- package/components/Tenant/Switcher.vue +102 -0
- package/components/Thread/Details.vue +135 -0
- package/components/Thread/Hierarchy.vue +136 -0
- package/components/Thread/Info.vue +41 -0
- package/components/Thread/List.vue +136 -0
- package/components/User/Bar.vue +74 -0
- package/components/User/List.vue +86 -0
- package/components/User/RoleChips.vue +83 -0
- package/components/User/Settings.vue +79 -0
- package/components/Workflow/Modal.vue +39 -0
- package/components/Workflow/NodeCard.vue +41 -0
- package/components/Workflow/StartNode.vue +24 -0
- package/components/Workflow/StepNode.vue +27 -0
- package/components/Workflow/StopNode.vue +24 -0
- package/components/Workflow/Visualization.vue +265 -0
- package/components/mdc/MarkdownFigure.vue +9 -0
- package/components/mdc/MarkdownTable.vue +9 -0
- package/components/mdc/ResolveImageComponent.vue +58 -0
- package/composables/agent/useAgentClass.ts +27 -0
- package/composables/agent/useAgentClassInstances.ts +27 -0
- package/composables/agent/useAgentClasses.ts +27 -0
- package/composables/agent/useAgentIconFromThread.ts +8 -0
- package/composables/agent/useAgentInstance.ts +28 -0
- package/composables/agent/useAgentInstanceThreads.ts +76 -0
- package/composables/agent/useAgentInstances.ts +25 -0
- package/composables/agent/useAgentNavigation.ts +35 -0
- package/composables/agent/useCreateAgentInstance.ts +33 -0
- package/composables/agent/useDeleteAgentInstance.ts +31 -0
- package/composables/agent/useUpdateAgentInstance.ts +40 -0
- package/composables/auth/useAuth.ts +54 -0
- package/composables/auth/useAuthProviders.ts +14 -0
- package/composables/chat/useChatCompletions.ts +30 -0
- package/composables/dashboard/useAgentNameFromDashboardWidget.ts +27 -0
- package/composables/dashboard/useDashboardComponent.ts +27 -0
- package/composables/dashboard/useSaveDashboard.ts +21 -0
- package/composables/document/useCreateNamespace.ts +26 -0
- package/composables/document/useDatabases.ts +23 -0
- package/composables/document/useDocument.ts +29 -0
- package/composables/document/useDocumentUrl.ts +20 -0
- package/composables/document/useDocuments.ts +107 -0
- package/composables/document/useNodes.ts +29 -0
- package/composables/document/useSummaryNodes.ts +32 -0
- package/composables/document/useUpdateNamespace.ts +22 -0
- package/composables/evaluation/useCreateDataset.ts +19 -0
- package/composables/evaluation/useDataset.ts +26 -0
- package/composables/evaluation/useDatasets.ts +25 -0
- package/composables/evaluation/useUpdateDataset.ts +23 -0
- package/composables/event/useBasicEventStatistics.ts +83 -0
- package/composables/event/useEventColor.ts +25 -0
- package/composables/event/useEventComponent.ts +87 -0
- package/composables/event/useEventTimeseries.ts +39 -0
- package/composables/event/useEventTimeseriesStats.ts +26 -0
- package/composables/file/useFileUpload.ts +91 -0
- package/composables/file/useSupportedFileTypes.ts +22 -0
- package/composables/form/useCreateInstanceForm.ts +251 -0
- package/composables/form/useFormKitTransform.ts +753 -0
- package/composables/memory/useMemoryCRUD.ts +88 -0
- package/composables/memory/useMemoryFactory.ts +319 -0
- package/composables/memory/useMemorySearchFilter.ts +74 -0
- package/composables/models/useModelsList.ts +24 -0
- package/composables/models/useSingleModel.ts +30 -0
- package/composables/notification/useNotificationPoller.ts +58 -0
- package/composables/notification/useNotifications.ts +57 -0
- package/composables/notification/useUpdateMultipleNotifications.ts +17 -0
- package/composables/notification/useUpdateNotification.ts +17 -0
- package/composables/process/useCreateProcessInstance.ts +32 -0
- package/composables/process/useDeleteProcessInstance.ts +31 -0
- package/composables/process/useProcessClasses.ts +27 -0
- package/composables/process/useProcessInstance.ts +28 -0
- package/composables/process/useProcessInstances.ts +27 -0
- package/composables/process/useProcessWalkthroughs.ts +73 -0
- package/composables/process/useSendProcessStartForm.ts +43 -0
- package/composables/process/useUpdateProcessInstance.ts +40 -0
- package/composables/role/useCreateRole.ts +19 -0
- package/composables/role/useDeleteRole.ts +21 -0
- package/composables/role/useRole.ts +30 -0
- package/composables/role/useRoles.ts +25 -0
- package/composables/role/useUpdateRole.ts +22 -0
- package/composables/suite/useApps.ts +31 -0
- package/composables/suite/useSuite.ts +26 -0
- package/composables/tenant/useActiveTenant.ts +27 -0
- package/composables/tenant/useSysadminNavigation.ts +19 -0
- package/composables/tenant/useTenant.ts +38 -0
- package/composables/tenant/useTenantMemberships.ts +15 -0
- package/composables/tenant/useTenantPath.ts +20 -0
- package/composables/tenant/useTenantPolling.ts +30 -0
- package/composables/tenant/useTenantReady.ts +12 -0
- package/composables/theme/useDarkMode.ts +5 -0
- package/composables/thread/useThread.ts +27 -0
- package/composables/thread/useThreadEvents.ts +91 -0
- package/composables/thread/useThreadUtils.ts +49 -0
- package/composables/thread/useThreads.ts +64 -0
- package/composables/thread/useThreadsInfinite.ts +56 -0
- package/composables/translation/useTranslate.ts +20 -0
- package/composables/useRouteReady.ts +21 -0
- package/composables/useTimeAgo.ts +40 -0
- package/composables/user/useAssignRoleToUser.ts +22 -0
- package/composables/user/useMyUser.ts +25 -0
- package/composables/user/useRevokeRoleFromUser.ts +21 -0
- package/composables/user/useUser.ts +30 -0
- package/composables/user/useUsers.ts +63 -0
- package/composables/utils/useJsonTree.ts +138 -0
- package/formkit.config.ts +44 -0
- package/i18n/locales/de.yaml +815 -0
- package/i18n/locales/en.yaml +804 -0
- package/i18n/locales/fr.yaml +812 -0
- package/i18n/locales/it.yaml +808 -0
- package/layouts/anonymous.vue +8 -0
- package/layouts/default.vue +116 -0
- package/middleware/auth.global.ts +62 -0
- package/nuxt.config.ts +145 -0
- package/package.json +114 -0
- package/pages/[tenant]/index.vue +31 -0
- package/pages/[tenant]/notifications/index.vue +235 -0
- package/pages/[tenant]/service/agents/[agent_class]-[agent_id]/chat.vue +67 -0
- package/pages/[tenant]/service/agents/[agent_class]-[agent_id]/configuration.vue +122 -0
- package/pages/[tenant]/service/agents/[agent_class]-[agent_id]/memories/[memory_id].vue +3 -0
- package/pages/[tenant]/service/agents/[agent_class]-[agent_id]/memories.vue +20 -0
- package/pages/[tenant]/service/agents/[agent_class]-[agent_id]/overview.vue +72 -0
- package/pages/[tenant]/service/agents/[agent_class]-[agent_id]/threads.vue +52 -0
- package/pages/[tenant]/service/agents/[agent_class]-[agent_id]/workflow.vue +19 -0
- package/pages/[tenant]/service/agents/[agent_class]-[agent_id].vue +63 -0
- package/pages/[tenant]/service/agents/templates.vue +102 -0
- package/pages/[tenant]/service/agents.vue +185 -0
- package/pages/[tenant]/service/datasets/[dataset_id].vue +81 -0
- package/pages/[tenant]/service/datasets.vue +53 -0
- package/pages/[tenant]/service/health/index.vue +3 -0
- package/pages/[tenant]/service/knowledge/[db]/[namespace]/[document_id]/nodes.vue +20 -0
- package/pages/[tenant]/service/knowledge/[db]/[namespace]/[document_id]/overview.vue +40 -0
- package/pages/[tenant]/service/knowledge/[db]/[namespace]/[document_id]/summary.vue +88 -0
- package/pages/[tenant]/service/knowledge/[db]/[namespace]/[document_id].vue +48 -0
- package/pages/[tenant]/service/knowledge/[db]/[namespace].vue +144 -0
- package/pages/[tenant]/service/knowledge.vue +126 -0
- package/pages/[tenant]/service/models/[model_name].vue +84 -0
- package/pages/[tenant]/service/models.vue +61 -0
- package/pages/[tenant]/service/my-account.vue +117 -0
- package/pages/[tenant]/service/openai/[thread_id]/[display_id]/memories.vue +66 -0
- package/pages/[tenant]/service/openai/[thread_id]/[display_id]/sources.vue +100 -0
- package/pages/[tenant]/service/openai/[thread_id]/[display_id]/tracing.vue +49 -0
- package/pages/[tenant]/service/openai.vue +101 -0
- package/pages/[tenant]/service/organization-memories/graph.vue +97 -0
- package/pages/[tenant]/service/organization-memories/list/[memory_id].vue +3 -0
- package/pages/[tenant]/service/organization-memories/list.vue +150 -0
- package/pages/[tenant]/service/organization-memories.vue +3 -0
- package/pages/[tenant]/service/processes/[process_class]-[process_id]/[process_walkthrough_id].vue +7 -0
- package/pages/[tenant]/service/processes/[process_class]-[process_id]/configuration.vue +106 -0
- package/pages/[tenant]/service/processes/[process_class]-[process_id]/overview.vue +67 -0
- package/pages/[tenant]/service/processes/[process_class]-[process_id]/start.vue +26 -0
- package/pages/[tenant]/service/processes/[process_class]-[process_id]/walkthroughs/[process_walkthrough_id]/overview.vue +14 -0
- package/pages/[tenant]/service/processes/[process_class]-[process_id]/walkthroughs.vue +54 -0
- package/pages/[tenant]/service/processes/[process_class]-[process_id].vue +60 -0
- package/pages/[tenant]/service/processes.vue +129 -0
- package/pages/[tenant]/service/roles/[role_id].vue +54 -0
- package/pages/[tenant]/service/roles.vue +84 -0
- package/pages/[tenant]/service/threads/[thread_id]/chat.vue +51 -0
- package/pages/[tenant]/service/threads/[thread_id]/display/[display_id].vue +21 -0
- package/pages/[tenant]/service/threads/[thread_id]/display.vue +29 -0
- package/pages/[tenant]/service/threads/[thread_id]/hierarchy.vue +14 -0
- package/pages/[tenant]/service/threads/[thread_id]/memories/[memory_id].vue +3 -0
- package/pages/[tenant]/service/threads/[thread_id]/memories.vue +19 -0
- package/pages/[tenant]/service/threads/[thread_id]/overview.vue +100 -0
- package/pages/[tenant]/service/threads/[thread_id].vue +54 -0
- package/pages/[tenant]/service/threads.vue +52 -0
- package/pages/[tenant]/service/user-memories/graph.vue +97 -0
- package/pages/[tenant]/service/user-memories/list/[memory_id].vue +3 -0
- package/pages/[tenant]/service/user-memories/list.vue +150 -0
- package/pages/[tenant]/service/user-memories.vue +3 -0
- package/pages/[tenant]/service/users/[user_id].vue +117 -0
- package/pages/[tenant]/service/users.vue +88 -0
- package/pages/auth/callback.vue +52 -0
- package/pages/auth/login.vue +80 -0
- package/pages/auth/renew.vue +24 -0
- package/pages/index.vue +59 -0
- package/pages/select-tenant.vue +76 -0
- package/plugins/0.runtime-config.client.ts +55 -0
- package/plugins/apexcharts.client.ts +5 -0
- package/plugins/api-client.client.ts +38 -0
- package/plugins/dark-mode.client.ts +12 -0
- package/plugins/keycloak-client.ts +41 -0
- package/plugins/oidc-client.ts +78 -0
- package/sdk/client/client/client.gen.ts +237 -0
- package/sdk/client/client/index.ts +24 -0
- package/sdk/client/client/types.gen.ts +213 -0
- package/sdk/client/client/utils.gen.ts +407 -0
- package/sdk/client/client.gen.ts +25 -0
- package/sdk/client/core/auth.gen.ts +42 -0
- package/sdk/client/core/bodySerializer.gen.ts +96 -0
- package/sdk/client/core/params.gen.ts +181 -0
- package/sdk/client/core/pathSerializer.gen.ts +180 -0
- package/sdk/client/core/queryKeySerializer.gen.ts +136 -0
- package/sdk/client/core/serverSentEvents.gen.ts +265 -0
- package/sdk/client/core/types.gen.ts +118 -0
- package/sdk/client/core/utils.gen.ts +143 -0
- package/sdk/client/index.ts +1013 -0
- package/sdk/client/schemas.gen.ts +35395 -0
- package/sdk/client/sdk.gen.ts +3438 -0
- package/sdk/client/transformers.gen.ts +143 -0
- package/sdk/client/types.gen.ts +27567 -0
- package/tailwind.config.mjs +27 -0
- package/themes/aihub-theme.ts +125 -0
- package/types/DashboardWidget.ts +13 -0
- package/types/EventChartInput.ts +7 -0
- package/types/NavItem.ts +6 -0
- package/types/TimeseriesInput.ts +7 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getThread, type ThreadDto } from '@core/sdk/client'
|
|
2
|
+
import { minutesToMilliseconds } from 'date-fns'
|
|
3
|
+
import { useRoute } from 'vue-router'
|
|
4
|
+
|
|
5
|
+
export const useThread = defineQuery(() => {
|
|
6
|
+
const route = useRoute()
|
|
7
|
+
const { tenantId } = useTenant()
|
|
8
|
+
|
|
9
|
+
const { data: thread, isPending: threadIsLoading } = useQuery<ThreadDto>({
|
|
10
|
+
key: () => ['tenant', tenantId.value, 'threads', route.params.thread_id as string],
|
|
11
|
+
staleTime: minutesToMilliseconds(5),
|
|
12
|
+
enabled: useTenantReady('thread_id'),
|
|
13
|
+
query: async () => {
|
|
14
|
+
return await getThread({
|
|
15
|
+
composable: '$fetch',
|
|
16
|
+
path: {
|
|
17
|
+
tenant_id: tenantId.value!,
|
|
18
|
+
thread_id: route.params.thread_id as string,
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
return {
|
|
24
|
+
thread,
|
|
25
|
+
threadIsLoading,
|
|
26
|
+
}
|
|
27
|
+
})
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { getAgentEventsInThread, type ContextualizedAgentEvent } from '@core/sdk/client'
|
|
2
|
+
import { useWebSocket } from '@vueuse/core'
|
|
3
|
+
import { minutesToMilliseconds } from 'date-fns'
|
|
4
|
+
import { useRoute } from 'vue-router'
|
|
5
|
+
|
|
6
|
+
export const useThreadEvents = defineQuery(() => {
|
|
7
|
+
const { getBearer } = useAuth()
|
|
8
|
+
const runtimeConfig = useRuntimeConfig()
|
|
9
|
+
|
|
10
|
+
const route = useRoute()
|
|
11
|
+
const { tenantId } = useTenant()
|
|
12
|
+
const queryCache = useQueryCache()
|
|
13
|
+
|
|
14
|
+
const { data: threadEvents, isPending: threadEventsAreLoading } = useQuery<ContextualizedAgentEvent[]>({
|
|
15
|
+
key: () => ['tenant', tenantId.value, 'thread', route.params.thread_id as string, 'events'],
|
|
16
|
+
staleTime: minutesToMilliseconds(5),
|
|
17
|
+
enabled: useTenantReady('thread_id'),
|
|
18
|
+
query: async () => {
|
|
19
|
+
return await getAgentEventsInThread({
|
|
20
|
+
composable: '$fetch',
|
|
21
|
+
path: {
|
|
22
|
+
tenant_id: tenantId.value!,
|
|
23
|
+
thread_id: route.params.thread_id as string,
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const { data: newEvent } = useWebSocket<string>(runtimeConfig.public.ws.endpoint, {
|
|
30
|
+
autoReconnect: {
|
|
31
|
+
retries: -1,
|
|
32
|
+
delay: 1000,
|
|
33
|
+
},
|
|
34
|
+
onConnected(ws) {
|
|
35
|
+
getBearer()
|
|
36
|
+
.then((token) => {
|
|
37
|
+
ws.send(JSON.stringify({ type: 'auth', token }))
|
|
38
|
+
})
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
// Update cache when new events arrive via WebSocket
|
|
43
|
+
watch(() => newEvent.value, (rawEventData) => {
|
|
44
|
+
if (!rawEventData) return
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const event = JSON.parse(rawEventData) as ContextualizedAgentEvent
|
|
48
|
+
|
|
49
|
+
// Only process events for the current thread
|
|
50
|
+
if (event.thread_id === route.params.thread_id) {
|
|
51
|
+
// Get current events from cache
|
|
52
|
+
const key = ['tenant', tenantId.value, 'thread', route.params.thread_id, 'events']
|
|
53
|
+
const currentEvents = queryCache.getQueryData<ContextualizedAgentEvent[]>(key) || []
|
|
54
|
+
|
|
55
|
+
// Check if event already exists (avoid duplicates)
|
|
56
|
+
const eventExists = currentEvents.some(e => e.event_id === event.event_id)
|
|
57
|
+
|
|
58
|
+
if (!eventExists) {
|
|
59
|
+
// Add new event to the cache
|
|
60
|
+
const updatedEvents = [...currentEvents, event]
|
|
61
|
+
|
|
62
|
+
// Sort events if needed
|
|
63
|
+
updatedEvents.sort((a, b) =>
|
|
64
|
+
(a.event.created_at ?? 0) - (b.event.created_at ?? 0),
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
// Update the cache with the new array
|
|
68
|
+
queryCache.setQueryData(key, updatedEvents)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Invalidate queries on stop event
|
|
72
|
+
const parents = event.event._parent_event_names
|
|
73
|
+
if (parents.includes('StopEvent') || parents.includes('ExceptionEvent')) {
|
|
74
|
+
new Promise(r => setTimeout(r, 500)).then(() => {
|
|
75
|
+
queryCache.invalidateQueries({ key: ['tenant', tenantId.value, 'threads'] })
|
|
76
|
+
queryCache.invalidateQueries({ key: ['tenant', tenantId.value, 'threads', event.thread_id] })
|
|
77
|
+
queryCache.invalidateQueries({ key: ['tenant', tenantId.value, 'agent', event.agent_class, event.agent_id] })
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
console.error('Error processing WebSocket event:', error)
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
threadEvents,
|
|
89
|
+
threadEventsAreLoading,
|
|
90
|
+
}
|
|
91
|
+
})
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createThread,
|
|
3
|
+
type CreateThreadRequest,
|
|
4
|
+
type DisplayStatistics,
|
|
5
|
+
type RunStatistics,
|
|
6
|
+
type ThreadDto,
|
|
7
|
+
type ContextualizedAgentEvent,
|
|
8
|
+
} from '@core/sdk/client'
|
|
9
|
+
|
|
10
|
+
export const useThreadUtils = () => {
|
|
11
|
+
const { t } = useI18n()
|
|
12
|
+
|
|
13
|
+
const pendingType = (thread: ThreadDto) => {
|
|
14
|
+
if (thread.open_hitl) {
|
|
15
|
+
return t('thread.utils.pendingTypes.hitl')
|
|
16
|
+
}
|
|
17
|
+
if (thread.open_aitl) {
|
|
18
|
+
return t('thread.utils.pendingTypes.aitl')
|
|
19
|
+
}
|
|
20
|
+
if (thread.open_bitl) {
|
|
21
|
+
return t('thread.utils.pendingTypes.bitl')
|
|
22
|
+
}
|
|
23
|
+
return t('thread.utils.pendingTypes.unknown')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const runForEvent = (thread: ThreadDto, event: ContextualizedAgentEvent) => {
|
|
27
|
+
const display = thread?.displays?.find((display: DisplayStatistics) => display.display_id == event.display_id)
|
|
28
|
+
return display?.runs?.find((run: RunStatistics) => run.run_id == event.run_id)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const createNewThread = useMutation({
|
|
32
|
+
mutation: ({ name, user_ids, agents, tenantId }: CreateThreadRequest & { tenantId: string }) =>
|
|
33
|
+
createThread({
|
|
34
|
+
composable: '$fetch',
|
|
35
|
+
path: { tenant_id: tenantId },
|
|
36
|
+
body: {
|
|
37
|
+
name,
|
|
38
|
+
user_ids,
|
|
39
|
+
agents,
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
pendingType,
|
|
46
|
+
runForEvent,
|
|
47
|
+
createNewThread,
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { getUserThreads, type ThreadDto } from '@core/sdk/client'
|
|
2
|
+
|
|
3
|
+
export const useThreads = defineQuery(() => {
|
|
4
|
+
const { tenantId } = useTenant()
|
|
5
|
+
const currentPage = ref(1)
|
|
6
|
+
const pageSize = ref(10)
|
|
7
|
+
|
|
8
|
+
const threadsQuery = useQuery({
|
|
9
|
+
key: () => ['tenant', tenantId.value, 'threads', { page: currentPage.value, size: pageSize.value }],
|
|
10
|
+
enabled: useTenantReady(),
|
|
11
|
+
query: async () => {
|
|
12
|
+
const pageToFetch = Math.max(1, currentPage.value)
|
|
13
|
+
|
|
14
|
+
return await getUserThreads({
|
|
15
|
+
composable: '$fetch',
|
|
16
|
+
path: { tenant_id: tenantId.value! },
|
|
17
|
+
query: {
|
|
18
|
+
page: pageToFetch,
|
|
19
|
+
page_size: pageSize.value,
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
},
|
|
23
|
+
placeholderData: previousData => previousData,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const setPageSize = (newSize: number) => {
|
|
27
|
+
if (newSize > 0) {
|
|
28
|
+
pageSize.value = newSize
|
|
29
|
+
currentPage.value = 1
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const setPage = (newPage: number) => {
|
|
34
|
+
if (newPage > 0) {
|
|
35
|
+
currentPage.value = newPage
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const paginationMeta = computed(() => {
|
|
40
|
+
const data = threadsQuery.state.value?.data
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
total: data?.total ?? 0,
|
|
44
|
+
currentPage: data?.page ?? currentPage.value,
|
|
45
|
+
pageSize: data?.page_size ?? pageSize.value,
|
|
46
|
+
totalPages: data?.total_pages ?? 0,
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const threads = computed(() => (threadsQuery.state.value?.data)?.threads ?? [] as ThreadDto[])
|
|
51
|
+
|
|
52
|
+
const isLoading = computed(() => threadsQuery.asyncStatus.value === 'loading')
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
threads,
|
|
56
|
+
isLoading,
|
|
57
|
+
pagination: paginationMeta,
|
|
58
|
+
currentPage,
|
|
59
|
+
pageSize,
|
|
60
|
+
setPage,
|
|
61
|
+
setPageSize,
|
|
62
|
+
refetch: threadsQuery.refetch,
|
|
63
|
+
}
|
|
64
|
+
})
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { getUserThreads, type ThreadDto } from '@core/sdk/client'
|
|
2
|
+
|
|
3
|
+
export const useThreadsInfinite = defineQuery(() => {
|
|
4
|
+
const { tenantId } = useTenant()
|
|
5
|
+
const PAGE_SIZE = 10
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
state,
|
|
9
|
+
loadMore: loadMoreThreads,
|
|
10
|
+
isLoading: threadsAreLoading,
|
|
11
|
+
} = useInfiniteQuery({
|
|
12
|
+
key: () => ['tenant', tenantId.value, 'threads'],
|
|
13
|
+
query: async ({ nextPage }) => {
|
|
14
|
+
if (nextPage === null) return null
|
|
15
|
+
|
|
16
|
+
return await getUserThreads({
|
|
17
|
+
composable: '$fetch',
|
|
18
|
+
path: { tenant_id: tenantId.value! },
|
|
19
|
+
query: {
|
|
20
|
+
page: nextPage,
|
|
21
|
+
page_size: PAGE_SIZE,
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
},
|
|
25
|
+
initialPage: {
|
|
26
|
+
threads: [] as ThreadDto[],
|
|
27
|
+
nextPage: 1 as number | null,
|
|
28
|
+
totalThreads: 0,
|
|
29
|
+
totalPages: 0,
|
|
30
|
+
},
|
|
31
|
+
merge(accumulated, newData) {
|
|
32
|
+
// If no new data was returned, return the accumulated data
|
|
33
|
+
if (!newData) return accumulated
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
threads: [...accumulated.threads, ...newData.threads],
|
|
37
|
+
nextPage: newData.page < newData.total_pages ? newData.page + 1 : null,
|
|
38
|
+
totalThreads: newData.total,
|
|
39
|
+
totalPages: newData.total_pages,
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
// Computed property for hasMore
|
|
45
|
+
const hasMoreThreads = computed(() => state.value?.data?.nextPage !== null)
|
|
46
|
+
|
|
47
|
+
// Expose only the necessary data and functions
|
|
48
|
+
return {
|
|
49
|
+
threads: computed(() => state.value?.data?.threads || []),
|
|
50
|
+
threadsAreLoading,
|
|
51
|
+
hasMoreThreads,
|
|
52
|
+
totalThreads: computed(() => state.value?.data?.totalThreads || 0),
|
|
53
|
+
totalPages: computed(() => state.value?.data?.totalPages || 0),
|
|
54
|
+
loadMoreThreads,
|
|
55
|
+
}
|
|
56
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { translateText, type TranslationRequest } from '@core/sdk/client'
|
|
2
|
+
|
|
3
|
+
export function useTranslate() {
|
|
4
|
+
const {
|
|
5
|
+
mutateAsync: translate,
|
|
6
|
+
isLoading: isTranslating,
|
|
7
|
+
} = useMutation({
|
|
8
|
+
mutation: ({ request, tenantId }: { request: TranslationRequest, tenantId: string }) =>
|
|
9
|
+
translateText({
|
|
10
|
+
composable: '$fetch',
|
|
11
|
+
path: { tenant_id: tenantId },
|
|
12
|
+
body: request,
|
|
13
|
+
}),
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
translate,
|
|
18
|
+
isTranslating,
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { computed } from 'vue'
|
|
2
|
+
import { useRoute } from 'vue-router'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Check if route parameters are ready for use in API queries.
|
|
6
|
+
* Prevents queries from executing with placeholder values during route transitions.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const isRouteReady = useRouteReady('dataset_id')
|
|
10
|
+
* const isRouteReady = useRouteReady('agent_id', 'agent_class')
|
|
11
|
+
*/
|
|
12
|
+
export const useRouteReady = (...paramNames: string[]) => {
|
|
13
|
+
const route = useRoute()
|
|
14
|
+
|
|
15
|
+
return computed(() => {
|
|
16
|
+
return paramNames.every((param) => {
|
|
17
|
+
const value = route.params[param]
|
|
18
|
+
return !!value && typeof value === 'string' && !value.startsWith('{')
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
type TimeAgo = {
|
|
2
|
+
text: string
|
|
3
|
+
severity: 'success' | 'info' | 'warning' | 'danger'
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function useTimeAgo() {
|
|
7
|
+
const { t } = useI18n()
|
|
8
|
+
|
|
9
|
+
const getTimeAgo = (dateValue: string | number | Date): TimeAgo => {
|
|
10
|
+
const date = new Date(dateValue)
|
|
11
|
+
const now = new Date()
|
|
12
|
+
const diffInSeconds = (now.getTime() - date.getTime()) / 1000
|
|
13
|
+
|
|
14
|
+
const minute = 60
|
|
15
|
+
const hour = minute * 60
|
|
16
|
+
const day = hour * 24
|
|
17
|
+
const week = day * 7
|
|
18
|
+
const month = day * 30.44 // Average month length
|
|
19
|
+
const year = day * 365.25 // Account for leap years
|
|
20
|
+
|
|
21
|
+
if (diffInSeconds < hour) {
|
|
22
|
+
return { text: t('time_ago.last_hour'), severity: 'success' }
|
|
23
|
+
}
|
|
24
|
+
if (diffInSeconds < day) {
|
|
25
|
+
return { text: t('time_ago.last_day'), severity: 'success' }
|
|
26
|
+
}
|
|
27
|
+
if (diffInSeconds < week) {
|
|
28
|
+
return { text: t('time_ago.last_week'), severity: 'info' }
|
|
29
|
+
}
|
|
30
|
+
if (diffInSeconds < month) {
|
|
31
|
+
return { text: t('time_ago.last_month'), severity: 'warning' }
|
|
32
|
+
}
|
|
33
|
+
if (diffInSeconds < year) {
|
|
34
|
+
return { text: t('time_ago.last_year'), severity: 'danger' }
|
|
35
|
+
}
|
|
36
|
+
return { text: t('time_ago.long_time_ago'), severity: 'danger' }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return { getTimeAgo }
|
|
40
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { assignRole } from '@core/sdk/client'
|
|
2
|
+
|
|
3
|
+
export const useAssignRoleToUser = defineMutation(() => {
|
|
4
|
+
const queryCache = useQueryCache()
|
|
5
|
+
|
|
6
|
+
const { mutateAsync, isLoading } = useMutation({
|
|
7
|
+
mutation: async ({ tenantId, userId, roleName }: { tenantId: string, userId: string, roleName: string }) => {
|
|
8
|
+
const result = await assignRole({
|
|
9
|
+
composable: '$fetch',
|
|
10
|
+
path: { tenant_id: tenantId, user_id: userId },
|
|
11
|
+
body: { role_name: roleName },
|
|
12
|
+
})
|
|
13
|
+
queryCache.invalidateQueries()
|
|
14
|
+
return result
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
assignRole: mutateAsync,
|
|
20
|
+
assignRoleIsLoading: isLoading,
|
|
21
|
+
}
|
|
22
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getMyAccount, type UserWithAccessDto } from '@core/sdk/client'
|
|
2
|
+
import { minutesToMilliseconds } from 'date-fns'
|
|
3
|
+
|
|
4
|
+
export default defineQuery(() => {
|
|
5
|
+
const { tenantId } = useTenant()
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
data: myUser,
|
|
9
|
+
isPending: myUserIsLoading,
|
|
10
|
+
} = useQuery<UserWithAccessDto>({
|
|
11
|
+
key: () => ['tenant', tenantId.value, 'my_user'],
|
|
12
|
+
staleTime: minutesToMilliseconds(5),
|
|
13
|
+
enabled: useTenantReady(),
|
|
14
|
+
query: async () => {
|
|
15
|
+
return await getMyAccount({
|
|
16
|
+
composable: '$fetch',
|
|
17
|
+
path: { tenant_id: tenantId.value! },
|
|
18
|
+
})
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
return {
|
|
22
|
+
myUser,
|
|
23
|
+
myUserIsLoading,
|
|
24
|
+
}
|
|
25
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { revokeRole } from '@core/sdk/client'
|
|
2
|
+
|
|
3
|
+
export const useRevokeRoleFromUser = defineMutation(() => {
|
|
4
|
+
const queryCache = useQueryCache()
|
|
5
|
+
|
|
6
|
+
const { mutateAsync, isLoading } = useMutation({
|
|
7
|
+
mutation: async ({ tenantId, userId, roleName }: { tenantId: string, userId: string, roleName: string }) => {
|
|
8
|
+
const result = await revokeRole({
|
|
9
|
+
composable: '$fetch',
|
|
10
|
+
path: { tenant_id: tenantId, user_id: userId, role_name: roleName },
|
|
11
|
+
})
|
|
12
|
+
queryCache.invalidateQueries()
|
|
13
|
+
return result
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
revokeRole: mutateAsync,
|
|
19
|
+
revokeRoleIsLoading: isLoading,
|
|
20
|
+
}
|
|
21
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getUser, type UserWithAccessDto } from '@core/sdk/client'
|
|
2
|
+
import { minutesToMilliseconds } from 'date-fns'
|
|
3
|
+
import { useRoute } from 'vue-router'
|
|
4
|
+
|
|
5
|
+
export default defineQuery(() => {
|
|
6
|
+
const route = useRoute()
|
|
7
|
+
const { tenantId } = useTenant()
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
data: user,
|
|
11
|
+
isPending: userIsLoading,
|
|
12
|
+
} = useQuery<UserWithAccessDto>({
|
|
13
|
+
key: () => ['tenant', tenantId.value, 'users', route.params.user_id as string],
|
|
14
|
+
staleTime: minutesToMilliseconds(5),
|
|
15
|
+
enabled: useTenantReady('user_id'),
|
|
16
|
+
query: async () => {
|
|
17
|
+
return await getUser({
|
|
18
|
+
composable: '$fetch',
|
|
19
|
+
path: {
|
|
20
|
+
tenant_id: tenantId.value!,
|
|
21
|
+
user_id: route.params.user_id as string,
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
return {
|
|
27
|
+
user,
|
|
28
|
+
userIsLoading,
|
|
29
|
+
}
|
|
30
|
+
})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { getUsers, type UserDto } from '@core/sdk/client'
|
|
2
|
+
|
|
3
|
+
export default defineQuery(() => {
|
|
4
|
+
const { tenantId } = useTenant()
|
|
5
|
+
const currentPage = ref(1)
|
|
6
|
+
const pageSize = ref(20)
|
|
7
|
+
|
|
8
|
+
const usersQuery = useQuery({
|
|
9
|
+
key: () => ['tenant', tenantId.value, 'users', { page: currentPage.value, size: pageSize.value }],
|
|
10
|
+
enabled: useTenantReady(),
|
|
11
|
+
query: async () => {
|
|
12
|
+
const pageToFetch = Math.max(1, currentPage.value)
|
|
13
|
+
|
|
14
|
+
return await getUsers({
|
|
15
|
+
composable: '$fetch',
|
|
16
|
+
path: { tenant_id: tenantId.value! },
|
|
17
|
+
query: {
|
|
18
|
+
page: pageToFetch,
|
|
19
|
+
page_size: pageSize.value,
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
},
|
|
23
|
+
placeholderData: previousData => previousData,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const setPageSize = (newSize: number) => {
|
|
27
|
+
if (newSize > 0) {
|
|
28
|
+
pageSize.value = newSize
|
|
29
|
+
currentPage.value = 1
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const setPage = (newPage: number) => {
|
|
34
|
+
if (newPage > 0) {
|
|
35
|
+
currentPage.value = newPage
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const pagination = computed(() => {
|
|
40
|
+
const data = usersQuery.data.value
|
|
41
|
+
return {
|
|
42
|
+
total: data?.total ?? 0,
|
|
43
|
+
currentPage: data?.page ?? currentPage.value,
|
|
44
|
+
pageSize: data?.page_size ?? pageSize.value,
|
|
45
|
+
totalPages: data?.total_pages ?? 0,
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const users = computed(() => usersQuery.data.value?.users ?? ([] as UserDto[]))
|
|
50
|
+
const usersAreLoading = computed(() => usersQuery.isLoading.value)
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
users,
|
|
54
|
+
usersAreLoading,
|
|
55
|
+
pagination,
|
|
56
|
+
currentPage,
|
|
57
|
+
pageSize,
|
|
58
|
+
setPage,
|
|
59
|
+
setPageSize,
|
|
60
|
+
refetchUsers: usersQuery.refetch,
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
})
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { TreeNode } from 'primevue/treenode'
|
|
2
|
+
|
|
3
|
+
interface JsonTreeOptions {
|
|
4
|
+
maxDepth?: number
|
|
5
|
+
expandLevel?: number
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const useJsonTree = () => {
|
|
9
|
+
const convertJsonToTree = (
|
|
10
|
+
data: unknown,
|
|
11
|
+
key: string = 'root',
|
|
12
|
+
options: JsonTreeOptions = {},
|
|
13
|
+
): TreeNode[] => {
|
|
14
|
+
const { maxDepth = 10, expandLevel = 2 } = options
|
|
15
|
+
|
|
16
|
+
const createNode = (
|
|
17
|
+
value: unknown,
|
|
18
|
+
label: string,
|
|
19
|
+
depth: number = 0,
|
|
20
|
+
parentPath: string = '',
|
|
21
|
+
): TreeNode => {
|
|
22
|
+
const currentPath = parentPath ? `${parentPath}.${label}` : label
|
|
23
|
+
const nodeKey = `${key}_${currentPath}_${depth}`.replaceAll(/[^a-zA-Z0-9_.-]/g, '_')
|
|
24
|
+
|
|
25
|
+
if (value === null) {
|
|
26
|
+
return {
|
|
27
|
+
key: nodeKey,
|
|
28
|
+
label: `${label}: null`,
|
|
29
|
+
type: 'null',
|
|
30
|
+
leaf: true,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (value === undefined) {
|
|
35
|
+
return {
|
|
36
|
+
key: nodeKey,
|
|
37
|
+
label: `${label}: undefined`,
|
|
38
|
+
type: 'undefined',
|
|
39
|
+
leaf: true,
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const valueType = typeof value
|
|
44
|
+
|
|
45
|
+
if (valueType === 'string') {
|
|
46
|
+
return {
|
|
47
|
+
key: nodeKey,
|
|
48
|
+
label: `${label}: "${value}"`,
|
|
49
|
+
type: 'string',
|
|
50
|
+
leaf: true,
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (valueType === 'number' || valueType === 'boolean') {
|
|
55
|
+
return {
|
|
56
|
+
key: nodeKey,
|
|
57
|
+
label: `${label}: ${value}`,
|
|
58
|
+
type: valueType,
|
|
59
|
+
leaf: true,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (Array.isArray(value)) {
|
|
64
|
+
const arrayLabel = `${label} [${value.length}]`
|
|
65
|
+
|
|
66
|
+
if (depth >= maxDepth) {
|
|
67
|
+
return {
|
|
68
|
+
key: nodeKey,
|
|
69
|
+
label: `${arrayLabel}: [max depth reached]`,
|
|
70
|
+
type: 'array',
|
|
71
|
+
leaf: true,
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const children = value.map((item, index) =>
|
|
76
|
+
createNode(item, `[${index}]`, depth + 1, currentPath),
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
key: nodeKey,
|
|
81
|
+
label: arrayLabel,
|
|
82
|
+
type: 'array',
|
|
83
|
+
leaf: children.length === 0,
|
|
84
|
+
children,
|
|
85
|
+
expanded: depth < expandLevel,
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (valueType === 'object') {
|
|
90
|
+
const entries = Object.entries(value)
|
|
91
|
+
const objectLabel = `${label} {${entries.length}}`
|
|
92
|
+
|
|
93
|
+
if (depth >= maxDepth) {
|
|
94
|
+
return {
|
|
95
|
+
key: nodeKey,
|
|
96
|
+
label: `${objectLabel}: {max depth reached}`,
|
|
97
|
+
type: 'object',
|
|
98
|
+
leaf: true,
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const children = entries.map(([objKey, objValue]) =>
|
|
103
|
+
createNode(objValue, objKey, depth + 1, currentPath),
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
key: nodeKey,
|
|
108
|
+
label: objectLabel,
|
|
109
|
+
type: 'object',
|
|
110
|
+
leaf: children.length === 0,
|
|
111
|
+
children,
|
|
112
|
+
expanded: depth < expandLevel,
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Fallback for unknown types
|
|
117
|
+
return {
|
|
118
|
+
key: nodeKey,
|
|
119
|
+
label: `${label}: ${String(value)}`,
|
|
120
|
+
type: 'unknown',
|
|
121
|
+
leaf: true,
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (typeof data === 'object' && data !== null) {
|
|
126
|
+
const entries = Object.entries(data)
|
|
127
|
+
return entries.map(([objKey, objValue]) =>
|
|
128
|
+
createNode(objValue, objKey, 0, ''),
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return [createNode(data, 'value', 0, '')]
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
convertJsonToTree,
|
|
137
|
+
}
|
|
138
|
+
}
|