reneco-advanced-input-module 0.0.20 → 0.0.22

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 (44) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/voice-input-module.cjs.entry.js +281 -65
  3. package/dist/cjs/voice-input-module.cjs.entry.js.map +1 -1
  4. package/dist/cjs/voice-input-module.cjs.js +1 -1
  5. package/dist/cjs/voice-input-module.entry.cjs.js.map +1 -1
  6. package/dist/collection/components/voice-input-module/voice-input-module.js +91 -7
  7. package/dist/collection/components/voice-input-module/voice-input-module.js.map +1 -1
  8. package/dist/collection/services/audio-recorder.service.js +61 -44
  9. package/dist/collection/services/audio-recorder.service.js.map +1 -1
  10. package/dist/collection/services/llm.service.js +140 -8
  11. package/dist/collection/services/llm.service.js.map +1 -1
  12. package/dist/collection/services/speech-to-text.service.js +39 -5
  13. package/dist/collection/services/speech-to-text.service.js.map +1 -1
  14. package/dist/collection/types/service-providers.types.js +9 -1
  15. package/dist/collection/types/service-providers.types.js.map +1 -1
  16. package/dist/components/voice-input-module.js +288 -66
  17. package/dist/components/voice-input-module.js.map +1 -1
  18. package/dist/esm/loader.js +1 -1
  19. package/dist/esm/voice-input-module.entry.js +281 -65
  20. package/dist/esm/voice-input-module.entry.js.map +1 -1
  21. package/dist/esm/voice-input-module.js +1 -1
  22. package/dist/types/components/voice-input-module/voice-input-module.d.ts +3 -0
  23. package/dist/types/components.d.ts +18 -0
  24. package/dist/types/services/audio-recorder.service.d.ts +5 -0
  25. package/dist/types/services/llm.service.d.ts +22 -0
  26. package/dist/types/services/speech-to-text.service.d.ts +8 -0
  27. package/dist/types/types/service-providers.types.d.ts +6 -2
  28. package/dist/voice-input-module/p-0e2b9ca0.entry.js +3 -0
  29. package/dist/voice-input-module/p-0e2b9ca0.entry.js.map +1 -0
  30. package/dist/voice-input-module/voice-input-module.entry.esm.js.map +1 -1
  31. package/dist/voice-input-module/voice-input-module.esm.js +1 -1
  32. package/package.json +1 -1
  33. package/readme.md +81 -0
  34. package/www/build/p-0e2b9ca0.entry.js +3 -0
  35. package/www/build/p-0e2b9ca0.entry.js.map +1 -0
  36. package/www/build/p-812b92c7.js +2 -0
  37. package/www/build/voice-input-module.entry.esm.js.map +1 -1
  38. package/www/build/voice-input-module.esm.js +1 -1
  39. package/www/index.html +12 -1
  40. package/dist/voice-input-module/p-b1207e8d.entry.js +0 -3
  41. package/dist/voice-input-module/p-b1207e8d.entry.js.map +0 -1
  42. package/www/build/p-5880afd7.js +0 -2
  43. package/www/build/p-b1207e8d.entry.js +0 -3
  44. package/www/build/p-b1207e8d.entry.js.map +0 -1
@@ -1,69 +1,96 @@
1
1
  import { proxyCustomElement, HTMLElement as HTMLElement$1, createEvent, h as h$1 } from '@stencil/core/internal/client';
2
2
  import { d as defineCustomElement$2 } from './ocr-file-uploader2.js';
3
3
 
