fix(mobile): image-only messages ask the agent to respond, like desktop (#16480)

Co-authored-by: Yash Singh <[email protected]>
This commit is contained in:
Ali YounesandYash Singh authored and GitHub committed 2026-10-11 02:40:36 -05:00
1 parent 2025430708
commit 8d199b4f7b
7 files changed
+59 -12

No files matched your search

@@ -8,6 +8,7 @@ import {
} from "@t3tools/contracts";
import { collectComposerInlineTokens } from "@t3tools/shared/composerInlineTokens";
import {
ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
collectComposerContextReferences,
formatComposerContextReference,
projectComposerContextForProvider,
@@ -207,6 +208,20 @@ describe("mobile composer context", () => {
});
describe("host context compatibility", () => {
it("sends an image-only prompt as the attachment-only prompt and keeps the image", () => {
const context: OrchestrationMessageContext = { version: 1, records: [image] };
const reference = formatComposerContextReference(image);
expect(serializeComposerMessageForServer(reference, context, true)).toEqual({
text: ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
context,
});
const withProse = `${reference} what is this?`;
expect(serializeComposerMessageForServer(withProse, context, true)).toEqual({
text: withProse,
context,
});
});
it.each(["existing-thread", "new-task"])("serializes %s sends for an older host", (path) => {
const pr = pullRequestComposerContext(
{
+11 -2
View File
@@ -13,8 +13,10 @@ import {
} from "@t3tools/contracts";
import * as Schema from "effect/Schema";
import {
ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
collectComposerContextReferences,
formatComposerContextReference,
isImageReferencesOnly,
replaceComposerContextReferences,
sanitizeComposerContextLabel,
} from "@t3tools/shared/composerContextReferences";
@@ -229,12 +231,19 @@ export function reidentifyComposerContext(
};
}
/** Keep queued records canonical; choose the wire format against the host at dispatch time. */
/**
* Keep queued records canonical; choose the wire format against the host at dispatch time.
* An image-only prompt goes out as the attachment-only prompt web sends, so the agent is still
* asked to respond. The images stay in the message's attachments and context records.
*/
export function serializeComposerMessageForServer(
text: string,
composerText: string,
context: OrchestrationMessageContext | undefined,
supportsInlineMessageContext: boolean,
): { text: string; context?: OrchestrationMessageContext } {
const text = isImageReferencesOnly(composerText)
? ATTACHMENT_ONLY_BOOTSTRAP_PROMPT
: composerText;
return supportsInlineMessageContext
? { text, ...(context ? { context } : {}) }
: { text: serializeLegacyContextMessage({ text, records: context?.records ?? [] }) };
+2 -4
View File
@@ -607,10 +607,8 @@ import {
supportsServerUpdateThreadContinuation,
} from "../versionSkew";
import { useAssetUrls } from "../assets/assetUrls";
import {
ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
recallableComposerPrompt,
} from "./chat/composerPromptHistory";
import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences";
import { recallableComposerPrompt } from "./chat/composerPromptHistory";
import { observeResize } from "~/lib/observeResize";
const EMPTY_PROVIDERS: ServerProvider[] = [];
@@ -1,8 +1,8 @@
import { describe, expect, it } from "vite-plus/test";
import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences";
import { buildPlanImplementationPrompt } from "../../proposedPlan";
import {
ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
buildComposerPromptHistoryEntries,
recallableComposerPrompt,
stepComposerPromptHistory,
@@ -1,4 +1,7 @@
import { collectComposerContextReferences } from "@t3tools/shared/composerContextReferences";
import {
ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
collectComposerContextReferences,
} from "@t3tools/shared/composerContextReferences";
import { PLAN_IMPLEMENTATION_PROMPT_PREFIX } from "../../proposedPlan";
/**
@@ -15,10 +18,6 @@ const REVIEW_COMMENT_BLOCK_PATTERN = /<review_comment\b[^>]*>[\s\S]*?<\/review_c
const TRAILING_LEGACY_CONTEXT =
/\n*<(terminal_context|element_context|preview_annotation)>\n([\s\S]*?)\n<\/\1>\s*$/;
/** Text sent in place of an empty prompt when a message is attachments only. */
export const ATTACHMENT_ONLY_BOOTSTRAP_PROMPT =
"[User attached one or more files without additional text. Respond using the conversation context and the attached files.]";
export interface ComposerPromptHistoryMessage {
readonly id: string;
readonly role: string;
@@ -6,6 +6,7 @@ import {
formatComposerContextHref,
formatComposerContextProviderMarker,
formatComposerContextReference,
isImageReferencesOnly,
parseComposerContextHref,
projectComposerContextForProvider,
replaceComposerContextReferences,
@@ -86,6 +87,17 @@ describe("labels and reference links", () => {
expect(collectComposerContextReferences("[x](https://example.com)")).toEqual([]);
});
it("recognizes a prompt made only of image references", () => {
const image = "![a.png](t3-context://v1/image/ctx_1)";
const file = "[notes.md](t3-context://v1/file/ctx_3)";
expect(isImageReferencesOnly(image)).toBe(true);
expect(isImageReferencesOnly(` ${image}\n![b.png](t3-context://v1/image/ctx_2) `)).toBe(true);
expect(isImageReferencesOnly(`${image} what is this?`)).toBe(false);
expect(isImageReferencesOnly(file)).toBe(false);
expect(isImageReferencesOnly(`${image} ${file}`)).toBe(false);
expect(isImageReferencesOnly(" ")).toBe(false);
});
it("replaces occurrences in place", () => {
const text = "a [x](t3-context://v1/skill/ctx_1) b [y](t3-context://v1/file/ctx_2) c";
expect(replaceComposerContextReferences(text, (o) => `<${o.contextId}>`)).toBe(
@@ -92,6 +92,20 @@ export function collectComposerContextReferences(
return occurrences;
}
/** Text sent in place of an empty prompt when a message is attachments only. */
export const ATTACHMENT_ONLY_BOOTSTRAP_PROMPT =
"[User attached one or more files without additional text. Respond using the conversation context and the attached files.]";
/** Whether `text` is image references and nothing else, which is how an image-only prompt reads. */
export function isImageReferencesOnly(text: string): boolean {
const references = collectComposerContextReferences(text);
return (
references.length > 0 &&
references.every((reference) => reference.kind === "image") &&
replaceComposerContextReferences(text, () => "").trim() === ""
);
}
export function replaceComposerContextReferences(
text: string,
replace: (occurrence: ComposerContextReferenceOccurrence) => string,