@gokulvenkatareddy/cortex 0.1.7
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/README.md +1295 -0
- package/apps/octogent/.github/workflows/ci.yml +40 -0
- package/apps/octogent/.shims/claude +4 -0
- package/apps/octogent/AGENTS.md +71 -0
- package/apps/octogent/CONTRIBUTING.md +72 -0
- package/apps/octogent/LICENSE +21 -0
- package/apps/octogent/README.md +184 -0
- package/apps/octogent/apps/api/AGENTS.md +32 -0
- package/apps/octogent/apps/api/package.json +19 -0
- package/apps/octogent/apps/api/src/agentStateDetection.ts +181 -0
- package/apps/octogent/apps/api/src/claudeSessionScanner.ts +235 -0
- package/apps/octogent/apps/api/src/claudeSkills.ts +182 -0
- package/apps/octogent/apps/api/src/claudeUsage.ts +922 -0
- package/apps/octogent/apps/api/src/cli.ts +595 -0
- package/apps/octogent/apps/api/src/codeIntelStore.ts +46 -0
- package/apps/octogent/apps/api/src/codexUsage.ts +278 -0
- package/apps/octogent/apps/api/src/createApiServer/codeIntelRoutes.ts +60 -0
- package/apps/octogent/apps/api/src/createApiServer/conversationRoutes.ts +128 -0
- package/apps/octogent/apps/api/src/createApiServer/deckRoutes.ts +873 -0
- package/apps/octogent/apps/api/src/createApiServer/gitParsers.ts +140 -0
- package/apps/octogent/apps/api/src/createApiServer/gitRoutes.ts +214 -0
- package/apps/octogent/apps/api/src/createApiServer/miscRoutes.ts +316 -0
- package/apps/octogent/apps/api/src/createApiServer/monitorParsers.ts +137 -0
- package/apps/octogent/apps/api/src/createApiServer/monitorRoutes.ts +95 -0
- package/apps/octogent/apps/api/src/createApiServer/requestHandler.ts +311 -0
- package/apps/octogent/apps/api/src/createApiServer/requestParsers.ts +25 -0
- package/apps/octogent/apps/api/src/createApiServer/routeHelpers.ts +97 -0
- package/apps/octogent/apps/api/src/createApiServer/security.ts +70 -0
- package/apps/octogent/apps/api/src/createApiServer/terminalParsers.ts +167 -0
- package/apps/octogent/apps/api/src/createApiServer/terminalRoutes.ts +315 -0
- package/apps/octogent/apps/api/src/createApiServer/types.ts +24 -0
- package/apps/octogent/apps/api/src/createApiServer/uiStateParsers.ts +255 -0
- package/apps/octogent/apps/api/src/createApiServer/upgradeHandler.ts +38 -0
- package/apps/octogent/apps/api/src/createApiServer/usageRoutes.ts +84 -0
- package/apps/octogent/apps/api/src/createApiServer.ts +176 -0
- package/apps/octogent/apps/api/src/deck/readDeckTentacles.ts +595 -0
- package/apps/octogent/apps/api/src/githubRepoSummary.ts +397 -0
- package/apps/octogent/apps/api/src/logging.ts +9 -0
- package/apps/octogent/apps/api/src/monitor/defaults.ts +3 -0
- package/apps/octogent/apps/api/src/monitor/index.ts +8 -0
- package/apps/octogent/apps/api/src/monitor/repository.ts +303 -0
- package/apps/octogent/apps/api/src/monitor/service.ts +349 -0
- package/apps/octogent/apps/api/src/monitor/types.ts +120 -0
- package/apps/octogent/apps/api/src/monitor/xProvider.ts +587 -0
- package/apps/octogent/apps/api/src/projectPersistence.ts +377 -0
- package/apps/octogent/apps/api/src/prompts/index.ts +10 -0
- package/apps/octogent/apps/api/src/prompts/promptResolver.ts +145 -0
- package/apps/octogent/apps/api/src/runtimeMetadata.ts +69 -0
- package/apps/octogent/apps/api/src/server.ts +80 -0
- package/apps/octogent/apps/api/src/setupState.ts +80 -0
- package/apps/octogent/apps/api/src/setupStatus.ts +174 -0
- package/apps/octogent/apps/api/src/startupPrerequisites.ts +146 -0
- package/apps/octogent/apps/api/src/terminalRuntime/channelMessaging.ts +87 -0
- package/apps/octogent/apps/api/src/terminalRuntime/claudeTranscript.ts +279 -0
- package/apps/octogent/apps/api/src/terminalRuntime/constants.ts +15 -0
- package/apps/octogent/apps/api/src/terminalRuntime/conversations.ts +492 -0
- package/apps/octogent/apps/api/src/terminalRuntime/gitOperations.ts +341 -0
- package/apps/octogent/apps/api/src/terminalRuntime/hookProcessor.ts +405 -0
- package/apps/octogent/apps/api/src/terminalRuntime/protocol.ts +46 -0
- package/apps/octogent/apps/api/src/terminalRuntime/ptyEnvironment.ts +50 -0
- package/apps/octogent/apps/api/src/terminalRuntime/registry.ts +423 -0
- package/apps/octogent/apps/api/src/terminalRuntime/sessionRuntime.ts +671 -0
- package/apps/octogent/apps/api/src/terminalRuntime/systemClients.ts +432 -0
- package/apps/octogent/apps/api/src/terminalRuntime/types.ts +157 -0
- package/apps/octogent/apps/api/src/terminalRuntime/worktreeManager.ts +135 -0
- package/apps/octogent/apps/api/src/terminalRuntime.ts +567 -0
- package/apps/octogent/apps/api/src/usageUtils.ts +16 -0
- package/apps/octogent/apps/api/src/ws-shim.d.ts +28 -0
- package/apps/octogent/apps/api/tests/agentStateDetection.test.ts +67 -0
- package/apps/octogent/apps/api/tests/claudeUsage.test.ts +583 -0
- package/apps/octogent/apps/api/tests/codexUsage.test.ts +107 -0
- package/apps/octogent/apps/api/tests/createApiServer.test.ts +3207 -0
- package/apps/octogent/apps/api/tests/githubRepoSummary.test.ts +100 -0
- package/apps/octogent/apps/api/tests/logging.test.ts +33 -0
- package/apps/octogent/apps/api/tests/monitorApi.test.ts +467 -0
- package/apps/octogent/apps/api/tests/monitorCore.test.ts +104 -0
- package/apps/octogent/apps/api/tests/promptResolver.test.ts +109 -0
- package/apps/octogent/apps/api/tests/protocol.test.ts +14 -0
- package/apps/octogent/apps/api/tests/sessionRuntime.test.ts +608 -0
- package/apps/octogent/apps/api/tests/startupPrerequisites.test.ts +70 -0
- package/apps/octogent/apps/api/tests/upgradeHandler.test.ts +40 -0
- package/apps/octogent/apps/api/tests/xMonitorProvider.test.ts +109 -0
- package/apps/octogent/apps/api/tsconfig.json +7 -0
- package/apps/octogent/apps/api/vitest.config.ts +7 -0
- package/apps/octogent/apps/web/AGENTS.md +38 -0
- package/apps/octogent/apps/web/index.html +13 -0
- package/apps/octogent/apps/web/package.json +32 -0
- package/apps/octogent/apps/web/public/octopus-favicon.svg +26 -0
- package/apps/octogent/apps/web/src/App.tsx +646 -0
- package/apps/octogent/apps/web/src/app/canvas/types.ts +34 -0
- package/apps/octogent/apps/web/src/app/codeIntelAggregation.ts +278 -0
- package/apps/octogent/apps/web/src/app/constants.ts +28 -0
- package/apps/octogent/apps/web/src/app/conversationNormalizers.ts +135 -0
- package/apps/octogent/apps/web/src/app/formatTimestamp.ts +18 -0
- package/apps/octogent/apps/web/src/app/githubMetrics.ts +76 -0
- package/apps/octogent/apps/web/src/app/githubNormalizers.ts +91 -0
- package/apps/octogent/apps/web/src/app/hooks/useAgentRuntimeStates.ts +18 -0
- package/apps/octogent/apps/web/src/app/hooks/useBackendLivenessPolling.ts +53 -0
- package/apps/octogent/apps/web/src/app/hooks/useCanvasGraphData.ts +449 -0
- package/apps/octogent/apps/web/src/app/hooks/useCanvasTransform.ts +260 -0
- package/apps/octogent/apps/web/src/app/hooks/useClaudeUsagePolling.ts +40 -0
- package/apps/octogent/apps/web/src/app/hooks/useClickOutside.ts +30 -0
- package/apps/octogent/apps/web/src/app/hooks/useCodeIntelRuntime.ts +83 -0
- package/apps/octogent/apps/web/src/app/hooks/useCodexUsagePolling.ts +35 -0
- package/apps/octogent/apps/web/src/app/hooks/useConsoleKeyboardShortcuts.ts +31 -0
- package/apps/octogent/apps/web/src/app/hooks/useConversationsRuntime.ts +377 -0
- package/apps/octogent/apps/web/src/app/hooks/useForceSimulation.ts +319 -0
- package/apps/octogent/apps/web/src/app/hooks/useGitHubPrimaryViewModel.ts +143 -0
- package/apps/octogent/apps/web/src/app/hooks/useGithubSummaryPolling.ts +28 -0
- package/apps/octogent/apps/web/src/app/hooks/useInitialColumnsHydration.ts +64 -0
- package/apps/octogent/apps/web/src/app/hooks/useMonitorRuntime.ts +220 -0
- package/apps/octogent/apps/web/src/app/hooks/usePersistedUiState.ts +536 -0
- package/apps/octogent/apps/web/src/app/hooks/usePollingData.ts +79 -0
- package/apps/octogent/apps/web/src/app/hooks/usePromptLibrary.ts +185 -0
- package/apps/octogent/apps/web/src/app/hooks/useTentacleGitLifecycle.ts +530 -0
- package/apps/octogent/apps/web/src/app/hooks/useTerminalCompletionNotification.ts +94 -0
- package/apps/octogent/apps/web/src/app/hooks/useTerminalMutations.ts +266 -0
- package/apps/octogent/apps/web/src/app/hooks/useTerminalStateReconciliation.ts +23 -0
- package/apps/octogent/apps/web/src/app/hooks/useUsageHeatmapPolling.ts +43 -0
- package/apps/octogent/apps/web/src/app/hooks/useWorkspaceSetup.ts +80 -0
- package/apps/octogent/apps/web/src/app/hotkeys.ts +31 -0
- package/apps/octogent/apps/web/src/app/monitorNormalizers.ts +145 -0
- package/apps/octogent/apps/web/src/app/notificationSounds.ts +164 -0
- package/apps/octogent/apps/web/src/app/terminalRuntimeStateStore.ts +261 -0
- package/apps/octogent/apps/web/src/app/terminalState.ts +21 -0
- package/apps/octogent/apps/web/src/app/types.ts +42 -0
- package/apps/octogent/apps/web/src/app/uiStateNormalizers.ts +113 -0
- package/apps/octogent/apps/web/src/app/usageNormalizers.ts +58 -0
- package/apps/octogent/apps/web/src/components/ActiveAgentsSidebar.tsx +60 -0
- package/apps/octogent/apps/web/src/components/ActivityPrimaryView.tsx +21 -0
- package/apps/octogent/apps/web/src/components/AgentStateBadge.tsx +47 -0
- package/apps/octogent/apps/web/src/components/CanvasPrimaryView.tsx +1532 -0
- package/apps/octogent/apps/web/src/components/ClearAllConversationsDialog.tsx +33 -0
- package/apps/octogent/apps/web/src/components/CodeIntelArcDiagram.tsx +245 -0
- package/apps/octogent/apps/web/src/components/CodeIntelPrimaryView.tsx +104 -0
- package/apps/octogent/apps/web/src/components/CodeIntelTreemap.tsx +138 -0
- package/apps/octogent/apps/web/src/components/ConsolePrimaryNav.tsx +31 -0
- package/apps/octogent/apps/web/src/components/ConversationsPrimaryView.tsx +243 -0
- package/apps/octogent/apps/web/src/components/DeckPrimaryView.tsx +613 -0
- package/apps/octogent/apps/web/src/components/DeleteTentacleDialog.tsx +91 -0
- package/apps/octogent/apps/web/src/components/EmptyOctopus.tsx +715 -0
- package/apps/octogent/apps/web/src/components/GitHubPrimaryView.tsx +494 -0
- package/apps/octogent/apps/web/src/components/MonitorPrimaryView.tsx +475 -0
- package/apps/octogent/apps/web/src/components/PrimaryViewRouter.tsx +99 -0
- package/apps/octogent/apps/web/src/components/PromptsPrimaryView.tsx +243 -0
- package/apps/octogent/apps/web/src/components/RuntimeStatusStrip.tsx +273 -0
- package/apps/octogent/apps/web/src/components/SettingsPrimaryView.tsx +92 -0
- package/apps/octogent/apps/web/src/components/SidebarActionPanel.tsx +124 -0
- package/apps/octogent/apps/web/src/components/SidebarConversationsList.tsx +279 -0
- package/apps/octogent/apps/web/src/components/SidebarPromptsList.tsx +116 -0
- package/apps/octogent/apps/web/src/components/TelemetryTape.tsx +106 -0
- package/apps/octogent/apps/web/src/components/TentacleGitActionsDialog.tsx +341 -0
- package/apps/octogent/apps/web/src/components/Terminal.tsx +524 -0
- package/apps/octogent/apps/web/src/components/TerminalPromptPicker.tsx +140 -0
- package/apps/octogent/apps/web/src/components/UsageHeatmap.tsx +702 -0
- package/apps/octogent/apps/web/src/components/canvas/CanvasTentaclePanel.tsx +485 -0
- package/apps/octogent/apps/web/src/components/canvas/CanvasTerminalColumn.tsx +89 -0
- package/apps/octogent/apps/web/src/components/canvas/DeleteAllTerminalsDialog.tsx +221 -0
- package/apps/octogent/apps/web/src/components/canvas/OctopusNode.tsx +307 -0
- package/apps/octogent/apps/web/src/components/canvas/SessionNode.tsx +185 -0
- package/apps/octogent/apps/web/src/components/deck/ActionCards.tsx +118 -0
- package/apps/octogent/apps/web/src/components/deck/AddTentacleForm.tsx +269 -0
- package/apps/octogent/apps/web/src/components/deck/DeckBottomActions.tsx +56 -0
- package/apps/octogent/apps/web/src/components/deck/TentaclePod.tsx +334 -0
- package/apps/octogent/apps/web/src/components/deck/WorkspaceSetupCard.tsx +105 -0
- package/apps/octogent/apps/web/src/components/deck/octopusVisuals.ts +72 -0
- package/apps/octogent/apps/web/src/components/terminalReplay.ts +62 -0
- package/apps/octogent/apps/web/src/components/terminalWheel.ts +54 -0
- package/apps/octogent/apps/web/src/components/ui/ActionButton.tsx +34 -0
- package/apps/octogent/apps/web/src/components/ui/ConfirmationDialog.tsx +86 -0
- package/apps/octogent/apps/web/src/components/ui/MarkdownContent.tsx +43 -0
- package/apps/octogent/apps/web/src/components/ui/SettingsToggle.tsx +34 -0
- package/apps/octogent/apps/web/src/components/ui/StatusBadge.tsx +24 -0
- package/apps/octogent/apps/web/src/main.tsx +17 -0
- package/apps/octogent/apps/web/src/runtime/HttpTerminalSnapshotReader.ts +87 -0
- package/apps/octogent/apps/web/src/runtime/runtimeEndpoints.ts +412 -0
- package/apps/octogent/apps/web/src/styles/chrome-and-buttons.css +272 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-activity.css +358 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-canvas.css +1843 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-code-intel.css +227 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-conversations.css +705 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-deck.css +1524 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-github.css +541 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-monitor.css +595 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-pixpack.css +81 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-prompts.css +474 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-settings.css +207 -0
- package/apps/octogent/apps/web/src/styles/console-chrome-status-nav.css +441 -0
- package/apps/octogent/apps/web/src/styles/console-overrides-telemetry.css +320 -0
- package/apps/octogent/apps/web/src/styles/console-theme-tokens.css +25 -0
- package/apps/octogent/apps/web/src/styles/cortex-theme.css +412 -0
- package/apps/octogent/apps/web/src/styles/foundation.css +100 -0
- package/apps/octogent/apps/web/src/styles/sidebar-and-scrollbars.css +447 -0
- package/apps/octogent/apps/web/src/styles/terminal-and-status.css +356 -0
- package/apps/octogent/apps/web/src/styles.css +25 -0
- package/apps/octogent/apps/web/src/types/ws.d.ts +23 -0
- package/apps/octogent/apps/web/tests/CanvasPrimaryView.test.tsx +347 -0
- package/apps/octogent/apps/web/tests/HttpTerminalSnapshotReader.test.tsx +54 -0
- package/apps/octogent/apps/web/tests/RuntimeStatusStrip.test.tsx +70 -0
- package/apps/octogent/apps/web/tests/Terminal.test.tsx +87 -0
- package/apps/octogent/apps/web/tests/add-tentacle-form.test.tsx +48 -0
- package/apps/octogent/apps/web/tests/app-github-runtime.test.tsx +162 -0
- package/apps/octogent/apps/web/tests/app-monitor-runtime.test.tsx +657 -0
- package/apps/octogent/apps/web/tests/app-shell-navigation.test.tsx +109 -0
- package/apps/octogent/apps/web/tests/app-swarm-refresh.test.tsx +268 -0
- package/apps/octogent/apps/web/tests/app-ui-state-persistence.test.tsx +116 -0
- package/apps/octogent/apps/web/tests/app-workspace-setup.test.tsx +217 -0
- package/apps/octogent/apps/web/tests/canvas-tentacle-panel.test.tsx +195 -0
- package/apps/octogent/apps/web/tests/delete-all-terminals-dialog.test.tsx +76 -0
- package/apps/octogent/apps/web/tests/githubMetrics.test.tsx +52 -0
- package/apps/octogent/apps/web/tests/hotkeys.test.tsx +44 -0
- package/apps/octogent/apps/web/tests/runtimeEndpoints.test.tsx +240 -0
- package/apps/octogent/apps/web/tests/setup.ts +39 -0
- package/apps/octogent/apps/web/tests/tentacle-pod.test.tsx +62 -0
- package/apps/octogent/apps/web/tests/terminalReplay.test.ts +71 -0
- package/apps/octogent/apps/web/tests/terminalState.test.tsx +49 -0
- package/apps/octogent/apps/web/tests/terminalWheel.test.tsx +51 -0
- package/apps/octogent/apps/web/tests/test-utils/appTestHarness.ts +48 -0
- package/apps/octogent/apps/web/tests/uiPrimitives.test.tsx +31 -0
- package/apps/octogent/apps/web/tests/useAgentRuntimeStates.test.tsx +47 -0
- package/apps/octogent/apps/web/tsconfig.json +8 -0
- package/apps/octogent/apps/web/vite.api.bundle.config.mts +32 -0
- package/apps/octogent/apps/web/vite.config.ts +22 -0
- package/apps/octogent/bin/octogent +3 -0
- package/apps/octogent/biome.json +21 -0
- package/apps/octogent/docs/concepts/mental-model.md +79 -0
- package/apps/octogent/docs/concepts/runtime-and-api.md +60 -0
- package/apps/octogent/docs/concepts/tentacles.md +85 -0
- package/apps/octogent/docs/getting-started/installation.md +54 -0
- package/apps/octogent/docs/getting-started/quickstart.md +79 -0
- package/apps/octogent/docs/guides/inter-agent-messaging.md +43 -0
- package/apps/octogent/docs/guides/orchestrating-child-agents.md +49 -0
- package/apps/octogent/docs/guides/working-with-todos.md +56 -0
- package/apps/octogent/docs/index.md +40 -0
- package/apps/octogent/docs/reference/api.md +103 -0
- package/apps/octogent/docs/reference/cli.md +71 -0
- package/apps/octogent/docs/reference/experimental-features.md +28 -0
- package/apps/octogent/docs/reference/filesystem-layout.md +62 -0
- package/apps/octogent/docs/reference/troubleshooting.md +49 -0
- package/apps/octogent/package.json +35 -0
- package/apps/octogent/packages/core/AGENTS.md +31 -0
- package/apps/octogent/packages/core/package.json +12 -0
- package/apps/octogent/packages/core/src/adapters/InMemoryTerminalSnapshotReader.ts +10 -0
- package/apps/octogent/packages/core/src/application/buildTerminalList.ts +13 -0
- package/apps/octogent/packages/core/src/domain/agentRuntime.ts +18 -0
- package/apps/octogent/packages/core/src/domain/channel.ts +8 -0
- package/apps/octogent/packages/core/src/domain/completionSound.ts +14 -0
- package/apps/octogent/packages/core/src/domain/conversation.ts +48 -0
- package/apps/octogent/packages/core/src/domain/deck.ts +33 -0
- package/apps/octogent/packages/core/src/domain/git.ts +32 -0
- package/apps/octogent/packages/core/src/domain/monitor.ts +62 -0
- package/apps/octogent/packages/core/src/domain/setup.ts +27 -0
- package/apps/octogent/packages/core/src/domain/terminal.ts +17 -0
- package/apps/octogent/packages/core/src/domain/uiState.ts +22 -0
- package/apps/octogent/packages/core/src/domain/usage.ts +60 -0
- package/apps/octogent/packages/core/src/index.ts +15 -0
- package/apps/octogent/packages/core/src/ports/TerminalSnapshotReader.ts +5 -0
- package/apps/octogent/packages/core/src/util/typeCoercion.ts +20 -0
- package/apps/octogent/packages/core/tests/buildTerminalList.test.ts +75 -0
- package/apps/octogent/packages/core/tsconfig.json +7 -0
- package/apps/octogent/packages/core/tsconfig.tsbuildinfo +1 -0
- package/apps/octogent/packages/core/vitest.config.ts +7 -0
- package/apps/octogent/pnpm-lock.yaml +3212 -0
- package/apps/octogent/pnpm-workspace.yaml +3 -0
- package/apps/octogent/prompts/meta-prompt-generator.md +223 -0
- package/apps/octogent/prompts/octoboss-clean-contexts.md +30 -0
- package/apps/octogent/prompts/octoboss-reorganize-tentacles.md +29 -0
- package/apps/octogent/prompts/octoboss-reorganize-todos.md +27 -0
- package/apps/octogent/prompts/sandbox-init.md +3 -0
- package/apps/octogent/prompts/swarm-parent.md +83 -0
- package/apps/octogent/prompts/swarm-worker.md +50 -0
- package/apps/octogent/prompts/tentacle-context-init.md +1 -0
- package/apps/octogent/prompts/tentacle-planner.md +110 -0
- package/apps/octogent/prompts/tentacle-reorganize-todos.md +20 -0
- package/apps/octogent/prompts/tentacle-update-tentacle.md +18 -0
- package/apps/octogent/scripts/build-package.mjs +23 -0
- package/apps/octogent/scripts/dev.mjs +158 -0
- package/apps/octogent/scripts/smoke-public-install.mjs +271 -0
- package/apps/octogent/static/images/octogent-header.png +0 -0
- package/apps/octogent/static/images/preview_1.jpg +0 -0
- package/apps/octogent/static/images/preview_2.jpg +0 -0
- package/apps/octogent/static/images/preview_3.jpg +0 -0
- package/apps/octogent/static/images/preview_4.jpg +0 -0
- package/apps/octogent/static/images/preview_5.jpg +0 -0
- package/apps/octogent/static/images/preview_6.jpg +0 -0
- package/apps/octogent/tsconfig.base.json +16 -0
- package/bin/AGI +3 -0
- package/bin/AGI-install-app +71 -0
- package/bin/AGI-ui +16 -0
- package/bin/AGI-voice +15 -0
- package/bin/AGI-web +16 -0
- package/bin/cortex +109 -0
- package/bin/cortex-octogent +99 -0
- package/bin/import-specifier.mjs +13 -0
- package/bin/import-specifier.test.mjs +13 -0
- package/bin/octo +150 -0
- package/dist/cli.mjs +555650 -0
- package/package.json +157 -0
- package/scripts/setup-wizard.ts +390 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useRef } from "react";
|
|
2
|
+
|
|
3
|
+
import { buildClaudeUsageUrl } from "../../runtime/runtimeEndpoints";
|
|
4
|
+
import { CODEX_USAGE_SCAN_INTERVAL_MS } from "../constants";
|
|
5
|
+
import type { ClaudeUsageSnapshot } from "../types";
|
|
6
|
+
import { normalizeClaudeUsageSnapshot } from "../usageNormalizers";
|
|
7
|
+
import { usePollingData } from "./usePollingData";
|
|
8
|
+
|
|
9
|
+
const fallback = (): ClaudeUsageSnapshot => ({
|
|
10
|
+
status: "error",
|
|
11
|
+
source: "none",
|
|
12
|
+
fetchedAt: new Date().toISOString(),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const useClaudeUsagePolling = () => {
|
|
16
|
+
const lastOkRef = useRef<ClaudeUsageSnapshot | null>(null);
|
|
17
|
+
|
|
18
|
+
const normalize = (raw: unknown): ClaudeUsageSnapshot | null => {
|
|
19
|
+
const snapshot = normalizeClaudeUsageSnapshot(raw);
|
|
20
|
+
if (snapshot?.status === "ok") {
|
|
21
|
+
lastOkRef.current = snapshot;
|
|
22
|
+
return snapshot;
|
|
23
|
+
}
|
|
24
|
+
// Keep showing the last successful snapshot until a new "ok" arrives
|
|
25
|
+
return lastOkRef.current ?? snapshot;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const { data, isLoading, refresh } = usePollingData<ClaudeUsageSnapshot>({
|
|
29
|
+
fetchUrl: buildClaudeUsageUrl(),
|
|
30
|
+
intervalMs: CODEX_USAGE_SCAN_INTERVAL_MS,
|
|
31
|
+
normalize,
|
|
32
|
+
fallback,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
claudeUsageSnapshot: data,
|
|
37
|
+
isRefreshingClaudeUsage: isLoading,
|
|
38
|
+
refreshClaudeUsage: refresh,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type RefObject, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
export const useClickOutside = (
|
|
4
|
+
ref: RefObject<HTMLElement | null>,
|
|
5
|
+
isActive: boolean,
|
|
6
|
+
onDismiss: () => void,
|
|
7
|
+
) => {
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (!isActive) return;
|
|
10
|
+
|
|
11
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
12
|
+
if (ref.current && !ref.current.contains(event.target as Node)) {
|
|
13
|
+
onDismiss();
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const handleEscape = (event: KeyboardEvent) => {
|
|
18
|
+
if (event.key === "Escape") {
|
|
19
|
+
onDismiss();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
24
|
+
document.addEventListener("keydown", handleEscape);
|
|
25
|
+
return () => {
|
|
26
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
27
|
+
document.removeEventListener("keydown", handleEscape);
|
|
28
|
+
};
|
|
29
|
+
}, [ref, isActive, onDismiss]);
|
|
30
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type CodeIntelEvent,
|
|
5
|
+
type CouplingData,
|
|
6
|
+
type TreemapNode,
|
|
7
|
+
buildCouplingData,
|
|
8
|
+
buildTreemapTree,
|
|
9
|
+
} from "../codeIntelAggregation";
|
|
10
|
+
|
|
11
|
+
type CodeIntelRuntimeResult = {
|
|
12
|
+
events: CodeIntelEvent[];
|
|
13
|
+
treemapRoot: TreemapNode | null;
|
|
14
|
+
couplingData: CouplingData | null;
|
|
15
|
+
isLoading: boolean;
|
|
16
|
+
error: string | null;
|
|
17
|
+
refresh: () => void;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const useCodeIntelRuntime = (enabled: boolean): CodeIntelRuntimeResult => {
|
|
21
|
+
const [events, setEvents] = useState<CodeIntelEvent[]>([]);
|
|
22
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
23
|
+
const [error, setError] = useState<string | null>(null);
|
|
24
|
+
|
|
25
|
+
const fetchEvents = useCallback(async () => {
|
|
26
|
+
setIsLoading(true);
|
|
27
|
+
setError(null);
|
|
28
|
+
try {
|
|
29
|
+
const response = await fetch("/api/code-intel/events");
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
setError(`Failed to load events: ${response.status}`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const data = (await response.json()) as { events: CodeIntelEvent[] };
|
|
35
|
+
setEvents(data.events);
|
|
36
|
+
} catch {
|
|
37
|
+
setError("Failed to connect to API");
|
|
38
|
+
} finally {
|
|
39
|
+
setIsLoading(false);
|
|
40
|
+
}
|
|
41
|
+
}, []);
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (!enabled) return;
|
|
45
|
+
void fetchEvents();
|
|
46
|
+
}, [enabled, fetchEvents]);
|
|
47
|
+
|
|
48
|
+
// Derive workspace cwd from common prefix of file paths
|
|
49
|
+
const workspaceCwd = events.length > 0 ? deriveWorkspaceCwd(events.map((e) => e.file)) : "";
|
|
50
|
+
|
|
51
|
+
const treemapRoot = events.length > 0 ? buildTreemapTree(events, workspaceCwd) : null;
|
|
52
|
+
const couplingData = events.length > 0 ? buildCouplingData(events, workspaceCwd) : null;
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
events,
|
|
56
|
+
treemapRoot,
|
|
57
|
+
couplingData,
|
|
58
|
+
isLoading,
|
|
59
|
+
error,
|
|
60
|
+
refresh: () => {
|
|
61
|
+
void fetchEvents();
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** Find the longest common directory prefix across all file paths. */
|
|
67
|
+
const deriveWorkspaceCwd = (paths: string[]): string => {
|
|
68
|
+
const [firstPath] = paths;
|
|
69
|
+
if (!firstPath) return "";
|
|
70
|
+
const parts = firstPath.split("/");
|
|
71
|
+
let prefix = "";
|
|
72
|
+
|
|
73
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
74
|
+
const candidate = parts.slice(0, i + 1).join("/");
|
|
75
|
+
if (paths.every((p) => p.startsWith(`${candidate}/`))) {
|
|
76
|
+
prefix = candidate;
|
|
77
|
+
} else {
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return prefix;
|
|
83
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useRef } from "react";
|
|
2
|
+
|
|
3
|
+
import { buildCodexUsageUrl } from "../../runtime/runtimeEndpoints";
|
|
4
|
+
import { CODEX_USAGE_SCAN_INTERVAL_MS } from "../constants";
|
|
5
|
+
import type { CodexUsageSnapshot } from "../types";
|
|
6
|
+
import { normalizeCodexUsageSnapshot } from "../usageNormalizers";
|
|
7
|
+
import { usePollingData } from "./usePollingData";
|
|
8
|
+
|
|
9
|
+
const fallback = (): CodexUsageSnapshot => ({
|
|
10
|
+
status: "error",
|
|
11
|
+
source: "none",
|
|
12
|
+
fetchedAt: new Date().toISOString(),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const useCodexUsagePolling = () => {
|
|
16
|
+
const lastOkRef = useRef<CodexUsageSnapshot | null>(null);
|
|
17
|
+
|
|
18
|
+
const normalize = (raw: unknown): CodexUsageSnapshot | null => {
|
|
19
|
+
const snapshot = normalizeCodexUsageSnapshot(raw);
|
|
20
|
+
if (snapshot?.status === "ok") {
|
|
21
|
+
lastOkRef.current = snapshot;
|
|
22
|
+
return snapshot;
|
|
23
|
+
}
|
|
24
|
+
return lastOkRef.current ?? snapshot;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const { data, refresh } = usePollingData<CodexUsageSnapshot>({
|
|
28
|
+
fetchUrl: buildCodexUsageUrl(),
|
|
29
|
+
intervalMs: CODEX_USAGE_SCAN_INTERVAL_MS,
|
|
30
|
+
normalize,
|
|
31
|
+
fallback,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return { codexUsageSnapshot: data, refreshCodexUsage: refresh };
|
|
35
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
import type { PrimaryNavIndex } from "../constants";
|
|
4
|
+
import { isEditableEventTarget, parsePrimaryNavKey } from "../hotkeys";
|
|
5
|
+
|
|
6
|
+
type UseConsoleKeyboardShortcutsOptions = {
|
|
7
|
+
setActivePrimaryNav: (index: PrimaryNavIndex) => void;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const useConsoleKeyboardShortcuts = ({
|
|
11
|
+
setActivePrimaryNav,
|
|
12
|
+
}: UseConsoleKeyboardShortcutsOptions) => {
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const handleWindowKeyDown = (event: globalThis.KeyboardEvent) => {
|
|
15
|
+
if (isEditableEventTarget(event.target)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const nextPrimaryNav = parsePrimaryNavKey(event.key);
|
|
20
|
+
if (nextPrimaryNav !== null) {
|
|
21
|
+
setActivePrimaryNav(nextPrimaryNav);
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
window.addEventListener("keydown", handleWindowKeyDown);
|
|
27
|
+
return () => {
|
|
28
|
+
window.removeEventListener("keydown", handleWindowKeyDown);
|
|
29
|
+
};
|
|
30
|
+
}, [setActivePrimaryNav]);
|
|
31
|
+
};
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
buildConversationExportUrl,
|
|
5
|
+
buildConversationSearchUrl,
|
|
6
|
+
buildConversationSessionUrl,
|
|
7
|
+
buildConversationsUrl,
|
|
8
|
+
} from "../../runtime/runtimeEndpoints";
|
|
9
|
+
import {
|
|
10
|
+
normalizeConversationSessionDetail,
|
|
11
|
+
normalizeConversationSessionSummary,
|
|
12
|
+
} from "../conversationNormalizers";
|
|
13
|
+
import type {
|
|
14
|
+
ConversationSearchHit,
|
|
15
|
+
ConversationSessionDetail,
|
|
16
|
+
ConversationSessionSummary,
|
|
17
|
+
} from "../types";
|
|
18
|
+
|
|
19
|
+
type ConversationExportFormat = "json" | "md";
|
|
20
|
+
|
|
21
|
+
type ConversationExportResult = {
|
|
22
|
+
filename: string;
|
|
23
|
+
contentType: string;
|
|
24
|
+
content: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type UseConversationsRuntimeOptions = {
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type UseConversationsRuntimeResult = {
|
|
32
|
+
sessions: ConversationSessionSummary[];
|
|
33
|
+
selectedSessionId: string | null;
|
|
34
|
+
selectedSession: ConversationSessionDetail | null;
|
|
35
|
+
isLoadingSessions: boolean;
|
|
36
|
+
isLoadingSelectedSession: boolean;
|
|
37
|
+
isExporting: boolean;
|
|
38
|
+
isClearing: boolean;
|
|
39
|
+
isSearching: boolean;
|
|
40
|
+
searchQuery: string;
|
|
41
|
+
searchHits: ConversationSearchHit[];
|
|
42
|
+
highlightedTurnId: string | null;
|
|
43
|
+
errorMessage: string | null;
|
|
44
|
+
selectSession: (sessionId: string) => void;
|
|
45
|
+
refreshSessions: () => Promise<void>;
|
|
46
|
+
clearAllSessions: () => Promise<void>;
|
|
47
|
+
deleteSession: (sessionId: string) => Promise<void>;
|
|
48
|
+
exportSession: (
|
|
49
|
+
sessionId: string,
|
|
50
|
+
format: ConversationExportFormat,
|
|
51
|
+
) => Promise<ConversationExportResult | null>;
|
|
52
|
+
searchConversations: (query: string) => Promise<void>;
|
|
53
|
+
clearSearch: () => void;
|
|
54
|
+
navigateToSearchHit: (hit: ConversationSearchHit) => void;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const buildErrorMessage = (fallback: string, error: unknown) =>
|
|
58
|
+
error instanceof Error && error.message.length > 0 ? error.message : fallback;
|
|
59
|
+
|
|
60
|
+
const buildExportFilename = (sessionId: string, format: ConversationExportFormat) =>
|
|
61
|
+
`${sessionId}.${format === "json" ? "json" : "md"}`;
|
|
62
|
+
|
|
63
|
+
export const useConversationsRuntime = ({
|
|
64
|
+
enabled = true,
|
|
65
|
+
}: UseConversationsRuntimeOptions = {}): UseConversationsRuntimeResult => {
|
|
66
|
+
const [sessions, setSessions] = useState<ConversationSessionSummary[]>([]);
|
|
67
|
+
const [selectedSessionId, setSelectedSessionId] = useState<string | null>(null);
|
|
68
|
+
const [selectedSession, setSelectedSession] = useState<ConversationSessionDetail | null>(null);
|
|
69
|
+
const [isLoadingSessions, setIsLoadingSessions] = useState(false);
|
|
70
|
+
const [isLoadingSelectedSession, setIsLoadingSelectedSession] = useState(false);
|
|
71
|
+
const [isExporting, setIsExporting] = useState(false);
|
|
72
|
+
const [isClearing, setIsClearing] = useState(false);
|
|
73
|
+
const [isSearching, setIsSearching] = useState(false);
|
|
74
|
+
const [searchQuery, setSearchQuery] = useState("");
|
|
75
|
+
const [searchHits, setSearchHits] = useState<ConversationSearchHit[]>([]);
|
|
76
|
+
const [highlightedTurnId, setHighlightedTurnId] = useState<string | null>(null);
|
|
77
|
+
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
|
78
|
+
const selectedSessionRequestRef = useRef(0);
|
|
79
|
+
|
|
80
|
+
const refreshSessions = useCallback(async () => {
|
|
81
|
+
if (!enabled) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
setIsLoadingSessions(true);
|
|
86
|
+
try {
|
|
87
|
+
const response = await fetch(buildConversationsUrl(), {
|
|
88
|
+
method: "GET",
|
|
89
|
+
headers: {
|
|
90
|
+
Accept: "application/json",
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
if (!response.ok) {
|
|
95
|
+
throw new Error(`Unable to read conversations (${response.status})`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const payload = (await response.json()) as unknown;
|
|
99
|
+
const normalized = Array.isArray(payload)
|
|
100
|
+
? payload
|
|
101
|
+
.map((entry) => normalizeConversationSessionSummary(entry))
|
|
102
|
+
.filter((entry): entry is ConversationSessionSummary => entry !== null)
|
|
103
|
+
: [];
|
|
104
|
+
setSessions(normalized);
|
|
105
|
+
setSelectedSessionId((current) => {
|
|
106
|
+
if (current && normalized.some((session) => session.sessionId === current)) {
|
|
107
|
+
return current;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return normalized[0]?.sessionId ?? null;
|
|
111
|
+
});
|
|
112
|
+
setErrorMessage(null);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
setErrorMessage(buildErrorMessage("Unable to load conversations.", error));
|
|
115
|
+
} finally {
|
|
116
|
+
setIsLoadingSessions(false);
|
|
117
|
+
}
|
|
118
|
+
}, [enabled]);
|
|
119
|
+
|
|
120
|
+
const clearAllSessions = useCallback(async () => {
|
|
121
|
+
if (!enabled) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
setIsClearing(true);
|
|
126
|
+
try {
|
|
127
|
+
const response = await fetch(buildConversationsUrl(), {
|
|
128
|
+
method: "DELETE",
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
if (!response.ok) {
|
|
132
|
+
throw new Error(`Unable to clear conversations (${response.status})`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
setSessions([]);
|
|
136
|
+
setSelectedSessionId(null);
|
|
137
|
+
setSelectedSession(null);
|
|
138
|
+
setErrorMessage(null);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
setErrorMessage(buildErrorMessage("Unable to clear conversations.", error));
|
|
141
|
+
} finally {
|
|
142
|
+
setIsClearing(false);
|
|
143
|
+
}
|
|
144
|
+
}, [enabled]);
|
|
145
|
+
|
|
146
|
+
const deleteSession = useCallback(
|
|
147
|
+
async (sessionId: string) => {
|
|
148
|
+
if (!enabled) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
const response = await fetch(buildConversationSessionUrl(sessionId), {
|
|
154
|
+
method: "DELETE",
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
if (!response.ok) {
|
|
158
|
+
throw new Error(`Unable to delete conversation (${response.status})`);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
setSessions((current) => {
|
|
162
|
+
const remaining = current.filter((s) => s.sessionId !== sessionId);
|
|
163
|
+
if (selectedSessionId === sessionId) {
|
|
164
|
+
const getTimestamp = (s: ConversationSessionSummary) => {
|
|
165
|
+
const raw = s.lastEventAt ?? s.endedAt ?? s.startedAt;
|
|
166
|
+
return raw ? Date.parse(raw) || 0 : 0;
|
|
167
|
+
};
|
|
168
|
+
const sorted = [...remaining].sort((a, b) => getTimestamp(b) - getTimestamp(a));
|
|
169
|
+
const nextId = sorted[0]?.sessionId ?? null;
|
|
170
|
+
setSelectedSessionId(nextId);
|
|
171
|
+
if (!nextId) {
|
|
172
|
+
setSelectedSession(null);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return remaining;
|
|
176
|
+
});
|
|
177
|
+
setErrorMessage(null);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
setErrorMessage(buildErrorMessage("Unable to delete conversation.", error));
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
[enabled, selectedSessionId],
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
const selectSession = useCallback((sessionId: string) => {
|
|
186
|
+
setSelectedSessionId(sessionId);
|
|
187
|
+
}, []);
|
|
188
|
+
|
|
189
|
+
const exportSession = useCallback(
|
|
190
|
+
async (
|
|
191
|
+
sessionId: string,
|
|
192
|
+
format: ConversationExportFormat,
|
|
193
|
+
): Promise<ConversationExportResult | null> => {
|
|
194
|
+
if (!enabled) {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
setIsExporting(true);
|
|
199
|
+
try {
|
|
200
|
+
const response = await fetch(buildConversationExportUrl(sessionId, format), {
|
|
201
|
+
method: "GET",
|
|
202
|
+
headers: {
|
|
203
|
+
Accept: format === "json" ? "application/json" : "text/markdown",
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
if (!response.ok) {
|
|
208
|
+
throw new Error(`Unable to export conversation (${response.status})`);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (format === "json") {
|
|
212
|
+
const payload = (await response.json()) as unknown;
|
|
213
|
+
const normalized = normalizeConversationSessionDetail(payload);
|
|
214
|
+
const json = `${JSON.stringify(normalized ?? payload, null, 2)}\n`;
|
|
215
|
+
return {
|
|
216
|
+
filename: buildExportFilename(sessionId, "json"),
|
|
217
|
+
contentType: "application/json",
|
|
218
|
+
content: json,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const markdown = await response.text();
|
|
223
|
+
return {
|
|
224
|
+
filename: buildExportFilename(sessionId, "md"),
|
|
225
|
+
contentType: "text/markdown",
|
|
226
|
+
content: markdown,
|
|
227
|
+
};
|
|
228
|
+
} catch (error) {
|
|
229
|
+
setErrorMessage(buildErrorMessage("Unable to export conversation.", error));
|
|
230
|
+
return null;
|
|
231
|
+
} finally {
|
|
232
|
+
setIsExporting(false);
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
[enabled],
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
const searchConversationsAction = useCallback(
|
|
239
|
+
async (query: string) => {
|
|
240
|
+
if (!enabled) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const trimmed = query.trim();
|
|
245
|
+
setSearchQuery(trimmed);
|
|
246
|
+
|
|
247
|
+
if (trimmed.length === 0) {
|
|
248
|
+
setSearchHits([]);
|
|
249
|
+
setHighlightedTurnId(null);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
setIsSearching(true);
|
|
254
|
+
try {
|
|
255
|
+
const response = await fetch(buildConversationSearchUrl(trimmed), {
|
|
256
|
+
method: "GET",
|
|
257
|
+
headers: { Accept: "application/json" },
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
if (!response.ok) {
|
|
261
|
+
throw new Error(`Search failed (${response.status})`);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const payload = (await response.json()) as { hits?: unknown[] };
|
|
265
|
+
const hits = Array.isArray(payload.hits) ? (payload.hits as ConversationSearchHit[]) : [];
|
|
266
|
+
setSearchHits(hits);
|
|
267
|
+
setHighlightedTurnId(null);
|
|
268
|
+
} catch (error) {
|
|
269
|
+
setErrorMessage(buildErrorMessage("Unable to search conversations.", error));
|
|
270
|
+
} finally {
|
|
271
|
+
setIsSearching(false);
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
[enabled],
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
const clearSearch = useCallback(() => {
|
|
278
|
+
setSearchQuery("");
|
|
279
|
+
setSearchHits([]);
|
|
280
|
+
setHighlightedTurnId(null);
|
|
281
|
+
}, []);
|
|
282
|
+
|
|
283
|
+
const navigateToSearchHit = useCallback((hit: ConversationSearchHit) => {
|
|
284
|
+
setSelectedSessionId(hit.sessionId);
|
|
285
|
+
setHighlightedTurnId(hit.turnId);
|
|
286
|
+
}, []);
|
|
287
|
+
|
|
288
|
+
useEffect(() => {
|
|
289
|
+
if (!enabled) {
|
|
290
|
+
setSessions([]);
|
|
291
|
+
setSelectedSessionId(null);
|
|
292
|
+
setSelectedSession(null);
|
|
293
|
+
setIsLoadingSessions(false);
|
|
294
|
+
setIsLoadingSelectedSession(false);
|
|
295
|
+
setIsExporting(false);
|
|
296
|
+
setIsClearing(false);
|
|
297
|
+
setIsSearching(false);
|
|
298
|
+
setSearchQuery("");
|
|
299
|
+
setSearchHits([]);
|
|
300
|
+
setHighlightedTurnId(null);
|
|
301
|
+
setErrorMessage(null);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
void refreshSessions();
|
|
306
|
+
}, [enabled, refreshSessions]);
|
|
307
|
+
|
|
308
|
+
useEffect(() => {
|
|
309
|
+
if (!enabled || !selectedSessionId) {
|
|
310
|
+
setSelectedSession(null);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const requestId = selectedSessionRequestRef.current + 1;
|
|
315
|
+
selectedSessionRequestRef.current = requestId;
|
|
316
|
+
setIsLoadingSelectedSession(true);
|
|
317
|
+
|
|
318
|
+
const loadSelectedSession = async () => {
|
|
319
|
+
try {
|
|
320
|
+
const response = await fetch(buildConversationSessionUrl(selectedSessionId), {
|
|
321
|
+
method: "GET",
|
|
322
|
+
headers: {
|
|
323
|
+
Accept: "application/json",
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
if (!response.ok) {
|
|
328
|
+
throw new Error(`Unable to read conversation (${response.status})`);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const payload = normalizeConversationSessionDetail(await response.json());
|
|
332
|
+
if (!payload) {
|
|
333
|
+
throw new Error("Conversation response is invalid.");
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (selectedSessionRequestRef.current === requestId) {
|
|
337
|
+
setSelectedSession(payload);
|
|
338
|
+
setErrorMessage(null);
|
|
339
|
+
}
|
|
340
|
+
} catch (error) {
|
|
341
|
+
if (selectedSessionRequestRef.current === requestId) {
|
|
342
|
+
setSelectedSession(null);
|
|
343
|
+
setErrorMessage(buildErrorMessage("Unable to read conversation.", error));
|
|
344
|
+
}
|
|
345
|
+
} finally {
|
|
346
|
+
if (selectedSessionRequestRef.current === requestId) {
|
|
347
|
+
setIsLoadingSelectedSession(false);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
void loadSelectedSession();
|
|
353
|
+
}, [enabled, selectedSessionId]);
|
|
354
|
+
|
|
355
|
+
return {
|
|
356
|
+
sessions,
|
|
357
|
+
selectedSessionId,
|
|
358
|
+
selectedSession,
|
|
359
|
+
isLoadingSessions,
|
|
360
|
+
isLoadingSelectedSession,
|
|
361
|
+
isExporting,
|
|
362
|
+
isClearing,
|
|
363
|
+
isSearching,
|
|
364
|
+
searchQuery,
|
|
365
|
+
searchHits,
|
|
366
|
+
highlightedTurnId,
|
|
367
|
+
errorMessage,
|
|
368
|
+
selectSession,
|
|
369
|
+
refreshSessions,
|
|
370
|
+
clearAllSessions,
|
|
371
|
+
deleteSession,
|
|
372
|
+
exportSession,
|
|
373
|
+
searchConversations: searchConversationsAction,
|
|
374
|
+
clearSearch,
|
|
375
|
+
navigateToSearchHit,
|
|
376
|
+
};
|
|
377
|
+
};
|