@grapesjs/studio-sdk-plugins 1.0.32 → 1.0.33-rc.1

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 (57) hide show
  1. package/dist/aiChat/clientTools.d.ts +4 -0
  2. package/dist/aiChat/clientToolsProcessors.d.ts +94 -0
  3. package/dist/aiChat/components/AiChatEmptyState.d.ts +9 -0
  4. package/dist/aiChat/components/AiChatError.d.ts +4 -0
  5. package/dist/aiChat/components/AiChatHeader.d.ts +5 -0
  6. package/dist/aiChat/components/AiChatInput.d.ts +17 -0
  7. package/dist/aiChat/components/AiChatLoadingState.d.ts +4 -0
  8. package/dist/aiChat/components/AiChatMessage.d.ts +17 -0
  9. package/dist/aiChat/components/AiChatMessages.d.ts +13 -0
  10. package/dist/aiChat/components/AiChatPanel.d.ts +14 -0
  11. package/dist/aiChat/components/index.d.ts +41 -0
  12. package/dist/aiChat/components/utils.d.ts +34 -0
  13. package/dist/aiChat/index.d.ts +4 -0
  14. package/dist/aiChat/server/index.d.ts +54 -0
  15. package/dist/aiChat/server/models.d.ts +15 -0
  16. package/dist/aiChat/server/prompts.d.ts +23 -0
  17. package/dist/aiChat/server/stream-utils.d.ts +16 -0
  18. package/dist/aiChat/server/stream.d.ts +21 -0
  19. package/dist/aiChat/server/tools.d.ts +90 -0
  20. package/dist/aiChat/server/types.d.ts +165 -0
  21. package/dist/aiChat/shared.d.ts +3 -0
  22. package/dist/aiChat/types.d.ts +470 -0
  23. package/dist/aiChat/typesSchema.d.ts +41 -0
  24. package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
  25. package/dist/googleFontsAssetProvider/index.es.js +35 -35
  26. package/dist/googleFontsAssetProvider/index.umd.js +1 -1
  27. package/dist/iconifyComponent/index.cjs.js +2 -2
  28. package/dist/iconifyComponent/index.es.js +64 -64
  29. package/dist/iconifyComponent/index.umd.js +2 -2
  30. package/dist/index.cjs.js +63 -63
  31. package/dist/index.es.js +6444 -6280
  32. package/dist/index.umd.js +72 -72
  33. package/dist/layoutSidebarButtons/index.cjs.js +1 -1
  34. package/dist/layoutSidebarButtons/index.es.js +35 -35
  35. package/dist/layoutSidebarButtons/index.umd.js +1 -1
  36. package/dist/presetPrintable/index.cjs.js +4 -4
  37. package/dist/presetPrintable/index.es.js +131 -131
  38. package/dist/presetPrintable/index.umd.js +4 -4
  39. package/dist/prosemirror/commands.d.ts +14 -0
  40. package/dist/prosemirror/index.cjs.js +9 -9
  41. package/dist/prosemirror/index.es.js +1736 -1572
  42. package/dist/prosemirror/index.umd.js +9 -9
  43. package/dist/prosemirror/schema.d.ts +48 -5
  44. package/dist/prosemirror/toolbar.d.ts +5 -0
  45. package/dist/prosemirror/types.d.ts +13 -5
  46. package/dist/prosemirror/utils.d.ts +9 -3
  47. package/dist/rteTinyMce/index.cjs.js +2 -2
  48. package/dist/rteTinyMce/index.es.js +13 -13
  49. package/dist/rteTinyMce/index.umd.js +2 -2
  50. package/dist/tableComponent/index.cjs.js +1 -1
  51. package/dist/tableComponent/index.es.js +1 -1
  52. package/dist/tableComponent/index.umd.js +1 -1
  53. package/dist/types.d.ts +1 -1
  54. package/dist/youtubeAssetProvider/index.cjs.js +1 -1
  55. package/dist/youtubeAssetProvider/index.es.js +51 -51
  56. package/dist/youtubeAssetProvider/index.umd.js +1 -1
  57. package/package.json +49 -2
