@blocksdiy/react-common 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +1 -0
  2. package/dist/components/agent-chat.d.ts +126 -0
  3. package/dist/components/agent-chat.d.ts.map +1 -0
  4. package/dist/components/agent-chat.js +548 -0
  5. package/dist/components/agent-chat.js.map +1 -0
  6. package/dist/hooks/use-ai-stream-chunks.d.ts +9 -0
  7. package/dist/hooks/use-ai-stream-chunks.d.ts.map +1 -0
  8. package/dist/hooks/use-ai-stream-chunks.js +27 -0
  9. package/dist/hooks/use-ai-stream-chunks.js.map +1 -0
  10. package/dist/iframe-communication/bridge-provider.d.ts +28 -0
  11. package/dist/iframe-communication/bridge-provider.d.ts.map +1 -0
  12. package/dist/iframe-communication/bridge-provider.js +32 -0
  13. package/dist/iframe-communication/bridge-provider.js.map +1 -0
  14. package/dist/iframe-communication/iframe-bridge-provider.d.ts +24 -0
  15. package/dist/iframe-communication/iframe-bridge-provider.d.ts.map +1 -0
  16. package/dist/iframe-communication/iframe-bridge-provider.js +68 -0
  17. package/dist/iframe-communication/iframe-bridge-provider.js.map +1 -0
  18. package/dist/iframe-communication/index.d.ts +5 -0
  19. package/dist/iframe-communication/index.d.ts.map +1 -0
  20. package/dist/iframe-communication/index.js +4 -0
  21. package/dist/iframe-communication/index.js.map +1 -0
  22. package/dist/iframe-communication/platform-bridge-provider.d.ts +34 -0
  23. package/dist/iframe-communication/platform-bridge-provider.d.ts.map +1 -0
  24. package/dist/iframe-communication/platform-bridge-provider.js +85 -0
  25. package/dist/iframe-communication/platform-bridge-provider.js.map +1 -0
  26. package/dist/iframe-communication/types.d.ts +60 -0
  27. package/dist/iframe-communication/types.d.ts.map +1 -0
  28. package/dist/iframe-communication/types.js +2 -0
  29. package/dist/iframe-communication/types.js.map +1 -0
  30. package/dist/index.d.ts +4 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +4 -0
  33. package/dist/index.js.map +1 -0
  34. package/package.json +59 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # react-common.
