@tencent-adp/portal-cli 0.0.2 → 0.0.3

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 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.2' },
13
+ agentInfo: { name: 'portal', title: 'Portal', version: '0.0.3' },
14
14
  agentCapabilities: {
15
15
  loadSession: true,
16
16
  sessionCapabilities: { list: {} },
@@ -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
- if (showedLoginUrl && request) {
88
- await request.notify(acp.methods.client.elicitation.complete, {
89
- elicitationId: LOGIN_URL_ID,
90
- }).catch((error) => {
91
- console.error(error instanceof Error ? error.message : String(error));
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
@@ -258,12 +258,20 @@ export function startLoginCallback(state, port = CALLBACK_PORT) {
258
258
  });
259
259
  }
260
260
  function answer(response, status, text) {
261
- response.writeHead(status, { 'content-type': 'text/html; charset=utf-8' });
262
- response.end(`<!doctype html><meta charset="utf-8"><title>Portal</title><p>${text}</p>`);
261
+ response.writeHead(status, {
262
+ 'content-type': 'text/html; charset=utf-8',
263
+ connection: 'close',
264
+ });
265
+ response.end(`<!doctype html><meta charset="utf-8"><title>Portal</title><p>${text}</p>`, () => {
266
+ response.socket?.destroy();
267
+ });
263
268
  }
264
269
  function closeServer(server) {
265
270
  return new Promise((resolve) => {
266
271
  server.close(() => resolve());
272
+ // A browser that keeps the callback socket open would otherwise hold
273
+ // server.close() until the tab is closed, so Zed never leaves the login page.
274
+ server.closeAllConnections();
267
275
  });
268
276
  }
269
277
  function openBrowser(url) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tencent-adp/portal-cli",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Talk to a Portal agent and let it use this machine",
5
5
  "type": "module",
6
6
  "bin": {