n8n-nodes-github-copilot 3.31.13 → 3.31.15

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.
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GitHubCopilotOpenAI = void 0;
4
4
  const nodeProperties_1 = require("./nodeProperties");
5
+ const utils_1 = require("../GitHubCopilotChatAPI/utils");
6
+ const GitHubCopilotEndpoints_1 = require("../../shared/utils/GitHubCopilotEndpoints");
5
7
  class GitHubCopilotOpenAI {
6
8
  constructor() {
7
9
  this.description = {
@@ -66,49 +68,73 @@ class GitHubCopilotOpenAI {
66
68
  content: "Hello! How can you help me?",
67
69
  });
68
70
  }
71
+ let parsedTools = [];
72
+ if (tools && tools.trim()) {
73
+ try {
74
+ parsedTools = JSON.parse(tools);
75
+ }
76
+ catch (error) {
77
+ throw new Error(`Failed to parse tools JSON: ${error instanceof Error ? error.message : "Unknown error"}`);
78
+ }
79
+ }
80
+ const max_tokens = this.getNodeParameter("max_tokens", i, 4096);
81
+ const seed = this.getNodeParameter("seed", i, 0);
82
+ const advancedOptions = this.getNodeParameter("advancedOptions", i, {});
83
+ let response_format = undefined;
84
+ if (advancedOptions.response_format && typeof advancedOptions.response_format === 'string') {
85
+ try {
86
+ response_format = JSON.parse(advancedOptions.response_format);
87
+ }
88
+ catch {
89
+ }
90
+ }
69
91
  const modelMapping = {
70
92
  "gpt-4": "gpt-4o",
71
93
  "gpt-4o": "gpt-4o",
72
94
  "gpt-4o-mini": "gpt-4o-mini",
95
+ "gpt-4-turbo": "gpt-4o",
73
96
  "claude-3-5-sonnet": "claude-3.5-sonnet",
97
+ "claude-3.5-sonnet-20241022": "claude-3.5-sonnet",
98
+ "o1": "o1",
99
+ "o1-preview": "o1-preview",
100
+ "o1-mini": "o1-mini",
74
101
  };
75
- const copilotModel = modelMapping[model] || "gpt-4o";
76
- const mockResponse = {
77
- id: `chatcmpl-${Date.now()}`,
78
- object: "chat.completion",
79
- created: Math.floor(Date.now() / 1000),
102
+ const copilotModel = modelMapping[model] || model;
103
+ const requestBody = {
104
+ model: copilotModel,
105
+ messages,
106
+ stream: false,
107
+ temperature,
108
+ max_tokens,
109
+ };
110
+ if (parsedTools.length > 0) {
111
+ requestBody.tools = parsedTools;
112
+ }
113
+ if (response_format) {
114
+ requestBody.response_format = response_format;
115
+ }
116
+ if (seed > 0) {
117
+ requestBody.seed = seed;
118
+ }
119
+ const response = await (0, utils_1.makeApiRequest)(this, GitHubCopilotEndpoints_1.GITHUB_COPILOT_API.ENDPOINTS.CHAT_COMPLETIONS, requestBody, false);
120
+ const openAIResponse = {
121
+ id: response.id || `chatcmpl-${Date.now()}`,
122
+ object: response.object || "chat.completion",
123
+ created: response.created || Math.floor(Date.now() / 1000),
80
124
  model: model,
81
- choices: [
82
- {
83
- index: 0,
84
- message: {
85
- role: "assistant",
86
- content: `🚀 GitHub Copilot OpenAI Mock Response
87
-
88
- **Request Details:**
89
- - Model: ${model} → ${copilotModel}
90
- - Messages: ${messages.length}
91
- - Temperature: ${temperature}
92
- - Tools: ${tools ? "Yes" : "No"}
93
-
94
- **Sample Messages:**
95
- ${messages
96
- .map((msg, idx) => `${idx + 1}. [${msg.role}]: ${msg.content.substring(0, 100)}${msg.content.length > 100 ? "..." : ""}`)
97
- .join("\n")}
98
-
99
- This is a mock response. The real GitHub Copilot integration will be implemented next.`,
100
- },
101
- finish_reason: "stop",
102
- },
103
- ],
104
- usage: {
105
- prompt_tokens: 50,
106
- completion_tokens: 125,
107
- total_tokens: 175,
125
+ choices: response.choices.map((choice) => ({
126
+ index: choice.index,
127
+ message: choice.message,
128
+ finish_reason: choice.finish_reason,
129
+ })),
130
+ usage: response.usage || {
131
+ prompt_tokens: 0,
132
+ completion_tokens: 0,
133
+ total_tokens: 0,
108
134
  },
109
135
  };
110
136
  returnData.push({
111
- json: mockResponse,
137
+ json: openAIResponse,
112
138
  pairedItem: { item: i },
113
139
  });
114
140
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-github-copilot",
3
- "version": "3.31.13",
3
+ "version": "3.31.15",
4
4
  "description": "n8n community node for GitHub Copilot with CLI integration, Chat API access, and AI Chat Model for workflows - access GPT-5, Claude, Gemini and more using your Copilot subscription",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/sufficit/n8n-nodes-github-copilot",
@@ -49,20 +49,45 @@ async function makeGitHubCopilotRequest(context, endpoint, body, hasMedia = fals
49
49
  body: JSON.stringify(body),
50
50
  };
51
51
  const fullUrl = `${GitHubCopilotEndpoints_1.GITHUB_COPILOT_API.BASE_URL}${endpoint}`;
52
- const response = await fetch(fullUrl, options);
53
- if (!response.ok) {
54
- const errorText = await response.text();
55
- const tokenPrefix = token.substring(0, 4);
56
- const tokenSuffix = token.substring(token.length - 5);
57
- const tokenInfo = `${tokenPrefix}...${tokenSuffix}`;
58
- console.error(`❌ GitHub Copilot API Error: ${response.status} ${response.statusText}`);
59
- console.error(`❌ Error details: ${errorText}`);
60
- console.error(`❌ Used credential type: ${credentialType}`);
61
- console.error(`❌ Token format used: ${tokenInfo}`);
62
- const enhancedError = `GitHub Copilot API error: ${response.status} ${response.statusText}. ${errorText} [Token used: ${tokenInfo}]`;
63
- throw new Error(enhancedError);
64
- }
65
- return await response.json();
52
+ const MAX_RETRIES = 3;
53
+ let lastError = null;
54
+ for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
55
+ try {
56
+ const response = await fetch(fullUrl, options);
57
+ if (response.status === 403 && attempt < MAX_RETRIES) {
58
+ console.warn(`⚠️ GitHub Copilot API 403 error on attempt ${attempt}/${MAX_RETRIES}. Retrying...`);
59
+ await new Promise(resolve => setTimeout(resolve, 500 * Math.pow(2, attempt - 1)));
60
+ continue;
61
+ }
62
+ if (!response.ok) {
63
+ const errorText = await response.text();
64
+ const tokenPrefix = token.substring(0, 4);
65
+ const tokenSuffix = token.substring(token.length - 5);
66
+ const tokenInfo = `${tokenPrefix}...${tokenSuffix}`;
67
+ console.error(`❌ GitHub Copilot API Error: ${response.status} ${response.statusText}`);
68
+ console.error(`❌ Error details: ${errorText}`);
69
+ console.error(`❌ Used credential type: ${credentialType}`);
70
+ console.error(`❌ Token format used: ${tokenInfo}`);
71
+ console.error(`❌ Attempt: ${attempt}/${MAX_RETRIES}`);
72
+ const enhancedError = `GitHub Copilot API error: ${response.status} ${response.statusText}. ${errorText} [Token used: ${tokenInfo}] [Attempt: ${attempt}/${MAX_RETRIES}]`;
73
+ throw new Error(enhancedError);
74
+ }
75
+ if (attempt > 1) {
76
+ console.log(`✅ GitHub Copilot API succeeded on attempt ${attempt}/${MAX_RETRIES}`);
77
+ }
78
+ return await response.json();
79
+ }
80
+ catch (error) {
81
+ lastError = error instanceof Error ? error : new Error(String(error));
82
+ if (attempt < MAX_RETRIES) {
83
+ console.warn(`⚠️ GitHub Copilot API error on attempt ${attempt}/${MAX_RETRIES}: ${lastError.message}. Retrying...`);
84
+ await new Promise(resolve => setTimeout(resolve, 500 * Math.pow(2, attempt - 1)));
85
+ continue;
86
+ }
87
+ throw lastError;
88
+ }
89
+ }
90
+ throw lastError || new Error("GitHub Copilot API request failed after all retries");
66
91
  }
67
92
  async function downloadFileFromUrl(url) {
68
93
  const response = await fetch(url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-github-copilot",
3
- "version": "3.31.13",
3
+ "version": "3.31.15",
4
4
  "description": "n8n community node for GitHub Copilot with CLI integration, Chat API access, and AI Chat Model for workflows - access GPT-5, Claude, Gemini and more using your Copilot subscription",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/sufficit/n8n-nodes-github-copilot",