n8n-nodes-github-copilot 1.0.1 → 1.0.3

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.
@@ -5,15 +5,65 @@ const n8n_workflow_1 = require("n8n-workflow");
5
5
  const child_process_1 = require("child_process");
6
6
  const util_1 = require("util");
7
7
  const execAsync = (0, util_1.promisify)(child_process_1.exec);
8
- async function callGitHubCopilotAPI(prompt, operation, _token) {
9
- return new Promise((resolve) => {
10
- const mockResponse = {
11
- suggest: `// AI-generated code suggestion for: ${prompt}\n// Note: Install GitHub CLI on server for full functionality\nfunction generatedFunction() {\n // Implementation based on: ${prompt}\n console.log('Generated by GitHub Copilot fallback');\n}`,
12
- explain: `This code appears to: ${prompt}\n\nExplanation:\n- The function processes the input\n- It performs the requested operation\n- Returns the expected result\n\nNote: Install GitHub CLI on server for detailed explanations.`,
13
- shell: `# Shell command suggestion for: ${prompt}\n# Note: Install GitHub CLI on server for full functionality\necho "Command for: ${prompt}"`
8
+ async function callGitHubCopilotAPI(prompt, operation, token) {
9
+ var _a, _b, _c;
10
+ try {
11
+ const response = await fetch('https://api.github.com/chat/completions', {
12
+ method: 'POST',
13
+ headers: {
14
+ 'Authorization': `Bearer ${token}`,
15
+ 'Content-Type': 'application/json',
16
+ 'User-Agent': 'n8n-nodes-github-copilot/1.0.2',
17
+ },
18
+ body: JSON.stringify({
19
+ model: 'gpt-4',
20
+ messages: [
21
+ {
22
+ role: 'system',
23
+ content: operation === 'suggest' ? 'You are GitHub Copilot. Provide code suggestions.' :
24
+ operation === 'explain' ? 'You are GitHub Copilot. Explain the provided code or command clearly and concisely.' :
25
+ 'You are GitHub Copilot. Suggest shell commands.'
26
+ },
27
+ {
28
+ role: 'user',
29
+ content: prompt
30
+ }
31
+ ],
32
+ max_tokens: 1000,
33
+ temperature: 0.3
34
+ })
35
+ });
36
+ if (!response.ok) {
37
+ throw new Error(`GitHub API error: ${response.status}`);
38
+ }
39
+ const data = await response.json();
40
+ return ((_c = (_b = (_a = data.choices) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.message) === null || _c === void 0 ? void 0 : _c.content) || `Fallback response for: ${prompt}`;
41
+ }
42
+ catch (error) {
43
+ const enhancedResponses = {
44
+ suggest: `// GitHub Copilot suggestion for: ${prompt}\n// (Using enhanced fallback - CLI not available)\n\n// Based on your prompt, here's a code suggestion:\nfunction handleRequest() {\n // TODO: Implement logic for ${prompt}\n return result;\n}\n\n// Note: Install and configure GitHub CLI for better AI suggestions`,
45
+ explain: getEnhancedExplanation(prompt),
46
+ shell: getEnhancedShellSuggestion(prompt)
14
47
  };
15
- resolve(mockResponse[operation] || `Response for: ${prompt}`);
16
- });
48
+ return enhancedResponses[operation] || `Enhanced fallback response for: ${prompt}`;
49
+ }
50
+ }
51
+ function getEnhancedExplanation(prompt) {
52
+ const command = prompt.toLowerCase().trim();
53
+ if (command.includes('bfg')) {
54
+ return `This command uses BFG Repo-Cleaner:\n\n• bfg --strip-blobs-bigger-than 50M\n - Removes all files larger than 50MB from Git history\n - Helps reduce repository size\n - CAUTION: This rewrites Git history permanently\n - Backup your repository before running\n - Use: java -jar bfg.jar --strip-blobs-bigger-than 50M my-repo.git\n\nNote: GitHub CLI not available - using enhanced fallback`;
55
+ }
56
+ if (command.includes('git')) {
57
+ return `This appears to be a Git command:\n\n${prompt}\n\n• Git is a version control system\n• This command likely manages repository history or files\n• Be careful with commands that modify history\n\nNote: GitHub CLI not available - using enhanced fallback`;
58
+ }
59
+ return `Command analysis for: ${prompt}\n\n• This appears to be a command-line instruction\n• Please verify the command before execution\n• Consider checking the documentation for more details\n\nNote: GitHub CLI not available - using enhanced fallback`;
60
+ }
61
+ function getEnhancedShellSuggestion(prompt) {
62
+ const lowerPrompt = prompt.toLowerCase();
63
+ if (lowerPrompt.includes('git') && lowerPrompt.includes('large')) {
64
+ return `# Git repository cleanup suggestions:\ngit gc --aggressive\ngit repack -ad\n\n# Or use BFG for removing large files:\njava -jar bfg.jar --strip-blobs-bigger-than 50M\n\n# Note: GitHub CLI not available - using enhanced fallback`;
65
+ }
66
+ return `# Shell command suggestion for: ${prompt}\n# (Enhanced fallback - GitHub CLI not available)\n\necho "Processing: ${prompt}"\n# Add your specific command here\n\n# Note: Configure GitHub CLI for better AI suggestions`;
17
67
  }
18
68
  class GitHubCopilot {
19
69
  constructor() {
@@ -157,10 +207,10 @@ class GitHubCopilot {
157
207
  if (language !== 'other') {
158
208
  fullPrompt = `[${language}] ${fullPrompt}`;
159
209
  }
160
- command = `gh copilot suggest "${fullPrompt}"`;
210
+ command = `/usr/bin/gh copilot suggest "${fullPrompt}"`;
161
211
  break;
162
212
  case 'explain':
163
- command = `gh copilot explain "${fullPrompt}"`;
213
+ command = `/usr/bin/gh copilot explain "${fullPrompt}"`;
164
214
  break;
165
215
  case 'shell':
166
216
  const commandType = this.getNodeParameter('commandType', i);
@@ -181,7 +231,7 @@ class GitHubCopilot {
181
231
  default:
182
232
  shellPrompt = fullPrompt;
183
233
  }
184
- command = `gh copilot suggest "${shellPrompt}" --type shell`;
234
+ command = `/usr/bin/gh copilot suggest "${shellPrompt}" --type shell`;
185
235
  break;
186
236
  default:
187
237
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown operation: ${operation}`);
@@ -203,7 +253,11 @@ class GitHubCopilot {
203
253
  result = stdout.trim();
204
254
  }
205
255
  catch (cliError) {
206
- console.log('GitHub CLI not available, using fallback API');
256
+ const errorMessage = cliError instanceof Error ? cliError.message : String(cliError);
257
+ console.log('GitHub CLI execution failed:', errorMessage);
258
+ console.log('Command attempted:', command);
259
+ console.log('Working directory:', process.cwd());
260
+ console.log('Environment PATH:', process.env.PATH);
207
261
  usedFallback = true;
208
262
  result = await callGitHubCopilotAPI(fullPrompt, operation, credentials.accessToken);
209
263
  }
@@ -228,7 +282,7 @@ class GitHubCopilot {
228
282
  suggestion,
229
283
  rawOutput: result,
230
284
  usedFallback,
231
- fallbackReason: usedFallback ? 'GitHub CLI not available on server' : undefined,
285
+ fallbackReason: usedFallback ? `GitHub CLI execution failed: ${command}` : undefined,
232
286
  timestamp: new Date().toISOString(),
233
287
  },
234
288
  pairedItem: { item: i },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-github-copilot",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "n8n community node for GitHub Copilot CLI integration",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/sufficit/n8n-nodes-github-copilot",