@theia/ai-copilot 1.75.0 → 1.76.0-next.10

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 (150) hide show
  1. package/README.md +86 -14
  2. package/lib/browser/copilot-auth-dialog.d.ts.map +1 -1
  3. package/lib/browser/copilot-auth-dialog.js +12 -4
  4. package/lib/browser/copilot-auth-dialog.js.map +1 -1
  5. package/lib/browser/copilot-frontend-application-contribution.d.ts +15 -1
  6. package/lib/browser/copilot-frontend-application-contribution.d.ts.map +1 -1
  7. package/lib/browser/copilot-frontend-application-contribution.js +52 -24
  8. package/lib/browser/copilot-frontend-application-contribution.js.map +1 -1
  9. package/lib/common/copilot-auth-service.d.ts +27 -24
  10. package/lib/common/copilot-auth-service.d.ts.map +1 -1
  11. package/lib/common/copilot-language-models-manager.d.ts +3 -21
  12. package/lib/common/copilot-language-models-manager.d.ts.map +1 -1
  13. package/lib/common/copilot-language-models-manager.js +1 -13
  14. package/lib/common/copilot-language-models-manager.js.map +1 -1
  15. package/lib/common/copilot-preferences.d.ts +1 -0
  16. package/lib/common/copilot-preferences.d.ts.map +1 -1
  17. package/lib/common/copilot-preferences.js +24 -6
  18. package/lib/common/copilot-preferences.js.map +1 -1
  19. package/lib/common/index.d.ts +0 -1
  20. package/lib/common/index.d.ts.map +1 -1
  21. package/lib/common/index.js +0 -1
  22. package/lib/common/index.js.map +1 -1
  23. package/lib/node/copilot-auth-service-impl.d.ts +25 -16
  24. package/lib/node/copilot-auth-service-impl.d.ts.map +1 -1
  25. package/lib/node/copilot-auth-service-impl.js +67 -183
  26. package/lib/node/copilot-auth-service-impl.js.map +1 -1
  27. package/lib/node/copilot-auth-service-impl.spec.js +104 -168
  28. package/lib/node/copilot-auth-service-impl.spec.js.map +1 -1
  29. package/lib/node/copilot-backend-module.d.ts.map +1 -1
  30. package/lib/node/copilot-backend-module.js +10 -2
  31. package/lib/node/copilot-backend-module.js.map +1 -1
  32. package/lib/node/copilot-cli-auth-provider.d.ts +146 -0
  33. package/lib/node/copilot-cli-auth-provider.d.ts.map +1 -0
  34. package/lib/node/copilot-cli-auth-provider.js +430 -0
  35. package/lib/node/copilot-cli-auth-provider.js.map +1 -0
  36. package/lib/node/copilot-cli-auth-provider.spec.d.ts +2 -0
  37. package/lib/node/copilot-cli-auth-provider.spec.d.ts.map +1 -0
  38. package/lib/node/copilot-cli-auth-provider.spec.js +249 -0
  39. package/lib/node/copilot-cli-auth-provider.spec.js.map +1 -0
  40. package/lib/node/copilot-cli-locator.d.ts +120 -0
  41. package/lib/node/copilot-cli-locator.d.ts.map +1 -0
  42. package/lib/node/copilot-cli-locator.js +348 -0
  43. package/lib/node/copilot-cli-locator.js.map +1 -0
  44. package/lib/node/copilot-cli-locator.spec.d.ts +2 -0
  45. package/lib/node/copilot-cli-locator.spec.d.ts.map +1 -0
  46. package/lib/node/copilot-cli-locator.spec.js +327 -0
  47. package/lib/node/copilot-cli-locator.spec.js.map +1 -0
  48. package/lib/node/copilot-credential-store.d.ts +45 -0
  49. package/lib/node/copilot-credential-store.d.ts.map +1 -0
  50. package/lib/node/copilot-credential-store.js +96 -0
  51. package/lib/node/copilot-credential-store.js.map +1 -0
  52. package/lib/node/copilot-credential-store.spec.d.ts +2 -0
  53. package/lib/node/copilot-credential-store.spec.d.ts.map +1 -0
  54. package/lib/node/copilot-credential-store.spec.js +93 -0
  55. package/lib/node/copilot-credential-store.spec.js.map +1 -0
  56. package/lib/node/copilot-language-models-manager-impl.d.ts +20 -18
  57. package/lib/node/copilot-language-models-manager-impl.d.ts.map +1 -1
  58. package/lib/node/copilot-language-models-manager-impl.js +39 -67
  59. package/lib/node/copilot-language-models-manager-impl.js.map +1 -1
  60. package/lib/node/copilot-language-models-manager-impl.spec.d.ts +2 -0
  61. package/lib/node/copilot-language-models-manager-impl.spec.d.ts.map +1 -0
  62. package/lib/node/copilot-language-models-manager-impl.spec.js +119 -0
  63. package/lib/node/copilot-language-models-manager-impl.spec.js.map +1 -0
  64. package/lib/node/copilot-runtime-env.d.ts +20 -0
  65. package/lib/node/copilot-runtime-env.d.ts.map +1 -0
  66. package/lib/node/copilot-runtime-env.js +49 -0
  67. package/lib/node/copilot-runtime-env.js.map +1 -0
  68. package/lib/node/copilot-sdk-client-provider.d.ts +103 -0
  69. package/lib/node/copilot-sdk-client-provider.d.ts.map +1 -0
  70. package/lib/node/copilot-sdk-client-provider.js +247 -0
  71. package/lib/node/copilot-sdk-client-provider.js.map +1 -0
  72. package/lib/node/copilot-sdk-client-provider.spec.d.ts +2 -0
  73. package/lib/node/copilot-sdk-client-provider.spec.d.ts.map +1 -0
  74. package/lib/node/copilot-sdk-client-provider.spec.js +215 -0
  75. package/lib/node/copilot-sdk-client-provider.spec.js.map +1 -0
  76. package/lib/node/copilot-sdk-language-model.d.ts +85 -0
  77. package/lib/node/copilot-sdk-language-model.d.ts.map +1 -0
  78. package/lib/node/copilot-sdk-language-model.js +301 -0
  79. package/lib/node/copilot-sdk-language-model.js.map +1 -0
  80. package/lib/node/copilot-sdk-language-model.spec.d.ts +2 -0
  81. package/lib/node/copilot-sdk-language-model.spec.d.ts.map +1 -0
  82. package/lib/node/copilot-sdk-language-model.spec.js +302 -0
  83. package/lib/node/copilot-sdk-language-model.spec.js.map +1 -0
  84. package/lib/node/copilot-sdk-loader.d.ts +57 -0
  85. package/lib/node/copilot-sdk-loader.d.ts.map +1 -0
  86. package/lib/node/copilot-sdk-loader.js +133 -0
  87. package/lib/node/copilot-sdk-loader.js.map +1 -0
  88. package/lib/node/copilot-sdk-loader.spec.d.ts +2 -0
  89. package/lib/node/copilot-sdk-loader.spec.d.ts.map +1 -0
  90. package/lib/node/copilot-sdk-loader.spec.js +113 -0
  91. package/lib/node/copilot-sdk-loader.spec.js.map +1 -0
  92. package/lib/node/copilot-sdk-mappers.d.ts +49 -0
  93. package/lib/node/copilot-sdk-mappers.d.ts.map +1 -0
  94. package/lib/node/copilot-sdk-mappers.js +147 -0
  95. package/lib/node/copilot-sdk-mappers.js.map +1 -0
  96. package/lib/node/copilot-sdk-mappers.spec.d.ts +2 -0
  97. package/lib/node/copilot-sdk-mappers.spec.d.ts.map +1 -0
  98. package/lib/node/copilot-sdk-mappers.spec.js +133 -0
  99. package/lib/node/copilot-sdk-mappers.spec.js.map +1 -0
  100. package/lib/node/copilot-sdk-types.d.ts +198 -0
  101. package/lib/node/copilot-sdk-types.d.ts.map +1 -0
  102. package/lib/{common/copilot-oauth-config.js → node/copilot-sdk-types.js} +2 -13
  103. package/lib/node/copilot-sdk-types.js.map +1 -0
  104. package/lib/node/index.d.ts +9 -1
  105. package/lib/node/index.d.ts.map +1 -1
  106. package/lib/node/index.js +9 -1
  107. package/lib/node/index.js.map +1 -1
  108. package/package.json +4 -6
  109. package/src/browser/copilot-auth-dialog.tsx +12 -8
  110. package/src/browser/copilot-frontend-application-contribution.ts +62 -29
  111. package/src/common/copilot-auth-service.ts +28 -24
  112. package/src/common/copilot-language-models-manager.ts +3 -28
  113. package/src/common/copilot-preferences.ts +24 -5
  114. package/src/common/index.ts +0 -1
  115. package/src/node/copilot-auth-service-impl.spec.ts +122 -207
  116. package/src/node/copilot-auth-service-impl.ts +63 -218
  117. package/src/node/copilot-backend-module.ts +11 -2
  118. package/src/node/copilot-cli-auth-provider.spec.ts +315 -0
  119. package/src/node/copilot-cli-auth-provider.ts +444 -0
  120. package/src/node/copilot-cli-locator.spec.ts +386 -0
  121. package/src/node/copilot-cli-locator.ts +363 -0
  122. package/src/node/copilot-credential-store.spec.ts +106 -0
  123. package/src/node/copilot-credential-store.ts +99 -0
  124. package/src/node/copilot-language-models-manager-impl.spec.ts +137 -0
  125. package/src/node/copilot-language-models-manager-impl.ts +51 -85
  126. package/src/node/copilot-runtime-env.ts +46 -0
  127. package/src/node/copilot-sdk-client-provider.spec.ts +253 -0
  128. package/src/node/copilot-sdk-client-provider.ts +241 -0
  129. package/src/node/copilot-sdk-language-model.spec.ts +363 -0
  130. package/src/node/copilot-sdk-language-model.ts +329 -0
  131. package/src/node/copilot-sdk-loader.spec.ts +126 -0
  132. package/src/node/copilot-sdk-loader.ts +142 -0
  133. package/src/node/copilot-sdk-mappers.spec.ts +151 -0
  134. package/src/node/copilot-sdk-mappers.ts +161 -0
  135. package/src/node/copilot-sdk-types.ts +276 -0
  136. package/src/node/index.ts +9 -1
  137. package/lib/common/copilot-oauth-config.d.ts +0 -33
  138. package/lib/common/copilot-oauth-config.d.ts.map +0 -1
  139. package/lib/common/copilot-oauth-config.js.map +0 -1
  140. package/lib/node/copilot-language-model.d.ts +0 -34
  141. package/lib/node/copilot-language-model.d.ts.map +0 -1
  142. package/lib/node/copilot-language-model.js +0 -236
  143. package/lib/node/copilot-language-model.js.map +0 -1
  144. package/lib/node/copilot-language-model.spec.d.ts +0 -2
  145. package/lib/node/copilot-language-model.spec.d.ts.map +0 -1
  146. package/lib/node/copilot-language-model.spec.js +0 -89
  147. package/lib/node/copilot-language-model.spec.js.map +0 -1
  148. package/src/common/copilot-oauth-config.ts +0 -55
  149. package/src/node/copilot-language-model.spec.ts +0 -106
  150. package/src/node/copilot-language-model.ts +0 -273
