hazo_collab_forms 1.12.0 → 2.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 (212) hide show
  1. package/CHANGE_LOG.md +49 -0
  2. package/README.md +406 -0
  3. package/dist/components/_internal_form_set.d.ts +13 -0
  4. package/dist/components/_internal_form_set.d.ts.map +1 -1
  5. package/dist/components/_internal_form_set.js +49 -3
  6. package/dist/components/_internal_form_set.js.map +1 -1
  7. package/dist/components/clarification/clarification_badge.d.ts +16 -0
  8. package/dist/components/clarification/clarification_badge.d.ts.map +1 -0
  9. package/dist/components/clarification/clarification_badge.js +15 -0
  10. package/dist/components/clarification/clarification_badge.js.map +1 -0
  11. package/dist/components/clarification/clarification_card.d.ts +48 -0
  12. package/dist/components/clarification/clarification_card.d.ts.map +1 -0
  13. package/dist/components/clarification/clarification_card.js +46 -0
  14. package/dist/components/clarification/clarification_card.js.map +1 -0
  15. package/dist/components/clarification/clarification_dialog.d.ts +32 -0
  16. package/dist/components/clarification/clarification_dialog.d.ts.map +1 -0
  17. package/dist/components/clarification/clarification_dialog.js +63 -0
  18. package/dist/components/clarification/clarification_dialog.js.map +1 -0
  19. package/dist/components/clarification/clarification_doc_reference.d.ts +18 -0
  20. package/dist/components/clarification/clarification_doc_reference.d.ts.map +1 -0
  21. package/dist/components/clarification/clarification_doc_reference.js +22 -0
  22. package/dist/components/clarification/clarification_doc_reference.js.map +1 -0
  23. package/dist/components/clarification/clarification_response_form.d.ts +32 -0
  24. package/dist/components/clarification/clarification_response_form.d.ts.map +1 -0
  25. package/dist/components/clarification/clarification_response_form.js +38 -0
  26. package/dist/components/clarification/clarification_response_form.js.map +1 -0
  27. package/dist/components/clarification/clarification_section.d.ts +26 -0
  28. package/dist/components/clarification/clarification_section.d.ts.map +1 -0
  29. package/dist/components/clarification/clarification_section.js +46 -0
  30. package/dist/components/clarification/clarification_section.js.map +1 -0
  31. package/dist/components/clarification/index.d.ts +18 -0
  32. package/dist/components/clarification/index.d.ts.map +1 -0
  33. package/dist/components/clarification/index.js +13 -0
  34. package/dist/components/clarification/index.js.map +1 -0
  35. package/dist/components/clarification/use_clarifications.d.ts +49 -0
  36. package/dist/components/clarification/use_clarifications.d.ts.map +1 -0
  37. package/dist/components/clarification/use_clarifications.js +160 -0
  38. package/dist/components/clarification/use_clarifications.js.map +1 -0
  39. package/dist/components/collab_form_file_upload.d.ts +16 -1
  40. package/dist/components/collab_form_file_upload.d.ts.map +1 -1
  41. package/dist/components/collab_form_file_upload.js +44 -10
  42. package/dist/components/collab_form_file_upload.js.map +1 -1
  43. package/dist/components/hazo_collab_form_base.d.ts +32 -2
  44. package/dist/components/hazo_collab_form_base.d.ts.map +1 -1
  45. package/dist/components/hazo_collab_form_base.js +11 -5
  46. package/dist/components/hazo_collab_form_base.js.map +1 -1
  47. package/dist/components/hazo_collab_form_group.d.ts +12 -0
  48. package/dist/components/hazo_collab_form_group.d.ts.map +1 -1
  49. package/dist/components/hazo_collab_form_group.js +27 -4
  50. package/dist/components/hazo_collab_form_group.js.map +1 -1
  51. package/dist/components/hazo_collab_form_view/context.d.ts.map +1 -1
  52. package/dist/components/hazo_collab_form_view/context.js +19 -1
  53. package/dist/components/hazo_collab_form_view/context.js.map +1 -1
  54. package/dist/components/hazo_collab_form_view/index.d.ts +1 -1
  55. package/dist/components/hazo_collab_form_view/index.d.ts.map +1 -1
  56. package/dist/components/hazo_collab_form_view/index.js +8 -0
  57. package/dist/components/hazo_collab_form_view/index.js.map +1 -1
  58. package/dist/components/hazo_collab_form_view/types.d.ts +32 -2
  59. package/dist/components/hazo_collab_form_view/types.d.ts.map +1 -1
  60. package/dist/components/hazo_collab_form_view/views/edit_view.d.ts.map +1 -1
  61. package/dist/components/hazo_collab_form_view/views/edit_view.js +74 -8
  62. package/dist/components/hazo_collab_form_view/views/edit_view.js.map +1 -1
  63. package/dist/components/hazo_collab_form_view/views/summary_view.d.ts.map +1 -1
  64. package/dist/components/hazo_collab_form_view/views/summary_view.js +187 -10
  65. package/dist/components/hazo_collab_form_view/views/summary_view.js.map +1 -1
  66. package/dist/components/hazo_data_form/field_renderers/index.d.ts +6 -0
  67. package/dist/components/hazo_data_form/field_renderers/index.d.ts.map +1 -1
  68. package/dist/components/hazo_data_form/field_renderers/index.js +22 -1
  69. package/dist/components/hazo_data_form/field_renderers/index.js.map +1 -1
  70. package/dist/components/hazo_data_form/group_renderer.d.ts.map +1 -1
  71. package/dist/components/hazo_data_form/group_renderer.js +2 -1
  72. package/dist/components/hazo_data_form/group_renderer.js.map +1 -1
  73. package/dist/components/hazo_data_form/shared/data_form_field_layout.d.ts +1 -1
  74. package/dist/components/hazo_data_form/shared/data_form_field_layout.d.ts.map +1 -1
  75. package/dist/components/hazo_data_form/shared/data_form_field_layout.js +3 -3
  76. package/dist/components/hazo_data_form/shared/data_form_field_layout.js.map +1 -1
  77. package/dist/components/hazo_data_form/shared/data_form_reference_value.d.ts +3 -1
  78. package/dist/components/hazo_data_form/shared/data_form_reference_value.d.ts.map +1 -1
  79. package/dist/components/hazo_data_form/shared/data_form_reference_value.js +5 -2
  80. package/dist/components/hazo_data_form/shared/data_form_reference_value.js.map +1 -1
  81. package/dist/components/hazo_data_form/types.d.ts +2 -0
  82. package/dist/components/hazo_data_form/types.d.ts.map +1 -1
  83. package/dist/components/hazo_validation_rule_editor/components/clarification_settings.d.ts +10 -0
  84. package/dist/components/hazo_validation_rule_editor/components/clarification_settings.d.ts.map +1 -0
  85. package/dist/components/hazo_validation_rule_editor/components/clarification_settings.js +57 -0
  86. package/dist/components/hazo_validation_rule_editor/components/clarification_settings.js.map +1 -0
  87. package/dist/components/hazo_validation_rule_editor/components/prompt_editor.d.ts +11 -0
  88. package/dist/components/hazo_validation_rule_editor/components/prompt_editor.d.ts.map +1 -0
  89. package/dist/components/hazo_validation_rule_editor/components/prompt_editor.js +145 -0
  90. package/dist/components/hazo_validation_rule_editor/components/prompt_editor.js.map +1 -0
  91. package/dist/components/hazo_validation_rule_editor/components/rule_editor.d.ts +6 -0
  92. package/dist/components/hazo_validation_rule_editor/components/rule_editor.d.ts.map +1 -0
  93. package/dist/components/hazo_validation_rule_editor/components/rule_editor.js +149 -0
  94. package/dist/components/hazo_validation_rule_editor/components/rule_editor.js.map +1 -0
  95. package/dist/components/hazo_validation_rule_editor/components/rule_list.d.ts +6 -0
  96. package/dist/components/hazo_validation_rule_editor/components/rule_list.d.ts.map +1 -0
  97. package/dist/components/hazo_validation_rule_editor/components/rule_list.js +57 -0
  98. package/dist/components/hazo_validation_rule_editor/components/rule_list.js.map +1 -0
  99. package/dist/components/hazo_validation_rule_editor/context.d.ts +19 -0
  100. package/dist/components/hazo_validation_rule_editor/context.d.ts.map +1 -0
  101. package/dist/components/hazo_validation_rule_editor/context.js +95 -0
  102. package/dist/components/hazo_validation_rule_editor/context.js.map +1 -0
  103. package/dist/components/hazo_validation_rule_editor/hooks/use_file_validation.d.ts +20 -0
  104. package/dist/components/hazo_validation_rule_editor/hooks/use_file_validation.d.ts.map +1 -0
  105. package/dist/components/hazo_validation_rule_editor/hooks/use_file_validation.js +127 -0
  106. package/dist/components/hazo_validation_rule_editor/hooks/use_file_validation.js.map +1 -0
  107. package/dist/components/hazo_validation_rule_editor/hooks/use_validation_rules.d.ts +30 -0
  108. package/dist/components/hazo_validation_rule_editor/hooks/use_validation_rules.d.ts.map +1 -0
  109. package/dist/components/hazo_validation_rule_editor/hooks/use_validation_rules.js +216 -0
  110. package/dist/components/hazo_validation_rule_editor/hooks/use_validation_rules.js.map +1 -0
  111. package/dist/components/hazo_validation_rule_editor/index.d.ts +14 -0
  112. package/dist/components/hazo_validation_rule_editor/index.d.ts.map +1 -0
  113. package/dist/components/hazo_validation_rule_editor/index.js +12 -0
  114. package/dist/components/hazo_validation_rule_editor/index.js.map +1 -0
  115. package/dist/components/hazo_validation_rule_editor/types.d.ts +53 -0
  116. package/dist/components/hazo_validation_rule_editor/types.d.ts.map +1 -0
  117. package/dist/components/hazo_validation_rule_editor/types.js +5 -0
  118. package/dist/components/hazo_validation_rule_editor/types.js.map +1 -0
  119. package/dist/components/hazo_validation_rule_editor/validation_rule_editor.d.ts +3 -0
  120. package/dist/components/hazo_validation_rule_editor/validation_rule_editor.d.ts.map +1 -0
  121. package/dist/components/hazo_validation_rule_editor/validation_rule_editor.js +14 -0
  122. package/dist/components/hazo_validation_rule_editor/validation_rule_editor.js.map +1 -0
  123. package/dist/components/index.d.ts +9 -2
  124. package/dist/components/index.d.ts.map +1 -1
  125. package/dist/components/index.js +9 -1
  126. package/dist/components/index.js.map +1 -1
  127. package/dist/components/shared/field_state/normalize.d.ts.map +1 -1
  128. package/dist/components/shared/field_state/normalize.js +1 -0
  129. package/dist/components/shared/field_state/normalize.js.map +1 -1
  130. package/dist/components/shared/field_state/types.d.ts +6 -0
  131. package/dist/components/shared/field_state/types.d.ts.map +1 -1
  132. package/dist/components/shared/field_utils/types.d.ts +1 -1
  133. package/dist/components/shared/field_utils/types.d.ts.map +1 -1
  134. package/dist/components/shared/strip_base_props.d.ts.map +1 -1
  135. package/dist/components/shared/strip_base_props.js +2 -0
  136. package/dist/components/shared/strip_base_props.js.map +1 -1
  137. package/dist/components/shared/summary_files/summary_files.d.ts +9 -1
  138. package/dist/components/shared/summary_files/summary_files.d.ts.map +1 -1
  139. package/dist/components/shared/summary_files/summary_files.js +11 -5
  140. package/dist/components/shared/summary_files/summary_files.js.map +1 -1
  141. package/dist/components/shared/unified_field_controls/types.d.ts +8 -0
  142. package/dist/components/shared/unified_field_controls/types.d.ts.map +1 -1
  143. package/dist/components/shared/unified_field_controls/unified_field_controls.d.ts +1 -1
  144. package/dist/components/shared/unified_field_controls/unified_field_controls.d.ts.map +1 -1
  145. package/dist/components/shared/unified_field_controls/unified_field_controls.js +3 -2
  146. package/dist/components/shared/unified_field_controls/unified_field_controls.js.map +1 -1
  147. package/dist/components/shared/use_base_form_field.d.ts +14 -0
  148. package/dist/components/shared/use_base_form_field.d.ts.map +1 -1
  149. package/dist/components/shared/use_base_form_field.js +41 -2
  150. package/dist/components/shared/use_base_form_field.js.map +1 -1
  151. package/dist/components/status_badges.d.ts +33 -0
  152. package/dist/components/status_badges.d.ts.map +1 -1
  153. package/dist/components/status_badges.js +27 -2
  154. package/dist/components/status_badges.js.map +1 -1
  155. package/dist/config/clarification_templates.d.ts +24 -0
  156. package/dist/config/clarification_templates.d.ts.map +1 -0
  157. package/dist/config/clarification_templates.js +66 -0
  158. package/dist/config/clarification_templates.js.map +1 -0
  159. package/dist/config/defaults.d.ts +4 -0
  160. package/dist/config/defaults.d.ts.map +1 -1
  161. package/dist/config/defaults.js +4 -0
  162. package/dist/config/defaults.js.map +1 -1
  163. package/dist/config/index.d.ts +3 -1
  164. package/dist/config/index.d.ts.map +1 -1
  165. package/dist/config/index.js +3 -1
  166. package/dist/config/index.js.map +1 -1
  167. package/dist/config/validation_rule_commands.d.ts +12 -0
  168. package/dist/config/validation_rule_commands.d.ts.map +1 -0
  169. package/dist/config/validation_rule_commands.js +106 -0
  170. package/dist/config/validation_rule_commands.js.map +1 -0
  171. package/dist/lib/autofill_handler.d.ts +34 -0
  172. package/dist/lib/autofill_handler.d.ts.map +1 -0
  173. package/dist/lib/autofill_handler.js +330 -0
  174. package/dist/lib/autofill_handler.js.map +1 -0
  175. package/dist/lib/index.d.ts +9 -0
  176. package/dist/lib/index.d.ts.map +1 -1
  177. package/dist/lib/index.js +5 -0
  178. package/dist/lib/index.js.map +1 -1
  179. package/dist/lib/validation_handler.d.ts +27 -0
  180. package/dist/lib/validation_handler.d.ts.map +1 -0
  181. package/dist/lib/validation_handler.js +341 -0
  182. package/dist/lib/validation_handler.js.map +1 -0
  183. package/dist/types/clarification.d.ts +126 -0
  184. package/dist/types/clarification.d.ts.map +1 -0
  185. package/dist/types/clarification.js +8 -0
  186. package/dist/types/clarification.js.map +1 -0
  187. package/dist/types/file_attachment.d.ts +2 -0
  188. package/dist/types/file_attachment.d.ts.map +1 -1
  189. package/dist/types/file_attachment.js.map +1 -1
  190. package/dist/types/file_manager.d.ts +36 -0
  191. package/dist/types/file_manager.d.ts.map +1 -1
  192. package/dist/types/index.d.ts +3 -1
  193. package/dist/types/index.d.ts.map +1 -1
  194. package/dist/types/index.js.map +1 -1
  195. package/dist/types/validation.d.ts +192 -0
  196. package/dist/types/validation.d.ts.map +1 -0
  197. package/dist/types/validation.js +9 -0
  198. package/dist/types/validation.js.map +1 -0
  199. package/dist/utils/build_rule_field_map.d.ts +31 -0
  200. package/dist/utils/build_rule_field_map.d.ts.map +1 -0
  201. package/dist/utils/build_rule_field_map.js +53 -0
  202. package/dist/utils/build_rule_field_map.js.map +1 -0
  203. package/dist/utils/index.d.ts +3 -0
  204. package/dist/utils/index.d.ts.map +1 -1
  205. package/dist/utils/index.js +4 -0
  206. package/dist/utils/index.js.map +1 -1
  207. package/dist/utils/slugify.d.ts +10 -0
  208. package/dist/utils/slugify.d.ts.map +1 -0
  209. package/dist/utils/slugify.js +17 -0
  210. package/dist/utils/slugify.js.map +1 -0
  211. package/package.json +15 -3
  212. package/templates/config/hazo_collab_forms_config.ini +7 -0
