@adriansteffan/reactive 0.1.36 → 0.2.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 (40) hide show
  1. package/.claude/settings.local.json +7 -1
  2. package/README.md +108 -5
  3. package/dist/{mod-urua6TFn.js → mod-C-XUCKhQ.js} +11569 -11218
  4. package/dist/mod.d.ts +110 -6
  5. package/dist/reactive.es.js +74 -63
  6. package/dist/reactive.umd.js +626 -654
  7. package/dist/style.css +1 -1
  8. package/dist/{web-D9yqAhIx.js → web-Dpb5MAUc.js} +1 -1
  9. package/dist/{web-BtWqed4E.js → web-Dv2PC8fG.js} +1 -1
  10. package/package.json +4 -2
  11. package/raw-loader-hooks.mjs +25 -0
  12. package/raw-loader.mjs +5 -0
  13. package/src/components/experimentrunner.tsx +54 -1
  14. package/src/components/index.ts +1 -0
  15. package/src/components/microphonecheck.tsx +70 -84
  16. package/src/components/text.tsx +1 -1
  17. package/src/components/upload.tsx +4 -1
  18. package/src/components/voicerecorder.tsx +184 -162
  19. package/src/components/voicerecording.tsx +198 -0
  20. package/src/index.css +6 -0
  21. package/src/mod.tsx +8 -3
  22. package/src/utils/array.ts +61 -11
  23. package/src/utils/audiodevice.ts +4 -0
  24. package/src/utils/distributions.ts +28 -5
  25. package/src/utils/llm.ts +101 -0
  26. package/src/utils/nodecompat.ts +11 -0
  27. package/src/utils/simulation.ts +2 -2
  28. package/src/utils/theme.ts +1 -0
  29. package/src/utils/tts.ts +82 -0
  30. package/src/utils/upload.ts +54 -1
  31. package/template/README.md +26 -0
  32. package/template/backend/src/backend.ts +32 -1
  33. package/template/docker-compose.yaml +32 -0
  34. package/template/package.json +5 -2
  35. package/template/simulate.ts +13 -3
  36. package/template/src/Experiment.tsx +10 -12
  37. package/template/transcription/Dockerfile.cpu +8 -0
  38. package/template/transcription/Dockerfile.gpu +8 -0
  39. package/template/transcription/transcribe.py +161 -0
  40. package/vite.config.ts +1 -1
@@ -47,7 +47,13 @@
47
47
  "Bash(kill 59399)",
48
48
  "Bash(rm -rf /tmp/quest-test)",
49
49
  "Bash(npm audit:*)",
50
- "Bash(npm view:*)"
50
+ "Bash(npm view:*)",
51
+ "Bash(say -v '?')",
52
+ "Read(//Users/adriansteffan/Projects/donkin/dec-from-exp/**)",
53
+ "Bash(npx tsx:*)",
54
+ "Bash(ls -la data/sim_1775827664642_y5r7bw/audio_*)",
55
+ "Bash(rm:*)",
56
+ "Bash(ls:*)"
51
57
  ],
52
58
  "deny": [],
53
59
  "ask": []
package/README.md CHANGED
@@ -40,6 +40,7 @@ Premade components available so far:
40
40
  * voicerecorder: a custom question type that allows participants to record voice
41
41
  * Tutorial: A paginated slide deck with navigation, dot indicators, and optional interactive slides via `useTutorialSlide`
42
42
  * RandomDotKinematogram: A random dot kinematogram (RDK) stimulus for motion perception experiments
43
+ * VoiceRecording: A standalone voice recording trial with pause/stop controls, optional minimum duration warning, and confirmation dialog
43
44
  * Upload: Uploads the collected data on a button press by the participant
44
45
 
45
46
 
