31 lines
1.2 KiB
JavaScript
31 lines
1.2 KiB
JavaScript
import { seatBySessionId } from '../shared/roles.js'
|
||
|
||
export const PROMPT_SECTION = 'sansheng'
|
||
|
||
export function renderSeatPrompt({ project, seatId, seat }) {
|
||
const lines = [
|
||
`你在「${project?.name ?? project?.id ?? '当前项目'}」项目中担任${seat.label}(${seatId})。`,
|
||
`本席职责:${seat.responsibility}`,
|
||
]
|
||
const note = project?.seats?.[seatId]?.instructions
|
||
if (typeof note === 'string' && note.trim() !== '') lines.push(`补充说明:${note.trim()}`)
|
||
lines.push('只在本项目本席会话内工作;不要修改其他项目或其他席的配置,也不要替用户提升权限。')
|
||
return lines.join('\n')
|
||
}
|
||
|
||
// 注册动态 systemPrompt section:只对十席会话注入本席角色文本,其它会话返回空串。
|
||
export function installPromptSection(ctx, { store }) {
|
||
return ctx.systemPrompt.section({
|
||
name: PROMPT_SECTION,
|
||
order: 60,
|
||
interpolate: false,
|
||
text: context => {
|
||
const sessionId = context?.agent?.id
|
||
if (!sessionId) return ''
|
||
const found = seatBySessionId(store.state?.projects, sessionId)
|
||
if (!found) return ''
|
||
return renderSeatPrompt({ project: found.project, seatId: found.seatId, seat: found.seat })
|
||
},
|
||
})
|
||
}
|