@agentuity/workbench 0.0.87 → 0.0.89
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/components/App.d.ts.map +1 -1
- package/dist/components/App.js +18 -2
- package/dist/components/App.js.map +1 -1
- package/dist/components/ai-elements/code-block.d.ts +3 -3
- package/dist/components/ai-elements/code-block.d.ts.map +1 -1
- package/dist/components/ai-elements/code-block.js +29 -7
- package/dist/components/ai-elements/code-block.js.map +1 -1
- package/dist/components/internal/Chat.d.ts +3 -2
- package/dist/components/internal/Chat.d.ts.map +1 -1
- package/dist/components/internal/Chat.js +23 -24
- package/dist/components/internal/Chat.js.map +1 -1
- package/dist/components/internal/MonacoJsonEditor.d.ts.map +1 -1
- package/dist/components/internal/MonacoJsonEditor.js +10 -53
- package/dist/components/internal/MonacoJsonEditor.js.map +1 -1
- package/dist/components/internal/Schema.d.ts +1 -2
- package/dist/components/internal/Schema.d.ts.map +1 -1
- package/dist/components/internal/Schema.js +2 -3
- package/dist/components/internal/Schema.js.map +1 -1
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/components/ui/input.d.ts.map +1 -1
- package/dist/components/ui/input.js +1 -1
- package/dist/components/ui/input.js.map +1 -1
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -6
- package/dist/index.js.map +1 -1
- package/dist/{styles.css → standalone.css} +207 -1537
- package/package.json +29 -29
- package/src/{styles.css → base.css} +36 -52
- package/src/components/App.tsx +41 -5
- package/src/components/ai-elements/code-block.tsx +42 -10
- package/src/components/internal/Chat.tsx +112 -120
- package/src/components/internal/MonacoJsonEditor.tsx +15 -63
- package/src/components/internal/Schema.tsx +74 -86
- package/src/components/ui/input.tsx +2 -3
- package/src/index.ts +5 -14
- package/src/integration.css +15 -0
- package/src/standalone.css +25 -0
- package/dist/components/ConnectionStatus.d.ts +0 -7
- package/dist/components/ConnectionStatus.d.ts.map +0 -1
- package/dist/components/ConnectionStatus.js +0 -52
- package/dist/components/ConnectionStatus.js.map +0 -1
- package/dist/components/Inline.d.ts +0 -10
- package/dist/components/Inline.d.ts.map +0 -1
- package/dist/components/Inline.js +0 -11
- package/dist/components/Inline.js.map +0 -1
- package/dist/components/ai-elements/artifact.d.ts +0 -24
- package/dist/components/ai-elements/artifact.d.ts.map +0 -1
- package/dist/components/ai-elements/artifact.js +0 -21
- package/dist/components/ai-elements/artifact.js.map +0 -1
- package/dist/components/ai-elements/branch.d.ts +0 -21
- package/dist/components/ai-elements/branch.d.ts.map +0 -1
- package/dist/components/ai-elements/branch.js +0 -71
- package/dist/components/ai-elements/branch.js.map +0 -1
- package/dist/components/ai-elements/canvas.d.ts +0 -9
- package/dist/components/ai-elements/canvas.d.ts.map +0 -1
- package/dist/components/ai-elements/canvas.js +0 -6
- package/dist/components/ai-elements/canvas.js.map +0 -1
- package/dist/components/ai-elements/chain-of-thought.d.ts +0 -30
- package/dist/components/ai-elements/chain-of-thought.d.ts.map +0 -1
- package/dist/components/ai-elements/chain-of-thought.js +0 -52
- package/dist/components/ai-elements/chain-of-thought.js.map +0 -1
- package/dist/components/ai-elements/confirmation.d.ts +0 -27
- package/dist/components/ai-elements/confirmation.d.ts.map +0 -1
- package/dist/components/ai-elements/confirmation.js +0 -57
- package/dist/components/ai-elements/confirmation.js.map +0 -1
- package/dist/components/ai-elements/connection.d.ts +0 -3
- package/dist/components/ai-elements/connection.d.ts.map +0 -1
- package/dist/components/ai-elements/connection.js +0 -4
- package/dist/components/ai-elements/connection.js.map +0 -1
- package/dist/components/ai-elements/context.d.ts +0 -33
- package/dist/components/ai-elements/context.d.ts.map +0 -1
- package/dist/components/ai-elements/context.js +0 -167
- package/dist/components/ai-elements/context.js.map +0 -1
- package/dist/components/ai-elements/controls.d.ts +0 -5
- package/dist/components/ai-elements/controls.d.ts.map +0 -1
- package/dist/components/ai-elements/controls.js +0 -6
- package/dist/components/ai-elements/controls.js.map +0 -1
- package/dist/components/ai-elements/edge.d.ts +0 -6
- package/dist/components/ai-elements/edge.d.ts.map +0 -1
- package/dist/components/ai-elements/edge.js +0 -83
- package/dist/components/ai-elements/edge.js.map +0 -1
- package/dist/components/ai-elements/image.d.ts +0 -7
- package/dist/components/ai-elements/image.d.ts.map +0 -1
- package/dist/components/ai-elements/image.js +0 -4
- package/dist/components/ai-elements/image.js.map +0 -1
- package/dist/components/ai-elements/inline-citation.d.ts +0 -39
- package/dist/components/ai-elements/inline-citation.d.ts.map +0 -1
- package/dist/components/ai-elements/inline-citation.js +0 -62
- package/dist/components/ai-elements/inline-citation.js.map +0 -1
- package/dist/components/ai-elements/loader.d.ts +0 -6
- package/dist/components/ai-elements/loader.d.ts.map +0 -1
- package/dist/components/ai-elements/loader.js +0 -5
- package/dist/components/ai-elements/loader.js.map +0 -1
- package/dist/components/ai-elements/node.d.ts +0 -22
- package/dist/components/ai-elements/node.d.ts.map +0 -1
- package/dist/components/ai-elements/node.js +0 -12
- package/dist/components/ai-elements/node.js.map +0 -1
- package/dist/components/ai-elements/open-in-chat.d.ts +0 -29
- package/dist/components/ai-elements/open-in-chat.d.ts.map +0 -1
- package/dist/components/ai-elements/open-in-chat.js +0 -97
- package/dist/components/ai-elements/open-in-chat.js.map +0 -1
- package/dist/components/ai-elements/panel.d.ts +0 -6
- package/dist/components/ai-elements/panel.d.ts.map +0 -1
- package/dist/components/ai-elements/panel.js +0 -5
- package/dist/components/ai-elements/panel.js.map +0 -1
- package/dist/components/ai-elements/plan.d.ts +0 -26
- package/dist/components/ai-elements/plan.d.ts.map +0 -1
- package/dist/components/ai-elements/plan.js +0 -32
- package/dist/components/ai-elements/plan.js.map +0 -1
- package/dist/components/ai-elements/queue.d.ts +0 -62
- package/dist/components/ai-elements/queue.d.ts.map +0 -1
- package/dist/components/ai-elements/queue.js +0 -25
- package/dist/components/ai-elements/queue.js.map +0 -1
- package/dist/components/ai-elements/reasoning.d.ts +0 -17
- package/dist/components/ai-elements/reasoning.d.ts.map +0 -1
- package/dist/components/ai-elements/reasoning.js +0 -77
- package/dist/components/ai-elements/reasoning.js.map +0 -1
- package/dist/components/ai-elements/response.d.ts +0 -6
- package/dist/components/ai-elements/response.d.ts.map +0 -1
- package/dist/components/ai-elements/response.js +0 -8
- package/dist/components/ai-elements/response.js.map +0 -1
- package/dist/components/ai-elements/sources.d.ts +0 -13
- package/dist/components/ai-elements/sources.d.ts.map +0 -1
- package/dist/components/ai-elements/sources.js +0 -10
- package/dist/components/ai-elements/sources.js.map +0 -1
- package/dist/components/ai-elements/suggestion.d.ts +0 -11
- package/dist/components/ai-elements/suggestion.d.ts.map +0 -1
- package/dist/components/ai-elements/suggestion.js +0 -13
- package/dist/components/ai-elements/suggestion.js.map +0 -1
- package/dist/components/ai-elements/task.d.ts +0 -15
- package/dist/components/ai-elements/task.d.ts.map +0 -1
- package/dist/components/ai-elements/task.js +0 -11
- package/dist/components/ai-elements/task.js.map +0 -1
- package/dist/components/ai-elements/tool.d.ts +0 -24
- package/dist/components/ai-elements/tool.d.ts.map +0 -1
- package/dist/components/ai-elements/tool.js +0 -47
- package/dist/components/ai-elements/tool.js.map +0 -1
- package/dist/components/ai-elements/toolbar.d.ts +0 -6
- package/dist/components/ai-elements/toolbar.d.ts.map +0 -1
- package/dist/components/ai-elements/toolbar.js +0 -5
- package/dist/components/ai-elements/toolbar.js.map +0 -1
- package/dist/components/ai-elements/web-preview.d.ts +0 -35
- package/dist/components/ai-elements/web-preview.d.ts.map +0 -1
- package/dist/components/ai-elements/web-preview.js +0 -63
- package/dist/components/ai-elements/web-preview.js.map +0 -1
- package/dist/components/ui/alert.d.ts +0 -10
- package/dist/components/ui/alert.d.ts.map +0 -1
- package/dist/components/ui/alert.js +0 -25
- package/dist/components/ui/alert.js.map +0 -1
- package/dist/components/ui/badge.d.ts +0 -10
- package/dist/components/ui/badge.d.ts.map +0 -1
- package/dist/components/ui/badge.js +0 -23
- package/dist/components/ui/badge.js.map +0 -1
- package/dist/components/ui/card.d.ts +0 -10
- package/dist/components/ui/card.d.ts.map +0 -1
- package/dist/components/ui/card.js +0 -25
- package/dist/components/ui/card.js.map +0 -1
- package/dist/components/ui/carousel.d.ts +0 -20
- package/dist/components/ui/carousel.d.ts.map +0 -1
- package/dist/components/ui/carousel.js +0 -92
- package/dist/components/ui/carousel.js.map +0 -1
- package/dist/components/ui/checkbox.d.ts +0 -5
- package/dist/components/ui/checkbox.d.ts.map +0 -1
- package/dist/components/ui/checkbox.js +0 -9
- package/dist/components/ui/checkbox.js.map +0 -1
- package/dist/components/ui/collapsible.d.ts +0 -6
- package/dist/components/ui/collapsible.d.ts.map +0 -1
- package/dist/components/ui/collapsible.js +0 -14
- package/dist/components/ui/collapsible.js.map +0 -1
- package/dist/components/ui/field.d.ts +0 -25
- package/dist/components/ui/field.d.ts.map +0 -1
- package/dist/components/ui/field.js +0 -74
- package/dist/components/ui/field.js.map +0 -1
- package/dist/components/ui/form.d.ts +0 -25
- package/dist/components/ui/form.d.ts.map +0 -1
- package/dist/components/ui/form.js +0 -58
- package/dist/components/ui/form.js.map +0 -1
- package/dist/components/ui/label.d.ts +0 -5
- package/dist/components/ui/label.d.ts.map +0 -1
- package/dist/components/ui/label.js +0 -9
- package/dist/components/ui/label.js.map +0 -1
- package/dist/components/ui/progress.d.ts +0 -5
- package/dist/components/ui/progress.d.ts.map +0 -1
- package/dist/components/ui/progress.js +0 -9
- package/dist/components/ui/progress.js.map +0 -1
- package/dist/components/ui/separator.d.ts +0 -5
- package/dist/components/ui/separator.d.ts.map +0 -1
- package/dist/components/ui/separator.js +0 -9
- package/dist/components/ui/separator.js.map +0 -1
- package/dist/components/ui/switch.d.ts +0 -5
- package/dist/components/ui/switch.d.ts.map +0 -1
- package/dist/components/ui/switch.js +0 -8
- package/dist/components/ui/switch.js.map +0 -1
- package/dist/components/ui/tabs.d.ts +0 -8
- package/dist/components/ui/tabs.d.ts.map +0 -1
- package/dist/components/ui/tabs.js +0 -17
- package/dist/components/ui/tabs.js.map +0 -1
- package/dist/components/ui/toggle.d.ts +0 -10
- package/dist/components/ui/toggle.d.ts.map +0 -1
- package/dist/components/ui/toggle.js +0 -26
- package/dist/components/ui/toggle.js.map +0 -1
- package/dist/components.d.ts +0 -12
- package/dist/components.d.ts.map +0 -1
- package/dist/components.js +0 -13
- package/dist/components.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -7
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -5
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/useWorkbenchSchemas.d.ts +0 -56
- package/dist/hooks/useWorkbenchSchemas.d.ts.map +0 -1
- package/dist/hooks/useWorkbenchSchemas.js +0 -63
- package/dist/hooks/useWorkbenchSchemas.js.map +0 -1
- package/src/components/ConnectionStatus.tsx +0 -67
- package/src/components/Inline.tsx +0 -16
- package/src/components/ai-elements/artifact.tsx +0 -118
- package/src/components/ai-elements/branch.tsx +0 -187
- package/src/components/ai-elements/canvas.tsx +0 -24
- package/src/components/ai-elements/chain-of-thought.tsx +0 -198
- package/src/components/ai-elements/confirmation.tsx +0 -119
- package/src/components/ai-elements/connection.tsx +0 -16
- package/src/components/ai-elements/context.tsx +0 -357
- package/src/components/ai-elements/controls.tsx +0 -18
- package/src/components/ai-elements/edge.tsx +0 -131
- package/src/components/ai-elements/image.tsx +0 -16
- package/src/components/ai-elements/inline-citation.tsx +0 -246
- package/src/components/ai-elements/loader.tsx +0 -88
- package/src/components/ai-elements/node.tsx +0 -66
- package/src/components/ai-elements/open-in-chat.tsx +0 -333
- package/src/components/ai-elements/panel.tsx +0 -12
- package/src/components/ai-elements/plan.tsx +0 -123
- package/src/components/ai-elements/queue.tsx +0 -231
- package/src/components/ai-elements/reasoning.tsx +0 -163
- package/src/components/ai-elements/response.tsx +0 -19
- package/src/components/ai-elements/sources.tsx +0 -53
- package/src/components/ai-elements/suggestion.tsx +0 -47
- package/src/components/ai-elements/task.tsx +0 -64
- package/src/components/ai-elements/tool.tsx +0 -136
- package/src/components/ai-elements/toolbar.tsx +0 -13
- package/src/components/ai-elements/web-preview.tsx +0 -238
- package/src/components/ui/alert.tsx +0 -60
- package/src/components/ui/badge.tsx +0 -40
- package/src/components/ui/card.tsx +0 -41
- package/src/components/ui/carousel.tsx +0 -234
- package/src/components/ui/checkbox.tsx +0 -27
- package/src/components/ui/collapsible.tsx +0 -21
- package/src/components/ui/field.tsx +0 -234
- package/src/components/ui/form.tsx +0 -154
- package/src/components/ui/label.tsx +0 -21
- package/src/components/ui/progress.tsx +0 -28
- package/src/components/ui/separator.tsx +0 -28
- package/src/components/ui/switch.tsx +0 -26
- package/src/components/ui/tabs.tsx +0 -52
- package/src/components/ui/toggle.tsx +0 -44
- package/src/components.tsx +0 -29
- package/src/hooks/index.ts +0 -20
- package/src/hooks/useWorkbenchSchemas.ts +0 -69
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Background, ReactFlow, type ReactFlowProps } from '@xyflow/react';
|
|
2
|
-
import type { ReactNode } from 'react';
|
|
3
|
-
import '@xyflow/react/dist/style.css';
|
|
4
|
-
import { Controls } from './controls';
|
|
5
|
-
|
|
6
|
-
type CanvasProps = ReactFlowProps & {
|
|
7
|
-
children?: ReactNode;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const Canvas = ({ children, ...props }: CanvasProps) => (
|
|
11
|
-
<ReactFlow
|
|
12
|
-
deleteKeyCode={['Backspace', 'Delete']}
|
|
13
|
-
fitView
|
|
14
|
-
panOnDrag={false}
|
|
15
|
-
panOnScroll
|
|
16
|
-
selectionOnDrag={true}
|
|
17
|
-
zoomOnDoubleClick={false}
|
|
18
|
-
{...props}
|
|
19
|
-
>
|
|
20
|
-
<Background bgColor="var(--sidebar)" />
|
|
21
|
-
<Controls />
|
|
22
|
-
{children}
|
|
23
|
-
</ReactFlow>
|
|
24
|
-
);
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useControllableState } from '@radix-ui/react-use-controllable-state';
|
|
4
|
-
import { Badge } from '../ui/badge';
|
|
5
|
-
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '../ui/collapsible';
|
|
6
|
-
import { cn } from '../../lib/utils';
|
|
7
|
-
import { BrainIcon, ChevronDownIcon, DotIcon, type LucideIcon } from 'lucide-react';
|
|
8
|
-
import type { ComponentProps } from 'react';
|
|
9
|
-
import { createContext, memo, useContext, useMemo } from 'react';
|
|
10
|
-
|
|
11
|
-
type ChainOfThoughtContextValue = {
|
|
12
|
-
isOpen: boolean;
|
|
13
|
-
setIsOpen: (open: boolean) => void;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const ChainOfThoughtContext = createContext<ChainOfThoughtContextValue | null>(null);
|
|
17
|
-
|
|
18
|
-
const useChainOfThought = () => {
|
|
19
|
-
const context = useContext(ChainOfThoughtContext);
|
|
20
|
-
if (!context) {
|
|
21
|
-
throw new Error('ChainOfThought components must be used within ChainOfThought');
|
|
22
|
-
}
|
|
23
|
-
return context;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type ChainOfThoughtProps = ComponentProps<'div'> & {
|
|
27
|
-
open?: boolean;
|
|
28
|
-
defaultOpen?: boolean;
|
|
29
|
-
onOpenChange?: (open: boolean) => void;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const ChainOfThought = memo(
|
|
33
|
-
({
|
|
34
|
-
className,
|
|
35
|
-
open,
|
|
36
|
-
defaultOpen = false,
|
|
37
|
-
onOpenChange,
|
|
38
|
-
children,
|
|
39
|
-
...props
|
|
40
|
-
}: ChainOfThoughtProps) => {
|
|
41
|
-
const [isOpen, setIsOpen] = useControllableState({
|
|
42
|
-
prop: open,
|
|
43
|
-
defaultProp: defaultOpen,
|
|
44
|
-
onChange: onOpenChange,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const chainOfThoughtContext = useMemo(() => ({ isOpen, setIsOpen }), [isOpen, setIsOpen]);
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<ChainOfThoughtContext.Provider value={chainOfThoughtContext}>
|
|
51
|
-
<div className={cn('not-prose max-w-prose space-y-4', className)} {...props}>
|
|
52
|
-
{children}
|
|
53
|
-
</div>
|
|
54
|
-
</ChainOfThoughtContext.Provider>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
export type ChainOfThoughtHeaderProps = ComponentProps<typeof CollapsibleTrigger>;
|
|
60
|
-
|
|
61
|
-
export const ChainOfThoughtHeader = memo(
|
|
62
|
-
({ className, children, ...props }: ChainOfThoughtHeaderProps) => {
|
|
63
|
-
const { isOpen, setIsOpen } = useChainOfThought();
|
|
64
|
-
|
|
65
|
-
return (
|
|
66
|
-
<Collapsible onOpenChange={setIsOpen} open={isOpen}>
|
|
67
|
-
<CollapsibleTrigger
|
|
68
|
-
className={cn(
|
|
69
|
-
'flex w-full items-center gap-2 text-muted-foreground text-sm transition-colors hover:text-foreground',
|
|
70
|
-
className
|
|
71
|
-
)}
|
|
72
|
-
{...props}
|
|
73
|
-
>
|
|
74
|
-
<BrainIcon className="size-4" />
|
|
75
|
-
<span className="flex-1 text-left">{children ?? 'Chain of Thought'}</span>
|
|
76
|
-
<ChevronDownIcon
|
|
77
|
-
className={cn('size-4 transition-transform', isOpen ? 'rotate-180' : 'rotate-0')}
|
|
78
|
-
/>
|
|
79
|
-
</CollapsibleTrigger>
|
|
80
|
-
</Collapsible>
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
export type ChainOfThoughtStepProps = ComponentProps<'div'> & {
|
|
86
|
-
icon?: LucideIcon;
|
|
87
|
-
label: string;
|
|
88
|
-
description?: string;
|
|
89
|
-
status?: 'complete' | 'active' | 'pending';
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export const ChainOfThoughtStep = memo(
|
|
93
|
-
({
|
|
94
|
-
className,
|
|
95
|
-
icon: Icon = DotIcon,
|
|
96
|
-
label,
|
|
97
|
-
description,
|
|
98
|
-
status = 'complete',
|
|
99
|
-
children,
|
|
100
|
-
...props
|
|
101
|
-
}: ChainOfThoughtStepProps) => {
|
|
102
|
-
const statusStyles = {
|
|
103
|
-
complete: 'text-muted-foreground',
|
|
104
|
-
active: 'text-foreground',
|
|
105
|
-
pending: 'text-muted-foreground/50',
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
return (
|
|
109
|
-
<div
|
|
110
|
-
className={cn(
|
|
111
|
-
'flex gap-2 text-sm',
|
|
112
|
-
statusStyles[status],
|
|
113
|
-
'fade-in-0 slide-in-from-top-2 animate-in',
|
|
114
|
-
className
|
|
115
|
-
)}
|
|
116
|
-
{...props}
|
|
117
|
-
>
|
|
118
|
-
<div className="relative mt-0.5">
|
|
119
|
-
<Icon className="size-4" />
|
|
120
|
-
<div className="-mx-px absolute top-7 bottom-0 left-1/2 w-px bg-border" />
|
|
121
|
-
</div>
|
|
122
|
-
<div className="flex-1 space-y-2">
|
|
123
|
-
<div>{label}</div>
|
|
124
|
-
{description && <div className="text-muted-foreground text-xs">{description}</div>}
|
|
125
|
-
{children}
|
|
126
|
-
</div>
|
|
127
|
-
</div>
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
export type ChainOfThoughtSearchResultsProps = ComponentProps<'div'>;
|
|
133
|
-
|
|
134
|
-
export const ChainOfThoughtSearchResults = memo(
|
|
135
|
-
({ className, ...props }: ChainOfThoughtSearchResultsProps) => (
|
|
136
|
-
<div className={cn('flex items-center gap-2', className)} {...props} />
|
|
137
|
-
)
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
export type ChainOfThoughtSearchResultProps = ComponentProps<typeof Badge>;
|
|
141
|
-
|
|
142
|
-
export const ChainOfThoughtSearchResult = memo(
|
|
143
|
-
({ className, children, ...props }: ChainOfThoughtSearchResultProps) => (
|
|
144
|
-
<Badge
|
|
145
|
-
className={cn('gap-1 px-2 py-0.5 font-normal text-xs', className)}
|
|
146
|
-
variant="secondary"
|
|
147
|
-
{...props}
|
|
148
|
-
>
|
|
149
|
-
{children}
|
|
150
|
-
</Badge>
|
|
151
|
-
)
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
export type ChainOfThoughtContentProps = ComponentProps<typeof CollapsibleContent>;
|
|
155
|
-
|
|
156
|
-
export const ChainOfThoughtContent = memo(
|
|
157
|
-
({ className, children, ...props }: ChainOfThoughtContentProps) => {
|
|
158
|
-
const { isOpen } = useChainOfThought();
|
|
159
|
-
|
|
160
|
-
return (
|
|
161
|
-
<Collapsible open={isOpen}>
|
|
162
|
-
<CollapsibleContent
|
|
163
|
-
className={cn(
|
|
164
|
-
'mt-2 space-y-3',
|
|
165
|
-
'data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-popover-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in',
|
|
166
|
-
className
|
|
167
|
-
)}
|
|
168
|
-
{...props}
|
|
169
|
-
>
|
|
170
|
-
{children}
|
|
171
|
-
</CollapsibleContent>
|
|
172
|
-
</Collapsible>
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
export type ChainOfThoughtImageProps = ComponentProps<'div'> & {
|
|
178
|
-
caption?: string;
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
export const ChainOfThoughtImage = memo(
|
|
182
|
-
({ className, children, caption, ...props }: ChainOfThoughtImageProps) => (
|
|
183
|
-
<div className={cn('mt-2 space-y-2', className)} {...props}>
|
|
184
|
-
<div className="relative flex max-h-[22rem] items-center justify-center overflow-hidden rounded-lg bg-muted p-3">
|
|
185
|
-
{children}
|
|
186
|
-
</div>
|
|
187
|
-
{caption && <p className="text-muted-foreground text-xs">{caption}</p>}
|
|
188
|
-
</div>
|
|
189
|
-
)
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
ChainOfThought.displayName = 'ChainOfThought';
|
|
193
|
-
ChainOfThoughtHeader.displayName = 'ChainOfThoughtHeader';
|
|
194
|
-
ChainOfThoughtStep.displayName = 'ChainOfThoughtStep';
|
|
195
|
-
ChainOfThoughtSearchResults.displayName = 'ChainOfThoughtSearchResults';
|
|
196
|
-
ChainOfThoughtSearchResult.displayName = 'ChainOfThoughtSearchResult';
|
|
197
|
-
ChainOfThoughtContent.displayName = 'ChainOfThoughtContent';
|
|
198
|
-
ChainOfThoughtImage.displayName = 'ChainOfThoughtImage';
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { Alert, AlertDescription } from '../ui/alert';
|
|
4
|
-
import { Button } from '../ui/button';
|
|
5
|
-
import { cn } from '../../lib/utils';
|
|
6
|
-
import type { ToolUIPart } from 'ai';
|
|
7
|
-
import { type ComponentProps, createContext, type ReactNode, useContext } from 'react';
|
|
8
|
-
|
|
9
|
-
type ConfirmationContextValue = {
|
|
10
|
-
approval: any;
|
|
11
|
-
state: any;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const ConfirmationContext = createContext<ConfirmationContextValue | null>(null);
|
|
15
|
-
|
|
16
|
-
const useConfirmation = () => {
|
|
17
|
-
const context = useContext(ConfirmationContext);
|
|
18
|
-
|
|
19
|
-
if (!context) {
|
|
20
|
-
throw new Error('Confirmation components must be used within Confirmation');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return context;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type ConfirmationProps = ComponentProps<typeof Alert> & {
|
|
27
|
-
approval?: any;
|
|
28
|
-
state: any;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const Confirmation = ({ className, approval, state, ...props }: ConfirmationProps) => {
|
|
32
|
-
if (!approval || state === 'input-streaming' || state === 'input-available') {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return (
|
|
37
|
-
<ConfirmationContext.Provider value={{ approval, state }}>
|
|
38
|
-
<Alert className={cn('flex flex-col gap-2', className)} {...props} />
|
|
39
|
-
</ConfirmationContext.Provider>
|
|
40
|
-
);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export type ConfirmationTitleProps = ComponentProps<typeof AlertDescription>;
|
|
44
|
-
|
|
45
|
-
export const ConfirmationTitle = ({ className, ...props }: ConfirmationTitleProps) => (
|
|
46
|
-
<AlertDescription className={cn('inline', className)} {...props} />
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
export type ConfirmationRequestProps = {
|
|
50
|
-
children?: ReactNode;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export const ConfirmationRequest = ({ children }: ConfirmationRequestProps) => {
|
|
54
|
-
const { state } = useConfirmation();
|
|
55
|
-
|
|
56
|
-
// Only show when approval is requested
|
|
57
|
-
if (state !== 'approval-requested') {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return children;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export type ConfirmationAcceptedProps = {
|
|
65
|
-
children?: ReactNode;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const ConfirmationAccepted = ({ children }: ConfirmationAcceptedProps) => {
|
|
69
|
-
const { approval, state } = useConfirmation();
|
|
70
|
-
|
|
71
|
-
// Only show when approved and in response states
|
|
72
|
-
if (
|
|
73
|
-
!approval?.approved ||
|
|
74
|
-
(state !== 'approval-responded' && state !== 'output-denied' && state !== 'output-available')
|
|
75
|
-
) {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return children;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export type ConfirmationRejectedProps = {
|
|
83
|
-
children?: ReactNode;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export const ConfirmationRejected = ({ children }: ConfirmationRejectedProps) => {
|
|
87
|
-
const { approval, state } = useConfirmation();
|
|
88
|
-
|
|
89
|
-
// Only show when rejected and in response states
|
|
90
|
-
if (
|
|
91
|
-
approval?.approved !== false ||
|
|
92
|
-
(state !== 'approval-responded' && state !== 'output-denied' && state !== 'output-available')
|
|
93
|
-
) {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return children;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export type ConfirmationActionsProps = ComponentProps<'div'>;
|
|
101
|
-
|
|
102
|
-
export const ConfirmationActions = ({ className, ...props }: ConfirmationActionsProps) => {
|
|
103
|
-
const { state } = useConfirmation();
|
|
104
|
-
|
|
105
|
-
// Only show when approval is requested
|
|
106
|
-
if (state !== 'approval-requested') {
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return (
|
|
111
|
-
<div className={cn('flex items-center justify-end gap-2 self-end', className)} {...props} />
|
|
112
|
-
);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export type ConfirmationActionProps = ComponentProps<typeof Button>;
|
|
116
|
-
|
|
117
|
-
export const ConfirmationAction = (props: ConfirmationActionProps) => (
|
|
118
|
-
<Button className="h-8 px-3 text-sm" type="button" {...props} />
|
|
119
|
-
);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ConnectionLineComponent } from '@xyflow/react';
|
|
2
|
-
|
|
3
|
-
const HALF = 0.5;
|
|
4
|
-
|
|
5
|
-
export const Connection: ConnectionLineComponent = ({ fromX, fromY, toX, toY }) => (
|
|
6
|
-
<g>
|
|
7
|
-
<path
|
|
8
|
-
className="animated"
|
|
9
|
-
d={`M${fromX},${fromY} C ${fromX + (toX - fromX) * HALF},${fromY} ${fromX + (toX - fromX) * HALF},${toY} ${toX},${toY}`}
|
|
10
|
-
fill="none"
|
|
11
|
-
stroke="var(--color-ring)"
|
|
12
|
-
strokeWidth={1}
|
|
13
|
-
/>
|
|
14
|
-
<circle cx={toX} cy={toY} fill="#fff" r={3} stroke="var(--color-ring)" strokeWidth={1} />
|
|
15
|
-
</g>
|
|
16
|
-
);
|
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { Button } from '../ui/button';
|
|
4
|
-
import { HoverCard, HoverCardContent, HoverCardTrigger } from '../ui/hover-card';
|
|
5
|
-
import { Progress } from '../ui/progress';
|
|
6
|
-
import { cn } from '../../lib/utils';
|
|
7
|
-
import type { LanguageModelUsage } from 'ai';
|
|
8
|
-
import { type ComponentProps, createContext, useContext } from 'react';
|
|
9
|
-
import { getUsage } from 'tokenlens';
|
|
10
|
-
|
|
11
|
-
const PERCENT_MAX = 100;
|
|
12
|
-
const ICON_RADIUS = 10;
|
|
13
|
-
const ICON_VIEWBOX = 24;
|
|
14
|
-
const ICON_CENTER = 12;
|
|
15
|
-
const ICON_STROKE_WIDTH = 2;
|
|
16
|
-
|
|
17
|
-
type ModelId = string;
|
|
18
|
-
|
|
19
|
-
type ContextSchema = {
|
|
20
|
-
usedTokens: number;
|
|
21
|
-
maxTokens: number;
|
|
22
|
-
usage?: LanguageModelUsage;
|
|
23
|
-
modelId?: ModelId;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const ContextContext = createContext<ContextSchema | null>(null);
|
|
27
|
-
|
|
28
|
-
const useContextValue = () => {
|
|
29
|
-
const context = useContext(ContextContext);
|
|
30
|
-
|
|
31
|
-
if (!context) {
|
|
32
|
-
throw new Error('Context components must be used within Context');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return context;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export type ContextProps = ComponentProps<typeof HoverCard> & ContextSchema;
|
|
39
|
-
|
|
40
|
-
export const Context = ({ usedTokens, maxTokens, usage, modelId, ...props }: ContextProps) => (
|
|
41
|
-
<ContextContext.Provider
|
|
42
|
-
value={{
|
|
43
|
-
usedTokens,
|
|
44
|
-
maxTokens,
|
|
45
|
-
usage,
|
|
46
|
-
modelId,
|
|
47
|
-
}}
|
|
48
|
-
>
|
|
49
|
-
<HoverCard closeDelay={0} openDelay={0} {...props} />
|
|
50
|
-
</ContextContext.Provider>
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
const ContextIcon = () => {
|
|
54
|
-
const { usedTokens, maxTokens } = useContextValue();
|
|
55
|
-
const circumference = 2 * Math.PI * ICON_RADIUS;
|
|
56
|
-
const usedPercent = usedTokens / maxTokens;
|
|
57
|
-
const dashOffset = circumference * (1 - usedPercent);
|
|
58
|
-
|
|
59
|
-
return (
|
|
60
|
-
<svg
|
|
61
|
-
aria-label="Model context usage"
|
|
62
|
-
height="20"
|
|
63
|
-
role="img"
|
|
64
|
-
style={{ color: 'currentcolor' }}
|
|
65
|
-
viewBox={`0 0 ${ICON_VIEWBOX} ${ICON_VIEWBOX}`}
|
|
66
|
-
width="20"
|
|
67
|
-
>
|
|
68
|
-
<circle
|
|
69
|
-
cx={ICON_CENTER}
|
|
70
|
-
cy={ICON_CENTER}
|
|
71
|
-
fill="none"
|
|
72
|
-
opacity="0.25"
|
|
73
|
-
r={ICON_RADIUS}
|
|
74
|
-
stroke="currentColor"
|
|
75
|
-
strokeWidth={ICON_STROKE_WIDTH}
|
|
76
|
-
/>
|
|
77
|
-
<circle
|
|
78
|
-
cx={ICON_CENTER}
|
|
79
|
-
cy={ICON_CENTER}
|
|
80
|
-
fill="none"
|
|
81
|
-
opacity="0.7"
|
|
82
|
-
r={ICON_RADIUS}
|
|
83
|
-
stroke="currentColor"
|
|
84
|
-
strokeDasharray={`${circumference} ${circumference}`}
|
|
85
|
-
strokeDashoffset={dashOffset}
|
|
86
|
-
strokeLinecap="round"
|
|
87
|
-
strokeWidth={ICON_STROKE_WIDTH}
|
|
88
|
-
style={{ transformOrigin: 'center', transform: 'rotate(-90deg)' }}
|
|
89
|
-
/>
|
|
90
|
-
</svg>
|
|
91
|
-
);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export type ContextTriggerProps = ComponentProps<typeof Button>;
|
|
95
|
-
|
|
96
|
-
export const ContextTrigger = ({ children, ...props }: ContextTriggerProps) => {
|
|
97
|
-
const { usedTokens, maxTokens } = useContextValue();
|
|
98
|
-
const usedPercent = usedTokens / maxTokens;
|
|
99
|
-
const renderedPercent = new Intl.NumberFormat('en-US', {
|
|
100
|
-
style: 'percent',
|
|
101
|
-
maximumFractionDigits: 1,
|
|
102
|
-
}).format(usedPercent);
|
|
103
|
-
|
|
104
|
-
return (
|
|
105
|
-
<HoverCardTrigger asChild>
|
|
106
|
-
{children ?? (
|
|
107
|
-
<Button type="button" variant="ghost" {...props}>
|
|
108
|
-
<span className="font-medium text-muted-foreground">{renderedPercent}</span>
|
|
109
|
-
<ContextIcon />
|
|
110
|
-
</Button>
|
|
111
|
-
)}
|
|
112
|
-
</HoverCardTrigger>
|
|
113
|
-
);
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export type ContextContentProps = ComponentProps<typeof HoverCardContent>;
|
|
117
|
-
|
|
118
|
-
export const ContextContent = ({ className, ...props }: ContextContentProps) => (
|
|
119
|
-
<HoverCardContent
|
|
120
|
-
className={cn('min-w-60 divide-y overflow-hidden p-0', className)}
|
|
121
|
-
{...props}
|
|
122
|
-
/>
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
export type ContextContentHeaderProps = ComponentProps<'div'>;
|
|
126
|
-
|
|
127
|
-
export const ContextContentHeader = ({
|
|
128
|
-
children,
|
|
129
|
-
className,
|
|
130
|
-
...props
|
|
131
|
-
}: ContextContentHeaderProps) => {
|
|
132
|
-
const { usedTokens, maxTokens } = useContextValue();
|
|
133
|
-
const usedPercent = usedTokens / maxTokens;
|
|
134
|
-
const displayPct = new Intl.NumberFormat('en-US', {
|
|
135
|
-
style: 'percent',
|
|
136
|
-
maximumFractionDigits: 1,
|
|
137
|
-
}).format(usedPercent);
|
|
138
|
-
const used = new Intl.NumberFormat('en-US', {
|
|
139
|
-
notation: 'compact',
|
|
140
|
-
}).format(usedTokens);
|
|
141
|
-
const total = new Intl.NumberFormat('en-US', {
|
|
142
|
-
notation: 'compact',
|
|
143
|
-
}).format(maxTokens);
|
|
144
|
-
|
|
145
|
-
return (
|
|
146
|
-
<div className={cn('w-full space-y-2 p-3', className)} {...props}>
|
|
147
|
-
{children ?? (
|
|
148
|
-
<>
|
|
149
|
-
<div className="flex items-center justify-between gap-3 text-xs">
|
|
150
|
-
<p>{displayPct}</p>
|
|
151
|
-
<p className="font-mono text-muted-foreground">
|
|
152
|
-
{used} / {total}
|
|
153
|
-
</p>
|
|
154
|
-
</div>
|
|
155
|
-
<div className="space-y-2">
|
|
156
|
-
<Progress className="bg-muted" value={usedPercent * PERCENT_MAX} />
|
|
157
|
-
</div>
|
|
158
|
-
</>
|
|
159
|
-
)}
|
|
160
|
-
</div>
|
|
161
|
-
);
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
export type ContextContentBodyProps = ComponentProps<'div'>;
|
|
165
|
-
|
|
166
|
-
export const ContextContentBody = ({ children, className, ...props }: ContextContentBodyProps) => (
|
|
167
|
-
<div className={cn('w-full p-3', className)} {...props}>
|
|
168
|
-
{children}
|
|
169
|
-
</div>
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
export type ContextContentFooterProps = ComponentProps<'div'>;
|
|
173
|
-
|
|
174
|
-
export const ContextContentFooter = ({
|
|
175
|
-
children,
|
|
176
|
-
className,
|
|
177
|
-
...props
|
|
178
|
-
}: ContextContentFooterProps) => {
|
|
179
|
-
const { modelId, usage } = useContextValue();
|
|
180
|
-
const costUSD = modelId
|
|
181
|
-
? getUsage({
|
|
182
|
-
modelId,
|
|
183
|
-
usage: {
|
|
184
|
-
input: usage?.inputTokens ?? 0,
|
|
185
|
-
output: usage?.outputTokens ?? 0,
|
|
186
|
-
},
|
|
187
|
-
}).costUSD?.totalUSD
|
|
188
|
-
: undefined;
|
|
189
|
-
const totalCost = new Intl.NumberFormat('en-US', {
|
|
190
|
-
style: 'currency',
|
|
191
|
-
currency: 'USD',
|
|
192
|
-
}).format(costUSD ?? 0);
|
|
193
|
-
|
|
194
|
-
return (
|
|
195
|
-
<div
|
|
196
|
-
className={cn(
|
|
197
|
-
'flex w-full items-center justify-between gap-3 bg-secondary p-3 text-xs',
|
|
198
|
-
className
|
|
199
|
-
)}
|
|
200
|
-
{...props}
|
|
201
|
-
>
|
|
202
|
-
{children ?? (
|
|
203
|
-
<>
|
|
204
|
-
<span className="text-muted-foreground">Total cost</span>
|
|
205
|
-
<span>{totalCost}</span>
|
|
206
|
-
</>
|
|
207
|
-
)}
|
|
208
|
-
</div>
|
|
209
|
-
);
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
export type ContextInputUsageProps = ComponentProps<'div'>;
|
|
213
|
-
|
|
214
|
-
export const ContextInputUsage = ({ className, children, ...props }: ContextInputUsageProps) => {
|
|
215
|
-
const { usage, modelId } = useContextValue();
|
|
216
|
-
const inputTokens = usage?.inputTokens ?? 0;
|
|
217
|
-
|
|
218
|
-
if (children) {
|
|
219
|
-
return children;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (!inputTokens) {
|
|
223
|
-
return null;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const inputCost = modelId
|
|
227
|
-
? getUsage({
|
|
228
|
-
modelId,
|
|
229
|
-
usage: { input: inputTokens, output: 0 },
|
|
230
|
-
}).costUSD?.totalUSD
|
|
231
|
-
: undefined;
|
|
232
|
-
const inputCostText = new Intl.NumberFormat('en-US', {
|
|
233
|
-
style: 'currency',
|
|
234
|
-
currency: 'USD',
|
|
235
|
-
}).format(inputCost ?? 0);
|
|
236
|
-
|
|
237
|
-
return (
|
|
238
|
-
<div className={cn('flex items-center justify-between text-xs', className)} {...props}>
|
|
239
|
-
<span className="text-muted-foreground">Input</span>
|
|
240
|
-
<TokensWithCost costText={inputCostText} tokens={inputTokens} />
|
|
241
|
-
</div>
|
|
242
|
-
);
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
export type ContextOutputUsageProps = ComponentProps<'div'>;
|
|
246
|
-
|
|
247
|
-
export const ContextOutputUsage = ({ className, children, ...props }: ContextOutputUsageProps) => {
|
|
248
|
-
const { usage, modelId } = useContextValue();
|
|
249
|
-
const outputTokens = usage?.outputTokens ?? 0;
|
|
250
|
-
|
|
251
|
-
if (children) {
|
|
252
|
-
return children;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if (!outputTokens) {
|
|
256
|
-
return null;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
const outputCost = modelId
|
|
260
|
-
? getUsage({
|
|
261
|
-
modelId,
|
|
262
|
-
usage: { input: 0, output: outputTokens },
|
|
263
|
-
}).costUSD?.totalUSD
|
|
264
|
-
: undefined;
|
|
265
|
-
const outputCostText = new Intl.NumberFormat('en-US', {
|
|
266
|
-
style: 'currency',
|
|
267
|
-
currency: 'USD',
|
|
268
|
-
}).format(outputCost ?? 0);
|
|
269
|
-
|
|
270
|
-
return (
|
|
271
|
-
<div className={cn('flex items-center justify-between text-xs', className)} {...props}>
|
|
272
|
-
<span className="text-muted-foreground">Output</span>
|
|
273
|
-
<TokensWithCost costText={outputCostText} tokens={outputTokens} />
|
|
274
|
-
</div>
|
|
275
|
-
);
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
export type ContextReasoningUsageProps = ComponentProps<'div'>;
|
|
279
|
-
|
|
280
|
-
export const ContextReasoningUsage = ({
|
|
281
|
-
className,
|
|
282
|
-
children,
|
|
283
|
-
...props
|
|
284
|
-
}: ContextReasoningUsageProps) => {
|
|
285
|
-
const { usage, modelId } = useContextValue();
|
|
286
|
-
const reasoningTokens = usage?.reasoningTokens ?? 0;
|
|
287
|
-
|
|
288
|
-
if (children) {
|
|
289
|
-
return children;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
if (!reasoningTokens) {
|
|
293
|
-
return null;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
const reasoningCost = modelId
|
|
297
|
-
? getUsage({
|
|
298
|
-
modelId,
|
|
299
|
-
usage: { reasoningTokens },
|
|
300
|
-
}).costUSD?.totalUSD
|
|
301
|
-
: undefined;
|
|
302
|
-
const reasoningCostText = new Intl.NumberFormat('en-US', {
|
|
303
|
-
style: 'currency',
|
|
304
|
-
currency: 'USD',
|
|
305
|
-
}).format(reasoningCost ?? 0);
|
|
306
|
-
|
|
307
|
-
return (
|
|
308
|
-
<div className={cn('flex items-center justify-between text-xs', className)} {...props}>
|
|
309
|
-
<span className="text-muted-foreground">Reasoning</span>
|
|
310
|
-
<TokensWithCost costText={reasoningCostText} tokens={reasoningTokens} />
|
|
311
|
-
</div>
|
|
312
|
-
);
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
export type ContextCacheUsageProps = ComponentProps<'div'>;
|
|
316
|
-
|
|
317
|
-
export const ContextCacheUsage = ({ className, children, ...props }: ContextCacheUsageProps) => {
|
|
318
|
-
const { usage, modelId } = useContextValue();
|
|
319
|
-
const cacheTokens = usage?.cachedInputTokens ?? 0;
|
|
320
|
-
|
|
321
|
-
if (children) {
|
|
322
|
-
return children;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
if (!cacheTokens) {
|
|
326
|
-
return null;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const cacheCost = modelId
|
|
330
|
-
? getUsage({
|
|
331
|
-
modelId,
|
|
332
|
-
usage: { cacheReads: cacheTokens, input: 0, output: 0 },
|
|
333
|
-
}).costUSD?.totalUSD
|
|
334
|
-
: undefined;
|
|
335
|
-
const cacheCostText = new Intl.NumberFormat('en-US', {
|
|
336
|
-
style: 'currency',
|
|
337
|
-
currency: 'USD',
|
|
338
|
-
}).format(cacheCost ?? 0);
|
|
339
|
-
|
|
340
|
-
return (
|
|
341
|
-
<div className={cn('flex items-center justify-between text-xs', className)} {...props}>
|
|
342
|
-
<span className="text-muted-foreground">Cache</span>
|
|
343
|
-
<TokensWithCost costText={cacheCostText} tokens={cacheTokens} />
|
|
344
|
-
</div>
|
|
345
|
-
);
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
const TokensWithCost = ({ tokens, costText }: { tokens?: number; costText?: string }) => (
|
|
349
|
-
<span>
|
|
350
|
-
{tokens === undefined
|
|
351
|
-
? '—'
|
|
352
|
-
: new Intl.NumberFormat('en-US', {
|
|
353
|
-
notation: 'compact',
|
|
354
|
-
}).format(tokens)}
|
|
355
|
-
{costText ? <span className="ml-2 text-muted-foreground">• {costText}</span> : null}
|
|
356
|
-
</span>
|
|
357
|
-
);
|