feat: add gated h5 code run entry
This commit is contained in:
@@ -19,6 +19,11 @@ H5_PUBLIC_BASE_URL=http://127.0.0.1:5173
|
||||
# MEMIND_RUNTIME_REDIS_URL=redis://127.0.0.1:6379/0
|
||||
# MEMIND_RUNTIME_REDIS_NAMESPACE=memind:runtime
|
||||
|
||||
# Code-tool agent run 灰度开关(默认关闭)。
|
||||
# 开启后,页面编辑子聊天会传 tool_mode=code;普通聊天仍需同时开启 AUTODETECT 才会按文本自动识别代码任务。
|
||||
# VITE_AGENT_CODE_RUNS_ENABLED=0
|
||||
# VITE_AGENT_CODE_RUNS_AUTODETECT=0
|
||||
|
||||
# ===== memind_adm(独立后台服务)=====
|
||||
# 平台超管 /admin-api/* 与广场运营 /api/ops/v1/* 已从公网服务拆出,独立进程运行。
|
||||
# 登录仍在主域完成;后台凭 H5_COOKIE_DOMAIN=.tkmind.cn 共享的会话 Cookie 鉴权(生产务必设置)。
|
||||
|
||||
@@ -58,6 +58,7 @@ import type {
|
||||
} from '../types';
|
||||
import { CHAT_IMAGE_UPLOAD_MAX_INPUT_BYTES } from '../utils/imageUpload';
|
||||
import { normalizeConversationMessages, normalizeUserMessageForApi } from '../utils/message';
|
||||
import type { AgentRunCreateOptions } from '../utils/agentRunMode';
|
||||
|
||||
const API = '/api';
|
||||
const DEFAULT_API_TIMEOUT_MS = 20_000;
|
||||
@@ -2247,6 +2248,7 @@ export async function createAgentRun(
|
||||
sessionId: string | null,
|
||||
requestId: string,
|
||||
userMessage: Message,
|
||||
options: AgentRunCreateOptions = {},
|
||||
): Promise<AgentRun> {
|
||||
const result = await apiFetch<{ run: AgentRun }>(
|
||||
AGENT_RUNS_PATH,
|
||||
@@ -2256,6 +2258,8 @@ export async function createAgentRun(
|
||||
session_id: sessionId,
|
||||
request_id: requestId,
|
||||
user_message: normalizeUserMessageForApi(userMessage),
|
||||
...(options.toolMode ? { tool_mode: options.toolMode } : {}),
|
||||
...(options.taskType ? { task_type: options.taskType } : {}),
|
||||
}),
|
||||
},
|
||||
{ timeoutMs: AGENT_CONNECT_TIMEOUT_MS },
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
CHAT_IMAGE_UPLOAD_MAX_INPUT_BYTES,
|
||||
} from '../utils/imageUpload';
|
||||
import { buildAbsoluteAssetImageUrl } from '../utils/mindspaceCards';
|
||||
import { resolveAgentRunOptions } from '../utils/agentRunMode';
|
||||
import {
|
||||
buildUserMessage,
|
||||
normalizeConversationMessages,
|
||||
@@ -339,7 +340,15 @@ export function usePageEditSubChat({
|
||||
setPendingTool(null);
|
||||
|
||||
try {
|
||||
const createdRun = await createAgentRun(currentSession.id, requestId, userMessage);
|
||||
const createdRun = await createAgentRun(
|
||||
currentSession.id,
|
||||
requestId,
|
||||
userMessage,
|
||||
resolveAgentRunOptions(trimmed, {
|
||||
taskType: 'page_edit_code_task',
|
||||
forceCode: true,
|
||||
}),
|
||||
);
|
||||
const finishedRun =
|
||||
createdRun.status === 'succeeded' ? createdRun : await waitForAgentRun(createdRun.id);
|
||||
if (!finishedRun.sessionId) {
|
||||
|
||||
@@ -50,6 +50,7 @@ import {
|
||||
CHAT_IMAGE_UPLOAD_MAX_INPUT_BYTES,
|
||||
} from '../utils/imageUpload';
|
||||
import { buildAbsoluteAssetImageUrl } from '../utils/mindspaceCards';
|
||||
import { resolveAgentRunOptions } from '../utils/agentRunMode';
|
||||
import {
|
||||
buildUserMessage,
|
||||
normalizeConversationMessages,
|
||||
@@ -1168,7 +1169,12 @@ export function useTKMindChat(
|
||||
}
|
||||
|
||||
try {
|
||||
const createdRun = await createAgentRun(activeSessionId, requestId, userMessage);
|
||||
const createdRun = await createAgentRun(
|
||||
activeSessionId,
|
||||
requestId,
|
||||
userMessage,
|
||||
resolveAgentRunOptions(trimmed, { taskType: 'h5_chat_code_task' }),
|
||||
);
|
||||
const finishedRun =
|
||||
createdRun.status === 'succeeded' ? createdRun : await waitForAgentRun(createdRun.id);
|
||||
activeSessionId = finishedRun.sessionId;
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
Vendored
+2
@@ -7,6 +7,8 @@ interface ImportMetaEnv {
|
||||
readonly VITE_TKMIND_MEMORY_QUERY: string;
|
||||
readonly VITE_PLAZA_BASE?: string;
|
||||
readonly VITE_MINDSPACE_BASE?: string;
|
||||
readonly VITE_AGENT_CODE_RUNS_ENABLED?: string;
|
||||
readonly VITE_AGENT_CODE_RUNS_AUTODETECT?: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
|
||||
Reference in New Issue
Block a user