n8n-nodes-github-copilot 3.4.0 → 3.5.0

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.
Files changed (35) hide show
  1. package/dist/credentials/GitHubApi.credentials.d.ts +8 -8
  2. package/dist/credentials/GitHubApi.credentials.js +50 -50
  3. package/dist/credentials/GitHubApiManual.credentials.d.ts +7 -7
  4. package/dist/credentials/GitHubApiManual.credentials.js +33 -33
  5. package/dist/nodes/GitHubCopilot/GitHubCopilot.node.d.ts +5 -5
  6. package/dist/nodes/GitHubCopilot/GitHubCopilot.node.js +324 -324
  7. package/dist/nodes/GitHubCopilotChatAPI/GitHubCopilotChatAPI.node.d.ts +5 -5
  8. package/dist/nodes/GitHubCopilotChatAPI/GitHubCopilotChatAPI.node.js +141 -146
  9. package/dist/nodes/GitHubCopilotChatAPI/nodeProperties.d.ts +2 -2
  10. package/dist/nodes/GitHubCopilotChatAPI/nodeProperties.js +172 -202
  11. package/dist/nodes/GitHubCopilotChatAPI/utils/helpers.d.ts +19 -21
  12. package/dist/nodes/GitHubCopilotChatAPI/utils/helpers.js +130 -131
  13. package/dist/nodes/GitHubCopilotChatAPI/utils/imageProcessor.d.ts +8 -8
  14. package/dist/nodes/GitHubCopilotChatAPI/utils/imageProcessor.js +100 -101
  15. package/dist/nodes/GitHubCopilotChatAPI/utils/index.d.ts +3 -3
  16. package/dist/nodes/GitHubCopilotChatAPI/utils/index.js +19 -19
  17. package/dist/nodes/GitHubCopilotChatAPI/utils/mediaDetection.d.ts +14 -14
  18. package/dist/nodes/GitHubCopilotChatAPI/utils/mediaDetection.js +70 -71
  19. package/dist/nodes/GitHubCopilotChatAPI/utils/modelCapabilities.d.ts +5 -5
  20. package/dist/nodes/GitHubCopilotChatAPI/utils/modelCapabilities.js +113 -113
  21. package/dist/nodes/GitHubCopilotChatAPI/utils/types.d.ts +57 -57
  22. package/dist/nodes/GitHubCopilotChatAPI/utils/types.js +2 -2
  23. package/dist/nodes/GitHubCopilotChatModel/GitHubCopilotChatModel.node.d.ts +5 -5
  24. package/dist/nodes/GitHubCopilotChatModel/GitHubCopilotChatModel.node.js +140 -211
  25. package/dist/shared/models/GitHubCopilotModels.d.ts +43 -0
  26. package/dist/shared/models/GitHubCopilotModels.js +218 -0
  27. package/package.json +5 -4
  28. package/dist/credentials/N8nApi.credentials.d.ts +0 -7
  29. package/dist/credentials/N8nApi.credentials.js +0 -31
  30. package/dist/nodes/GitHubCopilotChatAPI/GitHubCopilotChatAPI.node.backup.d.ts +0 -5
  31. package/dist/nodes/GitHubCopilotChatAPI/GitHubCopilotChatAPI.node.backup.js +0 -651
  32. package/dist/nodes/GitHubCopilotChatAPI/utils/audioProcessor.d.ts +0 -11
  33. package/dist/nodes/GitHubCopilotChatAPI/utils/audioProcessor.js +0 -86
  34. package/dist/nodes/N8nAiAgent/N8nAiAgent.node.d.ts +0 -5
  35. package/dist/nodes/N8nAiAgent/N8nAiAgent.node.js +0 -152
