fix(chat): satisfy hook documentation and lint contracts

This commit is contained in:
imccyu committed 2026-09-23 19:48:45 +08:00
1 parent 5a32aae571
commit 6943f9fee6
4 files changed
+11 -8

No files matched your search

@@ -25,9 +25,9 @@ export const TurnProcessNodeView = memo(function TurnProcessNodeView({
}, [ticking])
if (turn?.start === undefined && turn?.status !== 'closed') return null
const canCollapse = turnProcess.foldable && turnProcess.hasContent && !turnProcessAlwaysOpen(node)
const running = turn?.status === 'open'
const reason = turn?.end?.data.reason.kind
const elapsedMs = turn?.start === undefined ? undefined
const running = turn.status === 'open'
const reason = turn.end?.data.reason.kind
const elapsedMs = turn.start === undefined ? undefined
: Math.max(1000, (turn.end?.time ?? now) - turn.start.time)
const duration = elapsedMs === undefined ? undefined
: running ? formatLiveRunDuration(elapsedMs, t) : formatRunDuration(elapsedMs, t)
+2 -1
View File
@@ -9,7 +9,8 @@ import { TRANSCRIPT_VIEW_FIELD } from './chat-settings.ts'
import { ChatSettingsFields } from './chat-settings.ts'
export {
CHAT_SETTINGS_NAMESPACE, DEFAULT_TRANSCRIPT_VIEW_MODE, LEGACY_TRANSCRIPT_VIEW_MODE, LEGACY_EXPANDED_TRANSCRIPT_VIEW_MODE, TRANSCRIPT_VIEW_FIELD,
CHAT_SETTINGS_NAMESPACE, DEFAULT_TRANSCRIPT_VIEW_MODE, LEGACY_TRANSCRIPT_VIEW_MODE,
LEGACY_EXPANDED_TRANSCRIPT_VIEW_MODE, TRANSCRIPT_VIEW_FIELD,
TRANSCRIPT_VIEW_MODES, type ChatSettings, type TranscriptViewMode,
} from './chat-settings.ts'
@@ -11,13 +11,15 @@ const subscribeEmpty = (): (() => void) => () => {}
* @returns a Hook that reads only this call's raw argument prefix.
*/
export const bindToolCallArgumentsPartial: ToolCallInjected['hooks']['toolCallArgumentsPartial'] = (
_standard, { assistant, callId },
_standard, context,
) => {
const { assistant, callId } = context
const subscribe = assistant === undefined ? subscribeEmpty : (listener: () => void) => assistant.subscribe(listener)
const getSnapshot = (): string => {
const block = assistant?.getSnapshot()?.blocks.find(candidate => candidate.kind === 'tool-call' && candidate.callId === callId)
return block?.kind === 'tool-call' ? block.argsRaw : ''
}
return function useToolCallArgumentsPartial() {
return useSyncExternalStore(assistant?.subscribe ?? subscribeEmpty, getSnapshot)
return useSyncExternalStore(subscribe, getSnapshot)
}
}
@@ -28,9 +28,9 @@ function source(initial: AssistantChatData | undefined) {
const store = createSnapshotStore<AssistantChatData | undefined>(initial)
const listeners = new Set<() => void>()
return {
set: store.set,
set: (value: AssistantChatData | undefined) => { store.set(value) },
listeners,
getSnapshot: store.getSnapshot,
getSnapshot: () => store.getSnapshot(),
subscribe: (listener: () => void) => {
listeners.add(listener)
const dispose = store.subscribe(listener)