@@ -0,0 +1,4 @@
1
+ import { Editor } from 'grapesjs';
2
+ import { AiChatDefaultTools, AiChatToolApis } from './types';
3
+ export declare const defaultToolApis: Required<AiChatToolApis>;
4
+ export declare function createDefaultTools(editor: Editor, toolApis?: AiChatToolApis): AiChatDefaultTools;
@@ -0,0 +1,94 @@
1
+ import { UIMessage } from '@ai-sdk/react';
2
+ import { ChatOnDataCallback } from 'ai';
3
+ import { Component, Editor } from 'grapesjs';
4
+ import { UpdatesFromStream } from './components/utils';
5
+ import { AiChatToolName, AiChatToolsArguments, ChatToolAgentCode, ToolDataAddComponent, ToolDataAddPage, ToolDataAddProjectPage, ToolDataEditComponent, ToolDataTypes } from './types';
6
+ export interface ToolAddComponentSetupResult {
7
+ target: Component | undefined;
8
+ at: number | undefined;
9
+ domPosition: InsertPosition;
10
+ tempDOM: HTMLDivElement;
11
+ tempTargetEl: HTMLElement | undefined;
12
+ cleanUp: () => void;
13
+ }
14
+ export interface ToolEditComponentSetupResult {
15
+ toUpdate: {
16
+ cleanup(): void;
17
+ update: (content: string) => Map<string, UpdatesFromStream>;
18
+ };
19
+ mapUpdates: Map<string, UpdatesFromStream>;
20
+ cleanUp: () => void;
21
+ }
22
+ export interface ToolAddPageSetupResult {
23
+ pageId: string;
24
+ cmpRoot: Component;
25
+ cleanUp: () => void;
26
+ }
27
+ export interface ToolAddProjectPageSetupResult {
28
+ cmpRoot: Component;
29
+ pageName: string;
30
+ isEmail: boolean;
31
+ cleanUp: () => void;
32
+ }
33
+ interface ToolStatusAddComponent {
34
+ type: ChatToolAgentCode.ADD_COMPONENT_CODE;
35
+ toolSetup: ToolAddComponentSetupResult;
36
+ completed?: boolean;
37
+ }
38
+ interface ToolStatusEditComponent {
39
+ type: ChatToolAgentCode.EDIT_COMPONENT_CODE;
40
+ toolSetup: ToolEditComponentSetupResult;
41
+ completed?: boolean;
42
+ }
43
+ interface ToolStatusAddPage {
44
+ type: ChatToolAgentCode.ADD_PAGE_CODE;
45
+ toolSetup: ToolAddPageSetupResult;
46
+ completed?: boolean;
47
+ }
48
+ interface ToolStatusAddProjectPage {
49
+ type: ChatToolAgentCode.ADD_PROJECT_PAGE_CODE;
50
+ toolSetup: ToolAddProjectPageSetupResult;
51
+ completed?: boolean;
52
+ }
53
+ export type ToolStatusProgressEntry = ToolStatusAddComponent | ToolStatusEditComponent | ToolStatusAddPage | ToolStatusAddProjectPage;
54
+ export type ToolStatusProgressMap = Map<string, ToolStatusProgressEntry>;
55
+ export declare function toolAddComponentSetup(editor: Editor, args: AiChatToolsArguments[AiChatToolName.ADD_NEW_COMPONENT]): ToolAddComponentSetupResult;
56
+ export declare function toolAddComponentEnd(editor: Editor, toolSetup: ToolAddComponentSetupResult, content: string): Component | undefined;
57
+ export declare function processToolAddComponent(props: {
58
+ editor: Editor;
59
+ toolStatus: ToolDataAddComponent;
60
+ toolStatusProgress: ToolStatusProgressMap;
61
+ }): void;
62
+ export declare function toolEditComponentEnd(editor: Editor, toolSetup: ToolEditComponentSetupResult): void;
63
+ export declare function processToolEditComponent(props: {
64
+ editor: Editor;
65
+ toolStatus: ToolDataEditComponent;
66
+ toolStatusProgress: ToolStatusProgressMap;
67
+ }): void;
68
+ export declare function toolAddPageEnd(toolSetup: ToolAddPageSetupResult, content: string): void;
69
+ export declare function processToolAddPage(props: {
70
+ editor: Editor;
71
+ toolStatus: ToolDataAddPage;
72
+ toolStatusProgress: ToolStatusProgressMap;
73
+ }): void;
74
+ export declare function toolAddProjectPageEnd(editor: Editor, content: string, name: string): void;
75
+ export declare const commandMjmlToHtml = "mjml-code-to-html";
76
+ export declare function processToolNewProjectPage(props: {
77
+ editor: Editor;
78
+ toolStatus: ToolDataAddProjectPage;
79
+ toolStatusProgress: ToolStatusProgressMap;
80
+ }): void;
81
+ type DataToolStatusProcessor = (props: {
82
+ editor: Editor;
83
+ toolStatus: ToolDataTypes;
84
+ toolStatusProgress: ToolStatusProgressMap;
85
+ }) => void;
86
+ export declare const dataToolStatusProcessors: {
87
+ [K in ChatToolAgentCode]?: DataToolStatusProcessor;
88
+ };
89
+ export declare const processDataToolsStatus: ({ editor, data, toolStatusProgress }: {
90
+ editor: Editor;
91
+ data: Parameters<ChatOnDataCallback<UIMessage>>[0];
92
+ toolStatusProgress: ToolStatusProgressMap;
93
+ }) => void;
94
+ export {};
@@ -0,0 +1,9 @@
1
+ import { CommonComponentProps } from '../types';
2
+ export interface AiChatEmptyStateProps extends CommonComponentProps {
3
+ /**
4
+ * Suggestions to show in the empty state.
5
+ */
6
+ suggestions?: string[];
7
+ }
8
+ export declare const AiChatEmptyState: React.FC<AiChatEmptyStateProps>;
9
+ export default AiChatEmptyState;
@@ -0,0 +1,4 @@
1
+ import { CommonComponentProps } from '../types';
2
+ export interface AiChatErrorProps extends CommonComponentProps {
3
+ }
4
+ export declare const AiChatError: React.FC<AiChatErrorProps>;
@@ -0,0 +1,5 @@
1
+ import { CommonComponentProps } from '../types';
2
+ export interface AiChatHeaderProps extends CommonComponentProps {
3
+ }
4
+ export declare const AiChatHeader: React.FC<AiChatHeaderProps>;
5
+ export default AiChatHeader;
@@ -0,0 +1,17 @@
1
+ import { CommonComponentProps, UploadedAsset } from '../types';
2
+ export interface AiChatInputProps extends CommonComponentProps {
3
+ /**
4
+ * Maximum number of images per message. Set to 0 to disable images.
5
+ * @default 5
6
+ */
7
+ maxImages?: number;
8
+ /**
9
+ * Upload project assets (images) to server.
10
+ * If not provided and files are added, they will be sent directly to the chat.
11
+ */
12
+ uploadProjectAssets?: (props: {
13
+ files: File[];
14
+ }) => Promise<UploadedAsset[]>;
15
+ }
16
+ export declare const AiChatInput: React.FC<AiChatInputProps>;
17
+ export default AiChatInput;
@@ -0,0 +1,4 @@
1
+ import { CommonComponentProps } from '../types';
2
+ export interface AiChatLoadingStateProps extends CommonComponentProps {
3
+ }
4
+ export declare const AiChatLoadingState: React.FC<AiChatLoadingStateProps>;
@@ -0,0 +1,17 @@
1
+ import { Editor } from 'grapesjs';
2
+ import { CSSProperties } from 'react';
3
+ import { ChatContext, ChatMessage } from '../types';
4
+ export interface AiChatMessageProps {
5
+ editor: Editor;
6
+ chatContext: ChatContext;
7
+ message: ChatMessage;
8
+ isStreaming?: boolean;
9
+ className?: string;
10
+ style?: CSSProperties;
11
+ }
12
+ export interface AiChatMessagePartProps {
13
+ part: ChatMessage['parts'][0];
14
+ isStreamingPart?: boolean;
15
+ }
16
+ export declare const AiChatMessage: React.FC<AiChatMessageProps>;
17
+ export default AiChatMessage;
@@ -0,0 +1,13 @@
1
+ import { useChat } from '@ai-sdk/react';
2
+ import { Editor } from 'grapesjs';
3
+ import { ChatContext, ChatMessage } from '../types';
4
+ type ChatStatus = ReturnType<typeof useChat>['status'];
5
+ export interface AiChatMessagesProps {
6
+ editor: Editor;
7
+ chatContext: ChatContext;
8
+ messages: ChatMessage[];
9
+ status: ChatStatus;
10
+ suggestions?: string[];
11
+ }
12
+ export declare function AiChatMessages({ editor, chatContext, messages, status, suggestions }: AiChatMessagesProps): import("react/jsx-runtime").JSX.Element;
13
+ export default AiChatMessages;
@@ -0,0 +1,14 @@
1
+ import { Editor } from 'grapesjs';
2
+ import { AiChatOptions } from '../types';
3
+ export interface AiChatPanelProps {
4
+ editor: Editor;
5
+ pluginOptions: AiChatOptions;
6
+ style?: React.CSSProperties;
7
+ className?: string;
8
+ }
9
+ /**
10
+ * Uses AI SDK v6 patterns with DefaultChatTransport and sendMessage.
11
+ * Composed of AiChatHeader, AiChatMessages, and AiChatInput subcomponents.
12
+ */
13
+ export declare function AiChatPanel({ editor, pluginOptions, style, className }: AiChatPanelProps): import("react/jsx-runtime").JSX.Element;
14
+ export default AiChatPanel;
@@ -0,0 +1,41 @@
1
+ import { Editor } from 'grapesjs';
2
+ import { AiChatOptions } from '../types';
3
+ import { AiChatEmptyStateProps } from './AiChatEmptyState';
4
+ import { AiChatErrorProps } from './AiChatError';
5
+ import { AiChatHeaderProps } from './AiChatHeader';
6
+ import { AiChatInputProps } from './AiChatInput';
7
+ import { AiChatLoadingStateProps } from './AiChatLoadingState';
8
+ import { AiChatMessageProps } from './AiChatMessage';
9
+ import { AiChatPanelProps } from './AiChatPanel';
10
+ export type { AiChatEmptyStateProps } from './AiChatEmptyState';
11
+ export type { AiChatErrorProps } from './AiChatError';
12
+ export type { AiChatHeaderProps } from './AiChatHeader';
13
+ export type { AiChatInputProps } from './AiChatInput';
14
+ export type { AiChatMessageProps } from './AiChatMessage';
15
+ export type { AiChatMessagesProps } from './AiChatMessages';
16
+ declare module '@studio/editor/src/types' {
17
+ interface CustomLayoutComponentsRegistry {
18
+ aiChatPanel: Pick<AiChatPanelProps, 'className' | 'style'> & {
19
+ type: 'aiChatPanel';
20
+ };
21
+ aiChatHeader: Pick<AiChatHeaderProps, 'className' | 'style' | 'chatContext'> & {
22
+ type: 'aiChatHeader';
23
+ };
24
+ aiChatError: Pick<AiChatErrorProps, 'className' | 'style' | 'chatContext'> & {
25
+ type: 'aiChatError';
26
+ };
27
+ aiChatLoadingState: Pick<AiChatLoadingStateProps, 'className' | 'style' | 'chatContext'> & {
28
+ type: 'aiChatLoadingState';
29
+ };
30
+ aiChatInput: Pick<AiChatInputProps, 'className' | 'style' | 'chatContext' | 'maxImages' | 'uploadProjectAssets'> & {
31
+ type: 'aiChatInput';
32
+ };
33
+ aiChatEmptyState: Pick<AiChatEmptyStateProps, 'className' | 'style' | 'chatContext' | 'suggestions'> & {
34
+ type: 'aiChatEmptyState';
35
+ };
36
+ aiChatMessage: Pick<AiChatMessageProps, 'className' | 'style' | 'chatContext' | 'message' | 'isStreaming'> & {
37
+ type: 'aiChatMessage';
38
+ };
39
+ }
40
+ }
41
+ export declare const registerLayoutComponents: (editor: Editor, options: AiChatOptions) => () => void;
@@ -0,0 +1,34 @@
1
+ import { Component, Editor } from 'grapesjs';
2
+ import { StudioLayoutComponentsConfig } from '../../types';
3
+ import { ProjectContext } from '../types';
4
+ export declare const getProjectContext: (editor: Editor, { withPageContent, imageUrls }?: {
5
+ withPageContent?: boolean;
6
+ imageUrls?: string[];
7
+ }) => ProjectContext;
8
+ export declare const renderLayoutComponent: (editor: Editor, components: StudioLayoutComponentsConfig) => any;
9
+ export declare function clearGeneratedCode(code: string): string;
10
+ export declare const updateDomWithStreamContent: (content?: string, el?: HTMLElement, opts?: {
11
+ skipScroll?: boolean;
12
+ }) => void;
13
+ export declare const getComponentCodeWithIds: (component?: Component) => string;
14
+ export declare function setContentStreamStart(editor: Editor): void;
15
+ export declare function setContentStreamEnd(editor: Editor): void;
16
+ export declare const createToolError: (props: {
17
+ error: any;
18
+ msg: string;
19
+ abortMsg: string;
20
+ }) => {
21
+ error: string;
22
+ abortedByUser: boolean | undefined;
23
+ };
24
+ export declare function getPageContentWithStyles(editor: Editor): string;
25
+ export interface UpdatesFromStream {
26
+ cmp?: Component;
27
+ cmpEl?: HTMLElement;
28
+ newNode: Element;
29
+ }
30
+ export declare const createUpdatesFromStream: (editor: Editor) => {
31
+ cleanup(): void;
32
+ update: (content: string) => Map<string, UpdatesFromStream>;
33
+ };
34
+ export declare const replaceComponentWithHTML: (cmp: Component, content: string) => void;
@@ -0,0 +1,4 @@
1
+ import { SDKPluginWithAiChat } from './types';
2
+ declare const aiChatPlugin: SDKPluginWithAiChat;
3
+ export default aiChatPlugin;
4
+ export type * from './types';
@@ -0,0 +1,54 @@
1
+ /**
2
+ * AI Chat Server Utilities
3
+ *
4
+ * This module provides utilities for creating AI chat endpoints that work
5
+ * with the ai-sdk and integrate with the GrapesJS Studio SDK.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * // In your API route (e.g., Next.js)
10
+ * import {
11
+ * createStreamResponse,
12
+ * createModel,
13
+ * createTool,
14
+ * createToolsWeb,
15
+ * getSystemPromptChatPM
16
+ * } from '@grapesjs/studio-sdk-plugins/dist/aiChat/server';
17
+ *
18
+ * export const POST = async (request: Request) => {
19
+ * const body = await request.json();
20
+ *
21
+ * const model = await createModel('openai/gpt-4', {
22
+ * apiKey: process.env.OPENAI_API_KEY
23
+ * });
24
+ *
25
+ * return createStreamResponse({
26
+ * model,
27
+ * systemPrompt: getSystemPromptChatPM({
28
+ * projectContext: body.projectContext
29
+ * }),
30
+ * messages: body.messages,
31
+ * tools: {
32
+ * ...createToolsWeb(),
33
+ * // Add custom tools
34
+ * myCustomTool: createTool({
35
+ * description: 'Description for the LLM',
36
+ * inputSchema: z.object({
37
+ * input: z.string()
38
+ * }),
39
+ * execute: async ({ input }) => {
40
+ * // Custom logic
41
+ * return { result: 'success' };
42
+ * }
43
+ * })
44
+ * }
45
+ * });
46
+ * };
47
+ * ```
48
+ */
49
+ export { streamText } from 'ai';
50
+ export * from './stream';
51
+ export * from './models';
52
+ export * from './tools';
53
+ export * from './prompts';
54
+ export * from './types';
@@ -0,0 +1,15 @@
1
+ import { LanguageModelV3 } from '@ai-sdk/provider';
2
+ import { CreateModelOptions } from './types';
3
+ /**
4
+ * Create a model instance based on the provider and model name.
5
+ *
6
+ * Supports all native AI SDK providers:
7
+ * @see https://ai-sdk.dev/docs/foundations/providers-and-models
8
+ *
9
+ * @example
10
+ * // OpenAI
11
+ * const model = await createModel('openai/gpt-4', { apiKey: 'sk-...' });
12
+ * // Anthropic
13
+ * const model = await createModel('anthropic/claude-3-opus', { apiKey: 'sk-ant-...' });
14
+ */
15
+ export declare function createModel(modelString: string, options?: CreateModelOptions): Promise<LanguageModelV3>;
@@ -0,0 +1,23 @@
1
+ import { ProjectContext } from '../types';
2
+ /**
3
+ * Get the base system prompt for the Product Manager AI assistant
4
+ */
5
+ export declare function getSystemPromptChat(projectContext: ProjectContext): string;
6
+ export declare function getSystemPromptGenerateProject(projectContext: ProjectContext): string;
7
+ export declare function getSystemPromptGenerateProjectWeb(projectContext: ProjectContext): string;
8
+ export declare function getSystemPromptGenerateProjectEmail(projectContext: ProjectContext): string;
9
+ export declare function getSystemPromptAddPage(projectContext: ProjectContext): string;
10
+ /**
11
+ * Get system prompt for adding components
12
+ */
13
+ export declare function getSystemPromptAddComponent(projectContext: ProjectContext): string;
14
+ export declare function getSystemPromptAddComponentWeb(projectContext: ProjectContext): string;
15
+ export declare function getSystemPromptAddComponentEmail(projectContext: ProjectContext): string;
16
+ export declare function getSystemPromptEditComponent(projectContext: ProjectContext): string;
17
+ /**
18
+ * Get system prompt for editing components
19
+ */
20
+ export declare function getSystemPromptEditComponentWeb(projectContext: ProjectContext): string;
21
+ export declare function getSystemPromptEditComponentEmail(projectContext: ProjectContext): string;
22
+ export declare function getPromptHintCurrentSiteCode({ selectedPage }: ProjectContext): string;
23
+ export declare function getTailwindInstructions(): string;
@@ -0,0 +1,16 @@
1
+ import { ModelMessage } from 'ai';
2
+ import { ToolCallInfo } from './types';
3
+ export declare function injectImagesIntoMessages(messages: ModelMessage[], imageUrls: string[]): ModelMessage[];
4
+ export declare function handleTextChunk(chunk: {
5
+ type: 'text-delta';
6
+ text?: string;
7
+ }, onText?: (text: string) => void | Promise<void>): Promise<void>;
8
+ export declare function handleToolCallChunk(chunk: {
9
+ type: 'tool-call';
10
+ toolCallId: string;
11
+ toolName: string;
12
+ input?: unknown;
13
+ }, toolCalls: ToolCallInfo[], onToolCall?: (toolCall: ToolCallInfo) => void | Promise<void>): Promise<void>;
14
+ export declare function processStreamChunk(chunk: {
15
+ type: string;
16
+ }, toolCalls: ToolCallInfo[], onText?: (text: string) => void | Promise<void>, onToolCall?: (toolCall: ToolCallInfo) => void | Promise<void>): Promise<void>;
@@ -0,0 +1,21 @@
1
+ import { CreateStreamResponseOptions, CreateStreamTextResponseOptions } from './types';
2
+ /**
3
+ * Create a streaming response for AI chat.
4
+ *
5
+ * This is a wrapper around ai-sdk's streamText.
6
+ * Uses AI SDK v6 UIMessage stream architecture.
7
+ * When `tools` is a function `(opts) => Record`, uses createUIMessageStream so tools can use the writer.
8
+ * @see https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream
9
+ * @see https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data
10
+ */
11
+ export declare function createStreamResponse(options: CreateStreamResponseOptions): Promise<Response>;
12
+ /**
13
+ * Create a text streaming response for AI chat.
14
+ *
15
+ * This is a wrapper around ai-sdk's streamText that uses toTextStreamResponse
16
+ * instead of toUIMessageStreamResponse. Useful for simpler sub-agent calls
17
+ * that don't need the full UI message stream architecture.
18
+ *
19
+ * @see https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text
20
+ */
21
+ export declare function createStreamTextResponse(options: CreateStreamTextResponseOptions): Promise<Response>;
@@ -0,0 +1,90 @@
1
+ import { LanguageModelV3 } from '@ai-sdk/provider';
2
+ import { createUIMessageStream, Tool, tool, UIMessageStreamWriter } from 'ai';
3
+ import { z } from 'zod';
4
+ import { ProjectContext } from '../types';
5
+ import { AgentCodeOptions } from './types';
6
+ interface BuildDefaultToolsOptions {
7
+ writer: Parameters<Parameters<typeof createUIMessageStream>[0]['execute']>[0]['writer'];
8
+ agentCode?: AgentCodeOptions;
9
+ abortSignal?: AbortSignal;
10
+ }
11
+ interface CreateToolOptions extends Omit<Parameters<typeof tool>[0], 'inputSchema'> {
12
+ inputSchema: z.ZodTypeAny;
13
+ }
14
+ export declare function createTool<T extends CreateToolOptions>(options: T): Tool<unknown, unknown>;
15
+ export declare const toolAddNewComponent: Tool<unknown, unknown>;
16
+ export interface CreateToolAgentCodeProps {
17
+ writer: UIMessageStreamWriter;
18
+ projectContext: ProjectContext;
19
+ model: LanguageModelV3;
20
+ abortSignal?: AbortSignal;
21
+ }
22
+ /**
23
+ * Returns addNewComponent tool that runs on the server and uses the stream writer
24
+ * to send data-tool-status (in-progress, streaming, done) for real-time UI updates.
25
+ * @see https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream
26
+ */
27
+ export declare function createToolAddComponent(props: CreateToolAgentCodeProps): Tool<unknown, unknown>;
28
+ export declare const toolEditComponent: Tool<unknown, unknown>;
29
+ /**
30
+ * Returns editComponent tool that runs on the server and uses the stream writer
31
+ * to send data-tool-status (in-progress, streaming, done) for real-time UI updates.
32
+ * @see https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream
33
+ */
34
+ export declare function createToolEditComponent(props: CreateToolAgentCodeProps): Tool<unknown, unknown>;
35
+ export declare const toolRemoveComponent: Tool<unknown, unknown>;
36
+ export declare const toolMoveComponent: Tool<unknown, unknown>;
37
+ export declare const toolGetPageContent: Tool<unknown, unknown>;
38
+ export declare const toolListPages: Tool<unknown, unknown>;
39
+ export declare const toolFetchWebsite: Tool<unknown, unknown>;
40
+ export declare const toolAddNewPage: Tool<unknown, unknown>;
41
+ /**
42
+ * Returns addNewPage tool that runs on the server and uses the stream writer
43
+ * to send data-tool-status (in-progress, streaming, done) for real-time UI updates.
44
+ * @see https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream
45
+ */
46
+ export declare function createToolAddPage(props: CreateToolAgentCodeProps): Tool<unknown, unknown>;
47
+ export declare const toolAddNewProjectPage: Tool<unknown, unknown>;
48
+ /**
49
+ * Returns addNewProjectPage tool that runs on the server and uses the stream writer
50
+ * to send data-tool-status (in-progress, streaming, done) for real-time UI updates.
51
+ * @see https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream
52
+ */
53
+ export declare function createToolAddProjectPage(props: CreateToolAgentCodeProps): Tool<unknown, unknown>;
54
+ export declare const toolShowPanel: Tool<unknown, unknown>;
55
+ export declare const toolsNewProject: {
56
+ addNewProjectPage: Tool<unknown, unknown>;
57
+ fetchWebsite: Tool<unknown, unknown>;
58
+ };
59
+ export declare const toolsWeb: {
60
+ addNewPage: Tool<unknown, unknown>;
61
+ addNewComponent: Tool<unknown, unknown>;
62
+ removeComponent: Tool<unknown, unknown>;
63
+ moveComponent: Tool<unknown, unknown>;
64
+ editComponent: Tool<unknown, unknown>;
65
+ getPageContent: Tool<unknown, unknown>;
66
+ listPages: Tool<unknown, unknown>;
67
+ showPanel: Tool<unknown, unknown>;
68
+ fetchWebsite: Tool<unknown, unknown>;
69
+ };
70
+ export declare const toolsEmail: {
71
+ addNewComponent: Tool<unknown, unknown>;
72
+ editComponent: Tool<unknown, unknown>;
73
+ removeComponent: Tool<unknown, unknown>;
74
+ moveComponent: Tool<unknown, unknown>;
75
+ getPageContent: Tool<unknown, unknown>;
76
+ };
77
+ export declare function getDefaultProjectTools({ isEmail, isNewProject }?: Partial<ProjectContext> & {
78
+ isNewProject?: boolean;
79
+ }): {
80
+ addNewProjectPage: Tool<unknown, unknown>;
81
+ fetchWebsite: Tool<unknown, unknown>;
82
+ } | {
83
+ addNewComponent: Tool<unknown, unknown>;
84
+ editComponent: Tool<unknown, unknown>;
85
+ removeComponent: Tool<unknown, unknown>;
86
+ moveComponent: Tool<unknown, unknown>;
87
+ getPageContent: Tool<unknown, unknown>;
88
+ };
89
+ export declare function buildDefaultTools(options: BuildDefaultToolsOptions): Record<string, Tool>;
90
+ export {};
@@ -0,0 +1,165 @@
1
+ import { LanguageModelV3 } from '@ai-sdk/provider';
2
+ import { ModelMessage, Tool, UIMessage, UIMessageStreamOptions, UIMessageStreamWriter, streamText } from 'ai';
3
+ import { JSONSchema7 } from 'json-schema';
4
+ import { ProjectContext } from '../types';
5
+ export type StreamTextOptions = Parameters<typeof streamText>[0];
6
+ /**
7
+ * Options for configuring an agent that generates code (e.g., add/edit components).
8
+ */
9
+ export interface AgentCodeOptions {
10
+ /**
11
+ * The AI model to use for code generation.
12
+ */
13
+ model: LanguageModelV3;
14
+ /**
15
+ * Project context containing information about the current project
16
+ */
17
+ projectContext: ProjectContext;
18
+ }
19
+ /**
20
+ * Options passed to the tools callback function
21
+ */
22
+ export interface ToolsCallbackOptions {
23
+ /**
24
+ * Stream writer for tools that need to write data-tool-status or merge sub-streams
25
+ */
26
+ writer: UIMessageStreamWriter;
27
+ /**
28
+ * Default tools based on project context.
29
+ */
30
+ defaultTools: Record<string, Tool>;
31
+ /**
32
+ * Abort signal passed from the request, useful for cancelling long-running tool operations
33
+ */
34
+ abortSignal?: AbortSignal;
35
+ }
36
+ /**
37
+ * Options for creating a streaming response
38
+ */
39
+ export interface CreateStreamResponseOptions extends Pick<StreamTextOptions, 'toolChoice' | 'providerOptions'> {
40
+ /**
41
+ * The AI model to use
42
+ */
43
+ model: LanguageModelV3;
44
+ /**
45
+ * Messages from the conversation
46
+ */
47
+ messages: UIMessage[];
48
+ /**
49
+ * System prompt for the chat
50
+ */
51
+ systemPrompt?: string;
52
+ /**
53
+ * Abort signal for cancelling the stream and tool operations
54
+ */
55
+ abortSignal?: AbortSignal;
56
+ /**
57
+ * Configuration for the code generation agent.
58
+ * When provided, default tools will be automatically constructed and passed to the tools callback.
59
+ */
60
+ agentCode?: AgentCodeOptions;
61
+ /**
62
+ * Tools available to the AI. Can be a function that receives options including
63
+ * the stream writer, default tools (when agentCode is provided), and abort signal.
64
+ * @see https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream
65
+ * @see https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data
66
+ */
67
+ tools?: Record<string, Tool> | ((options: ToolsCallbackOptions) => Record<string, Tool>);
68
+ /**
69
+ * Image URLs to add to the last user message
70
+ * These will be formatted as image content parts for vision models
71
+ */
72
+ imageUrls?: string[];
73
+ /**
74
+ * Additional stream text options
75
+ */
76
+ streamOptions?: Partial<Omit<StreamTextOptions, 'toolChoice' | 'providerOptions' | 'model' | 'messages' | 'prompt' | 'tools' | 'onText' | 'onToolCall' | 'abortSignal'>>;
77
+ /**
78
+ * Additional response options
79
+ */
80
+ responseOptions?: Partial<UIMessageStreamOptions<UIMessage>>;
81
+ }
82
+ /**
83
+ * Options for creating a text streaming response (using toTextStreamResponse)
84
+ * Similar to CreateStreamResponseOptions but excludes responseOptions and uses prompt instead of messages
85
+ */
86
+ export interface CreateStreamTextResponseOptions extends Pick<StreamTextOptions, 'toolChoice' | 'providerOptions' | 'abortSignal' | 'onFinish' | 'onAbort' | 'onError'> {
87
+ /**
88
+ * The AI model to use
89
+ */
90
+ model: LanguageModelV3;
91
+ /**
92
+ * System prompt for the chat
93
+ */
94
+ system?: string;
95
+ /**
96
+ * User prompt (single string instead of messages array)
97
+ */
98
+ prompt: string;
99
+ /**
100
+ * Tools available to the AI
101
+ */
102
+ tools?: Record<string, Tool>;
103
+ /**
104
+ * Additional stream text options
105
+ */
106
+ streamOptions?: Partial<Omit<StreamTextOptions, 'toolChoice' | 'providerOptions' | 'model' | 'system' | 'prompt' | 'messages' | 'tools' | 'abortSignal' | 'onFinish' | 'onAbort' | 'onError'>>;
107
+ }
108
+ export interface StreamFinishResult {
109
+ text: string;
110
+ usage: {
111
+ promptTokens: number;
112
+ completionTokens: number;
113
+ totalTokens: number;
114
+ };
115
+ model: string;
116
+ /**
117
+ * Uses AI SDK's official type to ensure compatibility
118
+ * Extracted from streamText's onFinish callback parameter type
119
+ */
120
+ finishReason: Parameters<NonNullable<Parameters<typeof streamText>[0]['onFinish']>>[0]['finishReason'];
121
+ toolCalls?: ToolCallInfo[];
122
+ }
123
+ export interface ToolCallInfo {
124
+ toolCallId: string;
125
+ toolName: string;
126
+ args: Record<string, unknown>;
127
+ }
128
+ export interface CreateModelOptions {
129
+ apiKey?: string;
130
+ baseURL?: string;
131
+ [key: string]: unknown;
132
+ }
133
+ export interface ToolDefinition<TArgs = Record<string, unknown>, TResult = unknown> {
134
+ description: string;
135
+ /**
136
+ * JSON schema for the tool's input parameters (ai-sdk v6)
137
+ */
138
+ inputSchema: JSONSchema7;
139
+ execute?: (args: TArgs, context: ToolExecuteContext) => Promise<TResult>;
140
+ }
141
+ export interface ToolExecuteContext {
142
+ toolCallId: string;
143
+ messages: ModelMessage[];
144
+ abortSignal?: AbortSignal;
145
+ }
146
+ /**
147
+ * Options for creating the chat system prompt
148
+ */
149
+ export interface CreateSystemPromptChatOptions {
150
+ /**
151
+ * Project context from the client
152
+ */
153
+ projectContext?: ProjectContext;
154
+ }
155
+ export interface PromptConfig {
156
+ currentSiteCode?: string;
157
+ currentSelectedCode?: string;
158
+ userPrompt?: string;
159
+ projectType?: 'web' | 'email';
160
+ globalStyles?: string;
161
+ devices?: ProjectContext['devices'];
162
+ availablePages?: ProjectContext['availablePages'];
163
+ installedPlugins?: ProjectContext['installedPlugins'];
164
+ imageUrls?: string[];
165
+ }