@@ -0,0 +1,330 @@
1
+ /**
2
+ * Server-side autofill route handler factory.
3
+ *
4
+ * Wraps hazo_llm_api's hazo_llm_dynamic_data_extract into a ready-made
5
+ * POST handler so consumers can set up autofill in ~2 lines:
6
+ *
7
+ * import { create_autofill_route } from 'hazo_collab_forms/lib';
8
+ * export const POST = create_autofill_route();
9
+ *
10
+ * Uses standard Web API Request/Response for portability (works in Next.js,
11
+ * Deno, Cloudflare Workers, etc.).
12
+ *
13
+ * hazo_llm_api is dynamically imported so it's only required at runtime
14
+ * when the handler is actually called.
15
+ */
16
+ import 'server-only';
17
+ // ============================================================================
18
+ // Helpers
19
+ // ============================================================================
20
+ /**
21
+ * Build a detailed field list string from field schemas.
22
+ * Used as the {{field_list}} variable in LLM prompts.
23
+ */
24
+ function build_field_list_string(fields) {
25
+ return fields.map((f) => {
26
+ let desc = `- "${f.field_id}" (${f.label})`;
27
+ if (f.description)
28
+ desc += `: ${f.description}`;
29
+ if (f.input_type === 'numeric')
30
+ desc += ' [numeric value]';
31
+ if (f.input_options?.length) {
32
+ desc += ` [one of: ${f.input_options.map((o) => o.value).join(', ')}]`;
33
+ }
34
+ if (f.component_type === 'HazoCollabFormCheckbox')
35
+ desc += ' [true/false]';
36
+ if (f.component_type === 'HazoCollabFormDate')
37
+ desc += ' [date in YYYY-MM-DD format]';
38
+ // Data table: enumerate columns so the LLM knows exact column IDs/types
39
+ if (f.component_type === 'HazoCollabFormDataTable' && f.table_config) {
40
+ const config = f.table_config;
41
+ if (config.columns?.length) {
42
+ desc += ': array of row objects with columns:';
43
+ for (const col of config.columns) {
44
+ let col_desc = `\n - "${col.id}" (${col.label})`;
45
+ if (col.field_type === 'numeric' || col.field_type === 'currency') {
46
+ col_desc += ': numeric';
47
+ if (col.constraints?.decimal_places !== undefined) {
48
+ col_desc += ` [${col.constraints.decimal_places} decimal places]`;
49
+ }
50
+ }
51
+ else if (col.field_type === 'dropdown' || col.field_type === 'radiobutton') {
52
+ col_desc += `: ${col.field_type}`;
53
+ }
54
+ else {
55
+ col_desc += ': text';
56
+ }
57
+ if (col.constraints?.required)
58
+ col_desc += ' [required]';
59
+ desc += col_desc;
60
+ }
61
+ }
62
+ else {
63
+ desc += ' [array of row objects]';
64
+ }
65
+ }
66
+ return desc;
67
+ }).join('\n');
68
+ }
69
+ /**
70
+ * Parse LLM response text as JSON, stripping markdown code fences if present.
71
+ */
72
+ function parse_json_response(text) {
73
+ const cleaned = text.trim();
74
+ // Try direct parse first
75
+ try {
76
+ return JSON.parse(cleaned);
77
+ }
78
+ catch {
79
+ // Continue to more sophisticated extraction
80
+ }
81
+ // Strip markdown code fences
82
+ const fence_match = cleaned.match(/```(?:json)?\s*\n?([\s\S]*?)\n?```/);
83
+ if (fence_match) {
84
+ return JSON.parse(fence_match[1].trim());
85
+ }
86
+ // Try to find a JSON object anywhere in the text
87
+ const json_match = cleaned.match(/\{[\s\S]*\}/);
88
+ if (json_match) {
89
+ return JSON.parse(json_match[0]);
90
+ }
91
+ throw new Error('No JSON found in response');
92
+ }
93
+ function is_image_mime(mime_type) {
94
+ return mime_type.startsWith('image/');
95
+ }
96
+ function is_document_mime(mime_type) {
97
+ return mime_type === 'application/pdf';
98
+ }
99
+ // ============================================================================
100
+ // Route Handler Factory
101
+ // ============================================================================
102
+ /**
103
+ * Creates a POST route handler for autofill document extraction.
104
+ *
105
+ * The handler:
106
+ * 1. Validates request (prompt_area, prompt_key required)
107
+ * 2. Initializes hazo_llm_api (once, lazily)
108
+ * 3. Calls hazo_llm_dynamic_data_extract for prompt lookup + LLM extraction
109
+ * 4. Falls back to direct LLM call if dynamic extract isn't suitable
110
+ * 5. Returns extracted data as JSON
111
+ */
112
+ export function create_autofill_route(options) {
113
+ const sqlite_path = options?.sqlite_path ?? 'data/prompt_library.sqlite';
114
+ const on_error = options?.on_error ?? ((err, ctx) => console.error(`[autofill] ${ctx}:`, err));
115
+ let init_promise = null;
116
+ // Cache the dynamic import
117
+ let llm_api_module = null;
118
+ async function get_llm_api() {
119
+ if (!llm_api_module) {
120
+ try {
121
+ // Use variable to prevent TypeScript from resolving the module at compile time
122
+ const module_id = 'hazo_llm_api/server';
123
+ llm_api_module = await import(/* webpackIgnore: true */ module_id);
124
+ }
125
+ catch (err) {
126
+ throw new Error('hazo_llm_api is required for autofill. Install it: npm install hazo_llm_api');
127
+ }
128
+ }
129
+ return llm_api_module;
130
+ }
131
+ async function ensure_initialized() {
132
+ const api = await get_llm_api();
133
+ if (!api.is_initialized()) {
134
+ if (!init_promise) {
135
+ init_promise = api.initialize_llm_api({ sqlite_path }).then(() => { });
136
+ }
137
+ await init_promise;
138
+ }
139
+ }
140
+ /**
141
+ * Generate a default extraction prompt from field schemas.
142
+ * Used as fallback when no prompt exists in the database.
143
+ */
144
+ function generate_default_prompt(fields) {
145
+ const field_list = build_field_list_string(fields);
146
+ return `Extract the following fields from this document and return ONLY valid JSON (no markdown, no explanation).
147
+
148
+ Fields to extract:
149
+ ${field_list}
150
+
151
+ Return a JSON object where keys are the field IDs shown in quotes above.
152
+ For numeric fields, return the value as a string (e.g., "1234.56").
153
+ For checkbox fields, return true or false.
154
+ For date fields, return the date in YYYY-MM-DD format.
155
+ For data table fields, return an array of row objects where each key matches a column ID.
156
+ If a field cannot be found in the document, omit it from the response.
157
+
158
+ Return ONLY the JSON object, no other text.`;
159
+ }
160
+ return async function POST(request) {
161
+ try {
162
+ const body = await request.json();
163
+ const { file_name, mime_type, download_url, file_b64: request_file_b64, prompt_area, prompt_key, fields, } = body;
164
+ // Validate required fields
165
+ if (!prompt_area || !prompt_key) {
166
+ return Response.json({
167
+ success: false,
168
+ error: 'prompt_area and prompt_key are required',
169
+ data: {},
170
+ }, { status: 400 });
171
+ }
172
+ if (!fields?.length) {
173
+ return Response.json({
174
+ success: false,
175
+ error: 'fields array is required and must not be empty',
176
+ data: {},
177
+ }, { status: 400 });
178
+ }
179
+ // Initialize hazo_llm_api
180
+ await ensure_initialized();
181
+ const api = await get_llm_api();
182
+ // Get file as base64 — prefer inline data, fall back to fetching from download_url
183
+ let file_b64;
184
+ if (request_file_b64) {
185
+ file_b64 = request_file_b64;
186
+ }
187
+ else {
188
+ try {
189
+ const absolute_url = download_url.startsWith('http')
190
+ ? download_url
191
+ : `${new URL(request.url).origin}${download_url}`;
192
+ const file_response = await fetch(absolute_url);
193
+ if (!file_response.ok) {
194
+ throw new Error(`Failed to fetch file: ${file_response.status}`);
195
+ }
196
+ const buffer = Buffer.from(await file_response.arrayBuffer());
197
+ file_b64 = buffer.toString('base64');
198
+ }
199
+ catch (err) {
200
+ return Response.json({
201
+ success: false,
202
+ error: `Failed to fetch uploaded file "${file_name}": ${err instanceof Error ? err.message : 'Unknown error'}`,
203
+ data: {},
204
+ }, { status: 500 });
205
+ }
206
+ }
207
+ // Build field_list string for prompt variable substitution
208
+ const field_list = build_field_list_string(fields);
209
+ // Determine file MIME category for hazo_llm_dynamic_data_extract
210
+ const effective_mime = is_image_mime(mime_type) || is_document_mime(mime_type)
211
+ ? mime_type
212
+ : mime_type; // pass through — hazo_llm_api handles type routing
213
+ // Try hazo_llm_dynamic_data_extract first (prompt lookup + LLM call + JSON parsing)
214
+ try {
215
+ const result = await api.hazo_llm_dynamic_data_extract({
216
+ initial_prompt_area: prompt_area,
217
+ initial_prompt_key: prompt_key,
218
+ initial_prompt_variables: [{ field_list }],
219
+ file_b64,
220
+ file_mime_type: effective_mime,
221
+ max_depth: 1,
222
+ });
223
+ if (result.success && result.merged_result && Object.keys(result.merged_result).length > 0) {
224
+ const has_data = Object.values(result.merged_result).some((v) => {
225
+ if (v === null || v === undefined || v === '')
226
+ return false;
227
+ if (Array.isArray(v) && v.length === 0)
228
+ return false;
229
+ return true;
230
+ });
231
+ return Response.json({
232
+ success: true,
233
+ data: result.merged_result,
234
+ ...(has_data ? {} : { message: 'No matching data found in this document.' }),
235
+ });
236
+ }
237
+ // If dynamic extract failed or returned empty, fall through to direct LLM call
238
+ if (!result.success && result.errors?.length) {
239
+ on_error(result.errors, 'dynamic_data_extract failed, falling back to direct LLM call');
240
+ }
241
+ }
242
+ catch (dde_err) {
243
+ on_error(dde_err, 'dynamic_data_extract threw, falling back to direct LLM call');
244
+ }
245
+ // Fallback: direct LLM call with generated or DB-looked-up prompt
246
+ let prompt_text;
247
+ try {
248
+ const connect = api.get_hazo_connect();
249
+ if (connect) {
250
+ const lookup = await connect.get_by_area_key(prompt_area, prompt_key);
251
+ if (lookup.success && lookup.data?.prompt_text_full) {
252
+ prompt_text = api.substitute_variables(lookup.data.prompt_text_full, [{ field_list }], api.default_logger);
253
+ }
254
+ else {
255
+ prompt_text = generate_default_prompt(fields);
256
+ }
257
+ }
258
+ else {
259
+ prompt_text = generate_default_prompt(fields);
260
+ }
261
+ }
262
+ catch {
263
+ prompt_text = generate_default_prompt(fields);
264
+ }
265
+ // Call LLM based on file type
266
+ let llm_response;
267
+ if (is_image_mime(mime_type)) {
268
+ llm_response = await api.hazo_llm_image_text({
269
+ prompt: prompt_text,
270
+ image_b64: file_b64,
271
+ image_mime_type: mime_type,
272
+ });
273
+ }
274
+ else if (is_document_mime(mime_type)) {
275
+ llm_response = await api.hazo_llm_document_text({
276
+ prompt: prompt_text,
277
+ document_b64: file_b64,
278
+ document_mime_type: mime_type,
279
+ });
280
+ }
281
+ else {
282
+ llm_response = await api.hazo_llm_image_text({
283
+ prompt: prompt_text,
284
+ image_b64: file_b64,
285
+ image_mime_type: mime_type,
286
+ });
287
+ }
288
+ if (!llm_response.success || !llm_response.text) {
289
+ return Response.json({
290
+ success: false,
291
+ error: llm_response.error || 'LLM extraction failed',
292
+ data: {},
293
+ }, { status: 500 });
294
+ }
295
+ // Parse JSON response from LLM
296
+ let extracted_data;
297
+ try {
298
+ extracted_data = parse_json_response(llm_response.text);
299
+ }
300
+ catch {
301
+ return Response.json({
302
+ success: false,
303
+ error: `Failed to parse LLM response as JSON. Raw: ${llm_response.text.substring(0, 200)}`,
304
+ data: {},
305
+ }, { status: 500 });
306
+ }
307
+ const has_data = Object.values(extracted_data).some((v) => {
308
+ if (v === null || v === undefined || v === '')
309
+ return false;
310
+ if (Array.isArray(v) && v.length === 0)
311
+ return false;
312
+ return true;
313
+ });
314
+ return Response.json({
315
+ success: true,
316
+ data: extracted_data,
317
+ ...(has_data ? {} : { message: 'No matching data found in this document.' }),
318
+ });
319
+ }
320
+ catch (error) {
321
+ on_error(error, 'unhandled error');
322
+ return Response.json({
323
+ success: false,
324
+ error: error instanceof Error ? error.message : 'Unknown error',
325
+ data: {},
326
+ }, { status: 500 });
327
+ }
328
+ };
329
+ }
330
+ //# sourceMappingURL=autofill_handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autofill_handler.js","sourceRoot":"","sources":["../../src/lib/autofill_handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,aAAa,CAAC;AAerB,+EAA+E;AAC/E,UAAU;AACV,+EAA+E;AAE/E;;;GAGG;AAC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CAAC;oBAAE,OAAO,KAAK,CAAC;gBACrD,OAAO,IAAI,CAAC;YACd,CAAC,CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC,IAAI,CAAC;gBACnB,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,cAAc;gBACpB,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,0CAA0C,EAAE,CAAC;aAC7E,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;YACnC,OAAO,QAAQ,CAAC,IAAI,CAClB;gBACE,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;gBAC/D,IAAI,EAAE,EAAE;aACT,EACD,EAAE,MAAM,EAAE,GAAG,EAAE,CAChB,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -4,4 +4,13 @@
4
4
  export { get_config, get_config_path, has_config } from './config.js';
