@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
@@ -0,0 +1,301 @@
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.CopilotSdkLanguageModel = exports.CopilotStreamSink = exports.approveTheiaTools = void 0;
19
+ const ai_core_1 = require("@theia/ai-core");
20
+ const copilot_sdk_mappers_1 = require("./copilot-sdk-mappers");
21
+ /**
22
+ * Answers the permission requests of the CLI for the tools of a request.
23
+ *
24
+ * Only Theia's own tools are declared to the CLI, and those are gated by Theia's tool confirmation
25
+ * already, so a second confirmation by the CLI would ask the user the same question twice. This is
26
+ * the behaviour of the SDK's own `approveAll`, which cannot be used here because it is not imported
27
+ * at runtime.
28
+ *
29
+ * A request that managed policy reserves for an explicit decision is not approved on the user's
30
+ * behalf but denied as unconfirmable. Leaving it unanswered is what the SDK's `no-result` does, and
31
+ * it is only correct when another client is connected that can answer it; here it would leave the
32
+ * turn pending until the request is cancelled.
33
+ */
34
+ const approveTheiaTools = (request, invocation) => {
35
+ if (invocation.managedSettingsEnabled || ('managedApprovalRequired' in request && request.managedApprovalRequired)) {
36
+ return { kind: 'user-not-available' };
37
+ }
38
+ return { kind: 'approve-once' };
39
+ };
40
+ exports.approveTheiaTools = approveTheiaTools;
41
+ /**
42
+ * Upper bound for awaiting that a reported tool call has been consumed before the tool is run.
43
+ */
44
+ const TOOL_CALL_FLUSH_TIMEOUT_MS = 2000;
45
+ /**
46
+ * Collects the stream parts produced by the session events and by the tool handlers, and hands them
47
+ * to the consuming generator as they arrive.
48
+ *
49
+ * A buffer is needed because the parts originate from callbacks rather than from a stream we can
50
+ * await, and because the tool handlers of a turn run while its response is still being produced.
51
+ */
52
+ class CopilotStreamSink {
53
+ constructor() {
54
+ this.queue = [];
55
+ this.flushWaiters = [];
56
+ this.done = false;
57
+ }
58
+ push(part) {
59
+ this.queue.push(part);
60
+ this.wake();
61
+ }
62
+ /**
63
+ * Resolves once everything pushed so far has been taken by the consumer.
64
+ *
65
+ * Needed because a tool call has to be reported before the tool runs: the caller creates the
66
+ * record of the call from the stream, and the tool handler then completes that record. Handing the
67
+ * part over and invoking the handler in the same turn would leave the handler with nothing to
68
+ * complete.
69
+ */
70
+ flush() {
71
+ if (this.queue.length === 0 || this.done) {
72
+ return Promise.resolve();
73
+ }
74
+ return new Promise(resolve => this.flushWaiters.push(resolve));
75
+ }
76
+ /**
77
+ * Ends the stream. A given error is raised to the consumer once the buffered parts are drained.
78
+ */
79
+ finish(error) {
80
+ if (error !== undefined) {
81
+ this.failure = error;
82
+ }
83
+ this.done = true;
84
+ this.wake();
85
+ }
86
+ async *drain() {
87
+ while (true) {
88
+ while (this.queue.length > 0) {
89
+ yield this.queue.shift();
90
+ }
91
+ // Asking for the next part means the consumer is done with the previous ones.
92
+ this.releaseFlushWaiters();
93
+ if (this.done) {
94
+ break;
95
+ }
96
+ await new Promise(resolve => { this.notify = resolve; });
97
+ }
98
+ this.releaseFlushWaiters();
99
+ if (this.failure !== undefined) {
100
+ throw this.failure;
101
+ }
102
+ }
103
+ wake() {
104
+ const resolve = this.notify;
105
+ this.notify = undefined;
106
+ resolve?.();
107
+ }
108
+ releaseFlushWaiters() {
109
+ const waiters = this.flushWaiters.splice(0, this.flushWaiters.length);
110
+ for (const resolve of waiters) {
111
+ resolve();
112
+ }
113
+ }
114
+ }
115
+ exports.CopilotStreamSink = CopilotStreamSink;
116
+ /**
117
+ * Language model implementation for GitHub Copilot backed by the official Copilot
118
+ * CLI via `@github/copilot-sdk`.
119
+ *
120
+ * The CLI is an agent that owns the tool-calling loop, whereas Theia's language model contract
121
+ * expects the caller to drive it. The two are reconciled by handing the tools of the request to the
122
+ * CLI as custom tools whose handlers delegate back to Theia, and by reporting every invocation as a
123
+ * tool call part, so that the conversation and its tool calls are recorded and rendered as usual.
124
+ * None of the CLI's own tools are exposed, so only what Theia provides can run.
125
+ *
126
+ * Structured output is not supported on this path.
127
+ */
128
+ class CopilotSdkLanguageModel {
129
+ constructor(id, model, status, maxRetries, clientProvider, logger) {
130
+ this.id = id;
131
+ this.model = model;
132
+ this.status = status;
133
+ this.maxRetries = maxRetries;
134
+ this.clientProvider = clientProvider;
135
+ this.logger = logger;
136
+ }
137
+ async request(request, cancellationToken) {
138
+ const client = await this.clientProvider();
139
+ const { systemText, prompt } = (0, copilot_sdk_mappers_1.buildSdkPrompt)(request.messages);
140
+ const sink = new CopilotStreamSink();
141
+ const tools = this.createTools(request.tools ?? [], sink);
142
+ this.logger.debug(`Copilot: request with ${tools.length} tools [${tools.map(tool => tool.name).join(', ')}]`);
143
+ const session = await client.createSession({
144
+ model: this.model,
145
+ streaming: true,
146
+ tools,
147
+ // The prompt of the Theia agent belongs into the system message of the session rather than
148
+ // into its user prompt, so that it takes the place of the agent instructions of the CLI.
149
+ systemMessage: (0, copilot_sdk_mappers_1.buildSdkSystemMessage)(systemText),
150
+ // Enable exactly the tools declared above and nothing else: `custom:*` matches the tools of
151
+ // this request, while the built-in tools of the CLI and any MCP tools stay disabled, so that
152
+ // Theia remains in control of what runs on the host. An empty list would match nothing and
153
+ // would disable the declared tools as well.
154
+ availableTools: ['custom:*'],
155
+ // The declared tools are Theia's own and are already gated by its tool confirmation.
156
+ onPermissionRequest: exports.approveTheiaTools
157
+ });
158
+ return { stream: this.streamResponse(client, session, prompt, sink, cancellationToken) };
159
+ }
160
+ /**
161
+ * Maps the tools of the request onto tools of the CLI, reporting each invocation to the stream.
162
+ */
163
+ createTools(tools, sink) {
164
+ return tools.map(tool => ({
165
+ name: tool.name,
166
+ description: tool.description,
167
+ parameters: tool.parameters,
168
+ // Theia confirms tool invocations itself, so the CLI must not prompt on top of that.
169
+ skipPermission: true,
170
+ handler: async (args, invocation) => {
171
+ // Theia's tool handlers take the raw argument string of the model.
172
+ const argumentsString = JSON.stringify(args ?? {});
173
+ sink.push({
174
+ tool_calls: [{ id: invocation.toolCallId, function: { name: tool.name, arguments: argumentsString }, finished: false }]
175
+ });
176
+ // The handler completes the record of the call that the caller creates from the part
177
+ // above, so the part has to be consumed before the tool runs. The wait is bounded so
178
+ // that a consumer which stops reading cannot hold the tool call forever.
179
+ await Promise.race([sink.flush(), this.delay(TOOL_CALL_FLUSH_TIMEOUT_MS)]);
180
+ try {
181
+ // Passing the call id lets the caller correlate the invocation with the part above,
182
+ // instead of having to fall back to matching on the tool name and its arguments.
183
+ const result = await tool.handler(argumentsString, { toolCallId: invocation.toolCallId });
184
+ // The structured result is kept for the stream, so that the UI can render e.g. the
185
+ // HTML of an MCP app, while the model is handed a readable serialization of it.
186
+ sink.push({
187
+ tool_calls: [{ id: invocation.toolCallId, function: { name: tool.name, arguments: argumentsString }, finished: true, result }]
188
+ });
189
+ return (0, ai_core_1.formatToolCallContentForModel)(result);
190
+ }
191
+ catch (error) {
192
+ const message = error instanceof Error ? error.message : String(error);
193
+ sink.push({
194
+ tool_calls: [{
195
+ id: invocation.toolCallId,
196
+ function: { name: tool.name, arguments: argumentsString },
197
+ finished: true,
198
+ result: `Error: ${message}`
199
+ }]
200
+ });
201
+ // Report the failure to the agent instead of failing the turn, so that it can react.
202
+ return { error: message };
203
+ }
204
+ }
205
+ }));
206
+ }
207
+ delay(ms) {
208
+ return new Promise(resolve => setTimeout(resolve, ms));
209
+ }
210
+ async *streamResponse(client, session, prompt, sink, cancellationToken) {
211
+ let inputTokens;
212
+ let outputTokens;
213
+ const disposables = [];
214
+ disposables.push(session.on('assistant.message_delta', event => {
215
+ if (event.data.deltaContent) {
216
+ sink.push({ content: event.data.deltaContent });
217
+ }
218
+ }));
219
+ disposables.push(session.on('assistant.reasoning_delta', event => {
220
+ if (event.data.deltaContent) {
221
+ sink.push({ thought: event.data.deltaContent, signature: '' });
222
+ }
223
+ }));
224
+ disposables.push(session.on('assistant.message', event => {
225
+ if (typeof event.data.outputTokens === 'number') {
226
+ outputTokens = event.data.outputTokens;
227
+ }
228
+ }));
229
+ disposables.push(session.on('assistant.usage', event => {
230
+ if (typeof event.data.inputTokens === 'number') {
231
+ inputTokens = event.data.inputTokens;
232
+ }
233
+ if (typeof event.data.outputTokens === 'number') {
234
+ outputTokens = event.data.outputTokens;
235
+ }
236
+ }));
237
+ disposables.push(session.on('session.idle', () => sink.finish()));
238
+ disposables.push(session.on('session.error', event => {
239
+ // The CLI can report a terminal error (auth, quota, rate limit, context
240
+ // limit, ...) without a following `session.idle`. Surface it as a stream
241
+ // failure so the request rejects instead of hanging forever.
242
+ const data = event.data;
243
+ const detail = data.statusCode !== undefined ? ` (${data.errorType}, status ${data.statusCode})` : ` (${data.errorType})`;
244
+ const error = new Error(`Copilot request failed${detail}: ${data.message}`);
245
+ if (data.stack) {
246
+ error.stack = data.stack;
247
+ }
248
+ sink.finish(error);
249
+ }));
250
+ const cancelListener = cancellationToken?.onCancellationRequested(() => {
251
+ session.abort().catch(() => { });
252
+ sink.finish();
253
+ });
254
+ try {
255
+ if (cancellationToken?.isCancellationRequested) {
256
+ // Already cancelled before we started: don't bother sending.
257
+ await session.abort().catch(() => { });
258
+ sink.finish();
259
+ }
260
+ else {
261
+ // Deliberately not awaited: the turn only completes after the tool loop has run, and
262
+ // its parts have to be yielded while that happens.
263
+ session.send({ prompt }).catch(error => sink.finish(error));
264
+ }
265
+ yield* sink.drain();
266
+ if (inputTokens !== undefined || outputTokens !== undefined) {
267
+ yield { input_tokens: inputTokens ?? 0, output_tokens: outputTokens ?? 0 };
268
+ }
269
+ }
270
+ finally {
271
+ for (const dispose of disposables) {
272
+ dispose();
273
+ }
274
+ cancelListener?.dispose();
275
+ await this.discardSession(client, session);
276
+ }
277
+ }
278
+ /**
279
+ * Ends the session of a request and removes what it persisted.
280
+ *
281
+ * Disconnecting only releases the session in memory and keeps it stored for a later resumption,
282
+ * which Theia never does: it drives the conversation itself and starts a fresh session per
283
+ * request. Without the deletion, every request would leave a session behind in the Copilot home.
284
+ */
285
+ async discardSession(client, session) {
286
+ try {
287
+ await session.disconnect();
288
+ }
289
+ catch (error) {
290
+ this.logger.warn('Copilot SDK: failed to disconnect session:', error);
291
+ }
292
+ try {
293
+ await client.deleteSession(session.sessionId);
294
+ }
295
+ catch (error) {
296
+ this.logger.warn(`Copilot SDK: failed to delete session ${session.sessionId}:`, error);
297
+ }
298
+ }
299
+ }
300
+ exports.CopilotSdkLanguageModel = CopilotSdkLanguageModel;
301
+ //# sourceMappingURL=copilot-sdk-language-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot-sdk-language-model.js","sourceRoot":"","sources":["../../src/node/copilot-sdk-language-model.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,4CAQwB;AAGxB,+DAA8E;AAE9E;;;;;;;;;;;;GAYG;AACI,MAAM,iBAAiB,GAAsB,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE;IACxE,IAAI,UAAU,CAAC,sBAAsB,IAAI,CAAC,yBAAyB,IAAI,OAAO,IAAI,OAAO,CAAC,uBAAuB,CAAC,EAAE,CAAC;QACjH,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,CAAC;IAC1C,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;AACpC,CAAC,CAAC;AALW,QAAA,iBAAiB,qBAK5B;AAEF;;GAEG;AACH,MAAM,0BAA0B,GAAG,IAAI,CAAC;AAExC;;;;;;GAMG;AACH,MAAa,iBAAiB;IAA9B;QAEuB,UAAK,GAAsC,EAAE,CAAC;QAC9C,iBAAY,GAAsB,EAAE,CAAC;QAE9C,SAAI,GAAG,KAAK,CAAC;IAgE3B,CAAC;IA7DG,IAAI,CAAC,IAAqC;QACtC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,EAAE,CAAC;IAChB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK;QACD,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACvC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC7B,CAAC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appingURL=copilot-sdk-language-model.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot-sdk-language-model.spec.d.ts","sourceRoot":"","sources":["../../src/node/copilot-sdk-language-model.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,302 @@
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 deleted;
51
+ const listeners = new Map();
52
+ const session = {
53
+ sessionId: 'test-session',
54
+ on: (event, handler) => {
55
+ listeners.set(event, handler);
56
+ return () => listeners.delete(event);
57
+ },
58
+ send: async (message) => {
59
+ prompt = message.prompt;
60
+ listeners.get('session.idle')?.({});
61
+ },
62
+ abort: async () => { },
63
+ disconnect: async () => { }
64
+ };
65
+ const client = {
66
+ createSession: async (sessionConfig) => {
67
+ config = sessionConfig;
68
+ return session;
69
+ },
70
+ deleteSession: async (sessionId) => { deleted = sessionId; }
71
+ };
72
+ const model = new TestableCopilotSdkLanguageModel();
73
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
+ model.clientProvider = async () => client;
75
+ const response = await model.request(request);
76
+ for await (const part of response.stream) {
77
+ (0, chai_1.expect)(part).to.exist;
78
+ }
79
+ return { config, prompt, deleted };
80
+ }
81
+ }
82
+ function toolRequest(name, handler) {
83
+ return {
84
+ id: name,
85
+ name,
86
+ description: `the ${name} tool`,
87
+ parameters: { type: 'object', properties: { path: { type: 'string' } } },
88
+ handler
89
+ };
90
+ }
91
+ /**
92
+ * Runs a tool invocation the way the caller does, with the stream being consumed concurrently.
93
+ * The handler waits for its reported call to be consumed, so nothing may invoke it in isolation.
94
+ */
95
+ async function invokeWhileConsuming(sink, invoke) {
96
+ const parts = [];
97
+ const consumer = (async () => {
98
+ for await (const part of sink.drain()) {
99
+ parts.push(part);
100
+ }
101
+ })();
102
+ const result = await invoke();
103
+ sink.finish();
104
+ await consumer;
105
+ return { result, parts };
106
+ }
107
+ async function collect(sink) {
108
+ const parts = [];
109
+ for await (const part of sink.drain()) {
110
+ parts.push(part);
111
+ }
112
+ return parts;
113
+ }
114
+ function toolCalls(part) {
115
+ return part.tool_calls;
116
+ }
117
+ describe('CopilotSdkLanguageModel - createTools', () => {
118
+ const model = new TestableCopilotSdkLanguageModel();
119
+ it('should declare the tools of the request to the CLI', () => {
120
+ const tools = model.callCreateTools([toolRequest('readFile', async () => 'content')], new copilot_sdk_language_model_1.CopilotStreamSink());
121
+ (0, chai_1.expect)(tools).to.have.lengthOf(1);
122
+ (0, chai_1.expect)(tools[0].name).to.equal('readFile');
123
+ (0, chai_1.expect)(tools[0].description).to.equal('the readFile tool');
124
+ (0, chai_1.expect)(tools[0].parameters).to.deep.equal({ type: 'object', properties: { path: { type: 'string' } } });
125
+ // Theia confirms tool invocations itself, so the CLI must not prompt again.
126
+ (0, chai_1.expect)(tools[0].skipPermission).to.be.true;
127
+ });
128
+ it('should pass the raw argument string to the handler of the request', async () => {
129
+ let received;
130
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
131
+ const tools = model.callCreateTools([toolRequest('readFile', async (args) => { received = args; return 'content'; })], sink);
132
+ const { result } = await invokeWhileConsuming(sink, () => tools[0].handler({ path: 'a.ts' }, { sessionId: 's', toolCallId: 'call_1', toolName: 'readFile', arguments: {} }));
133
+ (0, chai_1.expect)(received).to.equal(JSON.stringify({ path: 'a.ts' }));
134
+ (0, chai_1.expect)(result).to.equal('content');
135
+ });
136
+ it('should report the invocation as an unfinished and then a finished tool call', async () => {
137
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
138
+ const tools = model.callCreateTools([toolRequest('readFile', async () => 'content')], sink);
139
+ const { parts } = await invokeWhileConsuming(sink, () => tools[0].handler({ path: 'a.ts' }, { sessionId: 's', toolCallId: 'call_1', toolName: 'readFile', arguments: {} }));
140
+ (0, chai_1.expect)(parts).to.have.lengthOf(2);
141
+ (0, chai_1.expect)(toolCalls(parts[0])[0]).to.deep.include({ id: 'call_1', finished: false });
142
+ (0, chai_1.expect)(toolCalls(parts[0])[0].function).to.deep.equal({ name: 'readFile', arguments: JSON.stringify({ path: 'a.ts' }) });
143
+ (0, chai_1.expect)(toolCalls(parts[1])[0]).to.deep.include({ id: 'call_1', finished: true, result: 'content' });
144
+ });
145
+ it('should report a failing tool to the stream and to the agent instead of throwing', async () => {
146
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
147
+ const tools = model.callCreateTools([toolRequest('readFile', async () => { throw new Error('no such file'); })], sink);
148
+ const { result, parts } = await invokeWhileConsuming(sink, () => tools[0].handler({ path: 'missing.ts' }, { sessionId: 's', toolCallId: 'call_1', toolName: 'readFile', arguments: {} }));
149
+ (0, chai_1.expect)(result).to.deep.equal({ error: 'no such file' });
150
+ (0, chai_1.expect)(toolCalls(parts[1])[0]).to.deep.include({ id: 'call_1', finished: true, result: 'Error: no such file' });
151
+ });
152
+ it('should return an empty tool list when the request has no tools', () => {
153
+ (0, chai_1.expect)(model.callCreateTools([], new copilot_sdk_language_model_1.CopilotStreamSink())).to.be.empty;
154
+ });
155
+ });
156
+ describe('CopilotSdkLanguageModel - session configuration', () => {
157
+ const model = new TestableCopilotSdkLanguageModel();
158
+ function requestWith(tools) {
159
+ return { messages: [{ actor: 'user', type: 'text', text: 'hi' }], tools };
160
+ }
161
+ it('should enable the declared tools and nothing else', async () => {
162
+ const config = await model.captureSessionConfig(requestWith([toolRequest('readFile', async () => 'content')]));
163
+ // An empty list would match nothing and would disable the declared tools as well.
164
+ (0, chai_1.expect)(config.availableTools).to.deep.equal(['custom:*']);
165
+ (0, chai_1.expect)(config.tools.map(tool => tool.name)).to.deep.equal(['readFile']);
166
+ });
167
+ it('should declare every tool of the request', async () => {
168
+ const config = await model.captureSessionConfig(requestWith([
169
+ toolRequest('readFile', async () => 'a'),
170
+ toolRequest('listFiles', async () => 'b')
171
+ ]));
172
+ (0, chai_1.expect)(config.tools.map(tool => tool.name)).to.deep.equal(['readFile', 'listFiles']);
173
+ });
174
+ it('should still exclude the built-in tools when the request has none', async () => {
175
+ const config = await model.captureSessionConfig(requestWith([]));
176
+ (0, chai_1.expect)(config.availableTools).to.deep.equal(['custom:*']);
177
+ (0, chai_1.expect)(config.tools).to.be.empty;
178
+ });
179
+ });
180
+ describe('approveTheiaTools', () => {
181
+ const customToolRequest = { kind: 'custom-tool', toolName: 'readFile' };
182
+ it('should approve a request for a tool Theia declared and confirmed itself', () => {
183
+ (0, chai_1.expect)((0, copilot_sdk_language_model_1.approveTheiaTools)(customToolRequest, { sessionId: 'test-session' })).to.deep.equal({ kind: 'approve-once' });
184
+ });
185
+ it('should report that nobody can confirm a request managed policy reserves for a decision', () => {
186
+ const request = { ...customToolRequest, managedApprovalRequired: true };
187
+ // Not `no-result`: that leaves the request pending for another client, and there is none here.
188
+ (0, chai_1.expect)((0, copilot_sdk_language_model_1.approveTheiaTools)(request, { sessionId: 'test-session' })).to.deep.equal({ kind: 'user-not-available' });
189
+ });
190
+ it('should report the same when the machine has managed settings enabled at all', () => {
191
+ (0, chai_1.expect)((0, copilot_sdk_language_model_1.approveTheiaTools)(customToolRequest, { sessionId: 'test-session', managedSettingsEnabled: true }))
192
+ .to.deep.equal({ kind: 'user-not-available' });
193
+ });
194
+ });
195
+ describe('CopilotSdkLanguageModel - turn', () => {
196
+ const model = new TestableCopilotSdkLanguageModel();
197
+ const request = {
198
+ messages: [
199
+ { actor: 'system', type: 'text', text: 'You are a helpful assistant.' },
200
+ { actor: 'user', type: 'text', text: 'hi' }
201
+ ]
202
+ };
203
+ it('should configure the system prompt as the system message of the session', async () => {
204
+ const { config } = await model.captureTurn(request);
205
+ (0, chai_1.expect)(config.systemMessage).to.deep.include({ mode: 'customize', content: 'You are a helpful assistant.' });
206
+ });
207
+ it('should send the user turn without the system prompt in it', async () => {
208
+ const { prompt } = await model.captureTurn(request);
209
+ (0, chai_1.expect)(prompt).to.equal('hi');
210
+ });
211
+ it('should delete the session it created, which the CLI would otherwise keep', async () => {
212
+ const { deleted } = await model.captureTurn(request);
213
+ (0, chai_1.expect)(deleted).to.equal('test-session');
214
+ });
215
+ });
216
+ describe('CopilotStreamSink', () => {
217
+ it('should yield parts pushed before draining', async () => {
218
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
219
+ sink.push({ content: 'a' });
220
+ sink.push({ content: 'b' });
221
+ sink.finish();
222
+ (0, chai_1.expect)(await collect(sink)).to.deep.equal([{ content: 'a' }, { content: 'b' }]);
223
+ });
224
+ it('should yield parts pushed while draining', async () => {
225
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
226
+ const collected = collect(sink);
227
+ sink.push({ content: 'a' });
228
+ await Promise.resolve();
229
+ sink.push({ content: 'b' });
230
+ sink.finish();
231
+ (0, chai_1.expect)(await collected).to.deep.equal([{ content: 'a' }, { content: 'b' }]);
232
+ });
233
+ it('should raise the failure after the buffered parts have been drained', async () => {
234
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
235
+ sink.push({ content: 'partial' });
236
+ sink.finish(new Error('session failed'));
237
+ const parts = [];
238
+ let error;
239
+ try {
240
+ for await (const part of sink.drain()) {
241
+ parts.push(part);
242
+ }
243
+ }
244
+ catch (caught) {
245
+ error = caught;
246
+ }
247
+ (0, chai_1.expect)(parts).to.deep.equal([{ content: 'partial' }]);
248
+ (0, chai_1.expect)(error.message).to.equal('session failed');
249
+ });
250
+ it('should end without parts when finished immediately', async () => {
251
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
252
+ sink.finish();
253
+ (0, chai_1.expect)(await collect(sink)).to.be.empty;
254
+ });
255
+ });
256
+ describe('CopilotSdkLanguageModel - tool call ordering', () => {
257
+ const model = new TestableCopilotSdkLanguageModel();
258
+ const invocation = { sessionId: 's', toolCallId: 'call_1', toolName: 'readFile', arguments: {} };
259
+ it('should report the call before running the tool, so the caller can record it first', async () => {
260
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
261
+ const observed = [];
262
+ const tools = model.callCreateTools([toolRequest('readFile', async () => {
263
+ observed.push('tool ran');
264
+ return 'content';
265
+ })], sink);
266
+ const invoked = tools[0].handler({ path: 'a.ts' }, invocation);
267
+ // The consumer has not taken the part yet, so the tool must not have run.
268
+ (0, chai_1.expect)(observed).to.be.empty;
269
+ const parts = [];
270
+ const consumer = (async () => {
271
+ for await (const part of sink.drain()) {
272
+ parts.push(part);
273
+ observed.push('part consumed');
274
+ }
275
+ })();
276
+ await invoked;
277
+ sink.finish();
278
+ await consumer;
279
+ (0, chai_1.expect)(observed[0]).to.equal('part consumed');
280
+ (0, chai_1.expect)(observed).to.contain('tool ran');
281
+ (0, chai_1.expect)(toolCalls(parts[0])[0]).to.deep.include({ id: 'call_1', finished: false });
282
+ });
283
+ it('should pass the call id to the handler so the caller can correlate it', async () => {
284
+ const sink = new copilot_sdk_language_model_1.CopilotStreamSink();
285
+ let receivedId;
286
+ const tools = model.callCreateTools([toolRequest('readFile', async (_args, ctx) => {
287
+ receivedId = ctx?.toolCallId;
288
+ return 'content';
289
+ })], sink);
290
+ const invoked = tools[0].handler({ path: 'a.ts' }, invocation);
291
+ const consumer = (async () => {
292
+ for await (const part of sink.drain()) {
293
+ (0, chai_1.expect)(part).to.exist;
294
+ }
295
+ })();
296
+ await invoked;
297
+ sink.finish();
298
+ await consumer;
299
+ (0, chai_1.expect)(receivedId).to.equal('call_1');
300
+ });
301
+ });
302
+ //# 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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