@alquimia-ai/ui 2.2.2 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3633,5 +3633,196 @@ function RatingDialog(param) {
3633
3633
  })
3634
3634
  });
3635
3635
  }
3636
- export { Assistant, AssistantInput, AssistantMessageArea, RatingDialog, SpeechToText, Whisper };
3636
+ // src/components/organisms/tool-approval.tsx
3637
+ import * as React38 from "react";
3638
+ import { Check as Check3, Loader2 as Loader22, ShieldAlert, X as X3 } from "lucide-react";
3639
+ import { Fragment as Fragment4, jsx as jsx50, jsxs as jsxs24 } from "react/jsx-runtime";
3640
+ function formatArguments(args) {
3641
+ if (args === null || args === void 0) return null;
3642
+ if (typeof args === "string") return args;
3643
+ try {
3644
+ return JSON.stringify(args, null, 2);
3645
+ } catch (e) {
3646
+ return String(args);
3647
+ }
3648
+ }
3649
+ function blockedMessage(approval, channelName) {
3650
+ var _approval_lastResult;
3651
+ var outcome = (_approval_lastResult = approval.lastResult) === null || _approval_lastResult === void 0 ? void 0 : _approval_lastResult.outcome;
3652
+ if (approval.channelOwned || outcome === "wrong-channel") {
3653
+ return "This approval has to be answered in ".concat(channelName !== null && channelName !== void 0 ? channelName : "the channel the conversation came from", ". It can't be answered here.");
3654
+ }
3655
+ switch(outcome){
3656
+ case "already-decided":
3657
+ return "Someone else already answered this request. Waiting for the agent to continue.";
3658
+ case "not-pending":
3659
+ return "This request is no longer waiting for a decision.";
3660
+ case "not-found":
3661
+ return "This conversation has ended, so the request can no longer be answered.";
3662
+ case "forbidden":
3663
+ return "You don't have permission to answer this request.";
3664
+ default:
3665
+ return null;
3666
+ }
3667
+ }
3668
+ function ToolApprovalCard(param) {
3669
+ var approval = param.approval, onDecide = param.onDecide, channelName = param.channelName, className = param.className;
3670
+ var _React38_useState = _sliced_to_array(React38.useState(false), 2), rejecting = _React38_useState[0], setRejecting = _React38_useState[1];
3671
+ var _React38_useState1 = _sliced_to_array(React38.useState(""), 2), reason = _React38_useState1[0], setReason = _React38_useState1[1];
3672
+ var args = formatArguments(approval.arguments);
3673
+ var _approval_toolName;
3674
+ var toolLabel = (_approval_toolName = approval.toolName) !== null && _approval_toolName !== void 0 ? _approval_toolName : "a tool";
3675
+ var submitting = approval.status === "submitting";
3676
+ var settled = approval.status === "approved" || approval.status === "rejected";
3677
+ var blocked = !settled && !submitting && !approval.canAnswer ? blockedMessage(approval, channelName) : null;
3678
+ var failed = !settled && !submitting && approval.canAnswer && approval.lastResult && approval.lastResult.outcome !== "accepted" ? approval.lastResult : null;
3679
+ var decide = function(approved) {
3680
+ var said = reason.trim();
3681
+ void onDecide(approval.controlId, approved, approved || !said ? void 0 : said);
3682
+ };
3683
+ return /* @__PURE__ */ jsxs24("section", {
3684
+ "aria-label": "Approval request for ".concat(toolLabel),
3685
+ "data-status": approval.status,
3686
+ className: cn("alq--tool-approval w-full max-w-[95%] rounded-2xl border bg-card p-4 shadow-sm", settled ? "border-border/60" : "border-amber-500/50", className),
3687
+ children: [
3688
+ /* @__PURE__ */ jsxs24("header", {
3689
+ className: "flex items-start gap-2",
3690
+ children: [
3691
+ /* @__PURE__ */ jsx50(ShieldAlert, {
3692
+ "aria-hidden": true,
3693
+ className: cn("mt-0.5 h-4 w-4 shrink-0", settled ? "text-muted-foreground" : "text-amber-500")
3694
+ }),
3695
+ /* @__PURE__ */ jsxs24("div", {
3696
+ className: "min-w-0 flex-1",
3697
+ children: [
3698
+ /* @__PURE__ */ jsx50("p", {
3699
+ className: "text-sm font-medium text-foreground",
3700
+ children: settled ? "Approval request" : "The agent needs your approval"
3701
+ }),
3702
+ /* @__PURE__ */ jsxs24("p", {
3703
+ className: "text-sm text-muted-foreground",
3704
+ children: [
3705
+ "Run ",
3706
+ /* @__PURE__ */ jsx50("code", {
3707
+ className: "rounded bg-muted px-1 py-0.5 font-mono text-xs text-foreground",
3708
+ children: toolLabel
3709
+ })
3710
+ ]
3711
+ })
3712
+ ]
3713
+ }),
3714
+ settled && /* @__PURE__ */ jsxs24("span", {
3715
+ className: cn("flex shrink-0 items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium", approval.status === "approved" ? "bg-emerald-500/10 text-emerald-600 dark:text-emerald-400" : "bg-destructive/10 text-destructive"),
3716
+ children: [
3717
+ approval.status === "approved" ? /* @__PURE__ */ jsx50(Check3, {
3718
+ className: "h-3 w-3"
3719
+ }) : /* @__PURE__ */ jsx50(X3, {
3720
+ className: "h-3 w-3"
3721
+ }),
3722
+ approval.status === "approved" ? "Approved" : "Rejected",
3723
+ approval.decidedHere ? " by you" : " elsewhere"
3724
+ ]
3725
+ })
3726
+ ]
3727
+ }),
3728
+ args !== null && /* @__PURE__ */ jsx50("pre", {
3729
+ "aria-label": "Arguments",
3730
+ className: "mt-3 max-h-48 overflow-auto rounded-lg bg-muted/60 p-3 font-mono text-xs text-foreground",
3731
+ children: args
3732
+ }),
3733
+ settled && approval.status === "rejected" && approval.reason && /* @__PURE__ */ jsxs24("p", {
3734
+ className: "mt-3 text-sm text-muted-foreground",
3735
+ children: [
3736
+ /* @__PURE__ */ jsx50("span", {
3737
+ className: "font-medium text-foreground",
3738
+ children: "Reason:"
3739
+ }),
3740
+ " ",
3741
+ approval.reason
3742
+ ]
3743
+ }),
3744
+ blocked && /* @__PURE__ */ jsx50("p", {
3745
+ role: "status",
3746
+ className: "mt-3 text-sm text-muted-foreground",
3747
+ children: blocked
3748
+ }),
3749
+ failed && /* @__PURE__ */ jsxs24("p", {
3750
+ role: "alert",
3751
+ className: "mt-3 text-sm text-destructive",
3752
+ children: [
3753
+ "Couldn't send your decision",
3754
+ failed.detail ? ": ".concat(failed.detail) : ".",
3755
+ " Try again."
3756
+ ]
3757
+ }),
3758
+ !settled && (submitting || approval.canAnswer) && /* @__PURE__ */ jsxs24("div", {
3759
+ className: "mt-3 flex flex-col gap-2",
3760
+ children: [
3761
+ rejecting && /* @__PURE__ */ jsx50(Textarea, {
3762
+ "aria-label": "Reason for rejecting (optional)",
3763
+ placeholder: "Reason for rejecting (optional)",
3764
+ value: reason,
3765
+ disabled: submitting,
3766
+ onChange: function(e) {
3767
+ return setReason(e.target.value);
3768
+ },
3769
+ className: "min-h-[64px] text-sm"
3770
+ }),
3771
+ /* @__PURE__ */ jsxs24("div", {
3772
+ className: "flex flex-wrap items-center justify-end gap-2",
3773
+ children: [
3774
+ submitting && /* @__PURE__ */ jsx50(Loader22, {
3775
+ "aria-label": "Sending decision",
3776
+ className: "h-4 w-4 animate-spin text-muted-foreground"
3777
+ }),
3778
+ rejecting ? /* @__PURE__ */ jsxs24(Fragment4, {
3779
+ children: [
3780
+ /* @__PURE__ */ jsx50(Button, {
3781
+ size: "sm",
3782
+ variant: "ghost",
3783
+ disabled: submitting,
3784
+ onClick: function() {
3785
+ return setRejecting(false);
3786
+ },
3787
+ children: "Cancel"
3788
+ }),
3789
+ /* @__PURE__ */ jsx50(Button, {
3790
+ size: "sm",
3791
+ variant: "destructive",
3792
+ disabled: submitting,
3793
+ onClick: function() {
3794
+ return decide(false);
3795
+ },
3796
+ children: "Reject"
3797
+ })
3798
+ ]
3799
+ }) : /* @__PURE__ */ jsxs24(Fragment4, {
3800
+ children: [
3801
+ /* @__PURE__ */ jsx50(Button, {
3802
+ size: "sm",
3803
+ variant: "outline",
3804
+ disabled: submitting,
3805
+ onClick: function() {
3806
+ return setRejecting(true);
3807
+ },
3808
+ children: "Reject\u2026"
3809
+ }),
3810
+ /* @__PURE__ */ jsx50(Button, {
3811
+ size: "sm",
3812
+ disabled: submitting,
3813
+ onClick: function() {
3814
+ return decide(true);
3815
+ },
3816
+ children: "Approve"
3817
+ })
3818
+ ]
3819
+ })
3820
+ ]
3821
+ })
3822
+ ]
3823
+ })
3824
+ ]
3825
+ });
3826
+ }
3827
+ export { Assistant, AssistantInput, AssistantMessageArea, RatingDialog, SpeechToText, ToolApprovalCard, Whisper };
3637
3828
  //# sourceMappingURL=index.mjs.map