admin08077/Githubgemini
0
1{"version":3,"file":"workspaceConnectorService-KhhKdOYD.js","sources":["../../services/workspaceConnectorService.ts"],"sourcesContent":["import * as vaultService from './vaultService.ts';\nimport { logError, logEvent } from './telemetryService.ts';\nimport { getDecryptedCredential } from './vaultService.ts';\n\n// Interface for any action\nexport interface WorkspaceAction {\n id: string; // e.g., 'jira_create_ticket'\n service: 'Jira' | 'Slack' | 'GitHub'; // etc.\n description: string;\n // Function to define the necessary input fields for this action\n getParameters: () => { [key: string]: { type: 'string' | 'number', required: boolean, default?: string } };\n // The actual logic to execute the action\n execute: (params: any) => Promise<any>;\n}\n\n// THE REGISTRY: This is the pattern for all services.\nexport const ACTION_REGISTRY: Map<string, WorkspaceAction> = new Map();\n\n// --- JIRA EXAMPLE ---\nACTION_REGISTRY.set('jira_create_ticket', {\n id: 'jira_create_ticket',\n service: 'Jira',\n description: 'Creates a new issue in a Jira project.',\n getParameters: () => ({\n projectKey: { type: 'string', required: true },\n summary: { type: 'string', required: true },\n description: { type: 'string', required: false },\n issueType: { type: 'string', required: true, default: 'Task' }\n }),\n execute: async (params) => {\n const domain = await getDecryptedCredential('jira_domain');\n const token = await getDecryptedCredential('jira_pat');\n const email = await getDecryptedCredential('jira_email');\n\n if (!domain || !token || !email) {\n throw new Error(\"Jira credentials not found in vault. Please connect Jira in the Workspace Connector Hub.\");\n }\n \n // The Atlassian Document Format for the description field\n const descriptionDoc = {\n type: 'doc',\n version: 1,\n content: [\n {\n type: 'paragraph',\n content: [\n {\n text: params.description || '',\n type: 'text'\n }\n ]\n }\n ]\n };\n\n const response = await fetch(`https://${domain}/rest/api/3/issue`, {\n method: 'POST',\n headers: {\n 'Authorization': `Basic ${btoa(`${email}:${token}`)}`,\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify({\n fields: {\n project: { key: params.projectKey },\n summary: params.summary,\n description: descriptionDoc,\n issuetype: { name: params.issueType || 'Task' }\n }\n })\n });\n if (!response.ok) {\n const errorBody = await response.text();\n throw new Error(`Jira API Error (${response.status}): ${errorBody}`);\n }\n return response.json();\n }\n});\n\n// --- SLACK EXAMPLE ---\nACTION_REGISTRY.set('slack_post_message', {\n id: 'slack_post_message',\n service: 'Slack',\n description: 'Posts a message to a Slack channel.',\n getParameters: () => ({\n channel: { type: 'string', required: true }, // e.g., #engineering or C1234567\n text: { type: 'string', required: true }\n }),\n execute: async (params) => {\n const token = await getDecryptedCredential('slack_bot_token');\n if (!token) {\n throw new Error(\"Slack credentials not found in vault. Please connect Slack in the Workspace Connector Hub.\");\n }\n const response = await fetch('https://slack.com/api/chat.postMessage', {\n method: 'POST',\n headers: {\n 'Authorization': `Bearer ${token}`,\n 'Content-Type': 'application/json; charset=utf-8'\n },\n body: JSON.stringify({\n channel: params.channel,\n text: params.text\n })\n });\n if (!response.ok) {\n const errorBody = await response.json();\n throw new Error(`Slack API Error: ${errorBody.error}`);\n }\n return response.json();\n }\n});\n\n\n// --- CENTRAL EXECUTION FUNCTION ---\nexport async function executeWorkspaceAction(actionId: string, params: any): Promise<any> {\n const action = ACTION_REGISTRY.get(actionId);\n if (!action) {\n throw new Error(`Action \"${actionId}\" not found.`);\n }\n logEvent('workspace_action_execute', { actionId });\n try {\n const result = await action.execute(params);\n logEvent('workspace_action_success', { actionId });\n return result;\n } catch (error) {\n logError(error as Error, { context: 'executeWorkspaceAction', actionId });\n throw error;\n }\n}"],"names":["ACTION_REGISTRY","params","domain","getDecryptedCredential","token","email","descriptionDoc","response","errorBody","executeWorkspaceAction","actionId","action","logEvent","result","error","logError"],"mappings":"uDAgBO,MAAMA,MAAoD,IAGjEA,EAAgB,IAAI,qBAAsB,CACxC,GAAI,qBACJ,QAAS,OACT,YAAa,yCACb,cAAe,KAAO,CACpB,WAAY,CAAE,KAAM,SAAU,SAAU,EAAA,EACxC,QAAS,CAAE,KAAM,SAAU,SAAU,EAAA,EACrC,YAAa,CAAE,KAAM,SAAU,SAAU,EAAA,EACzC,UAAW,CAAE,KAAM,SAAU,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