dsh-better-chat/src/client/chat-seat.ts

32 lines
1.2 KiB
TypeScript

export type ChatSeatKind = 'user' | 'steering';
export function chatSeatProps(kind: ChatSeatKind, key: string): Record<string, string> {
return {
'data-chat-anchor-key': key,
'data-chat-flow-key': key,
'data-chat-node-key': key,
'data-chat-flow-kind': kind,
};
}
/**
* Official ChatView's row contract for one assistant answer part.
*
* `data-chat-flow-kind="assistant-step"` is the marker plugins such as
* dsh-btw rely on to recognise "this selection is part of a model answer";
* without it they walk up from the selection, find no message row, and bail.
* The flow key stays unique per rendered part so row lookups do not merge
* separate paragraphs. `data-chat-anchor-key` is deliberately absent: the
* reader performs its own rewind hiding (`rewind-cut.ts`) and publishing the
* official anchor on every part would let a DOM-level rewind plugin hide only
* part of a turn.
*/
export function answerRowAttrs(nodeKey: string, partStart: number, turn: number | undefined): Record<string, string> {
return {
'data-chat-flow-kind': 'assistant-step',
'data-chat-flow-key': `${nodeKey}#${partStart}`,
'data-chat-node-key': nodeKey,
...(turn === undefined ? {} : { 'data-chat-turn': String(turn) }),
};
}