@formmy.app/chat 0.0.1-alpha.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Formmy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,186 @@
1
+ # @formmy.app/chat
2
+
3
+ Official SDK for Formmy AI Chat - Build conversational AI experiences in your React applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @formmy.app/chat
9
+ ```
10
+
11
+ **Peer Dependencies:**
12
+ ```bash
13
+ npm install react ai @ai-sdk/react
14
+ ```
15
+
16
+ ## Quick Start
17
+
18
+ ### Backend (Node.js)
19
+
20
+ Use the `Formmy` client to manage agents and conversations from your server.
21
+
22
+ ```typescript
23
+ import { Formmy } from '@formmy.app/chat';
24
+
25
+ const formmy = new Formmy({ secretKey: 'sk_live_xxx' });
26
+
27
+ // List all agents
28
+ const agents = await formmy.agents.list();
29
+
30
+ // Create a new agent
31
+ const { agent } = await formmy.agents.create({
32
+ name: 'Customer Support',
33
+ instructions: 'You are a helpful customer support agent.',
34
+ welcomeMessage: 'Hello! How can I help you today?',
35
+ });
36
+
37
+ // Send a message (non-streaming)
38
+ const response = await formmy.chat.send('Hello!', {
39
+ agentId: agent.id,
40
+ sessionId: 'user_123',
41
+ });
42
+ ```
43
+
44
+ ### Frontend (React)
45
+
46
+ Use the provider and components to add chat to your React app.
47
+
48
+ ```tsx
49
+ import { FormmyProvider, ChatBubble } from '@formmy.app/chat/react';
50
+
51
+ function App() {
52
+ return (
53
+ <FormmyProvider publishableKey="pk_live_xxx">
54
+ <YourApp />
55
+ <ChatBubble
56
+ agentId="agent_xxx"
57
+ position="bottom-right"
58
+ theme="light"
59
+ />
60
+ </FormmyProvider>
61
+ );
62
+ }
63
+ ```
64
+
65
+ ### Headless Hook
66
+
67
+ Build custom chat UIs with the `useFormmyChat` hook.
68
+
69
+ ```tsx
70
+ import { useFormmyChat } from '@formmy.app/chat/react';
71
+
72
+ function CustomChat({ agentId }: { agentId: string }) {
73
+ const { messages, input, setInput, handleSubmit, isLoading } = useFormmyChat({
74
+ agentId,
75
+ });
76
+
77
+ return (
78
+ <div>
79
+ {messages.map((msg) => (
80
+ <div key={msg.id}>
81
+ <strong>{msg.role}:</strong> {msg.content}
82
+ </div>
83
+ ))}
84
+
85
+ <form onSubmit={handleSubmit}>
86
+ <input
87
+ value={input}
88
+ onChange={(e) => setInput(e.target.value)}
89
+ placeholder="Type a message..."
90
+ />
91
+ <button type="submit" disabled={isLoading}>
92
+ Send
93
+ </button>
94
+ </form>
95
+ </div>
96
+ );
97
+ }
98
+ ```
99
+
100
+ ## API Reference
101
+
102
+ ### Formmy Client
103
+
104
+ ```typescript
105
+ const formmy = new Formmy({ secretKey: 'sk_live_xxx' });
106
+
107
+ // Agents
108
+ formmy.agents.list()
109
+ formmy.agents.get(agentId)
110
+ formmy.agents.create({ name, instructions, welcomeMessage?, model? })
111
+ formmy.agents.update(agentId, { name?, instructions?, model? })
112
+ formmy.agents.delete(agentId)
113
+
114
+ // Chat
115
+ formmy.chat.send(message, { agentId, sessionId })
116
+ formmy.chat.history(sessionId, agentId)
117
+ ```
118
+
119
+ ### React Components
120
+
121
+ #### FormmyProvider
122
+
123
+ ```tsx
124
+ <FormmyProvider
125
+ publishableKey="pk_live_xxx"
126
+ baseUrl="https://formmy.app" // optional
127
+ >
128
+ {children}
129
+ </FormmyProvider>
130
+ ```
131
+
132
+ #### ChatBubble
133
+
134
+ ```tsx
135
+ <ChatBubble
136
+ agentId="agent_xxx" // required
137
+ position="bottom-right" // bottom-right | bottom-left
138
+ theme="light" // light | dark
139
+ welcomeMessage="Hello!" // optional override
140
+ buttonLabel="Chat with us" // optional
141
+ />
142
+ ```
143
+
144
+ #### useFormmyChat
145
+
146
+ ```typescript
147
+ const {
148
+ messages, // Message[]
149
+ input, // string
150
+ setInput, // (value: string) => void
151
+ handleSubmit, // (e: FormEvent) => void
152
+ isLoading, // boolean
153
+ error, // Error | null
154
+ reload, // () => void
155
+ stop, // () => void
156
+ } = useFormmyChat({ agentId });
157
+ ```
158
+
159
+ ## Keys
160
+
161
+ | Key Type | Prefix | Usage | Scope |
162
+ |----------|--------|-------|-------|
163
+ | Secret Key | `sk_live_` | Backend only | Full API access |
164
+ | Publishable Key | `pk_live_` | Frontend safe | Chat only, domain-restricted |
165
+
166
+ Get your keys at [formmy.app/dashboard/api-keys](https://formmy.app/dashboard/api-keys)
167
+
168
+ ## TypeScript
169
+
170
+ Full TypeScript support included.
171
+
172
+ ```typescript
173
+ import type {
174
+ FormmyMessage,
175
+ Agent,
176
+ FormmyConfig
177
+ } from '@formmy.app/chat';
178
+ ```
179
+
180
+ ## Documentation
181
+
182
+ Full documentation at [formmy.app/docs/sdk](https://formmy.app/docs/sdk)
183
+
184
+ ## License
185
+
186
+ MIT
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @formmy.app/react - Backend Client
3
+ *
4
+ * Usage:
5
+ * ```typescript
6
+ * import { Formmy } from '@formmy.app/react/client';
7
+ *
8
+ * const formmy = new Formmy({ secretKey: 'sk_live_xxx' });
9
+ *
10
+ * // Create agent
11
+ * const agent = await formmy.agents.create({ name: 'Mi Asistente' });
12
+ *
13
+ * // List agents
14
+ * const { agents } = await formmy.agents.list();
15
+ * ```
16
+ */
17
+ import type { FormmyConfig, CreateAgentInput, UpdateAgentInput, AgentsListResponse, AgentResponse } from "./types";
18
+ export declare class FormmyError extends Error {
19
+ code: string;
20
+ status: number;
21
+ constructor(message: string, code: string, status: number);
22
+ }
23
+ export declare class Formmy {
24
+ private secretKey;
25
+ private baseUrl;
26
+ constructor(config: FormmyConfig);
27
+ get agents(): {
28
+ /**
29
+ * List all agents for the authenticated user
30
+ */
31
+ list: () => Promise<AgentsListResponse>;
32
+ /**
33
+ * Get a specific agent by ID
34
+ */
35
+ get: (agentId: string) => Promise<AgentResponse>;
36
+ /**
37
+ * Create a new agent
38
+ */
39
+ create: (data: CreateAgentInput) => Promise<AgentResponse>;
40
+ /**
41
+ * Update an existing agent
42
+ */
43
+ update: (agentId: string, data: UpdateAgentInput) => Promise<AgentResponse>;
44
+ /**
45
+ * Delete an agent (soft delete)
46
+ */
47
+ delete: (agentId: string) => Promise<{
48
+ success: boolean;
49
+ }>;
50
+ };
51
+ get chat(): {
52
+ /**
53
+ * Send a message and get a response (non-streaming)
54
+ * For streaming, use the useFormmyChat hook on the frontend
55
+ */
56
+ send: (options: {
57
+ agentId: string;
58
+ message: string;
59
+ conversationId?: string;
60
+ }) => Promise<{
61
+ content: string;
62
+ conversationId: string;
63
+ }>;
64
+ };
65
+ private request;
66
+ }
67
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACd,MAAM,SAAS,CAAC;AAIjB,qBAAa,WAAY,SAAQ,KAAK;IAG3B,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,MAAM;gBAFrB,OAAO,EAAE,MAAM,EACR,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM;CAKxB;AAED,qBAAa,MAAM;IACjB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,YAAY;IAiBhC,IAAI,MAAM;QAEN;;WAEG;oBACa,OAAO,CAAC,kBAAkB,CAAC;QAI3C;;WAEG;uBACkB,MAAM,KAAG,OAAO,CAAC,aAAa,CAAC;QAOpD;;WAEG;uBACkB,gBAAgB,KAAG,OAAO,CAAC,aAAa,CAAC;QAI9D;;WAEG;0BAEQ,MAAM,QACT,gBAAgB,KACrB,OAAO,CAAC,aAAa,CAAC;QAQzB;;WAEG;0BACqB,MAAM,KAAG,OAAO,CAAC;YAAE,OAAO,EAAE,OAAO,CAAA;SAAE,CAAC;MAOjE;IAMD,IAAI,IAAI;QAEJ;;;WAGG;wBACmB;YACpB,OAAO,EAAE,MAAM,CAAC;YAChB,OAAO,EAAE,MAAM,CAAC;YAChB,cAAc,CAAC,EAAE,MAAM,CAAC;SACzB,KAAG,OAAO,CAAC;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,cAAc,EAAE,MAAM,CAAA;SAAE,CAAC;MA4D3D;YAMa,OAAO;CA4BtB"}
@@ -0,0 +1,156 @@
1
+ /**
2
+ * @formmy.app/react - Backend Client
3
+ *
4
+ * Usage:
5
+ * ```typescript
6
+ * import { Formmy } from '@formmy.app/react/client';
7
+ *
8
+ * const formmy = new Formmy({ secretKey: 'sk_live_xxx' });
9
+ *
10
+ * // Create agent
11
+ * const agent = await formmy.agents.create({ name: 'Mi Asistente' });
12
+ *
13
+ * // List agents
14
+ * const { agents } = await formmy.agents.list();
15
+ * ```
16
+ */
17
+ const DEFAULT_BASE_URL = "https://formmy.app";
18
+ export class FormmyError extends Error {
19
+ code;
20
+ status;
21
+ constructor(message, code, status) {
22
+ super(message);
23
+ this.code = code;
24
+ this.status = status;
25
+ this.name = "FormmyError";
26
+ }
27
+ }
28
+ export class Formmy {
29
+ secretKey;
30
+ baseUrl;
31
+ constructor(config) {
32
+ if (!config.secretKey) {
33
+ throw new Error("Formmy client requires a secretKey (sk_live_xxx)");
34
+ }
35
+ if (!config.secretKey.startsWith("sk_live_")) {
36
+ throw new Error("Invalid secretKey format. Must start with sk_live_");
37
+ }
38
+ this.secretKey = config.secretKey;
39
+ this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;
40
+ }
41
+ // ═══════════════════════════════════════════════════════════════════════════
42
+ // Agents Namespace
43
+ // ═══════════════════════════════════════════════════════════════════════════
44
+ get agents() {
45
+ return {
46
+ /**
47
+ * List all agents for the authenticated user
48
+ */
49
+ list: async () => {
50
+ return this.request("GET", "?intent=agents.list");
51
+ },
52
+ /**
53
+ * Get a specific agent by ID
54
+ */
55
+ get: async (agentId) => {
56
+ return this.request("GET", `?intent=agents.get&agentId=${agentId}`);
57
+ },
58
+ /**
59
+ * Create a new agent
60
+ */
61
+ create: async (data) => {
62
+ return this.request("POST", "?intent=agents.create", data);
63
+ },
64
+ /**
65
+ * Update an existing agent
66
+ */
67
+ update: async (agentId, data) => {
68
+ return this.request("POST", `?intent=agents.update&agentId=${agentId}`, data);
69
+ },
70
+ /**
71
+ * Delete an agent (soft delete)
72
+ */
73
+ delete: async (agentId) => {
74
+ return this.request("POST", `?intent=agents.delete&agentId=${agentId}`);
75
+ },
76
+ };
77
+ }
78
+ // ═══════════════════════════════════════════════════════════════════════════
79
+ // Chat Namespace (for server-side chat)
80
+ // ═══════════════════════════════════════════════════════════════════════════
81
+ get chat() {
82
+ return {
83
+ /**
84
+ * Send a message and get a response (non-streaming)
85
+ * For streaming, use the useFormmyChat hook on the frontend
86
+ */
87
+ send: async (options) => {
88
+ // For server-side, we make a regular POST and read the full response
89
+ const sessionId = options.conversationId || `sdk_${Date.now()}`;
90
+ const response = await fetch(`${this.baseUrl}/api/v2/sdk?intent=chat&agentId=${options.agentId}`, {
91
+ method: "POST",
92
+ headers: {
93
+ "Content-Type": "application/json",
94
+ Authorization: `Bearer ${this.secretKey}`,
95
+ },
96
+ body: JSON.stringify({
97
+ message: {
98
+ id: `msg_${Date.now()}`,
99
+ role: "user",
100
+ parts: [{ type: "text", text: options.message }],
101
+ },
102
+ id: sessionId,
103
+ }),
104
+ });
105
+ if (!response.ok) {
106
+ const error = await response.json().catch(() => ({}));
107
+ throw new FormmyError(error.error || "Request failed", error.code || "REQUEST_FAILED", response.status);
108
+ }
109
+ // Read streaming response as text
110
+ const text = await response.text();
111
+ // Parse SSE response - Vercel AI SDK format
112
+ // Lines starting with "0:" contain text content chunks
113
+ const lines = text.split("\n");
114
+ const contentParts = [];
115
+ for (const line of lines) {
116
+ if (line.startsWith("0:")) {
117
+ try {
118
+ const parsed = JSON.parse(line.slice(2));
119
+ if (typeof parsed === "string") {
120
+ contentParts.push(parsed);
121
+ }
122
+ }
123
+ catch {
124
+ // Log malformed chunks but don't lose the rest
125
+ console.warn("[Formmy SDK] Malformed SSE chunk:", line.slice(0, 100));
126
+ }
127
+ }
128
+ }
129
+ return {
130
+ content: contentParts.join(""),
131
+ conversationId: sessionId,
132
+ };
133
+ },
134
+ };
135
+ }
136
+ // ═══════════════════════════════════════════════════════════════════════════
137
+ // Private methods
138
+ // ═══════════════════════════════════════════════════════════════════════════
139
+ async request(method, path, body) {
140
+ const url = `${this.baseUrl}/api/v2/sdk${path}`;
141
+ const response = await fetch(url, {
142
+ method,
143
+ headers: {
144
+ "Content-Type": "application/json",
145
+ Authorization: `Bearer ${this.secretKey}`,
146
+ },
147
+ body: body ? JSON.stringify(body) : undefined,
148
+ });
149
+ const data = await response.json();
150
+ if (!response.ok) {
151
+ throw new FormmyError(data.error || "Request failed", data.code || "REQUEST_FAILED", response.status);
152
+ }
153
+ return data;
154
+ }
155
+ }
156
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAUH,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAE9C,MAAM,OAAO,WAAY,SAAQ,KAAK;IAG3B;IACA;IAHT,YACE,OAAe,EACR,IAAY,EACZ,MAAc;QAErB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,SAAI,GAAJ,IAAI,CAAQ;QACZ,WAAM,GAAN,MAAM,CAAQ;QAGrB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,MAAM,OAAO,MAAM;IACT,SAAS,CAAS;IAClB,OAAO,CAAS;IAExB,YAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACtE,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC7C,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACxE,CAAC;QAED,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,gBAAgB,CAAC;IACpD,CAAC;IAED,8EAA8E;IAC9E,mBAAmB;IACnB,8EAA8E;IAE9E,IAAI,MAAM;QACR,OAAO;YACL;;eAEG;YACH,IAAI,EAAE,KAAK,IAAiC,EAAE;gBAC5C,OAAO,IAAI,CAAC,OAAO,CAAqB,KAAK,EAAE,qBAAqB,CAAC,CAAC;YACxE,CAAC;YAED;;eAEG;YACH,GAAG,EAAE,KAAK,EAAE,OAAe,EAA0B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C;gBAED,OAAO;oBACL,OAAO,EAAE,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC9B,cAAc,EAAE,SAAS;iBAC1B,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC;IAED,8EAA8E;IAC9E,kBAAkB;IAClB,8EAA8E;IAEtE,KAAK,CAAC,OAAO,CACnB,MAAyC,EACzC,IAAY,EACZ,IAAc;QAEd,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,cAAc,IAAI,EAAE,CAAC;QAEhD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAChC,MAAM;YACN,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,IAAI,CAAC,SAAS,EAAE;aAC1C;YACD,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEnC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,WAAW,CACnB,IAAI,CAAC,KAAK,IAAI,gBAAgB,EAC9B,IAAI,CAAC,IAAI,IAAI,gBAAgB,EAC7B,QAAQ,CAAC,MAAM,CAChB,CAAC;QACJ,CAAC;QAED,OAAO,IAAS,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @formmy.app/react - Type definitions
3
+ */
4
+ export interface FormmyConfig {
5
+ /** Publishable key for frontend (pk_live_xxx) */
6
+ publishableKey?: string;
7
+ /** Secret key for backend (sk_live_xxx) */
8
+ secretKey?: string;
9
+ /** Base URL for Formmy API (default: https://formmy.app) */
10
+ baseUrl?: string;
11
+ }
12
+ export interface FormmyProviderProps extends FormmyConfig {
13
+ children: React.ReactNode;
14
+ }
15
+ export interface UseFormmyChatOptions {
16
+ /** Agent ID to chat with */
17
+ agentId: string;
18
+ /** Initial messages to load */
19
+ initialMessages?: Message[];
20
+ /** Existing conversation ID to continue */
21
+ conversationId?: string;
22
+ /** Called when a new message is received */
23
+ onMessage?: (message: Message) => void;
24
+ /** Called on error */
25
+ onError?: (error: Error) => void;
26
+ /** Called when streaming finishes */
27
+ onFinish?: () => void;
28
+ }
29
+ export interface Message {
30
+ id: string;
31
+ role: "user" | "assistant" | "system";
32
+ content?: string;
33
+ parts?: MessagePart[];
34
+ createdAt?: Date;
35
+ }
36
+ export type MessagePart = {
37
+ type: "text";
38
+ text: string;
39
+ } | {
40
+ type: string;
41
+ toolCallId: string;
42
+ toolName: string;
43
+ args: unknown;
44
+ output?: unknown;
45
+ };
46
+ export interface Agent {
47
+ id: string;
48
+ name: string;
49
+ slug: string;
50
+ aiModel: string;
51
+ instructions?: string;
52
+ welcomeMessage?: string;
53
+ customInstructions?: string;
54
+ status: "ACTIVE" | "INACTIVE" | "DELETED";
55
+ createdAt: string;
56
+ updatedAt?: string;
57
+ }
58
+ export interface CreateAgentInput {
59
+ name: string;
60
+ instructions?: string;
61
+ welcomeMessage?: string;
62
+ model?: string;
63
+ }
64
+ export interface UpdateAgentInput {
65
+ name?: string;
66
+ instructions?: string;
67
+ welcomeMessage?: string;
68
+ customInstructions?: string;
69
+ model?: string;
70
+ }
71
+ export interface ChatBubbleProps {
72
+ /** Agent ID to chat with */
73
+ agentId: string;
74
+ /** Position of the bubble trigger */
75
+ position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
76
+ /** Theme customization */
77
+ theme?: ChatTheme;
78
+ /** Initial open state */
79
+ defaultOpen?: boolean;
80
+ /** Callback when open state changes */
81
+ onOpenChange?: (open: boolean) => void;
82
+ }
83
+ export interface ChatTheme {
84
+ /** Primary color for buttons and accents */
85
+ primaryColor?: string;
86
+ /** Background color for the chat panel */
87
+ backgroundColor?: string;
88
+ /** Text color */
89
+ textColor?: string;
90
+ /** Border radius for the panel */
91
+ borderRadius?: string;
92
+ }
93
+ export interface ApiResponse<T> {
94
+ data?: T;
95
+ error?: string;
96
+ code?: string;
97
+ }
98
+ export interface AgentsListResponse {
99
+ agents: Agent[];
100
+ }
101
+ export interface AgentResponse {
102
+ agent: Agent;
103
+ }
104
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,MAAM,WAAW,YAAY;IAC3B,iDAAiD;IACjD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,mBAAoB,SAAQ,YAAY;IACvD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAMD,MAAM,WAAW,oBAAoB;IACnC,4BAA4B;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,eAAe,CAAC,EAAE,OAAO,EAAE,CAAC;IAC5B,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,sBAAsB;IACtB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,qCAAqC;IACrC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,IAAI,CAAC;CAClB;AAED,MAAM,MAAM,WAAW,GACnB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AyB;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uCAAuC;IACvC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CACxC;AAED,MAAM,WAAW,SAAS;IACxB,4CAA4C;IAC5C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAMD,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,KAAK,CAAC;CACd"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @formmy.app/react - Type definitions
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @formmy.app/chat/react - useFormmyChat Hook
3
+ *
4
+ * Headless hook for chat functionality, wrapping Vercel AI SDK's useChat.
5
+ *
6
+ * Usage:
7
+ * ```tsx
8
+ * import { useFormmyChat } from '@formmy.app/chat/react';
9
+ *
10
+ * function Chat() {
11
+ * const { messages, sendMessage, status } = useFormmyChat({
12
+ * agentId: 'agent_123',
13
+ * });
14
+ *
15
+ * return (
16
+ * <div>
17
+ * {messages.map(m => <div key={m.id}>{getMessageText(m)}</div>)}
18
+ * <button onClick={() => sendMessage('Hello!')}>Send</button>
19
+ * </div>
20
+ * );
21
+ * }
22
+ * ```
23
+ */
24
+ import type { UseFormmyChatOptions } from "../core/types";
25
+ /**
26
+ * Extract text content from a message's parts
27
+ */
28
+ export declare function getMessageText(message: {
29
+ parts?: Array<{
30
+ type: string;
31
+ text?: string;
32
+ }>;
33
+ }): string;
34
+ /**
35
+ * Headless chat hook - provides all chat functionality without UI
36
+ */
37
+ export declare function useFormmyChat(options: UseFormmyChatOptions): {
38
+ messages: import("ai").UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>[];
39
+ status: import("ai").ChatStatus;
40
+ error: Error | undefined;
41
+ sessionId: string;
42
+ agentId: string;
43
+ sendMessage: (text: string) => Promise<void>;
44
+ reset: () => void;
45
+ stop: () => Promise<void>;
46
+ setMessages: (messages: import("ai").UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>[] | ((messages: import("ai").UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>[]) => import("ai").UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>[])) => void;
47
+ getMessageText: typeof getMessageText;
48
+ _chat: import("@ai-sdk/react").UseChatHelpers<import("ai").UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>>;
49
+ };
50
+ //# sourceMappingURL=use-formmy-chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-formmy-chat.d.ts","sourceRoot":"","sources":["../../src/hooks/use-formmy-chat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAMH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAK1D;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE;IAAE,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,GAAG,MAAM,CAMlG;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB;;;;;;wBAmG1C,MAAM;;;;;;EAuCtB"}