n8n-nodes-github-copilot 3.32.3 → 3.35.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.
@@ -1,5 +1,10 @@
1
- import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from "n8n-workflow";
1
+ import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription, ILoadOptionsFunctions, INodePropertyOptions } from "n8n-workflow";
2
2
  export declare class GitHubCopilotChatAPI implements INodeType {
3
3
  description: INodeTypeDescription;
4
+ methods: {
5
+ loadOptions: {
6
+ getAvailableModels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
7
+ };
8
+ };
4
9
  execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
5
10
  }
@@ -6,6 +6,7 @@ const nodeProperties_1 = require("./nodeProperties");
6
6
  const mediaDetection_1 = require("./utils/mediaDetection");
7
7
  const GitHubCopilotModels_1 = require("../../shared/models/GitHubCopilotModels");
8
8
  const GitHubCopilotEndpoints_1 = require("../../shared/utils/GitHubCopilotEndpoints");
9
+ const DynamicModelLoader_1 = require("../../shared/models/DynamicModelLoader");
9
10
  class GitHubCopilotChatAPI {
10
11
  constructor() {
11
12
  this.description = {
@@ -29,6 +30,13 @@ class GitHubCopilotChatAPI {
29
30
  ],
30
31
  properties: nodeProperties_1.nodeProperties,
31
32
  };
33
+ this.methods = {
34
+ loadOptions: {
35
+ async getAvailableModels() {
36
+ return await DynamicModelLoader_1.loadAvailableModels.call(this);
37
+ },
38
+ },
39
+ };
32
40
  }
33
41
  async execute() {
34
42
  var _a, _b, _c, _d;
@@ -37,7 +45,29 @@ class GitHubCopilotChatAPI {
37
45
  for (let i = 0; i < items.length; i++) {
38
46
  try {
39
47
  const operation = this.getNodeParameter("operation", i);
40
- const model = this.getNodeParameter("model", i);
48
+ const modelSource = this.getNodeParameter("modelSource", i, "fromList");
49
+ let model;
50
+ if (modelSource === "custom") {
51
+ model = this.getNodeParameter("customModel", i);
52
+ if (!model || model.trim() === "") {
53
+ throw new Error("Custom model name is required when using 'Custom (Manual Entry)' mode");
54
+ }
55
+ console.log(`🔧 Using custom model: ${model}`);
56
+ }
57
+ else {
58
+ const selectedModel = this.getNodeParameter("model", i);
59
+ if (selectedModel === "__manual__") {
60
+ model = this.getNodeParameter("customModel", i);
61
+ if (!model || model.trim() === "") {
62
+ throw new Error("Custom model name is required when selecting '✏️ Enter Custom Model Name'");
63
+ }
64
+ console.log(`✏️ Using manually entered model: ${model}`);
65
+ }
66
+ else {
67
+ model = selectedModel;
68
+ console.log(`✅ Using model from list: ${model}`);
69
+ }
70
+ }
41
71
  if (operation === "chat") {
42
72
  const userMessage = this.getNodeParameter("message", i);
43
73
  const systemMessage = this.getNodeParameter("systemMessage", i, "");
@@ -47,9 +77,12 @@ class GitHubCopilotChatAPI {
47
77
  const includeMedia = this.getNodeParameter("includeMedia", i, false);
48
78
  const modelInfo = GitHubCopilotModels_1.GitHubCopilotModelsManager.getModelByValue(model);
49
79
  if (includeMedia) {
50
- if (!(modelInfo === null || modelInfo === void 0 ? void 0 : modelInfo.capabilities.vision) && !(modelInfo === null || modelInfo === void 0 ? void 0 : modelInfo.capabilities.multimodal)) {
80
+ if (modelInfo && !(modelInfo === null || modelInfo === void 0 ? void 0 : modelInfo.capabilities.vision) && !(modelInfo === null || modelInfo === void 0 ? void 0 : modelInfo.capabilities.multimodal)) {
51
81
  throw new Error(`Model ${model} does not support vision/image processing. Please select a model with vision capabilities.`);
52
82
  }
83
+ else if (!modelInfo) {
84
+ console.warn(`⚠️ Model ${model} not found in known models list. Vision capability unknown - proceeding anyway.`);
85
+ }
53
86
  }
54
87
  const messages = [];
55
88
  if (systemMessage) {
@@ -17,13 +17,68 @@ exports.nodeProperties = [
17
17
  ],
18
18
  default: "chat",
19
19
  },
20
+ {
21
+ displayName: "Model Source",
22
+ name: "modelSource",
23
+ type: "options",
24
+ options: [
25
+ {
26
+ name: "From List (Auto-Discovered)",
27
+ value: "fromList",
28
+ description: "Select from available models based on your subscription",
29
+ },
30
+ {
31
+ name: "Custom (Manual Entry)",
32
+ value: "custom",
33
+ description: "Enter model name manually (use at your own risk)",
34
+ },
35
+ ],
36
+ default: "fromList",
37
+ description: "Choose how to specify the model",
38
+ },
20
39
  {
21
40
  displayName: "Model",
22
41
  name: "model",
23
42
  type: "options",
24
- options: GitHubCopilotModels_1.GitHubCopilotModelsManager.toN8nOptions(),
43
+ typeOptions: {
44
+ loadOptionsMethod: "getAvailableModels",
45
+ },
25
46
  default: GitHubCopilotModels_1.DEFAULT_MODELS.GENERAL,
26
- description: "Select the GitHub Copilot model to use",
47
+ description: "Select the GitHub Copilot model to use (loaded dynamically based on your subscription)",
48
+ displayOptions: {
49
+ show: {
50
+ modelSource: ["fromList"],
51
+ },
52
+ },
53
+ },
54
+ {
55
+ displayName: "Custom Model Name",
56
+ name: "customModel",
57
+ type: "string",
58
+ default: "",
59
+ placeholder: "gpt-4o, claude-3.5-sonnet, grok-code-fast-1, etc.",
60
+ description: "Enter the model name manually. Use at your own risk if the model is not available in your subscription.",
61
+ hint: "Examples: gpt-4o, gpt-4o-mini, claude-3.5-sonnet, gemini-2.0-flash-exp, grok-code-fast-1",
62
+ displayOptions: {
63
+ show: {
64
+ modelSource: ["custom"],
65
+ },
66
+ },
67
+ },
68
+ {
69
+ displayName: "Custom Model Name",
70
+ name: "customModel",
71
+ type: "string",
72
+ default: "",
73
+ placeholder: "gpt-4o, claude-3.5-sonnet, grok-code-fast-1, etc.",
74
+ description: "Enter the model name manually. This is useful for new/beta models not yet in the list.",
75
+ hint: "Examples: gpt-4o, gpt-4o-mini, claude-3.5-sonnet, gemini-2.0-flash-exp, grok-code-fast-1",
76
+ displayOptions: {
77
+ show: {
78
+ modelSource: ["fromList"],
79
+ model: ["__manual__"],
80
+ },
81
+ },
27
82
  },
28
83
  {
29
84
  displayName: "Message",
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-github-copilot",
3
- "version": "3.32.3",
3
+ "version": "3.35.0",
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",
@@ -0,0 +1,2 @@
1
+ import { ILoadOptionsFunctions, INodePropertyOptions } from "n8n-workflow";
2
+ export declare function loadAvailableModels(this: ILoadOptionsFunctions, forceRefresh?: boolean): Promise<INodePropertyOptions[]>;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadAvailableModels = loadAvailableModels;
4
+ const DynamicModelsManager_1 = require("../utils/DynamicModelsManager");
5
+ const OAuthTokenManager_1 = require("../utils/OAuthTokenManager");
6
+ async function loadAvailableModels(forceRefresh = false) {
7
+ try {
8
+ const credentials = await this.getCredentials("githubCopilotApi");
9
+ if (!credentials || !credentials.token) {
10
+ console.warn("⚠️ No credentials found for dynamic model loading");
11
+ return getDefaultModelsWithManualInput();
12
+ }
13
+ const githubToken = credentials.token;
14
+ let oauthToken;
15
+ try {
16
+ oauthToken = await OAuthTokenManager_1.OAuthTokenManager.getValidOAuthToken(githubToken);
17
+ }
18
+ catch (error) {
19
+ console.error("❌ Failed to generate OAuth token for model loading:", error);
20
+ return getDefaultModelsWithManualInput();
21
+ }
22
+ if (forceRefresh) {
23
+ DynamicModelsManager_1.DynamicModelsManager.clearCache(oauthToken);
24
+ console.log("🔄 Force refreshing models list...");
25
+ }
26
+ const models = await DynamicModelsManager_1.DynamicModelsManager.getAvailableModels(oauthToken);
27
+ const options = DynamicModelsManager_1.DynamicModelsManager.modelsToN8nOptions(models);
28
+ const optionsWithManualInput = [
29
+ {
30
+ name: "✏️ Enter Custom Model Name",
31
+ value: "__manual__",
32
+ description: "Type your own model name (for new/beta models)",
33
+ },
34
+ ...options,
35
+ ];
36
+ console.log(`✅ Loaded ${options.length} models dynamically (+ manual input option)`);
37
+ return optionsWithManualInput;
38
+ }
39
+ catch (error) {
40
+ console.error("❌ Error loading dynamic models:", error);
41
+ return getDefaultModelsWithManualInput();
42
+ }
43
+ }
44
+ function getDefaultModelsWithManualInput() {
45
+ return [
46
+ {
47
+ name: "✏️ Enter Custom Model Name",
48
+ value: "__manual__",
49
+ description: "Type your own model name (for new/beta models)",
50
+ },
51
+ ...getDefaultModels(),
52
+ ];
53
+ }
54
+ function getDefaultModels() {
55
+ return [
56
+ {
57
+ name: "GPT-4o (Latest)",
58
+ value: "gpt-4o",
59
+ description: "Most capable GPT-4o model - Best for complex tasks",
60
+ },
61
+ {
62
+ name: "GPT-4o Mini",
63
+ value: "gpt-4o-mini",
64
+ description: "Faster and cheaper GPT-4o variant - Good for simple tasks",
65
+ },
66
+ {
67
+ name: "Claude 3.5 Sonnet",
68
+ value: "claude-3.5-sonnet",
69
+ description: "Anthropic's most capable model - Excellent reasoning",
70
+ },
71
+ {
72
+ name: "o1-preview",
73
+ value: "o1-preview",
74
+ description: "OpenAI's reasoning model (preview)",
75
+ },
76
+ {
77
+ name: "o1-mini",
78
+ value: "o1-mini",
79
+ description: "Faster reasoning model variant",
80
+ },
81
+ ];
82
+ }
@@ -0,0 +1,4 @@
1
+ import { INodeProperties } from "n8n-workflow";
2
+ export declare const modelSelectionProperty: INodeProperties;
3
+ export declare const modelRefreshProperty: INodeProperties;
4
+ export declare const refreshTriggerProperty: INodeProperties;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.refreshTriggerProperty = exports.modelRefreshProperty = exports.modelSelectionProperty = void 0;
4
+ const GitHubCopilotModels_1 = require("../models/GitHubCopilotModels");
5
+ exports.modelSelectionProperty = {
6
+ displayName: "Model",
7
+ name: "model",
8
+ type: "options",
9
+ typeOptions: {
10
+ loadOptionsMethod: "getAvailableModels",
11
+ loadOptionsDependsOn: ["refresh"],
12
+ },
13
+ default: GitHubCopilotModels_1.DEFAULT_MODELS.GENERAL,
14
+ required: true,
15
+ description: "Select a model from your subscription or enter a custom model name",
16
+ placeholder: "Select model or type custom name (e.g., gpt-4o, claude-3.5-sonnet)",
17
+ hint: "Models are loaded based on your GitHub Copilot subscription. Use the refresh button to update the list.",
18
+ validateType: "string",
19
+ ignoreValidationDuringExecution: false,
20
+ };
21
+ exports.modelRefreshProperty = {
22
+ displayName: "Refresh Models",
23
+ name: "refreshModels",
24
+ type: "button",
25
+ typeOptions: {
26
+ action: "refreshModels",
27
+ },
28
+ default: "",
29
+ description: "Click to refresh the list of available models from your subscription",
30
+ displayOptions: {
31
+ show: {
32
+ operation: ["chat"],
33
+ },
34
+ },
35
+ };
36
+ exports.refreshTriggerProperty = {
37
+ displayName: "Refresh Trigger",
38
+ name: "refresh",
39
+ type: "hidden",
40
+ default: 0,
41
+ description: "Internal field to trigger model list refresh",
42
+ };
@@ -0,0 +1,32 @@
1
+ interface CopilotModel {
2
+ id: string;
3
+ name: string;
4
+ display_name?: string;
5
+ model_picker_enabled?: boolean;
6
+ capabilities?: any;
7
+ vendor?: string;
8
+ version?: string;
9
+ preview?: boolean;
10
+ }
11
+ export declare class DynamicModelsManager {
12
+ private static cache;
13
+ private static readonly CACHE_DURATION_MS;
14
+ private static readonly MIN_REFRESH_INTERVAL_MS;
15
+ private static hashToken;
16
+ private static fetchModelsFromAPI;
17
+ static getAvailableModels(oauthToken: string): Promise<CopilotModel[]>;
18
+ static modelsToN8nOptions(models: CopilotModel[]): Array<{
19
+ name: string;
20
+ value: string;
21
+ description?: string;
22
+ }>;
23
+ static clearCache(oauthToken: string): void;
24
+ static clearAllCache(): void;
25
+ static getCacheInfo(oauthToken: string): {
26
+ cached: boolean;
27
+ modelsCount: number;
28
+ expiresIn: number;
29
+ fetchedAt: string;
30
+ } | null;
31
+ }
32
+ export {};
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DynamicModelsManager = void 0;
4
+ const GitHubCopilotEndpoints_1 = require("./GitHubCopilotEndpoints");
5
+ class DynamicModelsManager {
6
+ static hashToken(token) {
7
+ let hash = 0;
8
+ for (let i = 0; i < token.length; i++) {
9
+ const char = token.charCodeAt(i);
10
+ hash = (hash << 5) - hash + char;
11
+ hash = hash & hash;
12
+ }
13
+ return `models_${Math.abs(hash).toString(36)}`;
14
+ }
15
+ static async fetchModelsFromAPI(oauthToken) {
16
+ const url = `${GitHubCopilotEndpoints_1.GITHUB_COPILOT_API.BASE_URL}${GitHubCopilotEndpoints_1.GITHUB_COPILOT_API.ENDPOINTS.MODELS}`;
17
+ console.log("🔄 Fetching available models from GitHub Copilot API...");
18
+ const response = await fetch(url, {
19
+ method: "GET",
20
+ headers: {
21
+ Authorization: `Bearer ${oauthToken}`,
22
+ Accept: "application/json",
23
+ "Content-Type": "application/json",
24
+ "User-Agent": "GitHub-Copilot/1.0 (n8n-node)",
25
+ "Editor-Version": "vscode/1.95.0",
26
+ "Editor-Plugin-Version": "copilot/1.0.0",
27
+ },
28
+ });
29
+ if (!response.ok) {
30
+ const errorText = await response.text();
31
+ console.error(`❌ Failed to fetch models: ${response.status} ${response.statusText}`);
32
+ console.error(`❌ Error details: ${errorText}`);
33
+ throw new Error(`Failed to fetch models: ${response.status} ${response.statusText}`);
34
+ }
35
+ const data = (await response.json());
36
+ console.log(`✅ Fetched ${data.data.length} models from API`);
37
+ return data.data;
38
+ }
39
+ static async getAvailableModels(oauthToken) {
40
+ const tokenHash = this.hashToken(oauthToken);
41
+ const now = Date.now();
42
+ const cached = this.cache.get(tokenHash);
43
+ if (cached && cached.expiresAt > now) {
44
+ const remainingMinutes = Math.round((cached.expiresAt - now) / 60000);
45
+ console.log(`✅ Using cached models (expires in ${remainingMinutes} minutes)`);
46
+ return cached.models;
47
+ }
48
+ if (cached && now - cached.fetchedAt < this.MIN_REFRESH_INTERVAL_MS) {
49
+ const waitSeconds = Math.round((this.MIN_REFRESH_INTERVAL_MS - (now - cached.fetchedAt)) / 1000);
50
+ console.log(`⏰ Models fetched recently, using cache (min refresh interval: ${waitSeconds}s)`);
51
+ return cached.models;
52
+ }
53
+ try {
54
+ const models = await this.fetchModelsFromAPI(oauthToken);
55
+ this.cache.set(tokenHash, {
56
+ models,
57
+ fetchedAt: now,
58
+ expiresAt: now + this.CACHE_DURATION_MS,
59
+ tokenHash,
60
+ });
61
+ return models;
62
+ }
63
+ catch (error) {
64
+ console.error("❌ Failed to fetch models from API:", error);
65
+ if (cached) {
66
+ console.log("⚠️ Using expired cache as fallback");
67
+ return cached.models;
68
+ }
69
+ throw error;
70
+ }
71
+ }
72
+ static modelsToN8nOptions(models) {
73
+ return models.map((model) => {
74
+ const badges = [];
75
+ if (model.capabilities) {
76
+ const supports = model.capabilities.supports || {};
77
+ if (supports.streaming)
78
+ badges.push("🔄 Streaming");
79
+ if (supports.tool_calls)
80
+ badges.push("🔧 Tools");
81
+ if (supports.vision)
82
+ badges.push("👁️ Vision");
83
+ if (supports.structured_outputs)
84
+ badges.push("📋 Structured");
85
+ if (supports.parallel_tool_calls)
86
+ badges.push("⚡ Parallel");
87
+ if (supports.max_thinking_budget)
88
+ badges.push("🧠 Reasoning");
89
+ }
90
+ const displayName = model.display_name || model.name || model.id;
91
+ const badgesText = badges.length > 0 ? ` [${badges.join(" • ")}]` : "";
92
+ let description = "";
93
+ if (model.capabilities) {
94
+ const limits = model.capabilities.limits || {};
95
+ const parts = [];
96
+ if (limits.max_context_window_tokens) {
97
+ parts.push(`Context: ${(limits.max_context_window_tokens / 1000).toFixed(0)}k`);
98
+ }
99
+ if (limits.max_output_tokens) {
100
+ parts.push(`Output: ${(limits.max_output_tokens / 1000).toFixed(0)}k`);
101
+ }
102
+ if (model.vendor) {
103
+ parts.push(`Provider: ${model.vendor}`);
104
+ }
105
+ description = parts.join(" • ");
106
+ }
107
+ return {
108
+ name: `${displayName}${badgesText}`,
109
+ value: model.id,
110
+ description: description || undefined,
111
+ };
112
+ });
113
+ }
114
+ static clearCache(oauthToken) {
115
+ const tokenHash = this.hashToken(oauthToken);
116
+ this.cache.delete(tokenHash);
117
+ console.log("🗑️ Cleared models cache");
118
+ }
119
+ static clearAllCache() {
120
+ this.cache.clear();
121
+ console.log("🗑️ Cleared all models cache");
122
+ }
123
+ static getCacheInfo(oauthToken) {
124
+ const tokenHash = this.hashToken(oauthToken);
125
+ const cached = this.cache.get(tokenHash);
126
+ if (!cached) {
127
+ return null;
128
+ }
129
+ const now = Date.now();
130
+ return {
131
+ cached: true,
132
+ modelsCount: cached.models.length,
133
+ expiresIn: Math.max(0, cached.expiresAt - now),
134
+ fetchedAt: new Date(cached.fetchedAt).toISOString(),
135
+ };
136
+ }
137
+ }
138
+ exports.DynamicModelsManager = DynamicModelsManager;
139
+ DynamicModelsManager.cache = new Map();
140
+ DynamicModelsManager.CACHE_DURATION_MS = 60 * 60 * 1000;
141
+ DynamicModelsManager.MIN_REFRESH_INTERVAL_MS = 5 * 60 * 1000;
@@ -11,6 +11,7 @@ exports.validateTokenLimit = validateTokenLimit;
11
11
  exports.truncateToTokenLimit = truncateToTokenLimit;
12
12
  const GitHubCopilotEndpoints_1 = require("./GitHubCopilotEndpoints");
13
13
  const OAuthTokenManager_1 = require("./OAuthTokenManager");
14
+ const DynamicModelsManager_1 = require("./DynamicModelsManager");
14
15
  async function makeGitHubCopilotRequest(context, endpoint, body, hasMedia = false, retryConfig) {
15
16
  var _a, _b, _c;
16
17
  const MAX_RETRIES = (_a = retryConfig === null || retryConfig === void 0 ? void 0 : retryConfig.maxRetries) !== null && _a !== void 0 ? _a : 3;
@@ -37,6 +38,13 @@ async function makeGitHubCopilotRequest(context, endpoint, body, hasMedia = fals
37
38
  try {
38
39
  token = await OAuthTokenManager_1.OAuthTokenManager.getValidOAuthToken(githubToken);
39
40
  console.log(`✅ OAuth token ready (auto-generated from GitHub token)`);
41
+ DynamicModelsManager_1.DynamicModelsManager.getAvailableModels(token)
42
+ .then((models) => {
43
+ console.log(`✅ Models list updated: ${models.length} models available`);
44
+ })
45
+ .catch((error) => {
46
+ console.warn(`⚠️ Failed to update models list: ${error instanceof Error ? error.message : String(error)}`);
47
+ });
40
48
  }
41
49
  catch (error) {
42
50
  throw new Error(`Failed to generate OAuth token: ${error instanceof Error ? error.message : String(error)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-github-copilot",
3
- "version": "3.32.3",
3
+ "version": "3.35.0",
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",