|
|
@@ -0,0 +1,229 @@
|
|
|
+import { ChangeDetectionStrategy, Component, computed, inject, input, output, signal } from '@angular/core';
|
|
|
+import { Agent } from '../../../core/api/models';
|
|
|
+import { SessionService } from '../../../core/session.service';
|
|
|
+
|
|
|
+/**
|
|
|
+ * 试用接入引导卡(2026-12-04)。
|
|
|
+ *
|
|
|
+ * ## 显示时机
|
|
|
+ *
|
|
|
+ * 用户刚复制提示词跳到会话页时,这里**什么都没说** —— 他不知道接下来该做什么。
|
|
|
+ * 所以在「试用容器 + 还没接入成功(matrixReady=false)」时显示三步引导。
|
|
|
+ *
|
|
|
+ * ## 只显示一次
|
|
|
+ *
|
|
|
+ * 用 localStorage 按账号记标记(写法照抄 `app-notification.service.ts` 的
|
|
|
+ * `shouldPromptPermission` / `markPrompted`):关掉之后不再出现。
|
|
|
+ * 设备级偏好,登出不清 —— 反正换账号 key 不同。
|
|
|
+ *
|
|
|
+ * ## 为什么不用弹窗
|
|
|
+ *
|
|
|
+ * 用户此时的重点是「去 Hermes 操作」,弹窗会挡住会话,
|
|
|
+ * 做成页内卡片即可,看完了自然消失。
|
|
|
+ */
|
|
|
+@Component({
|
|
|
+ selector: 'app-trial-onboarding',
|
|
|
+ changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
+ template: `
|
|
|
+ @if (visible()) {
|
|
|
+ <section class="trial-onb" role="region" aria-labelledby="trial-onb-title">
|
|
|
+ <header class="trial-onb-head">
|
|
|
+ <div class="trial-onb-title-wrap">
|
|
|
+ <i class="fa-solid fa-wand-magic-sparkles" aria-hidden="true"></i>
|
|
|
+ <h2 id="trial-onb-title">还差一步就能开始对话</h2>
|
|
|
+ </div>
|
|
|
+ <button type="button" class="trial-onb-close" aria-label="关闭引导" (click)="dismiss()">
|
|
|
+ <i class="fa-solid fa-xmark" aria-hidden="true"></i>
|
|
|
+ </button>
|
|
|
+ </header>
|
|
|
+
|
|
|
+ <ol class="trial-onb-steps">
|
|
|
+ <li>
|
|
|
+ <span class="trial-onb-num">1</span>
|
|
|
+ <div>
|
|
|
+ <strong>打开你的 Hermes,粘贴提示词</strong>
|
|
|
+ <p>把刚才复制的整段内容发给它,它会自动安装接入组件并完成配置。</p>
|
|
|
+ </div>
|
|
|
+ </li>
|
|
|
+ <li>
|
|
|
+ <span class="trial-onb-num">2</span>
|
|
|
+ <div>
|
|
|
+ <strong>重启网关</strong>
|
|
|
+ <p>提示词里已要求它自动重启;若没有自动重启,手动执行 <code>hermes gateway restart</code>。</p>
|
|
|
+ </div>
|
|
|
+ </li>
|
|
|
+ <li>
|
|
|
+ <span class="trial-onb-num">3</span>
|
|
|
+ <div>
|
|
|
+ <strong>回来这里发一句「你好」</strong>
|
|
|
+ <p>收到回复并出现 ✅,就说明接入成功,可以正常使用了。</p>
|
|
|
+ </div>
|
|
|
+ </li>
|
|
|
+ </ol>
|
|
|
+
|
|
|
+ <footer class="trial-onb-foot">
|
|
|
+ <button type="button" class="trial-onb-link" (click)="openInstruction.emit()">重新查看接入提示词</button>
|
|
|
+ <button type="button" class="trial-onb-ok" (click)="dismiss()">知道了</button>
|
|
|
+ </footer>
|
|
|
+ </section>
|
|
|
+ }
|
|
|
+ `,
|
|
|
+ styles: [
|
|
|
+ `
|
|
|
+ :host {
|
|
|
+ display: block;
|
|
|
+ }
|
|
|
+ .trial-onb {
|
|
|
+ margin: var(--sp-4);
|
|
|
+ padding: var(--sp-4);
|
|
|
+ border: 1px solid var(--primary);
|
|
|
+ border-radius: var(--r-lg, 14px);
|
|
|
+ background: var(--surface);
|
|
|
+ box-shadow: var(--shadow-card);
|
|
|
+ }
|
|
|
+ .trial-onb-head {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: space-between;
|
|
|
+ gap: var(--sp-3);
|
|
|
+ margin-bottom: var(--sp-3);
|
|
|
+ }
|
|
|
+ .trial-onb-title-wrap {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ gap: var(--sp-2);
|
|
|
+ min-width: 0;
|
|
|
+ }
|
|
|
+ .trial-onb-title-wrap i {
|
|
|
+ color: var(--primary);
|
|
|
+ }
|
|
|
+ .trial-onb-title-wrap h2 {
|
|
|
+ margin: 0;
|
|
|
+ font-size: var(--fs-15);
|
|
|
+ font-weight: 600;
|
|
|
+ color: var(--ink);
|
|
|
+ }
|
|
|
+ .trial-onb-close {
|
|
|
+ flex: none;
|
|
|
+ width: 32px;
|
|
|
+ height: 32px;
|
|
|
+ border: 0;
|
|
|
+ border-radius: 8px;
|
|
|
+ background: transparent;
|
|
|
+ color: var(--muted);
|
|
|
+ cursor: pointer;
|
|
|
+ }
|
|
|
+ .trial-onb-close:hover {
|
|
|
+ background: var(--surface-2);
|
|
|
+ color: var(--ink);
|
|
|
+ }
|
|
|
+ .trial-onb-steps {
|
|
|
+ display: grid;
|
|
|
+ gap: var(--sp-3);
|
|
|
+ margin: 0;
|
|
|
+ padding: 0;
|
|
|
+ list-style: none;
|
|
|
+ }
|
|
|
+ .trial-onb-steps li {
|
|
|
+ display: flex;
|
|
|
+ gap: var(--sp-3);
|
|
|
+ }
|
|
|
+ .trial-onb-num {
|
|
|
+ flex: none;
|
|
|
+ display: grid;
|
|
|
+ place-items: center;
|
|
|
+ width: 22px;
|
|
|
+ height: 22px;
|
|
|
+ border-radius: 999px;
|
|
|
+ background: var(--primary-subtle);
|
|
|
+ color: var(--primary);
|
|
|
+ font-size: var(--fs-12);
|
|
|
+ font-weight: 600;
|
|
|
+ }
|
|
|
+ .trial-onb-steps strong {
|
|
|
+ display: block;
|
|
|
+ font-size: var(--fs-13);
|
|
|
+ color: var(--ink);
|
|
|
+ }
|
|
|
+ .trial-onb-steps p {
|
|
|
+ margin: 2px 0 0;
|
|
|
+ font-size: var(--fs-12);
|
|
|
+ line-height: 1.6;
|
|
|
+ color: var(--ink-2);
|
|
|
+ }
|
|
|
+ .trial-onb-steps code {
|
|
|
+ padding: 1px 4px;
|
|
|
+ border-radius: 4px;
|
|
|
+ background: var(--surface-2);
|
|
|
+ font-size: var(--fs-11);
|
|
|
+ }
|
|
|
+ .trial-onb-foot {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: space-between;
|
|
|
+ gap: var(--sp-3);
|
|
|
+ margin-top: var(--sp-4);
|
|
|
+ padding-top: var(--sp-3);
|
|
|
+ border-top: 1px solid var(--edge);
|
|
|
+ }
|
|
|
+ .trial-onb-link {
|
|
|
+ border: 0;
|
|
|
+ background: transparent;
|
|
|
+ color: var(--primary);
|
|
|
+ font-size: var(--fs-12);
|
|
|
+ cursor: pointer;
|
|
|
+ }
|
|
|
+ .trial-onb-link:hover {
|
|
|
+ text-decoration: underline;
|
|
|
+ }
|
|
|
+ .trial-onb-ok {
|
|
|
+ min-height: 36px;
|
|
|
+ padding: 0 var(--sp-4);
|
|
|
+ border: 0;
|
|
|
+ border-radius: 8px;
|
|
|
+ background: var(--primary);
|
|
|
+ color: var(--inverse, #fff);
|
|
|
+ font-size: var(--fs-13);
|
|
|
+ cursor: pointer;
|
|
|
+ }
|
|
|
+ `,
|
|
|
+ ],
|
|
|
+})
|
|
|
+export class TrialOnboardingComponent {
|
|
|
+ /** 当前会话的容器 */
|
|
|
+ readonly agent = input<Agent | undefined>(undefined);
|
|
|
+ /** 用户点了「重新查看接入提示词」 */
|
|
|
+ readonly openInstruction = output<void>();
|
|
|
+
|
|
|
+ private readonly session = inject(SessionService);
|
|
|
+ private readonly dismissed = signal(false);
|
|
|
+
|
|
|
+ private readonly key = computed(() => {
|
|
|
+ const uid = this.session.me()?.id ?? 'anon';
|
|
|
+ return `fmode_trial_onboarding_${uid}`;
|
|
|
+ });
|
|
|
+
|
|
|
+ /** 本次会话内是否还显示(不看 localStorage,避免 SSR/隐私模式报错) */
|
|
|
+ protected readonly visible = computed(() => {
|
|
|
+ if (this.dismissed()) return false;
|
|
|
+ const a = this.agent();
|
|
|
+ if (!a || a.planCode !== 'trial') return false;
|
|
|
+ /* 已经接入成功就不需要再引导 */
|
|
|
+ if (a.matrixReady) return false;
|
|
|
+ try {
|
|
|
+ if (localStorage.getItem(this.key()) === '1') return false;
|
|
|
+ } catch {
|
|
|
+ /* 隐私模式读不到 → 当作没看过,仍显示 */
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+
|
|
|
+ protected dismiss(): void {
|
|
|
+ this.dismissed.set(true);
|
|
|
+ try {
|
|
|
+ localStorage.setItem(this.key(), '1');
|
|
|
+ } catch {
|
|
|
+ /* 写不进去也能关掉本次 */
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|