Skip to content

Commit abb40eb

Browse files
committed
fix(pi): preserve literal dialog titles and free-text hints
1 parent 3e18a97 commit abb40eb

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3374,7 +3374,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
33743374
? isChoiceOnlyPendingQuestion
33753375
? "Choose an option above"
33763376
: (activePendingProgress.activeQuestion?.placeholder ??
3377-
"Type your own answer, or leave this blank to use the selected option")
3377+
(isLiteralPendingAnswer
3378+
? "Type your answer"
3379+
: "Type your own answer, or leave this blank to use the selected option"))
33783380
: showPlanFollowUpPrompt && activeProposedPlan
33793381
? "Add feedback to refine the plan, or leave this blank to implement it"
33803382
: projectSelectionRequired

‎packages/provider-pi/src/server/adapter.test.ts‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3342,9 +3342,21 @@ describe("PiAdapterV2", () => {
33423342
}).pipe(Effect.scoped, Effect.provide(layerTest)),
33433343
);
33443344

3345-
it.effect.each([undefined, "", "1,3; custom answer"])(
3345+
it.effect.each([
3346+
{
3347+
placeholder: undefined,
3348+
title: "Enter <branch> & [name] *exact*",
3349+
question: String.raw`Enter &lt;branch&gt; &amp; \[name\] \*exact\*`,
3350+
},
3351+
{
3352+
placeholder: "",
3353+
title: "Where should this run?\n1. Current branch\n2. New worktree",
3354+
question: "Where should this run?\n1\\. Current branch\n2\\. New worktree",
3355+
},
3356+
{ placeholder: "1,3; custom answer", title: "Enter a value", question: "Enter a value" },
3357+
])(
33463358
"maps native text input without turning its placeholder into an answer, placeholder=%s",
3347-
(placeholder) =>
3359+
({ placeholder, title, question: expectedQuestion }) =>
33483360
Effect.gen(function* () {
33493361
const fake = yield* makeFakePi;
33503362
const { runtime, takeEvent } = yield* openRuntime(fake);
@@ -3353,7 +3365,6 @@ describe("PiAdapterV2", () => {
33533365
modelSelection: modelSelection("default"),
33543366
runtimePolicy,
33553367
});
3356-
const title = "Where should this run?\n1. Current branch\n2. New worktree";
33573368
for (const [index, answer] of ["", " exact answer\n"].entries()) {
33583369
const id = `ui-input-${index}`;
33593370
yield* fake.emit({
@@ -3375,7 +3386,7 @@ describe("PiAdapterV2", () => {
33753386
}
33763387
const [question] = decodeUserInputQuestions(event.turnItem.questions);
33773388
assert.equal(question?.header, "Question");
3378-
assert.equal(question?.question, title);
3389+
assert.equal(question?.question, expectedQuestion);
33793390
assert.deepEqual(question?.options, []);
33803391
assert.equal(question?.initialAnswer, "");
33813392
assert.equal(question?.placeholder, placeholder);
@@ -3414,7 +3425,10 @@ describe("PiAdapterV2", () => {
34143425
if (event.type !== "turn_item.updated" || event.turnItem.type !== "user_input_request") {
34153426
return assert.fail("expected a user input request");
34163427
}
3417-
assert.equal(decodeUserInputQuestions(event.turnItem.questions)[0]?.question, title);
3428+
assert.equal(
3429+
decodeUserInputQuestions(event.turnItem.questions)[0]?.question,
3430+
"Which database?\n1\\. Postgres\n2\\. Type something\\.\nType your answer:",
3431+
);
34183432
yield* runtime.respondToRuntimeRequest({
34193433
requestId: event.turnItem.requestId,
34203434
answers: { "ui-input": "SQLite" },

‎packages/provider-pi/src/server/adapter.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3330,7 +3330,12 @@ function piQuestion(
33303330
id: questionId,
33313331
header: "Question",
33323332
question:
3333-
title.trim() ||
3333+
title
3334+
.trim()
3335+
.replace(/&/g, "&amp;")
3336+
.replace(/</g, "&lt;")
3337+
.replace(/>/g, "&gt;")
3338+
.replace(/[\\`*_[\]{}()#+.!|~-]/g, "\\$&") ||
33343339
(method === "select"
33353340
? "Choose an option"
33363341
: method === "editor"

0 commit comments

Comments
 (0)