4
+ const TRANSCRIPTION_MODELS = {
5
+ openai: ['gpt-4o-transcribe', 'gpt-4o-mini-transcribe', 'whisper-1'],
6
+ mistral: ['voxtral-mini-latest', 'voxtral-mini-transcribe-realtime-latest'],
7
+ };
8
+ const COMPLETION_MODELS = {
9
+ openai: ['gpt-5', 'gpt-5-mini', 'gpt-5.5', 'gpt-4.1', 'gpt-4.1-mini', 'gpt-4o', 'gpt-4o-mini', 'o4-mini', 'gpt-5.2', 'gpt-5.3', 'gpt-5.4', 'gpt-5.4-mini', 'gpt-5.4-pro', 'gpt-5.4-nano'],
10
+ anthropic: ['claude-opus-4', 'claude-sonnet-4', 'claude-haiku-4', 'claude-3.7-sonnet', 'claude-3.5-sonnet', 'claude-opus-4.7', 'claude-opus-4.6', 'claude-opus-4.5', 'claude-sonnet-4.6', 'claude-sonnet-4.5'],
11
+ mistral: ['mistral-large-latest', 'mistral-medium-latest', 'mistral-small-latest', 'ministral', 'mistral-nemo'],
12
+ };
13
+
4
14
  class AudioRecorderService {
5
15
  constructor() {
6
16
  this.mediaRecorder = null;
7
17
  this.audioChunks = [];
8
18
  this.stream = null;
19
+ this.audioContext = null;
20
+ this.scriptProcessor = null;
21
+ this.pcmChunks = [];
22
+ this.sampleRate = 16000;
9
23
  }
10
24
  async startRecording() {
11
- try {
12
- // Check if the API exists before calling
13
- if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
14
- console.error('Failed to start recording:', 'Microphone access is not supported in this browser or the page is not served over HTTPS/localhost.');
15
- return; // Exit gracefully instead of throwing
16
- }
17
- this.stream = await navigator.mediaDevices.getUserMedia({
18
- audio: {
19
- echoCancellation: true,
20
- noiseSuppression: true,
21
- autoGainControl: true
22
- }
23
- });
24
- this.audioChunks = [];
25
- this.mediaRecorder = new MediaRecorder(this.stream, {
26
- mimeType: 'audio/webm;codecs=opus'
27
- });
28
- this.mediaRecorder.ondataavailable = (event) => {
29
- if (event.data && event.data.size > 0) {
30
- this.audioChunks.push(event.data);
31
- }
32
- };
33
- this.mediaRecorder.start(100); // Collect data every 100ms
34
- }
35
- catch (error) {
36
- console.error('Failed to start recording:', error);
25
+ if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
26
+ throw new Error('Microphone access is not supported in this browser or the page is not served over HTTPS/localhost.');
37
27
  }
28
+ this.stream = await navigator.mediaDevices.getUserMedia({
29
+ audio: { echoCancellation: true, noiseSuppression: true, autoGainControl: true }
30
+ });
31
+ this.audioContext = new AudioContext({ sampleRate: this.sampleRate });
32
+ const source = this.audioContext.createMediaStreamSource(this.stream);
33
+ this.scriptProcessor = this.audioContext.createScriptProcessor(4096, 1, 1);
34
+ this.pcmChunks = [];
35
+ this.scriptProcessor.onaudioprocess = (e) => {
36
+ const input = e.inputBuffer.getChannelData(0);
37
+ this.pcmChunks.push(new Float32Array(input));
38
+ };
39
+ source.connect(this.scriptProcessor);
40
+ this.scriptProcessor.connect(this.audioContext.destination);
38
41
  }
39
42
  async stopRecording() {
40
- return new Promise((resolve, reject) => {
41
- if (!this.mediaRecorder) {
42
- reject(new Error('No active recording found'));
43
- return;
43
+ if (!this.audioContext || !this.scriptProcessor) {
44
+ throw new Error('No active recording found');
45
+ }
46
+ this.scriptProcessor.disconnect();
47
+ await this.audioContext.close();
48
+ const wavBlob = this.encodeWav(this.pcmChunks, this.sampleRate);
49
+ this.cleanup();
50
+ return wavBlob;
51
+ }
52
+ encodeWav(chunks, sampleRate) {
53
+ const totalSamples = chunks.reduce((acc, c) => acc + c.length, 0);
54
+ const buffer = new ArrayBuffer(44 + totalSamples * 2);
55
+ const view = new DataView(buffer);
56
+ const writeStr = (offset, str) => {
57
+ for (let i = 0; i < str.length; i++)
58
+ view.setUint8(offset + i, str.charCodeAt(i));
59
+ };
60
+ writeStr(0, 'RIFF');
61
+ view.setUint32(4, 36 + totalSamples * 2, true);
62
+ writeStr(8, 'WAVE');
63
+ writeStr(12, 'fmt ');
64
+ view.setUint32(16, 16, true); // PCM chunk size
65
+ view.setUint16(20, 1, true); // PCM format
66
+ view.setUint16(22, 1, true); // mono
67
+ view.setUint32(24, sampleRate, true);
68
+ view.setUint32(28, sampleRate * 2, true); // byte rate
69
+ view.setUint16(32, 2, true); // block align
70
+ view.setUint16(34, 16, true); // bits per sample
71
+ writeStr(36, 'data');
72
+ view.setUint32(40, totalSamples * 2, true);
73
+ let offset = 44;
74
+ for (const chunk of chunks) {
75
+ for (let i = 0; i < chunk.length; i++) {
76
+ const s = Math.max(-1, Math.min(1, chunk[i]));
77
+ view.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7FFF, true);
78
+ offset += 2;
44
79
  }
45
- this.mediaRecorder.onstop = () => {
46
- const audioBlob = new Blob(this.audioChunks, { type: 'audio/webm' });
47
- this.cleanup();
48
- resolve(audioBlob);
49
- };
50
- this.mediaRecorder.onerror = (event) => {
51
- reject(new Error(`Recording error: ${event}`));
52
- };
53
- this.mediaRecorder.stop();
54
- });
80
+ }
81
+ return new Blob([buffer], { type: 'audio/wav' });
55
82
  }
56
83
  isRecording() {
57
- var _a;
58
- return ((_a = this.mediaRecorder) === null || _a === void 0 ? void 0 : _a.state) === 'recording';
84
+ return this.scriptProcessor !== null;
59
85
  }
60
86
  cleanup() {
61
87
  if (this.stream) {
62
88
  this.stream.getTracks().forEach(track => track.stop());
63
89
  this.stream = null;
64
90
  }
65
- this.mediaRecorder = null;
66
- this.audioChunks = [];
91
+ this.audioContext = null;
92
+ this.scriptProcessor = null;
93
+ this.pcmChunks = [];
67
94
  }
