@holoscript/core 2.0.1 → 2.0.2

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 (137) hide show
  1. package/LICENSE +21 -0
  2. package/dist/chunk-3N67RLQP.cjs +1298 -0
  3. package/dist/chunk-3N67RLQP.cjs.map +1 -0
  4. package/dist/chunk-3X2EGU7Z.cjs +52 -0
  5. package/dist/chunk-3X2EGU7Z.cjs.map +1 -0
  6. package/dist/chunk-4CV4JOE5.js +24 -0
  7. package/dist/chunk-4CV4JOE5.js.map +1 -0
  8. package/dist/chunk-4OHVW4XR.cjs +1027 -0
  9. package/dist/chunk-4OHVW4XR.cjs.map +1 -0
  10. package/dist/chunk-CZLDE2OZ.cjs +28 -0
  11. package/dist/chunk-CZLDE2OZ.cjs.map +1 -0
  12. package/{src/HoloScriptRuntime.ts → dist/chunk-EU6CZMGJ.js} +437 -794
  13. package/dist/chunk-EU6CZMGJ.js.map +1 -0
  14. package/dist/chunk-KWYIVRIH.js +344 -0
  15. package/dist/chunk-KWYIVRIH.js.map +1 -0
  16. package/dist/chunk-MCP6D4LT.js +1025 -0
  17. package/dist/chunk-MCP6D4LT.js.map +1 -0
  18. package/dist/chunk-SATNCODL.js +45 -0
  19. package/dist/chunk-SATNCODL.js.map +1 -0
  20. package/dist/chunk-VMZN4EVR.cjs +347 -0
  21. package/dist/chunk-VMZN4EVR.cjs.map +1 -0
  22. package/{src/HoloScriptDebugger.ts → dist/chunk-VYIDLUCV.js} +118 -257
  23. package/dist/chunk-VYIDLUCV.js.map +1 -0
  24. package/dist/chunk-WFI4T3XB.cjs +424 -0
  25. package/dist/chunk-WFI4T3XB.cjs.map +1 -0
  26. package/dist/debugger.cjs +20 -0
  27. package/dist/debugger.cjs.map +1 -0
  28. package/dist/debugger.d.cts +171 -0
  29. package/dist/debugger.d.ts +171 -0
  30. package/dist/debugger.js +7 -0
  31. package/dist/debugger.js.map +1 -0
  32. package/dist/index.cjs +6006 -0
  33. package/dist/index.cjs.map +1 -0
  34. package/dist/index.d.cts +2482 -0
  35. package/dist/index.d.ts +2482 -0
  36. package/dist/index.js +5926 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/parser.cjs +14 -0
  39. package/dist/parser.cjs.map +1 -0
  40. package/dist/parser.d.cts +139 -0
  41. package/dist/parser.d.ts +139 -0
  42. package/dist/parser.js +5 -0
  43. package/dist/parser.js.map +1 -0
  44. package/dist/runtime.cjs +14 -0
  45. package/dist/runtime.cjs.map +1 -0
  46. package/dist/runtime.d.cts +180 -0
  47. package/dist/runtime.d.ts +180 -0
  48. package/dist/runtime.js +5 -0
  49. package/dist/runtime.js.map +1 -0
  50. package/dist/type-checker.cjs +17 -0
  51. package/dist/type-checker.cjs.map +1 -0
  52. package/dist/type-checker.d.cts +105 -0
  53. package/dist/type-checker.d.ts +105 -0
  54. package/dist/type-checker.js +4 -0
  55. package/dist/type-checker.js.map +1 -0
  56. package/dist/types-D6g4ACjP.d.cts +262 -0
  57. package/dist/types-D6g4ACjP.d.ts +262 -0
  58. package/package.json +11 -8
  59. package/src/HoloScript2DParser.js +0 -227
  60. package/src/HoloScript2DParser.ts +0 -261
  61. package/src/HoloScriptCodeParser.js +0 -1102
  62. package/src/HoloScriptCodeParser.ts +0 -1188
  63. package/src/HoloScriptDebugger.js +0 -458
  64. package/src/HoloScriptParser.js +0 -338
  65. package/src/HoloScriptParser.ts +0 -397
  66. package/src/HoloScriptPlusParser.js +0 -371
  67. package/src/HoloScriptPlusParser.ts +0 -543
  68. package/src/HoloScriptRuntime.js +0 -1399
  69. package/src/HoloScriptRuntime.test.js +0 -351
  70. package/src/HoloScriptRuntime.test.ts +0 -436
  71. package/src/HoloScriptTypeChecker.js +0 -356
  72. package/src/HoloScriptTypeChecker.ts +0 -475
  73. package/src/__tests__/GraphicsServices.test.js +0 -357
  74. package/src/__tests__/GraphicsServices.test.ts +0 -427
  75. package/src/__tests__/HoloScriptPlusParser.test.js +0 -317
  76. package/src/__tests__/HoloScriptPlusParser.test.ts +0 -392
  77. package/src/__tests__/integration.test.js +0 -336
  78. package/src/__tests__/integration.test.ts +0 -416
  79. package/src/__tests__/performance.bench.js +0 -218
  80. package/src/__tests__/performance.bench.ts +0 -262
  81. package/src/__tests__/type-checker.test.js +0 -60
  82. package/src/__tests__/type-checker.test.ts +0 -73
  83. package/src/index.js +0 -217
  84. package/src/index.ts +0 -426
  85. package/src/interop/Interoperability.js +0 -413
  86. package/src/interop/Interoperability.ts +0 -494
  87. package/src/logger.js +0 -42
  88. package/src/logger.ts +0 -57
  89. package/src/parser/EnhancedParser.js +0 -205
  90. package/src/parser/EnhancedParser.ts +0 -251
  91. package/src/parser/HoloScriptPlusParser.js +0 -928
  92. package/src/parser/HoloScriptPlusParser.ts +0 -1089
  93. package/src/runtime/HoloScriptPlusRuntime.js +0 -674
  94. package/src/runtime/HoloScriptPlusRuntime.ts +0 -861
  95. package/src/runtime/PerformanceTelemetry.js +0 -323
  96. package/src/runtime/PerformanceTelemetry.ts +0 -467
  97. package/src/runtime/RuntimeOptimization.js +0 -361
  98. package/src/runtime/RuntimeOptimization.ts +0 -416
  99. package/src/services/HololandGraphicsPipelineService.js +0 -506
  100. package/src/services/HololandGraphicsPipelineService.ts +0 -662
  101. package/src/services/PlatformPerformanceOptimizer.js +0 -356
  102. package/src/services/PlatformPerformanceOptimizer.ts +0 -503
  103. package/src/state/ReactiveState.js +0 -427
  104. package/src/state/ReactiveState.ts +0 -572
  105. package/src/tools/DeveloperExperience.js +0 -376
  106. package/src/tools/DeveloperExperience.ts +0 -438
  107. package/src/traits/AIDriverTrait.js +0 -322
  108. package/src/traits/AIDriverTrait.test.js +0 -329
  109. package/src/traits/AIDriverTrait.test.ts +0 -357
  110. package/src/traits/AIDriverTrait.ts +0 -474
  111. package/src/traits/LightingTrait.js +0 -313
  112. package/src/traits/LightingTrait.test.js +0 -410
  113. package/src/traits/LightingTrait.test.ts +0 -462
  114. package/src/traits/LightingTrait.ts +0 -505
  115. package/src/traits/MaterialTrait.js +0 -194
  116. package/src/traits/MaterialTrait.test.js +0 -286
  117. package/src/traits/MaterialTrait.test.ts +0 -329
  118. package/src/traits/MaterialTrait.ts +0 -324
  119. package/src/traits/RenderingTrait.js +0 -356
  120. package/src/traits/RenderingTrait.test.js +0 -363
  121. package/src/traits/RenderingTrait.test.ts +0 -427
  122. package/src/traits/RenderingTrait.ts +0 -555
  123. package/src/traits/VRTraitSystem.js +0 -740
  124. package/src/traits/VRTraitSystem.ts +0 -1040
  125. package/src/traits/VoiceInputTrait.js +0 -284
  126. package/src/traits/VoiceInputTrait.test.js +0 -226
  127. package/src/traits/VoiceInputTrait.test.ts +0 -252
  128. package/src/traits/VoiceInputTrait.ts +0 -401
  129. package/src/types/AdvancedTypeSystem.js +0 -226
  130. package/src/types/AdvancedTypeSystem.ts +0 -494
  131. package/src/types/HoloScriptPlus.d.ts +0 -853
  132. package/src/types.js +0 -6
  133. package/src/types.ts +0 -369
  134. package/tsconfig.json +0 -23
  135. package/tsup.config.d.ts +0 -2
  136. package/tsup.config.js +0 -18
  137. package/tsup.config.ts +0 -19