@@ -1,324 +1,324 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GitHubCopilot = void 0;
4
- const n8n_workflow_1 = require("n8n-workflow");
5
- const child_process_1 = require("child_process");
6
- const util_1 = require("util");
7
- const execAsync = (0, util_1.promisify)(child_process_1.exec);
8
- function filterCopilotOutput(rawOutput) {
9
- const lines = rawOutput.split('\n');
10
- let startIndex = -1;
11
- const endIndex = lines.length;
12
- for (let i = 0; i < lines.length; i++) {
13
- const line = lines[i].trim();
14
- if (line.includes('# Explanation:') ||
15
- line.includes('# Suggestion:') ||
16
- line.includes('# Command:') ||
17
- line.includes('# Code:') ||
18
- (line.startsWith('•') && i > 5)) {
19
- startIndex = i;
20
- break;
21
- }
22
- }
23
- if (startIndex === -1) {
24
- for (let i = 0; i < lines.length; i++) {
25
- const line = lines[i].trim();
26
- if (line.includes('version ') && line.includes('(') && line.includes(')')) {
27
- startIndex = i + 3;
28
- break;
29
- }
30
- }
31
- }
32
- if (startIndex === -1) {
33
- for (let i = 0; i < lines.length; i++) {
34
- const line = lines[i].trim();
35
- if (line.length > 10 && !line.includes('Welcome to') && !line.includes('powered by AI')) {
36
- startIndex = i;
37
- break;
38
- }
39
- }
40
- }
41
- if (startIndex >= 0) {
42
- const filteredLines = lines.slice(startIndex, endIndex);
43
- return filteredLines.join('\n').trim();
44
- }
45
- return rawOutput.trim();
46
- }
47
- class GitHubCopilot {
48
- constructor() {
49
- this.description = {
50
- displayName: 'GitHub Copilot',
51
- name: 'gitHubCopilot',
52
- icon: 'file:githubcopilot.svg',
53
- group: ['transform'],
54
- version: 1,
55
- subtitle: '={{$parameter["operation"]}}',
56
- description: 'Use GitHub Copilot CLI for AI-powered code suggestions and explanations',
57
- defaults: {
58
- name: 'GitHub Copilot',
59
- },
60
- inputs: ["main"],
61
- outputs: ["main"],
62
- properties: [
63
- {
64
- displayName: 'Operation',
65
- name: 'operation',
66
- type: 'options',
67
- noDataExpression: true,
68
- options: [
69
- {
70
- name: 'Suggest',
71
- value: 'suggest',
72
- description: 'Get code suggestions from GitHub Copilot',
73
- action: 'Get code suggestions',
74
- },
75
- {
76
- name: 'Explain',
77
- value: 'explain',
78
- description: 'Explain code or commands using GitHub Copilot',
79
- action: 'Explain code or commands',
80
- },
81
- {
82
- name: 'Shell',
83
- value: 'shell',
84
- description: 'Get shell command suggestions from GitHub Copilot',
85
- action: 'Get shell command suggestions',
86
- },
87
- ],
88
- default: 'suggest',
89
- },
90
- {
91
- displayName: 'Prompt',
92
- name: 'prompt',
93
- type: 'string',
94
- typeOptions: {
95
- rows: 3,
96
- },
97
- required: true,
98
- default: '',
99
- placeholder: 'Enter your request...',
100
- description: 'What you want GitHub Copilot to help with',
101
- },
102
- {
103
- displayName: 'GitHub Token (Optional)',
104
- name: 'githubToken',
105
- type: 'string',
106
- typeOptions: { password: true },
107
- default: '',
108
- placeholder: 'gho_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
109
- description: '⚠️ IMPORTANT: Only tokens generated by GitHub CLI itself work with Copilot. Personal Access Tokens from GitHub website DO NOT work. If not provided, will use local "gh auth login" authentication. To get a working token, use: gh auth token',
110
- },
111
- {
112
- displayName: 'Filter Output',
113
- name: 'filterOutput',
114
- type: 'boolean',
115
- default: true,
116
- description: 'Remove GitHub Copilot CLI header and footer, keeping only the useful response',
117
- },
118
- {
119
- displayName: 'Language',
120
- name: 'language',
121
- type: 'options',
122
- displayOptions: {
123
- show: {
124
- operation: ['suggest'],
125
- },
126
- },
127
- options: [
128
- { name: 'JavaScript', value: 'javascript' },
129
- { name: 'TypeScript', value: 'typescript' },
130
- { name: 'Python', value: 'python' },
131
- { name: 'Java', value: 'java' },
132
- { name: 'C#', value: 'csharp' },
133
- { name: 'C++', value: 'cpp' },
134
- { name: 'Go', value: 'go' },
135
- { name: 'Rust', value: 'rust' },
136
- { name: 'PHP', value: 'php' },
137
- { name: 'Ruby', value: 'ruby' },
138
- { name: 'Shell', value: 'shell' },
139
- { name: 'SQL', value: 'sql' },
140
- { name: 'Other', value: 'other' },
141
- ],
142
- default: 'javascript',
143
- description: 'Programming language for code suggestions',
144
- },
145
- {
146
- displayName: 'Command Type',
147
- name: 'commandType',
148
- type: 'options',
149
- displayOptions: {
150
- show: {
151
- operation: ['shell'],
152
- },
153
- },
154
- options: [
155
- { name: 'General', value: 'general' },
156
- { name: 'Git', value: 'git' },
157
- { name: 'Docker', value: 'docker' },
158
- { name: 'npm/yarn', value: 'npm' },
159
- { name: 'File Operations', value: 'file' },
160
- ],
161
- default: 'general',
162
- description: 'Type of shell commands to suggest',
163
- },
164
- {
165
- displayName: 'Additional Context',
166
- name: 'context',
167
- type: 'string',
168
- typeOptions: {
169
- rows: 2,
170
- },
171
- default: '',
172
- placeholder: 'Any additional context or constraints...',
173
- description: 'Optional additional context to provide better suggestions',
174
- },
175
- ],
176
- };
177
- }
178
- async execute() {
179
- const items = this.getInputData();
180
- const returnData = [];
181
- for (let i = 0; i < items.length; i++) {
182
- try {
183
- const operation = this.getNodeParameter('operation', i);
184
- const prompt = this.getNodeParameter('prompt', i);
185
- const context = this.getNodeParameter('context', i, '');
186
- const githubToken = this.getNodeParameter('githubToken', i, '');
187
- const useToken = githubToken && githubToken.trim() !== '';
188
- const authMethod = useToken ? 'Manual Token' : 'Local CLI';
189
- let command;
190
- let fullPrompt = prompt;
191
- if (context) {
192
- fullPrompt = `${prompt}\n\nAdditional context: ${context}`;
193
- }
194
- switch (operation) {
195
- case 'suggest':
196
- const language = this.getNodeParameter('language', i);
197
- if (language !== 'other') {
198
- fullPrompt = `[${language}] ${fullPrompt}`;
199
- }
200
- const escapedSuggestPrompt = fullPrompt.replace(/'/g, `'"'"'`);
201
- command = `/usr/bin/gh copilot suggest '${escapedSuggestPrompt}'`;
202
- break;
203
- case 'explain':
204
- const escapedExplainPrompt = fullPrompt.replace(/'/g, `'"'"'`);
205
- command = `/usr/bin/gh copilot explain '${escapedExplainPrompt}'`;
206
- break;
207
- case 'shell':
208
- const commandType = this.getNodeParameter('commandType', i);
209
- let shellPrompt = fullPrompt;
210
- switch (commandType) {
211
- case 'git':
212
- shellPrompt = `git: ${fullPrompt}`;
213
- break;
214
- case 'docker':
215
- shellPrompt = `docker: ${fullPrompt}`;
216
- break;
217
- case 'npm':
218
- shellPrompt = `npm/yarn: ${fullPrompt}`;
219
- break;
220
- case 'file':
221
- shellPrompt = `file operations: ${fullPrompt}`;
222
- break;
223
- default:
224
- shellPrompt = fullPrompt;
225
- }
226
- const escapedShellPrompt = shellPrompt.replace(/'/g, `'"'"'`);
227
- command = `/usr/bin/gh copilot suggest '${escapedShellPrompt}' --type shell`;
228
- break;
229
- default:
230
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown operation: ${operation}`);
231
- }
232
- console.log('Executing command:', command);
233
- console.log('Auth method:', authMethod);
234
- console.log('Using token:', useToken ? 'Yes (Manual)' : 'No (Local CLI)');
235
- let stdout = '';
236
- let stderr = '';
237
- try {
238
- const envVars = {
239
- ...process.env,
240
- HOME: '/opt/n8n-source/packages/cli/bin',
241
- };
242
- if (useToken) {
243
- envVars.GH_TOKEN = githubToken;
244
- envVars.GITHUB_TOKEN = githubToken;
245
- }
246
- const result = await execAsync(command, {
247
- env: envVars,
248
- timeout: 30000,
249
- maxBuffer: 1024 * 1024,
250
- });
251
- stdout = result.stdout;
252
- stderr = result.stderr;
253
- }
254
- catch (execError) {
255
- const err = execError;
256
- stderr = err.stderr || err.message || String(execError);
257
- stdout = err.stdout || '';
258
- }
259
- if (stderr) {
260
- const debugInfo = useToken
261
- ? ` [Using manual token: ${githubToken.substring(0, 4)}...]`
262
- : ' [Using local CLI authentication]';
263
- if (stderr.includes('internal server error') || stderr.includes('code: 500')) {
264
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `GitHub Copilot service is temporarily unavailable (HTTP 500). This is a GitHub server issue. Please try again in a few moments.${debugInfo} Error: ${stderr}`);
265
- }
266
- else if (stderr.includes('code: 400') || stderr.includes('Bad Request')) {
267
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `GitHub Copilot request failed (HTTP 400). The request is malformed or invalid.${debugInfo} Full error response: ${stderr}`);
268
- }
269
- else if (stderr.includes('401') || stderr.includes('Unauthorized') || stderr.includes('Bad credentials')) {
270
- const tokenHelp = useToken
271
- ? ' IMPORTANT: Only tokens generated by "gh auth token" command work with Copilot. Personal Access Tokens from GitHub website DO NOT work. Try: run "gh auth login" first, then use "gh auth token" to get a working token.'
272
- : ' Please run "gh auth login" on the server first, or provide a token generated by "gh auth token" command.';
273
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `GitHub authentication failed (HTTP 401).${tokenHelp}${debugInfo} Full error response: ${stderr}`);
274
- }
275
- else if (stderr.includes('403') || stderr.includes('Forbidden')) {
276
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `GitHub Copilot access denied (HTTP 403). Please ensure your account has Copilot subscription.${debugInfo} Full error response: ${stderr}`);
277
- }
278
- else if (!stdout) {
279
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `GitHub Copilot CLI error:${debugInfo} Full error response: ${stderr}`);
280
- }
281
- }
282
- const filterOutput = this.getNodeParameter('filterOutput', i, true);
283
- let processedOutput = stdout;
284
- if (filterOutput) {
285
- processedOutput = filterCopilotOutput(stdout);
286
- }
287
- returnData.push({
288
- json: {
289
- operation,
290
- prompt: prompt,
291
- context: context || undefined,
292
- authMethod: authMethod,
293
- tokenUsed: useToken,
294
- tokenPrefix: useToken ? githubToken.substring(0, 4) + '...' : 'none',
295
- language: operation === 'suggest' ? this.getNodeParameter('language', i) : undefined,
296
- commandType: operation === 'shell' ? this.getNodeParameter('commandType', i) : undefined,
297
- output: processedOutput,
298
- cliRawOutput: stdout,
299
- cliStderr: stderr || undefined,
300
- timestamp: new Date().toISOString(),
301
- },
302
- pairedItem: { item: i },
303
- });
304
- }
305
- catch (error) {
306
- if (this.continueOnFail()) {
307
- returnData.push({
308
- json: {
309
- error: error instanceof Error ? error.message : String(error),
310
- operation: this.getNodeParameter('operation', i, 'unknown'),
311
- prompt: this.getNodeParameter('prompt', i, ''),
312
- timestamp: new Date().toISOString(),
313
- },
314
- pairedItem: { item: i },
315
- });
316
- continue;
317
- }
318
- throw error;
319
- }
320
- }
321
- return [returnData];
322
- }
323
- }
324
- exports.GitHubCopilot = GitHubCopilot;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GitHubCopilot = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ const child_process_1 = require("child_process");
6
+ const util_1 = require("util");
7
+ const execAsync = (0, util_1.promisify)(child_process_1.exec);
8
+ function filterCopilotOutput(rawOutput) {
9
+ const lines = rawOutput.split('\n');
10
+ let startIndex = -1;
11
+ const endIndex = lines.length;
12
+ for (let i = 0; i < lines.length; i++) {
13
+ const line = lines[i].trim();
14
+ if (line.includes('# Explanation:') ||
15
+ line.includes('# Suggestion:') ||
16
+ line.includes('# Command:') ||
17
+ line.includes('# Code:') ||
18
+ (line.startsWith('•') && i > 5)) {
19
+ startIndex = i;
20
+ break;
21
+ }
22
+ }
23
+ if (startIndex === -1) {
24
+ for (let i = 0; i < lines.length; i++) {
25
+ const line = lines[i].trim();
26
+ if (line.includes('version ') && line.includes('(') && line.includes(')')) {
27
+ startIndex = i + 3;
28
+ break;
29
+ }
30
+ }
31
+ }
32
+ if (startIndex === -1) {
33
+ for (let i = 0; i < lines.length; i++) {
34
+ const line = lines[i].trim();
35
+ if (line.length > 10 && !line.includes('Welcome to') && !line.includes('powered by AI')) {
36
+ startIndex = i;
37
+ break;
38
+ }
39
+ }
40
+ }
41
+ if (startIndex >= 0) {
42
+ const filteredLines = lines.slice(startIndex, endIndex);
43
+ return filteredLines.join('\n').trim();
44
+ }
45
+ return rawOutput.trim();
46
+ }
47
+ class GitHubCopilot {
48
+ constructor() {
49
+ this.description = {
50
+ displayName: 'GitHub Copilot',
51
+ name: 'gitHubCopilot',
52
+ icon: 'file:githubcopilot.svg',
53
+ group: ['transform'],
54
+ version: 1,
55
+ subtitle: '={{$parameter["operation"]}}',
56
+ description: 'Use GitHub Copilot CLI for AI-powered code suggestions and explanations',
57
+ defaults: {
58
+ name: 'GitHub Copilot',
59
+ },
60
+ inputs: ["main"],
61
+ outputs: ["main"],
62
+ properties: [
63
+ {
64
+ displayName: 'Operation',
65
+ name: 'operation',
66
+ type: 'options',
67
+ noDataExpression: true,
68
+ options: [
69
+ {
70
+ name: 'Suggest',
71
+ value: 'suggest',
72
+ description: 'Get code suggestions from GitHub Copilot',
73
+ action: 'Get code suggestions',
74
+ },
75
+ {
76
+ name: 'Explain',
77
+ value: 'explain',
78
+ description: 'Explain code or commands using GitHub Copilot',
79
+ action: 'Explain code or commands',
80
+ },
81
+ {
82
+ name: 'Shell',
83
+ value: 'shell',
84
+ description: 'Get shell command suggestions from GitHub Copilot',
85
+ action: 'Get shell command suggestions',
86
+ },
87
+ ],
88
+ default: 'suggest',
89
+ },
90
+ {
91
+ displayName: 'Prompt',
92
+ name: 'prompt',
93
+ type: 'string',
94
+ typeOptions: {
95
+ rows: 3,
96
+ },
97
+ required: true,
98
+ default: '',
99
+ placeholder: 'Enter your request...',
100
+ description: 'What you want GitHub Copilot to help with',
101
+ },
102
+ {
103
+ displayName: 'GitHub Token (Optional)',
104
+ name: 'githubToken',
105
+ type: 'string',
106
+ typeOptions: { password: true },
107
+ default: '',
108
+ placeholder: 'gho_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
109
+ description: '⚠️ IMPORTANT: Only tokens generated by GitHub CLI itself work with Copilot. Personal Access Tokens from GitHub website DO NOT work. If not provided, will use local "gh auth login" authentication. To get a working token, use: gh auth token',
110
+ },
111
+ {
112
+ displayName: 'Filter Output',
113
+ name: 'filterOutput',
114
+ type: 'boolean',
115
+ default: true,
116
+ description: 'Remove GitHub Copilot CLI header and footer, keeping only the useful response',
117
+ },
118
+ {
119
+ displayName: 'Language',
120
+ name: 'language',
121
+ type: 'options',
122
+ displayOptions: {
123
+ show: {
124
+ operation: ['suggest'],
125
+ },
126
+ },
127
+ options: [
128
+ { name: 'JavaScript', value: 'javascript' },
129
+ { name: 'TypeScript', value: 'typescript' },
130
+ { name: 'Python', value: 'python' },
131
+ { name: 'Java', value: 'java' },
132
+ { name: 'C#', value: 'csharp' },
133
+ { name: 'C++', value: 'cpp' },
134
+ { name: 'Go', value: 'go' },
135
+ { name: 'Rust', value: 'rust' },
136
+ { name: 'PHP', value: 'php' },
137
+ { name: 'Ruby', value: 'ruby' },
138
+ { name: 'Shell', value: 'shell' },
139
+ { name: 'SQL', value: 'sql' },
140
+ { name: 'Other', value: 'other' },
141
+ ],
142
+ default: 'javascript',
143
+ description: 'Programming language for code suggestions',
144
+ },
145
+ {
146
+ displayName: 'Command Type',
147
+ name: 'commandType',
148
+ type: 'options',
149
+ displayOptions: {
150
+ show: {
151
+ operation: ['shell'],
152
+ },
153
+ },
154
+ options: [
155
+ { name: 'General', value: 'general' },
156
+ { name: 'Git', value: 'git' },
157
+ { name: 'Docker', value: 'docker' },
158
+ { name: 'npm/yarn', value: 'npm' },
159
+ { name: 'File Operations', value: 'file' },
160
+ ],
161
+ default: 'general',
162
+ description: 'Type of shell commands to suggest',
163
+ },
164
+ {
165
+ displayName: 'Additional Context',
166
+ name: 'context',
167
+ type: 'string',
168
+ typeOptions: {
169
+ rows: 2,
170
+ },
171
+ default: '',
172
+ placeholder: 'Any additional context or constraints...',
173
+ description: 'Optional additional context to provide better suggestions',
174
+ },
175
+ ],
176
+ };
177
+ }
178
+ async execute() {
179
+ const items = this.getInputData();
180
+ const returnData = [];
181
+ for (let i = 0; i < items.length; i++) {
182
+ try {
183
+ const operation = this.getNodeParameter('operation', i);
184
+ const prompt = this.getNodeParameter('prompt', i);
185
+ const context = this.getNodeParameter('context', i, '');
186
+ const githubToken = this.getNodeParameter('githubToken', i, '');
187
+ const useToken = githubToken && githubToken.trim() !== '';
188
+ const authMethod = useToken ? 'Manual Token' : 'Local CLI';
189
+ let command;
190
+ let fullPrompt = prompt;
191
+ if (context) {
192
+ fullPrompt = `${prompt}\n\nAdditional context: ${context}`;
193
+ }
194
+ switch (operation) {
195
+ case 'suggest':
196
+ const language = this.getNodeParameter('language', i);
197
+ if (language !== 'other') {
198
+ fullPrompt = `[${language}] ${fullPrompt}`;
199
+ }
200
+ const escapedSuggestPrompt = fullPrompt.replace(/'/g, `'"'"'`);
201
+ command = `/usr/bin/gh copilot suggest '${escapedSuggestPrompt}'`;
202
+ break;
203
+ case 'explain':
204
+ const escapedExplainPrompt = fullPrompt.replace(/'/g, `'"'"'`);
205
+ command = `/usr/bin/gh copilot explain '${escapedExplainPrompt}'`;
206
+ break;
207
+ case 'shell':
208
+ const commandType = this.getNodeParameter('commandType', i);
209
+ let shellPrompt = fullPrompt;
210
+ switch (commandType) {
211
+ case 'git':
212
+ shellPrompt = `git: ${fullPrompt}`;
213
+ break;
214
+ case 'docker':
215
+ shellPrompt = `docker: ${fullPrompt}`;
216
+ break;
217
+ case 'npm':
218
+ shellPrompt = `npm/yarn: ${fullPrompt}`;
219
+ break;
220
+ case 'file':
221
+ shellPrompt = `file operations: ${fullPrompt}`;
222
+ break;
223
+ default:
224
+ shellPrompt = fullPrompt;
225
+ }
226
+ const escapedShellPrompt = shellPrompt.replace(/'/g, `'"'"'`);
227
+ command = `/usr/bin/gh copilot suggest '${escapedShellPrompt}' --type shell`;
228
+ break;
229
+ default:
230
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown operation: ${operation}`);
231
+ }
232
+ console.log('Executing command:', command);
233
+ console.log('Auth method:', authMethod);
234
+ console.log('Using token:', useToken ? 'Yes (Manual)' : 'No (Local CLI)');
235
+ let stdout = '';
236
+ let stderr = '';
237
+ try {
238
+ const envVars = {
239
+ ...process.env,
240
+ HOME: '/opt/n8n-source/packages/cli/bin',
241
+ };
242
+ if (useToken) {
243
+ envVars.GH_TOKEN = githubToken;
244
+ envVars.GITHUB_TOKEN = githubToken;
245
+ }
246
+ const result = await execAsync(command, {
247
+ env: envVars,
248
+ timeout: 30000,
249
+ maxBuffer: 1024 * 1024,
250
+ });
251
+ stdout = result.stdout;
252
+ stderr = result.stderr;
253
+ }
254
+ catch (execError) {
255
+ const err = execError;
256
+ stderr = err.stderr || err.message || String(execError);
257
+ stdout = err.stdout || '';
258
+ }
259
+ if (stderr) {
260
+ const debugInfo = useToken
261
+ ? ` [Using manual token: ${githubToken.substring(0, 4)}...]`
262
+ : ' [Using local CLI authentication]';
263
+ if (stderr.includes('internal server error') || stderr.includes('code: 500')) {
264
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `GitHub Copilot service is temporarily unavailable (HTTP 500). This is a GitHub server issue. Please try again in a few moments.${debugInfo} Error: ${stderr}`);
265
+ }
266
+ else if (stderr.includes('code: 400') || stderr.includes('Bad Request')) {
267
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `GitHub Copilot request failed (HTTP 400). The request is malformed or invalid.${debugInfo} Full error response: ${stderr}`);
268
+ }
269
+ else if (stderr.includes('401') || stderr.includes('Unauthorized') || stderr.includes('Bad credentials')) {
270
+ const tokenHelp = useToken
271
+ ? ' IMPORTANT: Only tokens generated by "gh auth token" command work with Copilot. Personal Access Tokens from GitHub website DO NOT work. Try: run "gh auth login" first, then use "gh auth token" to get a working token.'
272
+ : ' Please run "gh auth login" on the server first, or provide a token generated by "gh auth token" command.';
273
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `GitHub authentication failed (HTTP 401).${tokenHelp}${debugInfo} Full error response: ${stderr}`);
274
+ }
275
+ else if (stderr.includes('403') || stderr.includes('Forbidden')) {
276
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `GitHub Copilot access denied (HTTP 403). Please ensure your account has Copilot subscription.${debugInfo} Full error response: ${stderr}`);
277
+ }
278
+ else if (!stdout) {
279
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `GitHub Copilot CLI error:${debugInfo} Full error response: ${stderr}`);
280
+ }
281
+ }
282
+ const filterOutput = this.getNodeParameter('filterOutput', i, true);
283
+ let processedOutput = stdout;
284
+ if (filterOutput) {
285
+ processedOutput = filterCopilotOutput(stdout);
286
+ }
287
+ returnData.push({
288
+ json: {
289
+ operation,
290
+ prompt: prompt,
291
+ context: context || undefined,
292
+ authMethod: authMethod,
293
+ tokenUsed: useToken,
294
+ tokenPrefix: useToken ? githubToken.substring(0, 4) + '...' : 'none',
295
+ language: operation === 'suggest' ? this.getNodeParameter('language', i) : undefined,
296
+ commandType: operation === 'shell' ? this.getNodeParameter('commandType', i) : undefined,
297
+ output: processedOutput,
298
+ cliRawOutput: stdout,
299
+ cliStderr: stderr || undefined,
300
+ timestamp: new Date().toISOString(),
301
+ },
302
+ pairedItem: { item: i },
303
+ });
304
+ }
305
+ catch (error) {
306
+ if (this.continueOnFail()) {
307
+ returnData.push({
308
+ json: {
309
+ error: error instanceof Error ? error.message : String(error),
310
+ operation: this.getNodeParameter('operation', i, 'unknown'),
311
+ prompt: this.getNodeParameter('prompt', i, ''),
312
+ timestamp: new Date().toISOString(),
313
+ },
314
+ pairedItem: { item: i },
315
+ });
316
+ continue;
317
+ }
318
+ throw error;
319
+ }
320
+ }
321
+ return [returnData];
322
+ }
323
+ }
324
+ exports.GitHubCopilot = GitHubCopilot;