@@ -1,34 +0,0 @@
1
- import { LanguageModel, LanguageModelMessage, LanguageModelParsedResponse, LanguageModelRequest, LanguageModelResponse, LanguageModelStatus, LanguageModelTextResponse, 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 userAgentProvider: () => string;
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, userAgentProvider: () => string);
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 mergeConsecutiveAssistantMessages(messages: ChatCompletionMessageParam[]): ChatCompletionMessageParam[];
31
- protected toOpenAIMessage(message: LanguageModelMessage): ChatCompletionMessageParam;
32
- protected toOpenAiRole(message: LanguageModelMessage): 'developer' | 'user' | 'assistant' | 'system';
33
- }
34
- //# sourceMappingURL=copilot-language-model.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"copilot-language-model.d.ts","sourceRoot":"","sources":["../../src/node/copilot-language-model.ts"],"names":[],"mappings":"AAgBA,OAAO,EAGH,aAAa,EACb,oBAAoB,EACpB,2BAA2B,EAC3B,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,yBAAyB,EACzB,WAAW,EACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,gCAAgC,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAuC,0BAA0B,EAAE,MAAM,kBAAk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AW,CAAC,OAAO,EAAE,oBAAoB,GAAG,gCAAgC,EAAE,GAAG,SAAS;cAYpF,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC;IAmB1D,SAAS,CAAC,eAAe,CAAC,QAAQ,EAAE,oBAAoB,EAAE,GAAG,0BAA0B,EAAE;IAKzF,SAAS,CAAC,iCAAiC,CAAC,QAAQ,EAAE,0BAA0B,EAAE,GAAG,0BAA0B,EAAE;IA8BjH,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"}
@@ -1,236 +0,0 @@
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
- /**
24
- * Language model implementation for GitHub Copilot.
25
- * Uses the OpenAI SDK to communicate with the Copilot API.
26
- */
27
- class CopilotLanguageModel {
28
- constructor(id, model, status, enableStreaming, supportsStructuredOutput, maxRetries, accessTokenProvider, enterpriseUrlProvider, userAgentProvider) {
29
- this.id = id;
30
- this.model = model;
31
- this.status = status;
32
- this.enableStreaming = enableStreaming;
33
- this.supportsStructuredOutput = supportsStructuredOutput;
34
- this.maxRetries = maxRetries;
35
- this.accessTokenProvider = accessTokenProvider;
36
- this.enterpriseUrlProvider = enterpriseUrlProvider;
37
- this.userAgentProvider = userAgentProvider;
38
- this.runnerOptions = {
39
- maxChatCompletions: 100
40
- };
41
- }
42
- getSettings(request) {
43
- return request.settings ?? {};
44
- }
45
- async request(request, cancellationToken) {
46
- const openai = await this.initializeCopilotClient();
47
- if (request.response_format?.type === 'json_schema' && this.supportsStructuredOutput) {
48
- return this.handleStructuredOutputRequest(openai, request);
49
- }
50
- const settings = this.getSettings(request);
51
- if (!this.enableStreaming || (typeof settings.stream === 'boolean' && !settings.stream)) {
52
- return this.handleNonStreamingRequest(openai, request);
53
- }
54
- if (cancellationToken?.isCancellationRequested) {
55
- return { text: '' };
56
- }
57
- if (this.id.startsWith(`${common_1.COPILOT_PROVIDER_ID}/`)) {
58
- settings['stream_options'] = { include_usage: true };
59
- }
60
- let runner;
61
- const tools = this.createTools(request);
62
- if (tools) {
63
- runner = openai.chat.completions.runTools({
64
- model: this.model,
65
- messages: this.processMessages(request.messages),
66
- stream: true,
67
- tools: tools,
68
- tool_choice: 'auto',
69
- ...settings
70
- }, {
71
- ...this.runnerOptions,
72
- maxRetries: this.maxRetries
73
- });
74
- }
75
- else {
76
- runner = openai.chat.completions.stream({
77
- model: this.model,
78
- messages: this.processMessages(request.messages),
79
- stream: true,
80
- ...settings
81
- });
82
- }
83
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
- return { stream: new openai_streaming_iterator_1.StreamingAsyncIterator(runner, cancellationToken) };
85
- }
86
- async handleNonStreamingRequest(openai, request) {
87
- const settings = this.getSettings(request);
88
- const response = await openai.chat.completions.create({
89
- model: this.model,
90
- messages: this.processMessages(request.messages),
91
- ...settings
92
- });
93
- const message = response.choices[0].message;
94
- return {
95
- text: message.content ?? '',
96
- usage: response.usage ? {
97
- input_tokens: response.usage.prompt_tokens,
98
- output_tokens: response.usage.completion_tokens,
99
- } : undefined
100
- };
101
- }
102
- async handleStructuredOutputRequest(openai, request) {
103
- const settings = this.getSettings(request);
104
- const result = await openai.chat.completions.parse({
105
- model: this.model,
106
- messages: this.processMessages(request.messages),
107
- response_format: request.response_format,
108
- ...settings
109
- });
110
- const message = result.choices[0].message;
111
- if (message.refusal || message.parsed === undefined) {
112
- console.error('Error in Copilot chat completion:', JSON.stringify(message));
113
- }
114
- return {
115
- content: message.content ?? '',
116
- parsed: message.parsed,
117
- usage: result.usage ? {
118
- input_tokens: result.usage.prompt_tokens,
119
- output_tokens: result.usage.completion_tokens,
120
- } : undefined
121
- };
122
- }
123
- createTools(request) {
124
- return request.tools?.map(tool => ({
125
- type: 'function',
126
- function: {
127
- name: tool.name,
128
- description: tool.description,
129
- parameters: tool.parameters,
130
- function: (args_string) => tool.handler(args_string)
131
- }
132
- }));
133
- }
134
- async initializeCopilotClient() {
135
- const accessToken = await this.accessTokenProvider();
136
- if (!accessToken) {
137
- throw new Error('Not authenticated with GitHub Copilot. Please sign in first.');
138
- }
139
- const baseURL = (0, common_1.getCopilotApiBaseUrl)(this.enterpriseUrlProvider());
140
- return new openai_1.default({
141
- apiKey: accessToken,
142
- baseURL,
143
- defaultHeaders: {
144
- 'User-Agent': this.userAgentProvider(),
145
- 'Openai-Intent': 'conversation-edits',
146
- 'X-Initiator': 'user'
147
- }
148
- });
149
- }
150
- processMessages(messages) {
151
- const converted = messages.filter(m => m.type !== 'thinking' && m.type !== 'compaction').map(m => this.toOpenAIMessage(m));
152
- return this.mergeConsecutiveAssistantMessages(converted);
153
- }
154
- mergeConsecutiveAssistantMessages(messages) {
155
- const result = [];
156
- for (const message of messages) {
157
- const previous = result[result.length - 1];
158
- if (previous?.role === 'assistant' && message.role === 'assistant') {
159
- const merged = { ...previous, role: 'assistant' };
160
- const previousContent = typeof previous.content === 'string' ? previous.content : undefined;
161
- const nextContent = typeof message.content === 'string' ? message.content : undefined;
162
- if (previousContent !== undefined && nextContent !== undefined) {
163
- merged.content = `${previousContent}\n${nextContent}`;
164
- }
165
- else if (nextContent !== undefined) {
166
- merged.content = nextContent;
167
- }
168
- else if (previousContent !== undefined) {
169
- merged.content = previousContent;
170
- }
171
- const toolCalls = [...(previous.tool_calls ?? []), ...(message.tool_calls ?? [])];
172
- if (toolCalls.length > 0) {
173
- merged.tool_calls = toolCalls;
174
- }
175
- result[result.length - 1] = merged;
176
- }
177
- else {
178
- result.push(message);
179
- }
180
- }
181
- return result;
182
- }
183
- toOpenAIMessage(message) {
184
- if (ai_core_1.LanguageModelMessage.isTextMessage(message)) {
185
- return {
186
- role: this.toOpenAiRole(message),
187
- content: message.text
188
- };
189
- }
190
- if (ai_core_1.LanguageModelMessage.isToolUseMessage(message)) {
191
- return {
192
- role: 'assistant',
193
- tool_calls: [{
194
- id: message.id,
195
- function: {
196
- name: message.name,
197
- arguments: JSON.stringify(message.input)
198
- },
199
- type: 'function'
200
- }]
201
- };
202
- }
203
- if (ai_core_1.LanguageModelMessage.isToolResultMessage(message)) {
204
- return {
205
- role: 'tool',
206
- tool_call_id: message.tool_use_id,
207
- content: typeof message.content === 'string' ? message.content : (0, ai_core_1.formatToolCallContentForModel)(message.content)
208
- };
209
- }
210
- if (ai_core_1.LanguageModelMessage.isImageMessage(message) && message.actor === 'user') {
211
- return {
212
- role: 'user',
213
- content: [{
214
- type: 'image_url',
215
- image_url: {
216
- url: ai_core_1.ImageContent.isBase64(message.image)
217
- ? `data:${message.image.mimeType};base64,${message.image.base64data}`
218
- : message.image.url
219
- }
220
- }]
221
- };
222
- }
223
- throw new Error(`Unknown message type: '${JSON.stringify(message)}'`);
224
- }
225
- toOpenAiRole(message) {
226
- if (message.actor === 'system') {
227
- return 'developer';
228
- }
229
- else if (message.actor === 'ai') {
230
- return 'assistant';
231
- }
232
- return 'user';
233
- }
234
- }
235
- exports.CopilotLanguageModel = CopilotLanguageModel;
236
- //# sourceMappingURL=copilot-language-model.js.map
@@ -1 +0,0 @@
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,sCAAsE;AAItE;;;GAGG;AACH,MAAa,oBAAoB;IAM7B,YACoB,EAAU,EACnB,KAAa,EACb,MAA2B,EAC3B,eAAwB,EACxB,wBAAiC,EACjC,UAAkB,EACN,mBAAsD,EACtD,qBAA+C,EAC/C,iBAA+B;QARlC,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,CAAc;QAb5C,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,eAAe,EAAE,IAAI,KAAK,aAAa,IAAI,IAAI,CAAC,wBAAwB,EAAE,CAAC;YACnF,OAAO,IAAI,CA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I,EAAE,CAAC;YAChC,OAAO,WAAW,CAAC;QACvB,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAvOD,oDAuOC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=copilot-language-model.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"copilot-language-model.spec.d.ts","sourceRoot":"","sources":["../../src/node/copilot-language-model.spec.ts"],"names":[],"mappings":""}
@@ -1,89 +0,0 @@
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 chai_1 = require("chai");
19
- const copilot_language_model_1 = require("./copilot-language-model");
20
- class TestableCopilotLanguageModel extends copilot_language_model_1.CopilotLanguageModel {
21
- constructor() {
22
- super('test-id', 'test-model', { status: 'ready' }, true, false, 3, async () => 'test-token', () => undefined, () => 'test-user-agent');
23
- }
24
- callProcessMessages(messages) {
25
- return this.processMessages(messages);
26
- }
27
- }
28
- describe('CopilotLanguageModel - processMessages', () => {
29
- const model = new TestableCopilotLanguageModel();
30
- it('should merge an assistant text message followed by an assistant tool_use into a single message', () => {
31
- const messages = [
32
- { actor: 'user', type: 'text', text: 'do something' },
33
- { actor: 'ai', type: 'text', text: 'let me call a tool' },
34
- { actor: 'ai', type: 'tool_use', id: 'call_1', name: 'foo', input: { x: 1 } }
35
- ];
36
- const result = model.callProcessMessages(messages);
37
- (0, chai_1.expect)(result).to.deep.equal([
38
- { role: 'user', content: 'do something' },
39
- {
40
- role: 'assistant',
41
- content: 'let me call a tool',
42
- tool_calls: [{ id: 'call_1', function: { name: 'foo', arguments: JSON.stringify({ x: 1 }) }, type: 'function' }]
43
- }
44
- ]);
45
- });
46
- it('should merge multiple parallel assistant tool_use messages', () => {
47
- const messages = [
48
- { actor: 'user', type: 'text', text: 'do parallel work' },
49
- { actor: 'ai', type: 'tool_use', id: 'call_1', name: 'foo', input: { x: 1 } },
50
- { actor: 'ai', type: 'tool_use', id: 'call_2', name: 'bar', input: { y: 2 } }
51
- ];
52
- const result = model.callProcessMessages(messages);
53
- (0, chai_1.expect)(result).to.deep.equal([
54
- { role: 'user', content: 'do parallel work' },
55
- {
56
- role: 'assistant',
57
- tool_calls: [
58
- { id: 'call_1', function: { name: 'foo', arguments: JSON.stringify({ x: 1 }) }, type: 'function' },
59
- { id: 'call_2', function: { name: 'bar', arguments: JSON.stringify({ y: 2 }) }, type: 'function' }
60
- ]
61
- }
62
- ]);
63
- });
64
- it('should reproduce the bug scenario from issue #17104', () => {
65
- const messages = [
66
- { actor: 'user', type: 'text', text: 'first request' },
67
- { actor: 'ai', type: 'tool_use', id: 'call_1', name: 'foo', input: {} },
68
- { actor: 'user', type: 'tool_result', tool_use_id: 'call_1', name: 'foo', content: 'result_1' },
69
- { actor: 'ai', type: 'text', text: 'follow-up reasoning' },
70
- { actor: 'ai', type: 'tool_use', id: 'call_2', name: 'bar', input: {} }
71
- ];
72
- const result = model.callProcessMessages(messages);
73
- for (let i = 1; i < result.length; i++) {
74
- (0, chai_1.expect)(result[i - 1].role === 'assistant' && result[i].role === 'assistant').to.equal(false);
75
- }
76
- (0, chai_1.expect)(result).to.have.lengthOf(4);
77
- });
78
- it('should leave non-adjacent assistant messages separate', () => {
79
- const messages = [
80
- { actor: 'ai', type: 'tool_use', id: 'call_1', name: 'foo', input: {} },
81
- { actor: 'user', type: 'tool_result', tool_use_id: 'call_1', name: 'foo', content: 'r' },
82
- { actor: 'ai', type: 'text', text: 'final answer' }
83
- ];
84
- const result = model.callProcessMessages(messages);
85
- (0, chai_1.expect)(result).to.have.lengthOf(3);
86
- (0, chai_1.expect)(result[2]).to.deep.equal({ role: 'assistant', content: 'final answer' });
87
- });
88
- });
89
- //# sourceMappingURL=copilot-language-model.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"copilot-language-model.spec.js","sourceRoot":"","sources":["../../src/node/copilot-language-model.spec.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,+BAA8B;AAG9B,qEAAgE;AAEhE,MAAM,4BAA6B,SAAQ,6CAAoB;IAC3D;QACI,KAAK,CACD,SAAS,EACT,YAAY,EACZ,EAAE,MAAM,EAAE,OAAO,EAAE,EACnB,IAAI,EACJ,KAAK,EACL,CAAC,EACD,KAAK,IAAI,EAAE,CAAC,YAAY,EACxB,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,iBAAiB,CAC1B,CAAC;IACN,CAAC;IAEM,mBAAmB,CAAC,QAAgC;QACvD,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;CACJ;AAED,QAAQ,CAAC,wCAAwC,EAAE,GAAG,EAAE;IACpD,MAAM,KAAK,GAAG,IAAI,4BAA4B,EAAE,CAAC;IAEjD,EAAE,CAAC,gGAAgG,EAAE,GAAG,EAAE;QACtG,MAAM,QAAQ,GAA2B;YACrC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE;YACrD,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI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EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -1,55 +0,0 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2026 Lonti.com Pty Ltd.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- export const CopilotOAuthConfig = Symbol('CopilotOAuthConfig');
18
-
19
- /**
20
- * Configuration for the GitHub Copilot OAuth Device Flow.
21
- * Bind this symbol to a custom value in your container module to override the defaults
22
- * and use your own GitHub OAuth application.
23
- */
24
- export interface CopilotOAuthConfig {
25
- /**
26
- * The GitHub OAuth App client ID used to initiate the device flow.
27
- * Defaults to the built-in Theia Copilot OAuth App client ID.
28
- */
29
- readonly clientId: string;
30
- /**
31
- * The User-Agent header sent with GitHub API requests.
32
- * Defaults to `'Theia-Copilot/1.0.0'`.
33
- */
34
- readonly userAgent: string;
35
- /**
36
- * The service name used to store credentials in the system keystore.
37
- * Defaults to `'theia-copilot-auth'`.
38
- */
39
- readonly keystoreService: string;
40
- /**
41
- * The account name used to store credentials in the system keystore.
42
- * Defaults to `'github-copilot'`.
43
- */
44
- readonly keystoreAccount: string;
45
- }
46
-
47
- /**
48
- * Default OAuth configuration for the built-in Theia Copilot integration.
49
- */
50
- export const DEFAULT_COPILOT_OAUTH_CONFIG: CopilotOAuthConfig = {
51
- clientId: 'Ov23liS2vINy9VOAweyv',
52
- userAgent: 'Theia-Copilot/1.0.0',
53
- keystoreService: 'theia-copilot-auth',
54
- keystoreAccount: 'github-copilot'
55
- };
@@ -1,106 +0,0 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2026 EclipseSource GmbH.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { expect } from 'chai';
18
- import { LanguageModelMessage } from '@theia/ai-core';
19
- import { ChatCompletionMessageParam } from 'openai/resources';
20
- import { CopilotLanguageModel } from './copilot-language-model';
21
-
22
- class TestableCopilotLanguageModel extends CopilotLanguageModel {
23
- constructor() {
24
- super(
25
- 'test-id',
26
- 'test-model',
27
- { status: 'ready' },
28
- true,
29
- false,
30
- 3,
31
- async () => 'test-token',
32
- () => undefined,
33
- () => 'test-user-agent'
34
- );
35
- }
36
-
37
- public callProcessMessages(messages: LanguageModelMessage[]): ChatCompletionMessageParam[] {
38
- return this.processMessages(messages);
39
- }
40
- }
41
-
42
- describe('CopilotLanguageModel - processMessages', () => {
43
- const model = new TestableCopilotLanguageModel();
44
-
45
- it('should merge an assistant text message followed by an assistant tool_use into a single message', () => {
46
- const messages: LanguageModelMessage[] = [
47
- { actor: 'user', type: 'text', text: 'do something' },
48
- { actor: 'ai', type: 'text', text: 'let me call a tool' },
49
- { actor: 'ai', type: 'tool_use', id: 'call_1', name: 'foo', input: { x: 1 } }
50
- ];
51
- const result = model.callProcessMessages(messages);
52
- expect(result).to.deep.equal([
53
- { role: 'user', content: 'do something' },
54
- {
55
- role: 'assistant',
56
- content: 'let me call a tool',
57
- tool_calls: [{ id: 'call_1', function: { name: 'foo', arguments: JSON.stringify({ x: 1 }) }, type: 'function' }]
58
- }
59
- ]);
60
- });
61
-
62
- it('should merge multiple parallel assistant tool_use messages', () => {
63
- const messages: LanguageModelMessage[] = [
64
- { actor: 'user', type: 'text', text: 'do parallel work' },
65
- { actor: 'ai', type: 'tool_use', id: 'call_1', name: 'foo', input: { x: 1 } },
66
- { actor: 'ai', type: 'tool_use', id: 'call_2', name: 'bar', input: { y: 2 } }
67
- ];
68
- const result = model.callProcessMessages(messages);
69
- expect(result).to.deep.equal([
70
- { role: 'user', content: 'do parallel work' },
71
- {
72
- role: 'assistant',
73
- tool_calls: [
74
- { id: 'call_1', function: { name: 'foo', arguments: JSON.stringify({ x: 1 }) }, type: 'function' },
75
- { id: 'call_2', function: { name: 'bar', arguments: JSON.stringify({ y: 2 }) }, type: 'function' }
76
- ]
77
- }
78
- ]);
79
- });
80
-
81
- it('should reproduce the bug scenario from issue #17104', () => {
82
- const messages: LanguageModelMessage[] = [
83
- { actor: 'user', type: 'text', text: 'first request' },
84
- { actor: 'ai', type: 'tool_use', id: 'call_1', name: 'foo', input: {} },
85
- { actor: 'user', type: 'tool_result', tool_use_id: 'call_1', name: 'foo', content: 'result_1' },
86
- { actor: 'ai', type: 'text', text: 'follow-up reasoning' },
87
- { actor: 'ai', type: 'tool_use', id: 'call_2', name: 'bar', input: {} }
88
- ];
89
- const result = model.callProcessMessages(messages);
90
- for (let i = 1; i < result.length; i++) {
91
- expect(result[i - 1].role === 'assistant' && result[i].role === 'assistant').to.equal(false);
92
- }
93
- expect(result).to.have.lengthOf(4);
94
- });
95
-
96
- it('should leave non-adjacent assistant messages separate', () => {
97
- const messages: LanguageModelMessage[] = [
98
- { actor: 'ai', type: 'tool_use', id: 'call_1', name: 'foo', input: {} },
99
- { actor: 'user', type: 'tool_result', tool_use_id: 'call_1', name: 'foo', content: 'r' },
100
- { actor: 'ai', type: 'text', text: 'final answer' }
101
- ];
102
- const result = model.callProcessMessages(messages);
103
- expect(result).to.have.lengthOf(3);
104
- expect(result[2]).to.deep.equal({ role: 'assistant', content: 'final answer' });
105
- });
106
- });