@@ -1,284 +0,0 @@
1
- /**
2
- * @holoscript/core VoiceInput Trait
3
- *
4
- * Enables voice-driven interactions for HoloScript+ objects
5
- * Integrates speech recognition with confidence-based command parsing
6
- */
7
- /**
8
- * VoiceInputTrait - Enables speech recognition on HoloScript+ objects
9
- */
10
- export class VoiceInputTrait {
11
- constructor(config) {
12
- this.recognition = null;
13
- this.isListening = false;
14
- this.listeners = new Set();
15
- this.interimTranscript = '';
16
- this.commandCache = new Map();
17
- this.config = {
18
- showTranscript: false,
19
- audioFeedback: true,
20
- timeout: 10000,
21
- ...config,
22
- };
23
- this.initializeRecognition();
24
- this.buildCommandCache();
25
- }
26
- /**
27
- * Initialize Web Speech API
28
- */
29
- initializeRecognition() {
30
- // Use native Web Speech API or polyfill
31
- const SpeechRecognition = globalThis.SpeechRecognition ||
32
- globalThis.webkitSpeechRecognition;
33
- if (!SpeechRecognition) {
34
- console.error('Web Speech API not supported');
35
- return;
36
- }
37
- this.recognition = new SpeechRecognition();
38
- this.setupRecognitionHandlers();
39
- }
40
- /**
41
- * Setup Web Speech API event handlers
42
- */
43
- setupRecognitionHandlers() {
44
- if (!this.recognition)
45
- return;
46
- this.recognition.continuous = this.config.mode === 'continuous';
47
- this.recognition.interimResults = true;
48
- this.recognition.lang = this.config.languages?.[0] || 'en-US';
49
- this.recognition.onstart = () => {
50
- this.isListening = true;
51
- this.interimTranscript = '';
52
- if (this.config.audioFeedback) {
53
- this.playBeep('start');
54
- }
55
- };
56
- this.recognition.onresult = (event) => {
57
- this.interimTranscript = '';
58
- for (let i = event.resultIndex; i < event.results.length; i++) {
59
- const transcript = event.results[i][0].transcript;
60
- const confidence = event.results[i][0].confidence;
61
- const isFinal = event.results[i].isFinal;
62
- if (isFinal) {
63
- this.processVoiceCommand(transcript, confidence);
64
- }
65
- else {
66
- this.interimTranscript += transcript;
67
- }
68
- }
69
- if (this.config.showTranscript) {
70
- this.emitEvent({
71
- type: 'interim',
72
- result: {
73
- transcript: this.interimTranscript,
74
- confidence: 0,
75
- isFinal: false,
76
- language: this.recognition.lang,
77
- timestamp: Date.now(),
78
- },
79
- hologramId: '',
80
- });
81
- }
82
- };
83
- this.recognition.onerror = (_event) => {
84
- this.emitEvent({
85
- type: 'error',
86
- result: {
87
- transcript: '',
88
- confidence: 0,
89
- isFinal: false,
90
- language: this.recognition.lang,
91
- timestamp: Date.now(),
92
- },
93
- hologramId: '',
94
- });
95
- };
96
- this.recognition.onend = () => {
97
- this.isListening = false;
98
- if (this.config.audioFeedback) {
99
- this.playBeep('end');
100
- }
101
- };
102
- }
103
- /**
104
- * Process voice command with fuzzy matching
105
- */
106
- processVoiceCommand(transcript, confidence) {
107
- if (confidence < this.config.confidenceThreshold) {
108
- return;
109
- }
110
- const normalized = transcript.toLowerCase().trim();
111
- let bestMatch = null;
112
- let bestScore = 0;
113
- // Try to find matching command
114
- for (const command of this.config.commands || []) {
115
- const cmdConfidence = command.confidence || this.config.confidenceThreshold;
116
- // Exact match
117
- if (normalized === command.phrase.toLowerCase()) {
118
- if (confidence >= cmdConfidence) {
119
- bestMatch = command;
120
- bestScore = 1.0;
121
- break;
122
- }
123
- }
124
- // Fuzzy match with aliases
125
- const allPhrases = [command.phrase, ...(command.aliases || [])];
126
- for (const phrase of allPhrases) {
127
- const score = this.fuzzyMatch(normalized, phrase.toLowerCase());
128
- if (score > bestScore && score >= 0.7) {
129
- bestScore = score;
130
- bestMatch = command;
131
- }
132
- }
133
- }
134
- // Emit recognition result
135
- this.emitEvent({
136
- type: 'final',
137
- result: {
138
- transcript: normalized,
139
- confidence,
140
- isFinal: true,
141
- language: this.recognition.lang,
142
- matchedCommand: bestMatch || undefined,
143
- timestamp: Date.now(),
144
- },
145
- hologramId: '',
146
- });
147
- if (bestMatch) {
148
- if (this.config.audioFeedback) {
149
- this.playBeep('success');
150
- }
151
- }
152
- }
153
- /**
154
- * Fuzzy string matching (simple Levenshtein-like approach)
155
- */
156
- fuzzyMatch(input, target) {
157
- if (input === target)
158
- return 1.0;
159
- if (input.length === 0 || target.length === 0)
160
- return 0;
161
- // Check if input is substring of target
162
- if (target.includes(input)) {
163
- return Math.min(1.0, input.length / target.length);
164
- }
165
- // Simple edit distance estimation
166
- const distance = Math.abs(input.length - target.length);
167
- const maxLen = Math.max(input.length, target.length);
168
- return Math.max(0, 1.0 - distance / maxLen);
169
- }
170
- /**
171
- * Build command index for faster lookup
172
- */
173
- buildCommandCache() {
174
- for (const command of this.config.commands || []) {
175
- this.commandCache.set(command.phrase.toLowerCase(), command);
176
- for (const alias of command.aliases || []) {
177
- this.commandCache.set(alias.toLowerCase(), command);
178
- }
179
- }
180
- }
181
- /**
182
- * Start listening for voice input
183
- */
184
- startListening() {
185
- if (!this.recognition || this.isListening)
186
- return;
187
- try {
188
- this.recognition.start();
189
- }
190
- catch (error) {
191
- console.error('Failed to start speech recognition:', error);
192
- }
193
- }
194
- /**
195
- * Stop listening for voice input
196
- */
197
- stopListening() {
198
- if (!this.recognition || !this.isListening)
199
- return;
200
- try {
201
- this.recognition.stop();
202
- }
203
- catch (error) {
204
- console.error('Failed to stop speech recognition:', error);
205
- }
206
- }
207
- /**
208
- * Toggle listening state
209
- */
210
- toggleListening() {
211
- if (this.isListening) {
212
- this.stopListening();
213
- }
214
- else {
215
- this.startListening();
216
- }
217
- }
218
- /**
219
- * Add command listener
220
- */
221
- on(listener) {
222
- this.listeners.add(listener);
223
- }
224
- /**
225
- * Remove command listener
226
- */
227
- off(listener) {
228
- this.listeners.delete(listener);
229
- }
230
- /**
231
- * Emit voice event to all listeners
232
- */
233
- emitEvent(event) {
234
- for (const listener of this.listeners) {
235
- listener(event);
236
- }
237
- }
238
- /**
239
- * Play audio feedback beep
240
- */
241
- playBeep(type) {
242
- // AudioContext beep generation
243
- try {
244
- const audioContext = new globalThis.AudioContext();
245
- const oscillator = audioContext.createOscillator();
246
- const gainNode = audioContext.createGain();
247
- oscillator.connect(gainNode);
248
- gainNode.connect(audioContext.destination);
249
- const now = audioContext.currentTime;
250
- const duration = 0.1;
251
- // Vary beep frequency by type
252
- oscillator.frequency.value = type === 'start' ? 800 : type === 'success' ? 1000 : 600;
253
- gainNode.gain.setValueAtTime(0.3, now);
254
- gainNode.gain.exponentialRampToValueAtTime(0.01, now + duration);
255
- oscillator.start(now);
256
- oscillator.stop(now + duration);
257
- }
258
- catch (error) {
259
- // Silently fail if audio not available
260
- }
261
- }
262
- /**
263
- * Get current listening state
264
- */
265
- isActive() {
266
- return this.isListening;
267
- }
268
- /**
269
- * Dispose and cleanup
270
- */
271
- dispose() {
272
- if (this.recognition) {
273
- this.recognition.abort();
274
- }
275
- this.listeners.clear();
276
- this.commandCache.clear();
277
- }
278
- }
279
- /**
280
- * HoloScript+ @voice_input trait factory
281
- */
282
- export function createVoiceInputTrait(config) {
283
- return new VoiceInputTrait(config);
284
- }
@@ -1,226 +0,0 @@
1
- /**
2
- * VoiceInputTrait Tests
3
- *
4
- * Comprehensive tests for voice recognition and command matching
5
- */
6
- import { describe, it, expect, beforeEach, vi } from 'vitest';
7
- import { VoiceInputTrait } from '../traits/VoiceInputTrait';
8
- describe('VoiceInputTrait', () => {
9
- let trait;
10
- let config;
11
- beforeEach(() => {
12
- config = {
13
- mode: 'continuous',
14
- confidenceThreshold: 0.7,
15
- commands: [
16
- {
17
- phrase: 'turn on',
18
- aliases: ['activate', 'power up'],
19
- action: 'activate',
20
- },
21
- {
22
- phrase: 'move forward',
23
- aliases: ['go forward', 'advance'],
24
- action: 'move',
25
- params: { direction: 'forward' },
26
- },
27
- {
28
- phrase: 'stop',
29
- aliases: ['halt', 'pause'],
30
- action: 'stop',
31
- },
32
- ],
33
- };
34
- trait = new VoiceInputTrait(config);
35
- });
36
- describe('Initialization', () => {
37
- it('should initialize with config', () => {
38
- expect(trait).toBeDefined();
39
- });
40
- it('should not be listening initially', () => {
41
- expect(trait.isActive()).toBe(false);
42
- });
43
- it('should accept custom confidence threshold', () => {
44
- const customTrait = new VoiceInputTrait({
45
- mode: 'push-to-talk',
46
- confidenceThreshold: 0.85,
47
- });
48
- expect(customTrait).toBeDefined();
49
- });
50
- });
51
- describe('Listening Control', () => {
52
- it('should start listening', () => {
53
- trait.startListening();
54
- // Note: Web Speech API not available in test env, so this just tests the method exists
55
- expect(trait).toBeDefined();
56
- });
57
- it('should stop listening', () => {
58
- trait.stopListening();
59
- expect(trait.isActive()).toBe(false);
60
- });
61
- it('should toggle listening state', () => {
62
- const initialState = trait.isActive();
63
- trait.toggleListening();
64
- // Can't easily test state change without Web Speech API
65
- expect(trait).toBeDefined();
66
- });
67
- });
68
- describe('Event Listeners', () => {
69
- it('should register event listener', () => {
70
- const listener = vi.fn();
71
- trait.on(listener);
72
- expect(listener).not.toHaveBeenCalled();
73
- });
74
- it('should unregister event listener', () => {
75
- const listener = vi.fn();
76
- trait.on(listener);
77
- trait.off(listener);
78
- expect(trait).toBeDefined();
79
- });
80
- it('should allow multiple listeners', () => {
81
- const listener1 = vi.fn();
82
- const listener2 = vi.fn();
83
- trait.on(listener1);
84
- trait.on(listener2);
85
- expect(trait).toBeDefined();
86
- });
87
- });
88
- describe('Configuration', () => {
89
- it('should support continuous mode', () => {
90
- const continuousTrait = new VoiceInputTrait({
91
- mode: 'continuous',
92
- confidenceThreshold: 0.7,
93
- });
94
- expect(continuousTrait).toBeDefined();
95
- });
96
- it('should support push-to-talk mode', () => {
97
- const pushTrait = new VoiceInputTrait({
98
- mode: 'push-to-talk',
99
- confidenceThreshold: 0.7,
100
- });
101
- expect(pushTrait).toBeDefined();
102
- });
103
- it('should support always-listening mode', () => {
104
- const alwaysTrait = new VoiceInputTrait({
105
- mode: 'always-listening',
106
- confidenceThreshold: 0.5,
107
- });
108
- expect(alwaysTrait).toBeDefined();
109
- });
110
- it('should accept multiple languages', () => {
111
- const multiLangTrait = new VoiceInputTrait({
112
- mode: 'continuous',
113
- confidenceThreshold: 0.7,
114
- languages: ['en-US', 'es-ES', 'fr-FR'],
115
- });
116
- expect(multiLangTrait).toBeDefined();
117
- });
118
- it('should support audio feedback toggle', () => {
119
- const feedbackTrait = new VoiceInputTrait({
120
- mode: 'continuous',
121
- confidenceThreshold: 0.7,
122
- audioFeedback: true,
123
- });
124
- expect(feedbackTrait).toBeDefined();
125
- });
126
- it('should support transcript display', () => {
127
- const transcriptTrait = new VoiceInputTrait({
128
- mode: 'continuous',
129
- confidenceThreshold: 0.7,
130
- showTranscript: true,
131
- });
132
- expect(transcriptTrait).toBeDefined();
133
- });
134
- });
135
- describe('Command Configuration', () => {
136
- it('should support command phrases', () => {
137
- const commands = [
138
- { phrase: 'hello', action: 'greet' },
139
- ];
140
- const cmdTrait = new VoiceInputTrait({
141
- mode: 'continuous',
142
- confidenceThreshold: 0.7,
143
- commands,
144
- });
145
- expect(cmdTrait).toBeDefined();
146
- });
147
- it('should support command aliases', () => {
148
- const commands = [
149
- {
150
- phrase: 'turn on',
151
- aliases: ['activate', 'power up', 'enable'],
152
- action: 'activate',
153
- },
154
- ];
155
- const cmdTrait = new VoiceInputTrait({
156
- mode: 'continuous',
157
- confidenceThreshold: 0.7,
158
- commands,
159
- });
160
- expect(cmdTrait).toBeDefined();
161
- });
162
- it('should support per-command confidence', () => {
163
- const commands = [
164
- {
165
- phrase: 'critical action',
166
- action: 'critical',
167
- confidence: 0.95,
168
- },
169
- {
170
- phrase: 'normal action',
171
- action: 'normal',
172
- confidence: 0.7,
173
- },
174
- ];
175
- const cmdTrait = new VoiceInputTrait({
176
- mode: 'continuous',
177
- confidenceThreshold: 0.7,
178
- commands,
179
- });
180
- expect(cmdTrait).toBeDefined();
181
- });
182
- it('should support command parameters', () => {
183
- const commands = [
184
- {
185
- phrase: 'go to location',
186
- action: 'navigate',
187
- params: { target: 'location' },
188
- },
189
- ];
190
- const cmdTrait = new VoiceInputTrait({
191
- mode: 'continuous',
192
- confidenceThreshold: 0.7,
193
- commands,
194
- });
195
- expect(cmdTrait).toBeDefined();
196
- });
197
- });
198
- describe('Timeout Configuration', () => {
199
- it('should support custom timeout', () => {
200
- const timeoutTrait = new VoiceInputTrait({
201
- mode: 'continuous',
202
- confidenceThreshold: 0.7,
203
- timeout: 5000,
204
- });
205
- expect(timeoutTrait).toBeDefined();
206
- });
207
- it('should use default timeout if not specified', () => {
208
- const defaultTrait = new VoiceInputTrait({
209
- mode: 'continuous',
210
- confidenceThreshold: 0.7,
211
- });
212
- expect(defaultTrait).toBeDefined();
213
- });
214
- });
215
- describe('Cleanup', () => {
216
- it('should dispose resources', () => {
217
- trait.dispose();
218
- expect(trait).toBeDefined();
219
- });
220
- it('should stop listening on dispose', () => {
221
- trait.startListening();
222
- trait.dispose();
223
- expect(trait.isActive()).toBe(false);
224
- });
225
- });
226
- });