mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-02 10:44:52 +01:00
Route native question answers through their saved Paperclip cards
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
ccf7e50a99
commit
9bae201ea3
2 files changed
+47
-6
No files matched your search
@@ -3566,7 +3566,7 @@ describe("TaskChatThread live transcript", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("resolves a visible canonical input even while run adapter metadata is stale", async () => {
|
||||
it.each([false, true])("resolves canonical input with stale adapter metadata (saved card: %s)", async (hasSavedCard) => {
|
||||
transcriptState.transcriptByRun.set("run-input", [
|
||||
{
|
||||
kind: "runtime_request",
|
||||
@@ -3587,7 +3587,7 @@ describe("TaskChatThread live transcript", () => {
|
||||
prompt: "What should the server do?",
|
||||
required: true,
|
||||
answerMode: "single_select",
|
||||
options: [{ id: "api", label: "Starter API" }],
|
||||
options: [{ id: "api", label: "Starter API" }, { id: "worker", label: "Background worker" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -3597,8 +3597,19 @@ describe("TaskChatThread live transcript", () => {
|
||||
.spyOn(heartbeatsApi, "resolveRuntimeRequest")
|
||||
.mockResolvedValue({} as never);
|
||||
|
||||
const onSubmitInteractionAnswers = vi.fn().mockResolvedValue(undefined);
|
||||
const saved = {
|
||||
...questionInteraction("saved-question", "What should the server do?", "2026-08-23T20:00:00.000Z"),
|
||||
sourceRunId: "run-input", continuationPolicy: "none",
|
||||
payload: { version: 1, runtimeRequestId: "question-1",
|
||||
questionSet: transcriptState.transcriptByRun.get("run-input")[0].questionSet,
|
||||
questions: [{ id: "goal", prompt: "What should the server do?", required: true, selectionMode: "single",
|
||||
options: [{ id: "api", label: "Starter API" }, { id: "worker", label: "Background worker" }] }] },
|
||||
} as IssueThreadInteraction;
|
||||
render(
|
||||
<TaskChatThread
|
||||
interactions={hasSavedCard ? [saved] : []}
|
||||
onSubmitInteractionAnswers={onSubmitInteractionAnswers}
|
||||
comments={[]}
|
||||
onAdd={async () => {}}
|
||||
issueStatus="in_progress"
|
||||
@@ -3629,7 +3640,10 @@ describe("TaskChatThread live transcript", () => {
|
||||
);
|
||||
await act(async () => submit?.click());
|
||||
|
||||
expect(resolveRuntimeRequest).toHaveBeenCalledWith({
|
||||
if (hasSavedCard) {
|
||||
expect(resolveRuntimeRequest).not.toHaveBeenCalled();
|
||||
expect(onSubmitInteractionAnswers).toHaveBeenCalledWith(saved, [{ questionId: "goal", optionIds: ["api"] }]);
|
||||
} else expect(resolveRuntimeRequest).toHaveBeenCalledWith({
|
||||
runId: "run-input",
|
||||
requestId: "question-1",
|
||||
turnId: "turn-1",
|
||||
|
||||
@@ -2273,6 +2273,28 @@ export function TaskChatThread(props: TaskChatThreadProps) {
|
||||
item: TaskChatRuntimeRequestItem,
|
||||
decision: TaskChatRuntimeRequestDecision,
|
||||
) => {
|
||||
const projected = (interactions ?? []).find((interaction) =>
|
||||
interaction.kind === "ask_user_questions" && interaction.sourceRunId === item.runId &&
|
||||
interaction.payload.runtimeRequestId === item.requestId);
|
||||
if (projected?.kind === "ask_user_questions") {
|
||||
if (projected.status !== "pending") throw new Error("This question has already been answered or closed.");
|
||||
if (decision.action === "cancel") {
|
||||
if (!onCancelInteraction) throw new Error("Cancelling this question is unavailable.");
|
||||
await onCancelInteraction(projected);
|
||||
return;
|
||||
}
|
||||
if (decision.action !== "submit" || !("response" in decision) || !projected.payload.questionSet || !onSubmitInteractionAnswers) {
|
||||
throw new Error("Submit the answer through the saved question card.");
|
||||
}
|
||||
const response = decision.response;
|
||||
await onSubmitInteractionAnswers(projected, projected.payload.questionSet.questions.map(question => {
|
||||
const answer = response.answers[question.id];
|
||||
const otherText = question.answerMode === "text" ? answer?.text?.trim() : answer?.customText?.trim();
|
||||
return { questionId: question.id, optionIds: question.answerMode === "text" ? [] : (answer?.selectedOptionIds ?? []),
|
||||
...(otherText ? { otherText } : {}) };
|
||||
}));
|
||||
return;
|
||||
}
|
||||
if (!item.turnId || !item.requestKind) {
|
||||
throw new Error(
|
||||
"This runtime request is missing the provider turn identity needed to resolve it.",
|
||||
@@ -2308,14 +2330,19 @@ export function TaskChatThread(props: TaskChatThreadProps) {
|
||||
resolution,
|
||||
});
|
||||
},
|
||||
[],
|
||||
[interactions, onSubmitInteractionAnswers, onCancelInteraction],
|
||||
);
|
||||
const pendingComposerInputs = useMemo<PendingComposerInput[]>(() => {
|
||||
const result: PendingComposerInput[] = [];
|
||||
const runtimeKey = pendingRuntimeRequest
|
||||
? `runtime:${pendingRuntimeRequest.runId}:${pendingRuntimeRequest.requestId}`
|
||||
: null;
|
||||
if (pendingRuntimeRequest && runtimeKey) {
|
||||
// A projected card owns the durable answer and forwards it to the live
|
||||
// provider. Bypassing it leaves a pending card that blocks completion.
|
||||
const projectedRuntime = pendingRuntimeRequest && (interactions ?? []).some(interaction =>
|
||||
interaction.kind === "ask_user_questions" && interaction.sourceRunId === pendingRuntimeRequest.runId &&
|
||||
interaction.payload.runtimeRequestId === pendingRuntimeRequest.requestId);
|
||||
if (pendingRuntimeRequest && runtimeKey && !projectedRuntime) {
|
||||
result.push({
|
||||
key: runtimeKey,
|
||||
kind: "runtime",
|
||||
@@ -2343,7 +2370,7 @@ export function TaskChatThread(props: TaskChatThreadProps) {
|
||||
? `runtime:${interaction.sourceRunId}:${interaction.payload.runtimeRequestId}`
|
||||
: null;
|
||||
const key = recoveredRuntimeKey ?? `interaction:${interaction.id}`;
|
||||
if (key === runtimeKey) continue;
|
||||
|
||||
result.push({
|
||||
key,
|
||||
kind: "durable",
|
||||
|
||||
Reference in new issue
Block a user