fix(hub): 稳定 Feishu trigger 集成测试

This commit is contained in:
2026-07-08 15:13:50 +08:00
parent ecbc2c8666
commit ead5cf04d6
5 changed files with 167 additions and 28 deletions
+22
View File
@@ -119,6 +119,8 @@ export async function runAgent(req: RunRequest): Promise<RunResult> {
let sdkSessionId: string | undefined;
let error: string | undefined;
try {
await persistAgentMessage(req, "user", req.prompt);
const options: Parameters<typeof query>[0]["options"] = {
cwd: req.project.workspaceDir,
allowedTools: ["Read", "Write", "Bash", "Glob", "Grep"],
@@ -174,14 +176,17 @@ export async function runAgent(req: RunRequest): Promise<RunResult> {
const msg = (message as SDKAssistantMessage).message;
await heartbeat();
numTurns++;
let assistantText = "";
for (const block of msg.content) {
if (block.type === "text" && typeof block.text === "string") {
fullText += block.text;
assistantText += block.text;
}
if (block.type === "tool_use") {
onStream?.({ type: "tool-end", toolName: block.name });
}
}
await persistAgentMessage(req, "assistant", assistantText);
if (msg.usage !== undefined) {
usage.inputTokens += msg.usage.input_tokens ?? 0;
usage.outputTokens += msg.usage.output_tokens ?? 0;
@@ -219,3 +224,20 @@ export async function runAgent(req: RunRequest): Promise<RunResult> {
};
}
}
async function persistAgentMessage(req: RunRequest, role: string, content: string): Promise<void> {
if (content === "") return;
try {
await req.prisma.agentMessage.create({
data: {
sessionId: req.sessionId,
runId: req.runId,
role,
content,
attachments: [],
},
});
} catch {
// Best-effort projection: a history write failure must not break the run.
}
}