feat: 前端增加行内测试功能(场景绑定+接口工作流)

- 场景绑定表和接口工作流表操作列增加「测试」按钮
- 新增接口工作流测试对话框(流式+非流式)
- API 层提取 fetchSseStream 共享辅助函数
- 新增 testEndpointRuntime 和 streamEndpointRuntime

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-23 14:17:41 +08:00
parent cccb720060
commit c8f22bb157
3 changed files with 192 additions and 11 deletions
+28 -8
View File
@@ -1,12 +1,13 @@
import request from '@/utils/request'
import type {
AiConfigPageRequest,
AiConfigCreateRequest,
import type {
AiConfigPageRequest,
AiConfigCreateRequest,
AiConfigUpdateRequest,
AiProvider,
AiEndpointConfig,
AiSceneBinding,
AiRuntimeRequest
AiRuntimeRequest,
AiEndpointRuntimeRequest
} from '@/types/aiconfig'
// 分页查询AI配置
@@ -287,18 +288,19 @@ function parseSseFrame(frame: string): AiRuntimeStreamEvent | null {
}
}
export async function streamAiRuntime(
data: AiRuntimeRequest,
async function fetchSseStream(
url: string,
body: Record<string, any>,
onEvent: (event: AiRuntimeStreamEvent, output: string) => void
) {
const token = localStorage.getItem('adminToken')
const response = await fetch(`${import.meta.env.VITE_APP_BASE_API}/ai/runtime/stream`, {
const response = await fetch(`${import.meta.env.VITE_APP_BASE_API}${url}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...(token ? { Authorization: `Bearer ${token}` } : {})
},
body: JSON.stringify(data)
body: JSON.stringify(body)
})
if (!response.ok || !response.body) {
throw new Error(`流式测试请求失败(${response.status})`)
@@ -335,3 +337,21 @@ export async function streamAiRuntime(
if (buffer.trim()) consumeText('\n\n')
return output
}
export async function streamAiRuntime(
data: AiRuntimeRequest,
onEvent: (event: AiRuntimeStreamEvent, output: string) => void
) {
return fetchSseStream('/ai/runtime/stream', data, onEvent)
}
export async function streamEndpointRuntime(
data: AiEndpointRuntimeRequest,
onEvent: (event: AiRuntimeStreamEvent, output: string) => void
) {
return fetchSseStream('/ai/endpoint/stream', data, onEvent)
}
export function testEndpointRuntime(data: AiEndpointRuntimeRequest) {
return request({ url: '/ai/endpoint/test', method: 'post', data, timeout: 60000 })
}