@esheet/renderer 0.0.3 → 0.0.4-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.
package/README.md CHANGED
@@ -39,7 +39,7 @@ import { EsheetRenderer } from '@esheet/renderer';
39
39
  import type { FormDefinition } from '@esheet/core';
40
40
 
41
41
  const myForm: FormDefinition = {
42
- schemaType: 'mieforms-v1.0',
42
+ id: 'patient-intake',
43
43
  title: 'Patient Intake',
44
44
  fields: [
45
45
  {
@@ -105,7 +105,7 @@ function App() {
105
105
 
106
106
  ```tsx
107
107
  const yamlSchema = `
108
- schemaType: mieforms-v1.0
108
+ id: simple-form
109
109
  title: Simple Form
110
110
  fields:
111
111
  - id: q1
@@ -164,7 +164,7 @@ EsheetRenderer is a thin wrapper that:
164
164
 
165
165
  ```tsx
166
166
  const conditionalForm: FormDefinition = {
167
- schemaType: 'mieforms-v1.0',
167
+ id: 'conditional-form',
168
168
  title: 'Conditional Form',
169
169
  fields: [
170
170
  {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,12 @@
1
1
  import { default as default_2 } from 'react';
2
+ import { FhirQuestionnaireResponse } from '@esheet/adapters';
3
+ import { FieldDefinition } from '@esheet/core';
4
+ import { FormDefinition } from '@esheet/core';
2
5
  import { FormResponse } from '@esheet/core';
6
+ import { FormResponseEnvelope } from '@esheet/core';
3
7
  import { FormStore } from '@esheet/core';
4
8
  import { JSX } from 'react/jsx-runtime';
9
+ import { ResponseExportOptions } from '@esheet/adapters';
5
10
  import { UIStore } from '@esheet/core';
6
11
  import { ValidationError } from '@esheet/core';
7
12
 
@@ -30,6 +35,30 @@ export declare const EsheetRenderer: default_2.ForwardRefExoticComponent<EsheetR
30
35
  export declare interface EsheetRendererHandle {
31
36
  /** Get current form responses */
32
37
  getRawResponse: () => FormResponse;
38
+ /**
39
+ * Get form responses in the specified format.
40
+ *
41
+ * @param options - Format and export options
42
+ * @returns Native FormResponse or FHIR QuestionnaireResponse
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * // Native format (default)
47
+ * const native = ref.current.getResponse();
48
+ *
49
+ * // FHIR QuestionnaireResponse
50
+ * const fhir = ref.current.getResponse({
51
+ * format: 'fhir',
52
+ * fhir: {
53
+ * questionnaireUrl: 'http://example.org/Questionnaire/my-form',
54
+ * status: 'completed',
55
+ * }
56
+ * });
57
+ * ```
58
+ */
59
+ getResponse: <T extends ResponseFormat = 'native'>(options?: GetResponseOptions & {
60
+ format?: T;
61
+ }) => GetResponseResult<T>;
33
62
  /** Get form store instance */
34
63
  getFormStore: () => FormStore;
35
64
  /** Get UI store instance */
@@ -39,6 +68,12 @@ export declare interface EsheetRendererHandle {
39
68
  response: FormResponse | null;
40
69
  errors: ValidationError[];
41
70
  };
71
+ /** Returns true if touch mode is currently enabled */
72
+ isTouchModeEnabled: () => boolean;
73
+ /** Toggle touch mode on/off. Only works when touchMode prop is 'auto' or undefined. Overrides auto-detection. */
74
+ setTouchMode: (enabled: boolean) => void;
75
+ /** Reset to auto-detection mode (clears manual override). Only works when touchMode='auto'. */
76
+ resetTouchMode: () => void;
42
77
  }
43
78
 
44
79
  export declare interface EsheetRendererProps {
@@ -55,8 +90,28 @@ export declare interface EsheetRendererProps {
55
90
  strict?: boolean;
56
91
  /** Called after the form definition has been parsed and loaded into the store. */
57
92
  onReady?: () => void;
93
+ /**
94
+ * Called once after the renderer mounts, providing a narrow `RendererTools`
95
+ * facade for MCP / AI tool integrations.
96
+ */
97
+ onRendererToolsReady?: (tools: RendererTools) => void;
98
+ /**
99
+ * Enable touch-optimized mode with larger touch targets.
100
+ * - `true`: Always enable touch mode
101
+ * - `false`: Never enable touch mode (CSS media query still applies)
102
+ * - `'auto'`: Enable based on viewport width (<980px) via JavaScript
103
+ * - `undefined`: Rely on CSS media query only (default)
104
+ */
105
+ touchMode?: boolean | 'auto';
106
+ /**
107
+ * Called when touch mode changes (via auto-detection or programmatic toggle).
108
+ * Useful for syncing external UI with the renderer's touch state.
109
+ */
110
+ onTouchModeChange?: (enabled: boolean) => void;
58
111
  }
59
112
 
113
+ export declare function executeToolCall(toolName: string, args: ToolArgs, tools: RendererTools): string | Record<string, unknown>;
114
+
60
115
  /**
61
116
  * FieldNode - Renders a single field or section with recursive children
62
117
  *
@@ -73,6 +128,28 @@ declare interface FieldNodeProps {
73
128
  depth?: number;
74
129
  }
75
130
 
131
+ export { FormDefinition }
132
+
133
+ export { FormResponseEnvelope }
134
+
135
+ /** Options for getResponse() */
136
+ export declare interface GetResponseOptions {
137
+ /** Output format: 'native' (default) or 'fhir' (FHIR QuestionnaireResponse) */
138
+ format?: ResponseFormat;
139
+ /** FHIR export options (required when format is 'fhir') */
140
+ fhir?: Omit<ResponseExportOptions, 'questionnaireUrl'> & {
141
+ /** Canonical URL of the questionnaire. Falls back to form._sourceData metadata if available. */
142
+ questionnaireUrl?: string;
143
+ };
144
+ }
145
+
146
+ /** Return type for getResponse() — varies by format */
147
+ export declare type GetResponseResult<T extends ResponseFormat = 'native'> = T extends 'fhir' ? FhirQuestionnaireResponse : FormResponse;
148
+
149
+ export declare const RENDERER_SYSTEM_PROMPT: string;
150
+
151
+ export declare const RENDERER_TOOL_DEFINITIONS: readonly ToolDefinition[];
152
+
76
153
  /**
77
154
  * RendererBody - Iterates over visible root fields and renders them
78
155
  *
@@ -87,16 +164,128 @@ declare interface RendererBodyProps {
87
164
  ui: UIStore;
88
165
  }
89
166
 
167
+ /** Summary of a single field, suitable for AI context. */
168
+ declare interface RendererFieldSummary {
169
+ id: string;
170
+ fieldType: string;
171
+ /** For text fields: the HTML input type (e.g. 'date', 'datetime-local', 'month', 'time', 'email', 'number'). Use the correct format when filling this field. */
172
+ inputType?: string;
173
+ /** Required value format for structured input types. Use this exact format when calling fill_field. */
174
+ valueFormat?: string;
175
+ question: string | undefined;
176
+ required: boolean;
177
+ /** True if this field already has a response value. False means it is still empty and needs to be filled. */
178
+ hasValue: boolean;
179
+ /** Available option values for selection fields (radio, check, dropdown, etc.). Only present when the field has options. */
180
+ options?: string[];
181
+ /** Available row labels for matrix fields. Only present for singlematrix / multimatrix. */
182
+ rows?: string[];
183
+ /** Available column labels for matrix fields. Only present for singlematrix / multimatrix. */
184
+ columns?: string[];
185
+ }
186
+
187
+ /**
188
+ * Narrow interface exposed to MCP / AI tools via `onRendererToolsReady`.
189
+ * Read-oriented: inspect responses, fill responses, and query the render tree.
190
+ */
191
+ export declare interface RendererTools {
192
+ /** Currently visible, fillable fields with their available options. */
193
+ getForm: () => {
194
+ formId: string;
195
+ fieldCount: number;
196
+ fields: RendererFieldSummary[];
197
+ };
198
+ /** All fields in the form regardless of visibility, rules, or enabled state. */
199
+ getFormRaw: () => {
200
+ formId: string;
201
+ fieldCount: number;
202
+ fields: RendererFieldSummary[];
203
+ };
204
+ /** Get current raw responses keyed by field ID. */
205
+ getResponses: () => Record<string, unknown>;
206
+ /** Get validated responses — returns null if validation fails. */
207
+ getValidResponse: () => {
208
+ response: Record<string, unknown> | null;
209
+ errors: ValidationError[];
210
+ };
211
+ /** Set a response value for one visible field. Returns true on success, false if field not found/visible, or an error string if the value format is invalid. */
212
+ fillField: (fieldId: string, value: unknown) => boolean | string;
213
+ /** Clear all responses. */
214
+ clearResponses: () => void;
215
+ /** Full render tree with visibility/enabled/required per field. */
216
+ getFormTree: () => RenderFieldNode[];
217
+ /** Find a field ID by exact ID or partial question match. */
218
+ resolveFieldId: (fieldId?: string, fieldQuestion?: string) => string | undefined;
219
+ }
220
+
221
+ declare interface RenderFieldNode {
222
+ /** Field identifier. */
223
+ id: string;
224
+ /** Field definition without nested children. */
225
+ definition: Omit<FieldDefinition, 'fields'>;
226
+ /** Computed visible state. */
227
+ visible: boolean;
228
+ /** Computed enabled state. */
229
+ enabled: boolean;
230
+ /** Computed required state. */
231
+ required: boolean;
232
+ /** Renderable child nodes (sections only). */
233
+ children: RenderFieldNode[];
234
+ }
235
+
236
+ /** Response format options for getResponse() */
237
+ export declare type ResponseFormat = 'native' | 'fhir';
238
+
239
+ declare type ToolArgs = Record<string, unknown>;
240
+
241
+ export declare interface ToolDefinition {
242
+ type: string;
243
+ function: {
244
+ name: string;
245
+ description: string;
246
+ parameters: Record<string, unknown>;
247
+ };
248
+ }
249
+
90
250
  /**
91
251
  * Initialize renderer with form definition.
92
252
  *
93
253
  * Auto-detects and converts the following input formats:
94
254
  * - eSheet FormDefinition (object or JSON/YAML string)
255
+ * - FHIR R4 Questionnaire resource
95
256
  * - MCP elicitation/create envelope
96
257
  * - SurveyJS schema (has top-level `pages` or `elements` array)
97
258
  */
98
259
  export declare function useRendererInit(form: FormStore, ui: UIStore, formData: unknown, initialResponses?: FormResponse, onValidationError?: (errors: string[]) => void, strict?: boolean, onReady?: () => void): void;
99
260
 
261
+ /**
262
+ * Listens for AI tool-call events on a target element and dispatches them to
263
+ * the renderer's MCP tool executor. Returns the `onRendererToolsReady` callback
264
+ * to pass to `<EsheetRenderer>`.
265
+ *
266
+ * @example – default (listens on document)
267
+ * const onRendererToolsReady = useRendererMcpToolHandler({ eventName: 'ozwell-tool-call' });
268
+ * <EsheetRenderer onRendererToolsReady={onRendererToolsReady} ... />
269
+ *
270
+ * @example – scoped to a container element
271
+ * const ref = React.useRef<HTMLDivElement>(null);
272
+ * const onRendererToolsReady = useRendererMcpToolHandler({ target: ref.current ?? undefined, eventName: 'ozwell-tool-call' });
273
+ * <div ref={ref}><EsheetRenderer onRendererToolsReady={onRendererToolsReady} ... /></div>
274
+ */
275
+ export declare function useRendererMcpToolHandler(options: UseRendererMcpToolHandlerOptions): (tools: RendererTools) => void;
276
+
277
+ export declare interface UseRendererMcpToolHandlerOptions {
278
+ /**
279
+ * The DOM element to listen on for tool-call events.
280
+ * Pass `document` to listen globally, or a specific element to scope it.
281
+ */
282
+ target?: EventTarget;
283
+ /**
284
+ * The event name to listen for, e.g. `'ozwell-tool-call'`.
285
+ */
286
+ eventName: string;
287
+ }
288
+
100
289
  export { ValidationError }
101
290
 
102
291
  export { }