@theia/ai-copilot 1.68.0-next.79

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 (83) hide show
  1. package/README.md +73 -0
  2. package/lib/browser/copilot-auth-dialog.d.ts +46 -0
  3. package/lib/browser/copilot-auth-dialog.d.ts.map +1 -0
  4. package/lib/browser/copilot-auth-dialog.js +246 -0
  5. package/lib/browser/copilot-auth-dialog.js.map +1 -0
  6. package/lib/browser/copilot-command-contribution.d.ts +22 -0
  7. package/lib/browser/copilot-command-contribution.d.ts.map +1 -0
  8. package/lib/browser/copilot-command-contribution.js +95 -0
  9. package/lib/browser/copilot-command-contribution.js.map +1 -0
  10. package/lib/browser/copilot-frontend-application-contribution.d.ts +15 -0
  11. package/lib/browser/copilot-frontend-application-contribution.d.ts.map +1 -0
  12. package/lib/browser/copilot-frontend-application-contribution.js +90 -0
  13. package/lib/browser/copilot-frontend-application-contribution.js.map +1 -0
  14. package/lib/browser/copilot-frontend-module.d.ts +5 -0
  15. package/lib/browser/copilot-frontend-module.d.ts.map +1 -0
  16. package/lib/browser/copilot-frontend-module.js +69 -0
  17. package/lib/browser/copilot-frontend-module.js.map +1 -0
  18. package/lib/browser/copilot-status-bar-contribution.d.ts +18 -0
  19. package/lib/browser/copilot-status-bar-contribution.d.ts.map +1 -0
  20. package/lib/browser/copilot-status-bar-contribution.js +92 -0
  21. package/lib/browser/copilot-status-bar-contribution.js.map +1 -0
  22. package/lib/browser/index.d.ts +5 -0
  23. package/lib/browser/index.d.ts.map +1 -0
  24. package/lib/browser/index.js +23 -0
  25. package/lib/browser/index.js.map +1 -0
  26. package/lib/common/copilot-auth-service.d.ts +77 -0
  27. package/lib/common/copilot-auth-service.d.ts.map +1 -0
  28. package/lib/common/copilot-auth-service.js +22 -0
  29. package/lib/common/copilot-auth-service.js.map +1 -0
  30. package/lib/common/copilot-language-models-manager.d.ts +41 -0
  31. package/lib/common/copilot-language-models-manager.d.ts.map +1 -0
  32. package/lib/common/copilot-language-models-manager.js +22 -0
  33. package/lib/common/copilot-language-models-manager.js.map +1 -0
  34. package/lib/common/copilot-preferences.d.ts +5 -0
  35. package/lib/common/copilot-preferences.d.ts.map +1 -0
  36. package/lib/common/copilot-preferences.js +52 -0
  37. package/lib/common/copilot-preferences.js.map +1 -0
  38. package/lib/common/index.d.ts +4 -0
  39. package/lib/common/index.d.ts.map +1 -0
  40. package/lib/common/index.js +22 -0
  41. package/lib/common/index.js.map +1 -0
  42. package/lib/node/copilot-auth-service-impl.d.ts +28 -0
  43. package/lib/node/copilot-auth-service-impl.d.ts.map +1 -0
  44. package/lib/node/copilot-auth-service-impl.js +229 -0
  45. package/lib/node/copilot-auth-service-impl.js.map +1 -0
  46. package/lib/node/copilot-backend-module.d.ts +4 -0
  47. package/lib/node/copilot-backend-module.d.ts.map +1 -0
  48. package/lib/node/copilot-backend-module.js +39 -0
  49. package/lib/node/copilot-backend-module.js.map +1 -0
  50. package/lib/node/copilot-language-model.d.ts +33 -0
  51. package/lib/node/copilot-language-model.d.ts.map +1 -0
  52. package/lib/node/copilot-language-model.js +217 -0
  53. package/lib/node/copilot-language-model.js.map +1 -0
  54. package/lib/node/copilot-language-models-manager-impl.d.ts +23 -0
  55. package/lib/node/copilot-language-models-manager-impl.d.ts.map +1 -0
  56. package/lib/node/copilot-language-models-manager-impl.js +113 -0
  57. package/lib/node/copilot-language-models-manager-impl.js.map +1 -0
  58. package/lib/node/index.d.ts +4 -0
  59. package/lib/node/index.d.ts.map +1 -0
  60. package/lib/node/index.js +22 -0
  61. package/lib/node/index.js.map +1 -0
  62. package/lib/package.spec.d.ts +1 -0
  63. package/lib/package.spec.d.ts.map +1 -0
  64. package/lib/package.spec.js +26 -0
  65. package/lib/package.spec.js.map +1 -0
  66. package/package.json +52 -0
  67. package/src/browser/copilot-auth-dialog.tsx +326 -0
  68. package/src/browser/copilot-command-contribution.ts +93 -0
  69. package/src/browser/copilot-frontend-application-contribution.ts +89 -0
  70. package/src/browser/copilot-frontend-module.ts +86 -0
  71. package/src/browser/copilot-status-bar-contribution.ts +88 -0
  72. package/src/browser/index.ts +20 -0
  73. package/src/browser/style/index.css +167 -0
  74. package/src/common/copilot-auth-service.ts +103 -0
  75. package/src/common/copilot-language-models-manager.ts +59 -0
  76. package/src/common/copilot-preferences.ts +53 -0
  77. package/src/common/index.ts +19 -0
  78. package/src/node/copilot-auth-service-impl.ts +274 -0
  79. package/src/node/copilot-backend-module.ts +58 -0
  80. package/src/node/copilot-language-model.ts +262 -0
  81. package/src/node/copilot-language-models-manager-impl.ts +118 -0
  82. package/src/node/index.ts +19 -0
  83. package/src/package.spec.ts +27 -0
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2026 EclipseSource GmbH.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.CopilotAuthServiceImpl = void 0;
19
+ const tslib_1 = require("tslib");
20
+ const inversify_1 = require("@theia/core/shared/inversify");
21
+ const core_1 = require("@theia/core");
22
+ const key_store_1 = require("@theia/core/lib/common/key-store");
23
+ const COPILOT_CLIENT_ID = 'Iv23ctNZvWb5IGBKdyPY';
24
+ const COPILOT_SCOPE = 'read:user';
25
+ const COPILOT_GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:device_code';
26
+ const KEYSTORE_SERVICE = 'theia-copilot-auth';
27
+ const KEYSTORE_ACCOUNT = 'github-copilot';
28
+ const USER_AGENT = 'Theia-Copilot/1.0.0';
29
+ /**
30
+ * Maximum number of polling attempts for token retrieval.
31
+ * With a default 5-second interval, this allows approximately 5 minutes of polling.
32
+ */
33
+ const MAX_POLLING_ATTEMPTS = 60;
34
+ /**
35
+ * Backend implementation of the GitHub Copilot OAuth Device Flow authentication service.
36
+ * Handles device code generation, token polling, and credential storage.
37
+ */
38
+ let CopilotAuthServiceImpl = class CopilotAuthServiceImpl {
39
+ constructor() {
40
+ this.onAuthStateChangedEmitter = new core_1.Emitter();
41
+ this.onAuthStateChanged = this.onAuthStateChangedEmitter.event;
42
+ }
43
+ setClient(client) {
44
+ this.client = client;
45
+ }
46
+ getOAuthEndpoints(enterpriseUrl) {
47
+ if (enterpriseUrl) {
48
+ const domain = enterpriseUrl
49
+ .replace(/^https?:\/\//, '')
50
+ .replace(/\/$/, '');
51
+ return {
52
+ deviceCodeUrl: `https://${domain}/login/device/code`,
53
+ accessTokenUrl: `https://${domain}/login/oauth/access_token`
54
+ };
55
+ }
56
+ return {
57
+ deviceCodeUrl: 'https://github.com/login/device/code',
58
+ accessTokenUrl: 'https://github.com/login/oauth/access_token'
59
+ };
60
+ }
61
+ async initiateDeviceFlow(enterpriseUrl) {
62
+ const endpoints = this.getOAuthEndpoints(enterpriseUrl);
63
+ const response = await fetch(endpoints.deviceCodeUrl, {
64
+ method: 'POST',
65
+ headers: {
66
+ 'Accept': 'application/json',
67
+ 'Content-Type': 'application/json',
68
+ 'User-Agent': USER_AGENT
69
+ },
70
+ body: JSON.stringify({
71
+ client_id: COPILOT_CLIENT_ID,
72
+ scope: COPILOT_SCOPE
73
+ })
74
+ });
75
+ if (!response.ok) {
76
+ const errorText = await response.text();
77
+ throw new Error(`Failed to initiate device authorization: ${response.status} - ${errorText}`);
78
+ }
79
+ const data = await response.json();
80
+ return data;
81
+ }
82
+ async pollForToken(deviceCode, interval, enterpriseUrl) {
83
+ const endpoints = this.getOAuthEndpoints(enterpriseUrl);
84
+ let attempts = 0;
85
+ while (attempts < MAX_POLLING_ATTEMPTS) {
86
+ await this.delay(interval * 1000);
87
+ attempts++;
88
+ const response = await fetch(endpoints.accessTokenUrl, {
89
+ method: 'POST',
90
+ headers: {
91
+ 'Accept': 'application/json',
92
+ 'Content-Type': 'application/json',
93
+ 'User-Agent': USER_AGENT
94
+ },
95
+ body: JSON.stringify({
96
+ client_id: COPILOT_CLIENT_ID,
97
+ device_code: deviceCode,
98
+ grant_type: COPILOT_GRANT_TYPE
99
+ })
100
+ });
101
+ if (!response.ok) {
102
+ console.error(`Token request failed: ${response.status}`);
103
+ continue;
104
+ }
105
+ const data = await response.json();
106
+ if (data.access_token) {
107
+ // Get user info for account label
108
+ const accountLabel = await this.fetchAccountLabel(data.access_token, enterpriseUrl);
109
+ // Store credentials
110
+ const credentials = {
111
+ accessToken: data.access_token,
112
+ accountLabel,
113
+ enterpriseUrl
114
+ };
115
+ await this.keyStoreService.setPassword(KEYSTORE_SERVICE, KEYSTORE_ACCOUNT, JSON.stringify(credentials));
116
+ // Update cached state and notify
117
+ const newState = {
118
+ isAuthenticated: true,
119
+ accountLabel,
120
+ enterpriseUrl
121
+ };
122
+ this.updateAuthState(newState);
123
+ return true;
124
+ }
125
+ if (data.error === 'authorization_pending') {
126
+ // User hasn't authorized yet, continue polling
127
+ continue;
128
+ }
129
+ if (data.error === 'slow_down') {
130
+ // Increase polling interval
131
+ interval += 5;
132
+ continue;
133
+ }
134
+ if (data.error === 'expired_token' || data.error === 'access_denied') {
135
+ console.error(`Authorization failed: ${data.error} - ${data.error_description}`);
136
+ return false;
137
+ }
138
+ if (data.error) {
139
+ console.error(`Unexpected error: ${data.error} - ${data.error_description}`);
140
+ return false;
141
+ }
142
+ }
143
+ return false;
144
+ }
145
+ async fetchAccountLabel(accessToken, enterpriseUrl) {
146
+ try {
147
+ const apiBaseUrl = enterpriseUrl
148
+ ? `https://${enterpriseUrl.replace(/^https?:\/\//, '').replace(/\/$/, '')}/api/v3`
149
+ : 'https://api.github.com';
150
+ const response = await fetch(`${apiBaseUrl}/user`, {
151
+ headers: {
152
+ 'Authorization': `Bearer ${accessToken}`,
153
+ 'User-Agent': USER_AGENT,
154
+ 'Accept': 'application/vnd.github.v3+json'
155
+ }
156
+ });
157
+ if (response.ok) {
158
+ const userData = await response.json();
159
+ return userData.login;
160
+ }
161
+ }
162
+ catch (error) {
163
+ console.warn('Failed to fetch GitHub user info:', error);
164
+ }
165
+ return undefined;
166
+ }
167
+ async getAuthState() {
168
+ if (this.cachedState) {
169
+ return this.cachedState;
170
+ }
171
+ try {
172
+ const stored = await this.keyStoreService.getPassword(KEYSTORE_SERVICE, KEYSTORE_ACCOUNT);
173
+ if (stored) {
174
+ const credentials = JSON.parse(stored);
175
+ this.cachedState = {
176
+ isAuthenticated: true,
177
+ accountLabel: credentials.accountLabel,
178
+ enterpriseUrl: credentials.enterpriseUrl
179
+ };
180
+ return this.cachedState;
181
+ }
182
+ }
183
+ catch (error) {
184
+ console.warn('Failed to retrieve Copilot credentials:', error);
185
+ }
186
+ this.cachedState = { isAuthenticated: false };
187
+ return this.cachedState;
188
+ }
189
+ async getAccessToken() {
190
+ try {
191
+ const stored = await this.keyStoreService.getPassword(KEYSTORE_SERVICE, KEYSTORE_ACCOUNT);
192
+ if (stored) {
193
+ const credentials = JSON.parse(stored);
194
+ return credentials.accessToken;
195
+ }
196
+ }
197
+ catch (error) {
198
+ console.warn('Failed to retrieve Copilot access token:', error);
199
+ }
200
+ return undefined;
201
+ }
202
+ async signOut() {
203
+ try {
204
+ await this.keyStoreService.deletePassword(KEYSTORE_SERVICE, KEYSTORE_ACCOUNT);
205
+ }
206
+ catch (error) {
207
+ console.warn('Failed to delete Copilot credentials:', error);
208
+ }
209
+ const newState = { isAuthenticated: false };
210
+ this.updateAuthState(newState);
211
+ }
212
+ updateAuthState(state) {
213
+ this.cachedState = state;
214
+ this.onAuthStateChangedEmitter.fire(state);
215
+ this.client?.onAuthStateChanged(state);
216
+ }
217
+ delay(ms) {
218
+ return new Promise(resolve => setTimeout(resolve, ms));
219
+ }
220
+ };
221
+ exports.CopilotAuthServiceImpl = CopilotAuthServiceImpl;
222
+ tslib_1.__decorate([
223
+ (0, inversify_1.inject)(key_store_1.KeyStoreService),
224
+ tslib_1.__metadata("design:type", Object)
225
+ ], CopilotAuthServiceImpl.prototype, "keyStoreService", void 0);
226
+ exports.CopilotAuthServiceImpl = CopilotAuthServiceImpl = tslib_1.__decorate([
227
+ (0, inversify_1.injectable)()
228
+ ], CopilotAuthServiceImpl);
229
+ //# sourceMappingURL=copilot-auth-service-impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot-auth-service-impl.js","sourceRoot":"","sources":["../../src/node/copilot-auth-service-impl.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAEhF,4DAAkE;AAClE,sCAA6C;AAC7C,gEAAmE;AAQnE,MAAM,iBAAiB,GAAG,sBAAsB,CAAC;AACjD,MAAM,aAAa,GAAG,WAAW,CAAC;AAClC,MAAM,kBAAkB,GAAG,8CAA8C,CAAC;AAC1E,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAC9C,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;AAC1C,MAAM,UAAU,GAAG,qBAAqB,CAAC;AAEzC;;;GAGG;AACH,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAQhC;;;GAGG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAA5B;QAQgB,8BAAyB,GAAG,IAAI,cAAO,EAAoB,CAAC;QACtE,uBAAkB,GAA4B,IAAI,CAAC,yBAAyB,CAAC,KAAK,CAAC;IAsNhG,CAAC;IApNG,SAAS,CAAC,MA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0 +1,4 @@
1
+ import { ContainerModule } from '@theia/core/shared/inversify';
2
+ declare const _default: ContainerModule;
3
+ export default _default;
4
+ //# sourceMappingURL=copilot-backend-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot-backend-module.d.ts","sourceRoot":"","sources":["../../src/node/copilot-backend-module.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AAuC/D,wBAEG"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2026 EclipseSource GmbH.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const inversify_1 = require("@theia/core/shared/inversify");
19
+ const core_1 = require("@theia/core");
20
+ const connection_container_module_1 = require("@theia/core/lib/node/messaging/connection-container-module");
21
+ const common_1 = require("../common");
22
+ const copilot_language_models_manager_impl_1 = require("./copilot-language-models-manager-impl");
23
+ const copilot_auth_service_impl_1 = require("./copilot-auth-service-impl");
24
+ const copilotConnectionModule = connection_container_module_1.ConnectionContainerModule.create(({ bind }) => {
25
+ bind(copilot_auth_service_impl_1.CopilotAuthServiceImpl).toSelf().inSingletonScope();
26
+ bind(common_1.CopilotAuthService).toService(copilot_auth_service_impl_1.CopilotAuthServiceImpl);
27
+ bind(copilot_language_models_manager_impl_1.CopilotLanguageModelsManagerImpl).toSelf().inSingletonScope();
28
+ bind(common_1.CopilotLanguageModelsManager).toService(copilot_language_models_manager_impl_1.CopilotLanguageModelsManagerImpl);
29
+ bind(core_1.ConnectionHandler).toDynamicValue(ctx => new core_1.RpcConnectionHandler(common_1.COPILOT_AUTH_SERVICE_PATH, client => {
30
+ const authService = ctx.container.get(common_1.CopilotAuthService);
31
+ authService.setClient(client);
32
+ return authService;
33
+ })).inSingletonScope();
34
+ bind(core_1.ConnectionHandler).toDynamicValue(ctx => new core_1.RpcConnectionHandler(common_1.COPILOT_LANGUAGE_MODELS_MANAGER_PATH, () => ctx.container.get(common_1.CopilotLanguageModelsManager))).inSingletonScope();
35
+ });
36
+ exports.default = new inversify_1.ContainerModule(bind => {
37
+ bind(connection_container_module_1.ConnectionContainerModule).toConstantValue(copilotConnectionModule);
38
+ });
39
+ //# sourceMappingURL=copilot-backend-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot-backend-module.js","sourceRoot":"","sources":["../../src/node/copilot-backend-module.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,4DAA+D;AAC/D,sCAAsE;AACtE,4GAAuG;AACvG,sCAMmB;AACnB,iGAA0F;AAC1F,2EAAqE;AAErE,MAAM,uBAAuB,GAAG,uDAAyB,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;IAC1E,IAAI,CAAC,kDAAsB,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACzD,IAAI,CAAC,2BAAkB,CAAC,CAAC,SAAS,CAAC,kDAAsB,CAAC,CAAC;IAE3D,IAAI,CAAC,uEAAgC,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACnE,IAAI,CAAC,qCAA4B,CAAC,CAAC,SAAS,CAAC,uEAAgC,CAAC,CAAC;IAE/E,IAAI,CAAC,wBAAiB,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CACzC,IAAI,2BAAoB,CACpB,kCAAyB,EACzB,MAAM,CAAC,EAAE;QACL,MAAM,WAAW,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAAyB,2BAAkB,CAAC,CAAC;QAClF,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC9B,OAAO,WAAW,CAAC;IACvB,CAAC,CACJ,CACJ,CAAC,gBAAgB,EAAE,CAAC;IAErB,IAAI,CAAC,wBAAiB,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CACzC,IAAI,2BAAoB,CACpB,6CAAoC,EACpC,GAAG,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,qCAA4B,CAAC,CACxD,CACJ,CAAC,gBAAgB,EAAE,CAAC;AACzB,CAAC,CAAC,CAAC;AAEH,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,uDAAyB,CAAC,CAAC,eAAe,CAAC,uBAAuB,CAAC,CAAC;AAC7E,CAAC,CAAC,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { LanguageModel, LanguageModelMessage, LanguageModelParsedResponse, LanguageModelRequest, LanguageModelResponse, LanguageModelStatus, LanguageModelTextResponse, TokenUsageService, UserRequest } from '@theia/ai-core';
2
+ import { CancellationToken } from '@theia/core';
3
+ import OpenAI from 'openai';
4
+ import { RunnableToolFunctionWithoutParse } from 'openai/lib/RunnableFunction';
5
+ import { ChatCompletionMessageParam } from 'openai/resources';
6
+ import type { RunnerOptions } from 'openai/lib/AbstractChatCompletionRunner';
7
+ /**
8
+ * Language model implementation for GitHub Copilot.
9
+ * Uses the OpenAI SDK to communicate with the Copilot API.
10
+ */
11
+ export declare class CopilotLanguageModel implements LanguageModel {
12
+ readonly id: string;
13
+ model: string;
14
+ status: LanguageModelStatus;
15
+ enableStreaming: boolean;
16
+ supportsStructuredOutput: boolean;
17
+ maxRetries: number;
18
+ protected readonly accessTokenProvider: () => Promise<string | undefined>;
19
+ protected readonly enterpriseUrlProvider: () => string | undefined;
20
+ protected readonly tokenUsageService?: TokenUsageService | undefined;
21
+ protected runnerOptions: RunnerOptions;
22
+ constructor(id: string, model: string, status: LanguageModelStatus, enableStreaming: boolean, supportsStructuredOutput: boolean, maxRetries: number, accessTokenProvider: () => Promise<string | undefined>, enterpriseUrlProvider: () => string | undefined, tokenUsageService?: TokenUsageService | undefined);
23
+ protected getSettings(request: LanguageModelRequest): Record<string, unknown>;
24
+ request(request: UserRequest, cancellationToken?: CancellationToken): Promise<LanguageModelResponse>;
25
+ protected handleNonStreamingRequest(openai: OpenAI, request: UserRequest): Promise<LanguageModelTextResponse>;
26
+ protected handleStructuredOutputRequest(openai: OpenAI, request: UserRequest): Promise<LanguageModelParsedResponse>;
27
+ protected createTools(request: LanguageModelRequest): RunnableToolFunctionWithoutParse[] | undefined;
28
+ protected initializeCopilotClient(): Promise<OpenAI>;
29
+ protected processMessages(messages: LanguageModelMessage[]): ChatCompletionMessageParam[];
30
+ protected toOpenAIMessage(message: LanguageModelMessage): ChatCompletionMessageParam;
31
+ protected toOpenAiRole(message: LanguageModelMessage): 'developer' | 'user' | 'assistant' | 'system';
32
+ }
33
+ //# sourceMappingURL=copilot-language-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot-language-model.d.ts","sourceRoot":"","sources":["../../src/node/copilot-language-model.ts"],"names":[],"mappings":"AAgBA,OAAO,EAEH,aAAa,EACb,oBAAoB,EACpB,2BAA2B,EAC3B,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EACjB,WAAW,EACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OA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AAC,yBAAyB,CAAC;cA0BnG,6BAA6B,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,2BAA2B,CAAC;IA+BzH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,oBAAoB,GAAG,gCAAgC,EAAE,GAAG,SAAS;cAYpF,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC;IAsB1D,SAAS,CAAC,eAAe,CAAC,QAAQ,EAAE,oBAAoB,EAAE,GAAG,0BAA0B,EAAE;IAIzF,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,oBAAoB,GAAG,0BAA0B;IA2CpF,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,oBAAoB,GAAG,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ;CAQvG"}
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2026 EclipseSource GmbH.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.CopilotLanguageModel = void 0;
19
+ const ai_core_1 = require("@theia/ai-core");
20
+ const openai_1 = require("openai");
21
+ const openai_streaming_iterator_1 = require("@theia/ai-openai/lib/node/openai-streaming-iterator");
22
+ const common_1 = require("../common");
23
+ const COPILOT_API_BASE_URL = 'https://api.githubcopilot.com';
24
+ const USER_AGENT = 'Theia-Copilot/1.0.0';
25
+ /**
26
+ * Language model implementation for GitHub Copilot.
27
+ * Uses the OpenAI SDK to communicate with the Copilot API.
28
+ */
29
+ class CopilotLanguageModel {
30
+ constructor(id, model, status, enableStreaming, supportsStructuredOutput, maxRetries, accessTokenProvider, enterpriseUrlProvider, tokenUsageService) {
31
+ this.id = id;
32
+ this.model = model;
33
+ this.status = status;
34
+ this.enableStreaming = enableStreaming;
35
+ this.supportsStructuredOutput = supportsStructuredOutput;
36
+ this.maxRetries = maxRetries;
37
+ this.accessTokenProvider = accessTokenProvider;
38
+ this.enterpriseUrlProvider = enterpriseUrlProvider;
39
+ this.tokenUsageService = tokenUsageService;
40
+ this.runnerOptions = {
41
+ maxChatCompletions: 100
42
+ };
43
+ }
44
+ getSettings(request) {
45
+ return request.settings ?? {};
46
+ }
47
+ async request(request, cancellationToken) {
48
+ const openai = await this.initializeCopilotClient();
49
+ if (request.response_format?.type === 'json_schema' && this.supportsStructuredOutput) {
50
+ return this.handleStructuredOutputRequest(openai, request);
51
+ }
52
+ const settings = this.getSettings(request);
53
+ if (!this.enableStreaming || (typeof settings.stream === 'boolean' && !settings.stream)) {
54
+ return this.handleNonStreamingRequest(openai, request);
55
+ }
56
+ if (cancellationToken?.isCancellationRequested) {
57
+ return { text: '' };
58
+ }
59
+ if (this.id.startsWith(`${common_1.COPILOT_PROVIDER_ID}/`)) {
60
+ settings['stream_options'] = { include_usage: true };
61
+ }
62
+ let runner;
63
+ const tools = this.createTools(request);
64
+ if (tools) {
65
+ runner = openai.chat.completions.runTools({
66
+ model: this.model,
67
+ messages: this.processMessages(request.messages),
68
+ stream: true,
69
+ tools: tools,
70
+ tool_choice: 'auto',
71
+ ...settings
72
+ }, {
73
+ ...this.runnerOptions,
74
+ maxRetries: this.maxRetries
75
+ });
76
+ }
77
+ else {
78
+ runner = openai.chat.completions.stream({
79
+ model: this.model,
80
+ messages: this.processMessages(request.messages),
81
+ stream: true,
82
+ ...settings
83
+ });
84
+ }
85
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
86
+ return { stream: new openai_streaming_iterator_1.StreamingAsyncIterator(runner, request.requestId, cancellationToken, this.tokenUsageService, this.id) };
87
+ }
88
+ async handleNonStreamingRequest(openai, request) {
89
+ const settings = this.getSettings(request);
90
+ const response = await openai.chat.completions.create({
91
+ model: this.model,
92
+ messages: this.processMessages(request.messages),
93
+ ...settings
94
+ });
95
+ const message = response.choices[0].message;
96
+ if (this.tokenUsageService && response.usage) {
97
+ await this.tokenUsageService.recordTokenUsage(this.id, {
98
+ inputTokens: response.usage.prompt_tokens,
99
+ outputTokens: response.usage.completion_tokens,
100
+ requestId: request.requestId
101
+ });
102
+ }
103
+ return {
104
+ text: message.content ?? ''
105
+ };
106
+ }
107
+ async handleStructuredOutputRequest(openai, request) {
108
+ const settings = this.getSettings(request);
109
+ const result = await openai.chat.completions.parse({
110
+ model: this.model,
111
+ messages: this.processMessages(request.messages),
112
+ response_format: request.response_format,
113
+ ...settings
114
+ });
115
+ const message = result.choices[0].message;
116
+ if (message.refusal || message.parsed === undefined) {
117
+ console.error('Error in Copilot chat completion:', JSON.stringify(message));
118
+ }
119
+ if (this.tokenUsageService && result.usage) {
120
+ await this.tokenUsageService.recordTokenUsage(this.id, {
121
+ inputTokens: result.usage.prompt_tokens,
122
+ outputTokens: result.usage.completion_tokens,
123
+ requestId: request.requestId
124
+ });
125
+ }
126
+ return {
127
+ content: message.content ?? '',
128
+ parsed: message.parsed
129
+ };
130
+ }
131
+ createTools(request) {
132
+ return request.tools?.map(tool => ({
133
+ type: 'function',
134
+ function: {
135
+ name: tool.name,
136
+ description: tool.description,
137
+ parameters: tool.parameters,
138
+ function: (args_string) => tool.handler(args_string)
139
+ }
140
+ }));
141
+ }
142
+ async initializeCopilotClient() {
143
+ const accessToken = await this.accessTokenProvider();
144
+ if (!accessToken) {
145
+ throw new Error('Not authenticated with GitHub Copilot. Please sign in first.');
146
+ }
147
+ const enterpriseUrl = this.enterpriseUrlProvider();
148
+ const baseURL = enterpriseUrl
149
+ ? `https://copilot-api.${enterpriseUrl.replace(/^https?:\/\//, '').replace(/\/$/, '')}`
150
+ : COPILOT_API_BASE_URL;
151
+ return new openai_1.default({
152
+ apiKey: accessToken,
153
+ baseURL,
154
+ defaultHeaders: {
155
+ 'User-Agent': USER_AGENT,
156
+ 'Openai-Intent': 'conversation-edits',
157
+ 'X-Initiator': 'user'
158
+ }
159
+ });
160
+ }
161
+ processMessages(messages) {
162
+ return messages.filter(m => m.type !== 'thinking').map(m => this.toOpenAIMessage(m));
163
+ }
164
+ toOpenAIMessage(message) {
165
+ if (ai_core_1.LanguageModelMessage.isTextMessage(message)) {
166
+ return {
167
+ role: this.toOpenAiRole(message),
168
+ content: message.text
169
+ };
170
+ }
171
+ if (ai_core_1.LanguageModelMessage.isToolUseMessage(message)) {
172
+ return {
173
+ role: 'assistant',
174
+ tool_calls: [{
175
+ id: message.id,
176
+ function: {
177
+ name: message.name,
178
+ arguments: JSON.stringify(message.input)
179
+ },
180
+ type: 'function'
181
+ }]
182
+ };
183
+ }
184
+ if (ai_core_1.LanguageModelMessage.isToolResultMessage(message)) {
185
+ return {
186
+ role: 'tool',
187
+ tool_call_id: message.tool_use_id,
188
+ content: typeof message.content === 'string' ? message.content : JSON.stringify(message.content)
189
+ };
190
+ }
191
+ if (ai_core_1.LanguageModelMessage.isImageMessage(message) && message.actor === 'user') {
192
+ return {
193
+ role: 'user',
194
+ content: [{
195
+ type: 'image_url',
196
+ image_url: {
197
+ url: ai_core_1.ImageContent.isBase64(message.image)
198
+ ? `data:${message.image.mimeType};base64,${message.image.base64data}`
199
+ : message.image.url
200
+ }
201
+ }]
202
+ };
203
+ }
204
+ throw new Error(`Unknown message type: '${JSON.stringify(message)}'`);
205
+ }
206
+ toOpenAiRole(message) {
207
+ if (message.actor === 'system') {
208
+ return 'developer';
209
+ }
210
+ else if (message.actor === 'ai') {
211
+ return 'assistant';
212
+ }
213
+ return 'user';
214
+ }
215
+ }
216
+ exports.CopilotLanguageModel = CopilotLanguageModel;
217
+ //# sourceMappingURL=copilot-language-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot-language-model.js","sourceRoot":"","sources":["../../src/node/copilot-language-model.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAEhF,4CAWwB;AAExB,mCAA4B;AAG5B,mGAA6F;AAC7F,sCAAgD;AAIhD,MAAM,oBAAoB,GAAG,+BAA+B,CAAC;AAC7D,MAAM,UAAU,GAAG,qBAAqB,CAAC;AAEzC;;;GAGG;AACH,MAAa,oBAAoB;IAM7B,YACoB,EAAU,EACnB,KAAa,EACb,MAA2B,EAC3B,eAAwB,EACxB,wBAAiC,EACjC,UAAkB,EACN,mBAAsD,EACtD,qBAA+C,EAC/C,iBAAqC;QARxC,OAAE,GAAF,EAAE,CAAQ;QACnB,UAAK,GAAL,KAAK,CAAQ;QACb,WAAM,GAAN,MAAM,CAAqB;QAC3B,oBAAe,GAAf,eAAe,CAAS;QACxB,6BAAwB,GAAxB,wBAAwB,CAAS;QACjC,eAAU,GAAV,UAAU,CAAQ;QACN,wBAAmB,GAAnB,mBAAmB,CAAmC;QACtD,0BAAqB,GAArB,qBAAqB,CAA0B;QAC/C,sBAAiB,GAAjB,iBAAiB,CAAoB;QAblD,kBAAa,GAAkB;YACrC,kBAAkB,EAAE,GAAG;SAC1B,CAAC;IAYE,CAAC;IAEK,WAAW,CAAC,OAA6B;QAC/C,OAAO,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAoB,EAAE,iBAAqC;QACrE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAEpD,IAAI,OAAO,CAAC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K,CAAC,0BAA0B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1E,CAAC;IAES,YAAY,CAAC,OAA6B;QAChD,IAAI,OAAO,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO,WAAW,CAAC;QACvB,CAAC;aAAM,IAAI,OAAO,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;YAChC,OAAO,WAAW,CAAC;QACvB,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAzND,oDAyNC"}
@@ -0,0 +1,23 @@
1
+ import { LanguageModelRegistry, LanguageModelStatus, TokenUsageService } from '@theia/ai-core';
2
+ import { Disposable, DisposableCollection } from '@theia/core';
3
+ import { CopilotLanguageModelsManager, CopilotModelDescription } from '../common';
4
+ import { CopilotAuthServiceImpl } from './copilot-auth-service-impl';
5
+ /**
6
+ * Backend implementation of the Copilot language models manager.
7
+ * Manages registration and lifecycle of Copilot language models in the AI language model registry.
8
+ */
9
+ export declare class CopilotLanguageModelsManagerImpl implements CopilotLanguageModelsManager, Disposable {
10
+ protected readonly languageModelRegistry: LanguageModelRegistry;
11
+ protected readonly tokenUsageService: TokenUsageService;
12
+ protected readonly authService: CopilotAuthServiceImpl;
13
+ protected enterpriseUrl: string | undefined;
14
+ protected readonly toDispose: DisposableCollection;
15
+ protected init(): void;
16
+ dispose(): void;
17
+ setEnterpriseUrl(url: string | undefined): void;
18
+ protected calculateStatus(): Promise<LanguageModelStatus>;
19
+ createOrUpdateLanguageModels(...modelDescriptions: CopilotModelDescription[]): Promise<void>;
20
+ removeLanguageModels(...modelIds: string[]): void;
21
+ refreshModelsStatus(): Promise<void>;
22
+ }
23
+ //# sourceMappingURL=copilot-language-models-manager-impl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot-language-models-manager-impl.d.ts","sourceRoot":"","sources":["../../src/node/copilot-language-models-manager-impl.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC/F,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,EAAE,4BAA4B,EAAE,uBAAuB,EAAuB,MAAM,WAAW,CAAC;AAEvG,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE;;;GAGG;AACH,qBACa,gCAAiC,YAAW,4BAA4B,EAAE,UAAU;IAG7F,SAAS,CAAC,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IAGhE,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAGxD,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,sBAAsB,CAAC;IAEvD,SAAS,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5C,SAAS,CAAC,QAAQ,CAAC,SAAS,uBAA8B;IAG1D,SAAS,CAAC,IAAI,IAAI,IAAI;IAMtB,OAAO,IAAI,IAAI;IAIf,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;cAI/B,eAAe,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAQzD,4BAA4B,CAAC,GAAG,iBAAiB,EAAE,uBAAuB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAoClG,oBAAoB,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI;IAI3C,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;CAY7C"}