chore: 项目基线(基于 WeKnora 定制版,整理文件忽略规则)
This commit is contained in:
commit
9097ee699d
5769 files changed
+1446466
No files matched your search
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Fork affordance rules, kept as a pure function so they can be tested without
|
||||
* mounting the chat view.
|
||||
*
|
||||
* The backend re-derives all of this; this is purely so the UI can show the
|
||||
* right button state without an extra round trip.
|
||||
*
|
||||
* User messages fork *at* the question (history excludes it, composer prefills
|
||||
* it). Assistant messages fork *after* the answer (history includes it).
|
||||
*/
|
||||
|
||||
export interface ForkCandidateMessage {
|
||||
id?: unknown
|
||||
role?: unknown
|
||||
is_completed?: unknown
|
||||
}
|
||||
|
||||
export interface ForkAffordance {
|
||||
/** Whether the fork button should be offered on this message at all. */
|
||||
canFork: boolean
|
||||
}
|
||||
|
||||
const REFUSED: ForkAffordance = { canFork: false }
|
||||
|
||||
export function resolveForkAffordance(
|
||||
messages: ForkCandidateMessage[],
|
||||
messageId: string,
|
||||
): ForkAffordance {
|
||||
const index = messages.findIndex((m) => m.id === messageId)
|
||||
if (index < 0) {
|
||||
return REFUSED
|
||||
}
|
||||
|
||||
// A turn still streaming means the source session holds an active sandbox
|
||||
// lease. The backend would answer 409, so do not offer the button.
|
||||
if (messages.some((m) => m.role === 'assistant' && m.is_completed === false)) {
|
||||
return REFUSED
|
||||
}
|
||||
|
||||
const target = messages[index]
|
||||
if (target.role === 'assistant' || target.role === 'user') {
|
||||
return { canFork: true }
|
||||
}
|
||||
return REFUSED
|
||||
}
|
||||
Reference in new issue
Block a user