fix(tui): declare clarify_batch so a multi-question clarify is one form
The gateway advertises clarify-batch-v1 and the Ink TUI declares clarify_batch on real prompts when the owner advertises it. Row TUI-29. Refs #143547 Co-authored-by: Khwan888 <148256154+Khwan888@users.noreply.github.com>
This commit is contained in:
committed by
Mark S.
parent
39661bb10b
commit
163a633265
@@ -498,7 +498,8 @@ class AuthorityConnection:
|
||||
from gateway.session_skin import resolved_skin
|
||||
return {'instance_id': self.authority.instance_id, 'profile_id': self.authority.profile_id,
|
||||
'authority_epoch': self.authority.epoch,
|
||||
'capabilities': ['durable-admission-v1', 'event-replay-v1', 'local-cli-create-v1', 'acp-editor-policy-v1', 'acp-session-mcp-v1'],
|
||||
'capabilities': ['durable-admission-v1', 'event-replay-v1', 'local-cli-create-v1', 'acp-editor-policy-v1',
|
||||
'acp-session-mcp-v1', 'clarify-batch-v1'],
|
||||
'session_create': {'sources': sorted(SURFACES),
|
||||
'parameters': sorted(CREATE_FIELDS | {'title'})},
|
||||
# Main's ``gateway.ready.skin``: the canonical client's own ready carries it.
|
||||
|
||||
@@ -29,3 +29,20 @@ async def test_runtime_describe_carries_the_profiles_resolved_skin(tmp_path, mon
|
||||
finally:
|
||||
await conn.close()
|
||||
authority.db.close()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_runtime_describe_advertises_clarify_batch(tmp_path, monkeypatch):
|
||||
"""Ink declares ``clarify_batch`` on its prompts only to an owner advertising ``clarify-batch-v1``:
|
||||
an older owner's closed ``prompt.submit`` params would refuse the key on every prompt."""
|
||||
authority, _store = await _authority(tmp_path, monkeypatch)
|
||||
monkeypatch.setenv('HERMES_HOME', authority.profile_id)
|
||||
conn = AuthorityConnection(authority, SimpleNamespace(write=lambda frame: None), {'user_id': 'owner'})
|
||||
try:
|
||||
described = await conn.dispatch({'id': 0, 'method': 'runtime.describe', 'params': {}})
|
||||
assert 'clarify-batch-v1' in described['result']['capabilities']
|
||||
from tui_gateway.contracts.registry import CANONICAL_METHODS
|
||||
assert 'clarify_batch' in CANONICAL_METHODS['prompt.submit'].params.model_fields
|
||||
finally:
|
||||
await conn.close()
|
||||
authority.db.close()
|
||||
|
||||
@@ -260,6 +260,39 @@ describe('submissionCore.submitPrompt — voice marker ownership', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('submissionCore.submitPrompt — clarify batch declaration', () => {
|
||||
beforeEach(() => {
|
||||
resetUiState()
|
||||
patchUiState({ sid: 'sess-1' })
|
||||
})
|
||||
|
||||
it('a prompt declares clarify_batch to an owner advertising it; a busy correction does not', async () => {
|
||||
const request = vi.fn(async (_method: string, _params: Record<string, unknown>) => ({ status: 'accepted' }))
|
||||
const gw = { clarifyBatch: true, isCanonical: true, request } as unknown as GatewayClient
|
||||
|
||||
submitPrompt('fix it', makeDeps(gw), true, undefined, {
|
||||
behindTurn: true,
|
||||
queueItem: { controlMethod: 'session.redirect', executionGeneration: 3, submissionId: 'c1', text: 'fix it' } as never
|
||||
})
|
||||
submitPrompt('ask me', makeDeps(gw))
|
||||
await vi.waitFor(() => expect(request.mock.calls.map(([method]) => method)).toEqual(['session.redirect', 'prompt.submit']))
|
||||
|
||||
expect(request.mock.calls[0]?.[1]).not.toHaveProperty('clarify_batch')
|
||||
expect(request.mock.calls[1]?.[1]).toMatchObject({ clarify_batch: true })
|
||||
})
|
||||
|
||||
it('an owner without clarify-batch-v1 never sees the key (its closed submit params would refuse it)', async () => {
|
||||
const request = vi.fn(async (_method: string, _params: Record<string, unknown>) => ({ status: 'accepted' }))
|
||||
const gw = { clarifyBatch: false, isCanonical: true, request } as unknown as GatewayClient
|
||||
|
||||
submitPrompt('ask me', makeDeps(gw))
|
||||
await vi.waitFor(() => expect(request).toHaveBeenCalledTimes(1))
|
||||
|
||||
expect(request.mock.calls[0]?.[0]).toBe('prompt.submit')
|
||||
expect(request.mock.calls[0]?.[1]).not.toHaveProperty('clarify_batch')
|
||||
})
|
||||
})
|
||||
|
||||
describe('submissionCore.submitPrompt — typed voice stop on the shared gateway (TUI-26)', () => {
|
||||
beforeEach(() => {
|
||||
resetUiState()
|
||||
|
||||
@@ -124,7 +124,8 @@ function submitParams(
|
||||
item: QueueItem | undefined,
|
||||
submitText: string,
|
||||
attachments: SubmitPromptOpts['attachments'],
|
||||
voice: boolean
|
||||
voice: boolean,
|
||||
clarifyBatch: boolean
|
||||
) {
|
||||
return {
|
||||
session_id: sid,
|
||||
@@ -133,7 +134,9 @@ function submitParams(
|
||||
...(item?.controlMethod ? { execution_generation: item.executionGeneration } : {}),
|
||||
...(item && !item.controlMethod ? { submission_id: item.submissionId, queued: item.queued !== false } : {}),
|
||||
// A busy correction (steer/redirect) is not a turn: it never claims the voice route.
|
||||
...(!item?.controlMethod && voice && { voice_turn: true })
|
||||
...(!item?.controlMethod && voice && { voice_turn: true }),
|
||||
// Ink renders a whole question set as one form; undeclared, the owner asks one card per question.
|
||||
...(!item?.controlMethod && clarifyBatch && { clarify_batch: true })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,7 +398,14 @@ export function submitPrompt(
|
||||
deps.gw
|
||||
.request<PromptSubmitResponse>(
|
||||
item?.controlMethod ?? 'prompt.submit',
|
||||
submitParams(sid, item, submitText, opts.attachments, voiceTranscript === submitText.trim())
|
||||
submitParams(
|
||||
sid,
|
||||
item,
|
||||
submitText,
|
||||
opts.attachments,
|
||||
voiceTranscript === submitText.trim(),
|
||||
deps.gw.clarifyBatch === true
|
||||
)
|
||||
)
|
||||
.then(r => {
|
||||
if (item?.controlMethod) {
|
||||
|
||||
@@ -155,6 +155,7 @@ export class GatewayClient extends EventEmitter {
|
||||
isCanonical = false
|
||||
private creationContract?: CreationContract
|
||||
private describedSkin?: Record<string, unknown>
|
||||
private runtimeCapabilities: string[] = []
|
||||
private describeFlight?: Promise<void>
|
||||
private attachHold: AttachHold | null = null
|
||||
// The last session.create whose outcome is in doubt (see createCanonical).
|
||||
@@ -745,6 +746,7 @@ export class GatewayClient extends EventEmitter {
|
||||
// Each explicit connection negotiates its wire from the listener's ready frame.
|
||||
this.isCanonical = false
|
||||
this.creationContract = undefined
|
||||
this.runtimeCapabilities = []
|
||||
this.startAttachedGateway(attachUrl)
|
||||
|
||||
return
|
||||
@@ -852,13 +854,22 @@ export class GatewayClient extends EventEmitter {
|
||||
|
||||
private notConnected = (method: string) => new Error(`gateway not connected: ${method}`)
|
||||
|
||||
/** Only an owner advertising `clarify-batch-v1` knows `clarify_batch`: an older owner's
|
||||
* closed submit params would refuse every prompt carrying it. */
|
||||
get clarifyBatch(): boolean {
|
||||
return this.isCanonical && this.runtimeCapabilities.includes('clarify-batch-v1')
|
||||
}
|
||||
|
||||
/** The owner's session.create contract. A failed read is not cached: the next
|
||||
* session.create asks again instead of reporting an outdated gateway forever. */
|
||||
private describeRuntime(): Promise<void> {
|
||||
if (!this.describeFlight) {
|
||||
const flight: Promise<void> = this.requestOverWebSocket<{ session_create: CreationContract; skin?: Record<string, unknown> | null }>('runtime.describe').then(
|
||||
const flight: Promise<void> = this.requestOverWebSocket<{ capabilities?: unknown; session_create: CreationContract; skin?: Record<string, unknown> | null }>('runtime.describe').then(
|
||||
description => {
|
||||
this.creationContract = description.session_create
|
||||
this.runtimeCapabilities = Array.isArray(description.capabilities)
|
||||
? description.capabilities.filter((c): c is string => typeof c === 'string')
|
||||
: []
|
||||
this.describedSkin = description.skin && typeof description.skin === 'object' ? description.skin : undefined
|
||||
},
|
||||
error => {
|
||||
|
||||
Reference in New Issue
Block a user