5
5
  export { set_server_logger, get_server_logger } from '../logger/server.js';
6
6
  export type { Logger } from '../logger/types.js';
7
+ export { create_autofill_route } from './autofill_handler.js';
8
+ export type { AutofillRouteOptions } from './autofill_handler.js';
9
+ export type { ContentTagConfig } from '../types/file_manager.js';
10
+ export type { AutofillRequest, AutofillResponse, AutofillFieldSchema } from '../components/autofill_dropzone/types.js';
11
+ export type { ClarificationType, ClarificationStatus, ClarificationDocReference, ClarificationResponseOption, ClarificationItem, ClarificationTemplate, ClarificationResponse, ClarificationCallbacks, ClarificationCounts, } from '../types/clarification.js';
12
+ export { DEFAULT_CLARIFICATION_TEMPLATES } from '../config/clarification_templates.js';
13
+ export { create_validation_route } from './validation_handler.js';
14
+ export type { ValidationRouteOptions, ValidationRequest, ValidationResponse, ValidationRuleExecution, ValidationRuleResult, ValidationRule, ValidationRuleRecord, PromptCommand, PromptVariable, PromptEditorConfig, } from '../types/validation.js';
15
+ export { DEFAULT_PROMPT_COMMANDS, DEFAULT_PROMPT_VARIABLES, DEFAULT_PROMPT_EDITOR_CONFIG, } from '../config/validation_rule_commands.js';
7
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,YAAY,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,YAAY,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,YAAY,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAGlE,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAGvH,YAAY,EACV,iBAAiB,EACjB,mBAAmB,EACnB,yBAAyB,EACzB,2BAA2B,EAC3B,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AAGvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,YAAY,EACV,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,cAAc,EACd,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,4BAA4B,GAC7B,MAAM,uCAAuC,CAAC"}
package/dist/lib/index.js CHANGED
@@ -3,4 +3,9 @@
3
3
  */
