sync update from LAN repo (source master @ ca48c4ec)

This commit is contained in:
gozeros committed 2026-11-05 10:53:54 +08:00
1 parent 8bc8b0e082
commit ea9dcff9c0
873 files changed
+107866 -14011

No files matched your search

+434 -22
View File
@@ -5,7 +5,8 @@
* 流程:
* 1. 调 consumer 接口 ``GET {VITE_AIPI_CONSUMER_URL}/taskAnalyseSearch/cop-task-detail?taskId=``,
* 请求头 ``Authorization: Bearer admin``(由 service 拦截器统一注入)。
* 2. 把返回的 data(id/overview/taskDirection/taskName/taskContent)整包存到 sessionStorage。
* 2. 把返回的 data(id/overview/taskDirection/taskName/taskContent/taskType)整包存到 sessionStorage。
* ``taskType`` 是字典码,拼开发送的开场信息时映射为 1 打击 / 2 塑势 / 3 防御。
* 3. 按 goPath 解析出业务码 + 模式:
* - ``3qfx`` / ``rwfx`` / ``xdfx`` → 单智能体问答(用「配置管理」里该业务配置的智能体)
* - ``3qfx-A`` / ``rwfx-A`` / ``xdfx-A`` → 多智能体会商(用该业务配置的业务链条)
@@ -19,7 +20,10 @@ import { requestCrudService } from "@/service/request-axios-service";
import { clearTaskContext, persistTaskContext } from "@/core/auth/task-purpose";
import { fetchTaskDeeplinkConfig } from "@/core/auth/task-deeplink-config";
import { readRuntimeEnv, readRuntimeFlag } from "@/env";
import { listBusinessMappings } from "@/strategy-components/api/business-mapping";
import {
listBusinessMappings,
type BusinessMapping,
} from "@/strategy-components/api/business-mapping";
/** xdfx 业务码:深链传入的是「行动id」,需先调 action 接口解析出真正的「任务id」。 */
const XDFX_BUSINESS_CODE = "7BF";
@@ -31,6 +35,41 @@ export interface CopTaskDetail {
taskDirection: string;
taskName: string;
taskContent: string;
/**
* 任务类型字典码(cop-task-detail 的 ``taskType``)。
* 1 打击 / 2 塑势 / 3 防御;缺省或无法识别时为空,发送时省略该行。
*/
taskType?: string;
/** 传播网名称。xdfx 在目的或行为体为 null 时,用它请求传播网简介。 */
cbwName?: string;
}
/** cop-task-detail ``taskType`` 字典码 → 发给模型的任务类型。 */
const COP_TASK_TYPE_LABELS: Record<string, string> = {
"1": "打击",
"2": "塑势",
"3": "防御",
};
const COP_TASK_TYPE_LABEL_VALUES = new Set(Object.values(COP_TASK_TYPE_LABELS));
/** 把任务类型字典码映射成中文;数字、数字字符串和已是中文的值都接受。无法识别时返回空串。 */
export function mapCopTaskTypeLabel(value: unknown): string {
let key = "";
if (typeof value === "number" && Number.isFinite(value)) {
key = String(value);
} else if (typeof value === "string") {
key = value.trim();
}
if (!key) return "";
if (COP_TASK_TYPE_LABEL_VALUES.has(key)) return key;
return COP_TASK_TYPE_LABELS[key] ?? "";
}
function readTaskTypeCode(value: unknown): string {
if (typeof value === "number" && Number.isFinite(value)) return String(value);
if (typeof value === "string") return value.trim();
return "";
}
/** 任务详情整包暂存的 sessionStorage key(目标页/后续可读取)。 */
@@ -39,6 +78,12 @@ export const COP_TASK_DETAIL_STORAGE_KEY = "login.copTaskDetail";
/** 行动详情整包暂存的 sessionStorage key(xdfx 行动分析:会商/单智能体读取行动名称/叙事)。 */
export const ACTION_DETAIL_STORAGE_KEY = "login.actionDetail";
/**
* consumer ``GET /task-action/actionDetail`` 的结构化行动详情。
* 与 ``login.actionDetail``(行动名称/任务 id/传播网)不是同一份数据。
*/
export const TASK_ACTION_STRUCTURE_STORAGE_KEY = "login.taskActionStructure";
/** goPath 基础码 → 业务码(配置管理 businessCode)。 */
const GOPATH_BUSINESS_CODE: Record<string, string> = {
"3qfx": "3Q", // 三情分析
@@ -58,20 +103,33 @@ const BUSINESS_TASK_BASE: Record<string, string> = {
export interface ParsedGoPath {
businessCode: string;
goPath: "3qfx" | "rwfx" | "xdfx";
/** Base goPath, normalized to lowercase and without the optional `-A`. */
goPath: string;
/** true = 多智能体会商(``-A`` 后缀);false = 单智能体问答。 */
roundtable: boolean;
}
/** 解析 goPath(大小写不敏感);``-A`` 后缀表示多智能体会商。无法识别返回 null。 */
export function parseGoPath(goPath: string): ParsedGoPath | null {
/** Normalize any syntactically valid goPath before resolving the mapping. */
function parseGoPathToken(goPath: string): Pick<ParsedGoPath, "goPath" | "roundtable"> | null {
const raw = goPath.trim().toLowerCase();
if (!raw) return null;
const roundtable = raw.endsWith("-a");
const base = roundtable ? raw.slice(0, -2) : raw;
if (!base || base.length > 32) return null;
return { goPath: base, roundtable };
}
/**
* Parse the built-in goPaths (case-insensitive). Custom goPaths are resolved
* from the persisted business-mapping catalogue by `resolveTaskDeeplinkTarget`.
*/
export function parseGoPath(goPath: string): ParsedGoPath | null {
const token = parseGoPathToken(goPath);
if (!token) return null;
const { goPath: base, roundtable } = token;
const businessCode = GOPATH_BUSINESS_CODE[base];
if (!businessCode) return null;
return { businessCode, goPath: base as ParsedGoPath["goPath"], roundtable };
return { businessCode, goPath: base, roundtable };
}
function consumerBaseUrl(): string {
@@ -93,6 +151,8 @@ function mockCopTaskDetail(taskId: string): CopTaskDetail {
taskName: "任务01:暑期文旅舆情综合研判",
taskContent:
"围绕暑期文旅消费高峰,对重点城市、重点景区的公众情绪与舆情态势做综合研判,识别情绪拐点与潜在风险,提出正向引导与处置建议。",
taskType: "1",
cbwName: "暑期文旅传播网",
};
}
@@ -104,6 +164,7 @@ export function stubCopTaskDetail(taskId: string): CopTaskDetail {
taskDirection: "",
taskName: "",
taskContent: "",
taskType: "",
};
}
@@ -126,6 +187,8 @@ export async function fetchCopTaskDetail(taskId: string): Promise<CopTaskDetail
taskDirection: typeof d.taskDirection === "string" ? d.taskDirection : "",
taskName: typeof d.taskName === "string" ? d.taskName : "",
taskContent: typeof d.taskContent === "string" ? d.taskContent : "",
taskType: readTaskTypeCode(d.taskType),
cbwName: normalizeCbwName(d.cbwName),
};
} catch (error) {
console.warn("[task-deeplink] cop-task-detail failed", { taskId, error });
@@ -171,6 +234,236 @@ export function readActionDetail(): ActionDetail | null {
}
}
/**
* 传播网 id 是否可下发给模型。JSON ``null``、缺字段、空串、字面量 ``null`` 都视为不传。
*/
export function normalizeCbwId(value: unknown): string | null {
if (value == null) return null;
if (typeof value === "number") return Number.isFinite(value) ? String(value) : null;
if (typeof value !== "string") return null;
const text = value.trim();
if (!text || text.toLowerCase() === "null" || text.toLowerCase() === "undefined") return null;
return text;
}
/** 传播网名称。空值不下发;没有有效传播网 id 时调用方应整段省略。 */
export function normalizeCbwName(value: unknown): string {
if (typeof value !== "string") return "";
const text = value.trim();
if (!text || text.toLowerCase() === "null" || text.toLowerCase() === "undefined") return "";
return text;
}
/**
* consumer ``GET {VITE_AIPI_CONSUMER_URL}/task-action/actionDetail?actionId=`` 的 data。
* 写入 xdfx 用户消息时:purpose→目的,actor→行为体,expectedBehavior→预期行为,
* drivingFactor→驱动因素,narrationList→叙事(列表元素拼成一句)。
*/
export interface TaskActionStructure {
/** 本次请求使用的行动 id(深链 URL 的 actionId)。 */
actionId: string;
/** JSON null / 缺字段保持 null,用来决定要不要补拉传播网简介。 */
purpose: string | null;
actor: string | null;
expectedBehavior: string;
drivingFactor: string;
/** ``narrationList`` 拼成的一句话。 */
narration: string;
/** ``mainnets/narratives-by-name`` 的 data.summary。仅在目的或行为体为 null 时才有。 */
narrativeSummary: string;
}
function textField(value: unknown): string {
if (typeof value === "number" && Number.isFinite(value)) return String(value);
if (typeof value !== "string") return "";
return value.trim();
}
/** null / 缺字段保持 null;空串仍是空串,不触发传播网简介。 */
function nullableText(value: unknown): string | null {
if (value == null) return null;
return textField(value);
}
/** purpose 或 actor 有一个为 null,就补拉传播网简介。 */
export function actionNeedsNarrative(detail: {
purpose: string | null;
actor: string | null;
} | null | undefined): boolean {
if (!detail) return false;
return detail.purpose === null || detail.actor === null;
}
/** 把叙事列表收成一句。空元素丢掉,条目之间用分号连接。 */
export function joinNarrationList(value: unknown): string {
if (!Array.isArray(value)) return "";
return value.map((item) => textField(item)).filter(Boolean).join(";");
}
function isConsumerOk(state: unknown): boolean {
return state === 200 || state === "200";
}
/** 解析 ``{state, msg, data}``。state 不是 200、或 data 不是对象时返回 null。 */
export function parseTaskActionStructure(body: unknown, actionId: string): TaskActionStructure | null {
if (!body || typeof body !== "object") return null;
const envelope = body as { state?: unknown; data?: unknown };
if (!isConsumerOk(envelope.state)) return null;
const data = envelope.data;
if (!data || typeof data !== "object") return null;
const row = data as Record<string, unknown>;
return {
actionId,
purpose: nullableText(row.purpose),
actor: nullableText(row.actor),
expectedBehavior: textField(row.expectedBehavior),
drivingFactor: textField(row.drivingFactor),
narration: joinNarrationList(row.narrationList),
narrativeSummary: "",
};
}
/** 解析 ``mainnets/narratives-by-name`` 的 ``data.summary``。失败或无简介返回空串。 */
export function parseNarrativeSummary(body: unknown): string {
if (!body || typeof body !== "object") return "";
const envelope = body as { state?: unknown; data?: unknown };
if (!isConsumerOk(envelope.state)) return "";
const data = envelope.data;
if (!data || typeof data !== "object") return "";
return textField((data as { summary?: unknown }).summary);
}
export function taskActionStructureLines(detail: TaskActionStructure | null | undefined): string[] {
if (!detail) return [];
return [
detail.purpose ? `目的:${detail.purpose}` : "",
detail.actor ? `行为体:${detail.actor}` : "",
detail.expectedBehavior ? `预期行为:${detail.expectedBehavior}` : "",
detail.drivingFactor ? `驱动因素:${detail.drivingFactor}` : "",
detail.narration ? `叙事:${detail.narration}` : "",
detail.narrativeSummary ? `传播网简介:${detail.narrativeSummary}` : "",
].filter(Boolean);
}
function persistTaskActionStructure(detail: TaskActionStructure): void {
try {
sessionStorage.setItem(TASK_ACTION_STRUCTURE_STORAGE_KEY, JSON.stringify(detail));
} catch {
/* noop */
}
}
export function readTaskActionStructure(): TaskActionStructure | null {
try {
const raw = sessionStorage.getItem(TASK_ACTION_STRUCTURE_STORAGE_KEY);
if (!raw) return null;
const parsed = JSON.parse(raw) as Partial<TaskActionStructure>;
if (!parsed || typeof parsed !== "object") return null;
return {
actionId: typeof parsed.actionId === "string" ? parsed.actionId : "",
purpose: parsed.purpose == null ? null : typeof parsed.purpose === "string" ? parsed.purpose : "",
actor: parsed.actor == null ? null : typeof parsed.actor === "string" ? parsed.actor : "",
expectedBehavior: typeof parsed.expectedBehavior === "string" ? parsed.expectedBehavior : "",
drivingFactor: typeof parsed.drivingFactor === "string" ? parsed.drivingFactor : "",
narration: typeof parsed.narration === "string" ? parsed.narration : "",
narrativeSummary: typeof parsed.narrativeSummary === "string" ? parsed.narrativeSummary : "",
};
} catch {
return null;
}
}
/** 只取与当前行动 id 匹配的结构化详情,避免串到上一次深链。 */
export function readTaskActionStructureFor(actionId: string): TaskActionStructure | null {
const id = actionId.trim();
if (!id) return null;
const stored = readTaskActionStructure();
if (!stored || stored.actionId !== id) return null;
return stored;
}
const taskActionStructureRequests = new Map<string, Promise<TaskActionStructure | null>>();
const narrativeSummaryRequests = new Map<string, Promise<string>>();
function narrativeCbwName(task: { cbwName?: string | null } | null | undefined, action: { cbwName?: string | null } | null | undefined): string {
return normalizeCbwName(task?.cbwName) || normalizeCbwName(action?.cbwName);
}
async function loadNarrativeSummary(cbwName: string): Promise<string> {
const base = consumerBaseUrl();
if (!base) return "";
try {
const body = await requestCrudService.get(`${base}/mainnets/narratives-by-name`, { cbwName });
return parseNarrativeSummary(body);
} catch (error) {
console.warn("[task-deeplink] narratives-by-name failed", { cbwName, error });
return "";
}
}
/** 按传播网名称取简介。同一名称的在途请求会复用。 */
export function fetchNarrativeSummary(cbwName: string): Promise<string> {
const name = normalizeCbwName(cbwName);
if (!name) return Promise.resolve("");
const existing = narrativeSummaryRequests.get(name);
if (existing) return existing;
const pending = loadNarrativeSummary(name);
narrativeSummaryRequests.set(name, pending);
return pending;
}
/**
* 行动结构里目的或行为体为 null 时,用任务详情(没有则用行动详情)的 cbwName
* 拉传播网简介,写回同一份行动结构,供用户消息拼接。
*/
export async function ensureNarrativeSummary(actionId: string, cbwName: string): Promise<void> {
const id = actionId.trim();
const name = normalizeCbwName(cbwName);
if (!id || !name) return;
const structure = readTaskActionStructureFor(id) ?? (await fetchTaskActionStructure(id));
if (!actionNeedsNarrative(structure)) return;
const summary = await fetchNarrativeSummary(name);
const latest = readTaskActionStructureFor(id) ?? structure;
if (!latest) return;
persistTaskActionStructure({ ...latest, narrativeSummary: summary });
}
async function loadTaskActionStructure(actionId: string): Promise<TaskActionStructure | null> {
const base = consumerBaseUrl();
if (!base) return null;
try {
const body = await requestCrudService.get(`${base}/task-action/actionDetail`, { actionId });
const detail = parseTaskActionStructure(body, actionId);
if (detail) persistTaskActionStructure(detail);
return detail;
} catch (error) {
console.warn("[task-deeplink] task-action/actionDetail failed", { actionId, error });
return null;
}
}
/**
* xdfx 深链:按行动 id 拉 consumer 行动结构。同一 actionId 的在途/已完成请求会复用,
* 登录预取和开场词拼装不会各打一次。失败返回 null,不阻断跳转。
*/
export function fetchTaskActionStructure(actionId: string): Promise<TaskActionStructure | null> {
const id = actionId.trim();
if (!id) return Promise.resolve(null);
const existing = taskActionStructureRequests.get(id);
if (existing) return existing;
const pending = loadTaskActionStructure(id);
taskActionStructureRequests.set(id, pending);
return pending;
}
/** xdfx 发给模型的传播网两行。``cbwId`` 无效时返回空数组,名称也不带。 */
export function cbwModelLines(cbwId: unknown, cbwName: unknown): string[] {
const id = normalizeCbwId(cbwId);
if (!id) return [];
const name = normalizeCbwName(cbwName);
return [`传播网id(cbw_id)为${id}`, ...(name ? [`传播网名称:${name}`] : [])];
}
/** 行动详情接口 ``{action_detail_url}/{actionId}`` 返回的 ``data`` 字段(xdfx 行动分析用)。 */
export interface ActionDetail {
/** 行动id(深链 ?taskId= 传入的就是它)。 */
@@ -185,6 +478,10 @@ export interface ActionDetail {
actionStatus: number | string;
/** 行动叙事 / 描述。 */
narration: string;
/** 传播网 id。接口为 null / 空时保持 null,开场信息不带传播网。 */
cbwId: string | null;
/** 传播网名称。仅在 ``cbwId`` 有值时随开场信息下发。 */
cbwName: string;
}
/**
@@ -216,6 +513,8 @@ export async function fetchActionDetail(actionId: string): Promise<ActionDetail
actionStatus:
typeof d.actionStatus === "number" || typeof d.actionStatus === "string" ? d.actionStatus : "",
narration: typeof d.narration === "string" ? d.narration : "",
cbwId: normalizeCbwId(d.cbwId),
cbwName: normalizeCbwName(d.cbwName),
};
// 取到即整包暂存:登录解析任务id 时(resolveDeeplinkTaskId→fetchTaskIdFromAction)就会缓存它,
// 之后会商左上角「当前行动」、单智能体行动详情卡都能直接 readActionDetail(),避免重复请求。
@@ -250,13 +549,61 @@ export async function resolveDeeplinkTaskId(goPath: string, rawId: string): Prom
return rawId;
}
/**
* 深链预取:登录**进行中**就把不依赖 DeerFlow 登录态的深链数据并行拉好——
* 深链配置(公开端点)、xdfx 行动详情(含其内部缓存的配置)、任务详情
* (consumer 接口走静态 admin Bearer,与登录无关)。登录成功后登录页的
* 深链解析直接消费这些在途/已完成的结果,省掉「配置→行动→任务详情」
* 的整段登录后串行等待。
*
* 失败语义与登录页原逻辑一致:行动详情失败按原始 id 回退拉任务详情、
* realTaskId 给 ""(调用方回退原始 id);任务详情失败为 null(调用方
* 走 stub)。xdfx 同时预取 consumer ``task-action/actionDetail``,失败只是
* 开场词里不带目的/行为体等行。这些 promise 均不 reject。
*/
export interface TaskDeeplinkPrefetch {
/** 真实任务 id(xdfx:行动→任务;其余原样返回)。 */
realTaskId: Promise<string>;
/** 任务详情(xdfx 已串好「行动详情→任务详情」链;无数据/失败为 null)。 */
taskDetail: Promise<CopTaskDetail | null>;
/** xdfx:consumer 行动结构。其它业务为已完成的 null。失败不 reject。 */
actionStructure: Promise<TaskActionStructure | null>;
}
export function prefetchTaskDeeplink(taskId: string, goPath: string): TaskDeeplinkPrefetch {
const parsed = parseGoPath(goPath);
if (parsed?.businessCode === XDFX_BUSINESS_CODE) {
const actionDetail = fetchActionDetail(taskId).catch((error: unknown) => {
console.warn("[task-deeplink] prefetch action detail failed", { taskId, error });
return null;
});
const taskDetail = actionDetail.then((ad) => fetchCopTaskDetail(ad?.taskId || taskId));
const actionStructure = fetchTaskActionStructure(taskId).then(async (structure) => {
if (!actionNeedsNarrative(structure)) return structure;
const [ad, task] = await Promise.all([actionDetail, taskDetail]);
await ensureNarrativeSummary(taskId, narrativeCbwName(task, ad));
return readTaskActionStructureFor(taskId) ?? structure;
});
return {
realTaskId: actionDetail.then((ad) => ad?.taskId ?? ""),
taskDetail,
actionStructure,
};
}
return {
realTaskId: Promise.resolve(taskId),
taskDetail: fetchCopTaskDetail(taskId),
actionStructure: Promise.resolve(null),
};
}
export interface TaskDeeplinkTarget {
path: string;
/** react-router navigate 的 state(多智能体会商用 roundtablePrefill)。 */
state?: Record<string, unknown>;
}
/** xdfx(行动分析)开场信息里要追加的行动信息:行动标题 + 行动内容 + 行动id。 */
/** xdfx(行动分析)开场信息里要追加的行动信息:行动标题 + 行动内容 + 行动id + 传播网。 */
export interface ActionOpeningInfo {
/** 行动id(action_id)。 */
actionId?: string;
@@ -264,20 +611,32 @@ export interface ActionOpeningInfo {
actionName?: string;
/** 行动内容(行动叙事 narration)。 */
narration?: string;
/** 传播网 id。为 null / 空时不写入开场信息,名称一并省略。 */
cbwId?: string | null;
/** 传播网名称。仅在有传播网 id 时写入。 */
cbwName?: string | null;
}
/**
* 用 taskName / taskContent 拼出开场信息文本;末尾附上任务 id(task_id),供后端识别任务。
* ``taskType`` 能映射时插入「任务类型:打击/塑势/防御」。
* xdfx(行动分析)额外附上「行动标题 / 行动内容 / 行动id(action_id)」——传入 action 时追加这几行。
* 同一行动已取到的 consumer 行动结构会再追加「目的 / 行为体 / 预期行为 / 驱动因素 / 叙事」。
* 目的或行为体为 null 时,再追加「传播网简介」。
* 传播网 id、传播网名称仅在 ``cbwId`` 有值时追加;为 null 时两行都不写。
*/
function buildOpeningText(detail: CopTaskDetail, taskId: string, action?: ActionOpeningInfo): string {
const taskTypeLabel = mapCopTaskTypeLabel(detail.taskType);
return [
detail.taskName ? `任务名称:${detail.taskName}` : "",
detail.taskContent ? `任务内容:${detail.taskContent}` : "",
taskTypeLabel ? `任务类型:${taskTypeLabel}` : "",
taskId ? `任务id(task_id)为${taskId}` : "",
action?.actionName ? `行动标题:${action.actionName}` : "",
action?.narration ? `行动内容:${action.narration}` : "",
action?.actionId ? `行动id(action_id)为${action.actionId}` : "",
...taskActionStructureLines(action?.actionId ? readTaskActionStructureFor(action.actionId) : null),
...cbwModelLines(action?.cbwId, action?.cbwName),
]
.filter(Boolean)
.join("\n");
@@ -314,10 +673,36 @@ export async function resolveTaskDeeplinkTarget(
taskId: string,
rawId?: string,
): Promise<TaskDeeplinkTarget | null> {
const parsed = parseGoPath(goPath);
if (!parsed) return null;
const builtIn = parseGoPath(goPath);
const token = parseGoPathToken(goPath);
if (!token) return null;
// Built-ins retain their task-workspace routes. Any other valid base is a
// custom mapping only when it exists in the globally configured catalogue.
let mapping: BusinessMapping | null = null;
const isCustom = !builtIn;
const parsed: ParsedGoPath = builtIn ?? {
businessCode: "",
goPath: token.goPath,
roundtable: token.roundtable,
};
if (isCustom) {
try {
const mappings = await listBusinessMappings();
mapping = mappings.find(
(row) => row.isCustom && row.businessCode.trim().toLowerCase() === token.goPath,
) ?? null;
} catch (error) {
console.warn("[task-deeplink] custom business mapping failed", error);
}
if (!mapping) {
console.warn("[task-deeplink] custom goPath is not configured", token.goPath);
return null;
}
parsed.businessCode = mapping.businessCode;
}
const taskBase = BUSINESS_TASK_BASE[parsed.businessCode];
if (!taskBase) return null;
if (!isCustom && !taskBase) return null;
// 清掉上一次深链可能残留的任务上下文(单智能体分支会用本次任务重新写入)。
clearTaskContext();
@@ -331,11 +716,19 @@ export async function resolveTaskDeeplinkTarget(
let actionId = "";
if (parsed.businessCode === XDFX_BUSINESS_CODE && rawId) {
actionId = rawId;
const ad = readActionDetail() ?? (await fetchActionDetail(rawId));
const [, ad] = await Promise.all([
fetchTaskActionStructure(rawId),
readActionDetail() ? Promise.resolve(readActionDetail()) : fetchActionDetail(rawId),
]);
await ensureNarrativeSummary(rawId, narrativeCbwName(detail, ad));
actionName = ad?.actionName ?? "";
}
return {
path: `${taskBase}/roundtable`,
// Custom mappings have no host business page. They intentionally open a
// clean surface; hideChrome survives the subsequent in-page navigation.
path: isCustom
? "/page/strategy/qa/multi-agent-roundtable?hideChrome=1"
: `${taskBase}/roundtable`,
state: {
roundtablePrefill: {
taskTitle: detail.taskName,
@@ -350,14 +743,15 @@ export async function resolveTaskDeeplinkTarget(
};
}
let agentId: string | null = null;
try {
const mappings = await listBusinessMappings();
agentId = mappings.find((m) => m.businessCode === parsed.businessCode)?.agentId ?? null;
} catch (error) {
console.warn("[task-deeplink] business mapping failed", error);
agentId = null;
if (!mapping) {
try {
const mappings = await listBusinessMappings();
mapping = mappings.find((row) => row.businessCode === parsed.businessCode) ?? null;
} catch (error) {
console.warn("[task-deeplink] business mapping failed", error);
}
}
const agentId = mapping?.agentId ?? null;
if (!agentId) {
console.warn("[task-deeplink] no agent mapped for", parsed.businessCode);
return null;
@@ -368,13 +762,24 @@ export async function resolveTaskDeeplinkTarget(
// 开最新历史对话 / 新建。rwfx 在工作区里额外过「目的树闸门」;3qfx/xdfx 仅 1:N 列表,
// 新建对话直接带开场信息自动发出(见 task-purpose / AgentChatPage 的 taskGate / taskBind)。
// xdfx(行动分析):聊天记录按「行动id」划分(partitionByAction),且开场信息追加
// 行动标题 / 行动内容 / action_id(行动详情登录解析任务id 时已缓存,优先读缓存避免重复请求)。
// 行动标题 / 行动内容 / action_id / 传播网(行动详情登录解析任务id 时已缓存,优先读缓存避免重复请求)。
const isXdfx = parsed.businessCode === XDFX_BUSINESS_CODE;
const actionId = rawId || taskId;
let actionInfo: ActionOpeningInfo | undefined;
if (isXdfx) {
const ad = rawId ? (readActionDetail() ?? (await fetchActionDetail(rawId))) : null;
actionInfo = { actionId, actionName: ad?.actionName, narration: ad?.narration };
const structureId = rawId || actionId;
const [, ad] = await Promise.all([
structureId ? fetchTaskActionStructure(structureId) : Promise.resolve(null),
rawId ? (readActionDetail() ? Promise.resolve(readActionDetail()) : fetchActionDetail(rawId)) : Promise.resolve(null),
]);
if (structureId) await ensureNarrativeSummary(structureId, narrativeCbwName(detail, ad));
actionInfo = {
actionId,
actionName: ad?.actionName,
narration: ad?.narration,
cbwId: ad?.cbwId,
cbwName: ad?.cbwName,
};
}
persistTaskContext({
taskId,
@@ -384,5 +789,12 @@ export async function resolveTaskDeeplinkTarget(
partitionByAction: isXdfx,
goPath: parsed.goPath,
});
if (isCustom) {
// This route deliberately renders AgentChatPage without its left agent
// list. The query also removes the global header and PageSidebar.
return {
path: `/page/strategy/custom-deeplink/${encodeURIComponent(agentId)}/chats/new?hideChrome=1`,
};
}
return { path: `${taskBase}/agent/${agentId}/chats` };
}