bitte-ai-chat
Version:
Bitte AI chat component
5,494 lines • 184 kB
JavaScript
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
AssistantsMode: () => AssistantsMode,
BitteAiChat: () => BitteAiChat,
Model: () => Model,
ReviewTransaction: () => ReviewTransaction
});
module.exports = __toCommonJS(index_exports);
// src/components/BitteAiChat.tsx
var import_react19 = require("react");
// src/lib/chat.ts
var import_ai = require("ai");
var getAgentIdFromMessage = (message) => {
const { annotations } = message;
const agentIdAnnotation = annotations?.[0];
if (agentIdAnnotation && typeof agentIdAnnotation === "object") {
if ("agentId" in agentIdAnnotation && typeof agentIdAnnotation.agentId === "string") {
return agentIdAnnotation.agentId;
}
}
};
function addToolMessageToChat({
toolMessage,
messages
}) {
return messages.map((message) => {
if (message.toolInvocations) {
return {
...message,
toolInvocations: message.toolInvocations.map((toolInvocation) => {
const toolResult = toolMessage.content.find(
(tool) => tool.toolCallId === toolInvocation.toolCallId
);
if (toolResult) {
return {
...toolInvocation,
state: "result",
result: toolResult.result
};
}
return toolInvocation;
}),
annotations: message.agentId ? [{ agentId: message.agentId }] : void 0
};
}
return message;
});
}
function convertToUIMessages(messages) {
return messages.reduce((chatMessages, message) => {
const annotations = message.agentId ? [{ agentId: message.agentId }] : void 0;
if (message.role === "tool") {
return addToolMessageToChat({
toolMessage: message,
messages: chatMessages
});
}
let textContent = "";
const toolInvocations = [];
if (typeof message.content === "string") {
textContent = message.content;
} else if (Array.isArray(message.content)) {
for (const content of message.content) {
if (content.type === "text") {
textContent += content.text;
} else if (content.type === "tool-call") {
toolInvocations.push({
state: "call",
toolCallId: content.toolCallId,
toolName: content.toolName,
args: content.args
});
}
}
}
chatMessages.push({
id: message.id || (0, import_ai.generateId)(),
role: message.role,
content: textContent,
toolInvocations,
annotations
});
return chatMessages;
}, []);
}
var getTypedToolInvocations = (toolInvocation) => {
const toolName = toolInvocation.toolName;
if (toolInvocation.state === "result") {
const result = toolInvocation.result;
return { ...toolInvocation, toolName, result };
}
return { ...toolInvocation, toolName };
};
// src/lib/fetchChatHistory.ts
var fetchChatHistory = async (id, url) => {
try {
const response = await fetch(`${url}?id=${id}`, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
});
if (!response.ok) {
console.error("Failed to fetch chat history:", response.statusText);
return null;
}
const chat = await response.json();
return chat;
} catch (error) {
console.error("Error fetching chat history:", error);
return null;
}
};
// src/components/AccountContext.tsx
var import_react = require("react");
var import_jsx_runtime = require("react/jsx-runtime");
var AccountContext = (0, import_react.createContext)(void 0);
function AccountProvider({
children,
wallet: { near, evm } = {}
}) {
const [accountId, setAccountId] = (0, import_react.useState)(null);
(0, import_react.useEffect)(() => {
const getAccountId = async () => {
if (!accountId && near?.wallet) {
const accounts = await near.wallet.getAccounts();
setAccountId(
accounts?.[0]?.accountId || near.account?.accountId || null
);
}
};
getAccountId();
}, [near, accountId]);
(0, import_react.useEffect)(() => {
if (!near?.account && !near?.wallet && !evm) {
console.warn(
"No wallet or account configured - users will not be able to send transactions"
);
}
}, [near, evm]);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
AccountContext.Provider,
{
value: {
wallet: near?.wallet,
account: near?.account,
accountId,
evmWallet: evm,
evmAddress: evm?.address
},
children
}
);
}
function useAccount() {
const context = (0, import_react.useContext)(AccountContext);
if (context === void 0) {
throw new Error("useAccount must be used within an AccountProvider");
}
return context;
}
// src/components/chat/ChatContent.tsx
var import_ai2 = require("ai");
var import_react17 = require("ai/react");
var import_lucide_react13 = require("lucide-react");
var import_react18 = require("react");
// src/lib/utils.ts
var import_bn = __toESM(require("bn.js"));
var import_clsx = require("clsx");
var import_format = require("near-api-js/lib/utils/format");
var import_tailwind_merge = require("tailwind-merge");
function cn(...inputs) {
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
}
var formatName = (name, size) => {
const nameSize = size ?? 19;
return name?.length > nameSize ? `${name.slice(0, size ?? 20)}...` : name;
};
function shortenString(input, length, url) {
if (input?.length <= length * 2) {
return input;
}
if (url && input?.length) {
const urlParts = input?.split(/(https?:\/\/|\/|\?|&|=)/);
let currentLength = 0;
let result = "";
for (const part of urlParts) {
const partLength = part.length;
if (currentLength + partLength <= length) {
result += part;
currentLength += partLength;
} else {
const remaining = length - currentLength;
result += part.substring(0, remaining);
result += "...";
break;
}
}
return result;
} else {
const prefix = input?.slice(0, length);
const suffix = input?.slice(-length);
return `${prefix}...${suffix}`;
}
}
function safeJsonParse(input, defaultValue) {
try {
const parsed = typeof input === "string" ? JSON.parse(input) : input;
return typeof parsed === typeof defaultValue ? parsed : defaultValue;
} catch (error) {
console.error("Failed to parse JSON:", error);
return defaultValue;
}
}
function removeTrailingZeros(value) {
const formattedValue = Number(value).toFixed(8);
return formattedValue.replace(/\.?0+$/, "");
}
var getNearblocksURL = (accountId, txnHash, address) => {
const isTestnet = accountId?.includes("testnet");
const prefix = isTestnet ? "testnet." : "";
return !!address ? `https://${prefix}nearblocks.io/address/${address}` : `https://${prefix}nearblocks.io/txns/${txnHash}`;
};
function formatCosts(costs, gasPrice) {
if (costs && costs[0]) {
return {
gas: removeTrailingZeros(
(0, import_format.formatNearAmount)(costs[0].gas.mul(new import_bn.default(gasPrice)).toString(), 6)
),
deposit: removeTrailingZeros(
(0, import_format.formatNearAmount)(costs[0].deposit.toString(), 3)
)
};
}
return { gas: "0", deposit: "0" };
}
// src/types/types.ts
var AssistantsMode = /* @__PURE__ */ ((AssistantsMode2) => {
AssistantsMode2["DEFAULT"] = "default";
AssistantsMode2["DEBUG"] = "debug";
return AssistantsMode2;
})(AssistantsMode || {});
var Model = /* @__PURE__ */ ((Model2) => {
Model2["GPT4o"] = "gpt4o";
Model2["Grok2"] = "grok2";
Model2["Sonnet"] = "sonnet";
return Model2;
})(Model || {});
// src/components/ui/button.tsx
var import_react_slot = require("@radix-ui/react-slot");
var import_class_variance_authority = require("class-variance-authority");
var React2 = __toESM(require("react"));
var import_jsx_runtime2 = require("react/jsx-runtime");
var buttonVariants = (0, import_class_variance_authority.cva)(
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/90",
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline"
},
size: {
default: "h-10 px-4 py-2",
sm: "h-9 rounded-md px-3",
lg: "h-11 rounded-md px-8",
icon: "h-10 w-10"
}
},
defaultVariants: {
variant: "default",
size: "default"
}
}
);
var Button = React2.forwardRef(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? import_react_slot.Slot : "button";
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
Comp,
{
className: cn(buttonVariants({ variant, size, className })),
ref,
...props
}
);
}
);
Button.displayName = "Button";
// src/assets/bitte_animation.json
var bitte_animation_default = {
v: "5.12.1",
fr: 29.9700012207031,
ip: 0,
op: 96.0000039101602,
w: 1080,
h: 1080,
nm: "marcelokunze 3_v2",
ddd: 0,
assets: [],
layers: [
{
ddd: 0,
ind: 1,
ty: 3,
nm: "Adjustment Layer 1",
sr: 1,
ks: {
o: {
a: 0,
k: 100,
ix: 11
},
r: {
a: 0,
k: 0,
ix: 10
},
p: {
a: 0,
k: [
540,
540,
0
],
ix: 2,
l: 2
},
a: {
a: 0,
k: [
540,
540,
0
],
ix: 1,
l: 2
},
s: {
a: 0,
k: [
100,
100,
100
],
ix: 6,
l: 2
}
},
ao: 0,
ef: [
{
ty: 5,
nm: "Invert",
np: 4,
mn: "ADBE Invert",
ix: 1,
en: 1,
ef: [
{
ty: 7,
nm: "Channel",
mn: "ADBE Invert-0001",
ix: 1,
v: {
a: 0,
k: 1,
ix: 1
}
},
{
ty: 0,
nm: "Blend With Original",
mn: "ADBE Invert-0002",
ix: 2,
v: {
a: 0,
k: 0,
ix: 2
}
}
]
}
],
ip: -21.0000008553475,
op: 279.000011363903,
st: -21.0000008553475,
bm: 0
},
{
ddd: 0,
ind: 2,
ty: 4,
nm: "star 1 Outlines",
sr: 1,
ks: {
o: {
a: 0,
k: 100,
ix: 11
},
r: {
a: 0,
k: 0,
ix: 10
},
p: {
a: 0,
k: [
522.185,
483.019,
0
],
ix: 2,
l: 2
},
a: {
a: 0,
k: [
41.269,
41.27,
0
],
ix: 1,
l: 2
},
s: {
a: 1,
k: [
{
i: {
x: [
0.15,
0.15,
0.15
],
y: [
1,
1,
1
]
},
o: {
x: [
0.23,
0.23,
0.23
],
y: [
0,
0,
0
]
},
t: 45,
s: [
0,
0,
100
]
},
{
i: {
x: [
0.15,
0.15,
0.15
],
y: [
1,
1,
1
]
},
o: {
x: [
0.695,
0.695,
0.167
],
y: [
0,
0,
0
]
},
t: 74,
s: [
100,
100,
100
]
},
{
i: {
x: [
0.667,
0.667,
0.667
],
y: [
1,
1,
1
]
},
o: {
x: [
0.695,
0.695,
0.167
],
y: [
0,
0,
0
]
},
t: 81,
s: [
100,
100,
100
]
},
{
t: 95.0000038694293,
s: [
0,
0,
100
]
}
],
ix: 6,
l: 2
}
},
ao: 0,
shapes: [
{
ty: "gr",
it: [
{
ind: 0,
ty: "sh",
ix: 1,
ks: {
a: 0,
k: {
i: [
[
-0.883,
-0.263
],
[
0,
0
],
[
-0.503,
-0.503
],
[
-0.203,
-0.682
],
[
0,
0
],
[
-0.739,
-0.55
],
[
-0.921,
0
],
[
-0.738,
0.552
],
[
-0.264,
0.883
],
[
0,
0
],
[
-0.503,
0.503
],
[
-0.681,
0.203
],
[
0,
0
],
[
-0.551,
0.739
],
[
0,
0.922
],
[
0.551,
0.739
],
[
0.883,
0.264
],
[
0,
0
],
[
0.503,
0.502
],
[
0.203,
0.681
],
[
0,
0
],
[
0.739,
0.551
],
[
0.922,
0
],
[
0.739,
-0.551
],
[
0.263,
-0.883
],
[
0,
0
],
[
0.503,
-0.503
],
[
0.681,
-0.202
],
[
0,
0
],
[
0.551,
-0.738
],
[
0,
-0.921
],
[
-0.551,
-0.739
]
],
o: [
[
0,
0
],
[
0.681,
0.203
],
[
0.503,
0.503
],
[
0,
0
],
[
0.263,
0.883
],
[
0.739,
0.552
],
[
0.922,
0
],
[
0.739,
-0.55
],
[
0,
0
],
[
0.203,
-0.682
],
[
0.503,
-0.503
],
[
0,
0
],
[
0.883,
-0.263
],
[
0.551,
-0.739
],
[
0,
-0.921
],
[
-0.551,
-0.738
],
[
0,
0
],
[
-0.681,
-0.202
],
[
-0.503,
-0.503
],
[
0,
0
],
[
-0.264,
-0.883
],
[
-0.738,
-0.551
],
[
-0.921,
0
],
[
-0.739,
0.551
],
[
0,
0
],
[
-0.203,
0.681
],
[
-0.503,
0.502
],
[
0,
0
],
[
-0.883,
0.264
],
[
-0.551,
0.739
],
[
0,
0.922
],
[
0.551,
0.739
]
],
v: [
[
-37.962,
4.1
],
[
-14.089,
11.21
],
[
-12.285,
12.286
],
[
-11.21,
14.09
],
[
-4.1,
37.962
],
[
-2.557,
40.171
],
[
0,
41.02
],
[
2.557,
40.171
],
[
4.101,
37.962
],
[
11.21,
14.09
],
[
12.285,
12.286
],
[
14.089,
11.21
],
[
37.962,
4.1
],
[
40.171,
2.558
],
[
41.019,
0
],
[
40.171,
-2.557
],
[
37.962,
-4.1
],
[
14.089,
-11.21
],
[
12.285,
-12.284
],
[
11.21,
-14.088
],
[
4.101,
-37.962
],
[
2.557,
-40.171
],
[
0,
-41.02
],
[
-2.557,
-40.171
],
[
-4.1,
-37.962
],
[
-11.21,
-14.088
],
[
-12.285,
-12.284
],
[
-14.089,
-11.21
],
[
-37.962,
-4.1
],
[
-40.171,
-2.557
],
[
-41.019,
0
],
[
-40.171,
2.558
]
],
c: true
},
ix: 2
},
nm: "Path 1",
mn: "ADBE Vector Shape - Group",
hd: false
},
{
ty: "fl",
c: {
a: 0,
k: [
0,
0,
0,
1
],
ix: 4
},
o: {
a: 0,
k: 100,
ix: 5
},
r: 1,
bm: 0,
nm: "Fill 1",
mn: "ADBE Vector Graphic - Fill",
hd: false
},
{
ty: "tr",
p: {
a: 0,
k: [
41.269,
41.27
],
ix: 2
},
a: {
a: 0,
k: [
0,
0
],
ix: 1
},
s: {
a: 0,
k: [
100,
100
],
ix: 3
},
r: {
a: 0,
k: 0,
ix: 6
},
o: {
a: 0,
k: 100,
ix: 7
},
sk: {
a: 0,
k: 0,
ix: 4
},
sa: {
a: 0,
k: 0,
ix: 5
},
nm: "Transform"
}
],
nm: "Group 1",
np: 2,
cix: 2,
bm: 0,
ix: 1,
mn: "ADBE Vector Group",
hd: false
}
],
ip: -21.0000008553475,
op: 279.000011363903,
st: -21.0000008553475,
ct: 1,
bm: 0
},
{
ddd: 0,
ind: 3,
ty: 4,
nm: "star 2 Outlines",
sr: 1,
ks: {
o: {
a: 0,
k: 100,
ix: 11
},
r: {
a: 0,
k: 0,
ix: 10
},
p: {
a: 1,
k: [
{
i: {
x: 0.667,
y: 1
},
o: {
x: 0.693,
y: 0
},
t: 37,
s: [
540.525,
566.696,
0
],
to: [
9,
0,
0
],
ti: [
-9,
0,
0
]
},
{
i: {
x: 0.667,
y: 0.667
},
o: {
x: 0.333,
y: 0.333
},
t: 62,
s: [
594.525,
566.696,
0
],
to: [
0,
0,
0
],
ti: [
0,
0,
0
]
},
{
t: 74.0000030140818,
s: [
594.525,
566.696,
0
]
}
],
ix: 2,
l: 2
},
a: {
a: 0,
k: [
204.258,
69.681,
0
],
ix: 1,
l: 2
},
s: {
a: 1,
k: [
{
i: {
x: [
0.1,
0.1,
0.1
],
y: [
1,
1,
1
]
},
o: {
x: [
0.19,
0.19,
0.19
],
y: [
0,
0,
0
]
},
t: 0,
s: [
0,
0,
100
]
},
{
i: {
x: [
0.1,
0.1,
0.1
],
y: [
1,
1,
1
]
},
o: {
x: [
0.167,
0.167,
0.167
],
y: [
0,
0,
0
]
},
t: 34,
s: [
100,
100,
100
]
},
{
i: {
x: [
0.315,
0.315,
0.833
],
y: [
1,
1,
1
]
},
o: {
x: [
0.281,
0.281,
0.167
],
y: [
0,
0,
0
]
},
t: 81,
s: [
100,
100,
100
]
},
{
t: 95.0000038694293,
s: [
0,
0,
100
]
}
],
ix: 6,
l: 2
}
},
ao: 0,
shapes: [
{
ty: "gr",
it: [
{
ind: 0,
ty: "sh",
ix: 1,
ks: {
a: 1,
k: [
{
i: {
x: 0.271,
y: 1
},
o: {
x: 0.333,
y: 0
},
t: 31,
s: [
{
i: [
[
-1.495,
-0.445
],
[
0,
0
],
[
-0.851,
-0.852
],
[
-0.344,
-1.153
],
[
0,
0
],
[
-1.25,
-0.932
],
[
-1.561,
0
],
[
-1.251,
0.932
],
[
-0.445,
1.496
],
[
0,
0
],
[
-0.852,
0.85
],
[
-1.153,
0.343
],
[
0,
0
],
[
-0.933,
1.251
],
[
0,
1.56
],
[
0.932,
1.25
],
[
1.496,
0.445
],
[
0,
0
],
[
0.85,
0.851
],
[
0.344,
1.154
],
[
0,
0
],
[
1.251,
0.933
],
[
1.559,
0
],
[
1.25,
-0.932
],
[
0.445,
-1.495
],
[
0,
0
],
[
0.851,
-0.851
],
[
1.153,
-0.344
],
[
0,
0
],
[
0.932,
-1.251
],
[
0,
-1.56
],
[
-0.933,
-1.251
]
],
o: [
[
0,
0
],
[
1.153,
0.343
],
[
0.851,
0.85
],
[
0,
0
],
[
0.445,
1.496
],
[
1.25,
0.932
],
[
1.559,
0
],
[
1.251,
-0.932
],
[
0,
0
],
[
0.344,
-1.153
],
[
0.85,
-0.852
],
[
0,
0
],
[
1.496,
-0.445
],
[
0.932,
-1.251
],
[
0,
-1.56
],
[
-0.933,
-1.251
],
[
0,
0
],
[
-1.153,
-0.344
],
[
-0.852,
-0.851
],
[
0,
0
],
[
-0.445,
-1.495
],
[
-1.251,
-0.932
],
[
-1.561,
0
],
[
-1.25,
0.933
],
[
0,
0
],
[
-0.344,
1.154
],
[
-0.851,
0.851
],
[
0,
0
],
[
-1.495,
0.445
],
[
-0.933,
1.25
],
[
0,
1.559
],
[
0.932,
1.251
]
],
v: [
[
-0.834,
6.896
],
[
44.729,
18.975
],
[
47.783,
20.794
],
[
49.603,
23.848
],
[
61.637,
64.255
],
[
64.249,
67.995
],
[
68.578,
69.431
],
[
72.906,
67.995
],
[
75.518,
64.255
],
[
87.551,
23.848
],
[
89.372,
20.794
],
[
92.425,
18.975
],
[
132.833,
6.94
],
[
136.572,
4.328
],
[
138.008,
0
],
[
136.572,
-4.328
],
[
132.833,
-6.94
],
[
92.425,
-18.974
],
[
89.372,
-20.794
],
[
87.551,
-23.848
],
[
75.518,
-64.257
],
[
72.906,
-67.995
],
[
68.578,
-69.431
],
[
64.249,
-67.995
],
[
61.637,
-64.257
],
[
49.603,
-23.848
],
[
47.783,
-20.794
],
[
44.729,
-18.974
],
[
-0.834,
-6.985
],
[
-4.572,
-4.373
],
[
-6.008,
-0.044
],
[
-4.572,
4.284
]
],
c: true
}
]
},
{
i: {
x: 0.667,
y: 1
},
o: {
x: 0.693,
y: 0
},
t: 37,
s: [
{
i: [
[
-1.495,
-0.445
],
[
0,
0
],
[
-0.851,
-0.852
],
[
-0.344,
-1.153
],
[
0,
0
],
[
-1.25,
-0.932
],
[
-1.561,
0
],
[
-1.251,
0.932
],
[
-0.445,
1.496
],
[
0,
0
],
[
-0.852,
0.85
],
[
-1.153,
0.343
],
[
0,
0
],
[
-0.933,
1.251
],
[
0,
1.56
],
[
0.932,
1.25
],
[
1.496,
0.445
],
[
0,
0
],
[
0.85,
0.851
],
[
0.344,
1.154
],
[
0,
0
],
[
1.251,
0.933
],
[
1.559,
0
],
[
1.25,
-0.932
],
[
0.445,
-1.495
],
[
0,
0
],
[
0.851,
-0.851
],
[
1.153,
-0.344
],
[
0,
0
],
[
0.932,
-1.251
],
[
0,
-1.56
],
[
-0.933,
-1.251
]
],
o: [
[
0,
0
],
[
1.153,
0.343
],
[
0.851,
0.85
],
[
0,
0
],
[
0.445,
1.496
],
[
1.25,
0.932
],
[
1.559,
0
],
[
1.251,
-0.932
],
[
0,
0
],
[
0.344,
-1.153
],
[
0.85,
-0.852
],
[
0,
0
],
[
1.496,
-0.445
],
[
0.932,
-1.251
],
[
0,
-1.56
],
[
-0.933,
-1.251
],
[
0,
0
],
[
-1.153,
-0.344
],
[
-0.852,
-0.851
],
[
0,
0
],
[
-0.445,
-1.495
],
[
-1.251,
-0.932
],
[
-1.561,
0
],
[
-1.25,
0.933
],
[
0,
0
],
[
-0.344,
1.154
],
[
-0.851,
0.851
],
[
0,
0
],
[
-1.495,
0.445
],
[
-0.933,
1.25
],
[
0,
1.559
],
[
0.932,
1.251
]
],
v: [
[
-0.834,
6.896
],
[
44.729,
18.975
],
[
47.783,
20.794
],
[
49.603,
23.848
],
[
61.637,
64.255
],
[
64.249,
67.995
],
[
68.578,
69.431
],
[
72.906,
67.995
],
[
75.518,
64.255
],
[
87.551,
23.848
],
[
89.372,
20.794
],
[
92.425,
18.975
],
[
132.833,
6.94
],
[
136.572,
4.328
],
[
138.008,
0
],
[
136.572,
-4.328
],
[
132.833,
-6.94
],
[
92.425,
-18.974
],
[
89.372,
-20.794
],
[
87.551,
-23.848
],
[
75.518,
-64.257
],
[
72.906,
-67.995
],
[
68.578,
-69.431
],
[
64.249,
-67.995
],
[
61.637,
-64.257
],
[
49.603,
-23.848
],
[
47.783,
-20.794
],
[
44.729,
-18.974
],
[
-0.834,
-6.985
],
[
-4.572,
-4.373
],
[
-6.008,
-0.044
],
[
-4.572,
4.284
]
],
c: true
}
]
},
{
i: {
x: 0.667,
y: 1
},
o: {
x: 0.333,
y: 0
},
t: 62,
s: [
{
i: [
[
-1.495,
-0.445
],
[
0,
0
],
[
-0.851,
-0.852
],
[
-0.344,
-1.153
],
[
0,
0
],
[
-1.25,
-0.932
],
[
-1.561,
0
],
[
-1.251,
0.932
],
[
-0.445,
1.496
],
[
0,
0
],
[
-0.852,
0.85
],
[
-1.153,
0.343
],
[
0,
0
],
[
-0.933,
1.251
],
[
0,
1.56
],
[
0.932,
1.25
],
[
1.496,
0.445
],
[
0,
0
],
[
0.85,
0.851
],
[
0.344,
1.154
],
[
0,
0
],
[
1.251,
0.933
],
[
1.559,
0
],
[
1.25,
-0.932
],
[
0.445,
-1.495
],
[
0,
0
],
[
0.851,
-0.851
],
[
1.153,
-0.344
],
[
0,
0
],
[
0.932,
-1.251
],
[
0,
-1.56
],
[
-0.933,
-1.251
]
],
o: [
[
0,
0
],
[
1.153,
0.343
],
[
0.851,
0.85
],
[
0,
0
],
[
0.445,
1.496
],
[
1.25,
0.932
],
[
1.559,
0
],
[
1.251,
-0.932
],
[
0,
0
],
[
0.344,
-1.153
],
[
0.85,
-0.852
],
[
0,
0
],
[
1.496,
-0.445
],
[
0.932,
-1.251
],
[
0,
-1.56
],
[
-0.933,
-1.251
],
[
0,
0
],
[
-1.153,
-0.344
],
[
-0.852,
-0.851
],
[
0,
0
],
[
-0.445,
-1.495
],
[
-1.251,
-0.932
],
[
-1.561,
0
],
[
-1.25,
0.933
],
[
0,
0
],
[
-0.344,
1.154
],
[
-0.851,
0.851
],
[
0,
0
],
[
-1.495,
0.445
],
[
-0.933,
1.25
],
[
0,
1.559
],
[
0.932,
1.251
]
],
v: [
[
-132.834,
6.94
],
[
44.729,
18.975
],
[
47.783,
20.794
],
[
49.603,
23.848
],
[
61.637,
64.255
],
[
64.249,
67.995
],
[
68.578,
69.431
],
[
72.906,
67.995
],
[
75.518,
64.255
],
[
87.551,
23.848
],
[
89.372,
20.794
],
[
92.425,
18.975
],
[
132.833,
6.94
],
[
136.572,
4.328
],
[
138.008,
0
],
[
136.572,
-4.328
],
[
132.833,
-6.94
],
[
92.425,
-18.974
],
[
89.372,
-20.794
],
[
87.551,
-23.848
],
[
75.518,
-64.257
],
[
72.906,
-67.995
],
[
68.578,
-69.431
],
[
64.249,
-67.995
],
[
61.637,
-64.257
],
[
49.603,
-23.848
],
[
47.783,
-20.794
],
[
44.729,
-18.974
],
[
-132.834,
-6.94
],
[
-136.572,
-4.328
],
[
-138.008,
1e-3
],
[
-136.572,
4.328
]
],
c: true
}
]
},
{
t: 74.0000030140818,
s: [
{
i: [
[
-1.495,
-0.445
],
[
0,
0
],
[
-0.851,
-0.852
],
[
-0.344,
-1.153
],
[
0,
0
],
[
-1.25,
-0.932
],
[
-1.561,
0
],
[
-1.251,
0.932
],
[
-0.445,
1.496
],
[
0,
0
],
[
-0.852,
0.85
],
[
-1.153,
0.343
],
[
0,
0
],
[
-0.933,
1.251
],
[
0,
1.56
],
[
0.932,
1.25
],
[
1.496,
0.445
],
[
0,
0
],
[
0.85,
0.851
],
[
0.344,
1.154
],
[
0,
0
],
[
1.251,
0.933
],
[
1.559,
0
],
[
1.25,
-0.932
],
[
0.445,
-1.495
],
[
0,
0
],
[
0.851,
-0.851
],
[
1.153,
-0.344
],
[
0,
0
],
[
0.932,
-1.251
],
[
0,
-1.56
],
[
-0.933,
-1.251
]
],
o: [
[
0,
0
],
[
1.153,
0.343
],
[
0.851,
0.85
],
[
0,
0
],
[
0.445,
1.496
],
[
1.25,
0.932
],
[
1.559,
0
],
[
1.251,
-0.932
],
[
0,
0
],
[
0.344,
-1.153
],
[
0.85,
-0.852
],
[
0,
0
],
[
1.496,
-0.445
],
[
0.932,
-1.251
],
[
0,
-1.56
],
[
-0.933,
-1.251
],
[
0,
0
],
[
-1.153,
-0.344
],
[
-0.852,
-0.851
],
[
0,
0
],
[
-0.445,
-1.495
],
[
-1.251,
-0.932
],
[
-1.561,
0
],
[
-1.25,
0.933
],
[
0,
0
],
[
-0.344,
1.154
],
[
-0.851,
0.851
],
[
0,
0
],
[
-1.495,
0.445
],
[
-0.933,
1.25
],
[
0,
1.559
],
[
0.932,
1.251
]
],
v: [
[
-132.834,
6.94
],
[
44.729,
18.975
],
[
47.783,
20.794
],
[
49.603,
23.848
],
[
61.637,
64.255
],
[
64.249,
67.995
],
[
68.578,
69.431
],
[
72.906,
67.995
],
[
75.518,
64.255
],
[
87.551,
23.848
],
[
89.372,
20.794
],
[
92.425,
18.975
],
[
132.833,
6.94
],
[
136.572,
4.328
],
[
138.008,
0
],
[
136.572,
-4.328
],
[
132.833,
-6.94
],
[
92.425,
-18.974
],
[
89.372,
-20.794
],
[
87.551,
-23.848
],
[
75.518,
-64.257
],
[
72.906,
-67.995
],
[
68.578,
-69.431
],
[
64.249,
-67.995
],
[
61.637,
-64.257
],
[
49.603,
-23.848
],
[
47.783,
-20.794
],
[
44.729,
-18.974
],
[
-132.834,
-6.94
],
[
-136.572,
-4.328
],
[
-138.008,
1e-3
],
[
-136.572,
4.328
]
],
c: true
}
]
}
],
ix: 2
},
nm: "Path 1",
mn: "ADBE Vector Shape - Group",
hd: false
},
{
ty: "fl",
c: {
a: 0,
k: [
0,
0,
0,
1
],
ix: 4
},
o: {
a: 0,
k: 100,
ix: 5
},
r: 1,
bm: 0,
nm: "Fill 1",
mn: "ADBE Vector Graphic - Fill",
hd: false
},
{
ty: "tr",
p: {
a: 0,
k: [
138.258,
69.681
],
ix: 2
},
a: {
a: 0,
k: [
0,
0
],
ix: 1
},
s: {
a: 0,
k: [
100,
100
],
ix: 3
},
r: {
a: 0,
k: 0,
ix: 6
},
o: {
a: 0,
k: 100,
ix: 7
},
sk: {
a: 0,
k: 0,
ix: 4
},
sa: {
a: 0,
k: 0,
ix: 5
},
nm: "Transform"
}
],
nm: "Group 1",
np: 2,
cix: 2,
bm: 0,
ix: 1,
mn: "ADBE Vector Group",
hd: false
}
],
ip: -21.0000008553475,
op: 135.000005498663,
st: -21.0000008553475,
ct: 1,
bm: 0
}
],
markers: [],
props: {}
};
// src/components/chat/BitteSpinner.tsx
var import_LottiePlayerLight = __toESM(require("react-lottie-player/dist/LottiePlayerLight"));
var import_jsx_runtime3 = require("react/jsx-runtime");
var BitteSpinner = ({
width = 200,
height = 200
}) => {
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "dark:invert", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
import_LottiePlayerLight.default,
{
loop: true,
animationData: bitte_animation_default,
play: true,
speed: 1.5,
style: { width, height }
}
) });
};
// src/components/chat/ChatInput.tsx
var import_lucide_react = require("lucide-react");
var import_react3 = require("react");
// src/components/ui/textarea.tsx
var React3 = __toESM(require("react"));
var import_jsx_runtime4 = require("react/jsx-runtime");
var Textarea = React3.forwardRef(
({ className, style, ...props }, ref) => {
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
"textarea",
{
className: cn(
"flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
className
),
ref,
...props
}
);
}
);
Textarea.displayName = "Textarea";
// src/components/chat/AgentPill.tsx
var import_react2 = require("react");
var import_jsx_runtime5 = require("react/jsx-runtime");
var AgentPill = (0, import_react2.forwardRef)(
({ name }, ref) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
"div",
{
ref,
className: "w-fit rounded-full border border-dashed border-gray-40 px-2 py-1 text-xs font-semibold uppercase text-purple-100 absolute left-2 top-1/2 -translate-y-1/2",
children: name
}
)
);
AgentPill.displayName = "AgentPill";
// src/components/chat/ChatInput.tsx
var import_jsx_runtime6 = require("react/jsx-runtime");
var SmartActionsInput = ({
input,
isLoading,
agentName,
handleChange,
handleSubmit
}) => {
const agentNameRef = (0, import_react3.useRef)(null);
const [paddingLeft, setPaddingLeft] = (0, import_react3.useState)(16);
const [previousAgentName, setPreviousAgentName] = (0, import_react3.useState)("Select Agent");
(0, import_react3.useEffect)(() => {
if (agentNameRef.current) {
setPaddingLeft(agentNameRef.current.offsetWidth + 16);
} else {
setPaddingLeft(16);
}
}, [agentName]);
(0, import_react3.useEffect)(() => {
if (agentName && agentName !== previousAgentName) {
setPreviousAgentName(agentName);
}
}, [agentName]);
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
"form",
{
className: "relative mb-0 flex w-full items-center justify-center gap-4 max-lg:flex-wrap",
onSubmit: handleSubmit,
children: [
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "w-full relative", children: [
agentName ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AgentPill, { name: agentName, ref: agentNameRef }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
"div",
{
ref: agentNameRef,
className: "w-fit rounded-full border text-gray-40 border-gray-40 border-dashed px-2 py-1 text-xs font-semibold uppercase absolute left-2 top-1/2 -translate-y-1/2 text-opacity-0",
children: previousAgentName
}
),
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
Textarea,
{
placeholder: "Message Smart Actions",
style: {
paddingLeft: `${paddingLeft}px`
},
className: "h-[42px] w-full resize-none min-h-0",
onChange: handleChange,
onKeyDown: (e) => {
if (e.key === "Enter" && !e.shiftKey) {
e.preventDefault();
handleSubmit(e);
}
},
value: input
}
)
] }),
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
Button,
{
type: "submit",
disabled: !input || isLoading,
className: "h-[42px] w-full lg:w-[42px] p-0 disabled:opacity-20 bg-gray-800",
children: [
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react.ArrowUp, { className: "h-[16px] w-[16px] hidden lg:block" }),
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "lg:hidden", children: "Send" })
]
}
)
]
}
);
};
// src/components/chat/MessageGroup.tsx
var import_lucide_react12 = require("lucide-react");
// src/lib/constants.ts
var RPC_URL = "https://rpc.mainnet.near.org";
var DEFAULT_AGENT_ID = "bitte-assistant";
// src/lib/regex.ts
var isMarkdownTableString = (message) => {
const regex = /^\|.*\|.*$/gm;
return regex.test(message);
};
var isDataString = (str) => {
const cleaned = str.replace(/\\n/g, "").replace(/\s+/g, " ").replace(/['"]/g, "").trim();
const regex = /^\s*[{\[]|:\s*/;
return regex.test(cleaned);
};
// src/components/ui/accordion.tsx
var AccordionPrimitive = __toESM(require("@radix-ui/react-accordion"));
var import_lucide_react2 = require("lucide-react");
var React5 = __toESM(require("react"));
var import_jsx_runtime7 = require("react/jsx-runtime");
var Accordion = AccordionPrimitive.Root;
var AccordionItem = React5.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
AccordionPrimitive.Item,
{
ref,
className: cn("border-b", className),
...props
}
));
AccordionItem.displayName = "AccordionItem";
var AccordionTrigger = React5.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AccordionPrimitive.Header, { className: "flex", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
AccordionPrimitive.Trigger,
{
ref,
className: cn(
"flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",
className
),
...props,
children: [
children,
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_lucide_react2.ChevronDown, { className: "h-4 w-4 shrink-0 transition-transform duration-200" })
]
}
) }));
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName;
var AccordionContent = React5.forwardRef(({ className, children, style, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
AccordionPrimitive.Content,
{
ref,
className: "overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",
...props,
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: cn("pb-4 pt-0", className), children })
}
));
AccordionContent.displayName = AccordionPrimitive.Content.displayName;
// src/components/ui/card.tsx
var React6 = __toESM(require("react"));
var import_jsx_runtime8 = require("react/jsx-runtime");
var Card = React6.forwardRef(({ className, style, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
"div",
{
ref,
className: cn("rounded-lg border bg-card shadow-sm", className),
...props
}
));
Card.displayName = "Card";
var CardHeader = React6.forwardRef(({ className, style, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
"div",
{
ref,
className: cn("flex flex-col space-y-1.5 p-6", className),
...props
}
));
CardHeader.displayName = "CardHeader";
var CardTitle = React6.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
"div",
{
ref,
className: cn(
"text-2xl font-semibold leading-none tracking-tight",
className
),
...props
}
));
CardTitle.displayName = "CardTitle";
var CardDescription = React6.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
"div",
{
ref,
className: cn("text-sm text-muted-foreground", className),
...props
}
));
CardDescription.displayName = "CardDescription";
var CardContent = React6.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { ref, className: cn("p-6 pt-0", className), ...props }));
CardContent.displayName = "CardContent";
var CardFooter = React6.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
"div",
{
ref,
className: cn("flex items-center p-6 pt-0", className),
...props
}
));
CardFooter.displayName = "CardFooter";
// src/components/ui/ImageWithFallback.tsx
var import_react4 = require("react");
var import_jsx_runtime9 = require("react/jsx-runtime");
var ImageWithFallback = ({
fallbackSrc,
alt,
src,
className
}) => {
const [error, setError] = (0, import_react4.useState)(false);
(0, import_react4.useEffect)(() => {
setError(false);
}, [src]);
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
"img",
{
alt,
onError: () => setError(true),
src: error ? fallbackSrc : src,
className
}
);
};
// src/components/chat/CodeBlock.tsx
var import_jsx_runtime10 = require("react/jsx-runtime");
var CodeBlock = ({ content }) => {
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "w-full", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("pre", { className: "disable-scrollbars w-full overflow-x-auto rounded-lg bg-secondary p-4 text-secondary-foreground", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
"code",
{
className: "block w-[400px] font-mono text-sm",
"aria-label": "Code example",
children: content
}
) }) });
};
// src/components/chat/ErrorBoundary.tsx
var import_react5 = __toESM(require("react"));
var import_jsx_runtime11 = require("react/jsx-runtime");
var ErrorBoundary = class extends import_react5.default.Component {
state = { hasError: false };
static getDerivedStateFromError() {
return { hasError: true };
}
componentDidCatch(error) {
console.error("Generationerror:", error);
}
render() {
if (this.state.hasError) {
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: "my-6 overflow-auto text-center text-text-secondary", children: "Something went wrong" });
}
return this.props.children;
}
};
// src/components/chat/Message.tsx
var import_react6 = require("react");
var import_react_markdown = __toESM(require("react-markdown"));
var import_remark_gfm = __toESM(require("remark-gfm"));
var import_remark_math = __toESM(require("remark-math"));
// src/components/chat/MarkdownTable.tsx
var import_lucide_react3 = require("lucide-react");
// src/components/ui/table.tsx
var React8 = __toESM(require("react"));
var import_jsx_runtime12 = require("react/jsx-runtime");
var Table = React8.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "relative w-full overflow-auto", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
"table",
{
ref,
className: cn("w-full caption-bottom text-sm", className),
...props
}
) }));
Table.displayName = "Table";
var TableHeader = React8.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("thead", { ref, className: cn("[&_tr]:border-b", className), ...props }));
TableHeader.displayName = "TableHeader";
var TableBody = React8.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
"tbody",
{
ref,
className: cn("[&_tr:last-child]:border-0", className),
...props
}
));
TableBody.displayName = "TableBody";
var TableFooter = React8.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
"tfoot",
{
ref,
className: cn(
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
className
),
...props
}
));
TableFooter.displayName = "TableFooter";
var TableRow = React8.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
"tr",
{
ref,
className: cn(
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
className
),
...props
}
));
TableRow.displayName = "TableRow";
var TableHead = React8.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
"th",
{
ref,
className: cn(
"h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",
className
),
...props
}
));
TableHead.displayName = "TableHead";
var TableCell = React8.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
"td",
{
ref,
className: cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", className),
...props
}
));
TableCell.displayName = "TableCell";
var TableCaption = React8.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
"caption",
{
ref,
className: cn("mt-4 text-sm text-muted-foreground", className),
...props
}
));
TableCaption.displayName = "TableCaption";
// src/components/chat/MarkdownTable.tsx
var import_jsx_runtime13 = require("react/jsx-runtime");
var IMAGE_API = "https://image-cache-service-z3w7d7dnea-ew.a.run.app/media?url=";
var MarkdownTable = ({ content }) => {
const lines = content.split("\n");
const tableLines = lines.filter(
(line) => line.startsWith("|") && !line.includes("---")
);
const cells = tableLines.map(
(line) => line.split("|").slice(1, -1).map((cell) => cell.trim())
);
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(Table, { className: "mt-4 w-full", children: [
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(TableHeader, { children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(TableRow, { className: "border-none hover:bg-transparent", children: cells[0].map((header, index) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
TableHead,
{
className: "whitespace-nowrap px-4 text-left text-[12px] font-medium",
children: header
},
index
)) }) }),
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(TableBody, { children: cells.slice(1).map((row, rowIndex) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(TableRow, { className: "border-none hover:bg-transparent", children: row.map((cell, cellIndex) => {
const linkMatchQuery = cell.match(/\[Link\]\((.*)\)/);
const linkValue = linkMatchQuery?.[1];
const imageMatchQuery = cell.match(/!\[.*\]\((.*)\)/);
const imageMatch = imageMatchQuery?.[1];
const imageValue = imageMatch?.startsWith("https://") ? imageMatch : "/bitte-symbol-black.svg";
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
TableCell,
{
className: "whitespace-nowrap px-4 text-left",
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "max-w-[250px] break-words", children: linkValue ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("a", { href: linkValue, target: "_blank", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
Button,
{
variant: "ghost",
className: "flex items-center gap-2 p-0 text-shad-blue-100 hover:text-shad-blue-100",
children: [
"View",
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_lucide_react3.ArrowUpRight, { className: "h-4 w-4" })
]
}
) }) : imageMatch ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "relative h-24 w-24", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
"img",
{
src: `${IMAGE_API}${imageValue}`,
alt: `result-${cellIndex}`
}
) }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "truncate", children: cell }) })
},
cellIndex
);
}) }, rowIndex)) })
] });
};
// src/components/chat/Message.tsx
var import_jsx_runtime14 = require("react/jsx-runtime");
var MemoizedReactMarkdown = (0, import_react6.memo)(
import_react_markdown.default,
(prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.className === nextProps.className
);
var LinkRenderer = ({
href,
children,
...props
}) => {
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
"a",
{
href,
target: "_blank",
rel: "noopener noreferrer",
className: "text-blue-300",
...props,
children
}
);
};
var SAMessage = (0, import_react6.memo)(({ content }) => {
return isMarkdownTableString(content) ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MarkdownTable, { content }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
MemoizedReactMarkdown,
{
className: "prose dark:prose-invert prose-p:leading-relaxed prose-pre:p-0 break-words",
remarkPlugins: [import_remark_gfm.default, import_remark_math.default],
components: {
a: LinkRenderer
},
children: content
}
);
});
SAMessage.displayName = "SAMessage";
// src/components/chat/ShareDropButton.tsx
var import_react10 = require("react");
var import_lucide_react5 = require("lucide-react");
// src/hooks/useIsClient.ts
var import_react7 = require("react");
var useIsClient = () => {
const [isClient, setIsClient] = (0, import_react7.useState)(false);
(0, import_react7.useEffect)(() => {
setIsClient(true);
}, []);
return isClient;
};
// src/components/ui/modal/ShareModal.tsx
var import_react9 = require("react");
// src/hooks/useWindowSize.ts
var import_react8 = require("react");
var useWindowSize = () => {
const [windowSize, setWindowSize] = (0, import_react8.useState)({
width: void 0,
height: void 0
});
(0, import_react8.useEffect)(() => {
function handleResize() {
setWindowSize({
width: window.innerWidth,
height: window.innerHeight
});
}
window.addEventListener("resize", handleResize);
handleResize();
return () => window.removeEventListener("resize", handleResize);
}, []);
return windowSize;
};
// src/components/ui/dialog.tsx
var React10 = __toESM(require("react"));
var DialogPrimitive = __toESM(require("@radix-ui/react-dialog"));
var import_lucide_react4 = require("lucide-react");
var import_jsx_runtime15 = require("react/jsx-runtime");
var Dialog = DialogPrimitive.Root;
var DialogTrigger = DialogPrimitive.Trigger;
var DialogPortal = DialogPrimitive.Portal;
var DialogOverlay = React10.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
DialogPrimitive.Overlay,
{
ref,
className: cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
),
...props
}
));
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
var DialogContent = React10.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(DialogPortal, { children: [
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(DialogOverlay, {}),
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
DialogPrimitive.Content,
{
ref,
className: cn(
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
className
),
...props,
children: [
children,
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(DialogPrimitive.Close, { className: "absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground", children: [
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_lucide_react4.X, { className: "h-4 w-4" }),
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "sr-only", children: "Close" })
] })
]
}
)
] }));
DialogContent.displayName = DialogPrimitive.Content.displayName;
var DialogHeader = ({
className,
...props
}) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
"div",
{
className: cn(
"flex flex-col space-y-1.5 text-center sm:text-left",
className
),
...props
}
);
DialogHeader.displayName = "DialogHeader";
var DialogFooter = ({
className,
...props
}) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
"div",
{
className: cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
className
),
...props
}
);
DialogFooter.displayName = "DialogFooter";
var DialogTitle = React10.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
DialogPrimitive.Title,
{
ref,
className: cn(
"text-lg font-semibold leading-none tracking-tight",
className
),
...props
}
));
DialogTitle.displayName = DialogPrimitive.Title.displayName;
var DialogDescription = React10.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
DialogPrimitive.Description,
{
ref,
className: cn("text-sm text-muted-foreground", className),
...props
}
));
DialogDescription.displayName = DialogPrimitive.Description.displayName;
// src/components/ui/drawer.tsx
var React11 = __toESM(require("react"));
var import_vaul = require("vaul");
var import_jsx_runtime16 = require("react/jsx-runtime");
var Drawer = ({
shouldScaleBackground = true,
...props
}) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
import_vaul.Drawer.Root,
{
shouldScaleBackground,
...props
}
);
Drawer.displayName = "Drawer";
var DrawerTrigger = import_vaul.Drawer.Trigger;
var DrawerPortal = import_vaul.Drawer.Portal;
var DrawerClose = import_vaul.Drawer.Close;
var DrawerOverlay = React11.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
import_vaul.Drawer.Overlay,
{
ref,
className: cn("fixed inset-0 z-50 bg-black/80", className),
...props
}
));
DrawerOverlay.displayName = import_vaul.Drawer.Overlay.displayName;
var DrawerContent = React11.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(DrawerPortal, { children: [
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(DrawerOverlay, {}),
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
import_vaul.Drawer.Content,
{
ref,
className: cn(
"fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background",
className
),
...props,
children: [
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted" }),
children
]
}
)
] }));
DrawerContent.displayName = "DrawerContent";
var DrawerHeader = ({
className,
...props
}) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
"div",
{
className: cn("grid gap-1.5 p-4 text-center sm:text-left", className),
...props
}
);
DrawerHeader.displayName = "DrawerHeader";
var DrawerFooter = ({
className,
...props
}) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
"div",
{
className: cn("mt-auto flex flex-col gap-2 p-4", className),
...props
}
);
DrawerFooter.displayName = "DrawerFooter";
var DrawerTitle = React11.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
import_vaul.Drawer.Title,
{
ref,
className: cn(
"text-lg font-semibold leading-none tracking-tight",
className
),
...props
}
));
DrawerTitle.displayName = import_vaul.Drawer.Title.displayName;
var DrawerDescription = React11.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
import_vaul.Drawer.Description,
{
ref,
className: cn("text-sm text-muted-foreground", className),
...props
}
));
DrawerDescription.displayName = import_vaul.Drawer.Description.displayName;
// src/components/ui/input.tsx
var React12 = __toESM(require("react"));
var import_jsx_runtime17 = require("react/jsx-runtime");
var Input = React12.forwardRef(
({ className, type, ...props }, ref) => {
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
"input",
{
type,
className: cn(
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
className
),
ref,
...props
}
);
}
);
Input.displayName = "Input";
// src/components/ui/label.tsx
var React13 = __toESM(require("react"));
var LabelPrimitive = __toESM(require("@radix-ui/react-label"));
var import_class_variance_authority2 = require("class-variance-authority");
var import_jsx_runtime18 = require("react/jsx-runtime");
var labelVariants = (0, import_class_variance_authority2.cva)(
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
);
var Label = React13.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
LabelPrimitive.Root,
{
ref,
className: cn(labelVariants(), className),
...props
}
));
Label.displayName = LabelPrimitive.Root.displayName;
// src/components/ui/modal/ShareModal.tsx
var import_jsx_runtime19 = require("react/jsx-runtime");
var ShareModal = ({
title,
shareText,
trigger,
shareLink,
subtitle
}) => {
const [open, setOpen] = (0, import_react9.useState)(false);
const [showLinkCopiedText, setShowLinkCopiedText] = (0, import_react9.useState)(false);
const { width } = useWindowSize();
const isMobile = !!width && width < 640;
const social = {
twitter: `https://twitter.com/intent/tweet?url=${shareLink}&text=${shareText}`,
facebook: `https://www.facebook.com/sharer/sharer.php?u=${shareLink}`,
telegram: `https://telegram.me/share/url?url=${shareLink}&text=${shareText}`
};
const handleCopyLink = async () => {
const url = new URL(shareLink);
await navigator.clipboard.writeText(url.href);
setShowLinkCopiedText(true);
setTimeout(() => setShowLinkCopiedText(false), 3e3);
};
const dialogTitleInfo = /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DialogTitle, { className: "mb-2 text-[20px] font-semibold", children: title }),
subtitle && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("p", { className: "text-[14px]", children: subtitle })
] });
if (!isMobile) {
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(Dialog, { open, onOpenChange: setOpen, children: [
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DialogTrigger, { asChild: true, children: trigger }),
/* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(DialogContent, { className: "sm:w-[400px]", children: [
/* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(DialogHeader, { children: [
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DialogTitle, { className: "mb-2 text-center text-xl text-gray-800", children: title }),
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DialogDescription, { className: "text-center text-gray-800", children: subtitle })
] }),
/* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "mt-4 grid w-full max-w-sm items-center gap-1.5", children: [
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Label, { htmlFor: "smart-action-link", className: "text-gray-800", children: "Link" }),
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
Input,
{
id: "smart-action-link",
value: shareLink,
readOnly: true,
className: "text-gray-800"
}
)
] }),
/* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center gap-4", children: [
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
Button,
{
className: "w-full",
variant: "outline",
onClick: () => window.open(social.twitter, "_blank"),
children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("img", { src: "/twitter_black.svg", className: "theme-icon h-5 w-5" })
}
),
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
Button,
{
className: "w-full",
variant: "outline",
onClick: () => window.open(social.telegram, "_blank"),
children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("img", { src: "/telegram_black.svg", className: "theme-icon h-5 w-5" })
}
),
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
Button,
{
className: "w-full",
variant: "outline",
onClick: () => window.open(social.facebook, "_blank"),
children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("img", { src: "/facebook_black.svg", className: "theme-icon h-5 w-5" })
}
)
] }),
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Button, { className: "w-full", onClick: handleCopyLink, children: showLinkCopiedText ? "Copied" : "Copy Link" }) })
] })
] });
}
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(Drawer, { open, onOpenChange: setOpen, children: [
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DialogTrigger, { className: "border-0 focus:ring-0", asChild: true, children: trigger }),
/* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(DrawerContent, { className: "flex gap-4 px-2", children: [
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "text-center text-gray-800", children: dialogTitleInfo }),
/* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "mt-4 grid w-full items-center gap-1.5", children: [
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Label, { htmlFor: "smart-action-link", className: "text-gray-800", children: "Link" }),
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
Input,
{
id: "smart-action-link",
value: shareLink,
readOnly: true,
className: "text-gray-800"
}
)
] }),
/* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center gap-4", children: [
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
Button,
{
className: "w-full",
variant: "outline",
onClick: () => window.open(social.twitter, "_blank"),
children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("img", { src: "/twitter_black.svg", className: "theme-icon h-5 w-5" })
}
),
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
Button,
{
className: "w-full",
variant: "outline",
onClick: () => window.open(social.telegram, "_blank"),
children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("img", { src: "/telegram_black.svg", className: "theme-icon h-5 w-5" })
}
),
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
Button,
{
className: "w-full",
variant: "outline",
onClick: () => window.open(social.facebook, "_blank"),
children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("img", { src: "/facebook_black.svg", className: "theme-icon h-5 w-5" })
}
)
] }),
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DrawerFooter, { className: "gap-4 border-t border-shad-gray-20 p-4", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Button, { className: "w-full", onClick: handleCopyLink, children: showLinkCopiedText ? "Copied" : "Copy Link" }) }) })
] })
] });
};
var ShareModal_default = ShareModal;
// src/components/chat/ShareDropButton.tsx
var import_jsx_runtime20 = require("react/jsx-runtime");
var ShareDropButton = ({
dropId,
isSuccess,
isActions,
isApps,
hoverState
}) => {
const isClient = useIsClient();
const shareLink = (0, import_react10.useMemo)(
() => isClient ? `${window.location.origin}/claim/${dropId}` : "",
[isClient, dropId]
);
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
ShareModal_default,
{
title: "Share Token Drop",
subtitle: "Anyone who has this link and an Bitte Wallet account will be\n able to mint this token drop.",
shareLink,
shareText: "Check my Token Drop on Bitte Wallet!",
trigger: isActions ? /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
"span",
{
className: `flex cursor-pointer items-center gap-1 ${isApps ? "text-white" : "text-gray-800"}`,
children: [
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_lucide_react5.Share, { size: 16, color: isApps ? "#FFFFFF" : "#0f172a" }),
"Share"
]
}
) : isApps ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
"div",
{
className: `flex cursor-pointer items-center justify-center rounded-md border border-[#313E52] px-2 py-1 ease-out hover:border-none ${hoverState === dropId ? "border-none bg-white" : "bg-[#414D7D40] backdrop-blur-sm"} transition-all duration-500 ease-in-out`,
children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
"p",
{
className: `text-sm font-normal ${hoverState === dropId ? "text-black" : "text-white"}`,
children: "Share"
}
)
}
) : /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
Button,
{
className: !isSuccess ? "hover:bg-shad-slate-30 font-semi-bold bg-shad-white-10 text-gray-800" : "w-full bg-transparent",
...isSuccess && { variant: "outline" },
children: "Share"
}
)
}
);
};
var ShareDropButton_default = ShareDropButton;
// src/components/chat/transactions/EvmTxCard.tsx
var import_near_safe2 = require("near-safe");
var import_react12 = require("react");
var import_viem = require("viem");
// src/hooks/useTransaction.ts
var useTransaction = ({
account,
wallet,
evmWallet
}) => {
const handleTxn = async ({
transactions,
evmData
}) => {
const hasNoWalletOrAccount = !wallet && !account && !evmWallet?.address;
if (hasNoWalletOrAccount) {
throw new Error("No wallet or account provided");
}
let nearResult;
if (transactions) {
nearResult = account ? await executeWithAccount(transactions, account) : await executeWithWallet(transactions, wallet);
}
if (evmData && evmWallet) {
await executeWithEvmWallet(evmData, evmWallet);
}
return {
near: {
receipts: Array.isArray(nearResult) ? nearResult : [],
transactions: transactions || []
}
};
};
return {
handleTxn
};
};
var executeWithAccount = async (transactions, account) => {
const results = await Promise.all(
transactions.map(async (txn) => {
if (txn.actions.every((action) => action.type === "FunctionCall")) {
try {
return await account.functionCall({
contractId: txn.receiverId,
methodName: txn.actions[0].params.methodName,
args: txn.actions[0].params.args,
attachedDeposit: BigInt(txn.actions[0].params.deposit),
gas: BigInt(txn.actions[0].params.gas)
});
} catch (error) {
console.error(
`Transaction failed for contract ${txn.receiverId}, method ${txn.actions[0].params.methodName}:`,
error
);
return null;
}
}
return null;
})
);
return results.filter(
(result) => result !== null
);
};
var executeWithWallet = async (transactions, wallet) => {
if (!wallet) {
throw new Error("Can't have undefined account and wallet");
}
return wallet.signAndSendTransactions({
transactions
});
};
var executeWithEvmWallet = async (evmData, evmWallet) => {
if (!Array.isArray(evmData.params)) {
throw new Error("Invalid transaction parameters");
}
if (!evmData.params.every(
(tx) => typeof tx === "object" && "to" in tx
)) {
throw new Error("Invalid transaction parameters");
}
const txPromises = evmData.params.map((tx) => {
const rawTxParams = {
to: tx.to,
value: tx.value ? BigInt(tx.value) : BigInt(0),
data: tx.data || "0x",
from: tx.from,
gas: tx.gas ? BigInt(tx.gas) : void 0
};
return evmWallet.sendTransaction(rawTxParams);
});
await Promise.all(txPromises);
};
// src/components/chat/CopyStandard.tsx
var import_lucide_react6 = require("lucide-react");
var import_react11 = require("react");
var import_jsx_runtime21 = require("react/jsx-runtime");
var CopyStandard = ({
text,
textColor,
textSize,
charSize,
isUrl
}) => {
const [showLinkCopiedText, setShowLinkCopiedText] = (0, import_react11.useState)(false);
const { width } = useWindowSize();
const isMobile = !!width && width < 1024;
const handleCopyLink = async () => {
await navigator.clipboard.writeText(text);
setShowLinkCopiedText(true);
setTimeout(() => setShowLinkCopiedText(false), 3e3);
};
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { id: "copy", className: "cursor-pointer p-2.5", onClick: handleCopyLink, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
"span",
{
className: `relative flex items-center justify-center gap-2 ${textColor ? `text-${textColor}` : "text-shad-blue-100"} ${textSize ? `text-${textSize}` : "text-base"}`,
children: [
showLinkCopiedText ? "Copied" : isUrl ? formatName(text, isMobile ? charSize ?? 18 : charSize ?? 35) : shortenString(
text,
isMobile ? charSize ?? 18 : charSize ?? 35
),
" ",
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react6.CopyIcon, { size: 16, className: "text-shad-blue-100" })
]
}
) });
};
// src/components/chat/LoadingMessage.tsx
var import_jsx_runtime22 = require("react/jsx-runtime");
var LoadingMessage = () => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: "flex flex-col items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: "flex w-full items-center justify-center text-gray-600", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(BitteSpinner, { width: 100, height: 100 }) }) });
var LoadingMessage_default = LoadingMessage;
// src/components/chat/transactions/TransactionDetail.tsx
var import_jsx_runtime23 = require("react/jsx-runtime");
var TransactionDetail = ({
label,
value,
className
}) => /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: `flex items-center justify-between text-sm ${className}`, children: [
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "text-text-secondary", children: label }),
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "break-all text-gray-800", children: value })
] });
// src/components/chat/transactions/TransactionResult.tsx
var import_lucide_react7 = require("lucide-react");
var import_near_safe = require("near-safe");
var import_jsx_runtime24 = require("react/jsx-runtime");
var TransactionResult = ({
result: { evm, near },
accountId
}) => {
const scanUrl = evm?.txHash ? `${import_near_safe.Network.fromChainId(evm.chainId).scanUrl}/tx/${evm.txHash}` : null;
return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "mt-4", children: [
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)("p", { className: "text-center text-[14px] font-semibold", children: "Transaction success" }),
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "flex flex-col gap-4 p-6 text-[14px]", children: [
evm?.txHash && scanUrl && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "flex items-center justify-between px-6 text-[14px]", children: [
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "text-text-secondary", children: "EVM Transaction" }),
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
"a",
{
className: "flex gap-1 text-gray-800 items-center",
href: scanUrl,
target: "_blank",
rel: "noopener noreferrer",
children: [
shortenString(evm.txHash, 10),
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react7.MoveUpRight, { width: 12, height: 12 })
]
}
)
] }),
near?.receipts && near.receipts.map((receipt) => /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
"div",
{
className: "flex items-center justify-between px-6 text-[14px]",
children: [
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "text-text-secondary", children: "Near Transaction" }),
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
"a",
{
className: "flex gap-1 items-center text-gray-800",
href: getNearblocksURL(accountId, receipt.transaction.hash),
target: "_blank",
rel: "noopener noreferrer",
children: [
shortenString(receipt.transaction.hash, 10),
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react7.MoveUpRight, { width: 12, height: 12 })
]
}
)
]
},
receipt.transaction.hash
))
] })
] });
};
// src/components/chat/transactions/EvmTxCard.tsx
var import_jsx_runtime25 = require("react/jsx-runtime");
var EvmTxCard = ({ evmData }) => {
const { width } = useWindowSize();
const isMobile = !!width && width < 640;
const [errorMsg, setErrorMsg] = (0, import_react12.useState)("");
const [isLoading, setIsLoading] = (0, import_react12.useState)(false);
const [txHash, setTxHash] = (0, import_react12.useState)();
const { evmAddress, evmWallet } = useAccount();
if (!evmData)
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("p", { className: "my-6 overflow-auto text-center", children: "Unable to create evm transaction." });
if (!Array.isArray(evmData.params) || !evmData.params.every(isValidEvmParams)) {
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("p", { className: "my-6 overflow-auto text-center", children: "Invalid EVM transaction parameters." });
}
(0, import_react12.useEffect)(() => {
if (evmWallet?.hash) {
setIsLoading(false);
setTxHash(evmWallet.hash);
}
}, [evmWallet?.hash]);
const network = import_near_safe2.Network.fromChainId(evmData.chainId);
const { handleTxn } = useTransaction({ evmWallet });
const handleSmartAction = async () => {
setIsLoading(true);
try {
await handleTxn({ evmData });
} catch (error) {
setErrorMsg(error.message);
}
};
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_jsx_runtime25.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "mb-8 flex justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(Card, { className: "w-full", children: [
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(CardHeader, { className: "border-b border-slate-200 p-4 text-center md:p-6", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("p", { className: "text-xl font-semibold", children: "EVM Transaction" }) }),
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { children: evmData ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "p-6", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "flex flex-col gap-6 text-sm", children: [
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
TransactionDetail,
{
label: "Chain ID",
value: shortenString(
evmData.chainId.toString(),
isMobile ? 13 : 21
)
}
),
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(TransactionDetail, { label: "Network", value: network.name }),
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
Accordion,
{
type: "single",
collapsible: true,
defaultValue: "transaction-0",
children: evmData.params.map((transaction, index) => /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
AccordionItem,
{
value: `transaction-${index}`,
className: "border-0",
children: [
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(AccordionTrigger, { className: "pt-0 hover:no-underline", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "flex items-center justify-between text-sm", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("p", { className: "text-text-secondary", children: [
"Transaction ",
index + 1
] }) }) }),
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(AccordionContent, { className: "flex flex-col gap-6 border-0", children: [
transaction.to && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
TransactionDetail,
{
label: "To",
className: "-mr-2.5",
value: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
CopyStandard,
{
text: transaction.to,
textSize: "sm",
textColor: "gray-800",
charSize: isMobile ? 7 : 12
}
)
}
),
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
TransactionDetail,
{
label: "Value",
value: transaction.value ? (0, import_viem.formatEther)(BigInt(transaction.value)) : "0"
}
),
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
TransactionDetail,
{
label: "Data",
value: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
CopyStandard,
{
text: transaction.data || "0x",
textSize: "sm",
charSize: isMobile ? 10 : 15
}
)
}
)
] })
]
},
transaction.to
))
}
)
] }) }) : null }),
errorMsg && !isLoading ? /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "flex flex-col items-center gap-4 px-6 pb-6 text-center text-sm", children: [
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("p", { className: "text-red-300", children: [
"An error occurred trying to execute your transaction: ",
errorMsg,
"."
] }),
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
Button,
{
className: "w-1/2",
variant: "outline",
onClick: () => {
setErrorMsg("");
},
children: "Dismiss"
}
)
] }) : null,
isLoading ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(LoadingMessage_default, {}) : null,
txHash ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
TransactionResult,
{
result: { evm: { txHash, chainId: evmData.chainId } },
accountId: evmAddress
}
) : null,
!isLoading && !errorMsg && !txHash ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(CardFooter, { className: "flex items-center gap-6", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Button, { variant: "outline", className: "w-1/2", children: "Decline" }),
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
Button,
{
className: "w-1/2",
onClick: handleSmartAction,
disabled: isLoading,
children: isLoading ? "Confirming..." : "Approve"
}
)
] }) }) : null
] }) }) });
};
var isValidEvmParams = (data) => {
return typeof data === "object" && data !== null && "to" in data && typeof data.to === "string" && data.to.startsWith("0x");
};
// src/components/chat/transactions/ReviewTransaction.tsx
var import_bn4 = __toESM(require("bn.js"));
var import_react16 = require("react");
// src/hooks/useAccountBalance.ts
var import_react13 = require("react");
function useAccountBalance(account) {
const [balance, setBalance] = (0, import_react13.useState)(null);
(0, import_react13.useEffect)(() => {
const fetchBalance = async () => {
if (!account) return;
try {
const accountBalance = await account.getAccountBalance();
setBalance(Number(accountBalance.available));
} catch (error) {
console.error("Error fetching balance:", error);
}
};
if (account) {
fetchBalance();
}
}, [account]);
return { balance };
}
// src/hooks/useTxnFees.ts
var import_bn2 = __toESM(require("bn.js"));
var import_format2 = require("near-api-js/lib/utils/format");
var import_viem2 = require("viem");
var useTxnFees = (transactions, costs, gasPrice) => {
const feeLimitTgasBN = transactions?.reduce(
(acc, txn) => costs && costs.length > 0 ? costs[transactions.indexOf(txn)]?.gas : acc,
new import_bn2.default(0)
) || new import_bn2.default(0);
const feeLimitTgas = (0, import_viem2.formatUnits)(BigInt(feeLimitTgasBN.toString()), 12);
const feeLimitNear = (0, import_format2.formatNearAmount)(
feeLimitTgasBN.mul(new import_bn2.default(gasPrice)).toString(),
6
);
const totalDeposit = transactions?.reduce(
(acc, txn) => acc + (costs && costs.length > 0 ? parseFloat(
removeTrailingZeros(
(0, import_format2.formatNearAmount)(
costs[transactions.indexOf(txn)]?.deposit?.toString() || "0",
3
)
)
) : 0),
0
);
return {
totalGas: feeLimitNear,
totalDeposit,
feeLimitTgas
};
};
// src/hooks/useTxnPrice.ts
var import_getLatestGasPrice = require("@mintbase-js/rpc/lib/methods/getLatestGasPrice");
var import_bn3 = __toESM(require("bn.js/"));
var import_format3 = require("near-api-js/lib/utils/format");
var import_react14 = require("react");
var useTxnPrice = (balance, transactions) => {
const [hasBalance, setHasBalance] = (0, import_react14.useState)(true);
const [loaded, setLoaded] = (0, import_react14.useState)(false);
const [priceState, setPriceState] = (0, import_react14.useState)({
gasPrice: "0",
costs: [],
price: "0"
});
const gasPriceFetched = (0, import_react14.useRef)(false);
const costsCalculated = (0, import_react14.useRef)(false);
const updatePriceState = (updates) => {
setPriceState((prevState) => ({ ...prevState, ...updates }));
};
const COSTS = {
CreateAccount: new import_bn3.default(42e10),
Transfer: new import_bn3.default(45e10),
Stake: new import_bn3.default(5e10),
AddFullAccessKey: new import_bn3.default(42e10),
DeleteKey: new import_bn3.default(41e10)
};
(0, import_react14.useEffect)(() => {
const definePrice = async () => {
try {
const currentGasPrice = await (0, import_getLatestGasPrice.getLatestGasPrice)(RPC_URL);
updatePriceState({ gasPrice: currentGasPrice.toString() });
gasPriceFetched.current = true;
} catch (error) {
console.error("Failed to fetch gas price:", error);
updatePriceState({ gasPrice: "100000000" });
}
};
if (priceState?.gasPrice === "0") {
definePrice();
}
}, [priceState?.gasPrice]);
(0, import_react14.useEffect)(() => {
const defineCosts = () => {
if (!transactions || transactions.length === 0) return;
const costs = transactions.map((txn) => {
const actionCosts = txn.actions.map((action) => {
switch (action.type) {
case "FunctionCall":
return {
deposit: new import_bn3.default(action.params.deposit || "0"),
gas: new import_bn3.default(action.params.gas)
};
case "Transfer":
return {
deposit: new import_bn3.default(action.params.deposit || "0"),
gas: COSTS[action.type]
};
default:
return {
deposit: new import_bn3.default("0"),
gas: COSTS[action.type]
};
}
});
return actionCosts.reduce((acc, x) => ({
deposit: acc.deposit.add(x.deposit),
gas: acc.gas.add(x.gas)
}));
});
if (JSON.stringify(priceState.costs) !== JSON.stringify(costs)) {
updatePriceState({ costs });
}
const { deposit } = costs.reduce((acc, x) => ({
deposit: acc.deposit.add(x.deposit),
gas: acc.gas.add(x.gas)
}));
const hasBalance2 = deposit.lt(balance);
updatePriceState({
price: deposit.toString()
});
if (hasBalance2 !== hasBalance2) {
setHasBalance(hasBalance2);
}
if (!loaded) {
setLoaded(true);
}
costsCalculated.current = true;
};
if (!costsCalculated.current && Number(priceState?.gasPrice) !== 0 && balance !== void 0) {
defineCosts();
}
}, [priceState?.gasPrice, balance, transactions]);
const otherTokensAmount = (0, import_react14.useMemo)(() => {
if (!transactions?.length) return;
return transactions.map((txn) => {
const functionCallAction = txn.actions.find(
(action) => action.type === "FunctionCall" && action.params.methodName !== "storage_deposit"
);
if (!functionCallAction) return null;
const args = functionCallAction?.params?.args;
return "amount" in args && typeof args?.amount === "string" && args?.amount || null;
}).find((amount2) => amount2 !== null);
}, [transactions]);
const amount = (0, import_react14.useMemo)(() => {
const costsAmount = priceState.costs?.[0]?.deposit && (0, import_format3.formatNearAmount)(priceState.costs?.[0]?.deposit.toString(), 3);
if (["0", "0.000", null, void 0, ""].includes(costsAmount) || isNaN(Number(costsAmount))) {
return (0, import_format3.formatNearAmount)(otherTokensAmount || "0", 3);
} else {
return costsAmount;
}
}, [priceState.price, otherTokensAmount, priceState?.costs]);
const memoizedReturn = (0, import_react14.useMemo)(() => {
return {
amount,
gasPrice: priceState?.gasPrice,
hasBalance: !!loaded ? hasBalance : true,
costs: priceState.costs,
loaded
};
}, [amount, priceState?.gasPrice, hasBalance, priceState?.costs, loaded]);
return memoizedReturn;
};
// src/components/ui/badge.tsx
var import_class_variance_authority3 = require("class-variance-authority");
var import_jsx_runtime26 = require("react/jsx-runtime");
var badgeVariants = (0, import_class_variance_authority3.cva)(
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
{
variants: {
variant: {
default: "border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
secondary: "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
destructive: "border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
outline: "text-foreground"
}
},
defaultVariants: {
variant: "default"
}
}
);
function Badge({ className, variant, ...props }) {
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: cn(badgeVariants({ variant }), className), ...props });
}
// src/components/chat/transactions/TxnBadge.tsx
var import_jsx_runtime27 = require("react/jsx-runtime");
var TxnBadge = ({ transactionType }) => {
let styleClass = "";
let displayName = "";
switch (transactionType) {
case "nft_batch_mint":
case "mint":
styleClass = "bg-shad-white-10 text-shad-slate-20";
displayName = "Mint";
break;
case "nft_transfer":
styleClass = "bg-shad-bg-light-blue-10 text-shad-blue-100";
displayName = "Transfer";
break;
case "nft_approve":
styleClass = "bg-light-purple text-purple-100";
displayName = "List";
break;
case "nft_batch_burn":
styleClass = "bg-shad-error-5 text-shad-error";
displayName = "Burn";
break;
case "buy":
styleClass = "bg-shad-light-green text-shad-green-20";
displayName = "Buy";
break;
case "ft_transfer":
case "Send":
styleClass = "bg-shad-light-green text-shad-green-20";
displayName = "Send";
break;
default:
styleClass = "bg-shad-white-10 text-shad-slate-20";
displayName = transactionType;
}
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Badge, { className: `px-2 ${styleClass}`, children: displayName });
};
var TxnBadge_default = TxnBadge;
// src/components/chat/transactions/TxnDetailMultipleAction.tsx
var import_lucide_react9 = require("lucide-react");
// src/components/chat/transactions/TxAccordion.tsx
var import_lucide_react8 = require("lucide-react");
var import_react15 = require("react");
var import_jsx_runtime28 = require("react/jsx-runtime");
var TxAccordion = ({
label,
methodName,
children
}) => {
const [isOpen, setIsOpen] = (0, import_react15.useState)(false);
const toggleAccordion = () => {
setIsOpen((prevIsOpen) => !prevIsOpen);
};
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(import_jsx_runtime28.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: "flex items-center justify-between", children: [
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: "text-[14px] text-text-secondary", children: label }),
/* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: "flex cursor-pointer gap-0.5", onClick: toggleAccordion, children: [
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { className: "flex items-center justify-center bg-shad-white-10 p-1 px-2 text-[14px] text-text-primary", children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("code", { children: methodName }) }),
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: "flex w-[30px] items-center justify-center rounded-r-sm bg-shad-white-10 text-text-primary", children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
import_lucide_react8.ChevronDown,
{
className: `${isOpen ? "rotate-180" : ""}`,
width: 16
}
) })
] })
] }),
isOpen && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: "mt-2 w-full", children })
] });
};
var TxAccordion_default = TxAccordion;
// src/components/chat/transactions/TxnDetailMultipleAction.tsx
var import_jsx_runtime29 = require("react/jsx-runtime");
var DetailMethods = ({
action,
method
}) => {
return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_jsx_runtime29.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(TxAccordion_default, { label: "Function Call", methodName: method, children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: "overflow-x-auto rounded bg-shad-white-10 p-2 text-sm", children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("pre", { className: "p-2 md:p-4", children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("code", { children: JSON.stringify(action, null, 2) }) }) }) }) });
};
var TxnDetailMultipleAction = ({
data,
accountId,
actions,
showDetails
}) => {
const { transaction } = data;
const contractName = transaction.receiverId;
return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_jsx_runtime29.Fragment, { children: showDetails && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: "flex flex-col", children: transaction?.actions?.[0].type === "FunctionCall" && /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "relative flex w-full flex-col gap-4 rounded p-6", children: [
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { className: "text-sm font-semibold text-gray-800", children: "Contract Details" }),
/* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex flex-col items-start justify-start gap-2 text-sm md:flex-row md:items-center md:justify-between md:gap-0 md:space-x-4", children: [
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { className: "text-text-secondary", children: "For Contract" }),
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { className: "cursor-pointer", children: /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(
"a",
{
className: "flex gap-1 items-center text-gray-800",
href: getNearblocksURL(accountId, void 0, contractName),
target: "_blank",
children: [
shortenString(contractName, 14),
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_lucide_react9.MoveUpRight, { width: 12, height: 12 })
]
}
) })
] }),
actions.length > 1 ? actions.map((action, idx) => {
return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
DetailMethods,
{
action,
method: action.params.methodName
},
idx
);
}) : null
] }) }) });
};
// src/components/chat/transactions/multiple-transactions/MultipleTxnMultiAction.tsx
var import_jsx_runtime30 = require("react/jsx-runtime");
var MultipleTxnMultiActionDetails = ({
accountId,
transaction,
modifiedUrl,
showDetails,
showTxnDetail,
costs,
gasPrice
}) => {
return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_jsx_runtime30.Fragment, { children: transaction.map((txn, txnIdx) => {
const txnData = {
// TODO: Ensure that the actions are always FunctionCallAction.
transaction: txn,
showDetails,
modifiedUrl,
gasPrice,
...formatCosts(costs, gasPrice)
};
return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
TxnDetailMultipleAction,
{
accountId,
data: txnData,
showDetails: showTxnDetail,
actions: txnData.transaction.actions
},
txnIdx
);
}) });
};
// src/components/chat/transactions/TxnDetail.tsx
var import_lucide_react10 = require("lucide-react");
var import_jsx_runtime31 = require("react/jsx-runtime");
var TxnDetail = ({
data,
showDetails,
showTitle,
methodName,
accountId
}) => {
const { transaction } = data;
let method = methodName;
if (!method && transaction?.actions?.[0]?.type == "FunctionCall") {
method = transaction.actions[0].params.methodName;
}
const contractName = transaction.receiverId;
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_jsx_runtime31.Fragment, { children: !!showDetails && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: "flex flex-col", children: transaction?.actions?.[0].type === "FunctionCall" && /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", { className: "relative flex w-full flex-col gap-4 rounded p-6", children: [
showTitle ? /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("span", { className: "text-sm font-semibold text-gray-800", children: "Contract Details" }) : null,
/* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", { className: "flex flex-col items-start justify-start gap-2 text-sm md:flex-row md:items-center md:justify-between md:gap-0 md:space-x-4", children: [
/* @__PURE__ */ (0, import_jsx_runtime31.jsx)("span", { className: "text-text-secondary", children: "For Contract" }),
/* @__PURE__ */ (0, import_jsx_runtime31.jsx)("span", { className: "cursor-pointer", children: /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(
"a",
{
className: "flex gap-1 items-center text-gray-800",
href: getNearblocksURL(accountId, void 0, contractName),
target: "_blank",
children: [
shortenString(contractName, 14),
/* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_lucide_react10.MoveUpRight, { width: 12, height: 12 })
]
}
) })
] }),
method && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_jsx_runtime31.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(TxAccordion_default, { label: "Function Call", methodName: method, children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: "overflow-x-auto rounded bg-shad-white-10 p-2 text-sm text-text-primary", children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("pre", { className: "p-2 md:p-4", children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("code", { children: JSON.stringify(
transaction?.actions?.[0].params?.args,
null,
2
) }) }) }) }) })
] }) }) });
};
// src/components/chat/transactions/multiple-transactions/MultipleTxnSingleAction.tsx
var import_jsx_runtime32 = require("react/jsx-runtime");
var MultipleTxnSingleActionDetail = ({
accountId,
transaction,
modifiedUrl,
showDetails,
showTxnDetail,
gasPrice,
costs
}) => {
return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(import_jsx_runtime32.Fragment, { children: transaction.map((txn, idx) => {
const txnData = {
transaction: txn,
showDetails,
modifiedUrl,
gasPrice,
...formatCosts(costs, gasPrice)
};
return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("div", { className: "mb-1", children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
TxnDetail,
{
accountId,
showTitle: idx === 0,
data: txnData,
showDetails: showTxnDetail
}
) }, idx);
}) });
};
// src/components/chat/transactions/multiple-transactions/MultipleTxnDetail.tsx
var import_jsx_runtime33 = require("react/jsx-runtime");
var MultipleTxnDetail = ({
accountId,
transaction,
modifiedUrl,
showDetails,
showTxnDetail,
costs,
gasPrice
}) => {
const hasMultipleActions = transaction.every(
(tx) => tx.actions && tx.actions.length > 1
);
return hasMultipleActions ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
MultipleTxnMultiActionDetails,
{
accountId,
costs,
gasPrice,
transaction,
modifiedUrl,
showDetails,
showTxnDetail
}
) : /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
MultipleTxnSingleActionDetail,
{
accountId,
costs,
gasPrice,
transaction,
modifiedUrl,
showDetails,
showTxnDetail
}
);
};
// src/components/chat/transactions/ShowDetailsBtn.tsx
var import_lucide_react11 = require("lucide-react");
var import_jsx_runtime34 = require("react/jsx-runtime");
var ShowDetailsBtn = ({
setShowDetails,
showDetails,
displayName
}) => {
return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(
"div",
{
className: "flex cursor-pointer items-center justify-center gap-2 bg-shad-white-30 py-4",
onClick: () => setShowDetails(!showDetails),
children: [
showDetails ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_lucide_react11.ChevronsDownUp, { width: 16, height: 16, color: "#64748B" }) : /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_lucide_react11.ChevronsUpDown, { width: 16, height: 16, color: "#64748B" }),
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("span", { className: "text-[12px] text-text-secondary", children: displayName })
]
}
);
};
// src/components/chat/transactions/single-transaction/SingleTxnMultipleAction.tsx
var import_jsx_runtime35 = require("react/jsx-runtime");
var SingleTxnMultipleAction = ({
transaction,
accountId,
modifiedUrl,
showDetails,
showTxnDetail,
costs,
gasPrice
}) => {
const txnData = {
transaction: transaction[0],
showDetails,
modifiedUrl,
gasPrice,
...formatCosts(costs, gasPrice)
};
return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
TxnDetailMultipleAction,
{
accountId,
data: txnData,
showDetails: showTxnDetail,
actions: txnData.transaction.actions
}
);
};
// src/components/chat/transactions/single-transaction/SingleTxnSingleAction.tsx
var import_jsx_runtime36 = require("react/jsx-runtime");
var SingleTxnSingleAction = ({
accountId,
transaction,
modifiedUrl,
showDetails,
showTxnDetail,
costs,
gasPrice
}) => {
const txnData = {
transaction: transaction[0],
showDetails,
modifiedUrl,
gasPrice,
...formatCosts(costs, gasPrice)
};
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
TxnDetail,
{
accountId,
showTitle: true,
data: txnData,
showDetails: showTxnDetail
}
);
};
// src/components/chat/transactions/single-transaction/SingleTxnDetail.tsx
var import_jsx_runtime37 = require("react/jsx-runtime");
var SingleTxnDetail = ({
accountId,
costs,
gasPrice,
transaction,
modifiedUrl,
showDetails,
showTxnDetail
}) => {
const hasMultipleActions = transaction?.[0]?.actions?.length > 1;
return hasMultipleActions ? /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
SingleTxnMultipleAction,
{
accountId,
costs,
gasPrice,
transaction,
modifiedUrl,
showDetails,
showTxnDetail
}
) : /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
SingleTxnSingleAction,
{
accountId,
costs,
gasPrice,
transaction,
modifiedUrl,
showDetails,
showTxnDetail
}
);
};
// src/components/chat/transactions/TxnFees.tsx
var import_jsx_runtime38 = require("react/jsx-runtime");
var TxnFees = ({
transaction,
operation,
costs,
gasPrice
}) => {
const { totalGas, totalDeposit, feeLimitTgas } = useTxnFees(
transaction,
costs,
gasPrice
);
const showNoTxnFeeHighlight = operation?.operation === "relay" || operation?.operation === "sponsor";
return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className: "px-6", children: /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: "relative mb-1 flex w-full flex-col gap-4 rounded border-b border-slate-200 py-6", children: [
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)("span", { className: "text-sm font-semibold text-gray-800", children: "Network Fees" }),
/* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: "flex flex-col items-start justify-start text-sm md:flex-row md:items-center md:justify-between md:gap-0 md:space-x-4", children: [
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)("span", { className: "text-text-secondary", children: "Estimated Fees" }),
/* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: "flex flex-col", children: [
/* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(
"span",
{
className: `text-gray-800 ${showNoTxnFeeHighlight ? "line-through" : ""}`,
children: [
Number(totalGas).toFixed(5),
" NEAR"
]
}
),
showNoTxnFeeHighlight ? /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("span", { className: "text-end text-shad-green-30", children: "0 NEAR" }) : null
] })
] }),
/* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: "flex flex-col items-start justify-start text-sm md:flex-row md:items-center md:justify-between md:gap-0 md:space-x-4", children: [
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)("span", { className: "text-text-secondary", children: "Fee Limit" }),
/* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("span", { className: "text-gray-800", children: [
feeLimitTgas,
" ",
"",
"Tgas"
] })
] }),
/* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: "flex flex-col items-start justify-start text-sm md:flex-row md:items-center md:justify-between md:gap-0 md:space-x-4", children: [
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)("span", { className: "text-text-secondary", children: "Deposit" }),
/* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("span", { className: "text-gray-800", children: [
totalDeposit,
" ",
"",
"NEAR"
] })
] })
] }) });
};
// src/components/chat/transactions/TxnListWrapper.tsx
var import_jsx_runtime39 = require("react/jsx-runtime");
var TxnListWrapper = ({
accountId,
costs,
gasPrice,
transaction,
modifiedUrl,
showDetails,
showTxnDetail,
setShowTxnDetail,
operation
}) => {
return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: "mx-auto flex w-full flex-col gap-1", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: "flex w-full flex-col justify-center rounded", children: [
/* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
ShowDetailsBtn,
{
setShowDetails: setShowTxnDetail,
showDetails: showTxnDetail,
displayName: "Transaction Details"
}
),
showTxnDetail ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
TxnFees,
{
costs: costs || [],
gasPrice: gasPrice || "",
transaction,
operation
}
) : null,
transaction?.length > 1 ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
MultipleTxnDetail,
{
accountId,
costs: costs || [],
gasPrice: gasPrice || "",
transaction,
modifiedUrl,
showDetails,
showTxnDetail
}
) : /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
SingleTxnDetail,
{
accountId,
costs: costs || [],
gasPrice: gasPrice || "",
transaction,
modifiedUrl,
showDetails,
showTxnDetail
}
)
] }) });
};
// src/components/chat/transactions/ReviewTransaction.tsx
var import_jsx_runtime40 = require("react/jsx-runtime");
var ReviewTransaction = ({
transactions,
warnings,
walletLoading,
chatId
}) => {
const [showTxnDetail, setShowTxnDetail] = (0, import_react16.useState)(false);
const [errorMsg, setErrorMsg] = (0, import_react16.useState)("");
const [result, setResult] = (0, import_react16.useState)();
const [isLoading, setIsLoading] = (0, import_react16.useState)(false);
const { wallet, account, accountId } = useAccount();
const { handleTxn } = useTransaction({
account,
wallet
});
const { balance } = useAccountBalance(account);
const { costs, gasPrice } = useTxnPrice(new import_bn4.default(balance || 0), transactions);
const { totalDeposit } = useTxnFees(transactions, costs, gasPrice);
const loading = walletLoading || isLoading;
const { width } = useWindowSize();
const isMobile = !!width && width < 640;
if (!transactions || transactions.length === 0) {
return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("p", { className: "my-6 overflow-auto text-center text-text-secondary", children: "Unable to create transaction." });
}
const firstAction = transactions[0]?.actions[0];
const isTransfer = firstAction?.type === "Transfer";
const isFunctionCall = firstAction?.type === "FunctionCall";
const isMint = isFunctionCall && firstAction.params.methodName === "mint";
const transactionType = isTransfer ? "Send" : transactions.length > 1 ? "multi" : firstAction?.type === "FunctionCall" ? firstAction.params.methodName : "unknown";
const to = shortenString(transactions[0]?.receiverId, isMobile ? 13 : 15);
const txArgs = isFunctionCall ? safeJsonParse(firstAction.params?.args, {}) : null;
let txImage = null;
if (txArgs && typeof txArgs === "object" && "metadata" in txArgs) {
const metadata = safeJsonParse(txArgs.metadata, {});
if (metadata && typeof metadata === "object" && "media" in metadata && typeof metadata.media === "string") {
txImage = metadata.media;
}
}
const handleSmartAction = async () => {
setIsLoading(true);
setErrorMsg("");
if (chatId) {
sessionStorage.setItem("chatId", chatId);
}
try {
const successInfo = await handleTxn({
transactions
});
if (successInfo?.near?.receipts?.length > 0) {
setResult(successInfo);
}
} catch (error) {
setErrorMsg(error.message);
} finally {
setIsLoading(false);
}
};
return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(Card, { children: [
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(CardHeader, { className: "border-b border-slate-200 text-center", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("p", { className: "text-[20px] font-semibold", children: "Review Transaction" }) }),
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { children: [
isMint && txImage ? /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "border-b border-slate-200", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "p-6", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex items-center justify-between text-[14px]", children: [
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "text-text-secondary", children: "Asset" }),
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
"img",
{
src: `${txImage.includes("https://") ? txImage : `https://arweave.net/${txImage}`}`,
width: 64,
height: 64,
className: "rounded-md"
}
)
] }) }) }) : null,
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "p-6", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex items-center justify-between text-[14px]", children: [
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "text-text-secondary", children: "Tx Type" }),
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(TxnBadge_default, { transactionType })
] }) }),
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex flex-col gap-6 p-6", children: [
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex items-center justify-between text-[14px]", children: [
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "text-text-secondary", children: "Amount" }),
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "font-semibold text-gray-800", children: [
totalDeposit,
" NEAR"
] })
] }),
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex items-center justify-between text-[14px]", children: [
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "text-text-secondary", children: "From" }),
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "text-gray-800", children: accountId })
] }),
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex items-center justify-between text-[14px]", children: [
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "text-text-secondary", children: "To" }),
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "text-gray-800", children: to })
] })
] }),
warnings && warnings.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "px-6 pb-8", children: [
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "border-t p-4 border-slate-200" }),
warnings.map((warning, index) => /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(
"div",
{
className: "flex items-center justify-between text-sm",
children: [
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "text-red-500", children: "Warning" }),
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "text-gray-800", children: warning.message })
]
},
index
))
] }),
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
TxnListWrapper,
{
transaction: transactions,
accountId: accountId || "",
costs: costs || [],
gasPrice: gasPrice || "0",
showDetails: showTxnDetail,
modifiedUrl: `https://wallet.bitte.ai`,
setShowTxnDetail,
showTxnDetail
}
)
] }),
errorMsg && !loading ? /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex flex-col items-center gap-4 px-6 pb-6 text-center text-sm", children: [
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("p", { className: "text-red-300", children: [
"An error occurred trying to execute your transaction: ",
errorMsg,
"."
] }),
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
Button,
{
className: "w-1/2",
variant: "outline",
onClick: () => {
setErrorMsg("");
},
children: "Dismiss"
}
)
] }) : null,
loading ? /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(LoadingMessage_default, {}) : null,
result && !loading ? /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(TransactionResult, { result, accountId }) : null,
!loading && !result && !errorMsg && accountId ? /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(CardFooter, { className: "flex items-center gap-6", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_jsx_runtime40.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Button, { variant: "outline", className: "w-1/2", children: "Decline" }),
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Button, { className: "w-1/2", onClick: handleSmartAction, children: "Approve" })
] }) }) : null
] });
};
// src/components/chat/MessageGroup.tsx
var import_jsx_runtime41 = require("react/jsx-runtime");
var MessageGroup = ({
groupKey,
messages,
accountId,
creator,
isLoading,
agentImage,
agentName,
chatId
}) => {
return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { children: messages?.map((message, index) => {
let agentId = getAgentIdFromMessage(message);
if (!agentId) {
agentId = DEFAULT_AGENT_ID;
}
const uniqueKey = `${groupKey}-${index}`;
if (message.toolInvocations) {
for (const invocation of message.toolInvocations) {
const { toolName, state, result } = getTypedToolInvocations(
invocation
);
if (state !== "result") {
continue;
}
if (toolName === "generate-transaction" /* GENERATE_TRANSACTION */ || toolName === "transfer-ft" /* TRANSFER_FT */ || toolName === "generate-evm-tx" /* GENERATE_EVM_TX */) {
const [transactions, evmSignRequest] = result.data && "evmSignRequest" in result.data ? [result.data.transactions, result.data.evmSignRequest] : [result.data.transactions, void 0];
return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(ErrorBoundary, { children: evmSignRequest ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(EvmTxCard, { evmData: evmSignRequest }) : /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "my-6", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
ReviewTransaction,
{
chatId,
creator,
transactions: transactions || [],
warnings: result.warnings,
evmData: evmSignRequest,
agentId,
walletLoading: isLoading
}
) }) }, `${groupKey}-${message.id}`);
}
}
}
return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(Card, { className: "p-6", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
Accordion,
{
type: "single",
collapsible: true,
className: "w-full",
defaultValue: uniqueKey,
children: /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(AccordionItem, { value: uniqueKey, className: "border-0", children: [
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(AccordionTrigger, { className: "p-0 hover:no-underline", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "flex items-center justify-center gap-2", children: message.role === "user" ? /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(import_jsx_runtime41.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(import_lucide_react12.MessageSquare, { className: "h-[18px] w-[18px]" }),
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("p", { className: "text-[14px] text-shad-blue-100", children: creator || accountId })
] }) : /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(import_jsx_runtime41.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
ImageWithFallback,
{
src: agentImage,
fallbackSrc: "/bitte-symbol-black.svg",
className: cn(
"h-[18px] w-[18px] rounded",
agentImage === "/bitte-symbol-black.svg" ? "invert-0 dark:invert" : "dark:bg-card-list"
),
alt: `${agentName} icon`
}
),
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("p", { className: "text-[14px]", children: agentName ?? "Bitte Assistant" })
] }) }) }),
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(AccordionContent, { className: "mt-6 border-t border-gray-40 pb-0", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: "mt-6 flex w-full flex-col gap-2", children: [
message.content && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "flex flex-col gap-4 text-zinc-800 dark:text-zinc-300", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(SAMessage, { content: message.content }) }),
message.toolInvocations?.map((toolInvocation, index2) => {
const { toolName, toolCallId, state, result } = getTypedToolInvocations(toolInvocation);
return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { children: [
/* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: "flex w-full items-center justify-between text-[12px] text-text-secondary", children: [
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { children: "Tool Call" }),
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "rounded bg-shad-white-10 px-2 py-1", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("code", { children: toolName }) })
] }),
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "p-4", children: (() => {
if (state === "result") {
switch (toolName) {
case "generate-image" /* GENERATE_IMAGE */: {
return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
"img",
{
src: result.data?.url,
className: "w-full"
}
);
}
case "create-drop" /* CREATE_DROP */: {
return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: "flex items-center justify-center gap-2", children: [
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(Button, { asChild: true, variant: "link", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
"a",
{
href: `/claim/${result.data}`,
target: "_blank",
children: "View Drop"
}
) }),
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
ShareDropButton_default,
{
dropId: result.data || ""
}
)
] });
}
default: {
const stringifiedData = JSON.stringify(
result.data
);
return isDataString(stringifiedData) ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(CodeBlock, { content: stringifiedData }) : /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { children: stringifiedData });
}
}
}
})() }),
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "mt-2 border-t border-gray-40" })
] }, `${toolCallId}-${index2}`);
})
] }) })
] })
}
) }, `${message.id}-${index}`);
}) });
};
// src/components/chat/ChatContent.tsx
var import_jsx_runtime42 = require("react/jsx-runtime");
var ChatContent = ({
agentid,
apiUrl,
options,
messages: initialMessages
}) => {
const chatId = (0, import_react18.useRef)(options?.chatId || (0, import_ai2.generateId)()).current;
const [isAtBottom, setIsAtBottom] = (0, import_react18.useState)(true);
const [autoScrollEnabled, setAutoScrollEnabled] = (0, import_react18.useState)(true);
const messagesRef = (0, import_react18.useRef)(null);
const { accountId, evmAddress } = useAccount();
const {
messages,
input,
handleInputChange,
isLoading: isInProgress,
handleSubmit,
reload,
error
} = (0, import_react17.useChat)({
id: chatId,
api: apiUrl,
onError: (e) => {
console.error(e);
},
sendExtraMessageFields: true,
initialMessages,
body: {
id: chatId,
config: {
mode: "default" /* DEFAULT */,
agentId: agentid
},
accountId: accountId || "",
evmAddress
}
});
const groupedMessages = (0, import_react18.useMemo)(() => {
return messages?.reduce((groups, message) => {
if (message.role === "user") {
groups.push([message]);
} else {
const lastGroup = groups[groups.length - 1];
if (!lastGroup || lastGroup[0].role === "user") {
groups.push([message]);
} else {
lastGroup.push(message);
}
}
return groups;
}, []);
}, [messages]);
const scrollToBottom = (0, import_react18.useCallback)((element) => {
if (element) {
element.scrollTo({
top: element.scrollHeight,
behavior: "smooth"
});
}
}, []);
(0, import_react18.useLayoutEffect)(() => {
if (isAtBottom && autoScrollEnabled) {
requestAnimationFrame(() => {
scrollToBottom(messagesRef.current);
});
}
}, [isAtBottom, autoScrollEnabled, scrollToBottom]);
const handleSubmitChat = async (e) => {
e.preventDefault();
handleSubmit(e);
};
const handleScroll = (0, import_react18.useCallback)(() => {
if (messagesRef.current) {
const { scrollTop, scrollHeight, clientHeight } = messagesRef.current;
const atBottom = scrollTop + clientHeight >= scrollHeight - 100;
setIsAtBottom(atBottom);
setAutoScrollEnabled(atBottom);
}
}, []);
(0, import_react18.useEffect)(() => {
const scrollElement = messagesRef.current;
if (scrollElement) {
scrollElement.addEventListener("scroll", handleScroll);
handleScroll();
}
return () => {
if (scrollElement) {
scrollElement.removeEventListener("scroll", handleScroll);
}
};
}, [handleScroll]);
const scrollToBottomHandler = (0, import_react18.useCallback)(() => {
scrollToBottom(messagesRef.current);
setAutoScrollEnabled(true);
}, [scrollToBottom]);
return /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)("div", { className: "flex h-full w-full flex-col gap-4 text-justify", children: [
/* @__PURE__ */ (0, import_jsx_runtime42.jsxs)("div", { className: "relative flex h-[400px] w-full grow-0 overflow-y-auto rounded-lg max-lg:flex-col lg:border lg:border-shad-gray-20 lg:bg-gray-30 lg:px-6", children: [
!isAtBottom ? /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
Button,
{
size: "icon",
variant: "outline",
className: "absolute bottom-2 left-1/2 -translate-x-1/2 rounded-full hover:bg-inherit",
onClick: scrollToBottomHandler,
children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(import_lucide_react13.ArrowDown, { className: "h-4 w-4" })
}
) : null,
/* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
"div",
{
ref: messagesRef,
className: "flex h-full w-full justify-center overflow-y-auto p-4",
children: /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)(
"div",
{
className: cn(
"mx-auto flex w-full flex-col md:max-w-[480px] xl:max-w-[600px] 2xl:mx-56 2xl:max-w-[800px]",
!!agentid ? "h-[calc(100%-240px)]" : "h-[calc(100%-208px)]"
),
children: [
messages.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)("div", { className: "flex h-full flex-col items-center justify-center", children: [
/* @__PURE__ */ (0, import_jsx_runtime42.jsx)("img", { src: "/bitte_transparent.svg", className: "mx-auto mb-4" }),
/* @__PURE__ */ (0, import_jsx_runtime42.jsx)("div", { className: "mb-14 text-[20px] font-medium text-gray-40", children: "Execute Transactions with AI" })
] }),
/* @__PURE__ */ (0, import_jsx_runtime42.jsxs)("div", { className: "flex w-full flex-col space-y-4 py-6", children: [
groupedMessages.map((messages2) => {
const groupKey = `group-${messages2?.[0]?.id}`;
return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
MessageGroup,
{
chatId,
groupKey,
accountId,
messages: messages2,
isLoading: isInProgress,
agentImage: options?.agentImage,
agentName: options?.agentName
},
groupKey
);
}),
error && /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("div", { className: "flex flex-col items-center justify-center space-y-2 px-6 pb-6 text-center text-sm", children: !accountId ? /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)("p", { children: [
"An error occurred. ",
/* @__PURE__ */ (0, import_jsx_runtime42.jsx)("br", {}),
"Please connect your wallet and try again."
] }) : /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)(import_jsx_runtime42.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime42.jsx)("p", { children: "An error occurred." }),
/* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
Button,
{
type: "button",
variant: "secondary",
size: "sm",
onClick: () => reload(),
children: "Retry"
}
)
] }) }),
isInProgress ? /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("div", { className: "flex w-full flex-col items-center justify-center text-gray-600", children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(BitteSpinner, { width: 100, height: 100 }) }) : null
] })
]
}
)
}
)
] }),
/* @__PURE__ */ (0, import_jsx_runtime42.jsx)("div", { className: "z-10 rounded-lg border border-shad-gray-20 bg-background p-6", children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
SmartActionsInput,
{
input,
handleChange: handleInputChange,
handleSubmit: handleSubmitChat,
isLoading: isInProgress,
agentName: options?.agentName
}
) })
] });
};
// src/components/BitteAiChat.tsx
var import_jsx_runtime43 = require("react/jsx-runtime");
var BitteAiChat = ({
wallet,
apiUrl,
historyApiUrl,
agentid,
options,
theme = "dark"
}) => {
const [loadedData, setLoadedData] = (0, import_react19.useState)({
agentIdLoaded: "",
uiMessages: []
});
const chatId = typeof window !== "undefined" && sessionStorage.getItem("chatId");
console.log("pnpm link working 3 COLORs");
(0, import_react19.useEffect)(() => {
const fetchData = async () => {
if (chatId && historyApiUrl) {
const chat = await fetchChatHistory(chatId, historyApiUrl);
if (chat) {
const uiMessages2 = convertToUIMessages(chat.messages);
setLoadedData({
agentIdLoaded: chat.agentId,
uiMessages: uiMessages2
});
}
}
};
fetchData();
}, [chatId, historyApiUrl]);
const { agentIdLoaded, uiMessages } = loadedData;
return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(AccountProvider, { wallet, children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: theme, children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
ChatContent,
{
wallet,
apiUrl,
agentid: agentid ?? agentIdLoaded,
messages: uiMessages,
options: {
agentName: options?.agentName,
agentImage: options?.agentImage,
chatId: options?.chatId ?? (chatId || void 0)
}
}
) }) });
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
AssistantsMode,
BitteAiChat,
Model,
ReviewTransaction
});
//# sourceMappingURL=index.js.map