@theia/ai-copilot 1.76.0-next.4 → 1.76.0-next.42

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 +87 -14
  2. package/lib/browser/copilot-auth-dialog.d.ts.map +1 -1
  3. package/lib/browser/copilot-auth-dialog.js +19 -11
  4. package/lib/browser/copilot-auth-dialog.js.map +1 -1
  5. package/lib/browser/copilot-frontend-application-contribution.d.ts +21 -1
  6. package/lib/browser/copilot-frontend-application-contribution.d.ts.map +1 -1
  7. package/lib/browser/copilot-frontend-application-contribution.js +129 -26
  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 +6 -22
  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 +44 -20
  57. package/lib/node/copilot-language-models-manager-impl.d.ts.map +1 -1
  58. package/lib/node/copilot-language-models-manager-impl.js +112 -65
  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 +162 -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 +315 -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 +54 -0
  93. package/lib/node/copilot-sdk-mappers.d.ts.map +1 -0
  94. package/lib/node/copilot-sdk-mappers.js +158 -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 +168 -0
  99. package/lib/node/copilot-sdk-mappers.spec.js.map +1 -0
  100. package/lib/node/copilot-sdk-types.d.ts +208 -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 +20 -16
  110. package/src/browser/copilot-frontend-application-contribution.ts +144 -31
  111. package/src/common/copilot-auth-service.ts +28 -24
  112. package/src/common/copilot-language-models-manager.ts +6 -29
  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 +188 -0
  125. package/src/node/copilot-language-models-manager-impl.ts +131 -84
  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 +377 -0
  130. package/src/node/copilot-sdk-language-model.ts +330 -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 +190 -0
  134. package/src/node/copilot-sdk-mappers.ts +172 -0
  135. package/src/node/copilot-sdk-types.ts +290 -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
