fix(web): apply review round — notice anchors before turn-tail, published node kind, fixture nextTurn

Anchor the max-tokens notice between the closing assistant and the
turn-tail so the tail stays the turn's last chat node and its branch
action survives; forward the ChatNodeDataMap augmentation through the
client entry so built declarations publish the new kind; advance the
fixture's nextTurn past the appended history; drop the engine-unreachable
buildViewNode fallback; deduplicate the runtime README tail sentence.
This commit is contained in:
creatixchu
2026-08-12 16:04:03 +08:00
parent e4ca03cb85
commit 941449d92c
8 changed files with 32 additions and 13 deletions

View File

@@ -7,11 +7,14 @@ import type {
/**
* Relative positions in one durable event's seq neighborhood: interrupted
* Assistant, its follow-up Nodes, then follow-ups to an ordinary final.
* Assistant, its follow-up Nodes, then follow-ups to an ordinary final. The
* max-tokens notice sits between a closing Assistant and the turn-tail so the
* tail stays the turn's last node and keeps its branch action enabled.
*/
export const CHAT_SYNTHETIC_SEQ_OFFSETS = {
interruptedAssistant: -0.9,
interruptedFollowup: -0.8,
maxTokensNotice: 0.05,
finalizedFollowup: 0.1,
} as const

View File

@@ -2,7 +2,7 @@ import type { Context } from '@deepseek-ai/cordis'
import type {
ConversationMatch, ConversationNodeContext, ConversationNodeDefinition, TurnMaxTokensNode,
} from '@deepseek-ai/dsh-client-runtime/client'
import { chatNode } from './common.ts'
import { CHAT_SYNTHETIC_SEQ_OFFSETS, chatNode } from './common.ts'
declare module '@deepseek-ai/dsh-client-ui-conversation/client' {
interface ChatNodeDataMap {
@@ -23,6 +23,21 @@ function lastStep(context: ConversationNodeContext<TurnMaxTokensState>): number
return location.turn.steps.at(-1)?.step ?? 0
}
/**
* Anchor the notice between the closing Assistant and the turn-tail so the
* tail stays the turn's last Chat node and keeps its branch action enabled.
* Without a closing text Assistant there is no branch action to protect, and
* the turn/end seq keeps the notice at the truncation point.
*/
function noticeAnchor(context: ConversationNodeContext<TurnMaxTokensState>, seq: number): number {
const location = context.start?.location ?? context.matches[0]?.location
if (location?.kind !== 'turn' && location?.kind !== 'step') return seq
const closing = location.turn.data.get('turn-tail')?.closing
return closing === null || closing === undefined
? seq
: closing.finalNode.seq + CHAT_SYNTHETIC_SEQ_OFFSETS.maxTokensNotice
}
function stateFrom(match: ConversationMatch): TurnMaxTokensState | undefined {
if (match.event.type !== 'turn/end' || match.event.data.reason.kind !== 'max-tokens') return undefined
return { turn: match.event.data.turn, seq: match.event.seq, time: match.event.time }
@@ -46,7 +61,6 @@ export const turnMaxTokensDefinition: ConversationNodeDefinition<TurnMaxTokensSt
update: context => context.state,
buildViewNode: (context) => {
const state = context.state
?? context.matches.map(stateFrom).find(candidate => candidate !== undefined)
if (state === undefined) return null
const node: TurnMaxTokensNode = {
kind: 'turn-max-tokens',
@@ -55,7 +69,7 @@ export const turnMaxTokensDefinition: ConversationNodeDefinition<TurnMaxTokensSt
turn: state.turn,
step: lastStep(context),
}
return chatNode(context, 'turn-max-tokens', node.seq, node)
return chatNode(context, 'turn-max-tokens', noticeAnchor(context, state.seq), node)
},
}

View File

@@ -11,6 +11,7 @@ export type {} from './conversation-nodes/message.ts'
export type {} from './conversation-nodes/retry.ts'
export type {} from './conversation-nodes/tool.ts'
export type {} from './conversation-nodes/turn-error.ts'
export type {} from './conversation-nodes/turn-max-tokens.ts'
export type {} from './conversation-nodes/turn-tail.ts'
export { apply, inject } from './apply.ts'