@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.
- package/README.md +86 -14
- package/lib/browser/copilot-auth-dialog.d.ts.map +1 -1
- package/lib/browser/copilot-auth-dialog.js +12 -4
- package/lib/browser/copilot-auth-dialog.js.map +1 -1
- package/lib/browser/copilot-frontend-application-contribution.d.ts +15 -1
- package/lib/browser/copilot-frontend-application-contribution.d.ts.map +1 -1
- package/lib/browser/copilot-frontend-application-contribution.js +52 -24
- package/lib/browser/copilot-frontend-application-contribution.js.map +1 -1
- package/lib/common/copilot-auth-service.d.ts +27 -24
- package/lib/common/copilot-auth-service.d.ts.map +1 -1
- package/lib/common/copilot-language-models-manager.d.ts +3 -21
- package/lib/common/copilot-language-models-manager.d.ts.map +1 -1
- package/lib/common/copilot-language-models-manager.js +1 -13
- package/lib/common/copilot-language-models-manager.js.map +1 -1
- package/lib/common/copilot-preferences.d.ts +1 -0
- package/lib/common/copilot-preferences.d.ts.map +1 -1
- package/lib/common/copilot-preferences.js +24 -6
- package/lib/common/copilot-preferences.js.map +1 -1
- package/lib/common/index.d.ts +0 -1
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +0 -1
- package/lib/common/index.js.map +1 -1
- package/lib/node/copilot-auth-service-impl.d.ts +25 -16
- package/lib/node/copilot-auth-service-impl.d.ts.map +1 -1
- package/lib/node/copilot-auth-service-impl.js +67 -183
- package/lib/node/copilot-auth-service-impl.js.map +1 -1
- package/lib/node/copilot-auth-service-impl.spec.js +104 -168
- package/lib/node/copilot-auth-service-impl.spec.js.map +1 -1
- package/lib/node/copilot-backend-module.d.ts.map +1 -1
- package/lib/node/copilot-backend-module.js +10 -2
- package/lib/node/copilot-backend-module.js.map +1 -1
- package/lib/node/copilot-cli-auth-provider.d.ts +146 -0
- package/lib/node/copilot-cli-auth-provider.d.ts.map +1 -0
- package/lib/node/copilot-cli-auth-provider.js +430 -0
- package/lib/node/copilot-cli-auth-provider.js.map +1 -0
- package/lib/node/copilot-cli-auth-provider.spec.d.ts +2 -0
- package/lib/node/copilot-cli-auth-provider.spec.d.ts.map +1 -0
- package/lib/node/copilot-cli-auth-provider.spec.js +249 -0
- package/lib/node/copilot-cli-auth-provider.spec.js.map +1 -0
- package/lib/node/copilot-cli-locator.d.ts +120 -0
- package/lib/node/copilot-cli-locator.d.ts.map +1 -0
- package/lib/node/copilot-cli-locator.js +348 -0
- package/lib/node/copilot-cli-locator.js.map +1 -0
- package/lib/node/copilot-cli-locator.spec.d.ts +2 -0
- package/lib/node/copilot-cli-locator.spec.d.ts.map +1 -0
- package/lib/node/copilot-cli-locator.spec.js +327 -0
- package/lib/node/copilot-cli-locator.spec.js.map +1 -0
- package/lib/node/copilot-credential-store.d.ts +45 -0
- package/lib/node/copilot-credential-store.d.ts.map +1 -0
- package/lib/node/copilot-credential-store.js +96 -0
- package/lib/node/copilot-credential-store.js.map +1 -0
- package/lib/node/copilot-credential-store.spec.d.ts +2 -0
- package/lib/node/copilot-credential-store.spec.d.ts.map +1 -0
- package/lib/node/copilot-credential-store.spec.js +93 -0
- package/lib/node/copilot-credential-store.spec.js.map +1 -0
- package/lib/node/copilot-language-models-manager-impl.d.ts +20 -18
- package/lib/node/copilot-language-models-manager-impl.d.ts.map +1 -1
- package/lib/node/copilot-language-models-manager-impl.js +39 -67
- package/lib/node/copilot-language-models-manager-impl.js.map +1 -1
- package/lib/node/copilot-language-models-manager-impl.spec.d.ts +2 -0
- package/lib/node/copilot-language-models-manager-impl.spec.d.ts.map +1 -0
- package/lib/node/copilot-language-models-manager-impl.spec.js +119 -0
- package/lib/node/copilot-language-models-manager-impl.spec.js.map +1 -0
- package/lib/node/copilot-runtime-env.d.ts +20 -0
- package/lib/node/copilot-runtime-env.d.ts.map +1 -0
- package/lib/node/copilot-runtime-env.js +49 -0
- package/lib/node/copilot-runtime-env.js.map +1 -0
- package/lib/node/copilot-sdk-client-provider.d.ts +103 -0
- package/lib/node/copilot-sdk-client-provider.d.ts.map +1 -0
- package/lib/node/copilot-sdk-client-provider.js +247 -0
- package/lib/node/copilot-sdk-client-provider.js.map +1 -0
- package/lib/node/copilot-sdk-client-provider.spec.d.ts +2 -0
- package/lib/node/copilot-sdk-client-provider.spec.d.ts.map +1 -0
- package/lib/node/copilot-sdk-client-provider.spec.js +215 -0
- package/lib/node/copilot-sdk-client-provider.spec.js.map +1 -0
- package/lib/node/copilot-sdk-language-model.d.ts +85 -0
- package/lib/node/copilot-sdk-language-model.d.ts.map +1 -0
- package/lib/node/copilot-sdk-language-model.js +301 -0
- package/lib/node/copilot-sdk-language-model.js.map +1 -0
- package/lib/node/copilot-sdk-language-model.spec.d.ts +2 -0
- package/lib/node/copilot-sdk-language-model.spec.d.ts.map +1 -0
- package/lib/node/copilot-sdk-language-model.spec.js +302 -0
- package/lib/node/copilot-sdk-language-model.spec.js.map +1 -0
- package/lib/node/copilot-sdk-loader.d.ts +57 -0
- package/lib/node/copilot-sdk-loader.d.ts.map +1 -0
- package/lib/node/copilot-sdk-loader.js +133 -0
- package/lib/node/copilot-sdk-loader.js.map +1 -0
- package/lib/node/copilot-sdk-loader.spec.d.ts +2 -0
- package/lib/node/copilot-sdk-loader.spec.d.ts.map +1 -0
- package/lib/node/copilot-sdk-loader.spec.js +113 -0
- package/lib/node/copilot-sdk-loader.spec.js.map +1 -0
- package/lib/node/copilot-sdk-mappers.d.ts +49 -0
- package/lib/node/copilot-sdk-mappers.d.ts.map +1 -0
- package/lib/node/copilot-sdk-mappers.js +147 -0
- package/lib/node/copilot-sdk-mappers.js.map +1 -0
- package/lib/node/copilot-sdk-mappers.spec.d.ts +2 -0
- package/lib/node/copilot-sdk-mappers.spec.d.ts.map +1 -0
- package/lib/node/copilot-sdk-mappers.spec.js +133 -0
- package/lib/node/copilot-sdk-mappers.spec.js.map +1 -0
- package/lib/node/copilot-sdk-types.d.ts +198 -0
- package/lib/node/copilot-sdk-types.d.ts.map +1 -0
- package/lib/{common/copilot-oauth-config.js → node/copilot-sdk-types.js} +2 -13
- package/lib/node/copilot-sdk-types.js.map +1 -0
- package/lib/node/index.d.ts +9 -1
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +9 -1
- package/lib/node/index.js.map +1 -1
- package/package.json +4 -6
- package/src/browser/copilot-auth-dialog.tsx +12 -8
- package/src/browser/copilot-frontend-application-contribution.ts +62 -29
- package/src/common/copilot-auth-service.ts +28 -24
- package/src/common/copilot-language-models-manager.ts +3 -28
- package/src/common/copilot-preferences.ts +24 -5
- package/src/common/index.ts +0 -1
- package/src/node/copilot-auth-service-impl.spec.ts +122 -207
- package/src/node/copilot-auth-service-impl.ts +63 -218
- package/src/node/copilot-backend-module.ts +11 -2
- package/src/node/copilot-cli-auth-provider.spec.ts +315 -0
- package/src/node/copilot-cli-auth-provider.ts +444 -0
- package/src/node/copilot-cli-locator.spec.ts +386 -0
- package/src/node/copilot-cli-locator.ts +363 -0
- package/src/node/copilot-credential-store.spec.ts +106 -0
- package/src/node/copilot-credential-store.ts +99 -0
- package/src/node/copilot-language-models-manager-impl.spec.ts +137 -0
- package/src/node/copilot-language-models-manager-impl.ts +51 -85
- package/src/node/copilot-runtime-env.ts +46 -0
- package/src/node/copilot-sdk-client-provider.spec.ts +253 -0
- package/src/node/copilot-sdk-client-provider.ts +241 -0
- package/src/node/copilot-sdk-language-model.spec.ts +363 -0
- package/src/node/copilot-sdk-language-model.ts +329 -0
- package/src/node/copilot-sdk-loader.spec.ts +126 -0
- package/src/node/copilot-sdk-loader.ts +142 -0
- package/src/node/copilot-sdk-mappers.spec.ts +151 -0
- package/src/node/copilot-sdk-mappers.ts +161 -0
- package/src/node/copilot-sdk-types.ts +276 -0
- package/src/node/index.ts +9 -1
- package/lib/common/copilot-oauth-config.d.ts +0 -33
- package/lib/common/copilot-oauth-config.d.ts.map +0 -1
- package/lib/common/copilot-oauth-config.js.map +0 -1
- package/lib/node/copilot-language-model.d.ts +0 -34
- package/lib/node/copilot-language-model.d.ts.map +0 -1
- package/lib/node/copilot-language-model.js +0 -236
- package/lib/node/copilot-language-model.js.map +0 -1
- package/lib/node/copilot-language-model.spec.d.ts +0 -2
- package/lib/node/copilot-language-model.spec.d.ts.map +0 -1
- package/lib/node/copilot-language-model.spec.js +0 -89
- package/lib/node/copilot-language-model.spec.js.map +0 -1
- package/src/common/copilot-oauth-config.ts +0 -55
- package/src/node/copilot-language-model.spec.ts +0 -106
- package/src/node/copilot-language-model.ts +0 -273
|
@@ -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;;;;;;;;;;;GAWG;AAEI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAWzB;;OAEG;IACH,KAAK,CAAC,IAAI;QACN,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QAC5C,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;YAC1C,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;YACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC/B,wFAAwF;YACxF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;gBACnB,IAAI,IAAI,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;oBAC1B,IAAI,CAAC,MAAM,GAAG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AK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2CAA2C,EAAE,KAAK,CAAC,CAAC;YACrE,OAAO,SAAS,CAAC;QACrB,CAAC;IACL,CAAC;IAED;;OAEG;IACO,eAAe;QACrB,2FAA2F;QAC3F,OAAO,IAAA,sBAAa,EAAC,UAAU,CAAC,CAAC,qBAAqB,CAAC,CAAC;IAC5D,CAAC;IAED;;;OAGG;IACO,aAAa,CAAC,GAAW;QAC/B,OAAO,IAAI,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC,GAAG,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,MAAe;QAC3B,MAAM,GAAG,GAAG,MAAmC,CAAC;QAChD,IAAI,OAAO,GAAG,EAAE,aAAa,KAAK,UAAU,IAAI,OAAO,GAAG,EAAE,iBAAiB,EAAE,QAAQ,KAAK,UAAU,EAAE,CAAC;YACrG,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;CACJ,CAAA;AAhGY,4CAAgB;AAGN;IADlB,IAAA,kBAAM,EAAC,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 @@
|
|
|
1
|
+
{"version":3,"file":"copilot-sdk-loader.spec.d.ts","sourceRoot":"","sources":["../../src/node/copilot-sdk-loader.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,113 @@
|
|
|
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 path_1 = require("path");
|
|
20
|
+
const mock_logger_1 = require("@theia/core/lib/common/test/mock-logger");
|
|
21
|
+
const copilot_sdk_loader_1 = require("./copilot-sdk-loader");
|
|
22
|
+
/** What the loader checks for before accepting a module as the SDK. */
|
|
23
|
+
const usableSdk = {
|
|
24
|
+
CopilotClient: function CopilotClient() { },
|
|
25
|
+
RuntimeConnection: { forStdio: () => ({ kind: 'stdio' }) }
|
|
26
|
+
};
|
|
27
|
+
class TestableCopilotSdkLoader extends copilot_sdk_loader_1.CopilotSdkLoader {
|
|
28
|
+
constructor(clis) {
|
|
29
|
+
super();
|
|
30
|
+
this.clis = clis;
|
|
31
|
+
this.importedFromCli = [];
|
|
32
|
+
let call = 0;
|
|
33
|
+
Object.assign(this, {
|
|
34
|
+
logger: new mock_logger_1.MockLogger(),
|
|
35
|
+
cliLocator: { resolve: async () => this.clis[Math.min(call++, this.clis.length - 1)] }
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async importShipped(entry) {
|
|
39
|
+
this.importedFromCli.push(entry);
|
|
40
|
+
return this.shipped;
|
|
41
|
+
}
|
|
42
|
+
importInstalled() {
|
|
43
|
+
if (this.installedFailure) {
|
|
44
|
+
throw this.installedFailure;
|
|
45
|
+
}
|
|
46
|
+
return this.installed;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
describe('CopilotSdkLoader', () => {
|
|
50
|
+
const cli = (0, path_1.join)('/opt', 'copilot', 'copilot');
|
|
51
|
+
it('should load the SDK that ships with the CLI', async () => {
|
|
52
|
+
const loader = new TestableCopilotSdkLoader([cli]);
|
|
53
|
+
loader.shipped = usableSdk;
|
|
54
|
+
(0, chai_1.expect)(await loader.load()).to.equal(usableSdk);
|
|
55
|
+
(0, chai_1.expect)(loader.importedFromCli).to.deep.equal([(0, path_1.join)('/opt', 'copilot', 'copilot-sdk', 'index.js')]);
|
|
56
|
+
});
|
|
57
|
+
it('should fall back to an installed SDK when the CLI does not carry one', async () => {
|
|
58
|
+
const loader = new TestableCopilotSdkLoader([cli]);
|
|
59
|
+
loader.installed = usableSdk;
|
|
60
|
+
(0, chai_1.expect)(await loader.load()).to.equal(usableSdk);
|
|
61
|
+
});
|
|
62
|
+
it('should report the CLI when neither it nor an installation provides the SDK', async () => {
|
|
63
|
+
const loader = new TestableCopilotSdkLoader([cli]);
|
|
64
|
+
loader.installedFailure = new Error("Cannot find module '@github/copilot-sdk'");
|
|
65
|
+
try {
|
|
66
|
+
await loader.load();
|
|
67
|
+
chai_1.expect.fail('should have rejected');
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
// The module resolution failure is of no use to the user, the CLI to update is.
|
|
71
|
+
(0, chai_1.expect)(String(error)).to.contain(cli);
|
|
72
|
+
(0, chai_1.expect)(String(error)).to.not.contain('Cannot find module');
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
it('should reject an SDK that does not provide what is used', async () => {
|
|
76
|
+
const loader = new TestableCopilotSdkLoader([cli]);
|
|
77
|
+
loader.shipped = { CopilotClient: function () { } };
|
|
78
|
+
try {
|
|
79
|
+
await loader.load();
|
|
80
|
+
chai_1.expect.fail('should have rejected');
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
(0, chai_1.expect)(String(error)).to.contain(cli);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
it('should load once for as long as the CLI stays the same', async () => {
|
|
87
|
+
const loader = new TestableCopilotSdkLoader([cli]);
|
|
88
|
+
loader.shipped = usableSdk;
|
|
89
|
+
await loader.load();
|
|
90
|
+
await loader.load();
|
|
91
|
+
(0, chai_1.expect)(loader.importedFromCli).to.have.lengthOf(1);
|
|
92
|
+
});
|
|
93
|
+
it('should load again when a different CLI serves the requests', async () => {
|
|
94
|
+
const other = (0, path_1.join)('/usr', 'local', 'copilot');
|
|
95
|
+
const loader = new TestableCopilotSdkLoader([cli, other]);
|
|
96
|
+
loader.shipped = usableSdk;
|
|
97
|
+
await loader.load();
|
|
98
|
+
await loader.load();
|
|
99
|
+
(0, chai_1.expect)(loader.importedFromCli).to.deep.equal([
|
|
100
|
+
(0, path_1.join)('/opt', 'copilot', 'copilot-sdk', 'index.js'),
|
|
101
|
+
(0, path_1.join)('/usr', 'local', 'copilot-sdk', 'index.js')
|
|
102
|
+
]);
|
|
103
|
+
});
|
|
104
|
+
it('should not remember a failed load, since the CLI can be replaced while running', async () => {
|
|
105
|
+
const loader = new TestableCopilotSdkLoader([cli]);
|
|
106
|
+
loader.shipped = {};
|
|
107
|
+
await loader.load().catch(() => { });
|
|
108
|
+
loader.shipped = usableSdk;
|
|
109
|
+
(0, chai_1.expect)(await loader.load()).to.equal(usableSdk);
|
|
110
|
+
(0, chai_1.expect)(loader.importedFromCli).to.have.lengthOf(2);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
//# sourceMappingURL=copilot-sdk-loader.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copilot-sdk-loader.spec.js","sourceRoot":"","sources":["../../src/node/copilot-sdk-loader.spec.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,oDAAoD;AACpD,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC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AAM,GAAG,IAAI,wBAAwB,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;QAC1D,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC;QAC3B,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,IAAA,aAAM,EAAC,MAAM,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC;YACzC,IAAA,WAAI,EAAC,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,CAAC;YAClD,IAAA,WAAI,EAAC,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,UAAU,CAAC;SACnD,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gFAAgF,EAAE,KAAK,IAAI,EAAE;QAC5F,MAAM,MAAM,GAAG,IAAI,wBAAwB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACnD,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC;QACpB,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAkB,CAAC,CAAC,CAAC;QACpD,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC;QAC3B,IAAA,aAAM,EAAC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAChD,IAAA,aAAM,EAAC,MAAM,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { LanguageModelMessage } from '@theia/ai-core';
|
|
2
|
+
import type { ModelInfo, SystemMessageConfig } from './copilot-sdk-types';
|
|
3
|
+
/**
|
|
4
|
+
* Selects the model IDs that should be surfaced to Theia from the list returned
|
|
5
|
+
* by `CopilotClient.listModels()`.
|
|
6
|
+
*
|
|
7
|
+
* Models whose policy is explicitly `disabled` are filtered out; `enabled` and
|
|
8
|
+
* `unconfigured` models are kept. Order is preserved and duplicates are removed.
|
|
9
|
+
*
|
|
10
|
+
* The list can name the same model both by its family and by its dated releases. Offering the user
|
|
11
|
+
* several entries that select the same model is noise, so a dated release is dropped when the family
|
|
12
|
+
* it belongs to is offered as well. It is kept when it is the only way to select that model.
|
|
13
|
+
*/
|
|
14
|
+
export declare function selectSdkModelIds(models: ModelInfo[]): string[];
|
|
15
|
+
/**
|
|
16
|
+
* The result of flattening a Theia message history into a single prompt for the
|
|
17
|
+
* agentic Copilot SDK session.
|
|
18
|
+
*/
|
|
19
|
+
export interface SdkPrompt {
|
|
20
|
+
/** Concatenated content of all system messages (may be empty). */
|
|
21
|
+
systemText: string;
|
|
22
|
+
/** The user-facing prompt body derived from the non-system messages. */
|
|
23
|
+
prompt: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Flattens a Theia message history into an {@link SdkPrompt}.
|
|
27
|
+
*
|
|
28
|
+
* The Copilot SDK session is a stateful agent that accepts a single prompt
|
|
29
|
+
* string per `send()` call, so the full Theia history is collapsed here. System
|
|
30
|
+
* messages are extracted separately and become the system message of the session,
|
|
31
|
+
* see {@link buildSdkSystemMessage}. A lone user turn is forwarded verbatim;
|
|
32
|
+
* richer histories are rendered as a role-labelled transcript.
|
|
33
|
+
*
|
|
34
|
+
* This is a lossy mapping by design, see the limitations documented in the package
|
|
35
|
+
* README, and is intended for single-turn requests.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildSdkPrompt(messages: LanguageModelMessage[]): SdkPrompt;
|
|
38
|
+
/**
|
|
39
|
+
* Builds the system message configuration of a session from the system text of a request.
|
|
40
|
+
*
|
|
41
|
+
* The CLI is an agent with a system prompt of its own, while a Theia agent brings a complete one.
|
|
42
|
+
* The sections that describe who the agent is and how it should work are therefore removed, so that
|
|
43
|
+
* they cannot contradict the prompt of the Theia agent, and the prompt is added in their place. The
|
|
44
|
+
* sections that make tool calling work and the ones that carry the safety rules of the CLI are kept:
|
|
45
|
+
* this integration declares Theia's tools to the CLI, so the model still has to be told how to call
|
|
46
|
+
* them. Replacing the message as a whole would drop those as well.
|
|
47
|
+
*/
|
|
48
|
+
export declare function buildSdkSystemMessage(systemText: string): SystemMessageConfig | undefined;
|
|
49
|
+
//# sourceMappingURL=copilot-sdk-mappers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copilot-sdk-mappers.d.ts","sourceRoot":"","sources":["../../src/node/copilot-sdk-mappers.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAQ1E;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,CAmB/D;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACtB,kEAAkE;IAClE,UAAU,EAAE,MAAM,CAAC;IACnB,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAC;CAClB;AAgCD;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,oBAAoB,EAAE,GAAG,SAAS,CAwB1E;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAczF"}
|
|
@@ -0,0 +1,147 @@
|
|
|
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.selectSdkModelIds = selectSdkModelIds;
|
|
19
|
+
exports.buildSdkPrompt = buildSdkPrompt;
|
|
20
|
+
exports.buildSdkSystemMessage = buildSdkSystemMessage;
|
|
21
|
+
const ai_core_1 = require("@theia/ai-core");
|
|
22
|
+
/**
|
|
23
|
+
* Recognizes an id that names a dated release of another model, such as
|
|
24
|
+
* `gpt-4o-2024-11-20` or `claude-sonnet-5-20260514` for `gpt-4o` and `claude-sonnet-5`.
|
|
25
|
+
*/
|
|
26
|
+
const DATED_MODEL_ID = /^(.+?)-(\d{4}-\d{2}-\d{2}|\d{8})$/;
|
|
27
|
+
/**
|
|
28
|
+
* Selects the model IDs that should be surfaced to Theia from the list returned
|
|
29
|
+
* by `CopilotClient.listModels()`.
|
|
30
|
+
*
|
|
31
|
+
* Models whose policy is explicitly `disabled` are filtered out; `enabled` and
|
|
32
|
+
* `unconfigured` models are kept. Order is preserved and duplicates are removed.
|
|
33
|
+
*
|
|
34
|
+
* The list can name the same model both by its family and by its dated releases. Offering the user
|
|
35
|
+
* several entries that select the same model is noise, so a dated release is dropped when the family
|
|
36
|
+
* it belongs to is offered as well. It is kept when it is the only way to select that model.
|
|
37
|
+
*/
|
|
38
|
+
function selectSdkModelIds(models) {
|
|
39
|
+
const available = new Set(models.filter(model => model.id && model.policy?.state !== 'disabled').map(model => model.id));
|
|
40
|
+
const result = [];
|
|
41
|
+
const seen = new Set();
|
|
42
|
+
for (const model of models) {
|
|
43
|
+
if (!model.id || seen.has(model.id)) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (model.policy && model.policy.state === 'disabled') {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const family = model.id.match(DATED_MODEL_ID)?.[1];
|
|
50
|
+
if (family && available.has(family)) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
seen.add(model.id);
|
|
54
|
+
result.push(model.id);
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
function roleLabel(message) {
|
|
59
|
+
switch (message.actor) {
|
|
60
|
+
case 'ai':
|
|
61
|
+
return 'Assistant';
|
|
62
|
+
case 'system':
|
|
63
|
+
return 'System';
|
|
64
|
+
default:
|
|
65
|
+
return 'User';
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function messageToText(message) {
|
|
69
|
+
if (ai_core_1.LanguageModelMessage.isTextMessage(message)) {
|
|
70
|
+
return message.text;
|
|
71
|
+
}
|
|
72
|
+
if (ai_core_1.LanguageModelMessage.isToolUseMessage(message)) {
|
|
73
|
+
return `[tool call: ${message.name} ${JSON.stringify(message.input)}]`;
|
|
74
|
+
}
|
|
75
|
+
if (ai_core_1.LanguageModelMessage.isToolResultMessage(message)) {
|
|
76
|
+
const content = message.content === undefined
|
|
77
|
+
? ''
|
|
78
|
+
: (typeof message.content === 'string' ? message.content : JSON.stringify(message.content));
|
|
79
|
+
return `[tool result: ${content}]`;
|
|
80
|
+
}
|
|
81
|
+
if (ai_core_1.LanguageModelMessage.isImageMessage(message)) {
|
|
82
|
+
return '[image omitted]';
|
|
83
|
+
}
|
|
84
|
+
return '';
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Flattens a Theia message history into an {@link SdkPrompt}.
|
|
88
|
+
*
|
|
89
|
+
* The Copilot SDK session is a stateful agent that accepts a single prompt
|
|
90
|
+
* string per `send()` call, so the full Theia history is collapsed here. System
|
|
91
|
+
* messages are extracted separately and become the system message of the session,
|
|
92
|
+
* see {@link buildSdkSystemMessage}. A lone user turn is forwarded verbatim;
|
|
93
|
+
* richer histories are rendered as a role-labelled transcript.
|
|
94
|
+
*
|
|
95
|
+
* This is a lossy mapping by design, see the limitations documented in the package
|
|
96
|
+
* README, and is intended for single-turn requests.
|
|
97
|
+
*/
|
|
98
|
+
function buildSdkPrompt(messages) {
|
|
99
|
+
const systemParts = [];
|
|
100
|
+
const conversation = [];
|
|
101
|
+
for (const message of messages) {
|
|
102
|
+
if (message.actor === 'system' && ai_core_1.LanguageModelMessage.isTextMessage(message)) {
|
|
103
|
+
systemParts.push(message.text);
|
|
104
|
+
}
|
|
105
|
+
else if (message.type !== 'thinking') {
|
|
106
|
+
conversation.push(message);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const systemText = systemParts.join('\n\n').trim();
|
|
110
|
+
let prompt;
|
|
111
|
+
if (conversation.length === 1 && ai_core_1.LanguageModelMessage.isTextMessage(conversation[0]) && conversation[0].actor === 'user') {
|
|
112
|
+
prompt = conversation[0].text;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
prompt = conversation
|
|
116
|
+
.map(message => `${roleLabel(message)}: ${messageToText(message)}`)
|
|
117
|
+
.join('\n\n')
|
|
118
|
+
.trim();
|
|
119
|
+
}
|
|
120
|
+
return { systemText, prompt };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Builds the system message configuration of a session from the system text of a request.
|
|
124
|
+
*
|
|
125
|
+
* The CLI is an agent with a system prompt of its own, while a Theia agent brings a complete one.
|
|
126
|
+
* The sections that describe who the agent is and how it should work are therefore removed, so that
|
|
127
|
+
* they cannot contradict the prompt of the Theia agent, and the prompt is added in their place. The
|
|
128
|
+
* sections that make tool calling work and the ones that carry the safety rules of the CLI are kept:
|
|
129
|
+
* this integration declares Theia's tools to the CLI, so the model still has to be told how to call
|
|
130
|
+
* them. Replacing the message as a whole would drop those as well.
|
|
131
|
+
*/
|
|
132
|
+
function buildSdkSystemMessage(systemText) {
|
|
133
|
+
if (!systemText) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
mode: 'customize',
|
|
138
|
+
sections: {
|
|
139
|
+
identity: { action: 'remove' },
|
|
140
|
+
tone: { action: 'remove' },
|
|
141
|
+
guidelines: { action: 'remove' },
|
|
142
|
+
code_change_rules: { action: 'remove' }
|
|
143
|
+
},
|
|
144
|
+
content: systemText
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=copilot-sdk-mappers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copilot-sdk-mappers.js","sourceRoot":"","sources":["../../src/node/copilot-sdk-mappers.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;;AAsBhF,8CAmBC;AAuDD,wCAwBC;AAYD,sDAcC;AAhJD,4CAAsD;AAGtD;;;GAGG;AACH,MAAM,cAAc,GAAG,mCAAmC,CAAC;AAE3D;;;;;;;;;;GAUG;AACH,SAAgB,iBAAiB,CAAC,MAAmB;IACjD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,KAAK,CAAC,MAAM,EAAE,KAAK,KAAK,UAAU,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IACzH,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MA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