import{_ as i,o as a,c as t,a4 as e}from"./chunks/framework.Cre9sSJa.js";const c=JSON.parse('{"title":"业务管理器","description":"","frontmatter":{},"headers":[],"relativePath":"api/ai-blueking/managers.md","filePath":"api/ai-blueking/managers.md"}'),n={name:"api/ai-blueking/managers.md"};function h(l,s,d,p,k,r){return a(),t("div",null,[...s[0]||(s[0]=[e(`<h1 id="业务管理器" tabindex="-1">业务管理器 <a class="header-anchor" href="#业务管理器" aria-label="Permalink to &quot;业务管理器&quot;">​</a></h1><p>AI 小鲸的业务逻辑通过多个 Manager 类进行管理，各 Manager 职责单一、协作明确。本文档介绍各管理器的 API。</p><h2 id="componentmanager" tabindex="-1">ComponentManager <a class="header-anchor" href="#componentmanager" aria-label="Permalink to &quot;ComponentManager&quot;">​</a></h2><p>中央事件协调器，负责组件间的事件通信。所有 Manager 和组件通过 <code>ComponentManager</code> 进行解耦通信。</p><h3 id="方法" tabindex="-1">方法 <a class="header-anchor" href="#方法" aria-label="Permalink to &quot;方法&quot;">​</a></h3><table tabindex="0"><thead><tr><th>方法</th><th>类型</th><th>说明</th></tr></thead><tbody><tr><td><code>on</code></td><td><code>(event: InternalEvent, handler: Function) =&gt; void</code></td><td>注册事件监听</td></tr><tr><td><code>off</code></td><td><code>(event: InternalEvent, handler: Function) =&gt; void</code></td><td>移除事件监听</td></tr><tr><td><code>emit</code></td><td><code>(event: InternalEvent, ...args: any[]) =&gt; void</code></td><td>触发事件</td></tr></tbody></table><h3 id="事件类型" tabindex="-1">事件类型 <a class="header-anchor" href="#事件类型" aria-label="Permalink to &quot;事件类型&quot;">​</a></h3><p>通过 <code>InternalEvent</code> 枚举定义，常用事件包括：</p><div class="language-typescript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">enum</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> InternalEvent</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">  // 消息相关</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  SendMessage</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;send-message&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  StopGeneration</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;stop-generation&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  ReceiveStart</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;receive-start&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  ReceiveText</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;receive-text&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  ReceiveEnd</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;receive-end&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">  // 会话相关</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  SessionSwitched</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;session-switched&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  SessionCreated</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;session-created&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  SessionDeleted</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;session-deleted&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">  // 快捷指令</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  ShortcutClick</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;shortcut-click&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  ShortcutSelect</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;shortcut-select&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">  // UI 状态</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  SelectionModeChanged</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;selection-mode-changed&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">  // 错误</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  Error</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;error&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><h3 id="用法示例" tabindex="-1">用法示例 <a class="header-anchor" href="#用法示例" aria-label="Permalink to &quot;用法示例&quot;">​</a></h3><div class="language-typescript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { ComponentManager } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;@blueking/ai-blueking&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> manager</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ComponentManager</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 监听消息发送</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">manager.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">on</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(InternalEvent.SendMessage, (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">message</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> string</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  console.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">log</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;消息已发送:&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, message);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">});</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 触发事件</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">manager.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">emit</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(InternalEvent.SendMessage, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;你好&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span></code></pre></div><h2 id="chatbusinessmanager" tabindex="-1">ChatBusinessManager <a class="header-anchor" href="#chatbusinessmanager" aria-label="Permalink to &quot;ChatBusinessManager&quot;">​</a></h2><p>聊天业务管理器，封装消息发送、停止生成等核心聊天逻辑。</p><h3 id="构造函数" tabindex="-1">构造函数 <a class="header-anchor" href="#构造函数" aria-label="Permalink to &quot;构造函数&quot;">​</a></h3><div class="language-typescript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ChatBusinessManager</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(agentModule, sessionModule, chatbotInit)</span></span></code></pre></div><table tabindex="0"><thead><tr><th>参数</th><th>类型</th><th>说明</th></tr></thead><tbody><tr><td><code>agentModule</code></td><td><code>AgentModule</code></td><td>chat-helper 的 Agent 模块</td></tr><tr><td><code>sessionModule</code></td><td><code>SessionModule</code></td><td>chat-helper 的 Session 模块</td></tr><tr><td><code>chatbotInit</code></td><td><code>ChatbotInit</code></td><td>聊天机器人初始化配置</td></tr></tbody></table><h3 id="方法-1" tabindex="-1">方法 <a class="header-anchor" href="#方法-1" aria-label="Permalink to &quot;方法&quot;">​</a></h3><table tabindex="0"><thead><tr><th>方法</th><th>类型</th><th>说明</th></tr></thead><tbody><tr><td><code>sendMessage</code></td><td><code>(content: string, sessionCode: string, options?: object) =&gt; void</code></td><td>发送消息</td></tr><tr><td><code>stopGeneration</code></td><td><code>(sessionCode: string) =&gt; void</code></td><td>停止当前会话的生成</td></tr></tbody></table><h3 id="用法示例-1" tabindex="-1">用法示例 <a class="header-anchor" href="#用法示例-1" aria-label="Permalink to &quot;用法示例&quot;">​</a></h3><div class="language-typescript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 发送消息</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">chatBizManager.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sendMessage</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;帮我写一个排序算法&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, currentSession.sessionCode);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 停止生成</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">chatBizManager.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">stopGeneration</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(currentSession.sessionCode);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 带选项发送</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">chatBizManager.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sendMessage</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;解释这段代码&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, sessionCode, {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  shortcutId: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;explain-code&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  formData: { language: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;python&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> },</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">});</span></span></code></pre></div><h2 id="sessionbusinessmanager" tabindex="-1">SessionBusinessManager <a class="header-anchor" href="#sessionbusinessmanager" aria-label="Permalink to &quot;SessionBusinessManager&quot;">​</a></h2><p>会话业务管理器，封装会话的增删改查及切换逻辑。</p><h3 id="构造函数-1" tabindex="-1">构造函数 <a class="header-anchor" href="#构造函数-1" aria-label="Permalink to &quot;构造函数&quot;">​</a></h3><div class="language-typescript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> SessionBusinessManager</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(sessionModule, messageModule, agentModule</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">?</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, options</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">?</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre></div><table tabindex="0"><thead><tr><th>参数</th><th>类型</th><th>说明</th></tr></thead><tbody><tr><td><code>sessionModule</code></td><td><code>SessionModule</code></td><td>chat-helper 的 Session 模块</td></tr><tr><td><code>messageModule</code></td><td><code>MessageModule</code></td><td>chat-helper 的 Message 模块</td></tr><tr><td><code>agentModule</code></td><td><code>AgentModule</code></td><td>chat-helper 的 Agent 模块（可选）</td></tr><tr><td><code>options</code></td><td><code>object</code></td><td>配置选项（可选）</td></tr></tbody></table><h3 id="方法-2" tabindex="-1">方法 <a class="header-anchor" href="#方法-2" aria-label="Permalink to &quot;方法&quot;">​</a></h3><table tabindex="0"><thead><tr><th>方法</th><th>类型</th><th>说明</th></tr></thead><tbody><tr><td><code>createNewSession</code></td><td><code>() =&gt; Promise&lt;ISession&gt;</code></td><td>创建新会话</td></tr><tr><td><code>switchSession</code></td><td><code>(code: string) =&gt; Promise&lt;void&gt;</code></td><td>切换到指定会话</td></tr><tr><td><code>deleteSession</code></td><td><code>(code: string) =&gt; Promise&lt;void&gt;</code></td><td>删除指定会话</td></tr><tr><td><code>batchDeleteSessions</code></td><td><code>(codes: string[]) =&gt; Promise&lt;void&gt;</code></td><td>批量删除会话</td></tr><tr><td><code>renameSession</code></td><td><code>(code: string) =&gt; Promise&lt;void&gt;</code></td><td>重命名会话</td></tr><tr><td><code>loadRecentSession</code></td><td><code>(options?: object) =&gt; Promise&lt;void&gt;</code></td><td>加载最近会话</td></tr></tbody></table><h3 id="响应式属性" tabindex="-1">响应式属性 <a class="header-anchor" href="#响应式属性" aria-label="Permalink to &quot;响应式属性&quot;">​</a></h3><table tabindex="0"><thead><tr><th>属性</th><th>类型</th><th>说明</th></tr></thead><tbody><tr><td><code>sessionList</code></td><td><code>Ref&lt;ISession[]&gt;</code></td><td>会话列表</td></tr><tr><td><code>currentSession</code></td><td><code>Ref&lt;ISession | null&gt;</code></td><td>当前会话</td></tr></tbody></table><h3 id="用法示例-2" tabindex="-1">用法示例 <a class="header-anchor" href="#用法示例-2" aria-label="Permalink to &quot;用法示例&quot;">​</a></h3><div class="language-typescript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 创建新会话</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> session</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> await</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sessionBizManager.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">createNewSession</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 切换会话</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">await</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sessionBizManager.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">switchSession</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;session-abc-123&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 删除会话</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">await</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sessionBizManager.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">deleteSession</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;session-abc-123&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 批量删除</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">await</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sessionBizManager.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">batchDeleteSessions</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">([</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;session-1&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;session-2&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 重命名</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">await</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sessionBizManager.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">renameSession</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;session-abc-123&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 加载最近会话</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">await</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sessionBizManager.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">loadRecentSession</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">({ autoSwitch: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> });</span></span></code></pre></div><h2 id="shortcutmanager" tabindex="-1">ShortcutManager <a class="header-anchor" href="#shortcutmanager" aria-label="Permalink to &quot;ShortcutManager&quot;">​</a></h2><p>快捷指令管理器，负责快捷指令的获取、过滤和选择。</p><h3 id="构造函数-2" tabindex="-1">构造函数 <a class="header-anchor" href="#构造函数-2" aria-label="Permalink to &quot;构造函数&quot;">​</a></h3><div class="language-typescript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ShortcutManager</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(agentModule)</span></span></code></pre></div><table tabindex="0"><thead><tr><th>参数</th><th>类型</th><th>说明</th></tr></thead><tbody><tr><td><code>agentModule</code></td><td><code>AgentModule</code></td><td>chat-helper 的 Agent 模块</td></tr></tbody></table><h3 id="方法-3" tabindex="-1">方法 <a class="header-anchor" href="#方法-3" aria-label="Permalink to &quot;方法&quot;">​</a></h3><table tabindex="0"><thead><tr><th>方法</th><th>类型</th><th>说明</th></tr></thead><tbody><tr><td><code>getShortcuts</code></td><td><code>() =&gt; IShortcut[]</code></td><td>获取全部快捷指令</td></tr><tr><td><code>filterShortcuts</code></td><td><code>(keyword: string) =&gt; IShortcut[]</code></td><td>根据关键词过滤快捷指令</td></tr><tr><td><code>selectShortcut</code></td><td><code>(shortcut: IShortcut, text?: string) =&gt; void</code></td><td>选择快捷指令并可选填充文本</td></tr></tbody></table><h3 id="响应式属性-1" tabindex="-1">响应式属性 <a class="header-anchor" href="#响应式属性-1" aria-label="Permalink to &quot;响应式属性&quot;">​</a></h3><table tabindex="0"><thead><tr><th>属性</th><th>类型</th><th>说明</th></tr></thead><tbody><tr><td><code>shortcuts</code></td><td><code>Ref&lt;IShortcut[]&gt;</code></td><td>全部快捷指令列表</td></tr><tr><td><code>filteredShortcuts</code></td><td><code>Ref&lt;IShortcut[]&gt;</code></td><td>过滤后的快捷指令列表</td></tr></tbody></table><h3 id="用法示例-3" tabindex="-1">用法示例 <a class="header-anchor" href="#用法示例-3" aria-label="Permalink to &quot;用法示例&quot;">​</a></h3><div class="language-typescript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> shortcutManager</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ShortcutManager</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(agentModule);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 获取全部快捷指令</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> allShortcuts</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> shortcutManager.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">getShortcuts</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 过滤</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> filtered</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> shortcutManager.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">filterShortcuts</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;代码&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 选择快捷指令</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">shortcutManager.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">selectShortcut</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(shortcut, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;请帮我优化这段代码&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span></code></pre></div><h2 id="uistatemanager" tabindex="-1">UIStateManager <a class="header-anchor" href="#uistatemanager" aria-label="Permalink to &quot;UIStateManager&quot;">​</a></h2><p>UI 状态管理器，管理组件层面的全局 UI 状态，如多选模式。</p><h3 id="方法-4" tabindex="-1">方法 <a class="header-anchor" href="#方法-4" aria-label="Permalink to &quot;方法&quot;">​</a></h3><table tabindex="0"><thead><tr><th>方法</th><th>类型</th><th>说明</th></tr></thead><tbody><tr><td><code>enableSelectionMode</code></td><td><code>() =&gt; void</code></td><td>启用多选模式</td></tr><tr><td><code>disableSelectionMode</code></td><td><code>() =&gt; void</code></td><td>禁用多选模式</td></tr></tbody></table><h3 id="响应式属性-2" tabindex="-1">响应式属性 <a class="header-anchor" href="#响应式属性-2" aria-label="Permalink to &quot;响应式属性&quot;">​</a></h3><table tabindex="0"><thead><tr><th>属性</th><th>类型</th><th>说明</th></tr></thead><tbody><tr><td><code>isSelectionMode</code></td><td><code>Ref&lt;boolean&gt;</code></td><td>当前是否处于多选模式</td></tr></tbody></table><h3 id="用法示例-4" tabindex="-1">用法示例 <a class="header-anchor" href="#用法示例-4" aria-label="Permalink to &quot;用法示例&quot;">​</a></h3><div class="language-typescript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> uiManager</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> UIStateManager</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 进入多选模式（如分享场景）</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">uiManager.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">enableSelectionMode</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 退出多选模式</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">uiManager.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">disableSelectionMode</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 监听状态</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">watch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(uiManager.isSelectionMode, (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">val</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  console.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">log</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;多选模式:&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, val);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">});</span></span></code></pre></div><h2 id="sharebusinessmanager" tabindex="-1">ShareBusinessManager <a class="header-anchor" href="#sharebusinessmanager" aria-label="Permalink to &quot;ShareBusinessManager&quot;">​</a></h2><p>分享业务管理器，负责消息分享相关的业务逻辑。</p><h3 id="构造函数-3" tabindex="-1">构造函数 <a class="header-anchor" href="#构造函数-3" aria-label="Permalink to &quot;构造函数&quot;">​</a></h3><div class="language-typescript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ShareBusinessManager</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(messageModule, sessionModule)</span></span></code></pre></div><table tabindex="0"><thead><tr><th>参数</th><th>类型</th><th>说明</th></tr></thead><tbody><tr><td><code>messageModule</code></td><td><code>MessageModule</code></td><td>chat-helper 的 Message 模块</td></tr><tr><td><code>sessionModule</code></td><td><code>SessionModule</code></td><td>chat-helper 的 Session 模块</td></tr></tbody></table><h3 id="方法-5" tabindex="-1">方法 <a class="header-anchor" href="#方法-5" aria-label="Permalink to &quot;方法&quot;">​</a></h3><table tabindex="0"><thead><tr><th>方法</th><th>类型</th><th>说明</th></tr></thead><tbody><tr><td><code>shareMessages</code></td><td><code>(messages: Message[]) =&gt; Promise&lt;{ shareUrl: string; userMessageIds: string[] }&gt;</code></td><td>分享选中的消息，返回分享链接和用户消息 ID 列表</td></tr></tbody></table><h3 id="用法示例-5" tabindex="-1">用法示例 <a class="header-anchor" href="#用法示例-5" aria-label="Permalink to &quot;用法示例&quot;">​</a></h3><div class="language-typescript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> shareManager</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ShareBusinessManager</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(messageModule, sessionModule);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 分享消息</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">shareUrl</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">userMessageIds</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> await</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> shareManager.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">shareMessages</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(selectedMessages);</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">console.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">log</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;分享链接:&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, shareUrl);</span></span></code></pre></div>`,59)])])}const g=i(n,[["render",h]]);export{c as __pageData,g as default};
