开源免费的WPS AI 软件 察元AI文档助手:链路 004:getAssistantLaunchInfoInternal 与空输入拦截 - }#mermaid-svg-Bh8WwCgwDjm0076M
链路 004:getAssistantLaunchInfoInternal 与空输入拦截
总体链路图
下图在全系列各篇保持一致,仅通过高亮样式标示本篇所覆盖的环节;箭头表示主成功路径,点线为异常或可选路径。阅读任意一篇时都应能回到本图定位,避免在单文件里「钻太深」而失去上下游语境。
#mermaid-svg-Bh8WwCgwDjm0076M{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-Bh8WwCgwDjm0076M .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-Bh8WwCgwDjm0076M .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-Bh8WwCgwDjm0076M .error-icon{fill:#552222;}#mermaid-svg-Bh8WwCgwDjm0076M .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-Bh8WwCgwDjm0076M .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-Bh8WwCgwDjm0076M .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-Bh8WwCgwDjm0076M .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-Bh8WwCgwDjm0076M .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-Bh8WwCgwDjm0076M .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-Bh8WwCgwDjm0076M .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-Bh8WwCgwDjm0076M .marker{fill:#333333;stroke:#333333;}#mermaid-svg-Bh8WwCgwDjm0076M .marker.cross{stroke:#333333;}#mermaid-svg-Bh8WwCgwDjm0076M svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-Bh8WwCgwDjm0076M p{margin:0;}#mermaid-svg-Bh8WwCgwDjm0076M .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-Bh8WwCgwDjm0076M .cluster-label text{fill:#333;}#mermaid-svg-Bh8WwCgwDjm0076M .cluster-label span{color:#333;}#mermaid-svg-Bh8WwCgwDjm0076M .cluster-label span p{background-color:transparent;}#mermaid-svg-Bh8WwCgwDjm0076M .label text,#mermaid-svg-Bh8WwCgwDjm0076M span{fill:#333;color:#333;}#mermaid-svg-Bh8WwCgwDjm0076M .node rect,#mermaid-svg-Bh8WwCgwDjm0076M .node circle,#mermaid-svg-Bh8WwCgwDjm0076M .node ellipse,#mermaid-svg-Bh8WwCgwDjm0076M .node polygon,#mermaid-svg-Bh8WwCgwDjm0076M .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-Bh8WwCgwDjm0076M .rough-node .label text,#mermaid-svg-Bh8WwCgwDjm0076M .node .label text,#mermaid-svg-Bh8WwCgwDjm0076M .image-shape .label,#mermaid-svg-Bh8WwCgwDjm0076M .icon-shape .label{text-anchor:middle;}#mermaid-svg-Bh8WwCgwDjm0076M .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-Bh8WwCgwDjm0076M .rough-node .label,#mermaid-svg-Bh8WwCgwDjm0076M .node .label,#mermaid-svg-Bh8WwCgwDjm0076M .image-shape .label,#mermaid-svg-Bh8WwCgwDjm0076M .icon-shape .label{text-align:center;}#mermaid-svg-Bh8WwCgwDjm0076M .node.clickable{cursor:pointer;}#mermaid-svg-Bh8WwCgwDjm0076M .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-Bh8WwCgwDjm0076M .arrowheadPath{fill:#333333;}#mermaid-svg-Bh8WwCgwDjm0076M .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-Bh8WwCgwDjm0076M .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-Bh8WwCgwDjm0076M .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-Bh8WwCgwDjm0076M .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-Bh8WwCgwDjm0076M .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-Bh8WwCgwDjm0076M .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-Bh8WwCgwDjm0076M .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-Bh8WwCgwDjm0076M .cluster text{fill:#333;}#mermaid-svg-Bh8WwCgwDjm0076M .cluster span{color:#333;}#mermaid-svg-Bh8WwCgwDjm0076M div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-Bh8WwCgwDjm0076M .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-Bh8WwCgwDjm0076M rect.text{fill:none;stroke-width:0;}#mermaid-svg-Bh8WwCgwDjm0076M .icon-shape,#mermaid-svg-Bh8WwCgwDjm0076M .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-Bh8WwCgwDjm0076M .icon-shape p,#mermaid-svg-Bh8WwCgwDjm0076M .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-Bh8WwCgwDjm0076M .icon-shape .label rect,#mermaid-svg-Bh8WwCgwDjm0076M .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-Bh8WwCgwDjm0076M .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-Bh8WwCgwDjm0076M .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-Bh8WwCgwDjm0076M :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}
plain
structured
multimodal
1 入口: Ribbon/对话框 → assistantId
2 startAssistantTask 占位任务
3 launchInfo 与 resolveDocumentInput
4 resolveModel 与模型清单
5 提示词拼装与 launchGuard
6 分流 plain / structured / multimodal 拼多多帮助力入口
7a chatCompletion 文本链路 plain
7b chatCompletion 结构化批次
8a applyDocumentAction
8b executionPlan → applyDocumentProcessingPlan
7c generateMultimodalAsset
9 评测持久化与任务完成态
异常路径 normalizeError → 安全弹窗
本篇在总体链路中的位置
对应图中节点 N3 左半:launchInfo 在校验空输入后才允许继续,避免无效 HTTP。 高亮节点:N3。若本篇同时引用 chatApi 与任务运行器,通常意味着该逻辑处于「编排层与网络层交界」:修改时要同时考虑任务取消与 UI 快照。
深度说明(工程视角)
从工程维护角度看,本篇讨论的对象应当被视为「可替换实现」:只要对外的任务状态、HTTP 契约与文档写回语义保持不变,内部可以重构函数拆分或调整日志字段。阅读时建议始终抓住三个锚点:一是数据从哪来(PluginStorage、localStorage、COM 选区还是全文);二是数据何时离开本机(进入 fetch 之前是否已完成脱敏与快照);三是失败时用户可见的文本由谁归一(chatApi 与助手错误弹窗两条路径)。
就「链路 004:getAssistantLaunchInfoInternal 与空输入拦截」而言,源码位置可概括为:assistantTaskRunner.js 中 getAssistantLaunchInfoInternal。这与摘要中的判断一致:在任意 chatCompletion 调用之前,getAssistantLaunchInfoInternal 合并运行时配置、检查助手启用状态、解析 effectiveInputSource,并通过 resolveDocumentInput 得到 inputText。若文本为空直接抛错,避免无效 HTTP 请求。关键词「resolveDocumentInput、enabled、抛错」提示你在仓库内做全文检索时应优先锁定这些符号,而不是仅依赖界面文案。
与网络请求相关的修改,务必在本地用开发者工具或代理核对:请求体中的 model 字段是否与设置页保存的 modelId 一致;Authorization 是否只取 apiKey 列表的第一段(部分网关对多密钥格式敏感);stream 为 true 时宿主是否稳定消费 SSE。若你引入新的 provider,应对照 getChatApiConfigByProvider 的 URL 拼接分支补充单元测试或手测用例,避免「路径已含 v1 却又重复拼接」类错误。
与文档写回相关的修改,应优先在无界面的纯函数层复现:例如仅调用 applyDocumentAction 或 applyDocumentProcessingPlan 的入参快照,观察 Range 坐标是否在 CRLF 归一化前后发生漂移。WPS 与 Word 在选区、批注锚点上的差异会放大这类问题,因此本篇若在讲坐标或分段,请同时阅读 documentPositionUtils 与 chunk 相关教程篇目。
阅读顺序上,本篇之后建议继续看:通过后进入 resolveModel 与提示词拼装(005–012)。若在总体图中定位,对应图中节点 N3 左半:launchInfo 在校验空输入后才允许继续,避免无效 HTTP。 遇到与教程系列术语不一致时,以源码标识符为准:教程侧重导航与概念,本系列侧重调用次序与失败面。
最后说明写作立场:本系列不对任何云厂商或模型服务做优劣评价,也不暗示「必须开通」某类账号;所述配置项仅反映当前仓库为打通 OpenAI 兼容协议而需要的最小字段集合。若组织策略禁止外联,应在网关或 hosts 层拦截,而不是在加载项内写死假地址。
与教程系列文档的对照
下列文档来自 docs/chayuan-tutorial-series,侧重「如何阅读仓库」与界面侧概念,与本链路系列互补:不重复推销功能,仅帮助建立目录与模块边界。
chayuan-tutorial-series/08-wenben-fenxi-zhushou-changjing-yu-fengxian.md:与本篇链路相邻的工程说明,可对照变量命名与文件职责。chayuan-tutorial-series/16-wendang-shuru-laiyuan-jiekou.md:与本篇链路相邻的工程说明,可对照变量命名与文件职责。
摘要
在任意 chatCompletion 调用之前,getAssistantLaunchInfoInternal 合并运行时配置、检查助手启用状态、解析 effectiveInputSource,并通过 resolveDocumentInput 得到 inputText。若文本为空直接抛错,避免无效 HTTP 请求。
关键词
resolveDocumentInput;enabled;抛错
链路位置(源码索引)
assistantTaskRunner.js 中 getAssistantLaunchInfoInternal。
正文
1. 输入与空文档
inputInfo 与 inputText 来自 resolveDocumentInput;无文本时区分「未选中」与「全文无内容」两类错误信息。
维护时建议把本节涉及的符号在 IDE 里「查找引用」:确认是否还有对话框专用服务、拼写检查服务或评测脚本以拷贝粘贴方式重复了相似逻辑。若发现重复,优先抽到 chatApi 之上的薄封装,而不是在业务层再次拼接 URL 或 Authorization,以降低安全审查时的遗漏面。
// src/utils/assistantTaskRunner.js 第1408-1439行
function getAssistantLaunchInfoInternal(assistantId, overrides = {}) {
const resolved = getAssistantDefinition(assistantId)
if (!resolved) {
throw new Error('未找到对应的助手配置')
}
const strictAssistantDefaults = overrides.strictAssistantDefaults === true
const launchSource = String(overrides.launchSource || '').trim()
const runtimeConfig = mergeAssistantRuntimeConfig(resolved.config, overrides)
if (strictAssistantDefaults) {
runtimeConfig.documentAction = resolved.config?.documentAction || runtimeConfig.documentAction
runtimeConfig.inputSource = resolved.config?.inputSource || runtimeConfig.inputSource
}
const { definition, source } = resolved
if (source === 'builtin' && runtimeConfig.enabled === false) {
throw new Error('该助手功能已在设置中关闭,请先启用')
}
const reportSettings = getEffectiveReportSettings(runtimeConfig)
const effectiveInputSource = strictAssistantDefaults
? (reportSettings.enabled ? 'document' : runtimeConfig.inputSource || 'selection-preferred')
: (overrides.inputSource || (reportSettings.enabled ? 'document' : runtimeConfig.inputSource || 'selection-preferred'))
const effectiveDocumentAction = strictAssistantDefaults
? (runtimeConfig.documentAction || 'insert')
: (overrides.documentAction || runtimeConfig.documentAction)
const inputInfo = resolveDocumentInput(effectiveInputSource)
const inputText = String(overrides.inputText || inputInfo.text || '').trim()
if (!inputText) {
throw new Error(inputInfo.source === 'selection'
? '请先选中文本再执行该助手'
: '当前文档没有可处理的文本内容')
}
上下游衔接
通过后进入 resolveModel 与提示词拼装(005–012)。