@@ -57,7 +58,7 @@ export const simulationConfig = {
57
58
  seed: 42, // optional: makes simulations fully reproducible
58
59
  participants: () => sampleParticipants('sobol', 10, {
59
60
  needForCognition: { distribution: 'normal', mean: 3.5, sd: 0.8 },
60
- }).map((p, i) => ({ ...p, id: i })),
61
+ }),
61
62
  };
62
63
  ```
63
64
 
@@ -140,7 +141,7 @@ export const simulationConfig = {
140
141
  needForCognition: { distribution: 'normal', mean: 3.5, sd: 0.8 },
141
142
  agreeableness: { distribution: 'normal', mean: 3.0, sd: 1.0 },
142
143
  age: { distribution: 'uniform', min: 18, max: 65 },
143
- }).map((p, i) => ({ ...p, id: i })),
144
+ }),
144
145
  };
145
146
  ```
146
147
 
@@ -183,7 +184,7 @@ participants: () => {
183
184
  alertness: { distribution: 'normal', mean: 3.6, sd: 0.5 },
184
185
  }).map((p) => ({ ...p, smoker: false }));
185
186
 
186
- return [...smokers, ...nonSmokers].map((p, i) => ({ ...p, id: i }));
187
+ return [...smokers, ...nonSmokers];
187
188
  },
188
189
  ```
189
190
 
@@ -200,6 +201,7 @@ participants: () => {
200
201
  | Upload | *(none)* | Builds CSVs and POSTs to backend |
201
202
  | StoreUI | *(none)* | Uses field default values |
202
203
  | CheckDevice | *(none)* | Returns simulated device info |
204
+ | VoiceRecording | `respondTTS`, `respondBase64` | Platform TTS with default text; falls back to dummy sine tone |
203
205
  | EnterFullscreen, ExitFullscreen, MicrophoneCheck, ProlificEnding, RequestFilePermission | *(none)* | No-op, advances immediately |
204
206
 
205
207
 
@@ -414,6 +416,8 @@ Each dimension spec is one of:
414
416
  | Uniform | `{ distribution: 'uniform', min, max }` | Uniform over `[min, max)` |
415
417
  | Normal | `{ distribution: 'normal', mean, sd }` | Gaussian with given mean and standard deviation |
416
418
  | Poisson | `{ distribution: 'poisson', mean }` | Poisson with given mean (discrete) |
419
+ | Integer | `{ distribution: 'integer', min, max }` | Uniform integer in `[min, max]` inclusive |
420
+ | Discrete | `{ distribution: 'discrete', outcomes }` | Weighted categorical — `outcomes: [{ value, weight }, ...]` |
417
421
 
418
422
  For a single dimension, both return a flat `number[]`. For multiple dimensions, they return `number[][]`.
419
423
 
@@ -449,8 +453,8 @@ import { sampleParticipants } from '@adriansteffan/reactive';
449
453
  const participants = sampleParticipants('sobol', 100, {
450
454
  needForCognition: { distribution: 'normal', mean: 3.5, sd: 0.8 },
451
455
  agreeableness: { distribution: 'normal', mean: 3.0, sd: 1.0 },
452
- }).map((p, i) => ({ ...p, id: i }));
453
- // → [{ needForCognition: 3.5, agreeableness: 3.0, id: 0 }, ...]
456
+ });
457
+ // → [{ index: 0, needForCognition: 3.5, agreeableness: 3.0 }, ...]
454
458
  ```
455
459
 
456
460
  The first argument is the sampling method: `'sobol'`, `'halton'`, or `'random'`.
