@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.
package/dist/index.mjs CHANGED
@@ -4028,6 +4028,197 @@ function RatingDialog(param) {
4028
4028
  })
4029
4029
  });
4030
4030
  }
4031
+ // src/components/organisms/tool-approval.tsx
4032
+ import * as React38 from "react";
4033
+ import { Check as Check3, Loader2 as Loader22, ShieldAlert, X as X3 } from "lucide-react";
4034
+ import { Fragment as Fragment4, jsx as jsx55, jsxs as jsxs26 } from "react/jsx-runtime";
4035
+ function formatArguments(args) {
4036
+ if (args === null || args === void 0) return null;
4037
+ if (typeof args === "string") return args;
4038
+ try {
4039
+ return JSON.stringify(args, null, 2);
4040
+ } catch (e) {
4041
+ return String(args);
4042
+ }
4043
+ }
4044
+ function blockedMessage(approval, channelName) {
4045
+ var _approval_lastResult;
4046
+ var outcome = (_approval_lastResult = approval.lastResult) === null || _approval_lastResult === void 0 ? void 0 : _approval_lastResult.outcome;
4047
+ if (approval.channelOwned || outcome === "wrong-channel") {
4048
+ 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.");
4049
+ }
4050
+ switch(outcome){
4051
+ case "already-decided":
4052
+ return "Someone else already answered this request. Waiting for the agent to continue.";
4053
+ case "not-pending":
4054
+ return "This request is no longer waiting for a decision.";
4055
+ case "not-found":
4056
+ return "This conversation has ended, so the request can no longer be answered.";
4057
+ case "forbidden":
4058
+ return "You don't have permission to answer this request.";
4059
+ default:
4060
+ return null;
4061
+ }
4062
+ }
4063
+ function ToolApprovalCard(param) {
4064
+ var approval = param.approval, onDecide = param.onDecide, channelName = param.channelName, className = param.className;
4065
+ var _React38_useState = _sliced_to_array(React38.useState(false), 2), rejecting = _React38_useState[0], setRejecting = _React38_useState[1];
4066
+ var _React38_useState1 = _sliced_to_array(React38.useState(""), 2), reason = _React38_useState1[0], setReason = _React38_useState1[1];
4067
+ var args = formatArguments(approval.arguments);
4068
+ var _approval_toolName;
4069
+ var toolLabel = (_approval_toolName = approval.toolName) !== null && _approval_toolName !== void 0 ? _approval_toolName : "a tool";
4070
+ var submitting = approval.status === "submitting";
4071
+ var settled = approval.status === "approved" || approval.status === "rejected";
4072
+ var blocked = !settled && !submitting && !approval.canAnswer ? blockedMessage(approval, channelName) : null;
4073
+ var failed = !settled && !submitting && approval.canAnswer && approval.lastResult && approval.lastResult.outcome !== "accepted" ? approval.lastResult : null;
4074
+ var decide = function(approved) {
4075
+ var said = reason.trim();
4076
+ void onDecide(approval.controlId, approved, approved || !said ? void 0 : said);
4077
+ };
4078
+ return /* @__PURE__ */ jsxs26("section", {
4079
+ "aria-label": "Approval request for ".concat(toolLabel),
4080
+ "data-status": approval.status,
4081
+ 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),
4082
+ children: [
4083
+ /* @__PURE__ */ jsxs26("header", {
4084
+ className: "flex items-start gap-2",
4085
+ children: [
4086
+ /* @__PURE__ */ jsx55(ShieldAlert, {
4087
+ "aria-hidden": true,
4088
+ className: cn("mt-0.5 h-4 w-4 shrink-0", settled ? "text-muted-foreground" : "text-amber-500")
4089
+ }),
4090
+ /* @__PURE__ */ jsxs26("div", {
4091
+ className: "min-w-0 flex-1",
4092
+ children: [
4093
+ /* @__PURE__ */ jsx55("p", {
4094
+ className: "text-sm font-medium text-foreground",
4095
+ children: settled ? "Approval request" : "The agent needs your approval"
4096
+ }),
4097
+ /* @__PURE__ */ jsxs26("p", {
4098
+ className: "text-sm text-muted-foreground",
4099
+ children: [
4100
+ "Run ",
4101
+ /* @__PURE__ */ jsx55("code", {
4102
+ className: "rounded bg-muted px-1 py-0.5 font-mono text-xs text-foreground",
4103
+ children: toolLabel
4104
+ })
4105
+ ]
4106
+ })
4107
+ ]
4108
+ }),
4109
+ settled && /* @__PURE__ */ jsxs26("span", {
4110
+ 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"),
4111
+ children: [
4112
+ approval.status === "approved" ? /* @__PURE__ */ jsx55(Check3, {
4113
+ className: "h-3 w-3"
4114
+ }) : /* @__PURE__ */ jsx55(X3, {
4115
+ className: "h-3 w-3"
4116
+ }),
4117
+ approval.status === "approved" ? "Approved" : "Rejected",
4118
+ approval.decidedHere ? " by you" : " elsewhere"
4119
+ ]
4120
+ })
4121
+ ]
4122
+ }),
4123
+ args !== null && /* @__PURE__ */ jsx55("pre", {
4124
+ "aria-label": "Arguments",
4125
+ className: "mt-3 max-h-48 overflow-auto rounded-lg bg-muted/60 p-3 font-mono text-xs text-foreground",
4126
+ children: args
4127
+ }),
4128
+ settled && approval.status === "rejected" && approval.reason && /* @__PURE__ */ jsxs26("p", {
4129
+ className: "mt-3 text-sm text-muted-foreground",
4130
+ children: [
4131
+ /* @__PURE__ */ jsx55("span", {
4132
+ className: "font-medium text-foreground",
4133
+ children: "Reason:"
4134
+ }),
4135
+ " ",
4136
+ approval.reason
4137
+ ]
4138
+ }),
4139
+ blocked && /* @__PURE__ */ jsx55("p", {
4140
+ role: "status",
4141
+ className: "mt-3 text-sm text-muted-foreground",
4142
+ children: blocked
4143
+ }),
4144
+ failed && /* @__PURE__ */ jsxs26("p", {
4145
+ role: "alert",
4146
+ className: "mt-3 text-sm text-destructive",
4147
+ children: [
4148
+ "Couldn't send your decision",
4149
+ failed.detail ? ": ".concat(failed.detail) : ".",
4150
+ " Try again."
4151
+ ]
4152
+ }),
4153
+ !settled && (submitting || approval.canAnswer) && /* @__PURE__ */ jsxs26("div", {
4154
+ className: "mt-3 flex flex-col gap-2",
4155
+ children: [
4156
+ rejecting && /* @__PURE__ */ jsx55(Textarea, {
4157
+ "aria-label": "Reason for rejecting (optional)",
4158
+ placeholder: "Reason for rejecting (optional)",
4159
+ value: reason,
4160
+ disabled: submitting,
4161
+ onChange: function(e) {
4162
+ return setReason(e.target.value);
4163
+ },
4164
+ className: "min-h-[64px] text-sm"
4165
+ }),
4166
+ /* @__PURE__ */ jsxs26("div", {
4167
+ className: "flex flex-wrap items-center justify-end gap-2",
4168
+ children: [
4169
+ submitting && /* @__PURE__ */ jsx55(Loader22, {
4170
+ "aria-label": "Sending decision",
4171
+ className: "h-4 w-4 animate-spin text-muted-foreground"
4172
+ }),
4173
+ rejecting ? /* @__PURE__ */ jsxs26(Fragment4, {
4174
+ children: [
4175
+ /* @__PURE__ */ jsx55(Button, {
4176
+ size: "sm",
4177
+ variant: "ghost",
4178
+ disabled: submitting,
4179
+ onClick: function() {
4180
+ return setRejecting(false);
4181
+ },
4182
+ children: "Cancel"
4183
+ }),
4184
+ /* @__PURE__ */ jsx55(Button, {
4185
+ size: "sm",
4186
+ variant: "destructive",
4187
+ disabled: submitting,
4188
+ onClick: function() {
4189
+ return decide(false);
4190
+ },
4191
+ children: "Reject"
4192
+ })
4193
+ ]
4194
+ }) : /* @__PURE__ */ jsxs26(Fragment4, {
4195
+ children: [
4196
+ /* @__PURE__ */ jsx55(Button, {
4197
+ size: "sm",
4198
+ variant: "outline",
4199
+ disabled: submitting,
4200
+ onClick: function() {
4201
+ return setRejecting(true);
4202
+ },
4203
+ children: "Reject\u2026"
4204
+ }),
4205
+ /* @__PURE__ */ jsx55(Button, {
4206
+ size: "sm",
4207
+ disabled: submitting,
4208
+ onClick: function() {
4209
+ return decide(true);
4210
+ },
4211
+ children: "Approve"
4212
+ })
4213
+ ]
4214
+ })
4215
+ ]
4216
+ })
4217
+ ]
4218
+ })
4219
+ ]
4220
+ });
4221
+ }
4031
4222
  // src/types/type.ts
