Skip to content
Open
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
6 changes: 5 additions & 1 deletion apps/mobile/src/features/threads/QuestionAttachments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ export function QuestionAttachments(props: {
focusedRef.current = false;
onInputFocusChange?.(false);
}}
placeholder="Or type a custom answer"
placeholder={
props.question.initialAnswer !== undefined
? "Type your answer"
: "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
4 changes: 3 additions & 1 deletion apps/web/src/components/chat/ChatComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3472,7 +3472,9 @@ 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"
: isLiteralPendingAnswer
? "Type your answer"
: "Type your own answer, or leave this blank to use the selected option"
: projectSelectionRequired
? "Choose a project above to start a thread"
: showProviderUnavailable
Expand Down
71 changes: 45 additions & 26 deletions packages/provider-pi/src/server/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3954,32 +3954,51 @@ describe("PiAdapterV2", () => {
}).pipe(Effect.scoped, Effect.provide(layerTest)),
);

it.effect("keeps an input dialog's title as the header above its placeholder", () =>
Effect.gen(function* () {
const fake = yield* makeFakePi;
const { runtime, takeEvent } = yield* openRuntime(fake);
yield* runtime.ensureThread({
threadId: THREAD_ID,
modelSelection: modelSelection("default"),
runtimePolicy,
});
yield* fake.emit({
type: "extension_ui_request",
id: "ui-input-placeholder",
method: "input",
title: "Name",
placeholder: "Your name",
});
const event = yield* takeEvent(
(event) =>
event.type === "turn_item.updated" && event.turnItem.type === "user_input_request",
);
if (event.type !== "turn_item.updated" || event.turnItem.type !== "user_input_request") {
return assert.fail("expected a user input request");
}
assert.equal(event.turnItem.questions[0]?.header, "Name");
assert.equal(event.turnItem.questions[0]?.question, "Your name");
}).pipe(Effect.scoped, Effect.provide(layerTest)),
it.effect.each([" SQLite\n ", "", undefined])(
"asks the complete input title as free text and returns the exact answer %j",
(answer) =>
Effect.gen(function* () {
const fake = yield* makeFakePi;
const { runtime, takeEvent } = yield* openRuntime(fake);
yield* runtime.ensureThread({
threadId: THREAD_ID,
modelSelection: modelSelection("default"),
runtimePolicy,
});
yield* fake.emit({
type: "extension_ui_request",
id: "ui-input-placeholder",
method: "input",
title: "Which database?\n1. Postgres\n2. SQLite",
placeholder: "1,3; custom answer",
});
const event = yield* takeEvent(
(event) =>
event.type === "turn_item.updated" && event.turnItem.type === "user_input_request",
);
if (event.type !== "turn_item.updated" || event.turnItem.type !== "user_input_request") {
return assert.fail("expected a user input request");
}
assert.equal(event.turnItem.questions[0]?.header, "Question");
assert.equal(
event.turnItem.questions[0]?.question,
"Which database?\n1. Postgres\n2. SQLite",
);
assert.deepEqual(decodeUserInputQuestions(event.turnItem.questions)[0]?.options, []);
assert.equal(event.turnItem.questions[0]?.initialAnswer, "");
yield* runtime.respondToRuntimeRequest({
requestId: event.turnItem.requestId,
answers: answer === undefined ? {} : { "ui-input-placeholder": answer },
});
const response = yield* fake.takeRequest("extension_ui_response");
if (answer === undefined) {
assert.isTrue(response["cancelled"]);
assert.isUndefined(response["value"]);
} else {
assert.equal(response["value"], answer);
assert.isUndefined(response["cancelled"]);
}
}).pipe(Effect.scoped, Effect.provide(layerTest)),
);

it.effect("emits a valid empty select option and returns its original value", () =>
Expand Down
26 changes: 11 additions & 15 deletions packages/provider-pi/src/server/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3594,25 +3594,21 @@ function piQuestion(
description: option || "Empty value",
value: option,
}))
: method === "editor"
? []
: [
{
label: "Submit empty value",
description: "Send an empty string to the extension.",
value: "",
},
];
// Pi's select and editor dialogs carry only a title, so show it once, as the question.
// Extensions may send a blank placeholder, which is not a valid question.
const detail = [recordString(event, "message"), recordString(event, "placeholder")].find(
(text) => text !== undefined && text.trim().length > 0,
);
: [];
// Input/editor placeholders are hints, not question content.
const detail =
method === "select"
? [recordString(event, "message"), recordString(event, "placeholder")].find(
(text) => text !== undefined && text.trim().length > 0,
)
: undefined;
return {
id: questionId,
header: detail === undefined ? "Question" : title,
question: detail ?? title,
...(method === "editor" ? { initialAnswer: recordString(event, "prefill") ?? "" } : {}),
...(method !== "select"
? { initialAnswer: method === "editor" ? (recordString(event, "prefill") ?? "") : "" }
: {}),
options,
};
}
Expand Down
Loading