68
95
  }
69
96
 
@@ -125,15 +152,49 @@ class WhisperSpeechToTextService {
125
152
  }
126
153
  }
127
154
  }
155
+ class MistralSpeechToTextService {
156
+ constructor(config) {
157
+ this.useProxy = (config === null || config === void 0 ? void 0 : config.useProxy) || false;
158
+ this.proxyUrl = (config === null || config === void 0 ? void 0 : config.proxyUrl) || 'http://localhost:8492';
159
+ this.model = (config === null || config === void 0 ? void 0 : config.model) || 'voxtral-mini-latest';
160
+ this.apiKey = this.useProxy ? '' : ((config === null || config === void 0 ? void 0 : config.apiKey) || '');
161
+ if (!this.useProxy && !this.apiKey) {
162
+ throw new Error('Mistral API key is required for speech-to-text service');
163
+ }
164
+ }
165
+ async transcribe(audioContent, lang = 'en') {
166
+ var _a;
167
+ try {
168
+ const formData = new FormData();
169
+ formData.append('file', audioContent);
170
+ formData.append('model', this.model);
171
+ formData.append('language', lang);
172
+ const endpoint = this.useProxy ? `${this.proxyUrl}/transcribe-mistral` : 'https://api.mistral.ai/v1/audio/transcriptions';
173
+ const headers = {};
174
+ if (!this.useProxy) {
175
+ headers['Authorization'] = `Bearer ${this.apiKey}`;
176
+ }
177
+ const response = await fetch(endpoint, { method: 'POST', headers, body: formData });
178
+ if (!response.ok) {
179
+ const err = await response.json().catch(() => ({ error: 'Unknown error' }));
180
+ throw new Error(`Transcription failed: ${((_a = err.error) === null || _a === void 0 ? void 0 : _a.message) || response.statusText}`);
181
+ }
182
+ const result = await response.json();
183
+ return result.text || '';
184
+ }
185
+ catch (error) {
186
+ throw new Error(`Mistral speech-to-text failed: ${error.message}`);
187
+ }
188
+ }
189
+ }
128
190
  class SpeechToTextServiceFactory {
129
191
  static create(config) {
130
192
  var _a;
131
- const provider = ((_a = config.speechToText) === null || _a === void 0 ? void 0 : _a.provider) || 'whisper';
193
+ const provider = ((_a = config.speechToText) === null || _a === void 0 ? void 0 : _a.provider) || 'openai';
132
194
  switch (provider) {
133
- case 'whisper':
134
- return new WhisperSpeechToTextService(config.speechToText);
135
- default:
136
- throw new Error(`Unsupported speech-to-text provider: ${provider}`);
195
+ case 'openai': return new WhisperSpeechToTextService(config.speechToText);
196
+ case 'mistral': return new MistralSpeechToTextService(config.speechToText);
197
+ default: throw new Error(`Unsupported speech-to-text provider: ${provider}`);
137
198
  }
138
199
  }
139
200
  }
