mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
feat(pi): complete RPC parity, native steer, and history controls (#1353)
* feat(pi): complete RPC interaction parity * feat(pi): integrate native conversation history * fix(pi): harden RPC lifecycle boundaries * fix(pi): address review lifecycle and upload boundaries * fix(pi): release history transaction on rollback deadline * fix(pi): isolate preflight and timed-out mutations * fix(pi): preserve retry and editor boundaries * fix(pi): disable unavailable history synchronization * fix(pi): gate fallback readiness on history baseline * fix(pi): bind uploads and retire extension requests * fix(pi): preserve canceled and legacy stream boundaries * fix(pi): preserve native fork runtime state * fix(pi): persist dialogs and preserve select values * fix(pi): keep upload authorization path-stable * feat(pi): preserve native steer semantics Route ordinary sends during an active Pi main turn through native steer while keeping explicit queue delivery on the existing composer gestures. Persist the delivery contract across Hub replay and Web retries, and guard stale steer dispatch with streaming generations and ordered prompt fallback. * fix(pi): queue deferred steer deliveries Keep native steer only for the initial live emit. Reconnect replay, CLI backfill, clear-gate release, and mature delivery now downgrade turn-scoped steer intent to the durable HAPI queue without mutating stored provenance. * fix(pi): retain abort guard through preflight miss Treat an immediate no-active abort rejection as a possible async-preflight race. Keep the existing abort boundary alive so a late agent_start receives the compensating abort before queued work is released. * fix(pi): queue stale steer retries A failed send no longer reuses turn-scoped steer intent after its original Pi generation is lost. Text restoration, attachment retry, and legacy retry provenance all enter the durable HAPI queue while fresh ordinary sends retain native steer behavior. * fix(pi): invalidate rejected abort generation After a no-active preflight abort waits through late-start compensation, mark the target stream idle while the runtime mutation lease is still held. Waiting native steers therefore fall back instead of entering the aborted generation. * fix(pi): queue idempotent steer retries Track whether a localId insert created a new row. Initial inserts may retain live Pi steer, while duplicate-localId retries deliver a queue-safe view of the stored row without overwriting its original provenance. * fix(pi): sync command-only history before fallback Read the Pi append log before retiring a successful prompt that produced no agent lifecycle. Preserve FIFO history associations across missing entry events, and fail the wrapper closed if that mandatory synchronization cannot be completed.
This commit is contained in:
@@ -4,6 +4,7 @@ import { useRef, useState } from 'react'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { I18nProvider } from '@/lib/i18n-context'
|
||||
import type { PendingSchedule } from '@/components/AssistantChat/ScheduleTimePicker'
|
||||
import type { ComposerSendIntent } from '@/lib/messageDelivery'
|
||||
import { HappyComposer, type ComposerSendError } from './HappyComposer'
|
||||
|
||||
/**
|
||||
@@ -28,6 +29,8 @@ const runtime = vi.hoisted(() => ({
|
||||
thread: { isRunning: false, isDisabled: false },
|
||||
} as FakeRuntimeState,
|
||||
setSnapshot: null as null | ((updater: (current: FakeRuntimeState) => FakeRuntimeState) => void),
|
||||
pendingSendIntentRef: null as null | { current: ComposerSendIntent },
|
||||
sentIntents: [] as ComposerSendIntent[],
|
||||
}))
|
||||
|
||||
vi.mock('@assistant-ui/react', async () => {
|
||||
@@ -42,6 +45,9 @@ vi.mock('@assistant-ui/react', async () => {
|
||||
}))
|
||||
},
|
||||
send: () => {
|
||||
const intent = runtime.pendingSendIntentRef?.current ?? 'default'
|
||||
runtime.sentIntents.push(intent)
|
||||
if (runtime.pendingSendIntentRef) runtime.pendingSendIntentRef.current = 'default'
|
||||
runtime.setSnapshot!((current) => ({
|
||||
...current,
|
||||
composer: { text: '', attachments: [] },
|
||||
@@ -117,18 +123,25 @@ type HarnessControls = {
|
||||
getClearErrorCalls: () => number
|
||||
}
|
||||
|
||||
function ComposerHarness(props: { initialText: string; initialSchedule?: PendingSchedule | null; controls: { current: HarnessControls | null } }) {
|
||||
function ComposerHarness(props: {
|
||||
initialText: string
|
||||
initialSchedule?: PendingSchedule | null
|
||||
piRunning?: boolean
|
||||
controls: { current: HarnessControls | null }
|
||||
}) {
|
||||
const [snapshot, setSnapshot] = useState<FakeRuntimeState>(() => ({
|
||||
composer: { text: props.initialText, attachments: [] },
|
||||
thread: { isRunning: false, isDisabled: false },
|
||||
thread: { isRunning: props.piRunning ?? false, isDisabled: false },
|
||||
}))
|
||||
const [schedule, setSchedule] = useState<PendingSchedule | null>(props.initialSchedule ?? null)
|
||||
const [sendError, setSendError] = useState<ComposerSendError | null>(null)
|
||||
const [composerKey, setComposerKey] = useState('composer-a')
|
||||
const clearErrorCallsRef = useRef(0)
|
||||
const pendingSendIntentRef = useRef<ComposerSendIntent>('default')
|
||||
|
||||
runtime.snapshot = snapshot
|
||||
runtime.setSnapshot = setSnapshot
|
||||
runtime.pendingSendIntentRef = pendingSendIntentRef
|
||||
props.controls.current = {
|
||||
setError: sendError => setSendError(sendError),
|
||||
addAttachment: () => setSnapshot((current) => ({
|
||||
@@ -169,14 +182,22 @@ function ComposerHarness(props: { initialText: string; initialSchedule?: Pending
|
||||
? { ...current, restoreSuppressed: true }
|
||||
: current
|
||||
)}
|
||||
agentFlavor="pi"
|
||||
thinking={props.piRunning}
|
||||
pendingSendIntentRef={pendingSendIntentRef}
|
||||
/>
|
||||
</I18nProvider>
|
||||
)
|
||||
}
|
||||
|
||||
function renderComposer(initialText = 'failed text', initialSchedule: PendingSchedule | null = { type: 'absolute', ms: 1234 }) {
|
||||
function renderComposer(
|
||||
initialText = 'failed text',
|
||||
initialSchedule: PendingSchedule | null = { type: 'absolute', ms: 1234 },
|
||||
piRunning = false,
|
||||
) {
|
||||
const controls: { current: HarnessControls | null } = { current: null }
|
||||
render(<ComposerHarness initialText={initialText} initialSchedule={initialSchedule} controls={controls} />)
|
||||
runtime.sentIntents = []
|
||||
render(<ComposerHarness initialText={initialText} initialSchedule={initialSchedule} piRunning={piRunning} controls={controls} />)
|
||||
return controls
|
||||
}
|
||||
|
||||
@@ -411,3 +432,52 @@ describe('HappyComposer send-error atomic restore', () => {
|
||||
expect(screen.getByTestId('pending-schedule')).toHaveTextContent('null')
|
||||
})
|
||||
})
|
||||
|
||||
describe('HappyComposer send intent gestures', () => {
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
runtime.pendingSendIntentRef = null
|
||||
runtime.sentIntents = []
|
||||
})
|
||||
|
||||
it('uses queue for Alt/Option+Enter only while the Pi main thread is running', () => {
|
||||
renderComposer('follow-up', null, true)
|
||||
|
||||
fireEvent.keyDown(input(), { key: 'Enter', altKey: true })
|
||||
|
||||
expect(runtime.sentIntents).toEqual(['queue'])
|
||||
expect(runtime.pendingSendIntentRef?.current).toBe('default')
|
||||
})
|
||||
|
||||
it('uses default intent for the configured normal Enter send', () => {
|
||||
renderComposer('ordinary send', null, true)
|
||||
|
||||
fireEvent.keyDown(input(), { key: 'Enter' })
|
||||
|
||||
expect(runtime.sentIntents).toEqual(['default'])
|
||||
expect(runtime.pendingSendIntentRef?.current).toBe('default')
|
||||
})
|
||||
|
||||
it('consumes a restored queue retry mark before resetting the shared ref', () => {
|
||||
renderComposer('retry queue', null, true)
|
||||
runtime.pendingSendIntentRef!.current = 'queue'
|
||||
|
||||
fireEvent.keyDown(input(), { key: 'Enter' })
|
||||
|
||||
expect(runtime.sentIntents).toEqual(['queue'])
|
||||
expect(runtime.pendingSendIntentRef?.current).toBe('default')
|
||||
})
|
||||
|
||||
it('does not turn Alt/Option+Enter into queue when Pi is idle or a schedule is active', () => {
|
||||
const idle = renderComposer('idle', null, false)
|
||||
fireEvent.keyDown(input(), { key: 'Enter', altKey: true })
|
||||
expect(runtime.sentIntents).toEqual([])
|
||||
expect(idle.current).not.toBeNull()
|
||||
|
||||
cleanup()
|
||||
renderComposer('scheduled', { type: 'absolute', ms: 1234 }, true)
|
||||
fireEvent.keyDown(input(), { key: 'Enter', altKey: true })
|
||||
expect(runtime.sentIntents).toEqual([])
|
||||
expect(runtime.pendingSendIntentRef?.current).toBe('default')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user