@tencent-adp/portal-cli 0.0.2 → 0.0.4
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/dist/acp/agent.js +1 -1
- package/dist/acp/server.js +12 -7
- package/dist/auth/login.js +14 -3
- package/package.json +1 -1
package/dist/acp/agent.js
CHANGED
|
@@ -10,7 +10,7 @@ import { runAcpTurn } from './turn.js';
|
|
|
10
10
|
export function portalInitialize(needsLogin = false) {
|
|
11
11
|
return {
|
|
12
12
|
protocolVersion: PROTOCOL_VERSION,
|
|
13
|
-
agentInfo: { name: 'portal', title: 'Portal', version: '0.0.
|
|
13
|
+
agentInfo: { name: 'portal', title: 'Portal', version: '0.0.4' },
|
|
14
14
|
agentCapabilities: {
|
|
15
15
|
loadSession: true,
|
|
16
16
|
sessionCapabilities: { list: {} },
|
package/dist/acp/server.js
CHANGED
|
@@ -79,18 +79,23 @@ async function createAgent(interactive, request, canShowLoginUrl = false) {
|
|
|
79
79
|
});
|
|
80
80
|
if (!auth)
|
|
81
81
|
throw acp.RequestError.authRequired(undefined, '请先登录 Portal');
|
|
82
|
+
await finishLoginUrl();
|
|
82
83
|
const client = new PortalClient(auth);
|
|
83
84
|
const workbench = await loadWorkbench(client, auth.spaceId);
|
|
84
85
|
return new PortalAcpAgent(client, auth.spaceId, workbench, auth.baseUrl);
|
|
85
86
|
}
|
|
86
87
|
finally {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
await finishLoginUrl();
|
|
89
|
+
}
|
|
90
|
+
async function finishLoginUrl() {
|
|
91
|
+
if (!showedLoginUrl || !request)
|
|
92
|
+
return;
|
|
93
|
+
showedLoginUrl = false;
|
|
94
|
+
await request.notify(acp.methods.client.elicitation.complete, {
|
|
95
|
+
elicitationId: LOGIN_URL_ID,
|
|
96
|
+
}).catch((error) => {
|
|
97
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
98
|
+
});
|
|
94
99
|
}
|
|
95
100
|
}
|
|
96
101
|
//# sourceMappingURL=server.js.map
|
package/dist/auth/login.js
CHANGED
|
@@ -59,12 +59,15 @@ async function login(saved, showUrl) {
|
|
|
59
59
|
});
|
|
60
60
|
console.error('请在浏览器打开这个地址,登录 Portal,并选择要授权的空间。');
|
|
61
61
|
console.error(url);
|
|
62
|
-
openBrowser(url);
|
|
63
62
|
if (showUrl) {
|
|
63
|
+
// Zed shows its own Open button. Opening the browser here races that prompt.
|
|
64
64
|
void Promise.resolve(showUrl(url)).catch((error) => {
|
|
65
65
|
console.error(errorText(error));
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
|
+
else {
|
|
69
|
+
openBrowser(url);
|
|
70
|
+
}
|
|
68
71
|
const code = await withTimeout(callback.code, 5 * 60 * 1000);
|
|
69
72
|
const tokens = await exchangeCode({
|
|
70
73
|
tokenEndpoint: endpoints.tokenEndpoint,
|
|
@@ -258,12 +261,20 @@ export function startLoginCallback(state, port = CALLBACK_PORT) {
|
|
|
258
261
|
});
|
|
259
262
|
}
|
|
260
263
|
function answer(response, status, text) {
|
|
261
|
-
response.writeHead(status, {
|
|
262
|
-
|
|
264
|
+
response.writeHead(status, {
|
|
265
|
+
'content-type': 'text/html; charset=utf-8',
|
|
266
|
+
connection: 'close',
|
|
267
|
+
});
|
|
268
|
+
response.end(`<!doctype html><meta charset="utf-8"><title>Portal</title><p>${text}</p>`, () => {
|
|
269
|
+
response.socket?.destroy();
|
|
270
|
+
});
|
|
263
271
|
}
|
|
264
272
|
function closeServer(server) {
|
|
265
273
|
return new Promise((resolve) => {
|
|
266
274
|
server.close(() => resolve());
|
|
275
|
+
// A browser that keeps the callback socket open would otherwise hold
|
|
276
|
+
// server.close() until the tab is closed, so Zed never leaves the login page.
|
|
277
|
+
server.closeAllConnections();
|
|
267
278
|
});
|
|
268
279
|
}
|
|
269
280
|
function openBrowser(url) {
|