@ai-workbench/connect 0.7.46 → 0.7.47

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 CHANGED
@@ -1,3 +1,5 @@
1
+ 0.7.47:登录检查的外层 SSH 拒连、中断按既有连接类错误提示;真实认证读取失败仍保留原错误。传输原因只进脱敏技术详情,不新增设置或重试。随总包0.3.10分发。
2
+
1
3
  员工一次安装:在官方 DSH「插件 → 添加插件」输入 `@ai-workbench/workbench`。已分装 network、connect、remote-agent 的,先移除三者,再装总包。
2
4
 
3
5
  本轮总包0.1.6精确锁定 network 0.4.11 / connect 0.7.39 / remote-agent 0.8.31;管理员按[总包发版说明](packages/workbench/README.md)重新生成并核验固定 tgz 与 SHA。工人不 publish。
@@ -1,8 +1,9 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { need } from "./needs.js";
3
- const markers = ['AW_REMOTE_COMMAND_KILL_FAILED', 'AUTH_STATUS_JSON_INVALID:SyntaxError', 'Permission denied', 'Host key verification failed', 'Connection refused', 'Connection closed', 'command not found', 'No such file or directory'];
3
+ const markers = ['AW_REMOTE_COMMAND_KILL_FAILED', 'AUTH_STATUS_JSON_INVALID:SyntaxError', 'Permission denied', 'Host key verification failed', 'Connection refused', 'Connection closed', 'Broken pipe', 'Connection reset by peer', 'Connection timed out', 'command not found', 'No such file or directory'];
4
4
  const names = ['Error', 'TypeError', 'SyntaxError', 'RangeError', 'AbortError', 'DOMException', 'UnknownError'];
5
5
  const codes = ['ENOENT', 'ENOTDIR', 'EIO', 'EPERM', 'ESRCH', 'EACCES', 'EINVAL', 'EPIPE', 'ECONNRESET', 'ECONNREFUSED', 'ETIMEDOUT', 'ABORT_ERR', 'UNKNOWN'];
6
+ const transportReasons = ['CONNECTION_REFUSED', 'CONNECTION_RESET', 'PIPE_CLOSED', 'CONNECTION_CLOSED', 'CONNECTION_TIMEOUT', 'CANCELLED', 'SSH_EXIT_NONZERO', 'SSH_STDERR_NONEMPTY', 'SSH_PROCESS_FAILED'];
6
7
  const stages = ['ssh-status', 'ssh-result', 'remote-frame', 'auth-status', 'connect-check-login', 'integration-pre-login', 'process-spawn', 'process-stdin', 'process-output', 'process-runner'];
7
8
  const reasons = ['CANCELLED', 'SSH_EXIT_NONZERO', 'SSH_STDERR_NONEMPTY', 'FRAME_TRUNCATED', 'FRAME_JSON_INVALID', 'FRAME_OBJECT_INVALID', 'FRAME_VERSION_INVALID', 'FRAME_NONCE_INVALID', 'FRAME_AFTER_END', 'FRAME_KEYS_INVALID', 'FRAME_START_MISSING', 'FRAME_BASE64_INVALID', 'REMOTE_COMMAND_SIGNAL', 'FRAME_END_EXIT_INVALID', 'FRAME_SEQUENCE_OR_VALUE_INVALID', 'FRAME_END_MISSING', 'STATUS_ARGUMENT_INVALID', 'STATUS_EXECUTION_FAILED', 'STATUS_JSON_INVALID', 'STATUS_OBJECT_INVALID', 'STATUS_KEYS_INVALID', 'STATUS_VERSION_INVALID', 'STATUS_PROVIDER_INVALID', 'STATUS_EXIT_MISMATCH', 'STATUS_LOGGED_IN_INVALID', 'STATUS_STDERR_NONEMPTY', 'STATUS_EXIT_INVALID', 'STATUS_EXCEPTION', 'STATUS_SUPERSEDED', 'SSH_PORT_MISSING', 'STDIN_FAILED', 'SPAWN_FAILED', 'OUTPUT_LIMIT_EXCEEDED', 'PROCESS_SIGNAL'];
8
9
  const object = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
@@ -20,7 +21,7 @@ export function validAuthDiagnosticReason(value) {
20
21
  }
21
22
  if (!object(v) || JSON.stringify(v) !== value || v.version !== 1 || !stages.includes(v.stage) || !reasons.includes(v.reason))
22
23
  return false;
23
- const fields = { version: x => x === 1, stage: x => stages.includes(x), reason: x => reasons.includes(x), errorName: x => names.includes(x), errorCode: x => codes.includes(x), exitCode: x => x === null || typeof x === 'number' && Number.isFinite(x) && Number.isInteger(x), signal: x => ['SIGTERM', 'SIGKILL', 'SIGABRT', 'SIGHUP', 'SIGINT', 'SIGSEGV', 'OTHER'].includes(x), index: integer, unexpectedCount: integer, maxOutputBytes: x => integer(x) && x > 0, observedBytes: integer, stderr: summary, output: summary, missing: x => Array.isArray(x) && x.every(k => ['nonce', 'protocolVersion', 'type', 'data', 'exitCode', 'signal', 'loggedIn', 'provider'].includes(k)), loggedInType: x => ['null', 'undefined', 'object', 'boolean', 'number', 'string', 'function', 'symbol', 'bigint'].includes(x), exitCodeType: x => ['undefined', 'object', 'boolean', 'number', 'string', 'function', 'symbol', 'bigint'].includes(x) };
24
+ const fields = { transportReason: x => transportReasons.includes(x), version: x => x === 1, stage: x => stages.includes(x), reason: x => reasons.includes(x), errorName: x => names.includes(x), errorCode: x => codes.includes(x), exitCode: x => x === null || typeof x === 'number' && Number.isFinite(x) && Number.isInteger(x), signal: x => ['SIGTERM', 'SIGKILL', 'SIGABRT', 'SIGHUP', 'SIGINT', 'SIGSEGV', 'OTHER'].includes(x), index: integer, unexpectedCount: integer, maxOutputBytes: x => integer(x) && x > 0, observedBytes: integer, stderr: summary, output: summary, missing: x => Array.isArray(x) && x.every(k => ['nonce', 'protocolVersion', 'type', 'data', 'exitCode', 'signal', 'loggedIn', 'provider'].includes(k)), loggedInType: x => ['null', 'undefined', 'object', 'boolean', 'number', 'string', 'function', 'symbol', 'bigint'].includes(x), exitCodeType: x => ['undefined', 'object', 'boolean', 'number', 'string', 'function', 'symbol', 'bigint'].includes(x) };
24
25
  return Object.entries(v).every(([key, item]) => Object.hasOwn(fields, key) && fields[key](item));
