feat: migrate runtime backend to node server
This commit is contained in:
@@ -4,6 +4,7 @@ import type {
|
||||
RuntimeItemGenerationContext,
|
||||
RuntimeItemPlan,
|
||||
} from '../types';
|
||||
import { requestJson } from './apiClient';
|
||||
import {requestChatMessageContent} from './llmClient';
|
||||
import {parseJsonResponseText} from './llmParsers';
|
||||
import {
|
||||
@@ -88,6 +89,28 @@ export async function generateRuntimeItemAiIntents(params: {
|
||||
buildRuntimeItemAiIntent(params.context, plan),
|
||||
);
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
try {
|
||||
const response = await requestJson<{
|
||||
intents?: unknown[];
|
||||
}>(
|
||||
'/api/runtime/items/runtime-intent',
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(params),
|
||||
},
|
||||
'运行时物品意图生成失败',
|
||||
);
|
||||
const rawIntents = Array.isArray(response.intents) ? response.intents : [];
|
||||
return params.plans.map((_, index) =>
|
||||
sanitizeRuntimeItemAiIntent(rawIntents[index], fallbackIntents[index]!),
|
||||
);
|
||||
} catch (error) {
|
||||
console.warn('[runtimeItemAiDirector] backend intent generation failed, falling back', error);
|
||||
}
|
||||
}
|
||||
|
||||
const content = await requestChatMessageContent(
|
||||
RUNTIME_ITEM_INTENT_SYSTEM_PROMPT,
|
||||
buildRuntimeItemIntentPrompt(params),
|
||||
|
||||
Reference in New Issue
Block a user