@theia/ai-chatgpt 0.0.0-stage → 1.77.0-next.28
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 +106 -2
- package/lib/browser/chatgpt-command-contribution.d.ts +35 -0
- package/lib/browser/chatgpt-command-contribution.d.ts.map +1 -0
- package/lib/browser/chatgpt-command-contribution.js +163 -0
- package/lib/browser/chatgpt-command-contribution.js.map +1 -0
- package/lib/browser/chatgpt-command-contribution.spec.d.ts +2 -0
- package/lib/browser/chatgpt-command-contribution.spec.d.ts.map +1 -0
- package/lib/browser/chatgpt-command-contribution.spec.js +240 -0
- package/lib/browser/chatgpt-command-contribution.spec.js.map +1 -0
- package/lib/browser/chatgpt-frontend-application-contribution.d.ts +32 -0
- package/lib/browser/chatgpt-frontend-application-contribution.d.ts.map +1 -0
- package/lib/browser/chatgpt-frontend-application-contribution.js +238 -0
- package/lib/browser/chatgpt-frontend-application-contribution.js.map +1 -0
- package/lib/browser/chatgpt-frontend-application-contribution.spec.d.ts +2 -0
- package/lib/browser/chatgpt-frontend-application-contribution.spec.d.ts.map +1 -0
- package/lib/browser/chatgpt-frontend-application-contribution.spec.js +386 -0
- package/lib/browser/chatgpt-frontend-application-contribution.spec.js.map +1 -0
- package/lib/browser/chatgpt-frontend-module.d.ts +4 -0
- package/lib/browser/chatgpt-frontend-module.d.ts.map +1 -0
- package/lib/browser/chatgpt-frontend-module.js +63 -0
- package/lib/browser/chatgpt-frontend-module.js.map +1 -0
- package/lib/browser/chatgpt-status-bar-contribution.d.ts +20 -0
- package/lib/browser/chatgpt-status-bar-contribution.d.ts.map +1 -0
- package/lib/browser/chatgpt-status-bar-contribution.js +105 -0
- package/lib/browser/chatgpt-status-bar-contribution.js.map +1 -0
- package/lib/browser/chatgpt-status-bar-contribution.spec.d.ts +2 -0
- package/lib/browser/chatgpt-status-bar-contribution.spec.d.ts.map +1 -0
- package/lib/browser/chatgpt-status-bar-contribution.spec.js +161 -0
- package/lib/browser/chatgpt-status-bar-contribution.spec.js.map +1 -0
- package/lib/common/chatgpt-auth-service.d.ts +64 -0
- package/lib/common/chatgpt-auth-service.d.ts.map +1 -0
- package/lib/common/chatgpt-auth-service.js +24 -0
- package/lib/common/chatgpt-auth-service.js.map +1 -0
- package/lib/common/chatgpt-language-models-manager.d.ts +30 -0
- package/lib/common/chatgpt-language-models-manager.d.ts.map +1 -0
- package/lib/common/chatgpt-language-models-manager.js +22 -0
- package/lib/common/chatgpt-language-models-manager.js.map +1 -0
- package/lib/common/chatgpt-preferences.d.ts +11 -0
- package/lib/common/chatgpt-preferences.d.ts.map +1 -0
- package/lib/common/chatgpt-preferences.js +84 -0
- package/lib/common/chatgpt-preferences.js.map +1 -0
- package/lib/common/chatgpt-preferences.spec.d.ts +2 -0
- package/lib/common/chatgpt-preferences.spec.d.ts.map +1 -0
- package/lib/common/chatgpt-preferences.spec.js +38 -0
- package/lib/common/chatgpt-preferences.spec.js.map +1 -0
- package/lib/common/index.d.ts +4 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +22 -0
- package/lib/common/index.js.map +1 -0
- package/lib/node/chatgpt-auth-service-impl.d.ts +93 -0
- package/lib/node/chatgpt-auth-service-impl.d.ts.map +1 -0
- package/lib/node/chatgpt-auth-service-impl.js +472 -0
- package/lib/node/chatgpt-auth-service-impl.js.map +1 -0
- package/lib/node/chatgpt-auth-service-impl.spec.d.ts +2 -0
- package/lib/node/chatgpt-auth-service-impl.spec.d.ts.map +1 -0
- package/lib/node/chatgpt-auth-service-impl.spec.js +737 -0
- package/lib/node/chatgpt-auth-service-impl.spec.js.map +1 -0
- package/lib/node/chatgpt-auth-service.d.ts +20 -0
- package/lib/node/chatgpt-auth-service.d.ts.map +1 -0
- package/lib/node/chatgpt-auth-service.js +30 -0
- package/lib/node/chatgpt-auth-service.js.map +1 -0
- package/lib/node/chatgpt-backend-module.d.ts +4 -0
- package/lib/node/chatgpt-backend-module.d.ts.map +1 -0
- package/lib/node/chatgpt-backend-module.js +52 -0
- package/lib/node/chatgpt-backend-module.js.map +1 -0
- package/lib/node/chatgpt-language-model.d.ts +41 -0
- package/lib/node/chatgpt-language-model.d.ts.map +1 -0
- package/lib/node/chatgpt-language-model.js +92 -0
- package/lib/node/chatgpt-language-model.js.map +1 -0
- package/lib/node/chatgpt-language-model.spec.d.ts +2 -0
- package/lib/node/chatgpt-language-model.spec.d.ts.map +1 -0
- package/lib/node/chatgpt-language-model.spec.js +279 -0
- package/lib/node/chatgpt-language-model.spec.js.map +1 -0
- package/lib/node/chatgpt-language-models-manager-impl.d.ts +22 -0
- package/lib/node/chatgpt-language-models-manager-impl.d.ts.map +1 -0
- package/lib/node/chatgpt-language-models-manager-impl.js +106 -0
- package/lib/node/chatgpt-language-models-manager-impl.js.map +1 -0
- package/lib/node/chatgpt-language-models-manager-impl.spec.d.ts +2 -0
- package/lib/node/chatgpt-language-models-manager-impl.spec.d.ts.map +1 -0
- package/lib/node/chatgpt-language-models-manager-impl.spec.js +160 -0
- package/lib/node/chatgpt-language-models-manager-impl.spec.js.map +1 -0
- package/lib/node/chatgpt-model-catalog.d.ts +18 -0
- package/lib/node/chatgpt-model-catalog.d.ts.map +1 -0
- package/lib/node/chatgpt-model-catalog.js +126 -0
- package/lib/node/chatgpt-model-catalog.js.map +1 -0
- package/lib/node/chatgpt-model-catalog.spec.d.ts +2 -0
- package/lib/node/chatgpt-model-catalog.spec.d.ts.map +1 -0
- package/lib/node/chatgpt-model-catalog.spec.js +175 -0
- package/lib/node/chatgpt-model-catalog.spec.js.map +1 -0
- package/lib/node/chatgpt-oauth.d.ts +43 -0
- package/lib/node/chatgpt-oauth.d.ts.map +1 -0
- package/lib/node/chatgpt-oauth.js +129 -0
- package/lib/node/chatgpt-oauth.js.map +1 -0
- package/lib/node/chatgpt-oauth.spec.d.ts +2 -0
- package/lib/node/chatgpt-oauth.spec.d.ts.map +1 -0
- package/lib/node/chatgpt-oauth.spec.js +94 -0
- package/lib/node/chatgpt-oauth.spec.js.map +1 -0
- package/lib/node/chatgpt-response-api-utils.d.ts +18 -0
- package/lib/node/chatgpt-response-api-utils.d.ts.map +1 -0
- package/lib/node/chatgpt-response-api-utils.js +44 -0
- package/lib/node/chatgpt-response-api-utils.js.map +1 -0
- package/package.json +50 -4
- package/src/browser/chatgpt-command-contribution.spec.ts +279 -0
- package/src/browser/chatgpt-command-contribution.ts +164 -0
- package/src/browser/chatgpt-frontend-application-contribution.spec.ts +460 -0
- package/src/browser/chatgpt-frontend-application-contribution.ts +246 -0
- package/src/browser/chatgpt-frontend-module.ts +69 -0
- package/src/browser/chatgpt-status-bar-contribution.spec.ts +174 -0
- package/src/browser/chatgpt-status-bar-contribution.ts +95 -0
- package/src/common/chatgpt-auth-service.ts +92 -0
- package/src/common/chatgpt-language-models-manager.ts +48 -0
- package/src/common/chatgpt-preferences.spec.ts +42 -0
- package/src/common/chatgpt-preferences.ts +92 -0
- package/src/common/index.ts +18 -0
- package/src/node/chatgpt-auth-service-impl.spec.ts +853 -0
- package/src/node/chatgpt-auth-service-impl.ts +525 -0
- package/src/node/chatgpt-auth-service.ts +48 -0
- package/src/node/chatgpt-backend-module.ts +63 -0
- package/src/node/chatgpt-language-model.spec.ts +338 -0
- package/src/node/chatgpt-language-model.ts +108 -0
- package/src/node/chatgpt-language-models-manager-impl.spec.ts +187 -0
- package/src/node/chatgpt-language-models-manager-impl.ts +112 -0
- package/src/node/chatgpt-model-catalog.spec.ts +213 -0
- package/src/node/chatgpt-model-catalog.ts +116 -0
- package/src/node/chatgpt-oauth.spec.ts +115 -0
- package/src/node/chatgpt-oauth.ts +143 -0
- package/src/node/chatgpt-response-api-utils.ts +45 -0
package/README.md
CHANGED
|
@@ -1,3 +1,107 @@
|
|
|
1
|
-
|
|
1
|
+
<div align='center'>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<br />
|
|
4
|
+
|
|
5
|
+
<img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' />
|
|
6
|
+
|
|
7
|
+
<h2>ECLIPSE THEIA - CHATGPT EXTENSION</h2>
|
|
8
|
+
|
|
9
|
+
<hr />
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
## Description
|
|
14
|
+
|
|
15
|
+
The `@theia/ai-chatgpt` extension serves OpenAI models through your ChatGPT subscription instead of an OpenAI API key.
|
|
16
|
+
The models appear as `chatgpt/<model>` in the model picker and coexist with the API-key based `openai/<model>` models contributed by `@theia/ai-openai`.
|
|
17
|
+
|
|
18
|
+
By default the models your ChatGPT plan grants are queried from the endpoint once you are signed in. Set the `ai-features.chatGpt.modelOverrides`
|
|
19
|
+
preference to offer a fixed list of models instead. A built-in list is offered when authenticated discovery fails, for example when the
|
|
20
|
+
endpoint cannot be reached. Discovery returns no models without credentials.
|
|
21
|
+
|
|
22
|
+
### Signing in
|
|
23
|
+
|
|
24
|
+
Click the ChatGPT status bar item or run the command _ChatGPT: Sign in_. It opens the OpenAI authorization
|
|
25
|
+
page in your browser. The browser returns the authorization code to a
|
|
26
|
+
listener on `http://localhost:1455/auth/callback`, which is provided by the Theia backend. If the backend does not run on the same machine as
|
|
27
|
+
your browser, or the port is already in use, you can paste the authorization code (or the full redirect URL) into the input box Theia offers
|
|
28
|
+
instead. The credentials are stored in the credential store of your operating system and are removed again by the command _ChatGPT: Sign out_.
|
|
29
|
+
|
|
30
|
+
Models are only registered while signed in. The status bar shows the signed-in account and provides a sign-out action.
|
|
31
|
+
Set `ai-features.chatGpt.enabled` to `false` to disable the provider, remove its models and hide its status bar item; the configured model list is preserved.
|
|
32
|
+
|
|
33
|
+
### Backend application configuration
|
|
34
|
+
|
|
35
|
+
The default OAuth client id `app_EMoamEEZ73f0CkXaXp7hrann` belongs to OpenAI's Codex CLI; it is not a client registered by Theia.
|
|
36
|
+
Adopters must evaluate whether using this client and the subscription endpoint is suitable for their application.
|
|
37
|
+
They can rebind the configuration below to use their own registered OAuth client and matching callback configuration.
|
|
38
|
+
|
|
39
|
+
Application authors can rebind `ChatGptAuthServiceConfig` from `@theia/ai-chatgpt/lib/node/chatgpt-auth-service` in a backend module
|
|
40
|
+
loaded after this extension. These are backend DI values, not frontend preferences. All fields are required; spread
|
|
41
|
+
`DEFAULT_CHATGPT_AUTH_SERVICE_CONFIG` to override only selected values:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
45
|
+
import { ChatGptAuthServiceConfig, DEFAULT_CHATGPT_AUTH_SERVICE_CONFIG } from '@theia/ai-chatgpt/lib/node/chatgpt-auth-service';
|
|
46
|
+
|
|
47
|
+
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
|
48
|
+
rebind(ChatGptAuthServiceConfig).toConstantValue({
|
|
49
|
+
...DEFAULT_CHATGPT_AUTH_SERVICE_CONFIG,
|
|
50
|
+
clientId: 'your-registered-client-id',
|
|
51
|
+
keyStoreService: 'your-application-chatgpt'
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
| Field | Default |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| `clientId` | `app_EMoamEEZ73f0CkXaXp7hrann` |
|
|
59
|
+
| `callbackHost` | `localhost` |
|
|
60
|
+
| `callbackPort` | `1455` |
|
|
61
|
+
| `callbackPath` | `/auth/callback` |
|
|
62
|
+
| `keyStoreService` | `theia-chatgpt` |
|
|
63
|
+
| `keyStoreAccount` | `default` |
|
|
64
|
+
|
|
65
|
+
The redirect URI is derived as `http://<callbackHost>:<callbackPort><callbackPath>` and is used consistently for authorization,
|
|
66
|
+
code exchange and the loopback listener. Supply a hostname or unbracketed IP address, a fixed port and an absolute callback path.
|
|
67
|
+
The client and redirect URI must match an OpenAI OAuth registration; changing local values does not register a new callback.
|
|
68
|
+
Changing key store identifiers selects a different credential entry and does not migrate existing credentials.
|
|
69
|
+
|
|
70
|
+
Backend consumers use the `ChatGptBackendAuthService` interface symbol from the same module, which application authors can rebind
|
|
71
|
+
for a custom auth implementation. The frontend RPC service remains a narrow facade: it never exposes credentials or backend client registration.
|
|
72
|
+
|
|
73
|
+
### Server-side compaction
|
|
74
|
+
|
|
75
|
+
ChatGPT models request automatic server-side compaction through the Responses API `context_management` directive.
|
|
76
|
+
`ai-features.chatGpt.serverSideCompaction` defaults to `default`, inheriting the global chat compaction setting; `enabled`
|
|
77
|
+
and `disabled` override it. The optional `ai-features.chatGpt.serverSideCompactionTokenThreshold` overrides the global
|
|
78
|
+
input-token threshold. When neither is set, the provider chooses the threshold. Session compaction settings take precedence.
|
|
79
|
+
Responses remain unstored and streamed; encrypted compaction state returned in the stream is replayed on subsequent ChatGPT requests.
|
|
80
|
+
ChatGPT uses the `chatgpt-responses` compaction marker, distinct from OpenAI's `openai-responses` marker. When switching
|
|
81
|
+
between these providers, foreign compaction markers are ignored and the earlier conversation history is preserved.
|
|
82
|
+
|
|
83
|
+
### Limitations
|
|
84
|
+
|
|
85
|
+
This integration is experimental and relies on an undocumented endpoint. There is no stability guarantee: OpenAI may change or
|
|
86
|
+
remove endpoint access, authentication requirements, or supported features without notice, causing the integration to stop working.
|
|
87
|
+
Adopters should evaluate these risks and the suitability of this integration before including it in their applications.
|
|
88
|
+
|
|
89
|
+
Requests are served by the ChatGPT endpoint `https://chatgpt.com/backend-api/codex`. That endpoint only supports the streaming Response API,
|
|
90
|
+
does not retain responses, and only serves the models included in your ChatGPT plan, so models configured by hand need to be available for
|
|
91
|
+
your plan.
|
|
92
|
+
|
|
93
|
+
## Additional Information
|
|
94
|
+
|
|
95
|
+
- [API documentation for `@theia/ai-chatgpt`](https://eclipse-theia.github.io/theia/docs/next/modules/_theia_ai-chatgpt.html)
|
|
96
|
+
- [Theia - GitHub](https://github.com/eclipse-theia/theia)
|
|
97
|
+
- [Theia - Website](https://theia-ide.org/)
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
|
|
102
|
+
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
|
|
103
|
+
|
|
104
|
+
## Trademark
|
|
105
|
+
|
|
106
|
+
"Theia" is a trademark of the Eclipse Foundation
|
|
107
|
+
<https://www.eclipse.org/theia>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Command, CommandContribution, CommandRegistry, Disposable, DisposableCollection, MessageService, PreferenceService } from '@theia/core';
|
|
2
|
+
import { QuickInputService } from '@theia/core/lib/browser';
|
|
3
|
+
import { WindowService } from '@theia/core/lib/browser/window/window-service';
|
|
4
|
+
import { AIActivationService } from '@theia/ai-core/lib/browser';
|
|
5
|
+
import { ChatGptAuthService, ChatGptAuthState } from '../common';
|
|
6
|
+
export declare namespace ChatGptCommands {
|
|
7
|
+
const SIGN_IN: Command;
|
|
8
|
+
const SIGN_OUT: Command;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Drives the "Sign in with ChatGPT" flow: the authorization page is opened in the user's browser and the
|
|
12
|
+
* authorization code is either delivered to the backend's loopback listener or entered manually.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ChatGptCommandContribution implements CommandContribution, Disposable {
|
|
15
|
+
protected readonly authService: ChatGptAuthService;
|
|
16
|
+
protected readonly windowService: WindowService;
|
|
17
|
+
protected readonly messageService: MessageService;
|
|
18
|
+
protected readonly quickInputService: QuickInputService;
|
|
19
|
+
protected readonly activationService: AIActivationService;
|
|
20
|
+
protected readonly preferenceService: PreferenceService;
|
|
21
|
+
protected authState: ChatGptAuthState;
|
|
22
|
+
protected authGeneration: number;
|
|
23
|
+
protected disposed: boolean;
|
|
24
|
+
protected readonly toDispose: DisposableCollection;
|
|
25
|
+
protected init(): void;
|
|
26
|
+
dispose(): void;
|
|
27
|
+
protected refreshAuthState(): Promise<boolean>;
|
|
28
|
+
registerCommands(registry: CommandRegistry): void;
|
|
29
|
+
protected signIn(): Promise<void>;
|
|
30
|
+
/** Waits for the browser to complete the sign in while offering to enter the authorization code manually. */
|
|
31
|
+
protected awaitAuthorization(): Promise<boolean>;
|
|
32
|
+
protected requestAuthorizationCode(): Promise<boolean>;
|
|
33
|
+
protected signOut(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=chatgpt-command-contribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatgpt-command-contribution.d.ts","sourceRoot":"","sources":["../../src/browser/chatgpt-command-contribution.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,UAAU,EAAE,oBAAoB,EAAE,cAAc,EAAO,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACtJ,OAAO,EAAyB,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,+CAA+C,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,OAAO,EAAwB,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAEvF,yBAAiB,eAAe,CAAC;IACtB,MAAM,OAAO,EAAE,OAIrB,CAAC;IAEK,MAAM,QAAQ,EAAE,OAItB,CAAC;CACL;AAED;;;GAGG;AACH,qBACa,0BAA2B,YAAW,mBAAmB,EAAE,UAAU;IAG9E,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,kBAAkB,CAAC;IAGnD,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IAGhD,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IAGlD,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAGxD,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;IAG1D,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAExD,SAAS,CAAC,SAAS,EAAE,gBAAgB,CAA8B;IACnE,SAAS,CAAC,cAAc,SAAK;IAC7B,SAAS,CAAC,QAAQ,UAAS;IAC3B,SAAS,CAAC,QAAQ,CAAC,SAAS,uBAA8B;IAG1D,SAAS,CAAC,IAAI,IAAI,IAAI;IAQtB,OAAO,IAAI,IAAI;cAKC,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC;IAUpD,gBAAgB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;cAcjC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBvC,6GAA6G;cAC7F,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC;cAiBtC,wBAAwB,IAAI,OAAO,CAAC,OAAO,CAAC;cAY5C,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAW3C"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2026 EclipseSource GmbH.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.ChatGptCommandContribution = exports.ChatGptCommands = void 0;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const core_1 = require("@theia/core");
|
|
21
|
+
const browser_1 = require("@theia/core/lib/browser");
|
|
22
|
+
const window_service_1 = require("@theia/core/lib/browser/window/window-service");
|
|
23
|
+
const browser_2 = require("@theia/ai-core/lib/browser");
|
|
24
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
25
|
+
const common_1 = require("../common");
|
|
26
|
+
var ChatGptCommands;
|
|
27
|
+
(function (ChatGptCommands) {
|
|
28
|
+
ChatGptCommands.SIGN_IN = core_1.Command.toLocalizedCommand({ id: 'chatgpt.signIn', label: 'Sign in', category: 'ChatGPT' }, 'theia/ai/chatgpt/commands/signIn', 'theia/ai/chatgpt/category');
|
|
29
|
+
ChatGptCommands.SIGN_OUT = core_1.Command.toLocalizedCommand({ id: 'chatgpt.signOut', label: 'Sign out', category: 'ChatGPT' }, 'theia/ai/chatgpt/commands/signOut', 'theia/ai/chatgpt/category');
|
|
30
|
+
})(ChatGptCommands || (exports.ChatGptCommands = ChatGptCommands = {}));
|
|
31
|
+
/**
|
|
32
|
+
* Drives the "Sign in with ChatGPT" flow: the authorization page is opened in the user's browser and the
|
|
33
|
+
* authorization code is either delivered to the backend's loopback listener or entered manually.
|
|
34
|
+
*/
|
|
35
|
+
let ChatGptCommandContribution = class ChatGptCommandContribution {
|
|
36
|
+
constructor() {
|
|
37
|
+
this.authState = { isAuthenticated: false };
|
|
38
|
+
this.authGeneration = 0;
|
|
39
|
+
this.disposed = false;
|
|
40
|
+
this.toDispose = new core_1.DisposableCollection();
|
|
41
|
+
}
|
|
42
|
+
init() {
|
|
43
|
+
this.toDispose.push(this.authService.onAuthStateChanged(state => {
|
|
44
|
+
this.authGeneration++;
|
|
45
|
+
this.authState = state;
|
|
46
|
+
}));
|
|
47
|
+
this.refreshAuthState();
|
|
48
|
+
}
|
|
49
|
+
dispose() {
|
|
50
|
+
this.disposed = true;
|
|
51
|
+
this.toDispose.dispose();
|
|
52
|
+
}
|
|
53
|
+
async refreshAuthState() {
|
|
54
|
+
const generation = ++this.authGeneration;
|
|
55
|
+
const state = await this.authService.getAuthState();
|
|
56
|
+
if (this.disposed || generation !== this.authGeneration) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
this.authState = state;
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
registerCommands(registry) {
|
|
63
|
+
registry.registerCommand(ChatGptCommands.SIGN_IN, {
|
|
64
|
+
execute: () => this.signIn(),
|
|
65
|
+
isEnabled: () => !this.authState.isAuthenticated,
|
|
66
|
+
isVisible: () => this.activationService.isActive && this.preferenceService.get(common_1.CHATGPT_ENABLED_PREF, true)
|
|
67
|
+
});
|
|
68
|
+
registry.registerCommand(ChatGptCommands.SIGN_OUT, {
|
|
69
|
+
execute: () => this.signOut(),
|
|
70
|
+
isEnabled: () => this.authState.isAuthenticated,
|
|
71
|
+
isVisible: () => this.activationService.isActive && this.preferenceService.get(common_1.CHATGPT_ENABLED_PREF, true)
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async signIn() {
|
|
75
|
+
try {
|
|
76
|
+
const session = await this.authService.startLogin();
|
|
77
|
+
this.windowService.openNewWindow(session.authorizationUrl, { external: true });
|
|
78
|
+
const success = session.callbackListening ? await this.awaitAuthorization() : await this.requestAuthorizationCode();
|
|
79
|
+
if (success && await this.refreshAuthState() && this.authState.isAuthenticated) {
|
|
80
|
+
this.messageService.info(this.authState.accountLabel
|
|
81
|
+
? core_1.nls.localize('theia/ai/chatgpt/signedInAs', 'Signed in to ChatGPT as {0}.', this.authState.accountLabel)
|
|
82
|
+
: core_1.nls.localize('theia/ai/chatgpt/signedIn', 'Signed in to ChatGPT.'));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
await this.authService.cancelLogin();
|
|
87
|
+
this.messageService.error(core_1.nls.localize('theia/ai/chatgpt/signInFailed', 'The ChatGPT sign in failed: {0}', error instanceof Error ? error.message : String(error)));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** Waits for the browser to complete the sign in while offering to enter the authorization code manually. */
|
|
91
|
+
async awaitAuthorization() {
|
|
92
|
+
const enterCode = core_1.nls.localize('theia/ai/chatgpt/enterCode', 'Enter code manually');
|
|
93
|
+
const chosenAction = this.messageService.info(core_1.nls.localize('theia/ai/chatgpt/waiting', 'Complete the ChatGPT sign in in your browser.'), enterCode);
|
|
94
|
+
const outcome = await Promise.race([
|
|
95
|
+
this.authService.waitForLogin().then(success => ({ success })),
|
|
96
|
+
chosenAction.then(action => ({ action }))
|
|
97
|
+
]);
|
|
98
|
+
if ('success' in outcome) {
|
|
99
|
+
return outcome.success;
|
|
100
|
+
}
|
|
101
|
+
if (outcome.action === enterCode) {
|
|
102
|
+
return this.requestAuthorizationCode();
|
|
103
|
+
}
|
|
104
|
+
return this.authService.waitForLogin();
|
|
105
|
+
}
|
|
106
|
+
async requestAuthorizationCode() {
|
|
107
|
+
const input = await this.quickInputService.input({
|
|
108
|
+
prompt: core_1.nls.localize('theia/ai/chatgpt/codePrompt', 'Paste the authorization code or the full redirect URL from your browser'),
|
|
109
|
+
ignoreFocusLost: true
|
|
110
|
+
});
|
|
111
|
+
if (input === undefined) {
|
|
112
|
+
await this.authService.cancelLogin();
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
return this.authService.completeLogin(input);
|
|
116
|
+
}
|
|
117
|
+
async signOut() {
|
|
118
|
+
const confirmed = await new browser_1.ConfirmDialog({
|
|
119
|
+
title: core_1.nls.localize('theia/ai/chatgpt/signOutTitle', 'Sign out of ChatGPT'),
|
|
120
|
+
msg: core_1.nls.localize('theia/ai/chatgpt/signOutConfirm', 'Are you sure you want to sign out of ChatGPT?'),
|
|
121
|
+
ok: browser_1.Dialog.YES,
|
|
122
|
+
cancel: browser_1.Dialog.NO
|
|
123
|
+
}).open();
|
|
124
|
+
if (confirmed) {
|
|
125
|
+
await this.authService.signOut();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
exports.ChatGptCommandContribution = ChatGptCommandContribution;
|
|
130
|
+
tslib_1.__decorate([
|
|
131
|
+
(0, inversify_1.inject)(common_1.ChatGptAuthService),
|
|
132
|
+
tslib_1.__metadata("design:type", Object)
|
|
133
|
+
], ChatGptCommandContribution.prototype, "authService", void 0);
|
|
134
|
+
tslib_1.__decorate([
|
|
135
|
+
(0, inversify_1.inject)(window_service_1.WindowService),
|
|
136
|
+
tslib_1.__metadata("design:type", Object)
|
|
137
|
+
], ChatGptCommandContribution.prototype, "windowService", void 0);
|
|
138
|
+
tslib_1.__decorate([
|
|
139
|
+
(0, inversify_1.inject)(core_1.MessageService),
|
|
140
|
+
tslib_1.__metadata("design:type", core_1.MessageService)
|
|
141
|
+
], ChatGptCommandContribution.prototype, "messageService", void 0);
|
|
142
|
+
tslib_1.__decorate([
|
|
143
|
+
(0, inversify_1.inject)(browser_1.QuickInputService),
|
|
144
|
+
tslib_1.__metadata("design:type", Object)
|
|
145
|
+
], ChatGptCommandContribution.prototype, "quickInputService", void 0);
|
|
146
|
+
tslib_1.__decorate([
|
|
147
|
+
(0, inversify_1.inject)(browser_2.AIActivationService),
|
|
148
|
+
tslib_1.__metadata("design:type", Object)
|
|
149
|
+
], ChatGptCommandContribution.prototype, "activationService", void 0);
|
|
150
|
+
tslib_1.__decorate([
|
|
151
|
+
(0, inversify_1.inject)(core_1.PreferenceService),
|
|
152
|
+
tslib_1.__metadata("design:type", Object)
|
|
153
|
+
], ChatGptCommandContribution.prototype, "preferenceService", void 0);
|
|
154
|
+
tslib_1.__decorate([
|
|
155
|
+
(0, inversify_1.postConstruct)(),
|
|
156
|
+
tslib_1.__metadata("design:type", Function),
|
|
157
|
+
tslib_1.__metadata("design:paramtypes", []),
|
|
158
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
159
|
+
], ChatGptCommandContribution.prototype, "init", null);
|
|
160
|
+
exports.ChatGptCommandContribution = ChatGptCommandContribution = tslib_1.__decorate([
|
|
161
|
+
(0, inversify_1.injectable)()
|
|
162
|
+
], ChatGptCommandContribution);
|
|
163
|
+
//# sourceMappingURL=chatgpt-command-contribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatgpt-command-contribution.js","sourceRoot":"","sources":["../../src/browser/chatgpt-command-contribution.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAEhF,sCAAsJ;AACtJ,qDAAmF;AACnF,kFAA8E;AAC9E,wDAAiE;AACjE,4DAAiF;AACjF,sCAAuF;AAEvF,IAAiB,eAAe,CAY/B;AAZD,WAAiB,eAAe;IACf,uBAAO,GAAY,cAAO,CAAC,kBAAkB,CACtD,EAAE,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,EAC/D,kCAAkC,EAClC,2BAA2B,CAC9B,CAAC;IAEW,wBAAQ,GAAY,cAAO,CAAC,kBAAkB,CACvD,EAAE,EAAE,EAAE,iBAAiB,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,EACjE,mCAAmC,EACnC,2BAA2B,CAC9B,CAAC;AACN,CAAC,EAZgB,eAAe,+BAAf,eAAe,QAY/B;AAED;;;GAGG;AAEI,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAAhC;QAoBO,cAAS,GAAqB,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC;QACzD,mBAAc,GAAG,CAAC,CAAC;QACnB,aAAQ,GAAG,KAAK,CAAC;QACR,cAAS,GAAG,IAAI,2BAAoB,EAAE,CAAC;IAkG9D,CAAC;IA/Fa,IAAI;QACV,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CA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CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;IAES,KAAK,CAAC,OAAO;QACnB,MAAM,SAAS,GAAG,MAAM,IAAI,uBAAa,CAAC;YACtC,KAAK,EAAE,UAAG,CAAC,QAAQ,CAAC,+BAA+B,EAAE,qBAAqB,CAAC;YAC3E,GAAG,EAAE,UAAG,CAAC,QAAQ,CAAC,iCAAiC,EAAE,+CAA+C,CAAC;YACrG,EAAE,EAAE,gBAAM,CAAC,GAAG;YACd,MAAM,EAAE,gBAAM,CAAC,EAAE;SACpB,CAAC,CAAC,IAAI,EAAE,CAAC;QACV,IAAI,SAAS,EAAE,CAAC;YACZ,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QACrC,CAAC;IACL,CAAC;CACJ,CAAA;AAzHY,gEAA0B;AAGhB;IADlB,IAAA,kBAAM,EAAC,2BAAkB,CAAC;;+DACwB;AAGhC;IADlB,IAAA,kBAAM,EAAC,8BAAa,CAAC;;iEAC0B;AAG7B;IADlB,IAAA,kBAAM,EAAC,qBAAc,CAAC;sCACY,qBAAc;kEAAC;AAG/B;IADlB,IAAA,kBAAM,EAAC,2BAAiB,CAAC;;qEAC8B;AAGrC;IADlB,IAAA,kBAAM,EAAC,6BAAmB,CAAC;;qEAC8B;AAGvC;IADlB,IAAA,kBAAM,EAAC,wBAAiB,CAAC;;qEAC8B;AAQ9C;IADT,IAAA,yBAAa,GAAE;;;;sDAOf;qCAhCQ,0BAA0B;IADtC,IAAA,sBAAU,GAAE;GACA,0BAA0B,CAyHtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatgpt-command-contribution.spec.d.ts","sourceRoot":"","sources":["../../src/browser/chatgpt-command-contribution.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2026 EclipseSource GmbH.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const jsdom_1 = require("@theia/core/lib/browser/test/jsdom");
|
|
19
|
+
let disableJSDOM = (0, jsdom_1.enableJSDOM)();
|
|
20
|
+
const frontend_application_config_provider_1 = require("@theia/core/lib/browser/frontend-application-config-provider");
|
|
21
|
+
frontend_application_config_provider_1.FrontendApplicationConfigProvider.set({});
|
|
22
|
+
const chai_1 = require("chai");
|
|
23
|
+
const core_1 = require("@theia/core");
|
|
24
|
+
const promise_util_1 = require("@theia/core/lib/common/promise-util");
|
|
25
|
+
const common_1 = require("../common");
|
|
26
|
+
const chatgpt_command_contribution_1 = require("./chatgpt-command-contribution");
|
|
27
|
+
disableJSDOM();
|
|
28
|
+
class FakeAuthService {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.authState = { isAuthenticated: false };
|
|
31
|
+
this.session = { authorizationUrl: 'https://auth.openai.com/oauth/authorize?code_challenge=x', callbackListening: true };
|
|
32
|
+
this.login = new promise_util_1.Deferred();
|
|
33
|
+
this.completed = [];
|
|
34
|
+
this.cancelledLogins = 0;
|
|
35
|
+
this.signOuts = 0;
|
|
36
|
+
this.emitter = new core_1.Emitter();
|
|
37
|
+
this.onAuthStateChanged = this.emitter.event;
|
|
38
|
+
}
|
|
39
|
+
async startLogin() {
|
|
40
|
+
if (this.startLoginError) {
|
|
41
|
+
throw this.startLoginError;
|
|
42
|
+
}
|
|
43
|
+
return this.session;
|
|
44
|
+
}
|
|
45
|
+
waitForLogin() {
|
|
46
|
+
return this.login.promise;
|
|
47
|
+
}
|
|
48
|
+
async completeLogin(codeOrRedirectUrl) {
|
|
49
|
+
this.completed.push(codeOrRedirectUrl);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
async cancelLogin() {
|
|
53
|
+
this.cancelledLogins++;
|
|
54
|
+
}
|
|
55
|
+
async getAuthState() {
|
|
56
|
+
return this.authState;
|
|
57
|
+
}
|
|
58
|
+
async signOut() {
|
|
59
|
+
this.signOuts++;
|
|
60
|
+
}
|
|
61
|
+
fireAuthStateChanged(state) {
|
|
62
|
+
this.authState = state;
|
|
63
|
+
this.emitter.fire(state);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
describe('ChatGptCommandContribution', () => {
|
|
67
|
+
let authService;
|
|
68
|
+
let contribution;
|
|
69
|
+
let openedUrls;
|
|
70
|
+
let infoMessages;
|
|
71
|
+
let errorMessages;
|
|
72
|
+
let quickInput;
|
|
73
|
+
let quickInputRequests;
|
|
74
|
+
before(() => {
|
|
75
|
+
disableJSDOM = (0, jsdom_1.enableJSDOM)();
|
|
76
|
+
});
|
|
77
|
+
after(() => {
|
|
78
|
+
disableJSDOM();
|
|
79
|
+
});
|
|
80
|
+
beforeEach(async () => {
|
|
81
|
+
authService = new FakeAuthService();
|
|
82
|
+
openedUrls = [];
|
|
83
|
+
infoMessages = [];
|
|
84
|
+
errorMessages = [];
|
|
85
|
+
quickInput = undefined;
|
|
86
|
+
quickInputRequests = 0;
|
|
87
|
+
const messageService = {
|
|
88
|
+
// An action message stays open until the user picks one, which the tests model as a pending promise.
|
|
89
|
+
info: (message, ...actions) => {
|
|
90
|
+
infoMessages.push(message);
|
|
91
|
+
return actions.length ? new Promise(() => { }) : Promise.resolve(undefined);
|
|
92
|
+
},
|
|
93
|
+
error: (message) => {
|
|
94
|
+
errorMessages.push(message);
|
|
95
|
+
return Promise.resolve(undefined);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const windowService = { openNewWindow: (url) => { openedUrls.push(url); } };
|
|
99
|
+
const quickInputService = {
|
|
100
|
+
input: () => {
|
|
101
|
+
quickInputRequests++;
|
|
102
|
+
return Promise.resolve(quickInput);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const activationService = { isActive: true };
|
|
106
|
+
contribution = new chatgpt_command_contribution_1.ChatGptCommandContribution();
|
|
107
|
+
const preferenceService = { get: (_name, fallback) => fallback };
|
|
108
|
+
Object.assign(contribution, { authService, windowService, messageService, quickInputService, activationService, preferenceService });
|
|
109
|
+
contribution.init();
|
|
110
|
+
// The initial state is fetched asynchronously.
|
|
111
|
+
await Promise.resolve();
|
|
112
|
+
});
|
|
113
|
+
afterEach(() => {
|
|
114
|
+
contribution.dispose();
|
|
115
|
+
});
|
|
116
|
+
function registerCommands() {
|
|
117
|
+
const handlers = new Map();
|
|
118
|
+
contribution.registerCommands({
|
|
119
|
+
registerCommand: (command, handler) => handlers.set(command.id, handler)
|
|
120
|
+
});
|
|
121
|
+
return handlers;
|
|
122
|
+
}
|
|
123
|
+
it('offers signing in while there is no session and signing out once there is one', () => {
|
|
124
|
+
const handlers = registerCommands();
|
|
125
|
+
(0, chai_1.expect)(handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_IN.id).isEnabled()).to.equal(true);
|
|
126
|
+
(0, chai_1.expect)(handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_OUT.id).isEnabled()).to.equal(false);
|
|
127
|
+
authService.fireAuthStateChanged({ isAuthenticated: true, accountLabel: 'user@example.com' });
|
|
128
|
+
(0, chai_1.expect)(handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_IN.id).isEnabled()).to.equal(false);
|
|
129
|
+
(0, chai_1.expect)(handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_OUT.id).isEnabled()).to.equal(true);
|
|
130
|
+
});
|
|
131
|
+
function initWithPendingAuthState() {
|
|
132
|
+
contribution.dispose();
|
|
133
|
+
const lookup = new promise_util_1.Deferred();
|
|
134
|
+
authService.getAuthState = () => lookup.promise;
|
|
135
|
+
contribution = new chatgpt_command_contribution_1.ChatGptCommandContribution();
|
|
136
|
+
Object.assign(contribution, { authService });
|
|
137
|
+
contribution.init();
|
|
138
|
+
return lookup;
|
|
139
|
+
}
|
|
140
|
+
for (const isAuthenticated of [true, false]) {
|
|
141
|
+
it(`ignores an initial lookup after a newer ${isAuthenticated ? 'sign-in' : 'sign-out'} event`, async () => {
|
|
142
|
+
const lookup = initWithPendingAuthState();
|
|
143
|
+
const handlers = registerCommands();
|
|
144
|
+
authService.fireAuthStateChanged({ isAuthenticated });
|
|
145
|
+
lookup.resolve({ isAuthenticated: !isAuthenticated });
|
|
146
|
+
await lookup.promise;
|
|
147
|
+
(0, chai_1.expect)(handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_IN.id).isEnabled()).to.equal(!isAuthenticated);
|
|
148
|
+
(0, chai_1.expect)(handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_OUT.id).isEnabled()).to.equal(isAuthenticated);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
it('ignores an initial lookup completed after disposal', async () => {
|
|
152
|
+
const lookup = initWithPendingAuthState();
|
|
153
|
+
const handlers = registerCommands();
|
|
154
|
+
contribution.dispose();
|
|
155
|
+
authService.fireAuthStateChanged({ isAuthenticated: true });
|
|
156
|
+
lookup.resolve({ isAuthenticated: true });
|
|
157
|
+
await lookup.promise;
|
|
158
|
+
(0, chai_1.expect)(handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_IN.id).isEnabled()).to.equal(true);
|
|
159
|
+
(0, chai_1.expect)(handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_OUT.id).isEnabled()).to.equal(false);
|
|
160
|
+
});
|
|
161
|
+
it('hides both commands while the AI features are disabled', () => {
|
|
162
|
+
Object.assign(contribution, { activationService: { isActive: false } });
|
|
163
|
+
const handlers = registerCommands();
|
|
164
|
+
(0, chai_1.expect)(handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_IN.id).isVisible()).to.equal(false);
|
|
165
|
+
(0, chai_1.expect)(handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_OUT.id).isVisible()).to.equal(false);
|
|
166
|
+
});
|
|
167
|
+
it('hides both commands while the ChatGPT provider is disabled', () => {
|
|
168
|
+
Object.assign(contribution, { preferenceService: { get: () => false } });
|
|
169
|
+
const handlers = registerCommands();
|
|
170
|
+
(0, chai_1.expect)(handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_IN.id).isVisible()).to.equal(false);
|
|
171
|
+
(0, chai_1.expect)(handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_OUT.id).isVisible()).to.equal(false);
|
|
172
|
+
});
|
|
173
|
+
it('shows both commands when AI and the provider are enabled', () => {
|
|
174
|
+
const handlers = registerCommands();
|
|
175
|
+
(0, chai_1.expect)(handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_IN.id).isVisible()).to.equal(true);
|
|
176
|
+
(0, chai_1.expect)(handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_OUT.id).isVisible()).to.equal(true);
|
|
177
|
+
(0, chai_1.expect)(common_1.ChatGptPreferencesSchema.properties[common_1.CHATGPT_ENABLED_PREF].default).to.equal(true);
|
|
178
|
+
});
|
|
179
|
+
it('opens the authorization page and reports the account once the browser completed the sign in', async () => {
|
|
180
|
+
const handlers = registerCommands();
|
|
181
|
+
const signingIn = handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_IN.id).execute();
|
|
182
|
+
await Promise.resolve();
|
|
183
|
+
(0, chai_1.expect)(openedUrls).to.deep.equal([authService.session.authorizationUrl]);
|
|
184
|
+
authService.authState = { isAuthenticated: true, accountLabel: 'user@example.com' };
|
|
185
|
+
authService.login.resolve(true);
|
|
186
|
+
await signingIn;
|
|
187
|
+
(0, chai_1.expect)(infoMessages.pop()).to.contain('user@example.com');
|
|
188
|
+
(0, chai_1.expect)(quickInputRequests).to.equal(0);
|
|
189
|
+
});
|
|
190
|
+
for (const change of ['auth-event', 'dispose']) {
|
|
191
|
+
it(`ignores a post-login lookup after ${change}`, async () => {
|
|
192
|
+
const lookup = new promise_util_1.Deferred();
|
|
193
|
+
const lookupStarted = new promise_util_1.Deferred();
|
|
194
|
+
authService.getAuthState = () => {
|
|
195
|
+
lookupStarted.resolve();
|
|
196
|
+
return lookup.promise;
|
|
197
|
+
};
|
|
198
|
+
const handlers = registerCommands();
|
|
199
|
+
const signingIn = handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_IN.id).execute();
|
|
200
|
+
authService.login.resolve(true);
|
|
201
|
+
await lookupStarted.promise;
|
|
202
|
+
if (change === 'auth-event') {
|
|
203
|
+
authService.fireAuthStateChanged({ isAuthenticated: false });
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
contribution.dispose();
|
|
207
|
+
}
|
|
208
|
+
lookup.resolve({ isAuthenticated: true, accountLabel: 'old@example.com' });
|
|
209
|
+
await signingIn;
|
|
210
|
+
(0, chai_1.expect)(handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_IN.id).isEnabled()).to.equal(true);
|
|
211
|
+
(0, chai_1.expect)(handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_OUT.id).isEnabled()).to.equal(false);
|
|
212
|
+
(0, chai_1.expect)(infoMessages.some(message => message.includes('Signed in to ChatGPT'))).to.equal(false);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
it('asks for the authorization code when the callback listener is not reachable', async () => {
|
|
216
|
+
authService.session = { authorizationUrl: 'https://auth.openai.com/oauth/authorize', callbackListening: false };
|
|
217
|
+
quickInput = 'the-code';
|
|
218
|
+
const handlers = registerCommands();
|
|
219
|
+
await handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_IN.id).execute();
|
|
220
|
+
(0, chai_1.expect)(quickInputRequests).to.equal(1);
|
|
221
|
+
(0, chai_1.expect)(authService.completed).to.deep.equal(['the-code']);
|
|
222
|
+
});
|
|
223
|
+
it('abandons the sign in when the authorization code input is dismissed', async () => {
|
|
224
|
+
authService.session = { authorizationUrl: 'https://auth.openai.com/oauth/authorize', callbackListening: false };
|
|
225
|
+
quickInput = undefined;
|
|
226
|
+
const handlers = registerCommands();
|
|
227
|
+
await handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_IN.id).execute();
|
|
228
|
+
(0, chai_1.expect)(authService.completed).to.be.empty;
|
|
229
|
+
(0, chai_1.expect)(authService.cancelledLogins).to.equal(1);
|
|
230
|
+
(0, chai_1.expect)(infoMessages).to.be.empty;
|
|
231
|
+
});
|
|
232
|
+
it('cancels the sign in and reports the reason when it fails', async () => {
|
|
233
|
+
authService.startLoginError = new Error('the port is in use');
|
|
234
|
+
const handlers = registerCommands();
|
|
235
|
+
await handlers.get(chatgpt_command_contribution_1.ChatGptCommands.SIGN_IN.id).execute();
|
|
236
|
+
(0, chai_1.expect)(errorMessages.pop()).to.contain('the port is in use');
|
|
237
|
+
(0, chai_1.expect)(authService.cancelledLogins).to.equal(1);
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
//# sourceMappingURL=chatgpt-command-contribution.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatgpt-command-contribution.spec.js","sourceRoot":"","sources":["../../src/browser/chatgpt-command-contribution.spec.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF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AM,QAAQ,GAAG,gBAAgB,EAAE,CAAC;QACpC,MAAM,QAAQ,CAAC,GAAG,CAAC,8CAAe,CAAC,OAAO,CAAC,EAAE,CAAE,CAAC,OAAO,EAAE,CAAC;QAE1D,IAAA,aAAM,EAAC,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;QAC1C,IAAA,aAAM,EAAC,WAAW,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChD,IAAA,aAAM,EAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0DAA0D,EAAE,KAAK,IAAI,EAAE;QACtE,WAAW,CAAC,eAAe,GAAG,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAE9D,MAAM,QAAQ,GAAG,gBAAgB,EAAE,CAAC;QACpC,MAAM,QAAQ,CAAC,GAAG,CAAC,8CAAe,CAAC,OAAO,CAAC,EAAE,CAAE,CAAC,OAAO,EAAE,CAAC;QAE1D,IAAA,aAAM,EAAC,aAAa,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;QAC7D,IAAA,aAAM,EAAC,WAAW,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AAEP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AICorePreferences } from '@theia/ai-core/lib/common/ai-core-preferences';
|
|
2
|
+
import { ModelDiscoveryStatusService } from '@theia/ai-core/lib/browser';
|
|
3
|
+
import { PreferenceService } from '@theia/core';
|
|
4
|
+
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
|
5
|
+
import { ChatGptAuthService, ChatGptLanguageModelsManager, ChatGptModelDescription } from '../common';
|
|
6
|
+
/**
|
|
7
|
+
* The provider node of the AI Configuration view is keyed by the `ai-features.<segment>.*` preference segment,
|
|
8
|
+
* which differs from the `chatgpt/` prefix of the model ids.
|
|
9
|
+
*/
|
|
10
|
+
export declare const CHATGPT_DISCOVERY_PROVIDER_ID = "chatGpt";
|
|
11
|
+
export declare class ChatGptFrontendApplicationContribution implements FrontendApplicationContribution {
|
|
12
|
+
protected preferenceService: PreferenceService;
|
|
13
|
+
protected manager: ChatGptLanguageModelsManager;
|
|
14
|
+
protected aiCorePreferences: AICorePreferences;
|
|
15
|
+
protected authService: ChatGptAuthService;
|
|
16
|
+
protected discoveryStatus: ModelDiscoveryStatusService;
|
|
17
|
+
protected registeredModels: string[];
|
|
18
|
+
protected refreshGeneration: number;
|
|
19
|
+
/** Serializes the refreshes, so a slow one cannot register models the next one already dropped. */
|
|
20
|
+
protected refreshes: Promise<void>;
|
|
21
|
+
onStart(): void;
|
|
22
|
+
protected refreshModels(): Promise<void>;
|
|
23
|
+
protected doRefreshModels(generation: number): Promise<void>;
|
|
24
|
+
protected isEnabled(): boolean;
|
|
25
|
+
protected removeRegisteredModels(): void;
|
|
26
|
+
protected updateDisabledStatus(): void;
|
|
27
|
+
/** Signed-out accounts never register models, even when a list is configured. */
|
|
28
|
+
protected updateDiscoveryStatus(isAuthenticated: boolean, configured: boolean, models: string[]): void;
|
|
29
|
+
/** Per-model capabilities are resolved by the backend from the model id. */
|
|
30
|
+
protected createModelDescription(modelId: string): ChatGptModelDescription;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=chatgpt-frontend-application-contribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatgpt-frontend-application-contribution.d.ts","sourceRoot":"","sources":["../../src/browser/chatgpt-frontend-application-contribution.ts"],"names":[],"mappings":"AAgBA,OAAO,EACH,iBAAiB,EACpB,MAAM,+CAA+C,CAAC;AAEvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC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