mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
Keep widened-clear sends going and read typed image mentions correctly
Review follow-up. Refusing a send when text survives the widened clear dropped non-Claude sends without a notice and would refuse clears that landed but redrew slowly, so the body is written as before. An empty line again counts for an image-only send at the old timing, for agents that draw no chip. Agents that take images as typed `@path` mentions now expect the mention text, unwrapped from its paste framing, so their Enter no longer waits the 5 s cap.
This commit is contained in:
+2
-4
@@ -65,10 +65,8 @@ export function clearThenWrite(
|
||||
writeBody()
|
||||
return
|
||||
}
|
||||
clearAlone(AGENT_TUI_CLEAR_INPUT_MAX, () =>
|
||||
// Never paste onto text the clear could not remove; it would be submitted with the message.
|
||||
readNativeChatInputLine(options?.readInputLine) ? refuse() : writeBody()
|
||||
)
|
||||
// A refusal here would drop non-Claude sends silently, and a slow redraw would refuse a clear that landed.
|
||||
clearAlone(AGENT_TUI_CLEAR_INPUT_MAX, writeBody)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -27,8 +27,9 @@ const squash = (text: string): string => text.replace(/\s+/g, '')
|
||||
/** Whether the line shows the whole message, given `expected` from nativeChatExpectedLine: its
|
||||
* text, or a text-paste chip; image chips alone prove only an image-only send. */
|
||||
export function nativeChatLineShowsMessage(line: string, expected: string): boolean {
|
||||
// An empty line counts only for an image-only send, at the old timing, for agents that draw no chip.
|
||||
if (!squash(line)) {
|
||||
return false
|
||||
return expected === ''
|
||||
}
|
||||
const withoutImages = line.replace(IMAGE_CHIP, '')
|
||||
const rest = squash(withoutImages.replace(TEXT_PASTE_CHIP, ''))
|
||||
|
||||
+20
-8
@@ -2,10 +2,16 @@ import {
|
||||
sendNativeChatObservedWrites,
|
||||
type NativeChatObservedWrite
|
||||
} from './native-chat-observed-send'
|
||||
import { agentImagePasteWrites } from '../../../../../../../shared/native-chat/input/composer/agent-image-paste'
|
||||
import {
|
||||
agentImagePasteWrites,
|
||||
getAgentImageHandling
|
||||
} from '../../../../../../../shared/native-chat/input/composer/agent-image-paste'
|
||||
import { agentImagePastePath } from '../../../../../../../shared/native-chat/input/composer/agent-image-paste-path'
|
||||
import type { AgentType } from '../../../../../../../shared/agent-status/contracts/agent-status-types'
|
||||
import { BRACKETED_PASTE_START } from '../../../../../../../shared/terminal/input/terminal-bracketed-paste-text'
|
||||
import {
|
||||
BRACKETED_PASTE_END,
|
||||
BRACKETED_PASTE_START
|
||||
} from '../../../../../../../shared/terminal/input/terminal-bracketed-paste-text'
|
||||
import { sendRuntimePtyInput } from '@/runtime/hosted-terminals/input/runtime-terminal-input-send'
|
||||
import { NATIVE_CHAT_SUBMIT_DELAY_MS } from '../../../../../../../shared/native-chat/input/questions/native-chat-answer-stepping'
|
||||
import {
|
||||
@@ -42,7 +48,7 @@ export function sendNativeChatMessageWithImageAttachments(
|
||||
imagePaths.map((path) => buildNativeChatImagePasteBytes(agentImagePastePath(agent, path))),
|
||||
trimmedText.length > 0
|
||||
).map((data) => ({ data, delayBeforeMs: 0 }))
|
||||
const mentions = typedImageMentions(writes)
|
||||
const mentions = typedImageMentions(agent, writes)
|
||||
if (trimmedText) {
|
||||
writes.push({
|
||||
data: buildNativeChatPasteBytes(text),
|
||||
@@ -88,7 +94,11 @@ export function sendNativeChatMessageWithImageAttachments(
|
||||
afterNativeChatPasteLands({
|
||||
readInputLine: options?.readInputLine,
|
||||
lineWasEmpty,
|
||||
text: typedImageMentions(imageWrites.map((data) => ({ data }))) + text,
|
||||
text:
|
||||
typedImageMentions(
|
||||
agent,
|
||||
imageWrites.map((data) => ({ data }))
|
||||
) + text,
|
||||
delay,
|
||||
submit: () => {
|
||||
sendRuntimePtyInput(ptyId, NATIVE_CHAT_SUBMIT, 'driving')
|
||||
@@ -116,10 +126,12 @@ export function sendNativeChatMessageWithImageAttachments(
|
||||
)
|
||||
}
|
||||
|
||||
/** Agents without image paste get typed `@path` mentions, which the input line shows as text. */
|
||||
function typedImageMentions(writes: readonly { data: string }[]): string {
|
||||
/** Agents without image paste get `@path` mentions, which their input line shows as text. */
|
||||
function typedImageMentions(agent: AgentType, writes: readonly { data: string }[]): string {
|
||||
if (getAgentImageHandling(agent) === 'attachment') {
|
||||
return ''
|
||||
}
|
||||
return writes
|
||||
.map((write) => write.data)
|
||||
.filter((data) => !data.startsWith(BRACKETED_PASTE_START))
|
||||
.map((write) => write.data.replace(BRACKETED_PASTE_START, '').replace(BRACKETED_PASTE_END, ''))
|
||||
.join('')
|
||||
}
|
||||
|
||||
+24
@@ -16,6 +16,7 @@ vi.mock('@/runtime/hosted-terminals/input/runtime-terminal-verified-input', () =
|
||||
}))
|
||||
|
||||
import { sendNativeChatMessage } from './native-chat-runtime-send'
|
||||
import { sendNativeChatMessageWithImageAttachments } from './native-chat-runtime-image-send'
|
||||
import { resetNativeChatPtySendQueuesForTests } from './native-chat-pty-send-queue'
|
||||
import { nativeChatExpectedLine, nativeChatLineShowsMessage } from './native-chat-paste-landed'
|
||||
|
||||
@@ -88,3 +89,26 @@ describe('nativeChatLineShowsMessage', () => {
|
||||
expect(nativeChatLineShowsMessage('[Image #1] Reply with PONG', expected)).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('image sends to agents that take typed @path mentions', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
writes.length = 0
|
||||
})
|
||||
afterEach(() => {
|
||||
resetNativeChatPtySendQueuesForTests()
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
it('presses Enter once the line shows the mention and the caption', async () => {
|
||||
let line = ''
|
||||
sendNativeChatMessageWithImageAttachments('omp', 'pty-1', 'describe', ['/tmp/a.png'], {
|
||||
readInputLine: () => line,
|
||||
onWriteRejected: () => {}
|
||||
})
|
||||
await vi.advanceTimersByTimeAsync(300)
|
||||
line = '@/tmp/a.png describe'
|
||||
await vi.advanceTimersByTimeAsync(800)
|
||||
expect(writes.at(-1)).toBe('\r')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user