@@ -0,0 +1,126 @@
1
+ import { ReactNode, SetStateAction } from "react";
2
+ export interface Attachment {
3
+ url: string;
4
+ fileType: string;
5
+ fileName: string;
6
+ }
7
+ export type MessageRole = "human" | "ai";
8
+ interface MessageItemMsg {
9
+ id: string;
10
+ role: MessageRole;
11
+ attachments?: Attachment[];
12
+ content?: string;
13
+ type: "progress" | "text" | "missing_integration";
14
+ versionId?: number;
15
+ payload: Record<string, any>;
16
+ hiddenContent?: string;
17
+ }
18
+ export interface MessageItem {
19
+ msg: MessageItemMsg;
20
+ createdAt: string;
21
+ createdBy?: string;
22
+ chatId?: string;
23
+ threadId?: string;
24
+ id?: string;
25
+ }
26
+ export interface AgentChatContextValue {
27
+ messages: MessageItem[];
28
+ attachments: Attachment[];
29
+ prompt: string;
30
+ isThinking: boolean;
31
+ isFetchingMessages: boolean;
32
+ isDraggingFiles: boolean;
33
+ currentThreadId?: string;
34
+ threadIds: string[];
35
+ agentChatData?: AgentChatData;
36
+ sendMessage: (message: Omit<MessageItemMsg, "id" | "role" | "type" | "payload">) => Promise<void>;
37
+ sendFromInputs: () => Promise<void>;
38
+ addMessages: (newMessages: MessageItem[]) => void;
39
+ addAttachments: (attachments: Attachment[]) => void;
40
+ removeAttachment: (url: string) => void;
41
+ clearAttachments: () => void;
42
+ setPrompt: React.Dispatch<SetStateAction<string>>;
43
+ setAttachments: React.Dispatch<SetStateAction<Attachment[]>>;
44
+ setIsDraggingFiles: React.Dispatch<SetStateAction<boolean>>;
45
+ setCurrentThreadId: React.Dispatch<SetStateAction<string | undefined>>;
46
+ setThreadIds: React.Dispatch<SetStateAction<string[]>>;
47
+ appId: string;
48
+ agentChatId?: string;
49
+ chatId?: string;
50
+ noPersistency?: boolean;
51
+ }
52
+ export declare const useAgentChat: () => AgentChatContextValue;
53
+ export interface AgentChatData {
54
+ agent: {
55
+ title?: string;
56
+ jobTitle?: string;
57
+ photoUrl?: string;
58
+ };
59
+ initialMessages?: {
60
+ content: string;
61
+ }[];
62
+ initialPrompt?: {
63
+ content?: string;
64
+ hiddenContent?: string;
65
+ };
66
+ }
67
+ export interface AgentChatRootProps {
68
+ appId: string;
69
+ token?: string;
70
+ agentChatId?: string;
71
+ defaultThreadId?: string;
72
+ noPersistency?: boolean;
73
+ children?: ReactNode;
74
+ chatId?: string;
75
+ chatContext?: any;
76
+ chatContextFiles?: Attachment[];
77
+ agentChatData?: AgentChatData;
78
+ }
79
+ export declare const AgentChatRoot: ({ appId, token, agentChatId, children, chatId, noPersistency, defaultThreadId, chatContext, chatContextFiles, agentChatData, }: AgentChatRootProps) => import("react/jsx-runtime").JSX.Element;
80
+ export interface AgentChatMessageProps {
81
+ message: MessageItem;
82
+ index: number;
83
+ }
84
+ export declare function AgentChatMessage({ message, index, ...props }: React.ComponentProps<"div"> & AgentChatMessageProps): import("react/jsx-runtime").JSX.Element | null;
85
+ export interface AgentChatMessagesProps {
86
+ asChild?: boolean;
87
+ autoScroll?: boolean;
88
+ scrollAreaClassName?: string;
89
+ }
90
+ export declare function AgentChatMessages({ asChild, autoScroll, scrollAreaClassName, ...props }: React.ComponentProps<"div"> & AgentChatMessagesProps): import("react/jsx-runtime").JSX.Element;
91
+ export interface AgentChatThinkingProps {
92
+ asChild?: boolean;
93
+ }
94
+ export declare function AgentChatThinking({ asChild, ...props }: React.ComponentProps<"div"> & AgentChatThinkingProps): import("react/jsx-runtime").JSX.Element | null;
95
+ export interface AgentChatFetchingProps {
96
+ asChild?: boolean;
97
+ }
98
+ export declare function AgentChatFetching({ asChild, ...props }: React.ComponentProps<"div"> & AgentChatFetchingProps): import("react/jsx-runtime").JSX.Element | null;
99
+ export interface AgentChatInputProps {
100
+ asChild?: boolean;
101
+ onSubmit?: (e: React.FormEvent<HTMLTextAreaElement>) => void;
102
+ acceptFiles?: boolean;
103
+ }
104
+ export declare function AgentChatInput({ asChild, onChange, onKeyDown, onPaste, onDragOver, onDragLeave, onDrop, onSubmit, acceptFiles, ...props }: React.ComponentProps<"textarea"> & AgentChatInputProps): import("react/jsx-runtime").JSX.Element;
105
+ export interface AgentChatSendTriggerProps {
106
+ asChild?: boolean;
107
+ }
108
+ export declare function AgentChatSendTrigger({ asChild, onClick, disabled, ...props }: React.ComponentProps<"button"> & AgentChatSendTriggerProps): import("react/jsx-runtime").JSX.Element;
109
+ export interface AgentChatAttachmentTriggerProps {
110
+ asChild?: boolean;
111
+ accept?: string;
112
+ multiple?: boolean;
113
+ }
114
+ export declare function AgentChatAttachmentTrigger({ asChild, onClick, disabled, accept, multiple, ...props }: React.ComponentProps<"button"> & AgentChatAttachmentTriggerProps): import("react/jsx-runtime").JSX.Element;
115
+ export interface AgentChatAttachmentProps {
116
+ attachment: Attachment;
117
+ asChild?: boolean;
118
+ }
119
+ export declare function AgentChatAttachment({ attachment, asChild, ...props }: React.ComponentProps<"div"> & AgentChatAttachmentProps): import("react/jsx-runtime").JSX.Element;
120
+ export interface AgentChatAttachmentRemoveProps {
121
+ attachment: Attachment;
122
+ asChild?: boolean;
123
+ }
124
+ export declare function AgentChatAttachmentRemove({ attachment, asChild, onClick, ...props }: React.ComponentProps<"button"> & AgentChatAttachmentRemoveProps): import("react/jsx-runtime").JSX.Element;
125
+ export {};
126
+ //# sourceMappingURL=agent-chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-chat.d.ts","sourceRoot":"","sources":["../../src/components/agent-chat.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAiB,SAAS,EAAE,cAAc,EAAwD,MAAM,OAAO,CAAC;AAWvH,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAqBD,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,IAAI,CAAC;AAEzC,UAAU,cAAc;IACtB,EAAE,EAAE,MAAM,CA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C;CACnB;AAED,wBAAgB,yBAAyB,CAAC,EACxC,UAAU,EACV,OAAe,EACf,OAAO,EACP,GAAG,KAAK,EACT,EAAE,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,8BAA8B,2CAcjE"}
@@ -0,0 +1,548 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { AppVersionService, DataApiService } from "@blockscom/blocks-client-api";
3
+ import { getApiHost } from "@blockscom/blocks-client-api/envService";
4
+ import { WorkflowRequest } from "@blockscom/blocks-client-api/workflowService";
5
+ import { Slot } from "@radix-ui/react-slot";
6
+ import { createContext, useCallback, useContext, useEffect, useRef, useState } from "react";
7
+ /* public decouple - blocks common */
8
+ const CHAT_AGENT_HISTORY_TABLE_BLOCK_ID = "688ed13adefd8b565c779b8e";
9
+ const CHAT_AGENT_CALL_ACTION_BLOCK_ID = "688ed4d77b454b1fdaf5cf2d";
10
+ /* end of blocks common */
11
+ // File upload constraints
12
+ const MAX_FILE_SIZE_MB = 5;
13
+ const MAX_FILE_SIZE_BYTES = MAX_FILE_SIZE_MB * 1024 * 1024;
14
+ const validateAndConvertFiles = (files) => {
15
+ if (files.length === 0) {
16
+ return null;
17
+ }
18
+ const hasOversizedFiles = files.some((file) => file.size > MAX_FILE_SIZE_BYTES);
19
+ if (hasOversizedFiles) {
20
+ console.error(`Upload failed because some files are bigger than ${MAX_FILE_SIZE_MB} MB.`);
21
+ return null;
22
+ }
23
+ return files.map((file) => ({
24
+ fileType: file.type,
25
+ fileName: file.name,
26
+ url: URL.createObjectURL(file),
27
+ }));
28
+ };
29
+ const AgentChatContext = createContext(null);
30
+ const generateId = (length = 10) => {
31
+ return Math.random()
32
+ .toString(36)
33
+ .substring(2, 2 + length);
34
+ };
35
+ export const useAgentChat = () => {
36
+ const context = useContext(AgentChatContext);
37
+ if (!context) {
38
+ throw new Error("useAgentChat must be used within an AgentChatRoot provider");
39
+ }
40
+ return context;
41
+ };
42
+ const fileFromAttachment = async (attachment) => {
43
+ const res = await fetch(attachment.url); // or use XMLHttpRequest if you need progress events
44
+ if (!res.ok) {
45
+ throw new Error("The blob URL is no longer valid");
46
+ }
47
+ const blob = await res.blob(); // ← original bytes
48
+ return new File([blob], attachment.fileName, {
49
+ // wrap them in a File
50
+ type: attachment.fileType, // keep the MIME type
51
+ lastModified: Date.now(),
52
+ });
53
+ };
54
+ const getUploadUrl = async ({ token, data, }) => {
55
+ const appVersion = AppVersionService.getCurrentVersionNumber();
56
+ const headers = token
57
+ ? {
58
+ Authorization: `Bearer ${token}`,
59
+ ...(appVersion ? { "x-app-version": appVersion.toString() } : {}),
60
+ }
61
+ : undefined;
62
+ const response = await fetch(`${getApiHost()}/product/builder/data-assets/get-upload-url`, {
63
+ method: "post",
64
+ headers,
65
+ body: JSON.stringify(data),
66
+ });
67
+ const { result } = await response.json();
68
+ return result;
69
+ };
70
+ const uploadFile = async ({ appId, token, file }) => {
71
+ const formData = new FormData();
72
+ const { uploadUrl, fields, protectedUrl } = await getUploadUrl({
73
+ data: {
74
+ productId: appId,
75
+ fileName: file.name,
76
+ fileType: file.type,
77
+ },
78
+ token,
79
+ });
80
+ const request = new XMLHttpRequest();
81
+ if (uploadUrl && fields) {
82
+ for (const [key, value] of Object.entries(fields)) {
83
+ formData.append(key, value);
84
+ }
85
+ formData.append("file", file);
86
+ request.open("POST", uploadUrl);
87
+ }
88
+ return new Promise((resolve, reject) => {
89
+ request.onload = () => {
90
+ if (request.status >= 200 && request.status < 300) {
91
+ resolve(protectedUrl);
92
+ }
93
+ else {
94
+ reject(new Error("Error uploading file"));
95
+ }
96
+ };
97
+ request.send(formData);
98
+ });
99
+ };
100
+ const uploadAttachments = async ({ attachments, token, appId, }) => {
101
+ const uploadAttachmentsPromises = attachments?.map(async (attachment) => {
102
+ const file = await fileFromAttachment(attachment);
103
+ const url = await uploadFile({ appId, token, file });
104
+ return {
105
+ url,
106
+ fileName: attachment.fileName,
107
+ fileType: attachment.fileType,
108
+ };
109
+ });
110
+ const uploadAttachments = uploadAttachmentsPromises && uploadAttachmentsPromises.length > 0
111
+ ? await Promise.all(uploadAttachmentsPromises)
112
+ : undefined;
113
+ return uploadAttachments;
114
+ };
115
+ export const AgentChatRoot = ({ appId, token, agentChatId, children, chatId, noPersistency, defaultThreadId, chatContext, chatContextFiles, agentChatData, }) => {
116
+ const [prompt, setPrompt] = useState("");
117
+ const [attachments, setAttachments] = useState([]);
118
+ const [messages, setMessages] = useState([]);
119
+ const [isFetchingMessages, setIsFetchingMessages] = useState(!noPersistency);
120
+ const [isThinking, setIsThinking] = useState(false);
121
+ const [isDraggingFiles, setIsDraggingFiles] = useState(false);
122
+ const [currentThreadId, setCurrentThreadId] = useState(defaultThreadId);
123
+ const [threadIds, setThreadIds] = useState([]);
124
+ const initializedAgentChatDataRef = useRef(false);
125
+ const addMessages = useCallback((messagesToAdd) => {
126
+ setMessages((prevMessages) => {
127
+ const newMessages = [...prevMessages];
128
+ for (const messageToAdd of messagesToAdd) {
129
+ const existingIndex = newMessages.findIndex((m) => m.msg.id === messageToAdd.msg.id);
130
+ if (existingIndex !== -1) {
131
+ // Replace the existing message with the updated one
132
+ newMessages[existingIndex] = messageToAdd;
133
+ }
134
+ else {
135
+ // Insert new message
136
+ newMessages.push(messageToAdd);
137
+ }
138
+ }
139
+ // Ensure the messages are sorted chronologically by creation time
140
+ newMessages.sort((a, b) => Date.parse(a.createdAt) - Date.parse(b.createdAt));
141
+ return newMessages;
142
+ });
143
+ }, []);
144
+ useEffect(() => {
145
+ if (noPersistency) {
146
+ return;
147
+ }
148
+ const fetchMessages = async () => {
149
+ try {
150
+ setIsFetchingMessages(true);
151
+ const data = await new DataApiService({ token, appId }).getTableData(CHAT_AGENT_HISTORY_TABLE_BLOCK_ID, {
152
+ appId,
153
+ chatId,
154
+ threadId: currentThreadId,
155
+ });
156
+ const fetchedMessages = data.filter((chatMessage) => !!chatMessage);
157
+ addMessages(fetchedMessages);
158
+ }
159
+ finally {
160
+ setIsFetchingMessages(false);
161
+ }
162
+ };
163
+ fetchMessages();
164
+ }, [appId, token, chatId, currentThreadId, noPersistency, agentChatData, addMessages]);
165
+ const updateMessageWithChunk = useCallback((msgId, { content, ...updates }) => {
166
+ setMessages((prevMessages) => {
167
+ const newMessages = [...prevMessages];
168
+ const index = newMessages.findIndex((m) => m.msg.id === msgId);
169
+ if (index === -1) {
170
+ const responseMessage = {
171
+ createdAt: new Date().toISOString(),
172
+ msg: {
173
+ role: "ai",
174
+ type: "text",
175
+ id: msgId,
176
+ content: content || "",
177
+ payload: {},
178
+ },
179
+ };
180
+ newMessages.push(responseMessage);
181
+ }
182
+ else {
183
+ const newContent = content !== undefined ? newMessages[index].msg.content + content : content;
184
+ newMessages[index] = {
185
+ ...newMessages[index],
186
+ msg: { ...newMessages[index].msg, content: newContent || "", ...updates },
187
+ };
188
+ }
189
+ return newMessages;
190
+ });
191
+ }, []);
192
+ const addAttachments = useCallback((newAttachments) => {
193
+ setAttachments((prevAttachments) => [...prevAttachments, ...newAttachments]);
194
+ }, []);
195
+ const removeAttachment = useCallback((url) => {
196
+ setAttachments((prevAttachments) => prevAttachments.filter((attachment) => attachment.url !== url));
197
+ }, []);
198
+ const clearAttachments = useCallback(() => {
199
+ setAttachments([]);
200
+ }, []);
201
+ const sendMessage = useCallback(async ({ content, hiddenContent, ...message }) => {
202
+ const newMessage = {
203
+ createdAt: new Date().toISOString(),
204
+ msg: {
205
+ id: generateId(),
206
+ role: "human",
207
+ type: "text",
208
+ payload: {},
209
+ content: content ?? "",
210
+ hiddenContent: hiddenContent ?? "",
211
+ ...message,
212
+ },
213
+ };
214
+ addMessages([newMessage]);
215
+ try {
216
+ setIsThinking(true);
217
+ const uploadedAttachments = await uploadAttachments({
218
+ attachments: message.attachments,
219
+ appId,
220
+ token,
221
+ });
222
+ const result = await WorkflowRequest.run({
223
+ workflowBlockId: CHAT_AGENT_CALL_ACTION_BLOCK_ID,
224
+ appId,
225
+ token,
226
+ context: { appId, agentChatId },
227
+ input: {
228
+ prompt: content ?? "",
229
+ hiddenPrompt: hiddenContent ?? "",
230
+ files: uploadedAttachments,
231
+ messages: messages.map((m) => m.msg),
232
+ chatId,
233
+ noPersistency,
234
+ threadId: currentThreadId,
235
+ chatContextFiles,
236
+ chatContext: chatContext ? `Context: \n${JSON.stringify(chatContext)}` : undefined,
237
+ },
238
+ onChunk: (chunk) => {
239
+ updateMessageWithChunk(chunk.msgId, { content: chunk.content });
240
+ },
241
+ });
242
+ addMessages(result.messages);
243
+ }
244
+ catch (error) {
245
+ addMessages([
246
+ {
247
+ createdAt: new Date().toISOString(),
248
+ msg: {
249
+ id: generateId(10),
250
+ role: "ai",
251
+ type: "text",
252
+ content: "Error: " + error.message,
253
+ payload: {},
254
+ },
255
+ },
256
+ ]);
257
+ }
258
+ finally {
259
+ setIsThinking(false);
260
+ }
261
+ }, [
262
+ addMessages,
263
+ updateMessageWithChunk,
264
+ agentChatId,
265
+ appId,
266
+ messages,
267
+ token,
268
+ currentThreadId,
269
+ chatId,
270
+ noPersistency,
271
+ chatContext,
272
+ chatContextFiles,
273
+ ]);
274
+ useEffect(() => {
275
+ if (!agentChatData || initializedAgentChatDataRef.current) {
276
+ return;
277
+ }
278
+ const { initialMessages, initialPrompt } = agentChatData;
279
+ if (initialMessages && initialMessages.length > 0) {
280
+ setMessages((prevMessages) => {
281
+ return [
282
+ ...initialMessages.map((initialMessage) => ({
283
+ createdAt: new Date(1).toISOString(),
284
+ msg: {
285
+ id: generateId(),
286
+ role: "ai",
287
+ type: "text",
288
+ content: initialMessage.content,
289
+ },
290
+ })),
291
+ ...prevMessages,
292
+ ];
293
+ });
294
+ }
295
+ if (initialPrompt?.content || initialPrompt?.hiddenContent) {
296
+ sendMessage({ content: initialPrompt?.content, hiddenContent: initialPrompt?.hiddenContent });
297
+ }
298
+ initializedAgentChatDataRef.current = true;
299
+ }, [agentChatData, sendMessage]);
300
+ const sendFromInputs = useCallback(async () => {
301
+ if (isThinking || isFetchingMessages || (!prompt && attachments.length === 0)) {
302
+ return;
303
+ }
304
+ const newMessage = {
305
+ content: prompt,
306
+ type: "text",
307
+ attachments,
308
+ };
309
+ setPrompt("");
310
+ setAttachments([]);
311
+ return sendMessage(newMessage);
312
+ }, [setPrompt, setAttachments, sendMessage, isThinking, isFetchingMessages, prompt, attachments]);
313
+ return (_jsx(AgentChatContext.Provider, { value: {
314
+ // State
315
+ messages: messages.map((m) => ({
316
+ ...m,
317
+ ...m.msg,
318
+ })), // TODO: remove this at 1/1/2026, change to: `messages: messages,`
319
+ attachments,
320
+ prompt,
321
+ isThinking,
322
+ isFetchingMessages,
323
+ isDraggingFiles,
324
+ currentThreadId,
325
+ threadIds,
326
+ agentChatData,
327
+ // Actions
328
+ sendMessage,
329
+ sendFromInputs,
330
+ addMessages,
331
+ addAttachments,
332
+ removeAttachment,
333
+ clearAttachments,
334
+ // Setters
335
+ setPrompt,
336
+ setAttachments,
337
+ setIsDraggingFiles,
338
+ setCurrentThreadId,
339
+ setThreadIds,
340
+ // Config
341
+ appId,
342
+ agentChatId,
343
+ chatId,
344
+ noPersistency,
345
+ }, children: children }));
346
+ };
347
+ export function AgentChatMessage({ message, index, ...props }) {
348
+ if (!message.msg?.content && (!message.msg.attachments || message.msg.attachments.length === 0)) {
349
+ return null;
350
+ }
351
+ return _jsx("div", { "data-message-index": index, "data-message-role": message.msg.role, ...props });
352
+ }
353
+ export function AgentChatMessages({ asChild = false, autoScroll = true, scrollAreaClassName, ...props }) {
354
+ const { messages, isThinking } = useAgentChat();
355
+ const scrollRef = useRef(null);
356
+ const bottomRef = useRef(null);
357
+ const [isAtBottom, setIsAtBottom] = useState(true);
358
+ const Comp = asChild ? Slot : "div";
359
+ const scrollToBottom = useCallback(() => {
360
+ if (scrollRef.current) {
361
+ scrollRef.current.scrollTo({ top: scrollRef.current.scrollHeight, behavior: "instant" });
362
+ }
363
+ }, []);
364
+ // Set up Intersection Observer to detect if bottom sentinel is visible
365
+ useEffect(() => {
366
+ const bottomElement = bottomRef.current;
367
+ if (!bottomElement) {
368
+ return;
369
+ }
370
+ const observer = new IntersectionObserver((entries) => {
371
+ const entry = entries[0];
372
+ setIsAtBottom(entry.isIntersecting);
373
+ }, {
374
+ root: scrollRef.current,
375
+ rootMargin: "0px 0px 5px 0px", // Extend detection area 5px below viewport
376
+ threshold: 0, // Trigger as soon as sentinel enters extended area
377
+ });
378
+ observer.observe(bottomElement);
379
+ return () => {
380
+ observer.disconnect();
381
+ };
382
+ }, []);
383
+ // Auto-scroll when new messages arrive and user is at bottom
384
+ useEffect(() => {
385
+ if (!autoScroll) {
386
+ return;
387
+ }
388
+ if (isAtBottom) {
389
+ scrollToBottom();
390
+ }
391
+ }, [messages, isThinking, autoScroll, isAtBottom, scrollToBottom]);
392
+ return (_jsxs("div", { ref: scrollRef, style: { overflow: "auto" }, className: scrollAreaClassName, ...props, children: [_jsx(Comp, { "data-slot": "agent-chat-messages", ...props }), _jsx("div", { ref: bottomRef, style: {
393
+ height: 0,
394
+ width: "100%",
395
+ pointerEvents: "none",
396
+ }, "aria-hidden": "true" })] }));
397
+ }
398
+ export function AgentChatThinking({ asChild = false, ...props }) {
399
+ const { isThinking } = useAgentChat();
400
+ const Comp = asChild ? Slot : "div";
401
+ if (!isThinking) {
402
+ return null;
403
+ }
404
+ return _jsx(Comp, { "data-slot": "agent-chat-thinking", ...props });
405
+ }
406
+ export function AgentChatFetching({ asChild = false, ...props }) {
407
+ const { isFetchingMessages, agentChatData } = useAgentChat();
408
+ const Comp = asChild ? Slot : "div";
409
+ if (!isFetchingMessages && agentChatData) {
410
+ return null;
411
+ }
412
+ return _jsx(Comp, { "data-slot": "agent-chat-fetching", ...props });
413
+ }
414
+ export function AgentChatInput({ asChild = false, onChange, onKeyDown, onPaste, onDragOver, onDragLeave, onDrop, onSubmit, acceptFiles = true, ...props }) {
415
+ const { setIsDraggingFiles, addAttachments, prompt, setPrompt, sendFromInputs } = useAgentChat();
416
+ const handleDragOver = useCallback((e) => {
417
+ if (!acceptFiles) {
418
+ return;
419
+ }
420
+ e.preventDefault();
421
+ e.stopPropagation();
422
+ if (e.dataTransfer.types.includes("Files")) {
423
+ setIsDraggingFiles(true);
424
+ }
425
+ }, [setIsDraggingFiles, acceptFiles]);
426
+ const handleDragLeave = useCallback((e) => {
427
+ if (!acceptFiles) {
428
+ return;
429
+ }
430
+ e.preventDefault();
431
+ e.stopPropagation();
432
+ setIsDraggingFiles(false);
433
+ }, [setIsDraggingFiles, acceptFiles]);
434
+ const handleDrop = useCallback((e) => {
435
+ if (!acceptFiles) {
436
+ return;
437
+ }
438
+ e.preventDefault();
439
+ e.stopPropagation();
440
+ setIsDraggingFiles(false);
441
+ const files = Array.from(e.dataTransfer.files);
442
+ const attachments = validateAndConvertFiles(files);
443
+ if (attachments) {
444
+ addAttachments(attachments);
445
+ }
446
+ }, [addAttachments, setIsDraggingFiles, acceptFiles]);
447
+ const handleKeyDown = useCallback((e) => {
448
+ if (e.key === "Enter" && !e.shiftKey) {
449
+ e.preventDefault();
450
+ onSubmit?.(e);
451
+ sendFromInputs();
452
+ }
453
+ }, [sendFromInputs, onSubmit]);
454
+ const handleChange = useCallback((e) => {
455
+ setPrompt(e.target.value);
456
+ }, [setPrompt]);
457
+ const handlePaste = useCallback(async (e) => {
458
+ if (!acceptFiles) {
459
+ return;
460
+ }
461
+ const clipboardData = e.clipboardData;
462
+ if (!clipboardData) {
463
+ return;
464
+ }
465
+ const files = Array.from(clipboardData.files);
466
+ if (files.length === 0) {
467
+ return;
468
+ }
469
+ e.preventDefault();
470
+ const attachments = validateAndConvertFiles(files);
471
+ if (attachments) {
472
+ addAttachments(attachments);
473
+ }
474
+ }, [addAttachments, acceptFiles]);
475
+ const Comp = asChild ? Slot : "textarea";
476
+ return (_jsx(Comp, { value: prompt, onChange: (e) => {
477
+ handleChange(e);
478
+ onChange?.(e);
479
+ }, onKeyDown: (e) => {
480
+ handleKeyDown(e);
481
+ onKeyDown?.(e);
482
+ }, onPaste: (e) => {
483
+ handlePaste(e);
484
+ onPaste?.(e);
485
+ }, onDragOver: acceptFiles
486
+ ? (e) => {
487
+ handleDragOver(e);
488
+ onDragOver?.(e);
489
+ }
490
+ : onDragOver, onDragLeave: acceptFiles
491
+ ? (e) => {
492
+ handleDragLeave(e);
493
+ onDragLeave?.(e);
494
+ }
495
+ : onDragLeave, onDrop: acceptFiles
496
+ ? (e) => {
497
+ handleDrop(e);
498
+ onDrop?.(e);
499
+ }
500
+ : onDrop, "data-slot": "agent-chat-input", ...props }));
501
+ }
502
+ export function AgentChatSendTrigger({ asChild = false, onClick, disabled, ...props }) {
503
+ const { isThinking, sendFromInputs } = useAgentChat();
504
+ const Comp = asChild ? Slot : "button";
505
+ return (_jsx(Comp, { onClick: (e) => {
506
+ sendFromInputs();
507
+ onClick?.(e);
508
+ }, disabled: disabled ?? isThinking, "data-slot": "agent-chat-send-trigger", ...props }));
509
+ }
510
+ export function AgentChatAttachmentTrigger({ asChild = false, onClick, disabled, accept, multiple = true, ...props }) {
511
+ const { isThinking, addAttachments } = useAgentChat();
512
+ const fileInputRef = useRef(null);
513
+ const handleFileChange = useCallback(async (e) => {
514
+ const files = e.target.files;
515
+ if (!files || files.length === 0) {
516
+ return;
517
+ }
518
+ const attachments = validateAndConvertFiles(Array.from(files));
519
+ if (attachments) {
520
+ addAttachments(attachments);
521
+ }
522
+ // Reset input to allow selecting the same file again
523
+ if (fileInputRef.current) {
524
+ fileInputRef.current.value = "";
525
+ }
526
+ }, [addAttachments]);
527
+ const handleClick = useCallback(() => {
528
+ fileInputRef.current?.click();
529
+ }, []);
530
+ const Comp = asChild ? Slot : "button";
531
+ return (_jsxs(_Fragment, { children: [_jsx("input", { type: "file", ref: fileInputRef, onChange: handleFileChange, accept: accept, multiple: multiple, style: { display: "none" }, "aria-hidden": "true" }), _jsx(Comp, { onClick: (e) => {
532
+ handleClick();
533
+ onClick?.(e);
534
+ }, disabled: disabled ?? isThinking, "data-slot": "agent-chat-attachment-trigger", ...props })] }));
535
+ }
536
+ export function AgentChatAttachment({ attachment, asChild = false, ...props }) {
537
+ const Comp = asChild ? Slot : "div";
538
+ return _jsx(Comp, { "data-slot": "agent-chat-attachment", "data-file-type": attachment.fileType, ...props });
539
+ }
540
+ export function AgentChatAttachmentRemove({ attachment, asChild = false, onClick, ...props }) {
541
+ const { removeAttachment } = useAgentChat();
542
+ const Comp = asChild ? Slot : "button";
543
+ return (_jsx(Comp, { onClick: (e) => {
544
+ removeAttachment(attachment.url);
545
+ onClick?.(e);
546
+ }, "data-slot": "agent-chat-attachment-remove", ...props }));
547
+ }
548
+ //# sourceMappingURL=agent-chat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-chat.js","sourceRoot":"","sources":["../../src/components/agent-chat.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAC/E,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAA6B,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEvH,qCAAqC;AACrC,MAAM,iCAAiC,GAAG,0BAA0B,CAAC;AACrE,MAAM,+BAA+B,GAAG,0BAA0B,CAAC;AACnE,0BAA0B;AAE1B,0BAA0B;AAC1B,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,mBAAmB,GAAG,gBAAgB,GAAG,IAAI,GAAG,IAAI,CAAC;AAQ3D,MAAM,uBAAuB,GAAG,CAAC,KAAa,EAAuB,EAAE;IACrE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,iBAAiB,GAAG,KAAK,CAAC,IAAI,CAAC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AAY,EACjB,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,iBACd,MAAM,GAClB,EACF,KAAC,IAAI,IACH,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;oBACb,WAAW,EAAE,CAAC;oBACd,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;gBACf,CAAC,EACD,QAAQ,EAAE,QAAQ,IAAI,UAAU,eACtB,+BAA+B,KACrC,KAAK,GACT,IACD,CACJ,CAAC;AACJ,CAAC;AAOD,MAAM,UAAU,mBAAmB,CAAC,EAClC,UAAU,EACV,OAAO,GAAG,KAAK,EACf,GAAG,KAAK,EAC+C;IACvD,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAEpC,OAAO,KAAC,IAAI,iBAAW,uBAAuB,oBAAiB,UAAU,CAAC,QAAQ,KAAM,KAAK,GAAI,CAAC;AACpG,CAAC;AAOD,MAAM,UAAU,yBAAyB,CAAC,EACxC,UAAU,EACV,OAAO,GAAG,KAAK,EACf,OAAO,EACP,GAAG,KAAK,EACwD;IAChE,MAAM,EAAE,gBAAgB,EAAE,GAAG,YAAY,EAAE,CAAC;IAC5C,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC;IAEvC,OAAO,CACL,KAAC,IAAI,IACH,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;YACb,gBAAgB,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YACjC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;QACf,CAAC,eACS,8BAA8B,KACpC,KAAK,GACT,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { StreamEventData } from "@blockscom/blocks-client-api/types/app-data";
2
+ export declare const useAiStreamChunks: ({ onChunk }: {
3
+ onChunk: (chunkData: StreamEventData) => void;
4
+ }) => {
5
+ handleChunk: (chunkIndex: number, chunkData: StreamEventData) => void;
6
+ onCompleteChunks: () => void;
7
+ };
8
+ export default useAiStreamChunks;
9
+ //# sourceMappingURL=use-ai-stream-chunks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-ai-stream-chunks.d.ts","sourceRoot":"","sources":["../../src/hooks/use-ai-stream-chunks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAK9E,eAAO,MAAM,iBAAiB,GAAI,aAAa;IAAE,OAAO,EAAE,CAAC,SAAS,EAAE,eAAe,KAAK,IAAI,CAAA;CAAE;8BAIjD,MAAM,aAAa,eAAe;;CAyBhF,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { useCallback, useRef } from "react";
2
+ const NO_CHUNK_INDEX = -1;
3
+ export const useAiStreamChunks = ({ onChunk }) => {
4
+ const currentChunkIndexRef = useRef(NO_CHUNK_INDEX);
5
+ const chunksMapRef = useRef(new Map());
6
+ const handleChunk = useCallback((chunkIndex, chunkData) => {
7
+ chunksMapRef.current.set(chunkIndex, chunkData);
8
+ if (chunkIndex !== currentChunkIndexRef.current + 1) {
9
+ return;
10
+ }
11
+ currentChunkIndexRef.current = chunkIndex;
12
+ onChunk(chunkData);
13
+ const nextChunkIndex = currentChunkIndexRef.current + 1;
14
+ const nextChunk = chunksMapRef.current.get(nextChunkIndex);
15
+ if (!nextChunk) {
16
+ return;
17
+ }
18
+ handleChunk(nextChunkIndex, nextChunk);
19
+ }, []);
20
+ const resetChunks = useCallback(() => {
21
+ currentChunkIndexRef.current = NO_CHUNK_INDEX;
22
+ chunksMapRef.current = new Map();
23
+ }, []);
24
+ return { handleChunk, onCompleteChunks: resetChunks };
25
+ };
26
+ export default useAiStreamChunks;
27
+ //# sourceMappingURL=use-ai-stream-chunks.js.map
@@ -0,0 +1 @@
1
+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AAE,CAAC;AACxD,CAAC,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { type Methods } from "penpal";
2
+ import { type ReactNode } from "react";
3
+ type BridgeDataSuccess<TApi> = {
4
+ api: TApi;
5
+ error: undefined;
6
+ };
7
+ type BridgeDataError = {
8
+ api: undefined;
9
+ error: Error;
10
+ };
11
+ type BridgeDataNotLoaded = {
12
+ api: undefined;
13
+ error: undefined;
14
+ };
15
+ type BridgeData<TApi> = BridgeDataSuccess<TApi> | BridgeDataError | BridgeDataNotLoaded;
16
+ export type BridgeState<TApi extends Methods> = {
17
+ isLoading: boolean;
18
+ onConnectionLoading: () => void;
19
+ onConnectionSuccess: (api: TApi) => void;
20
+ onConnectionError: (error: Error) => void;
21
+ onConnectionEnded: () => void;
22
+ } & BridgeData<TApi>;
23
+ export declare function BridgeProvider({ children }: {
24
+ children: ReactNode;
25
+ }): import("react/jsx-runtime").JSX.Element;
26
+ export declare function useBridgeState<TApi extends Methods>(hookName?: string, providerName?: string): BridgeState<TApi>;
27
+ export {};
28
+ //# sourceMappingURL=bridge-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge-provider.d.ts","sourceRoot":"","sources":["../../src/iframe-communication/bridge-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAiB,KAAK,SAAS,EAAwB,MAAM,OAAO,CAAC;AAE5E,KAAK,iBAAiB,CAAC,IAAI,IAAI;IAAE,GAAG,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAC/D,KAAK,eAAe,GAAG;IAAE,GAAG,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AACxD,KAAK,mBAAmB,GAAG;IAAE,GAAG,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAEhE,KAAK,UAAU,CAAC,IAAI,IAAI,iBAAiB,CAAC,IAAI,CAAC,GAAG,eAAe,GAAG,mBAAmB,CAAC;AAExF,MAAM,MAAM,WAAW,CAAC,IAAI,SAAS,OAAO,IAAI;IAC9C,SAAS,EAAE,OAAO,CAAC;IACnB,mBAAmB,EAAE,MAAM,IAAI,CAAC;IAChC,mBAAmB,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,IAAI,CAAC;IACzC,iBAAiB,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC1C,iBAAiB,EAAE,MAAM,IAAI,CAAC;CAC/B,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;AAIrB,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,2CA+BnE;AAED,wBAAgB,cAAc,CAAC,IAAI,SAAS,OAAO,EAAE,QAAQ,SAAmB,EAAE,YAAY,SAAmB,qBAOhH"}
@@ -0,0 +1,32 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useState } from "react";
3
+ const BridgeStateContext = createContext(undefined);
4
+ export function BridgeProvider({ children }) {
5
+ const [data, setData] = useState({ api: undefined, error: undefined });
6
+ const [isLoading, setIsLoading] = useState(false);
7
+ const onConnectionSuccess = (api) => {
8
+ setIsLoading(false);
9
+ setData({ api, error: undefined });
10
+ };
11
+ const onConnectionError = (error) => {
12
+ setIsLoading(false);
13
+ setData({ api: undefined, error });
14
+ };
15
+ const onConnectionLoading = () => {
16
+ setIsLoading(true);
17
+ setData({ api: undefined, error: undefined });
18
+ };
19
+ const onConnectionEnded = () => {
20
+ setIsLoading(false);
21
+ setData({ api: undefined, error: undefined });
22
+ };
23
+ return (_jsx(BridgeStateContext, { value: { isLoading, onConnectionLoading, onConnectionSuccess, onConnectionError, onConnectionEnded, ...data }, children: children }));
24
+ }
25
+ export function useBridgeState(hookName = "useBridgeState", providerName = "BridgeProvider") {
26
+ const context = useContext(BridgeStateContext);
27
+ if (!context) {
28
+ throw new Error(`${hookName} must be used within a ${providerName}`);
29
+ }
30
+ return context;
31
+ }
32
+ //# sourceMappingURL=bridge-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge-provider.js","sourceRoot":"","sources":["../../src/iframe-communication/bridge-provider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAkB,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAgB5E,MAAM,kBAAkB,GAAG,aAAa,CAAmC,SAAS,CAAC,CAAC;AAEtF,MAAM,UAAU,cAAc,CAAC,EAAE,QAAQ,EAA2B;IAClE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAsB,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAC5F,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAElD,MAAM,mBAAmB,GAAG,CAAC,GAAY,EAAE,EAAE;QAC3C,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,OAAO,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IACrC,CAAC,CAAC;IAEF,MAAM,iBAAiB,GAAG,CAAC,KAAY,EAAE,EAAE;QACzC,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,OAAO,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IACrC,CAAC,CAAC;IAEF,MAAM,mBAAmB,GAAG,GAAG,EAAE;QAC/B,YAAY,CAAC,IAAI,CAAC,CAAC;QACnB,OAAO,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAChD,CAAC,CAAC;IAEF,MAAM,iBAAiB,GAAG,GAAG,EAAE;QAC7B,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,OAAO,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAChD,CAAC,CAAC;IAEF,OAAO,CACL,KAAC,kBAAkB,IACjB,KAAK,EAAE,EAAE,SAAS,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,GAAG,IAAI,EAAE,YAE5G,QAAQ,GACU,CACtB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAuB,QAAQ,GAAG,gBAAgB,EAAE,YAAY,GAAG,gBAAgB;IAC/G,MAAM,OAAO,GAAG,UAAU,CAAC,kBAAkB,CAAsB,CAAC;IACpE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,0BAA0B,YAAY,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { type ReactNode } from "react";
2
+ import { IframeApi, PlatformApi } from "./types.js";
3
+ /**
4
+ * Provider for the iframe (app-render) side of the bridge.
5
+ * Wraps the app inside the iframe and connects to the parent platform window.
6
+ *
7
+ * Use `usePlatform()` anywhere inside to access the platform's api.
8
+ */
9
+ export declare function IframeBridgeProvider({ iframeApi, children }: {
10
+ iframeApi: IframeApi;
11
+ children: ReactNode;
12
+ }): import("react/jsx-runtime").JSX.Element;
13
+ /**
14
+ * Hook for iframe-side code to access the platform's api and connection state.
15
+ *
16
+ * Returns `{ api, error, isLoading }`.
17
+ * `api` is undefined before the connection is established.
18
+ */
19
+ export declare function usePlatform(): {
20
+ platformApi: PlatformApi | undefined;
21
+ error: Error | undefined;
22
+ isLoading: boolean;
23
+ };
24
+ //# sourceMappingURL=iframe-bridge-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iframe-bridge-provider.d.ts","sourceRoot":"","sources":["../../src/iframe-communication/iframe-bridge-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,SAAS,EAAiC,MAAM,OAAO,CAAC;AAGrF,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAIjD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE;IAAE,SAAS,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAE,2CAM1G;AAED;;;;;GAKG;AACH,wBAAgB,WAAW;;;;EAyD1B"}
@@ -0,0 +1,68 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { getDomain, getProtocol } from "@blockscom/blocks-client-api/envService";
3
+ import { connect, WindowMessenger } from "penpal";
4
+ import { createContext, useContext, useEffect, useRef } from "react";
5
+ import { BridgeProvider, useBridgeState } from "./bridge-provider.js";
6
+ const IframeApiContext = createContext(undefined);
7
+ /**
8
+ * Provider for the iframe (app-render) side of the bridge.
9
+ * Wraps the app inside the iframe and connects to the parent platform window.
10
+ *
11
+ * Use `usePlatform()` anywhere inside to access the platform's api.
12
+ */
13
+ export function IframeBridgeProvider({ iframeApi, children }) {
14
+ return (_jsx(BridgeProvider, { children: _jsx(IframeApiContext, { value: iframeApi, children: children }) }));
15
+ }
16
+ /**
17
+ * Hook for iframe-side code to access the platform's api and connection state.
18
+ *
19
+ * Returns `{ api, error, isLoading }`.
20
+ * `api` is undefined before the connection is established.
21
+ */
22
+ export function usePlatform() {
23
+ const { error, isLoading, onConnectionSuccess, onConnectionError, onConnectionEnded, onConnectionLoading, api } = useBridgeState("usePlatform", "IframeBridgeProvider");
24
+ const iframeApi = useContext(IframeApiContext);
25
+ const iframeApiRef = useRef(iframeApi);
26
+ useEffect(() => {
27
+ iframeApiRef.current = iframeApi;
28
+ }, [iframeApi]);
29
+ const onConnectionSuccessRef = useRef(onConnectionSuccess);
30
+ useEffect(() => {
31
+ onConnectionSuccessRef.current = onConnectionSuccess;
32
+ }, [onConnectionSuccess]);
33
+ const onConnectionErrorRef = useRef(onConnectionError);
34
+ useEffect(() => {
35
+ onConnectionErrorRef.current = onConnectionError;
36
+ }, [onConnectionError]);
37
+ const onConnectionLoadingRef = useRef(onConnectionLoading);
38
+ useEffect(() => {
39
+ onConnectionLoadingRef.current = onConnectionLoading;
40
+ }, [onConnectionLoading]);
41
+ const onConnectionEndedRef = useRef(onConnectionEnded);
42
+ useEffect(() => {
43
+ onConnectionEndedRef.current = onConnectionEnded;
44
+ }, [onConnectionEnded]);
45
+ useEffect(() => {
46
+ onConnectionLoadingRef.current?.();
47
+ const messenger = new WindowMessenger({
48
+ remoteWindow: window.parent,
49
+ allowedOrigins: [new RegExp(`^${getProtocol()}://(b-\\d+\\.)?${getDomain().replace(/\./g, "\\.")}$`)],
50
+ });
51
+ const connection = connect({
52
+ messenger,
53
+ methods: iframeApiRef.current,
54
+ // log: debug("iframe-window"),
55
+ });
56
+ connection.promise
57
+ .then((platformApi) => onConnectionSuccessRef.current(platformApi))
58
+ .catch((error) => {
59
+ onConnectionErrorRef.current(error);
60
+ });
61
+ return () => {
62
+ connection.destroy();
63
+ onConnectionEndedRef.current?.();
64
+ };
65
+ }, []);
66
+ return { platformApi: api, error, isLoading };
67
+ }
68
+ //# sourceMappingURL=iframe-bridge-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iframe-bridge-provider.js","sourceRoot":"","sources":["../../src/iframe-communication/iframe-bridge-provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,aAAa,EAAkB,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAErF,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnE,MAAM,gBAAgB,GAAG,aAAa,CAAwB,SAAS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,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;IACvD,SAAS,CAAC,GAAG,EAAE;QACb,oBAAoB,CAAC,OAAO,GAAG,iBAAiB,CAAC;IACnD,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAExB,SAAS,CAAC,GAAG,EAAE;QACb,sBAAsB,CAAC,OAAO,EAAE,EAAE,CAAC;QAEnC,MAAM,SAAS,GAAG,IAAI,eAAe,CAAC;YACpC,YAAY,EAAE,MAAM,CAAC,MAAM;YAC3B,cAAc,EAAE,CAAC,IAAI,MAAM,CAAC,IAAI,WAAW,EAAE,kBAAkB,SAAS,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;SACtG,CAAC,CAAC;QAEH,MAAM,UAAU,GAAG,OAAO,CAAc;YACtC,SAAS;YACT,OAAO,EAAE,YAAY,CAAC,OAAO;YAC7B,+BAA+B;SAChC,CAAC,CAAC;QAEH,UAAU,CAAC,OAAO;aACf,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,sBAAsB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;aAClE,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,oBAAoB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QAEL,OAAO,GAAG,EAAE;YACV,UAAU,CAAC,OAAO,EAAE,CAAC;YACrB,oBAAoB,CAAC,OAAO,EAAE,EAAE,CAAC;QACnC,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAChD,CAAC"}
@@ -0,0 +1,5 @@
1
+ export type { ThemeMode, AppUpdate, PlatformApi, IframeApi } from "./types.js";
2
+ export { BridgeProvider, useBridgeState, type BridgeState } from "./bridge-provider.js";
3
+ export { IframeBridgeProvider, usePlatform } from "./iframe-bridge-provider.js";
4
+ export { PlatformBridgeProvider, PlatformBridgeIframe, useIframe } from "./platform-bridge-provider.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/iframe-communication/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErF,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { BridgeProvider, useBridgeState } from "./bridge-provider.js";
2
+ export { IframeBridgeProvider, usePlatform } from "./iframe-bridge-provider.js";
3
+ export { PlatformBridgeProvider, PlatformBridgeIframe, useIframe } from "./platform-bridge-provider.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/iframe-communication/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAoB,MAAM,mBAAmB,CAAC;AAErF,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { type ReactNode } from "react";
2
+ import type { IframeApi, PlatformApi } from "./types.js";
3
+ /**
4
+ * Context provider for the platform (Remix) side of the bridge.
5
+ * Does NOT render any iframe — use `PlatformBridgeIframe` inside this provider.
6
+ *
7
+ * `methods` — handlers the iframe can call on the platform.
8
+ * Use `useIframe()` anywhere inside to check `isLoaded` and call iframe methods.
9
+ */
10
+ export declare function PlatformBridgeProvider({ children }: {
11
+ children: ReactNode;
12
+ }): import("react/jsx-runtime").JSX.Element;
13
+ type PlatformBridgeIframeProps = {
14
+ platformApi: PlatformApi;
15
+ } & Omit<React.IframeHTMLAttributes<HTMLIFrameElement>, "ref" | "allow">;
16
+ /**
17
+ * The iframe element that establishes the bridge connection.
18
+ * Must be rendered inside a `PlatformBridgeProvider`.
19
+ *
20
+ * Accepts all standard `<iframe>` HTML attributes (`src`, `className`, `allow`, etc.).
21
+ */
22
+ export declare function PlatformBridgeIframe({ platformApi, ...iframeProps }: PlatformBridgeIframeProps): import("react/jsx-runtime").JSX.Element;
23
+ /**
24
+ * Hook for platform-side code to interact with the iframe.
25
+ *
26
+ * Must be used within a `PlatformBridgeProvider`.
27
+ */
28
+ export declare function useIframe(): {
29
+ iframeApi: IframeApi | undefined;
30
+ error: Error | undefined;
31
+ isLoading: boolean;
32
+ };
33
+ export {};
34
+ //# sourceMappingURL=platform-bridge-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform-bridge-provider.d.ts","sourceRoot":"","sources":["../../src/iframe-communication/platform-bridge-provider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAqB,MAAM,OAAO,CAAC;AAG1D,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,2CAE3E;AAED,KAAK,yBAAyB,GAAG;IAAE,WAAW,EAAE,WAAW,CAAA;CAAE,GAAG,IAAI,CAClE,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAC7C,KAAK,GAAG,OAAO,CAChB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,EAAE,yBAAyB,2CAuE9F;AAED;;;;GAIG;AACH,wBAAgB,SAAS;;;;EAQxB"}
@@ -0,0 +1,85 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { connect, WindowMessenger } from "penpal";
3
+ import { useEffect, useRef } from "react";
4
+ import { BridgeProvider, useBridgeState } from "./bridge-provider.js";
5
+ /**
6
+ * Context provider for the platform (Remix) side of the bridge.
7
+ * Does NOT render any iframe — use `PlatformBridgeIframe` inside this provider.
8
+ *
9
+ * `methods` — handlers the iframe can call on the platform.
10
+ * Use `useIframe()` anywhere inside to check `isLoaded` and call iframe methods.
11
+ */
12
+ export function PlatformBridgeProvider({ children }) {
13
+ return _jsx(BridgeProvider, { children: children });
14
+ }
15
+ /**
16
+ * The iframe element that establishes the bridge connection.
17
+ * Must be rendered inside a `PlatformBridgeProvider`.
18
+ *
19
+ * Accepts all standard `<iframe>` HTML attributes (`src`, `className`, `allow`, etc.).
20
+ */
21
+ export function PlatformBridgeIframe({ platformApi, ...iframeProps }) {
22
+ const { onConnectionSuccess, onConnectionError, onConnectionLoading, onConnectionEnded } = useBridgeState("PlatformBridgeIframe", "PlatformBridgeProvider");
23
+ const platformApiRef = useRef(platformApi);
24
+ useEffect(() => {
25
+ platformApiRef.current = platformApi;
26
+ }, [platformApi]);
27
+ const onConnectionSuccessRef = useRef(onConnectionSuccess);
28
+ useEffect(() => {
29
+ onConnectionSuccessRef.current = onConnectionSuccess;
30
+ }, [onConnectionSuccess]);
31
+ const onConnectionErrorRef = useRef(onConnectionError);
32
+ useEffect(() => {
33
+ onConnectionErrorRef.current = onConnectionError;
34
+ }, [onConnectionError]);
35
+ const onConnectionLoadingRef = useRef(onConnectionLoading);
36
+ useEffect(() => {
37
+ onConnectionLoadingRef.current = onConnectionLoading;
38
+ }, [onConnectionLoading]);
39
+ const onConnectionEndedRef = useRef(onConnectionEnded);
40
+ useEffect(() => {
41
+ onConnectionEndedRef.current = onConnectionEnded;
42
+ }, [onConnectionEnded]);
43
+ const iframeRef = useRef(null);
44
+ useEffect(() => {
45
+ const iframe = iframeRef.current;
46
+ if (!iframe?.contentWindow) {
47
+ onConnectionEndedRef.current();
48
+ return;
49
+ }
50
+ onConnectionLoadingRef.current();
51
+ const messenger = new WindowMessenger({
52
+ remoteWindow: iframe.contentWindow,
53
+ allowedOrigins: [new URL(iframe.src).origin],
54
+ });
55
+ const connection = connect({
56
+ messenger,
57
+ methods: platformApiRef.current,
58
+ // log: debug("platform-window"),
59
+ });
60
+ connection.promise
61
+ .then((api) => onConnectionSuccessRef.current(api))
62
+ .catch((error) => {
63
+ onConnectionErrorRef.current(error);
64
+ });
65
+ return () => {
66
+ connection.destroy();
67
+ onConnectionEndedRef.current();
68
+ };
69
+ }, []);
70
+ return (_jsx("iframe", { ref: iframeRef, allow: "accelerometer; autoplay; camera; encrypted-media; fullscreen; geolocation; gyroscope; microphone; midi; clipboard-read; clipboard-write; payment; usb; xr-spatial-tracking; screen-wake-lock; magnetometer; gamepad; picture-in-picture; display-capture; bluetooth;", ...iframeProps }));
71
+ }
72
+ /**
73
+ * Hook for platform-side code to interact with the iframe.
74
+ *
75
+ * Must be used within a `PlatformBridgeProvider`.
76
+ */
77
+ export function useIframe() {
78
+ const { api, error, isLoading } = useBridgeState("useIframe", "PlatformBridgeProvider");
79
+ return {
80
+ iframeApi: api,
81
+ error,
82
+ isLoading,
83
+ };
84
+ }
85
+ //# sourceMappingURL=platform-bridge-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform-bridge-provider.js","sourceRoot":"","sources":["../../src/iframe-communication/platform-bridge-provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAkB,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnE;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAAC,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GAAG;QACd,KAAK;QACL,SAAS;KACV,CAAC;AACJ,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { type Methods } from "penpal";
2
+ export type ThemeMode = "dark" | "light" | "system";
3
+ export interface AppUpdate {
4
+ id: string;
5
+ name: string;
6
+ defaultPageBlockId?: string;
7
+ compiledAt: number;
8
+ theme: {
9
+ variables?: Record<string, string>;
10
+ darkVariables?: Record<string, string>;
11
+ };
12
+ }
13
+ /**
14
+ * Methods the platform (Remix parent window) exposes to the iframe (app-render).
15
+ * Called by code running inside the iframe to communicate back to the platform.
16
+ */
17
+ export interface PlatformApi extends Methods {
18
+ getToken: () => Promise<string>;
19
+ onLogout: () => void;
20
+ onIframePageChange: (args: {
21
+ changeToPageId: string;
22
+ searchParams?: string;
23
+ }) => Promise<void>;
24
+ onIframeThemeModeChange: (themeMode: ThemeMode) => Promise<void>;
25
+ onFatalAppError: (errorData: {
26
+ error: Error;
27
+ blockId?: string;
28
+ componentStack?: string;
29
+ }) => Promise<void>;
30
+ onMissingPageError: (errorData: {
31
+ url: string;
32
+ pages: {
33
+ id: string;
34
+ name: string;
35
+ }[];
36
+ }) => Promise<void>;
37
+ onLoad: () => Promise<void>;
38
+ chooseElement: (data: {
39
+ name: string;
40
+ filePath: string;
41
+ line: string;
42
+ }) => Promise<void>;
43
+ }
44
+ /**
45
+ * Methods the iframe (app-render) exposes to the platform (Remix parent window).
46
+ * Called by the platform to push state changes into the iframe.
47
+ */
48
+ export interface IframeApi extends Methods {
49
+ onPlatformPageChange: (args: {
50
+ changeToPageName: string;
51
+ searchParams?: string;
52
+ }) => Promise<void>;
53
+ onAppUpdate: (appChanges: Partial<AppUpdate>) => Promise<void>;
54
+ onChangeViewAsRole: (args: {
55
+ role: string | undefined;
56
+ }) => Promise<void>;
57
+ onPlatformThemeModeChange: (themeMode: ThemeMode) => Promise<void>;
58
+ onChangeIsVisualEditMode: (isVisualEditMode: boolean) => Promise<void>;
59
+ }
60
+ //# sourceMappingURL=types.d.ts.map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AA;SAAE,EAAE,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzG,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,aAAa,EAAE,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1F;AAED;;;GAGG;AACH,MAAM,WAAW,SAAU,SAAQ,OAAO;IACxC,oBAAoB,EAAE,CAAC,IAAI,EAAE;QAAE,gBAAgB,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACnG,WAAW,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/D,kBAAkB,EAAE,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1E,yBAAyB,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE,wBAAwB,EAAE,CAAC,gBAAgB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACxE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/iframe-communication/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export * from "./hooks/use-ai-stream-chunks.js";
2
+ export * from "./components/agent-chat.js";
3
+ export * from "./iframe-communication/index.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./hooks/use-ai-stream-chunks.js";
2
+ export * from "./components/agent-chat.js";
3
+ export * from "./iframe-communication/index.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@blocksdiy/react-common",
3
+ "blocksLinkIgnore": false,
4
+ "version": "1.0.0",
5
+ "type": "module",
6
+ "description": "React common",
7
+ "keywords": [],
8
+ "author": "giladsherry <giladsherry@gmail.com>",
9
+ "license": "ISC",
10
+ "main": "dist/index.js",
11
+ "types": "dist/index.d.ts",
12
+ "exports": {
13
+ ".": "./dist/index.js",
14
+ "./useAiStreamChunks": "./dist/hooks/use-ai-stream-chunks.js",
15
+ "./agent-chat": "./dist/components/agent-chat.js",
16
+ "./iframe-communication": "./dist/iframe-communication/index.js"
17
+ },
18
+ "directories": {
19
+ "lib": "src"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "publishConfig": {
25
+ "registry": "https://registry.npmjs.org/",
26
+ "access": "public"
27
+ },
28
+ "nx": {
29
+ "tags": [
30
+ "type:package"
31
+ ]
32
+ },
33
+ "scripts": {
34
+ "clean": "rm -rf ./dist/ && rm -rf tsconfig.tsbuildinfo && rm -rf node_modules",
35
+ "build": "tsc && tsc-alias && echo $(date +%s) > .build-timestamp",
36
+ "test": "echo \"no tests\"",
37
+ "lint": "pnpm eslint src/",
38
+ "lint-fix": "pnpm eslint src/ --fix"
39
+ },
40
+ "dependencies": {
41
+ "@blocksdiy/blocks-client-api": "1.0.0",
42
+ "@radix-ui/react-slot": "^1.2.3",
43
+ "penpal": "^7.0.6",
44
+ "react": "^19.2.3"
45
+ },
46
+ "devDependencies": {
47
+ "@blockscom/eslint-config": "4.6.2",
48
+ "@types/react": "^19.2.14",
49
+ "babel-plugin-react-compiler": "^1.0.0",
50
+ "eslint-plugin-react": "^7.37.5",
51
+ "eslint-plugin-react-hooks": "^7.0.1",
52
+ "tsc-alias": "^1.8.10",
53
+ "typescript": "^5.9.3"
54
+ },
55
+ "engines": {
56
+ "node": ">=24.11.0"
57
+ },
58
+ "packageManager": "pnpm@10.20.0"
59
+ }