Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/mobile/src/features/threads/PendingUserInputCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function QuestionText(props: { readonly markdown: string; readonly environmentId
return (
<SelectableMarkdownText
markdown={markdown}
preserveSoftBreaks
textStyle={styles.nativeTextStyle}
onLinkPress={(href) => void openLink(href)}
/>
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/features/threads/QuestionAttachments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export function QuestionAttachments(props: {
focusedRef.current = false;
onInputFocusChange?.(false);
}}
placeholder="Or type a custom answer"
placeholder={props.question.placeholder ?? "Or type a custom answer"}
className="min-h-[54px] rounded-2xl border border-input-border bg-input px-3.5 py-3 font-sans text-base text-foreground"
/>
</TextInputWrapper>
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/mcp/toolkits/thread/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const question = Schema.Struct({
multiSelect: Schema.optional(Schema.Boolean),
allowCustomAnswer: Schema.optional(Schema.Boolean),
initialAnswer: Schema.optional(Schema.String),
placeholder: Schema.optional(Schema.String),
required: Schema.optional(Schema.Boolean),
});
const PendingRequestTool = Tool.make("t3_pending_request", {
Expand Down
6 changes: 5 additions & 1 deletion apps/web/src/components/chat/ChatComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ export interface ChatComposerProps {
activeQuestion: {
id: string;
initialAnswer?: string | undefined;
placeholder?: string | undefined;
multiSelect?: boolean | undefined;
allowCustomAnswer?: boolean | undefined;
} | null;
Expand Down Expand Up @@ -3372,7 +3373,10 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
: activePendingProgress
? isChoiceOnlyPendingQuestion
? "Choose an option above"
: "Type your own answer, or leave this blank to use the selected option"
: (activePendingProgress.activeQuestion?.placeholder ??
(isLiteralPendingAnswer
? "Type your answer"
: "Type your own answer, or leave this blank to use the selected option"))
: showPlanFollowUpPrompt && activeProposedPlan
? "Add feedback to refine the plan, or leave this blank to implement it"
: projectSelectionRequired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type RuntimeRequestId, type ScopedThreadRef } from "@t3tools/contracts";
import { decodeHTMLStrict } from "entities";
import { memo, use, useEffect, useEffectEvent, useRef, useState } from "react";
import { BackgroundThreadContext } from "./backgroundThread";
import { useStableCallback } from "~/hooks/useStableCallback";
Expand Down Expand Up @@ -204,7 +205,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
<>
<ComposerBanner.Separator />
<span className="min-w-0 flex-1 truncate text-secondary-label">
{activeQuestion.question}
{decodeHTMLStrict(activeQuestion.question)}
</span>
</>
) : null}
Expand Down Expand Up @@ -243,6 +244,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
<ComposerBanner.Body className="ps-6 pe-4 pb-1 wrap-anywhere sm:ps-5.5">
<ChatMarkdown
text={activeQuestion.question}
lineBreaks
cwd={cwd}
threadRef={threadRef}
className="pt-2 text-foreground/85"
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/src/orchestrationV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,7 @@ export const OrchestrationV2UserInputQuestion = Schema.Struct({
multiSelect: Schema.optional(Schema.Boolean),
allowCustomAnswer: Schema.optional(Schema.Boolean),
initialAnswer: Schema.optional(Schema.String),
placeholder: Schema.optional(Schema.String),
required: Schema.optional(Schema.Boolean),
});
export type OrchestrationV2UserInputQuestion = typeof OrchestrationV2UserInputQuestion.Type;
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/src/providerRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export const UserInputQuestion = Schema.Struct({
options: Schema.Array(UserInputQuestionOption),
allowCustomAnswer: Schema.optional(Schema.Boolean),
initialAnswer: Schema.optional(Schema.String),
placeholder: Schema.optional(Schema.String),
multiSelect: Schema.optional(Schema.Boolean).pipe(
Schema.withConstructorDefault(Effect.succeed(false)),
),
Expand Down
69 changes: 68 additions & 1 deletion packages/provider-pi/src/server/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3342,6 +3342,70 @@ describe("PiAdapterV2", () => {
}).pipe(Effect.scoped, Effect.provide(layerTest)),
);

it.effect.each([
{
placeholder: undefined,
title: "Enter <branch> & [name] *exact* $PATH$",
question: "Enter &lt;branch&gt; &amp; &#91;name&#93; &#42;exact&#42; &#36;PATH&#36;",
},
{
placeholder: "",
title: "Where should this run?\n1. Current branch\n2. New worktree",
question: "Where should this run?\n1&#46; Current branch\n2&#46; New worktree",
},
{ placeholder: "1,3; custom answer", title: "Enter a value", question: "Enter a value" },
{
placeholder: "",
title: "Optional release note\n===",
question: "Optional release note\n&#61;&#61;&#61;",
},
])(
"maps native text input without turning its placeholder into an answer, placeholder=%s",
({ placeholder, title, question: expectedQuestion }) =>
Effect.gen(function* () {
const fake = yield* makeFakePi;
const { runtime, takeEvent } = yield* openRuntime(fake);
yield* runtime.ensureThread({
threadId: THREAD_ID,
modelSelection: modelSelection("default"),
runtimePolicy,
});
for (const [index, answer] of ["", " exact answer\n"].entries()) {
const id = `ui-input-${index}`;
yield* fake.emit({
type: "extension_ui_request",
id,
method: "input",
title,
...(placeholder === undefined ? {} : { placeholder }),
});
const event = yield* takeEvent(
(event) =>
event.type === "turn_item.updated" &&
event.turnItem.type === "user_input_request" &&
event.turnItem.status === "waiting" &&
event.turnItem.questions.some((question) => question.id === id),
);
if (event.type !== "turn_item.updated" || event.turnItem.type !== "user_input_request") {
return assert.fail("expected a user input request");
}
const [question] = decodeUserInputQuestions(event.turnItem.questions);
assert.equal(question?.header, "Question");
assert.equal(question?.question, expectedQuestion);
assert.deepEqual(question?.options, []);
assert.equal(question?.initialAnswer, "");
assert.equal(question?.placeholder, placeholder);
yield* runtime.respondToRuntimeRequest({
requestId: event.turnItem.requestId,
answers: { [id]: answer },
});
const response = yield* fake.takeRequest("extension_ui_response");
assert.equal(response["value"], answer);
assert.isUndefined(response["cancelled"]);
}
}).pipe(Effect.scoped, Effect.provide(layerTest)),
);

it.effect("asks an input dialog's title when its placeholder is blank", () =>
Effect.gen(function* () {
const fake = yield* makeFakePi;
Expand All @@ -3366,7 +3430,10 @@ describe("PiAdapterV2", () => {
if (event.type !== "turn_item.updated" || event.turnItem.type !== "user_input_request") {
return assert.fail("expected a user input request");
}
assert.equal(decodeUserInputQuestions(event.turnItem.questions)[0]?.question, title);
assert.equal(
decodeUserInputQuestions(event.turnItem.questions)[0]?.question,
"Which database?\n1&#46; Postgres\n2&#46; Type something&#46;\nType your answer:",
);
yield* runtime.respondToRuntimeRequest({
requestId: event.turnItem.requestId,
answers: { "ui-input": "SQLite" },
Expand Down
36 changes: 19 additions & 17 deletions packages/provider-pi/src/server/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3324,25 +3324,27 @@ function piQuestion(
description: option || "Empty value",
value: option,
}))
: method === "editor"
? []
: [
{
label: "Submit empty value",
description: "Send an empty string to the extension.",
value: "",
},
];
// Extensions may send a blank placeholder, which is not a valid question.
const question =
[recordString(event, "message"), recordString(event, "placeholder")].find(
(text) => text !== undefined && text.trim().length > 0,
) ?? title;
: [];
const placeholder = method === "input" ? recordString(event, "placeholder") : undefined;
return {
id: questionId,
header: title,
question,
...(method === "editor" ? { initialAnswer: recordString(event, "prefill") ?? "" } : {}),
header: "Question",
question:
title
.trim()
.replace(/&/g, "&amp;")
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/[\\`*_[\]{}()#+.!|~=$-]/g, (character) => `&#${character.charCodeAt(0)};`) ||
(method === "select"
? "Choose an option"
: method === "editor"
? "Edit text"
: "Enter a value"),
...(method === "select"
? {}
: { initialAnswer: method === "editor" ? (recordString(event, "prefill") ?? "") : "" }),
...(placeholder === undefined ? {} : { placeholder }),
options,
};
}
Expand Down
Loading