@@ -0,0 +1,315 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2026 EclipseSource GmbH and others.
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 mock_logger_1 = require("@theia/core/lib/common/test/mock-logger");
20
+ const copilot_sdk_language_model_1 = require("./copilot-sdk-language-model");
21
+ class TestableCopilotSdkLanguageModel extends copilot_sdk_language_model_1.CopilotSdkLanguageModel {
22
+ constructor() {
23
+ super('copilot/test', 'test-model', { status: 'ready' }, 3, async () => ({}), new mock_logger_1.MockLogger());
24
+ }
25
+ callCreateTools(tools, sink) {
26
+ return this.createTools(tools, sink);
27
+ }
28
+ /** Captures the session configuration the model would create for a request. */
29
+ async captureSessionConfig(request) {
30
+ let captured = {};
31
+ const client = {
32
+ createSession: async (config) => {
33
+ captured = config;
34
+ return { on: () => () => { }, send: async () => { }, abort: async () => { }, disconnect: async () => { } };
35
+ }
36
+ };
37
+ const model = new TestableCopilotSdkLanguageModel();
38
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
+ model.clientProvider = async () => client;
40
+ await model.request(request);
41
+ return captured;
42
+ }
43
+ /**
44
+ * Runs a request against a session that reports itself idle as soon as it was sent to, and
45
+ * reports what the session was configured with, what it was sent, and what was discarded.
46
+ */
47
+ async captureTurn(request) {
48
+ let config = {};
49
+ let prompt;
50
+ let attachments;
51
+ let deleted;
52
+ const listeners = new Map();
53
+ const session = {
54
+ sessionId: 'test-session',
55
+ on: (event, handler) => {
56
+ listeners.set(event, handler);
57
+ return () => listeners.delete(event);
58
+ },
59
+ send: async (message) => {
60
+ prompt = message.prompt;
61
+ attachments = message.attachments;
62
+ listeners.get('session.idle')?.({});
63
+ },
64
+ abort: async () => { },
65
+ disconnect: async () => { }
66
+ };
67
+ const client = {
68
+ createSession: async (sessionConfig) => {
69
+ config = sessionConfig;
70
+ return session;
71
+ },
72
+ deleteSession: async (sessionId) => { deleted = sessionId; }
73
+ };
74
+ const model = new TestableCopilotSdkLanguageModel();
75
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
+ model.clientProvider = async () => client;
77
+ const response = await model.request(request);
78
+ for await (const part of response.stream) {
79
+ (0, chai_1.expect)(part).to.exist;
80
+ }
81
+ return { config, prompt, attachments, deleted };
82
+ }
83
+ }
84
+ function toolRequest(name, handler) {
85
+ return {
86
+ id: name,
87
+ name,
88
+ description: `the ${name} tool`,
89
+ parameters: { type: 'object', properties: { path: { type: 'string' } } },
90
+ handler
91
+ };
92
+ }
93
+ /**
94
+ * Runs a tool invocation the way the caller does, with the stream being consumed concurrently.
95
+ * The handler waits for its reported call to be consumed, so nothing may invoke it in isolation.
96
+ */
97
+ async function invokeWhileConsuming(sink, invoke) {
98
+ const parts = [];
99
+ const consumer = (async () => {
100
+ for await (const part of sink.drain()) {
101
+ parts.push(part);
102
+ }
103
+ })();
104
+ const result = await invoke();
105
+ sink.finish();
106
+ await consumer;
107
+ return { result, parts };
108
+ }
109
+ async function collect(sink) {
110
+ const parts = [];
111
+ for await (const part of sink.drain()) {
112
+ parts.push(part);
113
+ }
114
+ return parts;
115
+ }
116
+ function toolCalls(part) {
117
+ return part.tool_calls;
118
+ }
119
+ describe('CopilotSdkLanguageModel - createTools', () => {
120
+ const model = new TestableCopilotSdkLanguageModel();
121
+ it('should declare the tools of the request to the CLI', () => {
122
+ const tools = model.callCreateTools([toolRequest('readFile', async () => 'content')], new copilot_sdk_language_model_1.CopilotStreamSink());
123
+ (0, chai_1.expect)(tools).to.have.lengthOf(1);
124
+ (0, chai_1.expect)(tools[0].name).to.equal('readFile');
125
+ (0, chai_1.expect)(tools[0].description).to.equal('the readFile tool');
126
+ (0, chai_1.expect)(tools[0].parameters).to.deep.equal({ type: 'object', properties: { path: { type: 'string' } } });
127
+ // Theia confirms tool invocations itself, so the CLI must not prompt again.
128
+ (0, chai_1.expect)(tools[0].skipPermission).to.be.true;
129
+ });
130
+ it('should pass the raw argument string to the handler of the request', async () => {
131
+ let received;
132
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
133
+ const tools = model.callCreateTools([toolRequest('readFile', async (args) => { received = args; return 'content'; })], sink);
134
+ const { result } = await invokeWhileConsuming(sink, () => tools[0].handler({ path: 'a.ts' }, { sessionId: 's', toolCallId: 'call_1', toolName: 'readFile', arguments: {} }));
135
+ (0, chai_1.expect)(received).to.equal(JSON.stringify({ path: 'a.ts' }));
136
+ (0, chai_1.expect)(result).to.equal('content');
137
+ });
138
+ it('should report the invocation as an unfinished and then a finished tool call', async () => {
139
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
140
+ const tools = model.callCreateTools([toolRequest('readFile', async () => 'content')], sink);
141
+ const { parts } = await invokeWhileConsuming(sink, () => tools[0].handler({ path: 'a.ts' }, { sessionId: 's', toolCallId: 'call_1', toolName: 'readFile', arguments: {} }));
142
+ (0, chai_1.expect)(parts).to.have.lengthOf(2);
143
+ (0, chai_1.expect)(toolCalls(parts[0])[0]).to.deep.include({ id: 'call_1', finished: false });
144
+ (0, chai_1.expect)(toolCalls(parts[0])[0].function).to.deep.equal({ name: 'readFile', arguments: JSON.stringify({ path: 'a.ts' }) });
145
+ (0, chai_1.expect)(toolCalls(parts[1])[0]).to.deep.include({ id: 'call_1', finished: true, result: 'content' });
146
+ });
147
+ it('should report a failing tool to the stream and to the agent instead of throwing', async () => {
148
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
149
+ const tools = model.callCreateTools([toolRequest('readFile', async () => { throw new Error('no such file'); })], sink);
150
+ const { result, parts } = await invokeWhileConsuming(sink, () => tools[0].handler({ path: 'missing.ts' }, { sessionId: 's', toolCallId: 'call_1', toolName: 'readFile', arguments: {} }));
151
+ (0, chai_1.expect)(result).to.deep.equal({ error: 'no such file' });
152
+ (0, chai_1.expect)(toolCalls(parts[1])[0]).to.deep.include({ id: 'call_1', finished: true, result: 'Error: no such file' });
153
+ });
154
+ it('should return an empty tool list when the request has no tools', () => {
155
+ (0, chai_1.expect)(model.callCreateTools([], new copilot_sdk_language_model_1.CopilotStreamSink())).to.be.empty;
156
+ });
157
+ });
158
+ describe('CopilotSdkLanguageModel - session configuration', () => {
159
+ const model = new TestableCopilotSdkLanguageModel();
160
+ function requestWith(tools) {
161
+ return { messages: [{ actor: 'user', type: 'text', text: 'hi' }], tools };
162
+ }
163
+ it('should enable the declared tools and nothing else', async () => {
164
+ const config = await model.captureSessionConfig(requestWith([toolRequest('readFile', async () => 'content')]));
165
+ // An empty list would match nothing and would disable the declared tools as well.
166
+ (0, chai_1.expect)(config.availableTools).to.deep.equal(['custom:*']);
167
+ (0, chai_1.expect)(config.tools.map(tool => tool.name)).to.deep.equal(['readFile']);
168
+ });
169
+ it('should declare every tool of the request', async () => {
170
+ const config = await model.captureSessionConfig(requestWith([
171
+ toolRequest('readFile', async () => 'a'),
172
+ toolRequest('listFiles', async () => 'b')
173
+ ]));
174
+ (0, chai_1.expect)(config.tools.map(tool => tool.name)).to.deep.equal(['readFile', 'listFiles']);
175
+ });
176
+ it('should still exclude the built-in tools when the request has none', async () => {
177
+ const config = await model.captureSessionConfig(requestWith([]));
178
+ (0, chai_1.expect)(config.availableTools).to.deep.equal(['custom:*']);
179
+ (0, chai_1.expect)(config.tools).to.be.empty;
180
+ });
181
+ });
182
+ describe('approveTheiaTools', () => {
183
+ const customToolRequest = { kind: 'custom-tool', toolName: 'readFile' };
184
+ it('should approve a request for a tool Theia declared and confirmed itself', () => {
185
+ (0, chai_1.expect)((0, copilot_sdk_language_model_1.approveTheiaTools)(customToolRequest, { sessionId: 'test-session' })).to.deep.equal({ kind: 'approve-once' });
186
+ });
187
+ it('should report that nobody can confirm a request managed policy reserves for a decision', () => {
188
+ const request = { ...customToolRequest, managedApprovalRequired: true };
189
+ // Not `no-result`: that leaves the request pending for another client, and there is none here.
190
+ (0, chai_1.expect)((0, copilot_sdk_language_model_1.approveTheiaTools)(request, { sessionId: 'test-session' })).to.deep.equal({ kind: 'user-not-available' });
191
+ });
192
+ it('should report the same when the machine has managed settings enabled at all', () => {
193
+ (0, chai_1.expect)((0, copilot_sdk_language_model_1.approveTheiaTools)(customToolRequest, { sessionId: 'test-session', managedSettingsEnabled: true }))
194
+ .to.deep.equal({ kind: 'user-not-available' });
195
+ });
196
+ });
197
+ describe('CopilotSdkLanguageModel - turn', () => {
198
+ const model = new TestableCopilotSdkLanguageModel();
199
+ const request = {
200
+ messages: [
201
+ { actor: 'system', type: 'text', text: 'You are a helpful assistant.' },
202
+ { actor: 'user', type: 'text', text: 'hi' }
203
+ ]
204
+ };
205
+ it('should configure the system prompt as the system message of the session', async () => {
206
+ const { config } = await model.captureTurn(request);
207
+ (0, chai_1.expect)(config.systemMessage).to.deep.include({ mode: 'customize', content: 'You are a helpful assistant.' });
208
+ });
209
+ it('should send the user turn without the system prompt in it', async () => {
210
+ const { prompt } = await model.captureTurn(request);
211
+ (0, chai_1.expect)(prompt).to.equal('hi');
212
+ });
213
+ it('should delete the session it created, which the CLI would otherwise keep', async () => {
214
+ const { deleted } = await model.captureTurn(request);
215
+ (0, chai_1.expect)(deleted).to.equal('test-session');
216
+ });
217
+ it('should send a base64 image of the request as a blob attachment', async () => {
218
+ const requestWithImage = {
219
+ messages: [
220
+ { actor: 'user', type: 'text', text: 'what is this?' },
221
+ { actor: 'user', type: 'image', image: { base64data: 'aGk=', mimeType: 'image/png' } }
222
+ ]
223
+ };
224
+ const { prompt, attachments } = await model.captureTurn(requestWithImage);
225
+ (0, chai_1.expect)(prompt).to.equal('what is this?');
226
+ (0, chai_1.expect)(attachments).to.deep.equal([{ type: 'blob', data: 'aGk=', mimeType: 'image/png' }]);
227
+ });
228
+ });
229
+ describe('CopilotStreamSink', () => {
230
+ it('should yield parts pushed before draining', async () => {
231
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
232
+ sink.push({ content: 'a' });
233
+ sink.push({ content: 'b' });
234
+ sink.finish();
235
+ (0, chai_1.expect)(await collect(sink)).to.deep.equal([{ content: 'a' }, { content: 'b' }]);
236
+ });
237
+ it('should yield parts pushed while draining', async () => {
238
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
239
+ const collected = collect(sink);
240
+ sink.push({ content: 'a' });
241
+ await Promise.resolve();
242
+ sink.push({ content: 'b' });
243
+ sink.finish();
244
+ (0, chai_1.expect)(await collected).to.deep.equal([{ content: 'a' }, { content: 'b' }]);
245
+ });
246
+ it('should raise the failure after the buffered parts have been drained', async () => {
247
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
248
+ sink.push({ content: 'partial' });
249
+ sink.finish(new Error('session failed'));
250
+ const parts = [];
251
+ let error;
252
+ try {
253
+ for await (const part of sink.drain()) {
254
+ parts.push(part);
255
+ }
256
+ }
257
+ catch (caught) {
258
+ error = caught;
259
+ }
260
+ (0, chai_1.expect)(parts).to.deep.equal([{ content: 'partial' }]);
261
+ (0, chai_1.expect)(error.message).to.equal('session failed');
262
+ });
263
+ it('should end without parts when finished immediately', async () => {
264
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
265
+ sink.finish();
266
+ (0, chai_1.expect)(await collect(sink)).to.be.empty;
267
+ });
268
+ });
269
+ describe('CopilotSdkLanguageModel - tool call ordering', () => {
270
+ const model = new TestableCopilotSdkLanguageModel();
271
+ const invocation = { sessionId: 's', toolCallId: 'call_1', toolName: 'readFile', arguments: {} };
272
+ it('should report the call before running the tool, so the caller can record it first', async () => {
273
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
274
+ const observed = [];
275
+ const tools = model.callCreateTools([toolRequest('readFile', async () => {
276
+ observed.push('tool ran');
277
+ return 'content';
278
+ })], sink);
279
+ const invoked = tools[0].handler({ path: 'a.ts' }, invocation);
280
+ // The consumer has not taken the part yet, so the tool must not have run.
281
+ (0, chai_1.expect)(observed).to.be.empty;
282
+ const parts = [];
283
+ const consumer = (async () => {
284
+ for await (const part of sink.drain()) {
285
+ parts.push(part);
286
+ observed.push('part consumed');
287
+ }
288
+ })();
289
+ await invoked;
290
+ sink.finish();
291
+ await consumer;
292
+ (0, chai_1.expect)(observed[0]).to.equal('part consumed');
293
+ (0, chai_1.expect)(observed).to.contain('tool ran');
294
+ (0, chai_1.expect)(toolCalls(parts[0])[0]).to.deep.include({ id: 'call_1', finished: false });
295
+ });
296
+ it('should pass the call id to the handler so the caller can correlate it', async () => {
297
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
298
+ let receivedId;
299
+ const tools = model.callCreateTools([toolRequest('readFile', async (_args, ctx) => {
300
+ receivedId = ctx?.toolCallId;
301
+ return 'content';
302
+ })], sink);
303
+ const invoked = tools[0].handler({ path: 'a.ts' }, invocation);
304
+ const consumer = (async () => {
305
+ for await (const part of sink.drain()) {
306
+ (0, chai_1.expect)(part).to.exist;
307
+ }
308
+ })();
309
+ await invoked;
310
+ sink.finish();
311
+ await consumer;
312
+ (0, chai_1.expect)(receivedId).to.equal('call_1');
313
+ });
314
+ });
315
+ //# sourceMappingURL=copilot-sdk-language-model.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot-sdk-language-model.spec.js","sourceRoot":"","sources":["../../src/node/copilot-sdk-language-model.spec.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,oDAAoD;AACpD,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,yEAAqE;AACrE,6EAA6G;AAE7G,MAAM,+BAAgC,SAAQ,oDAAuB;IACjE;QACI,KAAK,CAAC,cAAc,EAAE,YAAY,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAoB,CAAA,EAAE,IAAI,wBAAU,EAAE,CAAC,CAAC;IACrH,CAAC;IAED,eAAe,CAAC,KAAoB,EAAE,IAAuB;QACzD,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,+EAA+E;IAC/E,KAAK,CAAC,oBAAoB,CAAC,OAAoB;QAC3C,IAAI,QAAQ,GAA4B,EAAE,CAAC;QAC3C,MAAM,MAAM,GAAG;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,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;IACtF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uEAAuE,EAAE,KAAK,IAAI,EAAE;QACnF,MAAM,IAAI,GAAG,IAAI,8CAAiB,EAAE,CAAC;QACrC,IAAI,UAA8B,CAAC;QACnC,MAAM,KAAK,GAAG,KAAK,CAAC,eAAe,CAAC,CAAC,WAAW,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;gBAC9E,UAAU,GAAG,GAAG,EAAE,UAAU,CAAC;gBAC7B,OAAO,SAAS,CAAC;YACrB,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QAEX,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,OAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC;QAChE,MAAM,QAAQ,GAAG,CAAC,KAAK,IAAI,EAAE;YACzB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;gBACpC,IAAA,aAAM,EAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC;YAC1B,CAAC;QACL,CAAC,CAAC,EAAE,CAAC;QACL,MAAM,OAAO,CAAC;QACd,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,MAAM,QAAQ,CAAC;QAEf,IAAA,aAAM,EAAC,UAAU,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { ILogger } from '@theia/core';
2
+ import { CopilotCliLocator } from './copilot-cli-locator';
3
+ import type { CopilotClientConstructor, RuntimeConnectionFactory } from './copilot-sdk-types';
4
+ /**
5
+ * The part of the Copilot SDK this integration uses at runtime.
6
+ */
7
+ export interface CopilotSdkApi {
8
+ readonly CopilotClient: CopilotClientConstructor;
9
+ readonly RuntimeConnection: RuntimeConnectionFactory;
10
+ }
11
+ /**
12
+ * Provides the Copilot SDK that belongs to the Copilot CLI in use.
13
+ *
14
+ * The SDK is not a dependency of this extension. It is published as `@github/copilot-sdk`, but that
15
+ * package depends on the CLI, which is a large proprietary binary that an application must not have
16
+ * to ship, see {@link CopilotCliLocator}. The CLI carries its own copy of the SDK, so the one
17
+ * belonging to the CLI that is actually going to serve the requests is loaded from there. What is used
18
+ * of its API is mirrored in `copilot-sdk-types.ts` rather than taken from the package.
19
+ *
20
+ * An installed `@github/copilot-sdk` is used when the CLI does not carry one, so that an application
21
+ * which does depend on the package keeps working.
22
+ */
23
+ export declare class CopilotSdkLoader {
24
+ protected readonly cliLocator: CopilotCliLocator;
25
+ protected readonly logger: ILogger;
26
+ protected loaded: Promise<CopilotSdkApi> | undefined;
27
+ protected loadedFrom: string | undefined;
28
+ /**
29
+ * Loads the SDK, and remembers it for as long as the CLI it belongs to stays the same.
30
+ */
31
+ load(): Promise<CopilotSdkApi>;
32
+ protected doLoad(cli: string): Promise<CopilotSdkApi>;
33
+ /**
34
+ * Imports the copy of the SDK that ships with the CLI. It is an ES module, hence the import by URL.
35
+ */
36
+ protected importShipped(entry: string): Promise<unknown | undefined>;
37
+ /**
38
+ * Imports an installed SDK if there is one, so that a missing package is reported as the CLI not
39
+ * providing what is needed rather than as a module that cannot be found.
40
+ */
41
+ protected tryImportInstalled(): unknown;
42
+ /**
43
+ * Imports an installed `@github/copilot-sdk`, for an application that depends on the package.
44
+ */
45
+ protected importInstalled(): unknown;
46
+ /**
47
+ * Dynamic import through a constructed function, so that a bundler leaves it alone: what is
48
+ * imported here is resolved on the machine running the backend, not at build time.
49
+ */
50
+ protected dynamicImport(url: string): Promise<unknown>;
51
+ /**
52
+ * Checks that what was loaded provides what is used, so that an incompatible CLI is reported as
53
+ * such instead of failing somewhere in the middle of a request.
54
+ */
55
+ protected toApi(loaded: unknown): CopilotSdkApi | undefined;
56
+ }
57
+ //# sourceMappingURL=copilot-sdk-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot-sdk-loader.d.ts","sourceRoot":"","sources":["../../src/node/copilot-sdk-loader.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,OAAO,EAAO,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAE9F;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B,QAAQ,CAAC,aAAa,EAAE,wBAAwB,CAAC;IACjD,QAAQ,CAAC,iBAAiB,EAAE,wBAAwB,CAAC;CACxD;AAED;;;;;;;;;;;GAWG;AACH,qBACa,gBAAgB;IAGzB,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,iBAAiB,CAAC;IAGjD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAEnC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC;IACrD,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAEzC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC;cAgBpB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAY3D;;OAEG;cACa,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;IAW1E;;;OAGG;IACH,SAAS,CAAC,kBAAkB,IAAI,OAAO;IASvC;;OAEG;IACH,SAAS,CAAC,eAAe,IAAI,OAAO;IAKpC;;;OAGG;IACH,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAItD;;;OAGG;IACH,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,GAAG,aAAa,GAAG,SAAS;CAO9D"}
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2026 EclipseSource GmbH and others.
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.CopilotSdkLoader = void 0;
19
+ const tslib_1 = require("tslib");
20
+ const module_1 = require("module");
21
+ const path_1 = require("path");
22
+ const url_1 = require("url");
23
+ const inversify_1 = require("@theia/core/shared/inversify");
24
+ const core_1 = require("@theia/core");
25
+ const copilot_cli_locator_1 = require("./copilot-cli-locator");
26
+ /**
27
+ * Provides the Copilot SDK that belongs to the Copilot CLI in use.
28
+ *
29
+ * The SDK is not a dependency of this extension. It is published as `@github/copilot-sdk`, but that
30
+ * package depends on the CLI, which is a large proprietary binary that an application must not have
31
+ * to ship, see {@link CopilotCliLocator}. The CLI carries its own copy of the SDK, so the one
32
+ * belonging to the CLI that is actually going to serve the requests is loaded from there. What is used
33
+ * of its API is mirrored in `copilot-sdk-types.ts` rather than taken from the package.
34
+ *
35
+ * An installed `@github/copilot-sdk` is used when the CLI does not carry one, so that an application
36
+ * which does depend on the package keeps working.
37
+ */
38
+ let CopilotSdkLoader = class CopilotSdkLoader {
39
+ /**
40
+ * Loads the SDK, and remembers it for as long as the CLI it belongs to stays the same.
41
+ */
42
+ async load() {
43
+ const cli = await this.cliLocator.resolve();
44
+ if (!this.loaded || this.loadedFrom !== cli) {
45
+ this.loadedFrom = cli;
46
+ this.loaded = this.doLoad(cli);
47
+ // Don't remember a failed load: a different CLI can be configured while we are running.
48
+ this.loaded.catch(() => {
49
+ if (this.loadedFrom === cli) {
50
+ this.loaded = undefined;
51
+ this.loadedFrom = undefined;
52
+ }
53
+ });
54
+ }
55
+ return this.loaded;
56
+ }
57
+ async doLoad(cli) {
58
+ const shipped = (0, path_1.join)((0, path_1.dirname)(cli), 'copilot-sdk', 'index.js');
59
+ const candidate = await this.importShipped(shipped) ?? this.tryImportInstalled();
60
+ const api = this.toApi(candidate);
61
+ if (!api) {
62
+ throw new Error(core_1.nls.localize('theia/ai/copilot/sdkUnusable', 'The GitHub Copilot CLI at {0} does not provide the interface this integration needs. '
63
+ + 'Update it with `npm install -g @github/copilot`.', cli));
64
+ }
65
+ return api;
66
+ }
67
+ /**
68
+ * Imports the copy of the SDK that ships with the CLI. It is an ES module, hence the import by URL.
69
+ */
70
+ async importShipped(entry) {
71
+ try {
72
+ const loaded = await this.dynamicImport((0, url_1.pathToFileURL)(entry).href);
73
+ this.logger.info(`Copilot: using the Copilot SDK at ${entry}.`);
74
+ return loaded;
75
+ }
76
+ catch (error) {
77
+ this.logger.info(`Copilot: no Copilot SDK next to the CLI at ${entry}, falling back to an installed one:`, error);
78
+ return undefined;
79
+ }
80
+ }
81
+ /**
82
+ * Imports an installed SDK if there is one, so that a missing package is reported as the CLI not
83
+ * providing what is needed rather than as a module that cannot be found.
84
+ */
85
+ tryImportInstalled() {
86
+ try {
87
+ return this.importInstalled();
88
+ }
89
+ catch (error) {
90
+ this.logger.info('Copilot: no installed Copilot SDK either:', error);
91
+ return undefined;
92
+ }
93
+ }
94
+ /**
95
+ * Imports an installed `@github/copilot-sdk`, for an application that depends on the package.
96
+ */
97
+ importInstalled() {
98
+ // A real require is needed here: the ambient one is rewritten when the backend is bundled.
99
+ return (0, module_1.createRequire)(__filename)('@github/copilot-sdk');
100
+ }
101
+ /**
102
+ * Dynamic import through a constructed function, so that a bundler leaves it alone: what is
103
+ * imported here is resolved on the machine running the backend, not at build time.
104
+ */
105
+ dynamicImport(url) {
106
+ return new Function('url', 'return import(url)')(url);
107
+ }
108
+ /**
109
+ * Checks that what was loaded provides what is used, so that an incompatible CLI is reported as
110
+ * such instead of failing somewhere in the middle of a request.
111
+ */
112
+ toApi(loaded) {
113
+ const api = loaded;
114
+ if (typeof api?.CopilotClient !== 'function' || typeof api?.RuntimeConnection?.forStdio !== 'function') {
115
+ return undefined;
116
+ }
117
+ return api;
118
+ }
119
+ };
120
+ exports.CopilotSdkLoader = CopilotSdkLoader;
121
+ tslib_1.__decorate([
122
+ (0, inversify_1.inject)(copilot_cli_locator_1.CopilotCliLocator),
123
+ tslib_1.__metadata("design:type", copilot_cli_locator_1.CopilotCliLocator)
124
+ ], CopilotSdkLoader.prototype, "cliLocator", void 0);
125
+ tslib_1.__decorate([
126
+ (0, inversify_1.inject)(core_1.ILogger),
127
+ (0, inversify_1.named)('ai-copilot:CopilotSdkLoader'),
128
+ tslib_1.__metadata("design:type", Object)
129
+ ], CopilotSdkLoader.prototype, "logger", void 0);
130
+ exports.CopilotSdkLoader = CopilotSdkLoader = tslib_1.__decorate([
131
+ (0, inversify_1.injectable)()
132
+ ], CopilotSdkLoader);
133
+ //# sourceMappingURL=copilot-sdk-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot-sdk-loader.js","sourceRoot":"","sources":["../../src/node/copilot-sdk-loader.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,oDAAoD;AACpD,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,mCAAuC;AACvC,+BAAqC;AACrC,6BAAoC;AACpC,4DAAyE;AACzE,sCAA2C;AAC3C,+DAA0D;AAW1D;;;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C,uCAAiB,CAAC;sCACK,uCAAiB;oDAAC;AAG9B;IADlB,IAAA,kBAAM,EAAC,cAAO,CAAC;IAAE,IAAA,iBAAK,EAAC,6BAA6B,CAAC;;gDACnB;2BAN1B,gBAAgB;IAD5B,IAAA,sBAAU,GAAE;GACA,gBAAgB,CAgG5B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=copilot-sdk-loader.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot-sdk-loader.spec.d.ts","sourceRoot":"","sources":["../../src/node/copilot-sdk-loader.spec.ts"],"names":[],"mappings":""}