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
@@ -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