Skip to content

Commit 1b2280a

Browse files
Merge pull request #997 from devtron-labs/feat/debug-ai
feat: ai debug mode
2 parents 1108d26 + deb23c6 commit 1b2280a

9 files changed

Lines changed: 95 additions & 25 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.22.0-beta-4",
3+
"version": "1.22.0-beta-5",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/Constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ export const URLS = {
8080
APP_DEPLOYMNENT_HISTORY: 'deployments',
8181
APP_DETAILS: 'details',
8282
APP_DETAILS_K8: 'k8s-resources', // for V2
83+
EXTERNAL_ARGO_APP: 'eaa',
84+
EXTERNAL_FLUX_APP: 'external-flux',
8385
DETAILS: '/details',
8486
CD_DETAILS: 'cd-details',
8587
APP_TRIGGER: 'trigger',

src/Shared/Components/AppStatusModal/AppStatusBody.tsx

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { getAIAnalyticsEvents } from '@Common/Helper'
2020
import { Tooltip } from '@Common/Tooltip'
2121
import { ComponentSizeType } from '@Shared/constants'
2222
import { getAppDetailsURL } from '@Shared/Helpers'
23+
import { MainContext, useMainContext } from '@Shared/Providers'
2324

2425
import { Button, ButtonComponentType, ButtonVariantType } from '../Button'
2526
import { DeploymentStatusDetailBreakdown } from '../CICDHistory'
@@ -86,7 +87,10 @@ export const AppStatusBody = ({
8687
deploymentStatusDetailsBreakdownData,
8788
selectedTab,
8889
debugWithAIButton: ExplainWithAIButton,
90+
handleClose,
8991
}: AppStatusBodyProps) => {
92+
const { aiAgentContext } = useMainContext()
93+
9094
const appStatus = appDetails.resourceTree?.status?.toUpperCase() || appDetails.appStatus
9195

9296
const getAppStatusInfoCardItems = (): (Omit<ComponentProps<typeof InfoCardItem>, 'isLast'> & { id: string })[] => {
@@ -101,6 +105,32 @@ export const AppStatusBody = ({
101105
)
102106
const debugObject = `${debugNode?.kind}/${debugNode?.name}`
103107

108+
const intelligenceConfig: MainContext['intelligenceConfig'] = {
109+
clusterId: appDetails.clusterId,
110+
metadata: {
111+
...(debugNode ? { object: debugObject } : { message }),
112+
namespace: appDetails.namespace,
113+
status: debugNode?.health?.status ?? appStatus,
114+
},
115+
prompt: `Debug ${message || 'error'} ${debugNode ? `of ${debugObject}` : ''} in ${appDetails.namespace}`,
116+
analyticsCategory: getAIAnalyticsEvents('APP_STATUS', appDetails.appType),
117+
}
118+
119+
// Have to add this to handle case of devtron-stack manager and software distribution hub.
120+
const debugAgentContext = aiAgentContext
121+
? ({
122+
...aiAgentContext,
123+
prompt: `Why is application '${appDetails.appName}' of '${appDetails.environmentName}' env ${appStatus}?`,
124+
data: {
125+
...aiAgentContext.data,
126+
...(debugNode ? { debugNodeKind: debugNode.kind, debugNodeName: debugNode.name } : {}),
127+
...(message ? { debugError: message } : {}),
128+
namespace: appDetails.namespace,
129+
status: debugNode?.health?.status ?? appStatus,
130+
},
131+
} as MainContext['debugAgentContext'])
132+
: null
133+
104134
return [
105135
{
106136
id: 'app-status-row',
@@ -112,19 +142,13 @@ export const AppStatusBody = ({
112142
envId={appDetails.environmentId}
113143
actionItem={
114144
ExplainWithAIButton &&
145+
debugAgentContext &&
115146
appStatus?.toLowerCase() !== StatusType.HEALTHY.toLowerCase() &&
116147
(debugNode || message) ? (
117148
<ExplainWithAIButton
118-
intelligenceConfig={{
119-
clusterId: appDetails.clusterId,
120-
metadata: {
121-
...(debugNode ? { object: debugObject } : { message }),
122-
namespace: appDetails.namespace,
123-
status: debugNode?.health?.status ?? appStatus,
124-
},
125-
prompt: `Debug ${message || 'error'} ${debugNode ? `of ${debugObject}` : ''} in ${appDetails.namespace}`,
126-
analyticsCategory: getAIAnalyticsEvents('APP_STATUS', appDetails.appType),
127-
}}
149+
intelligenceConfig={intelligenceConfig}
150+
debugAgentContext={debugAgentContext}
151+
onClick={handleClose}
128152
/>
129153
) : null
130154
}

src/Shared/Components/AppStatusModal/AppStatusModal.component.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ const AppStatusModal = ({
315315
deploymentStatusDetailsBreakdownData={deploymentStatusDetailsBreakdownData}
316316
selectedTab={selectedTab}
317317
debugWithAIButton={debugWithAIButton}
318+
handleClose={handleClose}
318319
/>
319320

320321
{type === 'stack-manager' && (

src/Shared/Components/AppStatusModal/types.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { FunctionComponent, PropsWithChildren, ReactNode } from 'react'
1818

1919
import { APIOptions, DeploymentAppTypes } from '@Common/Types'
20+
import { MainContext } from '@Shared/Providers'
2021
import {
2122
AppDetails,
2223
ConfigDriftModalProps,
@@ -38,7 +39,11 @@ export type AppStatusModalProps = {
3839
processVirtualEnvironmentDeploymentData: (
3940
data?: DeploymentStatusDetailsType,
4041
) => DeploymentStatusDetailsBreakdownDataType
41-
debugWithAIButton: FunctionComponent<{ intelligenceConfig: IntelligenceConfig }>
42+
debugWithAIButton: FunctionComponent<{
43+
intelligenceConfig: IntelligenceConfig
44+
debugAgentContext: MainContext['debugAgentContext']
45+
onClick?: () => void
46+
}>
4247
} & (
4348
| {
4449
type: 'release'
@@ -59,7 +64,7 @@ export type AppStatusModalProps = {
5964
)
6065

6166
export interface AppStatusBodyProps
62-
extends Required<Pick<AppStatusModalProps, 'appDetails' | 'type' | 'debugWithAIButton'>> {
67+
extends Required<Pick<AppStatusModalProps, 'appDetails' | 'type' | 'debugWithAIButton' | 'handleClose'>> {
6368
handleShowConfigDriftModal: () => void
6469
selectedTab: AppStatusModalTabType
6570
deploymentStatusDetailsBreakdownData: DeploymentStatusDetailsBreakdownDataType

src/Shared/Providers/MainContextProvider/types.ts

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,61 @@ export enum AIAgentContextSourceType {
5656
RESOURCE_BROWSER_CLUSTER = 'resource-browser-cluster',
5757
}
5858

59+
export type AIAgentAppType =
60+
| 'devtronApp'
61+
| 'devtronHelmChart'
62+
| 'externalHelmChart'
63+
| 'externalArgoApp'
64+
| 'externalFluxApp'
65+
66+
type AIAgentAppDataMasterType = {
67+
appId: number | string
68+
appName: string
69+
envId: number
70+
envName: string
71+
clusterId: number
72+
namespace: string
73+
appType: AIAgentAppType
74+
fluxAppDeploymentType: string
75+
}
76+
77+
type AIAgentAppDataType<TAppType extends AIAgentAppType, TRequiredFields extends keyof AIAgentAppDataMasterType> = Pick<
78+
AIAgentAppDataMasterType,
79+
TRequiredFields
80+
> & {
81+
[K in Exclude<keyof AIAgentAppDataMasterType, TRequiredFields | 'appType'>]?: never
82+
} & {
83+
appType: TAppType
84+
}
85+
5986
export type AIAgentContextType =
6087
| {
6188
source: AIAgentContextSourceType.APP_DETAILS
62-
data: {
63-
appId: number
64-
envId: number
65-
appName: string
66-
envName: string
67-
clusterId: number
68-
appType: 'devtronApp' | 'devtronHelmChart'
69-
}
89+
data:
90+
| AIAgentAppDataType<
91+
'devtronApp' | 'devtronHelmChart',
92+
'appId' | 'appName' | 'envId' | 'envName' | 'clusterId'
93+
>
94+
| AIAgentAppDataType<'externalHelmChart', 'appId' | 'appName' | 'clusterId' | 'namespace'>
95+
| AIAgentAppDataType<'externalArgoApp', 'appName' | 'clusterId' | 'namespace'>
96+
| (AIAgentAppDataType<
97+
'externalFluxApp',
98+
'appName' | 'clusterId' | 'namespace' | 'fluxAppDeploymentType'
99+
> &
100+
Record<string, unknown>)
70101
}
71102
| {
72103
source: AIAgentContextSourceType.RESOURCE_BROWSER_CLUSTER
73104
data: {
74105
clusterId: number
75106
clusterName: string
76-
}
107+
} & Record<string, unknown>
77108
}
78109

110+
export type DebugAgentContextType = AIAgentContextType & {
111+
prompt?: string
112+
}
113+
79114
export interface TempAppWindowConfig {
80115
/** Whether the temporary window is open */
81116
open: boolean
@@ -139,6 +174,8 @@ type CommonMainContextProps = {
139174
setLicenseData: Dispatch<SetStateAction<DevtronLicenseInfo>>
140175
canFetchHelmAppStatus: boolean
141176
setIntelligenceConfig: Dispatch<SetStateAction<IntelligenceConfig>>
177+
debugAgentContext: DebugAgentContextType | null
178+
setDebugAgentContext: (aiAgentContext: DebugAgentContextType | null) => void
142179
setAIAgentContext: (aiAgentContext: AIAgentContextType) => void
143180
setSidePanelConfig: Dispatch<SetStateAction<SidePanelConfig>>
144181
} & Pick<EnvironmentDataValuesDTO, 'isResourceRecommendationEnabled'>

src/Shared/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ export interface DeploymentStatusDetailsBreakdownDataType {
13271327

13281328
export interface IntelligenceConfig {
13291329
clusterId: number
1330-
metadata: Record<string, string>
1330+
metadata: Record<string, string | number>
13311331
prompt: string
13321332
analyticsCategory: string
13331333
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ export interface customEnv {
187187
* @default false
188188
*/
189189
FEATURE_STORAGE_ENABLE?: boolean
190+
FEATURE_ATHENA_DEBUG_MODE_ENABLE?: boolean
190191
}
191192
declare global {
192193
interface Window {

0 commit comments

Comments
 (0)