@@ -491,6 +495,105 @@ Boundaries can also collapse during viewing via `stimulusCollapse: { rate, delay
491
495
  The RDK component uses this as its default simulator with parameters from Ratcliff & McKoon (2008), converted to ms time steps.
492
496
 
493
497
 
498
+ ## Voice Recording
499
+
500
+ ### MicrophoneCheck
501
+
502
+ Place early in your timeline to let participants select and test their microphone:
503
+
504
+ ```tsx
505
+ { type: 'MicrophoneCheck' }
506
+ ```
507
+
508
+ The selected device ID is stored automatically and used by all subsequent recording components.
509
+
510
+ ### VoiceRecording
511
+
512
+ A standalone trial where participants record their voice. The "Continue" button only appears after a recording is made.
513
+
514
+ ```tsx
515
+ {
516
+ type: 'VoiceRecording',
517
+ props: {
518
+ content: <p>Please describe what you saw.</p>,
519
+ },
520
+ }
521
+ ```
522
+
523
+ With minimum duration enforcement; shows a warning when paused if the recording is too short:
524
+
525
+ ```tsx
526
+ {
527
+ type: 'VoiceRecording',
528
+ props: {
529
+ content: <p>Please describe your decision in detail.</p>,
530
+ minDuration: 15000,
531
+ },
532
+ }
533
+ ```
534
+
535
+ When `minDuration` is set, only pause and discard buttons are shown. When not set, pause, stop, and discard buttons appear with playback after stopping.
536
+
537
+ | Prop | Default | Description |
538
+ |---|---|---|
539
+ | `content` | — | Prompt text/JSX |
540
+ | `buttonText` | `'Continue'` / `'Save & Continue'` (with minDuration) | Button text |
541
+ | `shortButtonText` | `'Continue without improving'` | Button text when recording is too short |
542
+ | `shortRecordingWarning` | Generic message | Warning text for short recordings |
543
+ | `minDuration` | — | Minimum recording duration in ms |
544
+ | `showVisualizer` | `true` | Show volume level meter |
545
+ | `eagerUpload` | `true` | Upload audio immediately after recording |
546
+ | `animate` | `false` | Fade-in animation |
547
+
548
+ Audio recordings are automatically extracted as separate `.webm` files during upload and eagerly uploaded to reduce final upload size. The trial `name` is used in the filename.
549
+
550
+
551
+ ## LLM Integration
552
+
553
+ `invokeLLM` is a general-purpose function for calling LLM APIs. It works with any OpenAI-compatible endpoint (OpenAI, HuggingFace). Responses are cached to disk (`.reactive-cache/llm.json`) so repeated calls with the same arguments skip the API.
554
+
555
+ ```tsx
556
+ import { invokeLLM } from '@adriansteffan/reactive';
557
+
558
+ const text = await invokeLLM(
559
+ { provider: 'openai', model: 'gpt-4o-mini', apiKey: process.env.OPENAI_API_KEY! },
560
+ 'Describe a financial decision.'
561
+ );
562
+ ```
563
+
564
+ ### Structured output
565
+
566
+ Pass a JSON Schema as the third argument to constrain the model's output:
567
+
568
+ ```tsx
569
+ const result = await invokeLLM(
570
+ { provider: 'openai', model: 'gpt-4o-mini', apiKey: process.env.OPENAI_API_KEY! },
571
+ 'Describe a decision.',
572
+ {
573
+ type: 'object',
574
+ properties: {
575
+ text: { type: 'string' },
576
+ confidence: { type: 'number' },
577
+ },
578
+ required: ['text', 'confidence'],
579
+ }
580
+ );
581
+ const parsed = JSON.parse(result);
582
+ // parsed.text and parsed.confidence are guaranteed to exist
583
+ ```
584
+
585
+ ### Configuration
586
+
587
+ | Field | Type | Description |
588
+ |---|---|---|
589
+ | `provider` | `'openai' \| 'huggingface'` | API provider |
590
+ | `model` | `string` | Model name (e.g. `'gpt-4o-mini'`) |
591
+ | `apiKey` | `string` | API key |
592
+ | `baseUrl` | `string?` | Override the API endpoint |
593
+
594
+ Requires `import 'dotenv/config'` at the top of `simulate.ts` to load `.env` files. Add `.reactive-cache/` to your `.gitignore`.
595
+
596
+
494
597
  ## Development
495
598
 
496
599