25
26
  }
26
27
  // Raw command output and exception messages can contain authentication material.
@@ -38,8 +39,30 @@ export class AuthDiagnosticError extends Error {
38
39
  diagnostic;
39
40
  constructor(diagnostic, message = 'REMOTE_RESULT_INVALID') { super(message); this.name = 'AuthDiagnosticError'; this.diagnostic = diagnostic; }
40
41
  }
42
+ // 仅外层 SSH/进程及固定系统错误参与传输归类;已解帧的认证结果不走此分支。
43
+ function transportReason(error) {
44
+ const d = error instanceof AuthDiagnosticError ? error.diagnostic : undefined;
45
+ const code = (d?.errorCode ?? error?.code);
46
+ const systems = { ECONNREFUSED: 'CONNECTION_REFUSED', ECONNRESET: 'CONNECTION_RESET', EPIPE: 'PIPE_CLOSED', ETIMEDOUT: 'CONNECTION_TIMEOUT', ABORT_ERR: 'CANCELLED' };
47
+ if (typeof code === 'string' && Object.hasOwn(systems, code))
48
+ return systems[code];
49
+ if (!d)
50
+ return;
51
+ if (['ssh-result', 'process-runner'].includes(String(d.stage)) && d.reason === 'CANCELLED')
52
+ return 'CANCELLED';
53
+ if (d.stage === 'ssh-result' && ['SSH_EXIT_NONZERO', 'SSH_STDERR_NONEMPTY'].includes(String(d.reason))) {
54
+ const found = d.stderr?.markers ?? [];
55
+ for (const [marker, reason] of [['Connection refused', 'CONNECTION_REFUSED'], ['Connection reset by peer', 'CONNECTION_RESET'], ['Broken pipe', 'PIPE_CLOSED'], ['Connection closed', 'CONNECTION_CLOSED'], ['Connection timed out', 'CONNECTION_TIMEOUT']])
56
+ if (found.includes(marker))
57
+ return reason;
58
+ return String(d.reason);
59
+ }
60
+ if (['process-spawn', 'process-stdin', 'process-runner'].includes(String(d.stage)) && ['SPAWN_FAILED', 'STDIN_FAILED', 'PROCESS_SIGNAL'].includes(String(d.reason)))
61
+ return 'SSH_PROCESS_FAILED';
62
+ }
41
63
  export function authFailure(stage, reason, details = {}, error, code = 'AUTH_STATUS_INVALID') {
42
- const value = need(code);
43
- value.officialReason = JSON.stringify({ version: 1, ...(error instanceof AuthDiagnosticError ? error.diagnostic : { stage, reason, ...details, ...(error === undefined ? {} : exceptionSummary(error)) }) });
64
+ const transport = transportReason(error);
65
+ const value = need(transport ? ['CONNECTION_RESET', 'PIPE_CLOSED', 'CONNECTION_CLOSED', 'CANCELLED'].includes(transport) ? 'CONNECTION_LOST' : 'SSH_FAILED' : code);
66
+ value.officialReason = JSON.stringify({ version: 1, ...(error instanceof AuthDiagnosticError ? error.diagnostic : { stage, reason, ...details, ...(error === undefined ? {} : exceptionSummary(error)) }), ...(transport ? { transportReason: transport } : {}) });
44
67
  return { ok: false, error: value };
45
68
  }
package/lib/connect.js CHANGED
@@ -201,7 +201,7 @@ export function createConnect(ports, emit, options = {}) {
201
201
  const failure = authFailure('connect-check-login', 'STATUS_EXCEPTION', {}, error);
202
202
  if (!startup.finishCheck(ticket, failure))
203
203
  return authFailure('connect-check-login', 'STATUS_SUPERSEDED');
204
- return block(failure);
204
+ return ['network', 'ssh', 'enrollment'].includes(failure.error.layer) ? transportBlock(failure) : block(failure);
205
205
  }
206
206
  };
207
207
  const login = (provider) => {
package/lib/ssh.js CHANGED
@@ -107,8 +107,8 @@ export function createSsh(runner, maxOutputBytes) {
107
107
  const r = await runRemote(runner, t, 'id -un', signal);
108
108
  return r.exitCode === 0 && r.stdout.trim() === t.username ? ok(undefined) : fail('SSH_FAILED');
109
109
  }
110
- catch {
111
- return fail('SSH_FAILED');
110
+ catch (error) {
111
+ return authFailure('ssh-status', 'STATUS_EXECUTION_FAILED', {}, error, 'SSH_FAILED');
112
112
  } },
113
113
  status: async (t, p, signal) => {
114
114
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-workbench/connect",
3
- "version": "0.7.46",
3
+ "version": "0.7.47",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24.13.1",