简体中文
FxAiInsight
约 1868 字大约 6 分钟
2026-08-20
用于在 Web 页面展示基于提示词模板或 AI Agent 生成的 AI 洞察结果。
组件/API
Attributes
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|
objectApiName | 洞察所属对象的 API Name(必填)。前台新调用统一使用该名称。 | String | — | '' |
objectDataId | 当前记录 ID。需要使用记录数据、模板字段或记录上下文时必须传入。 | String | — | '' |
id | 当前洞察组件实例的唯一标识(必填)。同一业务位置应保持稳定,不同实例不要复用。 | String | Number | — | '' |
header | 组件标题(必填)。 | String | — | '' |
i18nInfoList | 标题多语言数据。首项 value 有值时优先于 header。示例:[{ value: '客户洞察' }]。 | Array | — | [] |
ai_mode | 洞察执行方式。两种值对应两套互斥参数,见下一节。 | String | prompt | agent | prompt |
trigger_mode | auto 在没有历史结果时自动生成;manual 显示手动生成入口。 | String | auto | manual | auto |
background | 组件背景样式。 | String | white | gradient | white |
maxHeight | 结果区域最大高度,单位为 px。传数字或纯数字字符串,不要带 px。 | Number | String | — | 600 |
有记录场景应直接传 objectDataId。无记录 ID 时,Runtime 会使用当前登录身份生成运行标识:
- CRM 环境读取
window.CRM.ea和window.CRM.curEmpId。 - Portal 环境读取
window.Portal.upstreamEa和window.Portal.EROuterUid。 - 身份信息应在组件挂载前准备完成。身份不完整时不会查询或生成洞察。
- Agent 还需要上述身份建立会话;即使传了
objectDataId,身份不完整时也不能启动 Agent。
Prompt 与 Agent 参数差异
ai_mode="prompt" 和 ai_mode="agent" 是互斥模式。调用方应只传当前模式对应的参数。
| 参数 | Prompt 模式 | Agent 模式 | 说明 |
|---|---|---|---|
promptApiname | 必填 | 不传 | 提示词模板 API Name。Prompt 的生成输入来自该模板、模板变量和记录上下文。 |
agent_api_name | 不传 | 必填 | Agent API Name。 |
topic_api_name | 不传 | 可选 | Agent 场景或技能 API Name。 |
default_message | 不传 | 可选 | Agent 默认输入内容,默认 ''。支持普通文本和 ${对象API.字段API} 模板字段。 |
prefer_ai_product | 不传 | 可选 | 是否优先展示 Agent 返回的 HTML 产物;仅显式传 false 时关闭,默认开启。 |
互斥关系如下:
- Prompt:
ai_mode="prompt"与promptApiname配套使用。 - Agent:
ai_mode="agent"与agent_api_name配套使用,可同时传topic_api_name、default_message和prefer_ai_product。 promptApiname与agent_api_name不应同时传入。default_message只进入 Agent 请求,不会改变提示词模板内容。
Agent 默认输入的传递
default_message 是 Agent 的输入,不是历史洞察结果。Runtime 在发起 Agent 请求前按以下顺序处理:
default_message
-> 解析 ${对象API.字段API} 模板字段
-> [{ type: 'text', text: '计算后的输入内容' }]
-> Agent 请求 content普通文本会原样传递。例如:
<FxAiInsight
ai_mode="agent"
agent_api_name="AccountInsightAgent"
default_message="请分析当前客户的经营情况"
/>传模板字段时必须同时提供真实的 objectDataId:
<FxAiInsight
ai_mode="agent"
agent_api_name="AccountInsightAgent"
object-api-name="AccountObj"
:object-data-id="accountId"
default_message="请分析客户 ${AccountObj.name} 的经营情况"
/>首次生成、无参重跑和带新输入重跑的差异:
| 场景 | 实际使用的 Agent 输入 |
|---|---|
| 首次生成 | 当前 default_message prop |
rerunInsight() | 调用时最新的 default_message prop |
rerunInsight('新内容') | 本次调用传入的新内容 |
传给 rerunInsight 的新内容只覆盖本次执行,不会修改父组件数据,也不会反向修改 default_message prop。显式传入空字符串 '' 也是有效的新输入。
方法
rerunInsight
前台组件实例公开以下方法:
rerunInsight(updatedDefaultMessage?: string): Promise<boolean>调用方式:
// Prompt、Agent 均支持:按当前配置重新执行
const accepted = await this.$refs.insight.rerunInsight();
// 仅 Agent 支持:使用本次更新后的默认输入重新执行
const acceptedWithNewInput = await this.$refs.insight.rerunInsight(
'请基于最新业务数据重新生成洞察'
);参数和返回值:
| 项目 | 说明 |
|---|---|
updatedDefaultMessage | 可选字符串,仅 Agent 支持。传值时作为本次 Agent 默认输入;支持空字符串。 |
返回 true | Runtime 已受理并启动本轮生成。 |
返回 false | 本轮未启动。常见原因包括身份未准备、历史查询未完成、正在生成、生成组件未就绪、模板计算失败、Prompt 传了输入参数或参数不是字符串。 |
Promise<boolean> 只表示是否成功启动,不等待 AI 返回最终内容,也不代表结果已经保存。生成期间不要重复调用;Prompt 模式调用 rerunInsight('文本') 会返回 false,因为 Prompt 不接收任意默认输入。
事件
当前组件未对外暴露公开事件。当前前台 API 不提供最终结果返回值或公开完成事件,调用方不应添加不存在的 @success、@finished 等监听。
插槽
当前组件未提供对外可配置插槽。
示例
简单使用
组件通过全局 Cmpt 加载器获取。返回值是 Vue 2 异步组件工厂,可以直接注册到 components:
const AiInsight = window.Cmpt.get_paas('AiInsight');<template>
<FxAiInsight
id="account-prompt-insight"
object-api-name="AccountObj"
:object-data-id="accountId"
header="客户洞察"
ai_mode="prompt"
prompt-apiname="AccountInsightPrompt"
/>
</template>
<script>
const AiInsight = window.Cmpt.get_paas('AiInsight');
export default {
components: {
FxAiInsight: AiInsight
},
props: {
accountId: String
}
};
</script>Prompt 模式示例
<template>
<div>
<FxAiInsight
ref="insight"
id="account-prompt-insight"
object-api-name="AccountObj"
:object-data-id="accountId"
header="客户洞察"
ai_mode="prompt"
trigger_mode="auto"
prompt-apiname="AccountInsightPrompt"
background="white"
:max-height="600"
/>
<fx-button @click="rerun">重新执行</fx-button>
</div>
</template>
<script>
const AiInsight = window.Cmpt.get_paas('AiInsight');
export default {
components: {
FxAiInsight: AiInsight
},
props: {
accountId: String
},
methods: {
async rerun() {
const accepted = await this.$refs.insight.rerunInsight();
if (!accepted) {
return;
}
// 已启动,最终内容仍由洞察组件内部渲染。
}
}
};
</script>Agent 模式示例
<template>
<div>
<FxAiInsight
ref="insight"
id="account-agent-insight"
object-api-name="AccountObj"
:object-data-id="accountId"
header="客户洞察"
ai_mode="agent"
trigger_mode="auto"
agent_api_name="AccountInsightAgent"
topic_api_name="AccountOperationAnalysis"
:default_message="defaultMessage"
:prefer_ai_product="true"
:max-height="600"
/>
<fx-button @click="rerunWithLatestInput">按最新输入重新执行</fx-button>
</div>
</template>
<script>
const AiInsight = window.Cmpt.get_paas('AiInsight');
export default {
components: {
FxAiInsight: AiInsight
},
props: {
accountId: String
},
data() {
return {
defaultMessage: '请分析当前客户 ${AccountObj.name} 的经营情况'
};
},
methods: {
async rerunWithLatestInput() {
const latestInput =
'请基于最新数据重新分析客户 ${AccountObj.name}';
const accepted = await this.$refs.insight.rerunInsight(
latestInput
);
if (!accepted) {
return;
}
// latestInput 只用于本轮,不会修改 defaultMessage。
}
}
};
</script>传统 JavaScript 挂载示例
async function mountInsight(container, accountId) {
const AiInsight = window.Cmpt.get_paas('AiInsight');
const componentModule = await AiInsight();
const Component = Vue.extend(componentModule.default || componentModule);
const instance = new Component({
propsData: {
id: 'account-agent-insight',
objectApiName: 'AccountObj',
objectDataId: accountId,
header: '客户洞察',
ai_mode: 'agent',
agent_api_name: 'AccountInsightAgent',
default_message: '请分析当前客户的经营情况'
}
});
instance.$mount();
container.appendChild(instance.$el);
const accepted = await instance.rerunInsight(
'请基于最新业务数据重新生成洞察'
);
return {
instance,
accepted,
destroy() {
instance.$destroy();
instance.$el.remove();
}
};
}注意事项
结果与生命周期
- Runtime 挂载后先查询当前实例的历史洞察;存在历史结果时直接展示,不自动重复生成。
- 无历史结果时,
trigger_mode="auto"自动生成,trigger_mode="manual"等待用户触发。 rerunInsight会跳过历史结果重新执行,完成后仍沿用组件内部的结果展示和保存流程。- 当前前台 API 不提供最终结果返回值或公开完成事件。调用方不应添加不存在的
@success、@finished等监听。 - 记录 ID 或登录身份尚未准备好时,应先更新对应 prop,待组件完成当前查询后再调用重跑方法。
接入检查
id在同一业务位置稳定且全局调用范围内不冲突。objectApiName使用真实对象 API Name。- 需要记录上下文时传入真实
objectDataId。 - Prompt 只传
promptApiname,Agent 只传agent_api_name及其专属参数。 - Agent 使用模板字段时已提供真实
objectDataId。 - 登录身份在组件挂载前已准备完成。
- 仅在组件 mounted 后通过
ref调用rerunInsight。 - 调用方正确处理
false,并避免在生成过程中重复调用。
