@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2026 EclipseSource and others.
|
|
3
|
+
// Copyright (C) 2026 EclipseSource GmbH and others.
|
|
4
4
|
//
|
|
5
5
|
// This program and the accompanying materials are made available under the
|
|
6
6
|
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
@@ -16,183 +16,119 @@
|
|
|
16
16
|
// *****************************************************************************
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
const chai_1 = require("chai");
|
|
19
|
-
const sinon = require("sinon");
|
|
20
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
21
|
-
const key_store_1 = require("@theia/core/lib/common/key-store");
|
|
22
|
-
const copilot_oauth_config_1 = require("../common/copilot-oauth-config");
|
|
23
|
-
const copilot_auth_service_impl_1 = require("./copilot-auth-service-impl");
|
|
24
|
-
const logger_1 = require("@theia/core/lib/common/logger");
|
|
25
19
|
const mock_logger_1 = require("@theia/core/lib/common/test/mock-logger");
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
findPassword: sinon.stub().resolves(undefined),
|
|
38
|
-
findCredentials: sinon.stub().resolves([]),
|
|
39
|
-
keys: sinon.stub().resolves([])
|
|
20
|
+
const copilot_auth_service_impl_1 = require("./copilot-auth-service-impl");
|
|
21
|
+
class TestableCopilotAuthServiceImpl extends copilot_auth_service_impl_1.CopilotAuthServiceImpl {
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
this.stubs = {
|
|
25
|
+
legacyRemoved: false,
|
|
26
|
+
legacyDelay: 0,
|
|
27
|
+
authState: { isAuthenticated: false },
|
|
28
|
+
authStateCalls: 0,
|
|
29
|
+
configuredPath: undefined,
|
|
30
|
+
deleted: 0
|
|
40
31
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
const token = await authService.getAccessToken();
|
|
63
|
-
(0, chai_1.expect)(token).to.equal(oauthToken);
|
|
64
|
-
});
|
|
65
|
-
it('should return undefined when stored data is malformed', async () => {
|
|
66
|
-
getPasswordStub.resolves('not-valid-json');
|
|
67
|
-
const token = await authService.getAccessToken();
|
|
68
|
-
(0, chai_1.expect)(token).to.be.undefined;
|
|
32
|
+
const stubs = this.stubs;
|
|
33
|
+
Object.assign(this, {
|
|
34
|
+
logger: new mock_logger_1.MockLogger(),
|
|
35
|
+
credentialStore: {
|
|
36
|
+
deleteLegacy: async () => {
|
|
37
|
+
await new Promise(resolve => setTimeout(resolve, stubs.legacyDelay));
|
|
38
|
+
return stubs.legacyRemoved;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
cliLocator: { setConfiguredPath: (path) => { stubs.configuredPath = path; } },
|
|
42
|
+
cliAuthProvider: {
|
|
43
|
+
getAuthState: async () => {
|
|
44
|
+
stubs.authStateCalls++;
|
|
45
|
+
return stubs.authState;
|
|
46
|
+
},
|
|
47
|
+
signOut: async () => {
|
|
48
|
+
stubs.deleted++;
|
|
49
|
+
stubs.authState = { isAuthenticated: false };
|
|
50
|
+
},
|
|
51
|
+
waitForLogin: async () => true
|
|
52
|
+
}
|
|
69
53
|
});
|
|
54
|
+
}
|
|
55
|
+
/** Runs what `@postConstruct` runs in production. */
|
|
56
|
+
start() {
|
|
57
|
+
this.init();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
describe('CopilotAuthServiceImpl - migration of the previous sign-in', () => {
|
|
61
|
+
it('should report that a new sign-in is required, even when asked before the cleanup finished', async () => {
|
|
62
|
+
const service = new TestableCopilotAuthServiceImpl();
|
|
63
|
+
service.stubs.legacyRemoved = true;
|
|
64
|
+
// The frontend evaluates the flag once at startup, so a state cached without it loses it.
|
|
65
|
+
service.stubs.legacyDelay = 20;
|
|
66
|
+
service.start();
|
|
67
|
+
(0, chai_1.expect)(await service.getAuthState()).to.deep.include({ isAuthenticated: false, migrationRequired: true });
|
|
70
68
|
});
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
(0, chai_1.expect)(state.isAuthenticated).to.be.false;
|
|
76
|
-
(0, chai_1.expect)(state.accountLabel).to.be.undefined;
|
|
77
|
-
});
|
|
78
|
-
it('should return authenticated with account label when credentials exist', async () => {
|
|
79
|
-
getPasswordStub.resolves(JSON.stringify({
|
|
80
|
-
accessToken: 'gho_test',
|
|
81
|
-
accountLabel: 'testuser',
|
|
82
|
-
enterpriseUrl: undefined
|
|
83
|
-
}));
|
|
84
|
-
const state = await authService.getAuthState();
|
|
85
|
-
(0, chai_1.expect)(state.isAuthenticated).to.be.true;
|
|
86
|
-
(0, chai_1.expect)(state.accountLabel).to.equal('testuser');
|
|
87
|
-
});
|
|
88
|
-
it('should return enterprise URL when stored', async () => {
|
|
89
|
-
getPasswordStub.resolves(JSON.stringify({
|
|
90
|
-
accessToken: 'gho_test',
|
|
91
|
-
accountLabel: 'testuser',
|
|
92
|
-
enterpriseUrl: 'github.mycompany.com'
|
|
93
|
-
}));
|
|
94
|
-
const state = await authService.getAuthState();
|
|
95
|
-
(0, chai_1.expect)(state.isAuthenticated).to.be.true;
|
|
96
|
-
(0, chai_1.expect)(state.enterpriseUrl).to.equal('github.mycompany.com');
|
|
97
|
-
});
|
|
98
|
-
it('should clear outdated non-gho_ token and flag migration', async () => {
|
|
99
|
-
getPasswordStub.resolves(JSON.stringify({
|
|
100
|
-
accessToken: 'ghu_old_token',
|
|
101
|
-
accountLabel: 'testuser'
|
|
102
|
-
}));
|
|
103
|
-
const state = await authService.getAuthState();
|
|
104
|
-
(0, chai_1.expect)(state.isAuthenticated).to.be.false;
|
|
105
|
-
(0, chai_1.expect)(state.migrationRequired).to.be.true;
|
|
106
|
-
(0, chai_1.expect)(keyStoreService.deletePassword.calledOnce).to.be.true;
|
|
107
|
-
});
|
|
108
|
-
it('should cache the auth state after first retrieval', async () => {
|
|
109
|
-
getPasswordStub.resolves(JSON.stringify({
|
|
110
|
-
accessToken: 'gho_test',
|
|
111
|
-
accountLabel: 'testuser'
|
|
112
|
-
}));
|
|
113
|
-
const state1 = await authService.getAuthState();
|
|
114
|
-
const state2 = await authService.getAuthState();
|
|
115
|
-
(0, chai_1.expect)(state1).to.equal(state2);
|
|
116
|
-
(0, chai_1.expect)(getPasswordStub.calledOnce).to.be.true;
|
|
117
|
-
});
|
|
69
|
+
it('should not claim a migration when there was nothing to discard', async () => {
|
|
70
|
+
const service = new TestableCopilotAuthServiceImpl();
|
|
71
|
+
service.start();
|
|
72
|
+
(0, chai_1.expect)(await service.getAuthState()).to.not.have.property('migrationRequired');
|
|
118
73
|
});
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
(0, chai_1.expect)(stateAfter.isAuthenticated).to.be.false;
|
|
132
|
-
});
|
|
133
|
-
it('should fire auth state changed event on sign out', async () => {
|
|
134
|
-
const stateChanges = [];
|
|
135
|
-
authService.onAuthStateChanged(state => stateChanges.push(state));
|
|
136
|
-
await authService.signOut();
|
|
137
|
-
(0, chai_1.expect)(stateChanges).to.have.lengthOf(1);
|
|
138
|
-
(0, chai_1.expect)(stateChanges[0].isAuthenticated).to.be.false;
|
|
139
|
-
});
|
|
140
|
-
it('should delete credentials from keystore on sign out', async () => {
|
|
141
|
-
await authService.signOut();
|
|
142
|
-
(0, chai_1.expect)(keyStoreService.deletePassword.calledOnce).to.be.true;
|
|
143
|
-
});
|
|
144
|
-
it('should notify client on sign out', async () => {
|
|
145
|
-
const client = { onAuthStateChanged: sinon.stub() };
|
|
146
|
-
authService.setClient(client);
|
|
147
|
-
await authService.signOut();
|
|
148
|
-
(0, chai_1.expect)(client.onAuthStateChanged.calledOnce).to.be.true;
|
|
149
|
-
(0, chai_1.expect)(client.onAuthStateChanged.firstCall.args[0].isAuthenticated).to.be.false;
|
|
150
|
-
});
|
|
74
|
+
it('should not claim a migration for a user who is signed in', async () => {
|
|
75
|
+
const service = new TestableCopilotAuthServiceImpl();
|
|
76
|
+
service.stubs.legacyRemoved = true;
|
|
77
|
+
service.stubs.authState = { isAuthenticated: true, accountLabel: 'octocat' };
|
|
78
|
+
service.start();
|
|
79
|
+
(0, chai_1.expect)(await service.getAuthState()).to.not.have.property('migrationRequired');
|
|
80
|
+
});
|
|
81
|
+
it('should survive a keychain that cannot be read', async () => {
|
|
82
|
+
const service = new TestableCopilotAuthServiceImpl();
|
|
83
|
+
Object.assign(service, { credentialStore: { deleteLegacy: async () => { throw new Error('keychain unavailable'); } } });
|
|
84
|
+
service.start();
|
|
85
|
+
(0, chai_1.expect)(await service.getAuthState()).to.deep.equal({ isAuthenticated: false });
|
|
151
86
|
});
|
|
152
87
|
});
|
|
153
|
-
describe('CopilotAuthServiceImpl
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
let authService;
|
|
161
|
-
let getPasswordStub;
|
|
162
|
-
let deletePasswordStub;
|
|
163
|
-
beforeEach(() => {
|
|
164
|
-
const container = new inversify_1.Container();
|
|
165
|
-
container.bind(logger_1.ILogger).to(mock_logger_1.MockLogger).inSingletonScope();
|
|
166
|
-
getPasswordStub = sinon.stub().resolves(undefined);
|
|
167
|
-
deletePasswordStub = sinon.stub().resolves(true);
|
|
168
|
-
const keyStoreService = {
|
|
169
|
-
setPassword: sinon.stub().resolves(),
|
|
170
|
-
getPassword: getPasswordStub,
|
|
171
|
-
deletePassword: deletePasswordStub,
|
|
172
|
-
findPassword: sinon.stub().resolves(undefined),
|
|
173
|
-
findCredentials: sinon.stub().resolves([]),
|
|
174
|
-
keys: sinon.stub().resolves([])
|
|
175
|
-
};
|
|
176
|
-
container.bind(key_store_1.KeyStoreService).toConstantValue(keyStoreService);
|
|
177
|
-
container.bind(copilot_oauth_config_1.CopilotOAuthConfig).toConstantValue(customConfig);
|
|
178
|
-
container.bind(copilot_auth_service_impl_1.CopilotAuthServiceImpl).toSelf().inSingletonScope();
|
|
179
|
-
authService = container.get(copilot_auth_service_impl_1.CopilotAuthServiceImpl);
|
|
88
|
+
describe('CopilotAuthServiceImpl - state', () => {
|
|
89
|
+
it('should ask the provider once and serve the cached state afterwards', async () => {
|
|
90
|
+
const service = new TestableCopilotAuthServiceImpl();
|
|
91
|
+
service.start();
|
|
92
|
+
await service.getAuthState();
|
|
93
|
+
await service.getAuthState();
|
|
94
|
+
(0, chai_1.expect)(service.stubs.authStateCalls).to.equal(1);
|
|
180
95
|
});
|
|
181
|
-
|
|
182
|
-
|
|
96
|
+
it('should report the new state after a sign-in', async () => {
|
|
97
|
+
const service = new TestableCopilotAuthServiceImpl();
|
|
98
|
+
service.start();
|
|
99
|
+
await service.getAuthState();
|
|
100
|
+
service.stubs.authState = { isAuthenticated: true, accountLabel: 'octocat' };
|
|
101
|
+
const reported = [];
|
|
102
|
+
service.onAuthStateChanged(state => reported.push(state));
|
|
103
|
+
(0, chai_1.expect)(await service.waitForSignIn()).to.be.true;
|
|
104
|
+
(0, chai_1.expect)(reported).to.deep.equal([{ isAuthenticated: true, accountLabel: 'octocat' }]);
|
|
105
|
+
(0, chai_1.expect)(await service.getAuthState()).to.deep.equal({ isAuthenticated: true, accountLabel: 'octocat' });
|
|
183
106
|
});
|
|
184
|
-
it('should
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
(
|
|
191
|
-
|
|
107
|
+
it('should report the new state after signing out', async () => {
|
|
108
|
+
const service = new TestableCopilotAuthServiceImpl();
|
|
109
|
+
service.stubs.authState = { isAuthenticated: true, accountLabel: 'octocat' };
|
|
110
|
+
service.start();
|
|
111
|
+
await service.getAuthState();
|
|
112
|
+
const reported = [];
|
|
113
|
+
service.onAuthStateChanged(state => reported.push(state));
|
|
114
|
+
await service.signOut();
|
|
115
|
+
(0, chai_1.expect)(service.stubs.deleted).to.equal(1);
|
|
116
|
+
(0, chai_1.expect)(reported).to.deep.equal([{ isAuthenticated: false }]);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
describe('CopilotAuthServiceImpl - executable path', () => {
|
|
120
|
+
it('should hand the configured location to the lookup, which cannot read preferences itself', async () => {
|
|
121
|
+
const service = new TestableCopilotAuthServiceImpl();
|
|
122
|
+
service.start();
|
|
123
|
+
await service.setExecutablePath('/opt/copilot/copilot');
|
|
124
|
+
(0, chai_1.expect)(service.stubs.configuredPath).to.equal('/opt/copilot/copilot');
|
|
192
125
|
});
|
|
193
|
-
it('should
|
|
194
|
-
|
|
195
|
-
|
|
126
|
+
it('should hand on that nothing is configured, so that the CLI is searched for', async () => {
|
|
127
|
+
const service = new TestableCopilotAuthServiceImpl();
|
|
128
|
+
service.start();
|
|
129
|
+
await service.setExecutablePath('/opt/copilot/copilot');
|
|
130
|
+
await service.setExecutablePath(undefined);
|
|
131
|
+
(0, chai_1.expect)(service.stubs.configuredPath).to.be.undefined;
|
|
196
132
|
});
|
|
197
133
|
});
|
|
198
134
|
//# sourceMappingURL=copilot-auth-service-impl.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copilot-auth-service-impl.spec.js","sourceRoot":"","sources":["../../src/node/copilot-auth-service-impl.spec.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF
|
|
1
|
+
{"version":3,"file":"copilot-auth-service-impl.spec.js","sourceRoot":"","sources":["../../src/node/copilot-auth-service-impl.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;AAC9B,yEAAqE;AAErE,2EAAqE;AAarE,MAAM,8BAA+B,SAAQ,kDAAsB;IAW/D;QACI,KAAK,EAAE,CAAC;QAVH,UAAK,GAAU;YACpB,aAAa,EAAE,KAAK;YACpB,WAAW,EAAE,CAAC;YACd,SAAS,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE;YACrC,cAAc,EAAE,CAAC;YACjB,cAAc,EAAE,SAAS;YACzB,OAAO,EAAE,CAAC;SACb,CAAC;QAIE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;YAChB,MAAM,EAAE,IAAI,wBAAU,EAAE;YACxB,eAAe,EAAE;gBACb,YAAY,EAAE,KAAK,IAAI,EAAE;oBACrB,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;oBACrE,OAAO,KAAK,CAAC,aAAa,CAAC;gBAC/B,CAAC;aACJ;YACD,UAA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AC,iBAAiB,CAAC,sBAAsB,CAAC,CAAC;QACxD,MAAM,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAC3C,IAAA,aAAM,EAAC,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC;IACzD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copilot-backend-module.d.ts","sourceRoot":"","sources":["../../src/node/copilot-backend-module.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;
|
|
1
|
+
{"version":3,"file":"copilot-backend-module.d.ts","sourceRoot":"","sources":["../../src/node/copilot-backend-module.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AAkD/D,wBAEG"}
|
|
@@ -19,10 +19,19 @@ const inversify_1 = require("@theia/core/shared/inversify");
|
|
|
19
19
|
const core_1 = require("@theia/core");
|
|
20
20
|
const connection_container_module_1 = require("@theia/core/lib/node/messaging/connection-container-module");
|
|
21
21
|
const common_1 = require("../common");
|
|
22
|
-
const copilot_oauth_config_1 = require("../common/copilot-oauth-config");
|
|
23
22
|
const copilot_language_models_manager_impl_1 = require("./copilot-language-models-manager-impl");
|
|
23
|
+
const copilot_sdk_client_provider_1 = require("./copilot-sdk-client-provider");
|
|
24
|
+
const copilot_sdk_loader_1 = require("./copilot-sdk-loader");
|
|
25
|
+
const copilot_cli_auth_provider_1 = require("./copilot-cli-auth-provider");
|
|
26
|
+
const copilot_cli_locator_1 = require("./copilot-cli-locator");
|
|
27
|
+
const copilot_credential_store_1 = require("./copilot-credential-store");
|
|
24
28
|
const copilot_auth_service_impl_1 = require("./copilot-auth-service-impl");
|
|
25
29
|
const copilotConnectionModule = connection_container_module_1.ConnectionContainerModule.create(({ bind }) => {
|
|
30
|
+
bind(copilot_cli_locator_1.CopilotCliLocator).toSelf().inSingletonScope();
|
|
31
|
+
bind(copilot_sdk_loader_1.CopilotSdkLoader).toSelf().inSingletonScope();
|
|
32
|
+
bind(copilot_credential_store_1.CopilotCredentialStore).toSelf().inSingletonScope();
|
|
33
|
+
bind(copilot_sdk_client_provider_1.CopilotSdkClientProvider).toSelf().inSingletonScope();
|
|
34
|
+
bind(copilot_cli_auth_provider_1.CopilotCliAuthProvider).toSelf().inSingletonScope();
|
|
26
35
|
bind(copilot_auth_service_impl_1.CopilotAuthServiceImpl).toSelf().inSingletonScope();
|
|
27
36
|
bind(common_1.CopilotAuthService).toService(copilot_auth_service_impl_1.CopilotAuthServiceImpl);
|
|
28
37
|
bind(copilot_language_models_manager_impl_1.CopilotLanguageModelsManagerImpl).toSelf().inSingletonScope();
|
|
@@ -35,7 +44,6 @@ const copilotConnectionModule = connection_container_module_1.ConnectionContaine
|
|
|
35
44
|
bind(core_1.ConnectionHandler).toDynamicValue(ctx => new core_1.RpcConnectionHandler(common_1.COPILOT_LANGUAGE_MODELS_MANAGER_PATH, () => ctx.container.get(common_1.CopilotLanguageModelsManager))).inSingletonScope();
|
|
36
45
|
});
|
|
37
46
|
exports.default = new inversify_1.ContainerModule(bind => {
|
|
38
|
-
bind(copilot_oauth_config_1.CopilotOAuthConfig).toConstantValue(copilot_oauth_config_1.DEFAULT_COPILOT_OAUTH_CONFIG);
|
|
39
47
|
bind(connection_container_module_1.ConnectionContainerModule).toConstantValue(copilotConnectionModule);
|
|
40
48
|
});
|
|
41
49
|
//# sourceMappingURL=copilot-backend-module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copilot-backend-module.js","sourceRoot":"","sources":["../../src/node/copilot-backend-module.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,4DAA+D;AAC/D,sCAAsE;AACtE,4GAAuG;AACvG,sCAMmB;AACnB,
|
|
1
|
+
{"version":3,"file":"copilot-backend-module.js","sourceRoot":"","sources":["../../src/node/copilot-backend-module.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,4DAA+D;AAC/D,sCAAsE;AACtE,4GAAuG;AACvG,sCAMmB;AACnB,iGAA0F;AAC1F,+EAAyE;AACzE,6DAAwD;AACxD,2EAAqE;AACrE,+DAA0D;AAC1D,yEAAoE;AACpE,2EAAqE;AAErE,MAAM,uBAAuB,GAAG,uDAAyB,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;IAC1E,IAAI,CAAC,uCAAiB,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACpD,IAAI,CAAC,qCAAgB,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACnD,IAAI,CAAC,iDAAsB,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACzD,IAAI,CAAC,sDAAwB,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAC3D,IAAI,CAAC,kDAAsB,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAEzD,IAAI,CAAC,kDAAsB,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACzD,IAAI,CAAC,2BAAkB,CAAC,CAAC,SAAS,CAAC,kDAAsB,CAAC,CAAC;IAE3D,IAAI,CAAC,uEAAgC,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACnE,IAAI,CAAC,qCAA4B,CAAC,CAAC,SAAS,CAAC,uEAAgC,CAAC,CAAC;IAE/E,IAAI,CAAC,wBAAiB,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CACzC,IAAI,2BAAoB,CACpB,kCAAyB,EACzB,MAAM,CAAC,EAAE;QACL,MAAM,WAAW,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAAyB,2BAAkB,CAAC,CAAC;QAClF,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC9B,OAAO,WAAW,CAAC;IACvB,CAAC,CACJ,CACJ,CAAC,gBAAgB,EAAE,CAAC;IAErB,IAAI,CAAC,wBAAiB,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CACzC,IAAI,2BAAoB,CACpB,6CAAoC,EACpC,GAAG,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,qCAA4B,CAAC,CACxD,CACJ,CAAC,gBAAgB,EAAE,CAAC;AACzB,CAAC,CAAC,CAAC;AAEH,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,uDAAyB,CAAC,CAAC,eAAe,CAAC,uBAAuB,CAAC,CAAC;AAC7E,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { ChildProcess } from 'child_process';
|
|
2
|
+
import { Deferred } from '@theia/core/lib/common/promise-util';
|
|
3
|
+
import { ILogger } from '@theia/core';
|
|
4
|
+
import { CopilotAuthState, DeviceCodeResponse } from '../common/copilot-auth-service';
|
|
5
|
+
import { CopilotCliLocator } from './copilot-cli-locator';
|
|
6
|
+
import { CopilotCredentialStore } from './copilot-credential-store';
|
|
7
|
+
import { CopilotSdkClientProvider } from './copilot-sdk-client-provider';
|
|
8
|
+
/**
|
|
9
|
+
* Authentication against GitHub Copilot, performed by the official Copilot CLI on our behalf.
|
|
10
|
+
*
|
|
11
|
+
* Access to the Copilot features is granted per OAuth application and the built-in Theia OAuth app
|
|
12
|
+
* is not entitled for them, whereas the Copilot CLI is. This provider therefore does not run an
|
|
13
|
+
* OAuth flow of its own but drives `copilot login --device-code` and reports its progress, so that
|
|
14
|
+
* the familiar sign-in dialog can be used.
|
|
15
|
+
*
|
|
16
|
+
* The credentials end up owned by this application rather than by the CLI: the login is run against
|
|
17
|
+
* a private, temporary Copilot home with the system keychain disabled, so that the CLI writes its
|
|
18
|
+
* token there instead of into the user's keyring. The token is then moved into
|
|
19
|
+
* {@link CopilotCredentialStore} and the temporary home is removed. Signing out consequently only
|
|
20
|
+
* has to delete our own entry, and never touches credentials of the user's machine such as their
|
|
21
|
+
* keyring entries or their GitHub CLI sign-in.
|
|
22
|
+
*/
|
|
23
|
+
export declare class CopilotCliAuthProvider {
|
|
24
|
+
protected readonly sdkClientProvider: CopilotSdkClientProvider;
|
|
25
|
+
protected readonly cliLocator: CopilotCliLocator;
|
|
26
|
+
protected readonly credentialStore: CopilotCredentialStore;
|
|
27
|
+
protected readonly logger: ILogger;
|
|
28
|
+
protected loginProcess: ChildProcess | undefined;
|
|
29
|
+
protected loginResult: Deferred<boolean> | undefined;
|
|
30
|
+
protected loginHome: string | undefined;
|
|
31
|
+
protected loginEnterpriseUrl: string | undefined;
|
|
32
|
+
protected loginAccountLabel: string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Stops a sign-in that is still in progress when the connection this provider belongs to closes.
|
|
35
|
+
* Unbinding a container runs `@preDestroy` rather than `dispose`, matching the client provider.
|
|
36
|
+
* Without this, the `copilot login` child process and the temporary home holding its token would
|
|
37
|
+
* be left behind.
|
|
38
|
+
*/
|
|
39
|
+
protected stop(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Starts `copilot login --device-code` and resolves once it reported the code the user has to
|
|
42
|
+
* enter. The process keeps running and polls GitHub itself until {@link waitForLogin} is awaited.
|
|
43
|
+
*/
|
|
44
|
+
startLogin(enterpriseUrl?: string): Promise<DeviceCodeResponse>;
|
|
45
|
+
/**
|
|
46
|
+
* Waits for the login started by {@link startLogin} to complete.
|
|
47
|
+
* Resolves `false` when the authorization was denied or expired.
|
|
48
|
+
*/
|
|
49
|
+
waitForLogin(): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* Moves the token the CLI just persisted into our own credential store.
|
|
52
|
+
*/
|
|
53
|
+
protected storeCredentials(home: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Terminates a login that is still in progress, if any.
|
|
56
|
+
*
|
|
57
|
+
* Resolves once the token the CLI may already have written has been removed again, so that a
|
|
58
|
+
* caller which cancels a sign-in can rely on nothing being left behind in plain text.
|
|
59
|
+
*/
|
|
60
|
+
cancelLogin(): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Reports whether this application holds Copilot credentials.
|
|
63
|
+
*
|
|
64
|
+
* Deliberately based on our own store rather than on what the Copilot CLI reports: the CLI also
|
|
65
|
+
* accepts a token from the environment or the sign-in of the GitHub CLI, and neither of those is
|
|
66
|
+
* a sign-in of this application, so neither may make it appear signed in.
|
|
67
|
+
*/
|
|
68
|
+
getAuthState(): Promise<CopilotAuthState>;
|
|
69
|
+
/**
|
|
70
|
+
* Discards the credentials of this application. Nothing outside of it is touched.
|
|
71
|
+
*/
|
|
72
|
+
signOut(): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Creates the private Copilot home the login is run against.
|
|
75
|
+
*/
|
|
76
|
+
protected createLoginHome(): Promise<string>;
|
|
77
|
+
/**
|
|
78
|
+
* Writes the opener the CLI is pointed at instead of a real browser, and returns its path.
|
|
79
|
+
*
|
|
80
|
+
* The CLI opens a browser whenever it believes one is available, even for the device code flow, and
|
|
81
|
+
* prefers the command in `BROWSER` over the opener of the platform. Pointing it at a script that
|
|
82
|
+
* does nothing is therefore the reliable way to keep the flow in the dialog, where the user can read
|
|
83
|
+
* and copy the code. Opening a browser would also be wrong whenever the backend does not run on the
|
|
84
|
+
* user's own machine.
|
|
85
|
+
*/
|
|
86
|
+
protected createNoopBrowser(home: string): Promise<string>;
|
|
87
|
+
/**
|
|
88
|
+
* Removes the private Copilot home, including the token the CLI wrote into it.
|
|
89
|
+
*/
|
|
90
|
+
protected removeLoginHome(home: string): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Builds the environment for the login process.
|
|
93
|
+
*
|
|
94
|
+
* The CLI is pointed at a private home and its use of the system keychain is disabled, so that
|
|
95
|
+
* it persists the token where we can take it over instead of in the keyring of the user. Tokens
|
|
96
|
+
* from the environment are removed so that a sign-in always establishes fresh credentials rather
|
|
97
|
+
* than silently succeeding with something the user configured elsewhere.
|
|
98
|
+
*/
|
|
99
|
+
protected createLoginEnv(home: string, noopBrowser: string): Record<string, string | undefined>;
|
|
100
|
+
/**
|
|
101
|
+
* Searches the configuration the CLI wrote in its private home for the persisted token.
|
|
102
|
+
*
|
|
103
|
+
* The file and the field the CLI uses are not part of its public interface, so every JSON file it
|
|
104
|
+
* wrote is searched for a value shaped like a GitHub token rather than relying on a fixed layout.
|
|
105
|
+
*/
|
|
106
|
+
protected findStoredToken(home: string): Promise<string | undefined>;
|
|
107
|
+
/**
|
|
108
|
+
* The files of the private home that are inspected for the token.
|
|
109
|
+
*
|
|
110
|
+
* The logs are skipped, and the configuration the CLI writes is not plain JSON but carries
|
|
111
|
+
* comments, so the files are searched as text rather than parsed.
|
|
112
|
+
*/
|
|
113
|
+
protected listCandidateFiles(home: string): Promise<string[]>;
|
|
114
|
+
/**
|
|
115
|
+
* Searches text for a value shaped like a GitHub token.
|
|
116
|
+
*
|
|
117
|
+
* Only the files the CLI wrote into the private home of this sign-in are searched, so anything
|
|
118
|
+
* shaped like a token in them is the token that was just obtained.
|
|
119
|
+
*/
|
|
120
|
+
protected findTokenInText(text: string): string | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Extracts the login the CLI reported for the account that signed in, if it reported one.
|
|
123
|
+
*/
|
|
124
|
+
protected parseAccountLabel(output: string): string | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* Extracts the verification URL and the user code from the output of the CLI.
|
|
127
|
+
* Returns `undefined` while the output does not contain both yet.
|
|
128
|
+
*/
|
|
129
|
+
protected parseDeviceCode(output: string): DeviceCodeResponse | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* Describes why a login failed, based on what the CLI reported.
|
|
132
|
+
*
|
|
133
|
+
* A line that names the problem is preferred, and the tail of the output is used otherwise, since
|
|
134
|
+
* the wording of the CLI is not stable enough to rely on and a bare exit code is not diagnosable.
|
|
135
|
+
*/
|
|
136
|
+
protected extractFailure(output: string): string | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* Turns the configured GitHub Enterprise deployment into the URL the CLI is pointed at.
|
|
139
|
+
*
|
|
140
|
+
* A bare domain is the expected form and gets a scheme. Plain HTTP is upgraded rather than passed
|
|
141
|
+
* on: the sign-in carries credentials, and a host that only matched "http" at the start of its
|
|
142
|
+
* name, such as `httpbin.example.com`, must not be mistaken for a URL that already has a scheme.
|
|
143
|
+
*/
|
|
144
|
+
protected toHostUrl(enterpriseUrl: string): string;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=copilot-cli-auth-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copilot-cli-auth-provider.d.ts","sourceRoot":"","sources":["../../src/node/copilot-cli-auth-provider.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,YAAY,EAAS,MAAM,eAAe,CAAC;AAKpD,OAAO,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAO,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACtF,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAA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