useCloseWidget
Finalize a widget interaction and pass context back
Returns a function that closes the widget and passes a context string back. Call it when the user has completed their interaction and you want to provide Eney with a summary of what happened.
Import
Import the hook from the Eney API package:
import { useCloseWidget } from "@eney/api";Usage
Initialize the hook at the top of your component and call the returned function with a status message when the task is complete:
const closeWidget = useCloseWidget();
// Call with a context string when the interaction is complete
closeWidget("Appended content to note 'Meeting Notes'");Signature
function useCloseWidget(): (context: string) => voidThe context string is passed back to Eney as the tool result. Eney uses it to continue the conversation — for example, to confirm the action or suggest a next step.
Example
This example shows how to use a "Done" button to close the widget after an operation completes:
import { useState } from "react";
import { Form, Action, ActionPanel, useCloseWidget } from "@eney/api";
function MyWidget(props: Props) {
const closeWidget = useCloseWidget();
const [result, setResult] = useState("");
async function onSubmit() {
const output = await doSomething();
setResult(output);
}
function onDone() {
closeWidget(`Operation complete: ${result}`);
}
const actions = (
<ActionPanel>
<Action.SubmitForm title="Run" onSubmit={onSubmit} style="secondary" />
<Action title="Done" onAction={onDone} style="primary" />
</ActionPanel>
);
return (
<Form actions={actions}>
{result && <Paper markdown={result} />}
</Form>
);
}If the user closes the widget by clicking the X button, no context is passed back to Eney and the interaction is treated as cancelled. Always provide a "Done" or "Submit" button that calls closeWidget so Eney receives the result.