fix: add goose execution override for h5 chat
This commit is contained in:
@@ -3,6 +3,7 @@ import type { MindSpaceChatContext } from '../types';
|
||||
export type AgentRunCreateOptions = {
|
||||
toolMode?: 'chat' | 'code';
|
||||
taskType?: string | null;
|
||||
forceGoose?: boolean;
|
||||
validation?: AgentRunValidation | null;
|
||||
validationInstruction?: string | null;
|
||||
};
|
||||
@@ -52,6 +53,16 @@ const CODE_TASK_PATTERNS = [
|
||||
/(代码|仓库|项目|文件|组件|接口).{0,12}(修改|修复|重构|调试|实现|新增|编写|更新)/,
|
||||
];
|
||||
|
||||
const GOOSE_TASK_PATTERNS = [
|
||||
/\b(public\/[^\s"'<>]+\.html)\b/i,
|
||||
/\b(html|h5|web\s?page|landing\s?page|microsite|docx|word)\b/i,
|
||||
/\b(write|create|generate|publish|download|export|save|edit)\b.{0,40}\b(file|page|html|docx|word|asset)\b/i,
|
||||
/\b(file|page|html|docx|word|asset)\b.{0,40}\b(write|create|generate|publish|download|export|save|edit)\b/i,
|
||||
/(?:生成|创建|制作|做|写|设计|发布|导出|下载|保存|修改|编辑).{0,24}(?:页面|网页|HTML|html|H5|h5|文件|文档|Word|word|docx|下载页|公开页|分享页|落地页|活动页)/u,
|
||||
/(?:页面|网页|HTML|html|H5|h5|文件|文档|Word|word|docx|下载页|公开页|分享页|落地页|活动页).{0,24}(?:生成|创建|制作|做|写|设计|发布|导出|下载|保存|修改|编辑)/u,
|
||||
/MindSpace\/[^/\s]+\/public\/[^\s"'<>]+\.html/i,
|
||||
];
|
||||
|
||||
function sanitizeRequestIdForPath(requestId: string): string {
|
||||
const normalized = String(requestId ?? '').trim().replace(/[^a-zA-Z0-9._-]/g, '-');
|
||||
return normalized || 'unknown-request';
|
||||
@@ -224,10 +235,18 @@ export function resolveAgentRunOptions(
|
||||
pageEdit?: { pageId?: string | null; pageTitle?: string | null } | null;
|
||||
} = {},
|
||||
): AgentRunCreateOptions {
|
||||
if (!agentCodeRunsEnabledForUser(userId)) return {};
|
||||
const normalizedText = String(text ?? '').trim();
|
||||
const shouldForceGoose =
|
||||
forceCode || GOOSE_TASK_PATTERNS.some((pattern) => pattern.test(normalizedText));
|
||||
|
||||
if (!agentCodeRunsEnabledForUser(userId)) {
|
||||
return shouldForceGoose ? { forceGoose: true, taskType } : {};
|
||||
}
|
||||
|
||||
const shouldUseCode = forceCode || (allowAutodetect && CODE_TASK_PATTERNS.some((pattern) => pattern.test(normalizedText)));
|
||||
if (!shouldUseCode) return {};
|
||||
if (!shouldUseCode) {
|
||||
return shouldForceGoose ? { forceGoose: true, taskType } : {};
|
||||
}
|
||||
const normalizedRequestId = requestId ?? crypto.randomUUID();
|
||||
const receipt = buildAgentRunValidationReceipt(normalizedRequestId);
|
||||
const taskValidation = buildAgentRunTaskValidation({
|
||||
@@ -240,6 +259,7 @@ export function resolveAgentRunOptions(
|
||||
return {
|
||||
toolMode: 'code',
|
||||
taskType,
|
||||
forceGoose: true,
|
||||
validation: mergeAgentRunValidationFiles(receipt.validation, taskValidation.validation),
|
||||
validationInstruction: `${receipt.instruction}${taskValidation.instruction}`,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user