@tianacloud/dsh-remote 0.2.4 → 0.2.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tianacloud/dsh-remote",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "type": "module",
5
5
  "description": "使用 Tiana 能力为 DeepSeek Harness 提供零公网 IP 远程访问、侧栏管理面板、无密钥流式子资源桥接与云端一键引导插件。",
6
6
  "license": "Apache-2.0",
package/src/tiana-cli.js CHANGED
@@ -27,6 +27,7 @@ const RELAY_GO_DIR = join(PROJECT_ROOT, 'relay-go');
27
27
  export const DEFAULT_FUNCTION_NAME = 'dsh-remote-relay';
28
28
  export const DEFAULT_WEB_NAME = 'DSH Remote';
29
29
  export const DEFAULT_TOKEN_NAME = 'dsh-remote-host';
30
+ const WEB_APP_OWNERSHIP_ERROR = 'Only the verified owner of this DSH Remote Web app can bind a host to it.';
30
31
 
31
32
  export function tianaBinary(overrideBin) {
32
33
  if (typeof overrideBin === 'string' && overrideBin.trim()) return overrideBin.trim();
@@ -346,11 +347,12 @@ export async function ensureHostToken(state, functionId, { rotateToken = false,
346
347
  return { token: receipt.token, tokenId: receipt.token_id || '', expiresAt };
347
348
  }
348
349
 
349
- async function ensureWebApp({ webName, webId, log = console.log, ...cliOpts }) {
350
+ async function ensureWebApp({ webName, webId, status, log = console.log, ...cliOpts }) {
351
+ requireTianaSpaceMatch(status, { webId });
350
352
  if (webId) {
351
- const items = await listTianaWebApps(cliOpts);
353
+ const items = await listWebAppsForOwnership(webId, status, cliOpts);
352
354
  const existing = items.find((item) => item.id === webId);
353
- if (!existing) throw new Error('The configured Web app is unavailable in the current Tiana space');
355
+ if (!existing) throw webAppNotFound(webId, status);
354
356
  return existing;
355
357
  }
356
358
  log(`[dsh-remote] Creating Web app "${webName}"...`);
@@ -363,7 +365,7 @@ async function ensureWebApp({ webName, webId, log = console.log, ...cliOpts }) {
363
365
  ], cliOpts);
364
366
  const createdApp = created?.project ?? created?.app ?? created;
365
367
  if (createdApp?.id && !normalizeIdentityValue(createdApp.owner_id) && !normalizeIdentityValue(createdApp.tenant_id)) {
366
- const items = await listTianaWebApps(cliOpts);
368
+ const items = await listWebAppsForOwnership(createdApp.id, status, cliOpts);
367
369
  const listed = items.find((item) => item.id === createdApp.id);
368
370
  if (listed) return listed;
369
371
  }
@@ -374,89 +376,141 @@ function normalizeIdentityValue(value) {
374
376
  return value == null ? '' : String(value).trim();
375
377
  }
376
378
 
379
+ function formatOwnershipError(baseMsg, { webId, status, webApp, binding, reason }) {
380
+ const { user, space } = status ?? {};
381
+ const account = [user?.display_name, user?.email, user?.user_id].map(normalizeIdentityValue).filter(Boolean);
382
+ const spaceId = normalizeIdentityValue(space?.tenant_id) || normalizeIdentityValue(user?.tenant_id);
383
+ const currentSpace = [space?.display_name, spaceId, space?.role].map(normalizeIdentityValue).filter(Boolean);
384
+ if (!reason) {
385
+ if (binding?.canManage === false) reason = '`tiana web functions get` returned `can_manage: false`.';
386
+ else if (binding?.canManage == null) reason = '`tiana web functions get` did not return `can_manage`.';
387
+ else reason = '`tiana web functions get` did not return `can_manage: true`.';
388
+ }
389
+
390
+ return [
391
+ baseMsg,
392
+ `Current Tiana CLI account: ${account.join(' / ') || '(unknown)'}`,
393
+ `Current Tiana space: ${currentSpace.join(' / ') || '(unknown)'}`,
394
+ `Target Web app: ${webId || webApp?.id || '(unknown)'}`,
395
+ `Reason: ${reason}`,
396
+ '',
397
+ 'Run `tiana status` to verify the active Tiana CLI account and space.',
398
+ 'If you are signed in with a different account, run `tiana logout && tiana login` and sign in as the Web app owner.',
399
+ 'If you are in a different space, run `tiana space list`, then `tiana space switch <spaceId>`, or pass `--space <spaceId>` to `dsh-remote connect`.',
400
+ ].join('\n');
401
+ }
402
+
403
+ function webAppNotFound(webId, status) {
404
+ return new Error(formatOwnershipError(`Web app "${webId}" was not found in the current Tiana space.`, {
405
+ webId, status, reason: '`tiana web list` did not include this Web app.',
406
+ }));
407
+ }
408
+
409
+ async function listWebAppsForOwnership(webId, status, cliOpts) {
410
+ try {
411
+ return await listTianaWebApps(cliOpts);
412
+ } catch {
413
+ throw new Error(formatOwnershipError(`Could not look up Web app "${webId}" in the current Tiana space.`, {
414
+ webId, status, reason: '`tiana web list` failed to retrieve Web apps in the active space.',
415
+ }));
416
+ }
417
+ }
418
+
419
+ async function getWebBindingForOwnership(webId, status, cliOpts) {
420
+ try {
421
+ return await getWebFunctionBinding(webId, cliOpts);
422
+ } catch {
423
+ throw new Error(formatOwnershipError(WEB_APP_OWNERSHIP_ERROR, {
424
+ webId, status, reason: '`tiana web functions get` failed to retrieve the app’s management permissions.',
425
+ }));
426
+ }
427
+ }
428
+
429
+ function requireTianaSpaceMatch(status, { webId, webApp, errorMessage } = {}) {
430
+ const spaceTenantId = normalizeIdentityValue(status?.space?.tenant_id);
431
+ if (spaceTenantId && spaceTenantId !== normalizeIdentityValue(status?.user?.tenant_id)) {
432
+ throw new Error(formatOwnershipError(errorMessage || WEB_APP_OWNERSHIP_ERROR, {
433
+ webId, webApp, status, reason: 'The space `tenant_id` in Tiana status does not match the account `tenant_id`.',
434
+ }));
435
+ }
436
+ }
437
+
377
438
  export function verifyWebAppOwnership(webApp, status, { binding = null, requireBindingProof = false, errorMessage } = {}) {
378
- const msg = errorMessage || 'Only the verified owner of this DSH Remote Web app can bind a host to it.';
439
+ const reject = (reason) => {
440
+ throw new Error(formatOwnershipError(errorMessage || WEB_APP_OWNERSHIP_ERROR, { webApp, status, binding, reason }));
441
+ };
379
442
  const expectedUserId = normalizeIdentityValue(status?.user?.user_id);
380
443
  const expectedTenantId = normalizeIdentityValue(status?.user?.tenant_id);
381
444
  if (!expectedUserId || !expectedTenantId) {
382
- throw new Error('Tiana login status is missing user_id or tenant_id.');
445
+ reject('Tiana login status is missing `user_id` or `tenant_id`.');
383
446
  }
384
447
 
385
448
  // Explicit management denial ALWAYS rejects fail-closed, even when webApp.owner_id matches.
386
449
  if (binding?.canManage === false) {
387
- throw new Error(msg);
450
+ reject();
388
451
  }
389
452
 
453
+ requireTianaSpaceMatch(status, { webApp, errorMessage });
454
+
390
455
  const webTenantId = normalizeIdentityValue(webApp?.tenant_id);
391
456
  if (webTenantId && webTenantId !== expectedTenantId) {
392
- throw new Error(msg);
457
+ reject('The Web app `tenant_id` does not match the active Tiana account `tenant_id`.');
393
458
  }
394
459
 
395
460
  const webOwnerId = normalizeIdentityValue(webApp?.owner_id);
396
461
  if (webOwnerId) {
397
462
  if (webOwnerId !== expectedUserId) {
398
- throw new Error(msg);
463
+ reject('The Web app `owner_id` does not match the active Tiana account `user_id`.');
399
464
  }
400
465
  return { mode: 'owner_id', verified: true };
401
466
  }
402
467
 
403
- // On Online (tiana CLI v1.0.34), `web list --json` returns `owner_id: ""` with `tenant_id`.
404
- // Require strict non-empty tenant_id match, space.can_manage (if boolean), and
405
- // management proof via `web functions get` returning `can_manage: true`.
406
- if (!webTenantId || webTenantId !== expectedTenantId) {
407
- throw new Error(msg);
468
+ // Online `web list --json` can return an empty owner_id. MGR's `web functions get`
469
+ // can_manage supplies Web app management proof. status.space.can_manage reflects
470
+ // multi-member team management and is false in standard personal default spaces.
471
+ if (!webTenantId) {
472
+ reject('The Web app is missing `tenant_id` and has no `owner_id`.');
408
473
  }
409
- if (status?.space && typeof status.space.can_manage === 'boolean' && status.space.can_manage !== true) {
410
- throw new Error(msg);
411
- }
412
- if (requireBindingProof) {
413
- if (binding?.canManage !== true) {
414
- throw new Error(msg);
415
- }
416
- return { mode: 'tenant_can_manage', verified: true };
417
- }
418
- return { mode: 'tenant_pending_manage_proof', verified: false };
474
+ if (!requireBindingProof) return { mode: 'tenant_pending_manage_proof', verified: false };
475
+ if (binding?.canManage !== true) reject();
476
+ return { mode: 'tenant_can_manage', verified: true };
419
477
  }
420
478
 
421
479
  async function revalidateWebAppAuthorization(webId, {
422
480
  expectedTenantId = '',
423
481
  expectedUserId = '',
424
- errorMessage,
425
482
  cliOpts = {},
426
483
  fallbackWebApp = null,
427
484
  allowCreatedFallback = false,
428
485
  } = {}) {
429
- const msg = errorMessage || 'Only the verified owner of this DSH Remote Web app can bind a host to it.';
430
486
  const latestStatus = await getTianaStatus(cliOpts);
431
- if (!latestStatus?.user?.user_id || !latestStatus?.user?.tenant_id) {
432
- throw new Error('Tiana login status is missing user_id or tenant_id.');
433
- }
434
487
  if (expectedTenantId && latestStatus.user.tenant_id !== expectedTenantId) {
435
- throw new Error(msg);
488
+ throw new Error(formatOwnershipError(WEB_APP_OWNERSHIP_ERROR, {
489
+ webId, status: latestStatus, reason: 'The active Tiana space changed while verifying the Web app.',
490
+ }));
436
491
  }
437
492
  if (expectedUserId && latestStatus.user.user_id !== expectedUserId) {
438
- throw new Error(msg);
493
+ throw new Error(formatOwnershipError(WEB_APP_OWNERSHIP_ERROR, {
494
+ webId, status: latestStatus, reason: 'The active Tiana CLI account changed while verifying the Web app.',
495
+ }));
439
496
  }
497
+ requireTianaSpaceMatch(latestStatus, { webId });
440
498
 
441
- const latestWebApps = await listTianaWebApps(cliOpts);
499
+ const latestWebApps = await listWebAppsForOwnership(webId, latestStatus, cliOpts);
442
500
  const listedWebApp = latestWebApps.find((item) => item.id === webId);
443
501
  if (!listedWebApp) {
444
502
  if (!allowCreatedFallback || !fallbackWebApp || latestWebApps.length > 0) {
445
- throw new Error(`Web app "${webId}" was not found in the current Tiana space.`);
446
- }
447
- // Stale owner_id from an earlier `web create` response is NOT current proof when `web list` is empty:
448
- // require current server-side management proof (`can_manage: true`) from `web functions get` + space check.
449
- if (latestStatus?.space && typeof latestStatus.space.can_manage === 'boolean' && latestStatus.space.can_manage !== true) {
450
- throw new Error(msg);
503
+ throw webAppNotFound(webId, latestStatus);
451
504
  }
452
- const latestBinding = await getWebFunctionBinding(webId, cliOpts);
505
+ // An earlier `web create` response needs fresh proof from `web functions get`
506
+ // when `web list` is empty, including when the create response had an owner_id.
507
+ const latestBinding = await getWebBindingForOwnership(webId, latestStatus, cliOpts);
453
508
  if (latestBinding?.canManage !== true) {
454
- throw new Error(msg);
509
+ throw new Error(formatOwnershipError(WEB_APP_OWNERSHIP_ERROR, { webId, status: latestStatus, binding: latestBinding }));
455
510
  }
456
511
  verifyWebAppOwnership(fallbackWebApp, latestStatus, {
457
512
  binding: latestBinding,
458
513
  requireBindingProof: true,
459
- errorMessage: msg,
460
514
  });
461
515
  if (fallbackWebApp.enabled === false) {
462
516
  throw new Error(`Web app "${webId}" is disabled.`);
@@ -474,10 +528,7 @@ async function revalidateWebAppAuthorization(webId, {
474
528
  };
475
529
  }
476
530
 
477
- verifyWebAppOwnership(listedWebApp, latestStatus, {
478
- requireBindingProof: false,
479
- errorMessage: msg,
480
- });
531
+ verifyWebAppOwnership(listedWebApp, latestStatus);
481
532
  if (listedWebApp.enabled === false) {
482
533
  throw new Error(`Web app "${webId}" is disabled.`);
483
534
  }
@@ -486,11 +537,10 @@ async function revalidateWebAppAuthorization(webId, {
486
537
  }
487
538
  const latestWebUrl = validateWebEndpoint(listedWebApp, webId);
488
539
 
489
- const latestBinding = await getWebFunctionBinding(webId, cliOpts);
540
+ const latestBinding = await getWebBindingForOwnership(webId, latestStatus, cliOpts);
490
541
  const verified = verifyWebAppOwnership(listedWebApp, latestStatus, {
491
542
  binding: latestBinding,
492
543
  requireBindingProof: true,
493
- errorMessage: msg,
494
544
  });
495
545
  return {
496
546
  status: latestStatus,
@@ -506,7 +556,7 @@ async function ensureWebFunctionBinding(webId, functionId, {
506
556
  requireManage = false,
507
557
  initialBinding = null,
508
558
  revalidate = null,
509
- errorMessage,
559
+ status,
510
560
  log = console.log,
511
561
  ...cliOpts
512
562
  } = {}) {
@@ -516,12 +566,13 @@ async function ensureWebFunctionBinding(webId, functionId, {
516
566
  const fresh = await revalidate();
517
567
  current = fresh.binding;
518
568
  requireManage = fresh.requiresManageProof;
569
+ status = fresh.status;
519
570
  } else {
520
- current = await getWebFunctionBinding(webId, cliOpts);
571
+ current = await getWebBindingForOwnership(webId, status, cliOpts);
521
572
  }
522
573
  }
523
- if (requireManage && current.canManage !== true) {
524
- throw new Error(errorMessage || 'Only the verified owner of this DSH Remote Web app can bind a host to it.');
574
+ if (current.canManage === false || (requireManage && current.canManage !== true)) {
575
+ throw new Error(formatOwnershipError(WEB_APP_OWNERSHIP_ERROR, { webId, status, binding: current }));
525
576
  }
526
577
  const bound = current.functionInstanceIds;
527
578
  if (bound.length === 1 && bound[0] === functionId) {
@@ -553,11 +604,12 @@ async function ensureWebFunctionBinding(webId, functionId, {
553
604
  const fresh = await revalidate();
554
605
  rechecked = fresh.binding;
555
606
  recheckedRequireManage = fresh.requiresManageProof;
607
+ status = fresh.status;
556
608
  } else {
557
- rechecked = await getWebFunctionBinding(webId, cliOpts);
609
+ rechecked = await getWebBindingForOwnership(webId, status, cliOpts);
558
610
  }
559
- if (recheckedRequireManage && rechecked.canManage !== true) {
560
- throw new Error(errorMessage || 'Only the verified owner of this DSH Remote Web app can bind a host to it.');
611
+ if (rechecked.canManage === false || (recheckedRequireManage && rechecked.canManage !== true)) {
612
+ throw new Error(formatOwnershipError(WEB_APP_OWNERSHIP_ERROR, { webId, status, binding: rechecked }));
561
613
  }
562
614
  if (rechecked.functionInstanceIds[0]) {
563
615
  log(`[dsh-remote] Adopting Relay Function ${rechecked.functionInstanceIds[0]} bound concurrently to Web ${webId}`);
@@ -601,9 +653,10 @@ export function hasBindingIdentityConflict(existingPolicy, { hostId, registratio
601
653
  * Writes DSH_REMOTE_POLICY via `tiana function parameters set` without rebuilding Go or .tweb.
602
654
  *
603
655
  * Transactional safety:
604
- * 1. Validates non-empty user_id/tenant_id and ownership (`webApp.owner_id === status.user.user_id`
605
- * when non-empty, or non-empty `webApp.tenant_id === status.user.tenant_id` + space/web `can_manage: true`
606
- * when Online CLI returns `owner_id: ""`).
656
+ * 1. Validates account and space IDs and checks ownership. A non-empty `owner_id` must match the
657
+ * account `user_id`. An empty `owner_id` requires a matching non-empty Web app `tenant_id` and
658
+ * MGR's Web app `can_manage: true` from `tiana web functions get`. `status.space.can_manage`
659
+ * describes multi-member team management and is false in ordinary personal default spaces.
607
660
  * 2. Validates Relay Function is ACTIVE, HTTPS, and passes `/healthz` check.
608
661
  * 3. Reads existing function parameters strictly (never swallows errors).
609
662
  * 4. Checks rebind conflict across hostId + hostDigest + hostPublicKey.
@@ -633,18 +686,15 @@ export async function bindTianaRemoteWeb(options = {}) {
633
686
  throw new Error(`Failed to switch Tiana space to "${options.spaceId}".`);
634
687
  }
635
688
 
636
- const bindOwnerError = 'Only the verified owner of this DSH Remote Web app can bind a host to it.';
689
+ requireTianaSpaceMatch(status, { webId });
637
690
  const targetTenantId = options.spaceId || status.user.tenant_id;
638
691
  const targetUserId = status.user.user_id;
639
- const webApps = await listTianaWebApps(cliOpts);
692
+ const webApps = await listWebAppsForOwnership(webId, status, cliOpts);
640
693
  let webApp = webApps.find((item) => item.id === webId);
641
694
  if (!webApp) {
642
- throw new Error(`Web app "${webId}" was not found in the current Tiana space.`);
695
+ throw webAppNotFound(webId, status);
643
696
  }
644
- verifyWebAppOwnership(webApp, status, {
645
- requireBindingProof: false,
646
- errorMessage: bindOwnerError,
647
- });
697
+ verifyWebAppOwnership(webApp, status);
648
698
  if (webApp.enabled === false) {
649
699
  throw new Error(`Web app "${webId}" is disabled.`);
650
700
  }
@@ -654,17 +704,15 @@ export async function bindTianaRemoteWeb(options = {}) {
654
704
  let webUrl = validateWebEndpoint(webApp, webId);
655
705
 
656
706
  // Locate bound Relay Function (and verify can_manage proof when owner_id is empty) before any mutation
657
- const binding = await getWebFunctionBinding(webId, cliOpts);
707
+ const binding = await getWebBindingForOwnership(webId, status, cliOpts);
658
708
  verifyWebAppOwnership(webApp, status, {
659
709
  binding,
660
710
  requireBindingProof: true,
661
- errorMessage: bindOwnerError,
662
711
  });
663
712
 
664
713
  const revalidateBindAuth = () => revalidateWebAppAuthorization(webId, {
665
714
  expectedTenantId: targetTenantId,
666
715
  expectedUserId: targetUserId,
667
- errorMessage: bindOwnerError,
668
716
  cliOpts,
669
717
  });
670
718
 
@@ -693,7 +741,7 @@ export async function bindTianaRemoteWeb(options = {}) {
693
741
  const boundFnId = await ensureWebFunctionBinding(webId, fnId, {
694
742
  adoptExisting: true,
695
743
  revalidate: revalidateBindAuth,
696
- errorMessage: bindOwnerError,
744
+ status,
697
745
  log,
698
746
  ...cliOpts,
699
747
  });
@@ -748,7 +796,7 @@ export async function bindTianaRemoteWeb(options = {}) {
748
796
  initialBinding: activeBinding,
749
797
  requireManage: freshAuth.requiresManageProof,
750
798
  revalidate: revalidateBindAuth,
751
- errorMessage: bindOwnerError,
799
+ status,
752
800
  log,
753
801
  ...cliOpts,
754
802
  });
@@ -1020,10 +1068,13 @@ export async function provisionTianaRemote(options = {}) {
1020
1068
  const hostName = options.hostName || prevState.host?.hostName || identity.hostName;
1021
1069
 
1022
1070
  if (!/^[a-z0-9_-]{1,48}$/u.test(hostId)) throw new Error('Invalid host ID');
1071
+ const configuredWebId = prevState.web?.id || pending.webId;
1023
1072
  const previousOwner = prevState.owner || pending.owner;
1024
1073
  if ((previousOwner?.userId && previousOwner.userId !== status.user.user_id) ||
1025
1074
  (previousOwner?.tenantId && previousOwner.tenantId !== status.user.tenant_id)) {
1026
- throw new Error('Use the Tiana account and space that originally configured this DSH host');
1075
+ throw new Error(formatOwnershipError(WEB_APP_OWNERSHIP_ERROR, {
1076
+ webId: configuredWebId, status, reason: 'Use the Tiana account and space that originally configured this DSH host.',
1077
+ }));
1027
1078
  }
1028
1079
  if ((prevState.host?.hostId || pending.hostId || hostId) !== hostId) {
1029
1080
  throw new Error('This installation is already bound to a different host ID');
@@ -1046,17 +1097,11 @@ export async function provisionTianaRemote(options = {}) {
1046
1097
  lastWrittenPendingSetup = snapshotPending;
1047
1098
  };
1048
1099
 
1049
- const setupOwnerError = 'The configured Web app does not belong to the DSH owner and space';
1050
- const configuredWebId = prevState.web?.id || pending.webId;
1051
1100
  const hadExistingWebId = Boolean(configuredWebId);
1052
- let webApp = await ensureWebApp({ webName, webId: configuredWebId, log, ...cliOpts });
1101
+ let webApp = await ensureWebApp({ webName, webId: configuredWebId, status, log, ...cliOpts });
1053
1102
  const webId = webApp?.id;
1054
1103
  if (!/^[a-z][a-z0-9]{11}$/u.test(webId || '')) throw new Error('Invalid Web app ID');
1055
- const ownershipCheck = verifyWebAppOwnership(webApp, status, {
1056
- requireBindingProof: false,
1057
- errorMessage: setupOwnerError,
1058
- });
1059
- let requiresManageProof = ownershipCheck.mode !== 'owner_id';
1104
+ verifyWebAppOwnership(webApp, status);
1060
1105
  if (webApp.enabled === false) {
1061
1106
  throw new Error(`Web app "${webId}" is disabled.`);
1062
1107
  }
@@ -1067,11 +1112,10 @@ export async function provisionTianaRemote(options = {}) {
1067
1112
  let webEndpoint = webUrl.href;
1068
1113
  // Always query web functions binding during preflight (even when owner_id matches)
1069
1114
  // so an explicit can_manage: false rejects before creating/publishing a Relay Function or minting a token.
1070
- const initialBinding = await getWebFunctionBinding(webId, cliOpts);
1115
+ const initialBinding = await getWebBindingForOwnership(webId, status, cliOpts);
1071
1116
  verifyWebAppOwnership(webApp, status, {
1072
1117
  binding: initialBinding,
1073
1118
  requireBindingProof: true,
1074
- errorMessage: setupOwnerError,
1075
1119
  });
1076
1120
  await checkpoint({ webId, owner, hostId, registrationKey, e2ee });
1077
1121
 
@@ -1101,7 +1145,6 @@ export async function provisionTianaRemote(options = {}) {
1101
1145
  preRelayAuth = await revalidateWebAppAuthorization(webId, {
1102
1146
  expectedTenantId: owner.tenantId,
1103
1147
  expectedUserId: owner.userId,
1104
- errorMessage: setupOwnerError,
1105
1148
  cliOpts,
1106
1149
  fallbackWebApp: hadExistingWebId ? null : webApp,
1107
1150
  allowCreatedFallback: !hadExistingWebId,
@@ -1114,7 +1157,6 @@ export async function provisionTianaRemote(options = {}) {
1114
1157
  webApp = preRelayAuth.webApp;
1115
1158
  webUrl = preRelayAuth.webUrl;
1116
1159
  webEndpoint = webUrl.href;
1117
- requiresManageProof = preRelayAuth.requiresManageProof;
1118
1160
 
1119
1161
  const fnShown = await syncAndPublishRelayFunction(fnInstance.id, webId, {
1120
1162
  forcePublish: Boolean(options.forcePublish), log, ...cliOpts,
@@ -1139,7 +1181,6 @@ export async function provisionTianaRemote(options = {}) {
1139
1181
  freshAuth = await revalidateWebAppAuthorization(webId, {
1140
1182
  expectedTenantId: owner.tenantId,
1141
1183
  expectedUserId: owner.userId,
1142
- errorMessage: setupOwnerError,
1143
1184
  cliOpts,
1144
1185
  fallbackWebApp: hadExistingWebId ? null : webApp,
1145
1186
  allowCreatedFallback: !hadExistingWebId,
@@ -1152,7 +1193,6 @@ export async function provisionTianaRemote(options = {}) {
1152
1193
  webApp = freshAuth.webApp;
1153
1194
  webUrl = freshAuth.webUrl;
1154
1195
  webEndpoint = webUrl.href;
1155
- requiresManageProof = freshAuth.requiresManageProof;
1156
1196
 
1157
1197
  const policy = buildRemotePolicy({
1158
1198
  hostId,
@@ -1167,8 +1207,8 @@ export async function provisionTianaRemote(options = {}) {
1167
1207
  await updateRemotePolicy(fnInstance.id, policy, { log, ...cliOpts });
1168
1208
  await ensureWebFunctionBinding(webId, fnInstance.id, {
1169
1209
  initialBinding: freshAuth.binding,
1170
- requireManage: requiresManageProof,
1171
- errorMessage: setupOwnerError,
1210
+ requireManage: freshAuth.requiresManageProof,
1211
+ status,
1172
1212
  log,
1173
1213
  ...cliOpts,
1174
1214
  });
@@ -10,6 +10,7 @@ const SHELL_STYLES = ':root{color-scheme:light dark;--dsh-bg-l:#f1f5f9;--dsh-bg-
10
10
  '.dsh-shell-tabs{display:flex;gap:8px;flex-wrap:wrap}.dsh-shell-tab{padding:6px 12px;border-radius:8px;font-size:13px;font-weight:500;cursor:pointer;border:1px solid var(--dsh-border);background:transparent;color:var(--dsh-muted)}.dsh-shell-tab[aria-selected="true"]{background:#2563eb;border-color:#2563eb;color:#fff}' +
11
11
  '.dsh-shell-codebox{display:flex;align-items:center;gap:10px;padding:12px 14px;border-radius:10px;min-width:0;max-width:100%;box-sizing:border-box;background:var(--dsh-code);border:1px solid var(--dsh-border)}' +
12
12
  '.dsh-shell-code{flex:1;min-width:0;overflow-x:auto;white-space:nowrap;font:13px ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace}' +
13
+ '#dsh-remote-key-cmd{white-space:normal;overflow-wrap:anywhere}' +
13
14
  '.dsh-shell-btn{padding:9px 14px;border-radius:9px;font-size:13px;font-weight:500;cursor:pointer;border:1px solid var(--dsh-border);background:transparent;color:var(--dsh-text);white-space:nowrap}.dsh-shell-btn-primary{background:#2563eb;border-color:#2563eb;color:#fff}.dsh-shell-btn:hover{filter:brightness(1.06)}' +
14
15
  '.dsh-shell-input-row{display:flex;gap:8px;align-items:center}.dsh-shell-input{flex:1;min-width:0;padding:11px 13px;border-radius:9px;border:1px solid var(--dsh-border);background:var(--dsh-code);color:var(--dsh-text);font:13px ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace}' +
15
16
  '.dsh-shell-err{padding:10px 12px;border-radius:9px;font-size:13px;line-height:1.45;background:rgba(220,38,38,.14);border:1px solid rgba(248,113,113,.45);color:#ef4444}' +
@@ -22,6 +23,7 @@ const SHELL_STYLES = ':root{color-scheme:light dark;--dsh-bg-l:#f1f5f9;--dsh-bg-
22
23
  '@media (max-width:560px){#dsh-remote-shell{padding:14px}.dsh-shell-card{padding:20px}}';
23
24
 
24
25
  const PAIRING_KEY_PATTERN = /^(?:dshk1_)?[A-Za-z0-9_-]{43}$/u;
26
+ export const KEY_VIEW_COMMAND = 'npx --yes @tianacloud/dsh-remote@latest key';
25
27
 
26
28
  export function validatePairingKeyInput(raw) {
27
29
  const trimmed = String(raw ?? '').trim();
@@ -47,6 +49,23 @@ function el(tag, props, ...children) {
47
49
  return node;
48
50
  }
49
51
 
52
+ function makeCopyButton(getText, { id, primary = false } = {}) {
53
+ const btn = el('button', {
54
+ id: id ?? '', type: 'button', className: `dsh-shell-btn${primary ? ' dsh-shell-btn-primary' : ''}`,
55
+ textContent: '复制命令',
56
+ });
57
+ let reset;
58
+ btn.addEventListener('click', async () => {
59
+ clearTimeout(reset);
60
+ try {
61
+ await navigator.clipboard.writeText(getText());
62
+ btn.textContent = '已复制';
63
+ reset = setTimeout(() => { btn.textContent = '复制命令'; }, 1800);
64
+ } catch { btn.textContent = '请手动复制'; }
65
+ });
66
+ return btn;
67
+ }
68
+
50
69
  function ensureShellStyles() {
51
70
  if (typeof document === 'undefined') return;
52
71
  if (!document.querySelector('meta[name="color-scheme"]')) {
@@ -130,14 +149,7 @@ export function createShellUI(rootEl) {
130
149
  tabButtons[key] = btn;
131
150
  tabs.append(btn);
132
151
  }
133
- const copyBtn = el('button', { type: 'button', id: 'dsh-remote-copy-cmd', className: 'dsh-shell-btn dsh-shell-btn-primary', textContent: '复制命令' });
134
- copyBtn.addEventListener('click', async () => {
135
- try {
136
- await navigator.clipboard.writeText(osCommands[activeOs].cmd);
137
- copyBtn.textContent = '已复制';
138
- setTimeout(() => { copyBtn.textContent = '复制命令'; }, 1800);
139
- } catch { copyBtn.textContent = '请手动复制'; }
140
- });
152
+ const copyBtn = makeCopyButton(() => osCommands[activeOs].cmd, { id: 'dsh-remote-copy-cmd', primary: true });
141
153
  const codeBox = el('div', { className: 'dsh-shell-codebox' }, codeEl, copyBtn);
142
154
  waitStatusEl = el('span', { textContent: '正在等待你的电脑完成配置并上线…(上线后自动进入解锁页)' });
143
155
  const waitBar = el('div', { className: 'dsh-shell-wait', id: 'dsh-remote-onboarding-wait' }, el('span', { className: 'dsh-shell-pulse' }), waitStatusEl);
@@ -209,8 +221,13 @@ export function createShellUI(rootEl) {
209
221
  const rememberLabel = el('label', { className: 'dsh-shell-check' }, rememberBox, '在此受信任浏览器记住密钥(取消勾选后密钥仅驻留当前页面内存,刷新或关闭标签页立即销毁)');
210
222
  const hint = el('div', { className: 'dsh-shell-sub', style: 'font-size:12px;', textContent: '密钥仅在浏览器与你的电脑之间进行端到端加密校验,Tiana 云端无法解密任何内容。可从刚运行的 connect 剪贴板粘贴,或在本地 DSH 侧栏「Tiana Remote」复制。' });
211
223
  const submitBtn = el('button', { id: 'dsh-remote-e2ee-submit', type: 'submit', className: 'dsh-shell-btn dsh-shell-btn-primary', textContent: '解锁并进入工作台' });
224
+ const keyHint = el('p', { className: 'dsh-shell-sub', textContent: '忘记或需要查看当前配对密钥?在本地主机终端运行:' });
225
+ const keyBox = el('div', { className: 'dsh-shell-codebox' },
226
+ el('code', { id: 'dsh-remote-key-cmd', className: 'dsh-shell-code', textContent: KEY_VIEW_COMMAND }),
227
+ makeCopyButton(() => KEY_VIEW_COMMAND, { id: 'dsh-remote-copy-key-cmd' }),
228
+ );
212
229
 
213
- const form = el('form', { style: 'display:grid;gap:12px;' }, errBox, el('div', { className: 'dsh-shell-input-row' }, input, toggleBtn), validationEl, rememberLabel, hint, submitBtn);
230
+ const form = el('form', { style: 'display:grid;gap:12px;' }, errBox, el('div', { className: 'dsh-shell-input-row' }, input, toggleBtn), validationEl, rememberLabel, hint, submitBtn, keyHint, keyBox);
214
231
  form.addEventListener('submit', (e) => {
215
232
  e.preventDefault();
216
233
  const check = updateValidation();