4032
4223
  var EditingStatus = /* @__PURE__ */ function(EditingStatus2) {
4033
4224
  EditingStatus2["EDITING"] = "EDITING";
@@ -4035,24 +4226,24 @@ var EditingStatus = /* @__PURE__ */ function(EditingStatus2) {
4035
4226
  return EditingStatus2;
4036
4227
  }(EditingStatus || {});
4037
4228
  // src/providers/alquimia-ui-provider.tsx
4038
- import * as React38 from "react";
4039
- import { jsx as jsx55 } from "react/jsx-runtime";
4229
+ import * as React39 from "react";
4230
+ import { jsx as jsx56 } from "react/jsx-runtime";
4040
4231
  function AlquimiaUIProvider(param) {
4041
4232
  var _param_defaultMode = param.defaultMode, defaultMode = _param_defaultMode === void 0 ? "system" : _param_defaultMode, children = param.children;
4042
- var _React38_useState = _sliced_to_array(React38.useState(function() {
4233
+ var _React39_useState = _sliced_to_array(React39.useState(function() {
4043
4234
  if (defaultMode !== "system") return defaultMode;
4044
4235
  if (typeof window !== "undefined") {
4045
4236
  return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
4046
4237
  }
4047
4238
  return "light";
4048
- }), 2), resolvedTheme = _React38_useState[0], setResolvedTheme = _React38_useState[1];
4239
+ }), 2), resolvedTheme = _React39_useState[0], setResolvedTheme = _React39_useState[1];
4049
4240
  function applyTheme(theme) {
4050
4241
  if (typeof document !== "undefined") {
4051
4242
  document.documentElement.classList.toggle("dark", theme === "dark");
4052
4243
  }
4053
4244
  setResolvedTheme(theme);
4054
4245
  }
4055
- React38.useEffect(function() {
4246
+ React39.useEffect(function() {
4056
4247
  if (defaultMode !== "system") {
4057
4248
  applyTheme(defaultMode);
4058
4249
  return;
@@ -4069,7 +4260,7 @@ function AlquimiaUIProvider(param) {
4069
4260
  }, [
4070
4261
  defaultMode
4071
4262
  ]);
4072
- return /* @__PURE__ */ jsx55(ThemeContext.Provider, {
4263
+ return /* @__PURE__ */ jsx56(ThemeContext.Provider, {
4073
4264
  value: {
4074
4265
  theme: resolvedTheme,
4075
4266
  setTheme: applyTheme
@@ -4077,5 +4268,5 @@ function AlquimiaUIProvider(param) {
4077
4268
  children: children
4078
4269
  });
4079
4270
  }
4080
- export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AlertTitle, AlquimiaUIProvider, AspectRatio, Assistant, AssistantButton, AssistantInput, AssistantMessageArea, Avatar, AvatarFallback, AvatarImage, Badge, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, CHART_PALETTE, Calendar, CallOut, CallOutActions, CallOutDate, CallOutResponse, Card, CardContent, CardDescription, CardFooter, CardHeader, CardImageWithHeadingAndDescriptionAvatarHorizontal, CardImageWithHeadingAndDescriptionHorizontal, CardTitle, CardWithImageHeadingDescriptionAvatarVertical, CardWithImageHeadingDescriptionVertical, Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious, Chart, Checkbox, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger, EditingStatus, Hero, HeroContent, Input, Label2 as Label, Loader, MessagesWindow, NavigationMenu, NavigationMenuContent, NavigationMenuIndicator, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, NavigationMenuViewport, PageContainer, Popover, PopoverContent, PopoverTrigger, Progress, QueryBox, RadioGroup, RadioGroupItem, RatingComment, RatingDialog, RatingStars, RatingThumbs, RichText, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator2 as Separator, Sidebar, SidebarFooter, Skeleton, Slider, Toaster2 as SonnerToaster, SpeechToText, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, Textarea, ThemeContext, ThinkIndicator, Toast, ToastAction, ToastClose, ToastDescription, ToastProvider, ToastTitle, ToastViewport, Toaster, Toggle, Tooltip2 as Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, Typography, Whisper, badgeVariants, blobToBase64, buttonVariants, cn, getCookies, getErrorMessage, hasToolResult, navigationMenuTriggerStyle, parseTextToSpeech, reducer, themedChartAxes, thinkIndicatorVariants, toast, toggleVariants, truncateString, useAlquimiaTheme, useDocumentReader, useTextStreaming, useToast };
4271
+ export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AlertTitle, AlquimiaUIProvider, AspectRatio, Assistant, AssistantButton, AssistantInput, AssistantMessageArea, Avatar, AvatarFallback, AvatarImage, Badge, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, CHART_PALETTE, Calendar, CallOut, CallOutActions, CallOutDate, CallOutResponse, Card, CardContent, CardDescription, CardFooter, CardHeader, CardImageWithHeadingAndDescriptionAvatarHorizontal, CardImageWithHeadingAndDescriptionHorizontal, CardTitle, CardWithImageHeadingDescriptionAvatarVertical, CardWithImageHeadingDescriptionVertical, Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious, Chart, Checkbox, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger, EditingStatus, Hero, HeroContent, Input, Label2 as Label, Loader, MessagesWindow, NavigationMenu, NavigationMenuContent, NavigationMenuIndicator, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, NavigationMenuViewport, PageContainer, Popover, PopoverContent, PopoverTrigger, Progress, QueryBox, RadioGroup, RadioGroupItem, RatingComment, RatingDialog, RatingStars, RatingThumbs, RichText, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator2 as Separator, Sidebar, SidebarFooter, Skeleton, Slider, Toaster2 as SonnerToaster, SpeechToText, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, Textarea, ThemeContext, ThinkIndicator, Toast, ToastAction, ToastClose, ToastDescription, ToastProvider, ToastTitle, ToastViewport, Toaster, Toggle, ToolApprovalCard, Tooltip2 as Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, Typography, Whisper, badgeVariants, blobToBase64, buttonVariants, cn, getCookies, getErrorMessage, hasToolResult, navigationMenuTriggerStyle, parseTextToSpeech, reducer, themedChartAxes, thinkIndicatorVariants, toast, toggleVariants, truncateString, useAlquimiaTheme, useDocumentReader, useTextStreaming, useToast };
4081
4272
  //# sourceMappingURL=index.mjs.map