Team Ai
Apppublic

admin08077/Githubgemini

sourceHugging Faceotherupdated 11mo agoView on Hugging Face
0likes
AiCommandCenter-ClG32klM.js.map1 linesDownload Raw Back to assets
1{"version":3,"file":"AiCommandCenter-ClG32klM.js","sources":["../../components/features/AiCommandCenter.tsx"],"sourcesContent":["import React, { useState, useCallback } from 'react';\nimport { Type, FunctionDeclaration } from \"@google/genai\";\nimport { logError } from '../../services/telemetryService.ts';\nimport { getInferenceFunction, CommandResponse } from '../../services/aiService.ts';\nimport { FEATURE_TAXONOMY } from '../../services/taxonomyService.ts';\nimport { useGlobalState } from '../../contexts/GlobalStateContext.tsx';\nimport { CommandLineIcon } from '../icons.tsx';\nimport { LoadingSpinner } from '../shared/index.tsx';\nimport { ALL_FEATURE_IDS } from '../../constants.tsx';\nimport { executeWorkspaceAction, ACTION_REGISTRY } from '../../services/workspaceConnectorService.ts';\n\nconst baseFunctionDeclarations: FunctionDeclaration[] = [\n    {\n        name: 'navigateTo',\n        description: 'Navigates to a specific feature page.',\n        parameters: {\n            type: Type.OBJECT,\n            properties: {\n                featureId: { \n                    type: Type.STRING, \n                    description: 'The ID of the feature to navigate to.',\n                    enum: ALL_FEATURE_IDS\n                },\n            },\n            required: ['featureId'],\n        },\n    },\n    {\n        name: 'runFeatureWithInput',\n        description: 'Navigates to a feature and passes initial data to it.',\n        parameters: {\n            type: Type.OBJECT,\n            properties: {\n                 featureId: { \n                    type: Type.STRING, \n                    description: 'The ID of the feature to run.',\n                    enum: ALL_FEATURE_IDS\n                },\n                props: {\n                    type: Type.OBJECT,\n                    description: 'An object containing the initial properties for the feature, based on its required inputs.',\n                    properties: {\n                        initialCode: { type: Type.STRING },\n                        initialPrompt: { type: Type.STRING },\n                        beforeCode: { type: Type.STRING },\n                        afterCode: { type: Type.STRING },\n                        logInput: { type: Type.STRING },\n                        diff: { type: Type.STRING },\n                        codeInput: { type: Type.STRING },\n                        jsonInput: { type: Type.STRING },\n                    }\n                }\n            },\n            required: ['featureId', 'props']\n        }\n    }\n];\n\n// Dynamically add the workspace action\nconst functionDeclarations: FunctionDeclaration[] = [\n    ...baseFunctionDeclarations,\n    {\n        name: 'runWorkspaceAction',\n        description: 'Executes a defined action on a connected workspace service like Jira, Slack, or GitHub.',\n        parameters: {\n            type: Type.OBJECT,\n            properties: {\n                 actionId: {\n                    type: Type.STRING,\n                    description: 'The unique identifier for the action to execute.',\n                    enum: [ ...ACTION_REGISTRY.keys() ]\n                },\n                params: {\n                    type: Type.OBJECT,\n                    description: 'An object containing the parameters for the action, matching its required inputs.'\n                }\n            },\n            required: ['actionId', 'params']\n        }\n    }\n]\n\nconst knowledgeBase = FEATURE_TAXONOMY.map(f => `- ${f.name} (${f.id}): ${f.description} Inputs: ${f.inputs}`).join('\\n');\n\nconst ExamplePromptButton: React.FC<{ text: string, onClick: (text: string) => void }> = ({ text, onClick }) => (\n    <button\n        onClick={() => onClick(text)}\n        className=\"px-3 py-1.5 bg-surface border border-border rounded-full text-xs hover:bg-gray-100 dark:hover:bg-slate-700 transition-colors\"\n    >\n        {text}\n    </button>\n)\n\nexport const AiCommandCenter: React.FC = () => {\n    const { dispatch } = useGlobalState();\n    const [prompt, setPrompt] = useState('');\n    const [isLoading, setIsLoading] = useState(false);\n    const [lastResponse, setLastResponse] = useState('');\n\n    const handleCommand = useCallback(async () => {\n        if (!prompt.trim()) return;\n\n        setIsLoading(true);\n        setLastResponse('');\n\n        try {\n            const response: CommandResponse = await getInferenceFunction(prompt, functionDeclarations, knowledgeBase);\n            \n            if (response.functionCalls && response.functionCalls.length > 0) {\n                const call = response.functionCalls[0];\n                const { name, args } = call;\n\n                setLastResponse(`Understood! Executing command: ${name}`);\n\n                switch (name) {\n                    case 'navigateTo':\n                        dispatch({ type: 'SET_VIEW', payload: { view: args.featureId }});\n                        break;\n                    case 'runFeatureWithInput':\n                         dispatch({ type: 'SET_VIEW', payload: { view: args.featureId, props: args.props } });\n                        break;\n                    case 'runWorkspaceAction':\n                        try {\n                            const result = await executeWorkspaceAction(args.actionId, args.params);\n                            setLastResponse(`Action '${args.actionId}' executed successfully.\\n\\nResult: \\`\\`\\`json\\n${JSON.stringify(result, null, 2)}\\n\\`\\`\\``);\n                        } catch (e) {\n                            setLastResponse(`Action failed: ${e instanceof Error ? e.message : 'Unknown error'}`);\n                        }\n                        break;\n                    default:\n                        setLastResponse(`Unknown command: ${name}`);\n                }\n                 setPrompt('');\n            } else {\n                 setLastResponse(response.text);\n            }\n\n        } catch (err) {\n            logError(err as Error, { prompt });\n            setLastResponse(err instanceof Error ? err.message : 'An unknown error occurred.');\n        } finally {\n            setIsLoading(false);\n        }\n    }, [prompt, dispatch]);\n\n    const handleKeyDown = (e: React.KeyboardEvent) => {\n        if (e.key === 'Enter' && !e.shiftKey) {\n            e.preventDefault();\n            handleCommand();\n        }\n    };\n    \n    const handleExampleClick = (text: string) => {\n        setPrompt(text);\n    }\n\n    return (\n        <div className=\"h-full flex flex-col p-4 sm:p-6 lg:p-8 text-text-primary\">\n            <header className=\"mb-6 text-center\">\n                <h1 className=\"text-4xl font-extrabold tracking-tight flex items-center justify-center\">\n                    <CommandLineIcon />\n                    <span className=\"ml-3\">AI Command Center</span>\n                </h1>\n                <p className=\"mt-2 text-lg text-text-secondary\">What would you like to do?</p>\n            </header>\n            \n            <div className=\"flex-grow flex flex-col justify-end max-w-3xl w-full mx-auto\">\n                {lastResponse && (\n                    <div className=\"mb-4 p-4 bg-surface rounded-lg text-text-primary border border-border\">\n                        <p><strong>AI:</strong> {lastResponse}</p>\n                    </div>\n                )}\n                 <div className=\"relative\">\n                    <textarea\n                        value={prompt}\n                        onChange={e => setPrompt(e.target.value)}\n                        onKeyDown={handleKeyDown}\n                        disabled={isLoading}\n                        placeholder='Try \"explain this code: const a = 1;\" or \"open the theme designer\"'\n                        className=\"w-full p-4 pr-28 rounded-lg bg-surface border border-border focus:ring-2 focus:ring-primary focus:outline-none resize-none shadow-sm\"\n                        rows={2}\n                    />\n                    <button\n                        onClick={handleCommand}\n                        disabled={isLoading}\n                        className=\"btn-primary absolute right-3 top-1/2 -translate-y-1/2 px-4 py-2\"\n                    >\n                       {isLoading ? <LoadingSpinner/> : 'Send'}\n                    </button>\n                </div>\n                 <div className=\"flex flex-wrap items-center justify-center gap-2 mt-4\">\n                    <ExamplePromptButton text=\"Open Theme Designer\" onClick={handleExampleClick} />\n                    <ExamplePromptButton text=\"Generate a commit for a bug fix\" onClick={handleExampleClick} />\n                    <ExamplePromptButton text=\"Create a regex for email validation\" onClick={handleExampleClick} />\n                </div>\n                 <p className=\"text-xs text-text-secondary text-center mt-2\">Press Enter to send, Shift+Enter for new line.</p>\n            </div>\n        </div>\n    );\n};"],"names":["baseFunctionDeclarations","Type","ALL_FEATURE_IDS","functionDeclarations","ACTION_REGISTRY","knowledgeBase","FEATURE_TAXONOMY","f","ExamplePromptButton","text","onClick","jsx","AiCommandCenter","dispatch","useGlobalState","prompt","setPrompt","useState","isLoading","setIsLoading","lastResponse","setLastResponse","handleCommand","useCallback","response","getInferenceFunction","call","name","args","result","executeWorkspaceAction","e","err","logError","handleKeyDown","handleExampleClick","jsxs","CommandLineIcon","LoadingSpinner"],"mappings":"gxFAWA,MAAMA,EAAkD,CACpD,CACI,KAAM,aACN,YAAa,wCACb,WAAY,CACR,KAAMC,EAAK,OACX,WAAY,CACR,UAAW,CACP,KAAMA,EAAK,OACX,YAAa,wCACb,KAAMC,CAAA,CACV,EAEJ,SAAU,CAAC,WAAW,CAAA,CAC1B,EAEJ,CACI,KAAM,sBACN,YAAa,wDACb,WAAY,CACR,KAAMD,EAAK,OACX,WAAY,CACP,UAAW,CACR,KAAMA,EAAK,OACX,YAAa,gCACb,KAAMC,CAAA,EAEV,MAAO,CACH,KAAMD,EAAK,OACX,YAAa,6FACb,WAAY,CACR,YAAa,CAAE,KAAMA,EAAK,MAAA,EAC1B,cAAe,CAAE,KAAMA,EAAK,MAAA,EAC5B,WAAY,CAAE,KAAMA,EAAK,MAAA,EACzB,UAAW,CAAE,KAAMA,EAAK,MAAA,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