722b18326f
含 MindSpace 三列布局与统计修复、聊天加载态与连接降级、平台页脚标记与 og:site_name 微信卡片、勾选资料删除 Agent 接口及内部话术过滤。 Co-authored-by: Cursor <cursoragent@cursor.com>
59 lines
2.5 KiB
JavaScript
59 lines
2.5 KiB
JavaScript
export function buildSelectedAssetDeleteInstructions(context) {
|
|
const selected = context.selectedAssets ?? [];
|
|
if (selected.length !== 1) return [];
|
|
|
|
const asset = selected[0];
|
|
const h5ApiBase = String(context.h5ApiBase ?? '').replace(/\/$/, '');
|
|
const sessionId = String(context.agentSessionId ?? '').trim();
|
|
if (!h5ApiBase) return [];
|
|
|
|
const sessionToken = sessionId || '<CURRENT_AGENT_SESSION>';
|
|
const sessionHint = sessionId
|
|
? ''
|
|
: '- session_id 未写入上下文时,使用当前 Agent 会话 ID 替换 `<CURRENT_AGENT_SESSION>`。\n';
|
|
|
|
return [
|
|
'【勾选资料删除(硬性)】',
|
|
`- 你对用户 MindSpace 拥有完整读写删改权限;用户已勾选「${asset.displayName}」(id: ${asset.id})。`,
|
|
'- 用户要求删除这份资料时:先说明将删除哪一份并等待用户明确确认(如「确定」「删吧」「确认删除」);**禁止**未确认就删。',
|
|
sessionHint,
|
|
'- 用户确认后,**必须立即**用 shell 执行(不要只口头说已删,也不要让用户自己去界面点删除):',
|
|
'```bash',
|
|
`curl -sS -X POST '${h5ApiBase}/api/agent/mindspace_asset_delete' \\`,
|
|
" -H 'Content-Type: application/json' \\",
|
|
` -d '{"session_id":"${sessionToken}","asset_id":"${asset.id}","confirmed":true}'`,
|
|
'```',
|
|
'- curl 成功后再回复「已删除」;若返回 asset_in_use,说明被页面引用,告知用户先删关联页面。',
|
|
'- 禁止删除未勾选的其它文件。',
|
|
'',
|
|
].filter(Boolean);
|
|
}
|
|
|
|
export function createAssetAgentService({ assetService, resolveUserIdForAgentSession }) {
|
|
return {
|
|
async applyAgentDelete(input = {}) {
|
|
const sessionId = String(input?.sessionId ?? input?.session_id ?? '').trim();
|
|
const assetId = String(input?.assetId ?? input?.asset_id ?? '').trim();
|
|
const confirmed = input?.confirmed === true || String(input?.confirmed ?? '').toLowerCase() === 'true';
|
|
if (!sessionId || !assetId) {
|
|
throw Object.assign(new Error('缺少 session_id 或 asset_id'), { code: 'invalid_request' });
|
|
}
|
|
if (!confirmed) {
|
|
throw Object.assign(new Error('删除前须已在对话中获得用户确认'), { code: 'confirmation_required' });
|
|
}
|
|
|
|
const userId = await resolveUserIdForAgentSession(sessionId);
|
|
if (!userId) {
|
|
throw Object.assign(new Error('无效的 Agent 会话'), { code: 'forbidden' });
|
|
}
|
|
|
|
const result = await assetService.deleteAsset(userId, assetId);
|
|
return {
|
|
assetId,
|
|
userId,
|
|
...result,
|
|
};
|
|
},
|
|
};
|
|
}
|