asdf
Squash the current repository state back into one baseline commit while preserving the README reframing and repository contents. Constraint: User explicitly requested a single squashed commit with subject "asdf" Confidence: high Scope-risk: broad Reversibility: clean Directive: This commit intentionally rewrites published history; coordinate before future force-pushes Tested: git status clean; local history rewritten to one commit; force-pushed main to origin and instructkr Not-tested: Fresh clone verification after push
This commit is contained in:
commit
d2542c9a62
46
src/hooks/useDeferredHookMessages.ts
Normal file
46
src/hooks/useDeferredHookMessages.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { useCallback, useEffect, useRef } from 'react'
|
||||
import type { HookResultMessage, Message } from '../types/message.js'
|
||||
|
||||
/**
|
||||
* Manages deferred SessionStart hook messages so the REPL can render
|
||||
* immediately instead of blocking on hook execution (~500ms).
|
||||
*
|
||||
* Hook messages are injected asynchronously when the promise resolves.
|
||||
* Returns a callback that onSubmit should call before the first API
|
||||
* request to ensure the model always sees hook context.
|
||||
*/
|
||||
export function useDeferredHookMessages(
|
||||
pendingHookMessages: Promise<HookResultMessage[]> | undefined,
|
||||
setMessages: (action: React.SetStateAction<Message[]>) => void,
|
||||
): () => Promise<void> {
|
||||
const pendingRef = useRef(pendingHookMessages ?? null)
|
||||
const resolvedRef = useRef(!pendingHookMessages)
|
||||
|
||||
useEffect(() => {
|
||||
const promise = pendingRef.current
|
||||
if (!promise) return
|
||||
let cancelled = false
|
||||
promise.then(msgs => {
|
||||
if (cancelled) return
|
||||
resolvedRef.current = true
|
||||
pendingRef.current = null
|
||||
if (msgs.length > 0) {
|
||||
setMessages(prev => [...msgs, ...prev])
|
||||
}
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [setMessages])
|
||||
|
||||
return useCallback(async () => {
|
||||
if (resolvedRef.current || !pendingRef.current) return
|
||||
const msgs = await pendingRef.current
|
||||
if (resolvedRef.current) return
|
||||
resolvedRef.current = true
|
||||
pendingRef.current = null
|
||||
if (msgs.length > 0) {
|
||||
setMessages(prev => [...msgs, ...prev])
|
||||
}
|
||||
}, [setMessages])
|
||||
}
|
||||
Reference in New Issue
Block a user