4
4
  export { get_config, get_config_path, has_config } from './config.js';
5
5
  export { set_server_logger, get_server_logger } from '../logger/server.js';
6
+ export { create_autofill_route } from './autofill_handler.js';
7
+ export { DEFAULT_CLARIFICATION_TEMPLATES } from '../config/clarification_templates.js';
8
+ // Validation route handler (for server-side use)
9
+ export { create_validation_route } from './validation_handler.js';
10
+ export { DEFAULT_PROMPT_COMMANDS, DEFAULT_PROMPT_VARIABLES, DEFAULT_PROMPT_EDITOR_CONFIG, } from '../config/validation_rule_commands.js';
6
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAG3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAmB9D,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AAEvF,iDAAiD;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAalE,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,4BAA4B,GAC7B,MAAM,uCAAuC,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Server-side validation route handler factory.
3
+ *
4
+ * Creates a POST handler that executes validation rules against uploaded documents
5
+ * using LLM analysis, and returns ClarificationItems for any issues found.
6
+ *
7
+ * Usage:
8
+ * import { create_validation_route } from 'hazo_collab_forms/lib';
9
+ * export const POST = create_validation_route();
10
+ *
11
+ * Uses standard Web API Request/Response for portability.
12
+ * hazo_llm_api is dynamically imported so it's only required at runtime.
13
+ */
14
+ import 'server-only';
15
+ import type { ValidationRouteOptions } from '../types/validation.js';
16
+ /**
17
+ * Creates a POST route handler for document validation.
18
+ *
19
+ * The handler:
20
+ * 1. Validates the request payload
21
+ * 2. Fetches the file (inline or from URL)
22
+ * 3. Executes each validation rule against the document via LLM
23
+ * 4. Creates ClarificationItems for rules that find issues
24
+ * 5. Returns the results
25
+ */
26
+ export declare function create_validation_route(options?: ValidationRouteOptions): (request: Request) => Promise<Response>;
27
+ //# sourceMappingURL=validation_handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation_handler.d.ts","sourceRoot":"","sources":["../../src/lib/validation_handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,aAAa,CAAC;AAErB,OAAO,KAAK,EAKV,sBAAsB,EACvB,MAAM,wBAAwB,CAAC;AAoLhC;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,sBAAsB,IA+F3C,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,CAyHhE"}