forked from EduCraft/curriculum-project-hub
fix: bind agent sessions to role
This commit is contained in:
@@ -180,23 +180,26 @@ export function makeTriggerHandler(deps: TriggerDeps): TriggerHandler {
|
||||
});
|
||||
const promptForAgent = withFeishuTriggerContext(agentPrompt, feishuTriggerContext);
|
||||
|
||||
// ADR-0017: provider+model-bound session. Reuse if one exists for this
|
||||
// (project, provider, model) triple; otherwise create.
|
||||
// ADR-0017: provider+role+model-bound session. Reuse if one exists for
|
||||
// this (project, provider, role, model) tuple; otherwise create. Role is
|
||||
// part of the key because role prompts/tool surfaces can differ even when
|
||||
// the underlying model is the same.
|
||||
const existingSession = await deps.prisma.agentSession.findFirst({
|
||||
where: { projectId, provider: providerId, model, archivedAt: null },
|
||||
where: { projectId, provider: providerId, roleId, model, archivedAt: null },
|
||||
select: { id: true, metadata: true },
|
||||
});
|
||||
const session =
|
||||
existingSession !== null
|
||||
? await deps.prisma.agentSession.update({
|
||||
where: { id: existingSession.id },
|
||||
data: { provider: providerId, model, updatedAt: new Date() },
|
||||
data: { provider: providerId, roleId, model, updatedAt: new Date() },
|
||||
select: { id: true, metadata: true },
|
||||
})
|
||||
: await deps.prisma.agentSession.create({
|
||||
data: {
|
||||
projectId,
|
||||
provider: providerId,
|
||||
roleId,
|
||||
model,
|
||||
title: agentPrompt.slice(0, 40) || null,
|
||||
metadata: {},
|
||||
|
||||
Reference in New Issue
Block a user