28 lines
959 B
TypeScript
28 lines
959 B
TypeScript
import { useState } from "react";
|
|
import type { WidgetDescriptor, UiResponse } from "../api/types";
|
|
import { FreetextWidget } from "./FreetextWidget";
|
|
|
|
/**
|
|
* LinkageHost: when an artifact-gate option has `opens` (a child descriptor),
|
|
* this component renders the child widget and merges the parent choice with
|
|
* the child's text into a single combined UiResponse.
|
|
*/
|
|
export function LinkageHost({
|
|
parentResponse,
|
|
childDescriptor,
|
|
onRespond,
|
|
}: {
|
|
parentResponse: UiResponse;
|
|
childDescriptor: WidgetDescriptor;
|
|
onRespond: (r: UiResponse) => void;
|
|
}) {
|
|
function handleChildResponse(childResponse: UiResponse) {
|
|
// Merge parent choice + child text into one response
|
|
onRespond({ ...parentResponse, text: childResponse.text });
|
|
}
|
|
|
|
// Currently only freetext child is supported per spec.
|
|
// FreetextWidget is the canonical child for "opens".
|
|
return <FreetextWidget descriptor={childDescriptor} onRespond={handleChildResponse} />;
|
|
}
|