forked from EduCraft/curriculum-project-hub
fix(hub): 稳定 Feishu trigger 集成测试
This commit is contained in:
@@ -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.
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user