feat: add gated h5 code run entry

This commit is contained in:
John
2026-07-02 07:19:26 +08:00
parent 0271d83756
commit ac20ac212e
6 changed files with 72 additions and 2 deletions
+44
View File
@@ -0,0 +1,44 @@
export type AgentRunCreateOptions = {
toolMode?: 'chat' | 'code';
taskType?: string | null;
};
function envFlag(value: unknown): boolean {
const normalized = String(value ?? '').trim().toLowerCase();
return ['1', 'true', 'yes', 'on'].includes(normalized);
}
export const agentCodeRunsEnabled = envFlag(import.meta.env.VITE_AGENT_CODE_RUNS_ENABLED);
export const agentCodeRunsAutodetectEnabled = envFlag(
import.meta.env.VITE_AGENT_CODE_RUNS_AUTODETECT,
);
const CODE_TASK_PATTERNS = [
/\b(repo|repository|branch|commit|pull request|pr|diff|patch)\b/i,
/\b(aider|openhands|codex|codebase|workspace)\b/i,
/\b(refactor|debug|fix bug|implement|add test|unit test)\b/i,
/(修改|修复|重构|调试|实现|新增|编写|更新).{0,12}(代码|仓库|分支|文件|测试|组件|接口)/,
/(代码|仓库|项目|文件|组件|接口).{0,12}(修改|修复|重构|调试|实现|新增|编写|更新)/,
];
export function resolveAgentRunOptions(
text: string,
{
taskType = 'code_task',
forceCode = false,
allowAutodetect = agentCodeRunsAutodetectEnabled,
}: {
taskType?: string;
forceCode?: boolean;
allowAutodetect?: boolean;
} = {},
): AgentRunCreateOptions {
if (!agentCodeRunsEnabled) return {};
const normalizedText = String(text ?? '').trim();
const shouldUseCode = forceCode || (allowAutodetect && CODE_TASK_PATTERNS.some((pattern) => pattern.test(normalizedText)));
if (!shouldUseCode) return {};
return {
toolMode: 'code',
taskType,
};
}