@informedai/react 0.4.12 → 0.4.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -109,6 +109,12 @@ interface InformedAssistantConfig {
109
109
  onSessionChange?: (session: Session) => void;
110
110
  /** Callback when an error occurs */
111
111
  onError?: (error: Error) => void;
112
+ /**
113
+ * Callback to get current field values from your form.
114
+ * Called before each message is sent so the AI knows about unsaved changes.
115
+ * Return the current values of all fields as they appear in your UI.
116
+ */
117
+ getCurrentFieldValues?: () => Record<string, unknown>;
112
118
  /** Custom theme overrides */
113
119
  theme?: Partial<WidgetTheme>;
114
120
  /** Position of the widget (for floating mode) */
@@ -267,14 +273,24 @@ declare class InformedAIClient {
267
273
  getSession(id: string): Promise<GetSessionResponse>;
268
274
  /**
269
275
  * Send a message to the session with SSE streaming.
276
+ *
277
+ * @param sessionId - The session ID
278
+ * @param message - The user's message
279
+ * @param onEvent - SSE event handler
280
+ * @param currentFieldValues - Current values from the UI form (for unsaved changes context)
270
281
  */
271
- sendMessage(sessionId: string, message: string, onEvent: (event: SSEEvent) => void): Promise<void>;
282
+ sendMessage(sessionId: string, message: string, onEvent: (event: SSEEvent) => void, currentFieldValues?: Record<string, unknown>): Promise<void>;
272
283
  /**
273
284
  * Send a quick action to the session.
274
285
  * For actions that trigger AI (task_action:*), returns SSE stream.
275
286
  * For other actions (select_task:*, resume_task:*), returns session directly.
287
+ *
288
+ * @param sessionId - The session ID
289
+ * @param action - The quick action string
290
+ * @param onEvent - Optional SSE event handler
291
+ * @param currentFieldValues - Current values from the UI form (for task_action context)
276
292
  */
277
- sendQuickAction(sessionId: string, action: string, onEvent?: (event: SSEEvent) => void): Promise<Session>;
293
+ sendQuickAction(sessionId: string, action: string, onEvent?: (event: SSEEvent) => void, currentFieldValues?: Record<string, unknown>): Promise<Session>;
278
294
  /**
279
295
  * Apply the pending value for the active task.
280
296
  */
package/dist/index.d.ts CHANGED
@@ -109,6 +109,12 @@ interface InformedAssistantConfig {
109
109
  onSessionChange?: (session: Session) => void;
110
110
  /** Callback when an error occurs */
111
111
  onError?: (error: Error) => void;
112
+ /**
113
+ * Callback to get current field values from your form.
114
+ * Called before each message is sent so the AI knows about unsaved changes.
115
+ * Return the current values of all fields as they appear in your UI.
116
+ */
117
+ getCurrentFieldValues?: () => Record<string, unknown>;
112
118
  /** Custom theme overrides */
113
119
  theme?: Partial<WidgetTheme>;
114
120
  /** Position of the widget (for floating mode) */
@@ -267,14 +273,24 @@ declare class InformedAIClient {
267
273
  getSession(id: string): Promise<GetSessionResponse>;
268
274
  /**
269
275
  * Send a message to the session with SSE streaming.
276
+ *
277
+ * @param sessionId - The session ID
278
+ * @param message - The user's message
279
+ * @param onEvent - SSE event handler
280
+ * @param currentFieldValues - Current values from the UI form (for unsaved changes context)
270
281
  */
271
- sendMessage(sessionId: string, message: string, onEvent: (event: SSEEvent) => void): Promise<void>;
282
+ sendMessage(sessionId: string, message: string, onEvent: (event: SSEEvent) => void, currentFieldValues?: Record<string, unknown>): Promise<void>;
272
283
  /**
273
284
  * Send a quick action to the session.
274
285
  * For actions that trigger AI (task_action:*), returns SSE stream.
275
286
  * For other actions (select_task:*, resume_task:*), returns session directly.
287
+ *
288
+ * @param sessionId - The session ID
289
+ * @param action - The quick action string
290
+ * @param onEvent - Optional SSE event handler
291
+ * @param currentFieldValues - Current values from the UI form (for task_action context)
276
292
  */
277
- sendQuickAction(sessionId: string, action: string, onEvent?: (event: SSEEvent) => void): Promise<Session>;
293
+ sendQuickAction(sessionId: string, action: string, onEvent?: (event: SSEEvent) => void, currentFieldValues?: Record<string, unknown>): Promise<Session>;
278
294
  /**
279
295
  * Apply the pending value for the active task.
280
296
  */
package/dist/index.js CHANGED
@@ -91,12 +91,17 @@ var InformedAIClient = class {
91
91
  }
92
92
  /**
93
93
  * Send a message to the session with SSE streaming.
94
+ *
95
+ * @param sessionId - The session ID
96
+ * @param message - The user's message
97
+ * @param onEvent - SSE event handler
98
+ * @param currentFieldValues - Current values from the UI form (for unsaved changes context)
94
99
  */
95
- async sendMessage(sessionId, message, onEvent) {
100
+ async sendMessage(sessionId, message, onEvent, currentFieldValues) {
96
101
  const response = await fetch(`${this.apiUrl}/widget/sessions/${sessionId}/message`, {
97
102
  method: "POST",
98
103
  headers: this.getHeaders(),
99
- body: JSON.stringify({ message })
104
+ body: JSON.stringify({ message, currentFieldValues })
100
105
  });
101
106
  if (!response.ok) {
102
107
  const error = await response.json().catch(() => ({ error: "Request failed" }));
@@ -108,12 +113,17 @@ var InformedAIClient = class {
108
113
  * Send a quick action to the session.
109
114
  * For actions that trigger AI (task_action:*), returns SSE stream.
110
115
  * For other actions (select_task:*, resume_task:*), returns session directly.
116
+ *
117
+ * @param sessionId - The session ID
118
+ * @param action - The quick action string
119
+ * @param onEvent - Optional SSE event handler
120
+ * @param currentFieldValues - Current values from the UI form (for task_action context)
111
121
  */
112
- async sendQuickAction(sessionId, action, onEvent) {
122
+ async sendQuickAction(sessionId, action, onEvent, currentFieldValues) {
113
123
  const response = await fetch(`${this.apiUrl}/widget/sessions/${sessionId}/quick-action`, {
114
124
  method: "POST",
115
125
  headers: this.getHeaders(),
116
- body: JSON.stringify({ action })
126
+ body: JSON.stringify({ action, currentFieldValues })
117
127
  });
118
128
  if (!response.ok) {
119
129
  const error = await response.json().catch(() => ({ error: "Request failed" }));
@@ -575,7 +585,8 @@ function InformedAIProvider({ config, children }) {
575
585
  setIsStreaming(true);
576
586
  setStreamingContent("");
577
587
  setError(null);
578
- await clientRef.current.sendMessage(session.id, message, handleSSEEvent);
588
+ const currentFieldValues = config.getCurrentFieldValues?.();
589
+ await clientRef.current.sendMessage(session.id, message, handleSSEEvent, currentFieldValues);
579
590
  } catch (err) {
580
591
  if (isSessionNotFoundError(err)) {
581
592
  await handleSessionDeleted();
@@ -594,10 +605,12 @@ function InformedAIProvider({ config, children }) {
594
605
  setIsStreaming(true);
595
606
  setStreamingContent("");
596
607
  setError(null);
608
+ const currentFieldValues = action.startsWith("task_action:") ? config.getCurrentFieldValues?.() : void 0;
597
609
  const newSession = await clientRef.current.sendQuickAction(
598
610
  session.id,
599
611
  action,
600
- handleSSEEvent
612
+ handleSSEEvent,
613
+ currentFieldValues
601
614
  );
602
615
  setSession(newSession);
603
616
  config.onSessionChange?.(newSession);
package/dist/index.mjs CHANGED
@@ -61,12 +61,17 @@ var InformedAIClient = class {
61
61
  }
62
62
  /**
63
63
  * Send a message to the session with SSE streaming.
64
+ *
65
+ * @param sessionId - The session ID
66
+ * @param message - The user's message
67
+ * @param onEvent - SSE event handler
68
+ * @param currentFieldValues - Current values from the UI form (for unsaved changes context)
64
69
  */
65
- async sendMessage(sessionId, message, onEvent) {
70
+ async sendMessage(sessionId, message, onEvent, currentFieldValues) {
66
71
  const response = await fetch(`${this.apiUrl}/widget/sessions/${sessionId}/message`, {
67
72
  method: "POST",
68
73
  headers: this.getHeaders(),
69
- body: JSON.stringify({ message })
74
+ body: JSON.stringify({ message, currentFieldValues })
70
75
  });
71
76
  if (!response.ok) {
72
77
  const error = await response.json().catch(() => ({ error: "Request failed" }));
@@ -78,12 +83,17 @@ var InformedAIClient = class {
78
83
  * Send a quick action to the session.
79
84
  * For actions that trigger AI (task_action:*), returns SSE stream.
80
85
  * For other actions (select_task:*, resume_task:*), returns session directly.
86
+ *
87
+ * @param sessionId - The session ID
88
+ * @param action - The quick action string
89
+ * @param onEvent - Optional SSE event handler
90
+ * @param currentFieldValues - Current values from the UI form (for task_action context)
81
91
  */
82
- async sendQuickAction(sessionId, action, onEvent) {
92
+ async sendQuickAction(sessionId, action, onEvent, currentFieldValues) {
83
93
  const response = await fetch(`${this.apiUrl}/widget/sessions/${sessionId}/quick-action`, {
84
94
  method: "POST",
85
95
  headers: this.getHeaders(),
86
- body: JSON.stringify({ action })
96
+ body: JSON.stringify({ action, currentFieldValues })
87
97
  });
88
98
  if (!response.ok) {
89
99
  const error = await response.json().catch(() => ({ error: "Request failed" }));
@@ -545,7 +555,8 @@ function InformedAIProvider({ config, children }) {
545
555
  setIsStreaming(true);
546
556
  setStreamingContent("");
547
557
  setError(null);
548
- await clientRef.current.sendMessage(session.id, message, handleSSEEvent);
558
+ const currentFieldValues = config.getCurrentFieldValues?.();
559
+ await clientRef.current.sendMessage(session.id, message, handleSSEEvent, currentFieldValues);
549
560
  } catch (err) {
550
561
  if (isSessionNotFoundError(err)) {
551
562
  await handleSessionDeleted();
@@ -564,10 +575,12 @@ function InformedAIProvider({ config, children }) {
564
575
  setIsStreaming(true);
565
576
  setStreamingContent("");
566
577
  setError(null);
578
+ const currentFieldValues = action.startsWith("task_action:") ? config.getCurrentFieldValues?.() : void 0;
567
579
  const newSession = await clientRef.current.sendQuickAction(
568
580
  session.id,
569
581
  action,
570
- handleSSEEvent
582
+ handleSSEEvent,
583
+ currentFieldValues
571
584
  );
572
585
  setSession(newSession);
573
586
  config.onSessionChange?.(newSession);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@informedai/react",
3
- "version": "0.4.12",
3
+ "version": "0.4.13",
4
4
  "description": "React SDK for InformedAI Assistant - AI-powered content creation widget",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",