@@ -323,8 +384,10 @@ class OpenAILLMService {
323
384
  `(${field.type}` +
324
385
  `${field.required ? ', required' : ''}` +
325
386
  `${field.readonly ? ', readonly' : ''}` +
387
+ `${field.default !== undefined && field.default !== null && field.default !== '' ? ', default=' + field.default : ''}` +
326
388
  `${field.min && field.min !== "" ? ', min=' + field.min : ''}` +
327
- `${field.max && field.max !== "" ? ', max=' + field.max : ''}`;
389
+ `${field.max && field.max !== "" ? ', max=' + field.max : ''}` +
390
+ `${field.pattern && field.pattern !== "" ? ', pattern=' + field.pattern : ''}`;
328
391
  if (field.options && field.options.length > 0) {
329
392
  if (field.options.length < 50) {
330
393
  description += `) - options: ${field.options.join(', ')}`;
@@ -344,8 +407,10 @@ class OpenAILLMService {
344
407
  `(${field.type}` +
345
408
  `${field.required ? ', required' : ''}` +
346
409
  `${field.readonly ? ', readonly' : ''}` +
410
+ `${field.default !== undefined && field.default !== null && field.default !== '' ? ', default=' + field.default : ''}` +
347
411
  `${field.min && field.min !== "" ? ', min=' + field.min : ''}` +
348
- `${field.max && field.max !== "" ? ', max=' + field.max : ''}`;
412
+ `${field.max && field.max !== "" ? ', max=' + field.max : ''}` +
413
+ `${field.pattern && field.pattern !== "" ? ', pattern=' + field.pattern : ''}`;
349
414
  if (field.options && field.options.length > 0) {
350
415
  if (field.options.length < 50) {
351
416
  description += `) - options: ${field.options.join(', ')}`;
@@ -489,11 +554,14 @@ class OpenAILLMService {
489
554
  7. Only include fields where relevant information is found
490
555
  8. The current GMT datetime is ${new Date().toGMTString()}
491
556
  9. Respect the constraints written between parenthesis for readonly status (readonly fields MUST NOT be filled with values), min and max values, whatever the transcription says
557
+ 9b. CRITICAL - DATE/DATETIME OUT OF RANGE: For date and datetime fields with min and/or max constraints, if the value from the transcription falls outside the allowed range, leave the field EMPTY. NEVER clamp, adjust, or substitute a boundary date - either the date is valid and within range, or the field is left empty
492
558
  10. IMPORTANT: Fields marked as "readonly" are presentation elements (headers, labels) that provide context but MUST NOT receive values
493
559
  11. CRITICAL - DUPLICATE FIELDS: When you see multiple fields with the same name but different IDs (e.g., "ID:field1 | Event date" and "ID:field2 | Event date"), these are DIFFERENT fields in DIFFERENT sections. The user may explicitly say which section they are filling (e.g., "for the first/second sub-form"). Listen VERY CAREFULLY to these contextual clues. Use the readonly headers to understand which section each field belongs to. If the user says "for the clinical sign, the event date is X", you must fill the Event date field that comes AFTER the "MC Clinical sign" header, NOT the first Event date you see
494
560
  12. Use readonly fields as contextual hints to understand form structure and field grouping, but never fill them
495
- 13. CRITICAL: For select fields, options like "No", "Non", "Non applicable", "Inconnu", "Unknown", "N/A" are VALID VALUES that can be selected. When the user says these words, treat them as legitimate option choices, NOT always as negations or refusals to answer. HOWEVER, for non-select fields (string, number, date, etc.), if the user says "I don't know", "unknown", "not known", "inconnu", "je ne sais pas", this usually means they have NO VALUE to provide, unless explicitely precised - leave the field empty, do NOT fill it with the literal text "unknown" or "I don't know"
561
+ 13. CRITICAL - UNKNOWN/NO/N-A VALUES: The interpretation of words like "Unknown", "Inconnu", "No", "Non", "N/A", "Non applicable" depends ENTIRELY on whether the field has those words as explicit options. Rule: if the user says "field X is Unknown" (or any similar phrasing) AND "Unknown" (or a close variant) exists in the options list for that field, then SELECT that option - it is a valid value. If the user says such words for a field that does NOT have them as options (string, number, date, etc.), then it means the user has no value to provide - leave the field empty, do NOT fill it with the literal text
496
562
  14. CRITICAL: Each field has a unique ID shown as "ID:xxx" at the start of its description. You MUST include this exact ID in your response for each field you fill. The ID is the ONLY way to distinguish between fields with the same name
563
+ 15. CRITICAL - DEFAULT VALUES: Some fields have default values shown as "default=xxx". If the user does NOT mention a specific value for that field in the transcription, you MUST return the default value. Default values should be preserved unless explicitly overridden by the user
564
+ 16. CRITICAL - PATTERN VALIDATION: Some fields have a regex pattern shown as "pattern=xxx". The value you extract MUST match this pattern exactly. If the transcription is too ambiguous to produce a value that matches the pattern, leave the field EMPTY
497
565
 
498
566
  Respond with JSON in this exact format: {"fields": [{"id": "field_id", "name": "field_name", "value": "extracted_value"}]}`;
499
567
  let userPrompt = `
@@ -562,10 +630,12 @@ class OpenAILLMService {
562
630
  8. Return the same schema structure with 'default' values filled
563
631
  9. The current GMT datetime is ${new Date().toGMTString()}
564
632
  10. Respect the constraints written between parenthesis for readonly status (readonly fields MUST NOT be filled with values), min and max values, whatever the transcription says
633
+ 10b. CRITICAL - DATE/DATETIME OUT OF RANGE: For date and datetime fields with min and/or max constraints, if the value from the transcription falls outside the allowed range, leave the field EMPTY. NEVER clamp, adjust, or substitute a boundary date - either the date is valid and within range, or the field is left empty
565
634
  11. IMPORTANT: Fields marked as "readonly" are presentation elements (headers, labels) that provide context but MUST NOT receive values
566
635
  12. CRITICAL - DUPLICATE FIELDS: When you see multiple fields with the same name but different IDs (e.g., "ID:field1 | Event date" and "ID:field2 | Event date"), these are DIFFERENT fields in DIFFERENT sections. The user will explicitly say which section they are filling (e.g., "for the first/second sub-form", "in the anamnesis section", "for the clinical sign"). Listen VERY CAREFULLY to these contextual clues. Use the readonly headers to understand which section each field belongs to. If the user says "for the clinical sign, the event date is X", you must fill the Event date field that comes AFTER the "MC Clinical sign" header, NOT the first Event date you see
567
636
  13. Use readonly fields as contextual hints to understand form structure and field grouping, but never fill them
568
- 14. CRITICAL: For select fields, options like "No", "Non", "Non applicable", "Inconnu", "Unknown", "N/A" are VALID VALUES that can be selected. When the user says these words, treat them as legitimate option choices, NOT always as negations or refusals to answer. HOWEVER, for non-select fields (string, number, date, etc.), if the user says "I don't know", "unknown", "not known", "inconnu", "je ne sais pas", this usually means they have NO VALUE to provide, unless explicitely precised - leave the field empty, do NOT fill it with the literal text "unknown" or "I don't know"
637
+ 14. CRITICAL - UNKNOWN/NO/N-A VALUES: The interpretation of words like "Unknown", "Inconnu", "No", "Non", "N/A", "Non applicable" depends ENTIRELY on whether the field has those words as explicit options. Rule: if the user says "field X is Unknown" (or any similar phrasing) AND "Unknown" (or a close variant) exists in the options list for that field, then SELECT that option - it is a valid value. If the user says such words for a field that does NOT have them as options (string, number, date, etc.), then it means the user has no value to provide - leave the field empty, do NOT fill it with the literal text
638
+ 15. CRITICAL - PATTERN VALIDATION: Some fields have a regex pattern shown as "pattern=xxx". The value you extract MUST match this pattern exactly. If the transcription is too ambiguous to produce a value that matches the pattern, leave the field EMPTY
569
639
 
570
640
  Respond with JSON in this exact format: {"schema": {...}}`;
571
641
  let userPrompt = `
@@ -629,15 +699,138 @@ class OpenAILLMService {
629
699
  }
630
700
  }
631
701
  }
702
+ class AnthropicLLMService {
703
+ constructor(config) {
704
+ this.useProxy = (config === null || config === void 0 ? void 0 : config.useProxy) || false;
705
+ this.proxyUrl = (config === null || config === void 0 ? void 0 : config.proxyUrl) || 'http://localhost:8492';
706
+ this.model = (config === null || config === void 0 ? void 0 : config.model) || 'claude-sonnet-4.5';
707
+ this.apiKey = this.useProxy ? '' : ((config === null || config === void 0 ? void 0 : config.apiKey) || '');
708
+ if (!this.useProxy && !this.apiKey) {
709
+ throw new Error('Anthropic API key is required');
710
+ }
711
+ }
712
+ async fillFormFromTranscription(transcription, schema) {
713
+ return this.fillForm(transcription, schema);
714
+ }
715
+ async fillFormFromJson(json, schema) {
716
+ return this.fillForm(json, schema);
717
+ }
718
+ async fillForm(data, schema) {
719
+ var _a;
720
+ const endpoint = this.useProxy ? `${this.proxyUrl}/complete-anthropic` : 'https://api.anthropic.com/v1/messages';
721
+ const headers = { 'Content-Type': 'application/json' };
722
+ if (!this.useProxy) {
723
+ headers['x-api-key'] = this.apiKey;
724
+ headers['anthropic-version'] = '2023-06-01';
725
+ }
726
+ const finalSchema = (schema === null || schema === void 0 ? void 0 : schema.fields) || (schema === null || schema === void 0 ? void 0 : schema.schema) || schema;
727
+ const systemPrompt = this.buildSystemPrompt();
728
+ const userPrompt = `Data: "${data}"
729
+
730
+ Form fields:
731
+ ${JSON.stringify(finalSchema, null, 2)}
732
+
733
+ Respond with JSON: {"fields": [{"id": "field_id", "name": "field_name", "value": "extracted_value"}]}`;
734
+ const body = this.useProxy
735
+ ? { model: this.model, messages: [{ role: 'user', content: userPrompt }], system: systemPrompt }
736
+ : { model: this.model, max_tokens: 4096, system: systemPrompt, messages: [{ role: 'user', content: userPrompt }] };
737
+ const response = await fetch(endpoint, { method: 'POST', headers, body: JSON.stringify(body) });
738
+ if (!response.ok) {
739
+ const err = await response.json().catch(() => ({ error: 'Unknown error' }));
740
+ throw new Error(`Anthropic API failed: ${((_a = err.error) === null || _a === void 0 ? void 0 : _a.message) || response.statusText}`);
741
+ }
742
+ const result = await response.json();
743
+ const content = this.useProxy ? result.choices[0].message.content : result.content[0].text;
744
+ return JSON.parse(content);
745
+ }
746
+ buildSystemPrompt() {
747
+ return `You are an expert form-filling assistant. Extract values from the input data and fill form fields.
748
+ Rules:
749
+ 1. Only extract values that can be confidently determined
750
+ 2. Respect field types (string, number, datetime, boolean, select)
751
+ 3. For datetime fields, use ISO format (YYYY-MM-DDTHH:MM)
752
+ 4. For date fields, use DD/MM/YYYY format
753
+ 5. For select fields, use exact option values from the provided choices
754
+ 6. Leave fields empty if no relevant information is found
755
+ 7. Fields marked readonly MUST NOT receive values
756
+ 8. DATE/DATETIME OUT OF RANGE: if a date falls outside min/max constraints, leave the field EMPTY
757
+ 9. PATTERN VALIDATION: if a field has a pattern, the value MUST match it exactly, otherwise leave empty
758
+ 10. UNKNOWN VALUES: if the user says "Unknown" and it exists as an option, select it; otherwise leave empty
759
+ Respond ONLY with valid JSON.`;
760
+ }
761
+ }
762
+ class MistralLLMService {
763
+ constructor(config) {
764
+ this.useProxy = (config === null || config === void 0 ? void 0 : config.useProxy) || false;
765
+ this.proxyUrl = (config === null || config === void 0 ? void 0 : config.proxyUrl) || 'http://localhost:8492';
766
+ this.model = (config === null || config === void 0 ? void 0 : config.model) || 'mistral-medium-latest';
767
+ this.apiKey = this.useProxy ? '' : ((config === null || config === void 0 ? void 0 : config.apiKey) || '');
768
+ if (!this.useProxy && !this.apiKey) {
769
+ throw new Error('Mistral API key is required');
770
+ }
771
+ }
772
+ async fillFormFromTranscription(transcription, schema) {
773
+ return this.fillForm(transcription, schema);
774
+ }
775
+ async fillFormFromJson(json, schema) {
776
+ return this.fillForm(json, schema);
777
+ }
778
+ async fillForm(data, schema) {
779
+ var _a;
780
+ const endpoint = this.useProxy ? `${this.proxyUrl}/complete-mistral` : 'https://api.mistral.ai/v1/chat/completions';
781
+ const headers = { 'Content-Type': 'application/json' };
782
+ if (!this.useProxy) {
783
+ headers['Authorization'] = `Bearer ${this.apiKey}`;
784
+ }
785
+ const finalSchema = (schema === null || schema === void 0 ? void 0 : schema.fields) || (schema === null || schema === void 0 ? void 0 : schema.schema) || schema;
786
+ const systemPrompt = this.buildSystemPrompt();
787
+ const userPrompt = `Data: "${data}"
788
+
789
+ Form fields:
790
+ ${JSON.stringify(finalSchema, null, 2)}
791
+
792
+ Respond with JSON: {"fields": [{"id": "field_id", "name": "field_name", "value": "extracted_value"}]}`;
793
+ const response = await fetch(endpoint, {
794
+ method: 'POST',
795
+ headers,
796
+ body: JSON.stringify({
797
+ model: this.model,
798
+ messages: [{ role: 'system', content: systemPrompt }, { role: 'user', content: userPrompt }],
799
+ response_format: { type: 'json_object' },
800
+ }),
801
+ });
802
+ if (!response.ok) {
803
+ const err = await response.json().catch(() => ({ error: 'Unknown error' }));
804
+ throw new Error(`Mistral API failed: ${((_a = err.error) === null || _a === void 0 ? void 0 : _a.message) || response.statusText}`);
805
+ }
806
+ const result = await response.json();
807
+ return JSON.parse(result.choices[0].message.content);
808
+ }
809
+ buildSystemPrompt() {
810
+ return `You are an expert form-filling assistant. Extract values from the input data and fill form fields.
811
+ Rules:
812
+ 1. Only extract values that can be confidently determined
813
+ 2. Respect field types (string, number, datetime, boolean, select)
814
+ 3. For datetime fields, use ISO format (YYYY-MM-DDTHH:MM)
815
+ 4. For date fields, use DD/MM/YYYY format
816
+ 5. For select fields, use exact option values from the provided choices
817
+ 6. Leave fields empty if no relevant information is found
818
+ 7. Fields marked readonly MUST NOT receive values
819
+ 8. DATE/DATETIME OUT OF RANGE: if a date falls outside min/max constraints, leave the field EMPTY
820
+ 9. PATTERN VALIDATION: if a field has a pattern, the value MUST match it exactly, otherwise leave empty
821
+ 10. UNKNOWN VALUES: if the user says "Unknown" and it exists as an option, select it; otherwise leave empty
822
+ Respond ONLY with valid JSON.`;
823
+ }
824
+ }
632
825
  class LLMServiceFactory {
633
826
  static create(config) {
634
827
  var _a;
635
828
  const provider = ((_a = config.llm) === null || _a === void 0 ? void 0 : _a.provider) || 'openai';
636
829
  switch (provider) {
637
- case 'openai':
638
- return new OpenAILLMService(config.llm);
639
- default:
640
- throw new Error(`Unsupported LLM provider: ${provider}`);
830
+ case 'openai': return new OpenAILLMService(config.llm);
831
+ case 'anthropic': return new AnthropicLLMService(config.llm);
832
+ case 'mistral': return new MistralLLMService(config.llm);
833
+ default: throw new Error(`Unsupported LLM provider: ${provider}`);
641
834
  }
642
835
  }
643
836
  }
@@ -4159,6 +4352,8 @@ const VoiceFormRecorder = /*@__PURE__*/ proxyCustomElement(class VoiceFormRecord
4159
4352
  this.apiProxyUrl = 'http://localhost:8492';
4160
4353
  this.transcriptionModel = 'gpt-4o-transcribe';
4161
4354
  this.completionModel = 'gpt-5-mini';
4355
+ this.transcriptionProvider = 'openai';
4356
+ this.completionProvider = 'openai';
4162
4357
  this.context = undefined;
4163
4358
  this.classificationRootUrl = 'http://localhost';
4164
4359
  this.language = 'en';
@@ -4206,17 +4401,33 @@ const VoiceFormRecorder = /*@__PURE__*/ proxyCustomElement(class VoiceFormRecord
4206
4401
  this.updateDebugInfo(errorMessage, { error: errorMessage });
4207
4402
  }
4208
4403
  else {
4404
+ // Validate transcription provider/model
4405
+ const allowedTranscriptionModels = TRANSCRIPTION_MODELS[this.transcriptionProvider];
4406
+ if (!allowedTranscriptionModels) {
4407
+ throw new Error(`Unsupported transcription provider: '${this.transcriptionProvider}'. Allowed: openai, mistral`);
4408
+ }
4409
+ if (!allowedTranscriptionModels.includes(this.transcriptionModel)) {
4410
+ throw new Error(`Model '${this.transcriptionModel}' is not allowed for transcription provider '${this.transcriptionProvider}'. Allowed: ${allowedTranscriptionModels.join(', ')}`);
4411
+ }
4412
+ // Validate completion provider/model
4413
+ const allowedCompletionModels = COMPLETION_MODELS[this.completionProvider];
4414
+ if (!allowedCompletionModels) {
4415
+ throw new Error(`Unsupported completion provider: '${this.completionProvider}'. Allowed: openai, anthropic, mistral`);
4416
+ }
4417
+ if (!allowedCompletionModels.includes(this.completionModel)) {
4418
+ throw new Error(`Model '${this.completionModel}' is not allowed for completion provider '${this.completionProvider}'. Allowed: ${allowedCompletionModels.join(', ')}`);
4419
+ }
4209
4420
  // Parse form schema
4210
4421
  this.parsedSchema = JSON.parse(this.formJson || '{}');
4211
4422
  // Parse service configuration
4212
4423
  this.parsedConfig = JSON.parse(this.serviceConfig || '{}');
4213
4424
  // Add API key to config if provided via prop
4214
4425
  if (this.apiKey) {
4215
- this.parsedConfig = Object.assign(Object.assign({}, this.parsedConfig), { speechToText: Object.assign(Object.assign({}, this.parsedConfig.speechToText), { apiKey: this.apiKey, model: this.transcriptionModel }), llm: Object.assign(Object.assign({}, this.parsedConfig.llm), { apiKey: this.apiKey, model: this.completionModel }) });
4426
+ this.parsedConfig = Object.assign(Object.assign({}, this.parsedConfig), { speechToText: Object.assign(Object.assign({}, this.parsedConfig.speechToText), { provider: this.transcriptionProvider, apiKey: this.apiKey, model: this.transcriptionModel }), llm: Object.assign(Object.assign({}, this.parsedConfig.llm), { provider: this.completionProvider, apiKey: this.apiKey, model: this.completionModel }) });
4216
4427
  }
4217
4428
  else {
4218
4429
  // Use proxy API if no API key provided
4219
- this.parsedConfig = Object.assign(Object.assign({}, this.parsedConfig), { speechToText: Object.assign(Object.assign({}, this.parsedConfig.speechToText), { useProxy: true, proxyUrl: this.apiProxyUrl, model: this.transcriptionModel }), llm: Object.assign(Object.assign({}, this.parsedConfig.llm), { useProxy: true, proxyUrl: this.apiProxyUrl, model: this.completionModel }) });
4430
+ this.parsedConfig = Object.assign(Object.assign({}, this.parsedConfig), { speechToText: Object.assign(Object.assign({}, this.parsedConfig.speechToText), { provider: this.transcriptionProvider, useProxy: true, proxyUrl: this.apiProxyUrl, model: this.transcriptionModel }), llm: Object.assign(Object.assign({}, this.parsedConfig.llm), { provider: this.completionProvider, useProxy: true, proxyUrl: this.apiProxyUrl, model: this.completionModel }) });
4220
4431
  }
4221
4432
  // Initialize services
4222
4433
  this.speechToTextService = SpeechToTextServiceFactory.create(this.parsedConfig);
@@ -4382,7 +4593,7 @@ const VoiceFormRecorder = /*@__PURE__*/ proxyCustomElement(class VoiceFormRecord
4382
4593
  });
4383
4594
  // Stop recording and get audio blob
4384
4595
  const audioBlob = await this.audioRecorder.stopRecording();
4385
- const audioContent = new File([audioBlob], 'audio.webm', { type: 'audio/webm' });
4596
+ const audioContent = new File([audioBlob], 'audio.wav', { type: 'audio/wav' });
4386
4597
  this.processAudioContent(audioContent);
4387
4598
  }
4388
4599
  catch (error) {
@@ -4476,12 +4687,13 @@ const VoiceFormRecorder = /*@__PURE__*/ proxyCustomElement(class VoiceFormRecord
4476
4687
  case "ng":
4477
4688
  const trimmed = { fields: [] };
4478
4689
  schema.Children.forEach((child) => {
4479
- var _a;
4690
+ var _a, _b;
4480
4691
  if (!child.System_Name || !child.Type)
4481
4692
  return;
4482
4693
  const fieldData = {
4483
4694
  name: child.Label || ((_a = child.Settings) === null || _a === void 0 ? void 0 : _a.Label) || child.System_Name,
4484
- type: this.mapFieldType(child.Type)
4695
+ type: this.mapFieldType(child.Type),
4696
+ default: (_b = child.Settings) === null || _b === void 0 ? void 0 : _b.Default_Value
4485
4697
  };
4486
4698
  // Add options for classification/select/multiselect fields
4487
4699
  const selectTypes = ['InputClassification', 'select', 'multiselect', 'InputMultiSelect'];
@@ -4557,7 +4769,7 @@ const VoiceFormRecorder = /*@__PURE__*/ proxyCustomElement(class VoiceFormRecord
4557
4769
  title: field.title,
4558
4770
  options: field.options,
4559
4771
  readonly: field.type === 'header' || field.Enabled === false,
4560
- default: field.DefaultValue,
4772
+ default: field.default || field.DefaultValue,
4561
4773
  pattern: field.Mask,
4562
4774
  min: field.ValidationMin,
4563
4775
  max: field.ValidationMax
@@ -4886,12 +5098,16 @@ const VoiceFormRecorder = /*@__PURE__*/ proxyCustomElement(class VoiceFormRecord
4886
5098
  render() {
4887
5099
  const containerStyle = this.getContainerStyle();
4888
5100
  const statusStyle = this.getStatusStyle();
4889
- return (h$1("div", { key: '4f71f7f6dc15cb9be9545060fe992b4076f592e6' }, h$1("div", { key: '84b0fbc8e896b2b695bf32cd937763621c7fa62a', class: "voice-recorder-container" + (this.debug || this.renderForm ? "-debug" : ""), style: containerStyle }, h$1("div", { key: 'd84473027ffd89b30ade93eaa9d8e69c532549a3', class: "row-audio-area" }, this.renderRecordButton(), this.renderUploadRecordButton(), this.renderUploadButton()), this.displayStatus ? h$1("div", { class: "status-text", style: statusStyle }, this.statusMessage) : "", this.renderForm ? this.renderFormPreview() : "", this.debug ? this.renderDebugPanel() : "")));
5101
+ return (h$1("div", { key: '8378e98f02e5b7482929d255c5ec12ff8c2731e4' }, h$1("div", { key: 'b8a0d873bd4e1b4c8936747c0919ac8c4c15301b', class: "voice-recorder-container" + (this.debug || this.renderForm ? "-debug" : ""), style: containerStyle }, h$1("div", { key: '86e7783e3686db378ee16aa91a640f33c3255923', class: "row-audio-area" }, this.renderRecordButton(), this.renderUploadRecordButton(), this.renderUploadButton()), this.displayStatus ? h$1("div", { class: "status-text", style: statusStyle }, this.statusMessage) : "", this.renderForm ? this.renderFormPreview() : "", this.debug ? this.renderDebugPanel() : "")));
4890
5102
  }
4891
5103
  static get watchers() { return {
4892
5104
  "formJson": ["initializeServices"],
4893
5105
  "serviceConfig": ["initializeServices"],
4894
- "theme": ["initializeServices"]
5106
+ "theme": ["initializeServices"],
5107
+ "transcriptionProvider": ["initializeServices"],
5108
+ "completionProvider": ["initializeServices"],
5109
+ "transcriptionModel": ["initializeServices"],
5110
+ "completionModel": ["initializeServices"]
4895
5111
  }; }
4896
5112
  static get style() { return voiceInputModuleCss; }
4897
5113
  }, [257, "voice-input-module", {
@@ -4901,6 +5117,8 @@ const VoiceFormRecorder = /*@__PURE__*/ proxyCustomElement(class VoiceFormRecord
4901
5117
  "apiProxyUrl": [1, "api-proxy-url"],
4902
5118
  "transcriptionModel": [1, "transcription-model"],
4903
5119
  "completionModel": [1, "completion-model"],
5120
+ "transcriptionProvider": [1, "transcription-provider"],
5121
+ "completionProvider": [1, "completion-provider"],
4904
5122
  "context": [1],
4905
5123
  "classificationRootUrl": [1, "classification-root-url"],
4906
5124
  "language": [1],
@@ -4924,7 +5142,11 @@ const VoiceFormRecorder = /*@__PURE__*/ proxyCustomElement(class VoiceFormRecord
4924
5142
  }, undefined, {
4925
5143
  "formJson": ["initializeServices"],
4926
5144
  "serviceConfig": ["initializeServices"],
4927
- "theme": ["initializeServices"]
5145
+ "theme": ["initializeServices"],
5146
+ "transcriptionProvider": ["initializeServices"],
5147
+ "completionProvider": ["initializeServices"],
5148
+ "transcriptionModel": ["initializeServices"],
5149
+ "completionModel": ["initializeServices"]
4928
5150
  }]);
4929
5151
  function defineCustomElement$1() {
4930
5152
  if (typeof customElements === "undefined") {