feat: rwfx 任务深链支持目的树闸门 + 任务↔对话(1:N)绑定
后端 - config.yaml 新增 task_deeplink 段:完整 URL(无 base)+ test/delete_test 两个独立测试开关 + mock 假数据(目的树 / delete 结果,可随时编辑) - 新增 TaskDeeplinkConfig 模型挂到 AppConfig;新增公开只读接口 GET /api/public/config/task-deeplink 暴露给前端(/api/public 已在鉴权白名单) 前端 - 登录深链 goPath=rwfx 进入「任务工作区」:左侧按 metadata.taskId 过滤的对话列表 (新建对话 / 编辑 / 下一步 / 清除任务记录)+ 右侧问答 - 新建对话(含首次进入)顶部展示目的树闸门:有数据弹覆盖确认→调 delete,success 才开始问答; 恢复历史对话不跑闸门 - 新建 thread 打 metadata.taskId 标签实现「一个任务挂多个对话」(1:N) - 地址/开关/假数据全部走后端配置,拿不到时用内置默认值兜底;test/delete_test=true 走假数据 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
5b610fd807
commit
a2d767e2db
15 files changed
+907
-36
No files matched your search
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* 任务深链(``goPath=rwfx``)的运行时配置:从后端公开只读接口
|
||||
* ``GET /api/public/config/task-deeplink`` 读取(地址、测试开关、测试假数据全在后端
|
||||
* ``config.yaml`` 的 ``task_deeplink`` 段,改完即时生效,前端无需重建)。
|
||||
*
|
||||
* 两种用法:
|
||||
* - 命令式(登录深链流程,非 React 环境):``fetchTaskDeeplinkConfig()`` 拉取并模块级缓存;
|
||||
* ``getCachedTaskDeeplinkConfig()`` 同步读缓存(拼跳转地址用)。
|
||||
* - React 组件:``useTaskDeeplinkConfig()``(见 [[task-purpose]] 的面板/列表)。
|
||||
*
|
||||
* 拉取失败 → 用内置默认值(``test=false`` + 真实 URL)兜底,功能不整体挂掉。
|
||||
*/
|
||||
|
||||
import { apiFetch } from "@/core/api/fetch-client";
|
||||
import { getBackendBaseURL } from "@/core/config";
|
||||
|
||||
export interface TaskDeeplinkConfig {
|
||||
/** 目的树查询走假数据。 */
|
||||
test: boolean;
|
||||
/** 删除接口走假数据(该接口未开发完时打开)。 */
|
||||
deleteTest: boolean;
|
||||
/** 目的树查询完整 URL(调用追加 ?taskId=)。 */
|
||||
purposeDetailUrl: string;
|
||||
/** 删除完整 URL(调用追加 ?taskId=)。 */
|
||||
deleteUrl: string;
|
||||
/** B 系统树形完整编辑页 URL(跳转追加 ?id=)。 */
|
||||
treemapEditUrl: string;
|
||||
/** B 系统树形下一步页 URL(跳转追加 ?id=)。 */
|
||||
treemapNextUrl: string;
|
||||
/** 测试假数据:purposeDetail = 原始 {state,msg,data};delete = {message,success}。 */
|
||||
mock: {
|
||||
purposeDetail?: unknown;
|
||||
delete?: { message?: string; success?: boolean };
|
||||
};
|
||||
}
|
||||
|
||||
/** 内置默认值(后端拿不到时兜底;真实 URL + 关闭测试)。 */
|
||||
export const DEFAULT_TASK_DEEPLINK_CONFIG: TaskDeeplinkConfig = {
|
||||
test: false,
|
||||
deleteTest: false,
|
||||
purposeDetailUrl: "https://ch1.b.uat.4.cn/consumer/taskAnalyseSearch/getTaskPurposeDetail",
|
||||
deleteUrl: "https://ch1.b.uat.4.cn/consumer/taskAnalyseSearch/delete",
|
||||
treemapEditUrl: "https://ch1.b.uat.4.cn/web/#/task/item-aicoh/step-mode-treemap-full-edit",
|
||||
treemapNextUrl: "https://ch1.b.uat.4.cn/web/#/task/item-aicoh/step-mode-treemap-full-next",
|
||||
mock: {},
|
||||
};
|
||||
|
||||
/** 后端 snake_case 响应 → 前端 camelCase;缺字段回退默认值。 */
|
||||
function normalize(body: unknown): TaskDeeplinkConfig {
|
||||
const o = body && typeof body === "object" ? (body as Record<string, unknown>) : {};
|
||||
const d = DEFAULT_TASK_DEEPLINK_CONFIG;
|
||||
const str = (v: unknown, fallback: string) =>
|
||||
typeof v === "string" && v.trim() ? v : fallback;
|
||||
const mock = o.mock && typeof o.mock === "object" ? (o.mock as Record<string, unknown>) : {};
|
||||
return {
|
||||
test: o.test === true,
|
||||
deleteTest: o.delete_test === true,
|
||||
purposeDetailUrl: str(o.purpose_detail_url, d.purposeDetailUrl),
|
||||
deleteUrl: str(o.delete_url, d.deleteUrl),
|
||||
treemapEditUrl: str(o.treemap_edit_url, d.treemapEditUrl),
|
||||
treemapNextUrl: str(o.treemap_next_url, d.treemapNextUrl),
|
||||
mock: {
|
||||
purposeDetail: mock.purpose_detail,
|
||||
delete:
|
||||
mock.delete && typeof mock.delete === "object"
|
||||
? (mock.delete as { message?: string; success?: boolean })
|
||||
: undefined,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
let cached: TaskDeeplinkConfig | null = null;
|
||||
let inflight: Promise<TaskDeeplinkConfig> | null = null;
|
||||
|
||||
/** 拉取(带模块级缓存 + 去重);失败回退默认值。 */
|
||||
export async function fetchTaskDeeplinkConfig(): Promise<TaskDeeplinkConfig> {
|
||||
if (cached) return cached;
|
||||
if (inflight) return inflight;
|
||||
inflight = (async () => {
|
||||
try {
|
||||
const res = await apiFetch(`${getBackendBaseURL()}/api/public/config/task-deeplink`);
|
||||
if (!res.ok) throw new Error(`task-deeplink config ${res.status}`);
|
||||
cached = normalize(await res.json());
|
||||
} catch {
|
||||
cached = { ...DEFAULT_TASK_DEEPLINK_CONFIG };
|
||||
} finally {
|
||||
inflight = null;
|
||||
}
|
||||
return cached;
|
||||
})();
|
||||
return inflight;
|
||||
}
|
||||
|
||||
/** 同步读缓存(未拉取过则返回默认值)。 */
|
||||
export function getCachedTaskDeeplinkConfig(): TaskDeeplinkConfig {
|
||||
return cached ?? DEFAULT_TASK_DEEPLINK_CONFIG;
|
||||
}
|
||||
|
||||
/** 在完整 URL(可能含 `#` 片段)后追加查询参数,供跳转/调用拼 id/taskId。 */
|
||||
export function appendQueryParam(url: string, key: string, value: string): string {
|
||||
if (!url) return "";
|
||||
const sep = url.includes("?") ? "&" : "?";
|
||||
return `${url}${sep}${key}=${encodeURIComponent(value)}`;
|
||||
}
|
||||
@@ -16,8 +16,12 @@
|
||||
*/
|
||||
|
||||
import { requestCrudService } from "@/service/request-axios-service";
|
||||
import { clearTaskContext, persistTaskContext } from "@/core/auth/task-purpose";
|
||||
import { listBusinessMappings } from "@/strategy-components/api/business-mapping";
|
||||
|
||||
/** rwfx 业务码:单智能体走「任务工作区 + 目的树闸门」(其它业务保持原问答逻辑)。 */
|
||||
const RWFX_BUSINESS_CODE = "6BF";
|
||||
|
||||
/** consumer 接口返回的任务详情(data 字段)。 */
|
||||
export interface CopTaskDetail {
|
||||
id: string | number | null;
|
||||
@@ -132,12 +136,16 @@ function buildOpeningText(detail: CopTaskDetail): string {
|
||||
export async function resolveTaskDeeplinkTarget(
|
||||
goPath: string,
|
||||
detail: CopTaskDetail,
|
||||
taskId: string,
|
||||
): Promise<TaskDeeplinkTarget | null> {
|
||||
const parsed = parseGoPath(goPath);
|
||||
if (!parsed) return null;
|
||||
const taskBase = BUSINESS_TASK_BASE[parsed.businessCode];
|
||||
if (!taskBase) return null;
|
||||
|
||||
// 清掉上一次深链可能残留的任务上下文(仅 rwfx 单智能体会重新写入)。
|
||||
clearTaskContext();
|
||||
|
||||
if (parsed.roundtable) {
|
||||
// 多智能体会商:嵌进对应业务的「任务管理」布局;businessCode 让会商页自动选用配置的业务链条。
|
||||
return {
|
||||
@@ -162,6 +170,15 @@ export async function resolveTaskDeeplinkTarget(
|
||||
}
|
||||
if (!agentId) return null;
|
||||
|
||||
if (parsed.businessCode === RWFX_BUSINESS_CODE) {
|
||||
// rwfx:走「任务工作区」——暂存任务上下文(taskId + 开场信息),跳到 chats 索引,
|
||||
// 由工作区按 taskId 决定开最新历史对话 / 新建(新建走目的树闸门)。不设 pendingAgentMessage:
|
||||
// 开场信息在闸门通过后由目的树面板发出。
|
||||
persistTaskContext({ taskId, agentId, openingText: buildOpeningText(detail) });
|
||||
return { path: `${taskBase}/agent/${agentId}/chats` };
|
||||
}
|
||||
|
||||
// 其它单智能体问答:保持原逻辑(pendingAgentMessage 自动发出 + chats/new)。
|
||||
try {
|
||||
sessionStorage.setItem(
|
||||
"pendingAgentMessage",
|
||||
@@ -170,6 +187,5 @@ export async function resolveTaskDeeplinkTarget(
|
||||
} catch {
|
||||
/* noop */
|
||||
}
|
||||
// 单智能体问答:同样嵌进对应业务的「任务管理」布局。
|
||||
return { path: `${taskBase}/agent/${agentId}/chats/new` };
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
/**
|
||||
* 任务深链(``goPath=rwfx``)的「目的树闸门 + 任务↔对话绑定」支持。
|
||||
*
|
||||
* 角色区分:
|
||||
* - **目的树数据**:B 系统里的策划结果,走 ``getTaskPurposeDetail`` / ``delete``(地址、测试
|
||||
* 开关、测试假数据都来自 [[task-deeplink-config]] / 后端 config.yaml),与聊天对话无关。
|
||||
* 新建对话(含首次进入)前用它做「已有数据→覆盖确认」闸门。
|
||||
* - **对话(thread)**:聊天会话;通过 thread 的 ``metadata.taskId`` 标签把多个对话挂到同一个
|
||||
* 任务下(1:N),列表用 useThreadsPage({ metadata:{ taskId } }) 过滤。详见 [[task-deeplink]]。
|
||||
*/
|
||||
|
||||
import {
|
||||
appendQueryParam,
|
||||
fetchTaskDeeplinkConfig,
|
||||
getCachedTaskDeeplinkConfig,
|
||||
} from "@/core/auth/task-deeplink-config";
|
||||
import { requestCrudService } from "@/service/request-axios-service";
|
||||
|
||||
/** 归一化后的目的树节点(用于展示,逐层:目的→行为体→预期行为→驱动因素→叙事)。 */
|
||||
export interface PurposeTreeNode {
|
||||
/** 节点类型中文标签。 */
|
||||
label: string;
|
||||
/** 节点主文本(目的/行为体名/预期/因素/叙事内容)。 */
|
||||
text: string;
|
||||
/** 推荐理由(若有)。 */
|
||||
reason?: string;
|
||||
children: PurposeTreeNode[];
|
||||
}
|
||||
|
||||
/** 当前 rwfx 任务上下文(深链进入或「新建对话」时暂存,供闸门面板与绑定使用)。 */
|
||||
export interface TaskContext {
|
||||
taskId: string;
|
||||
agentId: string;
|
||||
/** 自动发出的开场信息(任务名称/内容)。 */
|
||||
openingText: string;
|
||||
}
|
||||
|
||||
const TASK_CONTEXT_STORAGE_KEY = "task.rwfxContext";
|
||||
|
||||
/* --------------------------- 目的树查询/删除 --------------------------- */
|
||||
|
||||
/** 逐层 dto 字段映射:key=childrenList 里出现的 *Dto 字段名。 */
|
||||
const DTO_FIELD_MAP: Record<string, { label: string; textKey: string }> = {
|
||||
purposeDto: { label: "目的", textKey: "zzPurpose" },
|
||||
actorDto: { label: "行为体", textKey: "actorName" },
|
||||
expectedBehaviorDto: { label: "预期行为", textKey: "behavior" },
|
||||
drivingFactorDto: { label: "驱动因素", textKey: "drivingFactor" },
|
||||
narrationDto: { label: "叙事", textKey: "narration" },
|
||||
};
|
||||
|
||||
function normalizeNode(raw: unknown): PurposeTreeNode | null {
|
||||
if (!raw || typeof raw !== "object") return null;
|
||||
const obj = raw as Record<string, unknown>;
|
||||
// 找出本节点携带的 dto 字段(目的/行为体/...)。
|
||||
const dtoKey = Object.keys(DTO_FIELD_MAP).find(
|
||||
(k) => obj[k] && typeof obj[k] === "object",
|
||||
);
|
||||
if (!dtoKey) return null;
|
||||
const { label, textKey } = DTO_FIELD_MAP[dtoKey];
|
||||
const dto = obj[dtoKey] as Record<string, unknown>;
|
||||
const text = typeof dto[textKey] === "string" ? (dto[textKey] as string) : "";
|
||||
const reason =
|
||||
typeof dto.recReason === "string" && dto.recReason.trim()
|
||||
? (dto.recReason as string)
|
||||
: undefined;
|
||||
const childrenRaw = Array.isArray(obj.childrenList) ? obj.childrenList : [];
|
||||
const children = childrenRaw
|
||||
.map(normalizeNode)
|
||||
.filter((n): n is PurposeTreeNode => n !== null);
|
||||
return { label, text, reason, children };
|
||||
}
|
||||
|
||||
/** 从接口/假数据的整包 body 里取出 data 数组并归一化成树。 */
|
||||
function bodyToTree(body: unknown): PurposeTreeNode[] {
|
||||
const data =
|
||||
body && typeof body === "object" ? (body as { data?: unknown }).data : null;
|
||||
const arr = Array.isArray(data) ? data : [];
|
||||
return arr.map(normalizeNode).filter((n): n is PurposeTreeNode => n !== null);
|
||||
}
|
||||
|
||||
export interface TaskPurposeResult {
|
||||
tree: PurposeTreeNode[];
|
||||
/** data 数组里有有效目的节点 = 已有策划数据。 */
|
||||
hasData: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询任务目的树。``test=true`` 时直接用后端配置里的假数据;否则打真实接口
|
||||
* (地址来自配置,``Authorization: Bearer admin`` 由 axios 拦截器统一注入)。
|
||||
* 缺地址 / 返回不合法 → ``{ tree: [], hasData: false }``。
|
||||
*/
|
||||
export async function fetchTaskPurposeDetail(
|
||||
taskId: string,
|
||||
): Promise<TaskPurposeResult> {
|
||||
if (!taskId) return { tree: [], hasData: false };
|
||||
const cfg = await fetchTaskDeeplinkConfig();
|
||||
let body: unknown;
|
||||
if (cfg.test) {
|
||||
body = cfg.mock.purposeDetail;
|
||||
} else if (cfg.purposeDetailUrl) {
|
||||
body = await requestCrudService.get(cfg.purposeDetailUrl, { taskId });
|
||||
} else {
|
||||
return { tree: [], hasData: false };
|
||||
}
|
||||
const tree = bodyToTree(body);
|
||||
return { tree, hasData: tree.length > 0 };
|
||||
}
|
||||
|
||||
export interface DeleteTaskPurposeResult {
|
||||
message: string;
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除任务目的树(覆盖前清空 / 手动清除任务记录都走这里)。``delete_test=true`` 时
|
||||
* 用后端配置里的假数据(接口未开发完时用);否则打真实接口。
|
||||
*/
|
||||
export async function deleteTaskPurpose(
|
||||
taskId: string,
|
||||
): Promise<DeleteTaskPurposeResult> {
|
||||
if (!taskId) return { message: "缺少 taskId", success: false };
|
||||
const cfg = await fetchTaskDeeplinkConfig();
|
||||
if (cfg.deleteTest) {
|
||||
const m = cfg.mock.delete ?? {};
|
||||
return { message: typeof m.message === "string" ? m.message : "", success: m.success === true };
|
||||
}
|
||||
if (!cfg.deleteUrl) return { message: "缺少删除接口地址", success: false };
|
||||
const body = await requestCrudService.get(cfg.deleteUrl, { taskId });
|
||||
const obj =
|
||||
body && typeof body === "object" ? (body as unknown as Record<string, unknown>) : {};
|
||||
return {
|
||||
message: typeof obj.message === "string" ? obj.message : "",
|
||||
success: obj.success === true,
|
||||
};
|
||||
}
|
||||
|
||||
/* ----------------------------- 跳转地址 ----------------------------- */
|
||||
|
||||
/** B 系统「树形完整编辑」页地址(问答后「编辑」按钮,新标签打开)。用同步缓存配置。 */
|
||||
export function buildTreemapEditUrl(taskId: string): string {
|
||||
const url = getCachedTaskDeeplinkConfig().treemapEditUrl;
|
||||
return url && taskId ? appendQueryParam(url, "id", taskId) : "";
|
||||
}
|
||||
|
||||
/** B 系统「树形下一步」页地址(问答后「下一步」按钮,新标签打开)。 */
|
||||
export function buildTreemapNextUrl(taskId: string): string {
|
||||
const url = getCachedTaskDeeplinkConfig().treemapNextUrl;
|
||||
return url && taskId ? appendQueryParam(url, "id", taskId) : "";
|
||||
}
|
||||
|
||||
/* --------------------------- 任务上下文暂存 --------------------------- */
|
||||
|
||||
export function persistTaskContext(ctx: TaskContext): void {
|
||||
try {
|
||||
sessionStorage.setItem(TASK_CONTEXT_STORAGE_KEY, JSON.stringify(ctx));
|
||||
} catch {
|
||||
/* noop */
|
||||
}
|
||||
}
|
||||
|
||||
export function readTaskContext(): TaskContext | null {
|
||||
try {
|
||||
const raw = sessionStorage.getItem(TASK_CONTEXT_STORAGE_KEY);
|
||||
if (!raw) return null;
|
||||
const parsed = JSON.parse(raw) as Partial<TaskContext>;
|
||||
if (!parsed?.taskId || !parsed?.agentId) return null;
|
||||
return {
|
||||
taskId: String(parsed.taskId),
|
||||
agentId: String(parsed.agentId),
|
||||
openingText: typeof parsed.openingText === "string" ? parsed.openingText : "",
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function clearTaskContext(): void {
|
||||
try {
|
||||
sessionStorage.removeItem(TASK_CONTEXT_STORAGE_KEY);
|
||||
} catch {
|
||||
/* noop */
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user