@apteva/apteva-kit 0.1.137 → 0.1.138
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +186 -131
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4457,22 +4457,6 @@ function base64ToFloat32(base64) {
|
|
|
4457
4457
|
}
|
|
4458
4458
|
return float32Array;
|
|
4459
4459
|
}
|
|
4460
|
-
function resampleAudio(inputData, inputSampleRate, outputSampleRate) {
|
|
4461
|
-
if (inputSampleRate === outputSampleRate) {
|
|
4462
|
-
return inputData;
|
|
4463
|
-
}
|
|
4464
|
-
const ratio = inputSampleRate / outputSampleRate;
|
|
4465
|
-
const outputLength = Math.floor(inputData.length / ratio);
|
|
4466
|
-
const output = new Float32Array(outputLength);
|
|
4467
|
-
for (let i = 0; i < outputLength; i++) {
|
|
4468
|
-
const srcIndex = i * ratio;
|
|
4469
|
-
const srcIndexFloor = Math.floor(srcIndex);
|
|
4470
|
-
const srcIndexCeil = Math.min(srcIndexFloor + 1, inputData.length - 1);
|
|
4471
|
-
const t = srcIndex - srcIndexFloor;
|
|
4472
|
-
output[i] = inputData[srcIndexFloor] * (1 - t) + inputData[srcIndexCeil] * t;
|
|
4473
|
-
}
|
|
4474
|
-
return output;
|
|
4475
|
-
}
|
|
4476
4460
|
|
|
4477
4461
|
// src/hooks/useVoiceSession.ts
|
|
4478
4462
|
function useVoiceSession(config) {
|
|
@@ -4491,8 +4475,10 @@ function useVoiceSession(config) {
|
|
|
4491
4475
|
const mutedRef = _react.useRef.call(void 0, false);
|
|
4492
4476
|
const configRef = _react.useRef.call(void 0, config);
|
|
4493
4477
|
configRef.current = config;
|
|
4494
|
-
const
|
|
4495
|
-
const
|
|
4478
|
+
const activeSourcesRef = _react.useRef.call(void 0, []);
|
|
4479
|
+
const responseStartTimeRef = _react.useRef.call(void 0, 0);
|
|
4480
|
+
const totalAudioDurationMsRef = _react.useRef.call(void 0, 0);
|
|
4481
|
+
const interruptedRef = _react.useRef.call(void 0, false);
|
|
4496
4482
|
const cleanup = _react.useCallback.call(void 0, () => {
|
|
4497
4483
|
if (durationIntervalRef.current) {
|
|
4498
4484
|
clearInterval(durationIntervalRef.current);
|
|
@@ -4529,15 +4515,26 @@ function useVoiceSession(config) {
|
|
|
4529
4515
|
}
|
|
4530
4516
|
nextPlayTimeRef.current = 0;
|
|
4531
4517
|
mutedRef.current = false;
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
}
|
|
4518
|
+
activeSourcesRef.current = [];
|
|
4519
|
+
responseStartTimeRef.current = 0;
|
|
4520
|
+
totalAudioDurationMsRef.current = 0;
|
|
4521
|
+
interruptedRef.current = false;
|
|
4537
4522
|
setMuted(false);
|
|
4538
4523
|
setPartialTranscript("");
|
|
4539
4524
|
setDuration(0);
|
|
4540
4525
|
}, []);
|
|
4526
|
+
const resetPlayback = _react.useCallback.call(void 0, () => {
|
|
4527
|
+
activeSourcesRef.current.forEach((source) => {
|
|
4528
|
+
try {
|
|
4529
|
+
source.stop();
|
|
4530
|
+
} catch (_) {
|
|
4531
|
+
}
|
|
4532
|
+
});
|
|
4533
|
+
activeSourcesRef.current = [];
|
|
4534
|
+
nextPlayTimeRef.current = 0;
|
|
4535
|
+
responseStartTimeRef.current = 0;
|
|
4536
|
+
totalAudioDurationMsRef.current = 0;
|
|
4537
|
+
}, []);
|
|
4541
4538
|
_react.useEffect.call(void 0, () => {
|
|
4542
4539
|
return () => {
|
|
4543
4540
|
cleanup();
|
|
@@ -4557,18 +4554,18 @@ function useVoiceSession(config) {
|
|
|
4557
4554
|
const source = ctx.createBufferSource();
|
|
4558
4555
|
source.buffer = audioBuffer;
|
|
4559
4556
|
source.connect(ctx.destination);
|
|
4557
|
+
activeSourcesRef.current.push(source);
|
|
4558
|
+
source.onended = () => {
|
|
4559
|
+
activeSourcesRef.current = activeSourcesRef.current.filter((s) => s !== source);
|
|
4560
|
+
};
|
|
4560
4561
|
const currentTime = ctx.currentTime;
|
|
4561
4562
|
const startTime = Math.max(currentTime, nextPlayTimeRef.current);
|
|
4562
4563
|
source.start(startTime);
|
|
4563
4564
|
nextPlayTimeRef.current = startTime + audioBuffer.duration;
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
const remainingMs = (nextPlayTimeRef.current - currentTime) * 1e3 + 150;
|
|
4569
|
-
agentSpeakingTimeoutRef.current = setTimeout(() => {
|
|
4570
|
-
agentSpeakingRef.current = false;
|
|
4571
|
-
}, remainingMs);
|
|
4565
|
+
if (responseStartTimeRef.current === 0) {
|
|
4566
|
+
responseStartTimeRef.current = startTime;
|
|
4567
|
+
}
|
|
4568
|
+
totalAudioDurationMsRef.current += Math.floor(audioBuffer.duration * 1e3);
|
|
4572
4569
|
}, []);
|
|
4573
4570
|
const startCaptureRef = _react.useRef.call(void 0, () => {
|
|
4574
4571
|
});
|
|
@@ -4584,17 +4581,50 @@ function useVoiceSession(config) {
|
|
|
4584
4581
|
startCaptureRef.current();
|
|
4585
4582
|
break;
|
|
4586
4583
|
case "audio_delta":
|
|
4584
|
+
if (interruptedRef.current) break;
|
|
4587
4585
|
if (_optionalChain([msg, 'access', _93 => _93.data, 'optionalAccess', _94 => _94.chunk])) {
|
|
4588
4586
|
playAudioChunk(msg.data.chunk);
|
|
4589
4587
|
}
|
|
4590
4588
|
break;
|
|
4589
|
+
case "audio_complete":
|
|
4590
|
+
interruptedRef.current = false;
|
|
4591
|
+
break;
|
|
4592
|
+
case "audio_interrupt": {
|
|
4593
|
+
if (activeSourcesRef.current.length === 0) break;
|
|
4594
|
+
let audioEndMs = 0;
|
|
4595
|
+
if (playbackCtxRef.current && responseStartTimeRef.current > 0) {
|
|
4596
|
+
const elapsedMs = Math.max(0, Math.floor(
|
|
4597
|
+
(playbackCtxRef.current.currentTime - responseStartTimeRef.current) * 1e3
|
|
4598
|
+
));
|
|
4599
|
+
audioEndMs = Math.min(elapsedMs, totalAudioDurationMsRef.current);
|
|
4600
|
+
}
|
|
4601
|
+
const itemId = _optionalChain([msg, 'access', _95 => _95.data, 'optionalAccess', _96 => _96.item_id]);
|
|
4602
|
+
const contentIndex = _optionalChain([msg, 'access', _97 => _97.data, 'optionalAccess', _98 => _98.content_index]) || 0;
|
|
4603
|
+
resetPlayback();
|
|
4604
|
+
if (itemId) {
|
|
4605
|
+
interruptedRef.current = true;
|
|
4606
|
+
}
|
|
4607
|
+
const ws = wsRef.current;
|
|
4608
|
+
if (ws && ws.readyState === WebSocket.OPEN && itemId) {
|
|
4609
|
+
ws.send(JSON.stringify({
|
|
4610
|
+
type: "control",
|
|
4611
|
+
data: {
|
|
4612
|
+
action: "truncate",
|
|
4613
|
+
item_id: itemId,
|
|
4614
|
+
content_index: contentIndex,
|
|
4615
|
+
audio_end_ms: audioEndMs
|
|
4616
|
+
}
|
|
4617
|
+
}));
|
|
4618
|
+
}
|
|
4619
|
+
break;
|
|
4620
|
+
}
|
|
4591
4621
|
case "transcript":
|
|
4592
4622
|
if (msg.data) {
|
|
4593
4623
|
if (msg.data.partial) {
|
|
4594
4624
|
setPartialTranscript(msg.data.content);
|
|
4595
4625
|
} else {
|
|
4596
4626
|
setPartialTranscript("");
|
|
4597
|
-
_optionalChain([cfg, 'access',
|
|
4627
|
+
_optionalChain([cfg, 'access', _99 => _99.onTranscript, 'optionalCall', _100 => _100({
|
|
4598
4628
|
id: `vt-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
|
|
4599
4629
|
role: msg.data.role,
|
|
4600
4630
|
content: msg.data.content,
|
|
@@ -4606,8 +4636,8 @@ function useVoiceSession(config) {
|
|
|
4606
4636
|
break;
|
|
4607
4637
|
case "tool_call":
|
|
4608
4638
|
if (msg.data) {
|
|
4609
|
-
|
|
4610
|
-
_optionalChain([cfg, 'access',
|
|
4639
|
+
resetPlayback();
|
|
4640
|
+
_optionalChain([cfg, 'access', _101 => _101.onTranscript, 'optionalCall', _102 => _102({
|
|
4611
4641
|
id: `vt-tool-${Date.now()}`,
|
|
4612
4642
|
role: "system",
|
|
4613
4643
|
content: `Using ${msg.data.name}...`,
|
|
@@ -4618,24 +4648,48 @@ function useVoiceSession(config) {
|
|
|
4618
4648
|
break;
|
|
4619
4649
|
case "tool_result":
|
|
4620
4650
|
if (msg.data) {
|
|
4621
|
-
|
|
4651
|
+
const status = msg.data.error ? "failed" : "completed";
|
|
4652
|
+
_optionalChain([cfg, 'access', _103 => _103.onTranscript, 'optionalCall', _104 => _104({
|
|
4653
|
+
id: `vt-toolresult-${Date.now()}`,
|
|
4654
|
+
role: "system",
|
|
4655
|
+
content: `Tool ${status}: ${msg.data.name || msg.data.call_id}`,
|
|
4656
|
+
partial: false,
|
|
4657
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
4658
|
+
})]);
|
|
4622
4659
|
}
|
|
4623
4660
|
break;
|
|
4661
|
+
case "turn_end":
|
|
4662
|
+
interruptedRef.current = false;
|
|
4663
|
+
break;
|
|
4624
4664
|
case "error":
|
|
4625
4665
|
setState("error");
|
|
4626
|
-
_optionalChain([cfg, 'access',
|
|
4666
|
+
_optionalChain([cfg, 'access', _105 => _105.onError, 'optionalCall', _106 => _106(new Error(_optionalChain([msg, 'access', _107 => _107.data, 'optionalAccess', _108 => _108.message]) || "Voice session error"))]);
|
|
4627
4667
|
break;
|
|
4628
4668
|
}
|
|
4629
|
-
}, [playAudioChunk]);
|
|
4669
|
+
}, [playAudioChunk, resetPlayback]);
|
|
4630
4670
|
const startCapture = _react.useCallback.call(void 0, async () => {
|
|
4631
4671
|
const ws = wsRef.current;
|
|
4632
4672
|
if (!ws) return;
|
|
4673
|
+
if (processorRef.current) {
|
|
4674
|
+
processorRef.current.disconnect();
|
|
4675
|
+
processorRef.current = null;
|
|
4676
|
+
}
|
|
4677
|
+
if (mediaStreamRef.current) {
|
|
4678
|
+
mediaStreamRef.current.getTracks().forEach((t) => t.stop());
|
|
4679
|
+
mediaStreamRef.current = null;
|
|
4680
|
+
}
|
|
4681
|
+
if (captureCtxRef.current) {
|
|
4682
|
+
try {
|
|
4683
|
+
captureCtxRef.current.close();
|
|
4684
|
+
} catch (_) {
|
|
4685
|
+
}
|
|
4686
|
+
captureCtxRef.current = null;
|
|
4687
|
+
}
|
|
4633
4688
|
try {
|
|
4634
|
-
captureCtxRef.current = new AudioContext();
|
|
4689
|
+
captureCtxRef.current = new AudioContext({ sampleRate: 24e3 });
|
|
4635
4690
|
if (captureCtxRef.current.state === "suspended") {
|
|
4636
4691
|
await captureCtxRef.current.resume();
|
|
4637
4692
|
}
|
|
4638
|
-
const nativeSampleRate = captureCtxRef.current.sampleRate;
|
|
4639
4693
|
mediaStreamRef.current = await navigator.mediaDevices.getUserMedia({
|
|
4640
4694
|
audio: {
|
|
4641
4695
|
echoCancellation: true,
|
|
@@ -4644,27 +4698,28 @@ function useVoiceSession(config) {
|
|
|
4644
4698
|
}
|
|
4645
4699
|
});
|
|
4646
4700
|
const source = captureCtxRef.current.createMediaStreamSource(mediaStreamRef.current);
|
|
4647
|
-
processorRef.current = captureCtxRef.current.createScriptProcessor(
|
|
4701
|
+
processorRef.current = captureCtxRef.current.createScriptProcessor(4096, 1, 1);
|
|
4648
4702
|
processorRef.current.onaudioprocess = (e) => {
|
|
4649
4703
|
if (!ws || ws.readyState !== WebSocket.OPEN) return;
|
|
4650
4704
|
if (mutedRef.current) return;
|
|
4651
|
-
if (agentSpeakingRef.current) return;
|
|
4652
4705
|
const inputData = e.inputBuffer.getChannelData(0);
|
|
4653
|
-
const
|
|
4654
|
-
const int16Data = float32ToInt16(resampledData);
|
|
4706
|
+
const int16Data = float32ToInt16(inputData);
|
|
4655
4707
|
const base64Data = int16ToBase64(int16Data);
|
|
4656
4708
|
ws.send(JSON.stringify({
|
|
4657
4709
|
type: "audio",
|
|
4658
|
-
data: { chunk: base64Data }
|
|
4710
|
+
data: { chunk: base64Data, sample_rate: 24e3 }
|
|
4659
4711
|
}));
|
|
4660
4712
|
};
|
|
4661
4713
|
source.connect(processorRef.current);
|
|
4662
|
-
|
|
4714
|
+
const silentGain = captureCtxRef.current.createGain();
|
|
4715
|
+
silentGain.gain.value = 0;
|
|
4716
|
+
processorRef.current.connect(silentGain);
|
|
4717
|
+
silentGain.connect(captureCtxRef.current.destination);
|
|
4663
4718
|
} catch (e) {
|
|
4664
4719
|
console.warn("Microphone access denied:", e);
|
|
4665
|
-
_optionalChain([configRef, 'access',
|
|
4720
|
+
_optionalChain([configRef, 'access', _109 => _109.current, 'access', _110 => _110.onError, 'optionalCall', _111 => _111(new Error("Microphone access denied"))]);
|
|
4666
4721
|
}
|
|
4667
|
-
}, [
|
|
4722
|
+
}, []);
|
|
4668
4723
|
startCaptureRef.current = startCapture;
|
|
4669
4724
|
const start = _react.useCallback.call(void 0, () => {
|
|
4670
4725
|
if (state !== "idle") return;
|
|
@@ -4704,13 +4759,13 @@ function useVoiceSession(config) {
|
|
|
4704
4759
|
};
|
|
4705
4760
|
ws.onerror = () => {
|
|
4706
4761
|
setState("error");
|
|
4707
|
-
_optionalChain([configRef, 'access',
|
|
4762
|
+
_optionalChain([configRef, 'access', _112 => _112.current, 'access', _113 => _113.onError, 'optionalCall', _114 => _114(new Error("WebSocket connection failed"))]);
|
|
4708
4763
|
};
|
|
4709
4764
|
ws.onclose = () => {
|
|
4710
4765
|
cleanup();
|
|
4711
4766
|
setState("idle");
|
|
4712
4767
|
};
|
|
4713
|
-
}, [state, config.apiUrl, handleMessage, cleanup]);
|
|
4768
|
+
}, [state, config.apiUrl, config.apiKey, handleMessage, cleanup]);
|
|
4714
4769
|
const stop = _react.useCallback.call(void 0, () => {
|
|
4715
4770
|
cleanup();
|
|
4716
4771
|
setState("idle");
|
|
@@ -4884,7 +4939,7 @@ ${widgetContext}` : widgetContext;
|
|
|
4884
4939
|
}, [apiUrl, apiKey]);
|
|
4885
4940
|
_react.useEffect.call(void 0, () => {
|
|
4886
4941
|
if (threadId) {
|
|
4887
|
-
_optionalChain([onThreadChange, 'optionalCall',
|
|
4942
|
+
_optionalChain([onThreadChange, 'optionalCall', _115 => _115(threadId)]);
|
|
4888
4943
|
}
|
|
4889
4944
|
}, [threadId, onThreadChange]);
|
|
4890
4945
|
_react.useEffect.call(void 0, () => {
|
|
@@ -4902,7 +4957,7 @@ ${widgetContext}` : widgetContext;
|
|
|
4902
4957
|
}, [showSettingsMenu]);
|
|
4903
4958
|
const handleModeChange = (newMode) => {
|
|
4904
4959
|
setMode(newMode);
|
|
4905
|
-
_optionalChain([onModeChange, 'optionalCall',
|
|
4960
|
+
_optionalChain([onModeChange, 'optionalCall', _116 => _116(newMode)]);
|
|
4906
4961
|
if (newMode === "command") {
|
|
4907
4962
|
setCommandState("idle");
|
|
4908
4963
|
setCommandResult(null);
|
|
@@ -4911,8 +4966,8 @@ ${widgetContext}` : widgetContext;
|
|
|
4911
4966
|
};
|
|
4912
4967
|
const defaultPlaceholder = mode === "chat" ? "Type a message..." : "Enter your command...";
|
|
4913
4968
|
const handleWidgetAction = _react.useCallback.call(void 0, (action) => {
|
|
4914
|
-
_optionalChain([onAction, 'optionalCall',
|
|
4915
|
-
if (action.type === "submit" && _optionalChain([action, 'access',
|
|
4969
|
+
_optionalChain([onAction, 'optionalCall', _117 => _117(action)]);
|
|
4970
|
+
if (action.type === "submit" && _optionalChain([action, 'access', _118 => _118.payload, 'optionalAccess', _119 => _119.formData])) {
|
|
4916
4971
|
const formData = action.payload.formData;
|
|
4917
4972
|
const lines = [];
|
|
4918
4973
|
for (const [key, value] of Object.entries(formData)) {
|
|
@@ -4951,7 +5006,7 @@ ${widgetContext}` : widgetContext;
|
|
|
4951
5006
|
metadata: hasFiles ? { attachments } : void 0
|
|
4952
5007
|
};
|
|
4953
5008
|
setMessages((prev) => [...prev, userMessage]);
|
|
4954
|
-
_optionalChain([onMessageSent, 'optionalCall',
|
|
5009
|
+
_optionalChain([onMessageSent, 'optionalCall', _120 => _120(userMessage)]);
|
|
4955
5010
|
}
|
|
4956
5011
|
setIsLoading(true);
|
|
4957
5012
|
try {
|
|
@@ -5019,7 +5074,7 @@ ${widgetContext}` : widgetContext;
|
|
|
5019
5074
|
responseThreadId = chunk.thread_id;
|
|
5020
5075
|
if (!currentThreadId) {
|
|
5021
5076
|
setCurrentThreadId(chunk.thread_id);
|
|
5022
|
-
_optionalChain([onThreadChange, 'optionalCall',
|
|
5077
|
+
_optionalChain([onThreadChange, 'optionalCall', _121 => _121(chunk.thread_id)]);
|
|
5023
5078
|
}
|
|
5024
5079
|
}
|
|
5025
5080
|
break;
|
|
@@ -5051,7 +5106,7 @@ ${widgetContext}` : widgetContext;
|
|
|
5051
5106
|
contentSegments.push({ type: "tool", id: chunk.tool_id, name: displayName, status: "preparing" });
|
|
5052
5107
|
toolInputBuffers[chunk.tool_id] = "";
|
|
5053
5108
|
setChatToolName(displayName);
|
|
5054
|
-
_optionalChain([onToolCall, 'optionalCall',
|
|
5109
|
+
_optionalChain([onToolCall, 'optionalCall', _122 => _122(chunk.tool_name, chunk.tool_id)]);
|
|
5055
5110
|
updateMessage();
|
|
5056
5111
|
}
|
|
5057
5112
|
break;
|
|
@@ -5111,7 +5166,7 @@ ${widgetContext}` : widgetContext;
|
|
|
5111
5166
|
toolSegment.result = chunk.content;
|
|
5112
5167
|
toolSegment.status = "completed";
|
|
5113
5168
|
toolSegment.isReceiving = false;
|
|
5114
|
-
_optionalChain([onToolResult, 'optionalCall',
|
|
5169
|
+
_optionalChain([onToolResult, 'optionalCall', _123 => _123(toolSegment.name, chunk.content)]);
|
|
5115
5170
|
}
|
|
5116
5171
|
setChatToolName(null);
|
|
5117
5172
|
updateMessage();
|
|
@@ -5155,7 +5210,7 @@ ${widgetContext}` : widgetContext;
|
|
|
5155
5210
|
});
|
|
5156
5211
|
if (threadId2 && threadId2 !== currentThreadId) {
|
|
5157
5212
|
setCurrentThreadId(threadId2);
|
|
5158
|
-
_optionalChain([onThreadChange, 'optionalCall',
|
|
5213
|
+
_optionalChain([onThreadChange, 'optionalCall', _124 => _124(threadId2)]);
|
|
5159
5214
|
}
|
|
5160
5215
|
setIsLoading(false);
|
|
5161
5216
|
setCurrentRequestId(null);
|
|
@@ -5179,7 +5234,7 @@ ${widgetContext}` : widgetContext;
|
|
|
5179
5234
|
setIsLoading(false);
|
|
5180
5235
|
setCurrentRequestId(null);
|
|
5181
5236
|
setChatToolName(null);
|
|
5182
|
-
_optionalChain([onError, 'optionalCall',
|
|
5237
|
+
_optionalChain([onError, 'optionalCall', _125 => _125(error)]);
|
|
5183
5238
|
}
|
|
5184
5239
|
);
|
|
5185
5240
|
}
|
|
@@ -5192,7 +5247,7 @@ ${widgetContext}` : widgetContext;
|
|
|
5192
5247
|
metadata: { error: true }
|
|
5193
5248
|
};
|
|
5194
5249
|
setMessages((prev) => [...prev, errorMessage]);
|
|
5195
|
-
_optionalChain([onError, 'optionalCall',
|
|
5250
|
+
_optionalChain([onError, 'optionalCall', _126 => _126(error instanceof Error ? error : new Error("Unknown error"))]);
|
|
5196
5251
|
} finally {
|
|
5197
5252
|
setIsLoading(false);
|
|
5198
5253
|
}
|
|
@@ -5238,7 +5293,7 @@ ${planningInstruction}` : planningInstruction;
|
|
|
5238
5293
|
const error = err instanceof Error ? err : new Error("Failed to generate plan");
|
|
5239
5294
|
setCommandError(error);
|
|
5240
5295
|
setCommandState("error");
|
|
5241
|
-
_optionalChain([onError, 'optionalCall',
|
|
5296
|
+
_optionalChain([onError, 'optionalCall', _127 => _127(error)]);
|
|
5242
5297
|
}
|
|
5243
5298
|
}
|
|
5244
5299
|
return;
|
|
@@ -5271,12 +5326,12 @@ ${planningInstruction}` : planningInstruction;
|
|
|
5271
5326
|
setCommandResult(result);
|
|
5272
5327
|
setCommandState("success");
|
|
5273
5328
|
setProgress(100);
|
|
5274
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
5329
|
+
_optionalChain([onComplete, 'optionalCall', _128 => _128(result)]);
|
|
5275
5330
|
},
|
|
5276
5331
|
(error) => {
|
|
5277
5332
|
setCommandError(error);
|
|
5278
5333
|
setCommandState("error");
|
|
5279
|
-
_optionalChain([onError, 'optionalCall',
|
|
5334
|
+
_optionalChain([onError, 'optionalCall', _129 => _129(error)]);
|
|
5280
5335
|
}
|
|
5281
5336
|
);
|
|
5282
5337
|
} else {
|
|
@@ -5289,7 +5344,7 @@ ${planningInstruction}` : planningInstruction;
|
|
|
5289
5344
|
setCommandResult(result);
|
|
5290
5345
|
setCommandState("success");
|
|
5291
5346
|
setProgress(100);
|
|
5292
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
5347
|
+
_optionalChain([onComplete, 'optionalCall', _130 => _130(result)]);
|
|
5293
5348
|
}
|
|
5294
5349
|
} else {
|
|
5295
5350
|
const commandInstruction = `CRITICAL COMMAND MODE: Maximum 10 words per response. Execute the command immediately. Make reasonable assumptions based on context. Use sensible defaults for missing details. DO NOT ask questions unless something is truly impossible without user input (e.g., missing required password). State what you're doing or the result. Examples: "Analyzing customer data from last quarter..." or "Created 5 new database entries successfully" or "Search complete: found 12 matching results". NO greetings, NO filler words, NO clarification requests. Action/result only.`;
|
|
@@ -5319,16 +5374,16 @@ ${commandInstruction}` : commandInstruction;
|
|
|
5319
5374
|
const displayName = chunk.tool_display_name || chunk.tool_name;
|
|
5320
5375
|
lastToolName = chunk.tool_name;
|
|
5321
5376
|
setCurrentToolName(displayName);
|
|
5322
|
-
_optionalChain([onToolCall, 'optionalCall',
|
|
5377
|
+
_optionalChain([onToolCall, 'optionalCall', _131 => _131(chunk.tool_name, chunk.tool_id || "")]);
|
|
5323
5378
|
accumulatedContent = "";
|
|
5324
5379
|
setStreamedContent("");
|
|
5325
5380
|
} else if (chunk.type === "tool_result") {
|
|
5326
|
-
_optionalChain([onToolResult, 'optionalCall',
|
|
5381
|
+
_optionalChain([onToolResult, 'optionalCall', _132 => _132(lastToolName, chunk.content)]);
|
|
5327
5382
|
setCurrentToolName(null);
|
|
5328
5383
|
} else if (chunk.type === "thread_id" && chunk.thread_id) {
|
|
5329
5384
|
if (!currentThreadId) {
|
|
5330
5385
|
setCurrentThreadId(chunk.thread_id);
|
|
5331
|
-
_optionalChain([onThreadChange, 'optionalCall',
|
|
5386
|
+
_optionalChain([onThreadChange, 'optionalCall', _133 => _133(chunk.thread_id)]);
|
|
5332
5387
|
}
|
|
5333
5388
|
} else if (chunk.type === "request_id" && chunk.request_id) {
|
|
5334
5389
|
setCurrentRequestId(chunk.request_id);
|
|
@@ -5344,13 +5399,13 @@ ${commandInstruction}` : commandInstruction;
|
|
|
5344
5399
|
setCommandState("success");
|
|
5345
5400
|
setProgress(100);
|
|
5346
5401
|
setCurrentRequestId(null);
|
|
5347
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
5402
|
+
_optionalChain([onComplete, 'optionalCall', _134 => _134(result)]);
|
|
5348
5403
|
},
|
|
5349
5404
|
(error) => {
|
|
5350
5405
|
setCommandError(error);
|
|
5351
5406
|
setCommandState("error");
|
|
5352
5407
|
setCurrentRequestId(null);
|
|
5353
|
-
_optionalChain([onError, 'optionalCall',
|
|
5408
|
+
_optionalChain([onError, 'optionalCall', _135 => _135(error)]);
|
|
5354
5409
|
}
|
|
5355
5410
|
);
|
|
5356
5411
|
} else {
|
|
@@ -5370,14 +5425,14 @@ ${commandInstruction}` : commandInstruction;
|
|
|
5370
5425
|
setCommandResult(result);
|
|
5371
5426
|
setCommandState("success");
|
|
5372
5427
|
setProgress(100);
|
|
5373
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
5428
|
+
_optionalChain([onComplete, 'optionalCall', _136 => _136(result)]);
|
|
5374
5429
|
}
|
|
5375
5430
|
}
|
|
5376
5431
|
} catch (err) {
|
|
5377
5432
|
const error = err instanceof Error ? err : new Error("Unknown error");
|
|
5378
5433
|
setCommandError(error);
|
|
5379
5434
|
setCommandState("error");
|
|
5380
|
-
_optionalChain([onError, 'optionalCall',
|
|
5435
|
+
_optionalChain([onError, 'optionalCall', _137 => _137(error)]);
|
|
5381
5436
|
}
|
|
5382
5437
|
};
|
|
5383
5438
|
const resetCommand = () => {
|
|
@@ -5483,8 +5538,8 @@ ${planToExecute}`;
|
|
|
5483
5538
|
executeCommand(text, files);
|
|
5484
5539
|
},
|
|
5485
5540
|
state: commandState,
|
|
5486
|
-
response: _optionalChain([commandResult, 'optionalAccess',
|
|
5487
|
-
error: _optionalChain([commandError, 'optionalAccess',
|
|
5541
|
+
response: _optionalChain([commandResult, 'optionalAccess', _138 => _138.data, 'optionalAccess', _139 => _139.summary]) || _optionalChain([commandResult, 'optionalAccess', _140 => _140.message]),
|
|
5542
|
+
error: _optionalChain([commandError, 'optionalAccess', _141 => _141.message]),
|
|
5488
5543
|
plan,
|
|
5489
5544
|
streamedContent,
|
|
5490
5545
|
toolName: currentToolName,
|
|
@@ -5651,7 +5706,7 @@ function Call({
|
|
|
5651
5706
|
const next = [...prev, entry];
|
|
5652
5707
|
return next.length > maxTranscriptEntries ? next.slice(next.length - maxTranscriptEntries) : next;
|
|
5653
5708
|
});
|
|
5654
|
-
_optionalChain([onTranscript, 'optionalCall',
|
|
5709
|
+
_optionalChain([onTranscript, 'optionalCall', _142 => _142(entry)]);
|
|
5655
5710
|
}, [maxTranscriptEntries, onTranscript]);
|
|
5656
5711
|
const voice = useVoiceSession({
|
|
5657
5712
|
apiUrl,
|
|
@@ -5667,10 +5722,10 @@ function Call({
|
|
|
5667
5722
|
_react.useEffect.call(void 0, () => {
|
|
5668
5723
|
const prev = prevStateRef.current;
|
|
5669
5724
|
if (prev !== "active" && voice.state === "active") {
|
|
5670
|
-
_optionalChain([onCallStart, 'optionalCall',
|
|
5725
|
+
_optionalChain([onCallStart, 'optionalCall', _143 => _143()]);
|
|
5671
5726
|
}
|
|
5672
5727
|
if (prev === "active" && voice.state === "idle") {
|
|
5673
|
-
_optionalChain([onCallEnd, 'optionalCall',
|
|
5728
|
+
_optionalChain([onCallEnd, 'optionalCall', _144 => _144({ duration: durationRef.current, transcripts })]);
|
|
5674
5729
|
}
|
|
5675
5730
|
prevStateRef.current = voice.state;
|
|
5676
5731
|
}, [voice.state, onCallStart, onCallEnd, transcripts]);
|
|
@@ -5681,7 +5736,7 @@ function Call({
|
|
|
5681
5736
|
}
|
|
5682
5737
|
}, [autoStart, voice.state, voice.start]);
|
|
5683
5738
|
_react.useEffect.call(void 0, () => {
|
|
5684
|
-
_optionalChain([onMuteChange, 'optionalCall',
|
|
5739
|
+
_optionalChain([onMuteChange, 'optionalCall', _145 => _145(voice.muted)]);
|
|
5685
5740
|
}, [voice.muted, onMuteChange]);
|
|
5686
5741
|
const cn2 = [
|
|
5687
5742
|
"apteva-call",
|
|
@@ -5857,13 +5912,13 @@ ${planningInstruction}` : planningInstruction;
|
|
|
5857
5912
|
const error2 = err instanceof Error ? err : new Error("Failed to generate plan");
|
|
5858
5913
|
setError(error2);
|
|
5859
5914
|
setState("error");
|
|
5860
|
-
_optionalChain([onError, 'optionalCall',
|
|
5915
|
+
_optionalChain([onError, 'optionalCall', _146 => _146(error2)]);
|
|
5861
5916
|
});
|
|
5862
5917
|
} catch (err) {
|
|
5863
5918
|
const error2 = err instanceof Error ? err : new Error("Failed to generate plan");
|
|
5864
5919
|
setError(error2);
|
|
5865
5920
|
setState("error");
|
|
5866
|
-
_optionalChain([onError, 'optionalCall',
|
|
5921
|
+
_optionalChain([onError, 'optionalCall', _147 => _147(error2)]);
|
|
5867
5922
|
}
|
|
5868
5923
|
}
|
|
5869
5924
|
return;
|
|
@@ -5874,7 +5929,7 @@ ${planningInstruction}` : planningInstruction;
|
|
|
5874
5929
|
setStreamedContent("");
|
|
5875
5930
|
setCommand("");
|
|
5876
5931
|
setUploadedFiles([]);
|
|
5877
|
-
_optionalChain([onStart, 'optionalCall',
|
|
5932
|
+
_optionalChain([onStart, 'optionalCall', _148 => _148()]);
|
|
5878
5933
|
try {
|
|
5879
5934
|
if (useMock) {
|
|
5880
5935
|
if (enableStreaming) {
|
|
@@ -5885,16 +5940,16 @@ ${planningInstruction}` : planningInstruction;
|
|
|
5885
5940
|
if (chunk.type === "token" && chunk.content) {
|
|
5886
5941
|
accumulatedContent += chunk.content;
|
|
5887
5942
|
setStreamedContent(accumulatedContent);
|
|
5888
|
-
_optionalChain([onChunk, 'optionalCall',
|
|
5943
|
+
_optionalChain([onChunk, 'optionalCall', _149 => _149(chunk.content)]);
|
|
5889
5944
|
const estimatedProgress = Math.min(Math.round(accumulatedContent.length / 10), 90);
|
|
5890
5945
|
setProgress(estimatedProgress);
|
|
5891
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
5946
|
+
_optionalChain([onProgress, 'optionalCall', _150 => _150(estimatedProgress)]);
|
|
5892
5947
|
} else if (chunk.type === "widget" && chunk.widget) {
|
|
5893
5948
|
const widget = chunk.widget;
|
|
5894
5949
|
setResult((prev) => ({
|
|
5895
5950
|
success: true,
|
|
5896
|
-
data: _optionalChain([prev, 'optionalAccess',
|
|
5897
|
-
widgets: [..._optionalChain([prev, 'optionalAccess',
|
|
5951
|
+
data: _optionalChain([prev, 'optionalAccess', _151 => _151.data]) || {},
|
|
5952
|
+
widgets: [..._optionalChain([prev, 'optionalAccess', _152 => _152.widgets]) || [], widget],
|
|
5898
5953
|
message: accumulatedContent || "Command executed successfully"
|
|
5899
5954
|
}));
|
|
5900
5955
|
}
|
|
@@ -5914,19 +5969,19 @@ ${planningInstruction}` : planningInstruction;
|
|
|
5914
5969
|
setResult(result2);
|
|
5915
5970
|
setState("success");
|
|
5916
5971
|
setProgress(100);
|
|
5917
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
5972
|
+
_optionalChain([onComplete, 'optionalCall', _153 => _153(result2)]);
|
|
5918
5973
|
},
|
|
5919
5974
|
(error2) => {
|
|
5920
5975
|
setError(error2);
|
|
5921
5976
|
setState("error");
|
|
5922
|
-
_optionalChain([onError, 'optionalCall',
|
|
5977
|
+
_optionalChain([onError, 'optionalCall', _154 => _154(error2)]);
|
|
5923
5978
|
}
|
|
5924
5979
|
);
|
|
5925
5980
|
} else {
|
|
5926
5981
|
const progressInterval = setInterval(() => {
|
|
5927
5982
|
setProgress((prev) => {
|
|
5928
5983
|
const next = Math.min(prev + 10, 90);
|
|
5929
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
5984
|
+
_optionalChain([onProgress, 'optionalCall', _155 => _155(next)]);
|
|
5930
5985
|
return next;
|
|
5931
5986
|
});
|
|
5932
5987
|
}, 200);
|
|
@@ -5950,7 +6005,7 @@ ${planningInstruction}` : planningInstruction;
|
|
|
5950
6005
|
setResult(result2);
|
|
5951
6006
|
setState("success");
|
|
5952
6007
|
setProgress(100);
|
|
5953
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
6008
|
+
_optionalChain([onComplete, 'optionalCall', _156 => _156(result2)]);
|
|
5954
6009
|
}
|
|
5955
6010
|
} else {
|
|
5956
6011
|
if (enableStreaming) {
|
|
@@ -5996,16 +6051,16 @@ ${commandInstruction}` : commandInstruction;
|
|
|
5996
6051
|
if (chunk.type === "token" && chunk.content) {
|
|
5997
6052
|
accumulatedContent += chunk.content;
|
|
5998
6053
|
setStreamedContent(accumulatedContent);
|
|
5999
|
-
_optionalChain([onChunk, 'optionalCall',
|
|
6054
|
+
_optionalChain([onChunk, 'optionalCall', _157 => _157(chunk.content)]);
|
|
6000
6055
|
const estimatedProgress = Math.min(Math.round(accumulatedContent.length / 10), 90);
|
|
6001
6056
|
setProgress(estimatedProgress);
|
|
6002
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
6057
|
+
_optionalChain([onProgress, 'optionalCall', _158 => _158(estimatedProgress)]);
|
|
6003
6058
|
} else if (chunk.type === "widget" && chunk.widget) {
|
|
6004
6059
|
const widget = chunk.widget;
|
|
6005
6060
|
setResult((prev) => ({
|
|
6006
6061
|
success: true,
|
|
6007
|
-
data: _optionalChain([prev, 'optionalAccess',
|
|
6008
|
-
widgets: [..._optionalChain([prev, 'optionalAccess',
|
|
6062
|
+
data: _optionalChain([prev, 'optionalAccess', _159 => _159.data]) || {},
|
|
6063
|
+
widgets: [..._optionalChain([prev, 'optionalAccess', _160 => _160.widgets]) || [], widget],
|
|
6009
6064
|
message: accumulatedContent || "Command executed successfully"
|
|
6010
6065
|
}));
|
|
6011
6066
|
}
|
|
@@ -6025,20 +6080,20 @@ ${commandInstruction}` : commandInstruction;
|
|
|
6025
6080
|
setResult(result2);
|
|
6026
6081
|
setState("success");
|
|
6027
6082
|
setProgress(100);
|
|
6028
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
6083
|
+
_optionalChain([onComplete, 'optionalCall', _161 => _161(result2)]);
|
|
6029
6084
|
},
|
|
6030
6085
|
(error2) => {
|
|
6031
6086
|
const err = error2 instanceof Error ? error2 : new Error("Unknown error");
|
|
6032
6087
|
setError(err);
|
|
6033
6088
|
setState("error");
|
|
6034
|
-
_optionalChain([onError, 'optionalCall',
|
|
6089
|
+
_optionalChain([onError, 'optionalCall', _162 => _162(err)]);
|
|
6035
6090
|
}
|
|
6036
6091
|
);
|
|
6037
6092
|
} else {
|
|
6038
6093
|
const progressInterval = setInterval(() => {
|
|
6039
6094
|
setProgress((prev) => {
|
|
6040
6095
|
const next = Math.min(prev + 10, 90);
|
|
6041
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
6096
|
+
_optionalChain([onProgress, 'optionalCall', _163 => _163(next)]);
|
|
6042
6097
|
return next;
|
|
6043
6098
|
});
|
|
6044
6099
|
}, 200);
|
|
@@ -6094,14 +6149,14 @@ ${commandInstruction}` : commandInstruction;
|
|
|
6094
6149
|
setResult(result2);
|
|
6095
6150
|
setState("success");
|
|
6096
6151
|
setProgress(100);
|
|
6097
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
6152
|
+
_optionalChain([onComplete, 'optionalCall', _164 => _164(result2)]);
|
|
6098
6153
|
}
|
|
6099
6154
|
}
|
|
6100
6155
|
} catch (err) {
|
|
6101
6156
|
const error2 = err instanceof Error ? err : new Error("Unknown error");
|
|
6102
6157
|
setError(error2);
|
|
6103
6158
|
setState("error");
|
|
6104
|
-
_optionalChain([onError, 'optionalCall',
|
|
6159
|
+
_optionalChain([onError, 'optionalCall', _165 => _165(error2)]);
|
|
6105
6160
|
}
|
|
6106
6161
|
};
|
|
6107
6162
|
const resetCommand = () => {
|
|
@@ -6134,14 +6189,14 @@ ${planToExecute}`;
|
|
|
6134
6189
|
};
|
|
6135
6190
|
const handleFileSelect = async (e) => {
|
|
6136
6191
|
if (e.target.files && e.target.files.length > 0) {
|
|
6137
|
-
_optionalChain([onFileUpload, 'optionalCall',
|
|
6192
|
+
_optionalChain([onFileUpload, 'optionalCall', _166 => _166(e.target.files)]);
|
|
6138
6193
|
const files = [];
|
|
6139
6194
|
for (let i = 0; i < e.target.files.length; i++) {
|
|
6140
6195
|
const file = e.target.files[i];
|
|
6141
6196
|
const reader = new FileReader();
|
|
6142
6197
|
await new Promise((resolve) => {
|
|
6143
6198
|
reader.onload = (event) => {
|
|
6144
|
-
if (_optionalChain([event, 'access',
|
|
6199
|
+
if (_optionalChain([event, 'access', _167 => _167.target, 'optionalAccess', _168 => _168.result])) {
|
|
6145
6200
|
const fullDataUrl = event.target.result;
|
|
6146
6201
|
const base64Data = fullDataUrl.split(",")[1];
|
|
6147
6202
|
if (file.type.startsWith("image/")) {
|
|
@@ -6235,7 +6290,7 @@ ${planToExecute}`;
|
|
|
6235
6290
|
enableFileUpload && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
6236
6291
|
"button",
|
|
6237
6292
|
{
|
|
6238
|
-
onClick: () => _optionalChain([fileInputRef, 'access',
|
|
6293
|
+
onClick: () => _optionalChain([fileInputRef, 'access', _169 => _169.current, 'optionalAccess', _170 => _170.click, 'call', _171 => _171()]),
|
|
6239
6294
|
className: "w-8 h-8 rounded-lg flex items-center justify-center transition-all flex-shrink-0 !text-neutral-500 dark:!text-neutral-500 hover:bg-neutral-100 dark:hover:bg-neutral-800",
|
|
6240
6295
|
title: "Attach file",
|
|
6241
6296
|
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M8.4 2.8L4.4 6.8C3.736 7.464 3.736 8.536 4.4 9.2C5.064 9.864 6.136 9.864 6.8 9.2L11.6 4.4C12.704 3.296 12.704 1.504 11.6 0.4C10.496 -0.704 8.704 -0.704 7.6 0.4L2.8 5.2C1.256 6.744 1.256 9.256 2.8 10.8C4.344 12.344 6.856 12.344 8.4 10.8L12.4 6.8", stroke: "currentColor", strokeWidth: "1.2", strokeLinecap: "round", strokeLinejoin: "round", transform: "translate(1.6, 2.4)" }) })
|
|
@@ -6454,7 +6509,7 @@ ${planToExecute}`;
|
|
|
6454
6509
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-5 h-5 text-red-600 mt-0.5 flex-shrink-0", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" }) }),
|
|
6455
6510
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
|
|
6456
6511
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h3", { className: "text-sm font-semibold text-red-800 dark:text-red-400", children: "Error" }),
|
|
6457
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-red-700 dark:text-red-300 text-sm mt-1", children: _optionalChain([error, 'optionalAccess',
|
|
6512
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-red-700 dark:text-red-300 text-sm mt-1", children: _optionalChain([error, 'optionalAccess', _172 => _172.message]) })
|
|
6458
6513
|
] })
|
|
6459
6514
|
] }) }),
|
|
6460
6515
|
allowInput && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
@@ -6482,7 +6537,7 @@ ${planToExecute}`;
|
|
|
6482
6537
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-green-700 dark:text-green-300 text-sm", children: "Command executed successfully" })
|
|
6483
6538
|
] })
|
|
6484
6539
|
] }),
|
|
6485
|
-
_optionalChain([result, 'access',
|
|
6540
|
+
_optionalChain([result, 'access', _173 => _173.data, 'optionalAccess', _174 => _174.summary]) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-neutral-700 dark:text-neutral-300 text-sm leading-relaxed whitespace-pre-line", children: result.data.summary }),
|
|
6486
6541
|
result.widgets && result.widgets.length > 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "space-y-3", children: result.widgets.map((widget) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
6487
6542
|
WidgetRenderer,
|
|
6488
6543
|
{
|
|
@@ -6533,7 +6588,7 @@ ${planToExecute}`;
|
|
|
6533
6588
|
enableFileUpload && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
6534
6589
|
"button",
|
|
6535
6590
|
{
|
|
6536
|
-
onClick: () => _optionalChain([fileInputRef, 'access',
|
|
6591
|
+
onClick: () => _optionalChain([fileInputRef, 'access', _175 => _175.current, 'optionalAccess', _176 => _176.click, 'call', _177 => _177()]),
|
|
6537
6592
|
className: "w-8 h-8 rounded-lg flex items-center justify-center transition-all flex-shrink-0 !text-neutral-500 dark:!text-neutral-500 hover:bg-neutral-100 dark:hover:bg-neutral-800",
|
|
6538
6593
|
title: "Attach file",
|
|
6539
6594
|
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M8.4 2.8L4.4 6.8C3.736 7.464 3.736 8.536 4.4 9.2C5.064 9.864 6.136 9.864 6.8 9.2L11.6 4.4C12.704 3.296 12.704 1.504 11.6 0.4C10.496 -0.704 8.704 -0.704 7.6 0.4L2.8 5.2C1.256 6.744 1.256 9.256 2.8 10.8C4.344 12.344 6.856 12.344 8.4 10.8L12.4 6.8", stroke: "currentColor", strokeWidth: "1.2", strokeLinecap: "round", strokeLinejoin: "round", transform: "translate(1.6, 2.4)" }) })
|
|
@@ -6719,25 +6774,25 @@ function Prompt({
|
|
|
6719
6774
|
const newValue = e.target.value;
|
|
6720
6775
|
if (!maxLength || newValue.length <= maxLength) {
|
|
6721
6776
|
setValue(newValue);
|
|
6722
|
-
_optionalChain([onChange, 'optionalCall',
|
|
6777
|
+
_optionalChain([onChange, 'optionalCall', _178 => _178(newValue)]);
|
|
6723
6778
|
}
|
|
6724
6779
|
};
|
|
6725
6780
|
const handleSubmit = async () => {
|
|
6726
6781
|
if (value.length < minLength) return;
|
|
6727
|
-
_optionalChain([onSubmit, 'optionalCall',
|
|
6782
|
+
_optionalChain([onSubmit, 'optionalCall', _179 => _179(value)]);
|
|
6728
6783
|
setIsLoading(true);
|
|
6729
6784
|
try {
|
|
6730
6785
|
if (useMock) {
|
|
6731
6786
|
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
6732
6787
|
const mockResult = `Enhanced version: ${value} [AI-generated content]`;
|
|
6733
|
-
_optionalChain([onResult, 'optionalCall',
|
|
6788
|
+
_optionalChain([onResult, 'optionalCall', _180 => _180(mockResult)]);
|
|
6734
6789
|
setValue("");
|
|
6735
6790
|
} else {
|
|
6736
6791
|
const response = await aptevaClient.chat({
|
|
6737
6792
|
agent_id: agentId,
|
|
6738
6793
|
message: value
|
|
6739
6794
|
});
|
|
6740
|
-
_optionalChain([onResult, 'optionalCall',
|
|
6795
|
+
_optionalChain([onResult, 'optionalCall', _181 => _181(response.message)]);
|
|
6741
6796
|
setValue("");
|
|
6742
6797
|
}
|
|
6743
6798
|
} catch (error) {
|
|
@@ -6832,7 +6887,7 @@ function Stream({
|
|
|
6832
6887
|
}, [autoStart]);
|
|
6833
6888
|
const startStreaming = async () => {
|
|
6834
6889
|
setIsStreaming(true);
|
|
6835
|
-
_optionalChain([onStart, 'optionalCall',
|
|
6890
|
+
_optionalChain([onStart, 'optionalCall', _182 => _182()]);
|
|
6836
6891
|
try {
|
|
6837
6892
|
if (useMock) {
|
|
6838
6893
|
const mockText = "This is a simulated streaming response from the AI agent. In a real implementation, this would stream data from your backend API. The text appears word by word to simulate the streaming effect. You can customize the typing speed and styling based on your needs.";
|
|
@@ -6840,13 +6895,13 @@ function Stream({
|
|
|
6840
6895
|
mockText,
|
|
6841
6896
|
(chunk) => {
|
|
6842
6897
|
setText((prev) => prev + chunk);
|
|
6843
|
-
_optionalChain([onChunk, 'optionalCall',
|
|
6898
|
+
_optionalChain([onChunk, 'optionalCall', _183 => _183(chunk)]);
|
|
6844
6899
|
},
|
|
6845
6900
|
typingSpeed
|
|
6846
6901
|
);
|
|
6847
6902
|
setIsComplete(true);
|
|
6848
6903
|
setIsStreaming(false);
|
|
6849
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
6904
|
+
_optionalChain([onComplete, 'optionalCall', _184 => _184(text + mockText)]);
|
|
6850
6905
|
} else {
|
|
6851
6906
|
let accumulatedText = "";
|
|
6852
6907
|
await aptevaClient.chatStream(
|
|
@@ -6859,24 +6914,24 @@ function Stream({
|
|
|
6859
6914
|
if (chunk.type === "token" && chunk.content) {
|
|
6860
6915
|
accumulatedText += chunk.content;
|
|
6861
6916
|
setText(accumulatedText);
|
|
6862
|
-
_optionalChain([onChunk, 'optionalCall',
|
|
6917
|
+
_optionalChain([onChunk, 'optionalCall', _185 => _185(chunk.content)]);
|
|
6863
6918
|
}
|
|
6864
6919
|
},
|
|
6865
6920
|
() => {
|
|
6866
6921
|
setIsComplete(true);
|
|
6867
6922
|
setIsStreaming(false);
|
|
6868
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
6923
|
+
_optionalChain([onComplete, 'optionalCall', _186 => _186(accumulatedText)]);
|
|
6869
6924
|
},
|
|
6870
6925
|
(error) => {
|
|
6871
6926
|
const err = error instanceof Error ? error : new Error("Streaming error");
|
|
6872
|
-
_optionalChain([onError, 'optionalCall',
|
|
6927
|
+
_optionalChain([onError, 'optionalCall', _187 => _187(err)]);
|
|
6873
6928
|
setIsStreaming(false);
|
|
6874
6929
|
}
|
|
6875
6930
|
);
|
|
6876
6931
|
}
|
|
6877
6932
|
} catch (error) {
|
|
6878
6933
|
const err = error instanceof Error ? error : new Error("Streaming error");
|
|
6879
|
-
_optionalChain([onError, 'optionalCall',
|
|
6934
|
+
_optionalChain([onError, 'optionalCall', _188 => _188(err)]);
|
|
6880
6935
|
setIsStreaming(false);
|
|
6881
6936
|
}
|
|
6882
6937
|
};
|
|
@@ -6968,7 +7023,7 @@ function ThreadList({
|
|
|
6968
7023
|
}) {
|
|
6969
7024
|
const [searchQuery, setSearchQuery] = _react.useState.call(void 0, "");
|
|
6970
7025
|
const filteredThreads = threads.filter(
|
|
6971
|
-
(thread) => thread.title.toLowerCase().includes(searchQuery.toLowerCase()) || _optionalChain([thread, 'access',
|
|
7026
|
+
(thread) => thread.title.toLowerCase().includes(searchQuery.toLowerCase()) || _optionalChain([thread, 'access', _189 => _189.preview, 'optionalAccess', _190 => _190.toLowerCase, 'call', _191 => _191(), 'access', _192 => _192.includes, 'call', _193 => _193(searchQuery.toLowerCase())])
|
|
6972
7027
|
);
|
|
6973
7028
|
const groupedThreads = groupBy === "date" ? groupThreadsByDate(filteredThreads) : { All: filteredThreads };
|
|
6974
7029
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col h-full", children: [
|
|
@@ -6990,8 +7045,8 @@ function ThreadList({
|
|
|
6990
7045
|
{
|
|
6991
7046
|
thread,
|
|
6992
7047
|
isActive: thread.id === currentThreadId,
|
|
6993
|
-
onSelect: () => _optionalChain([onThreadSelect, 'optionalCall',
|
|
6994
|
-
onDelete: () => _optionalChain([onThreadDelete, 'optionalCall',
|
|
7048
|
+
onSelect: () => _optionalChain([onThreadSelect, 'optionalCall', _194 => _194(thread.id)]),
|
|
7049
|
+
onDelete: () => _optionalChain([onThreadDelete, 'optionalCall', _195 => _195(thread.id)])
|
|
6995
7050
|
},
|
|
6996
7051
|
thread.id
|
|
6997
7052
|
))
|
|
@@ -7053,7 +7108,7 @@ function Threads({
|
|
|
7053
7108
|
threads.slice(0, 5).map((thread) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
7054
7109
|
"button",
|
|
7055
7110
|
{
|
|
7056
|
-
onClick: () => _optionalChain([onThreadSelect, 'optionalCall',
|
|
7111
|
+
onClick: () => _optionalChain([onThreadSelect, 'optionalCall', _196 => _196(thread.id)]),
|
|
7057
7112
|
className: cn(
|
|
7058
7113
|
"px-4 py-2 whitespace-nowrap font-medium transition-colors",
|
|
7059
7114
|
thread.id === currentThreadId ? "border-b-2 border-apteva-500 text-apteva-500" : "text-neutral-600 hover:text-neutral-900"
|
|
@@ -7238,7 +7293,7 @@ function TabsLayout({ node, renderNode }) {
|
|
|
7238
7293
|
var STRUCTURAL_KEYS = /* @__PURE__ */ new Set(["type", "id", "layout", "props", "children", "actions", "metadata", "isStreaming"]);
|
|
7239
7294
|
function normalizeNode(n) {
|
|
7240
7295
|
let node = { ...n };
|
|
7241
|
-
if (node.type === "widget" && _optionalChain([node, 'access',
|
|
7296
|
+
if (node.type === "widget" && _optionalChain([node, 'access', _197 => _197.props, 'optionalAccess', _198 => _198.widget])) {
|
|
7242
7297
|
node.type = node.props.widget;
|
|
7243
7298
|
const { widget: _, ...rest } = node.props;
|
|
7244
7299
|
node.props = rest;
|
|
@@ -7376,10 +7431,10 @@ function AutoInterface({
|
|
|
7376
7431
|
].filter(Boolean).join("\n\n");
|
|
7377
7432
|
const updateInterface = _react.useCallback.call(void 0, (newSpec) => {
|
|
7378
7433
|
setInterfaceSpec(newSpec);
|
|
7379
|
-
_optionalChain([onInterfaceChange, 'optionalCall',
|
|
7434
|
+
_optionalChain([onInterfaceChange, 'optionalCall', _199 => _199(newSpec)]);
|
|
7380
7435
|
}, [onInterfaceChange]);
|
|
7381
7436
|
const handleAction = _react.useCallback.call(void 0, (action) => {
|
|
7382
|
-
_optionalChain([onAction, 'optionalCall',
|
|
7437
|
+
_optionalChain([onAction, 'optionalCall', _200 => _200(action)]);
|
|
7383
7438
|
if (chatRef.current) {
|
|
7384
7439
|
chatRef.current.sendMessage(
|
|
7385
7440
|
`[Action: ${action.type} on widget ${action.widgetId || "unknown"}. Payload: ${JSON.stringify(action.payload)}]`
|
|
@@ -7387,7 +7442,7 @@ function AutoInterface({
|
|
|
7387
7442
|
}
|
|
7388
7443
|
}, [onAction]);
|
|
7389
7444
|
const handleMessageComplete = _react.useCallback.call(void 0, (result) => {
|
|
7390
|
-
if (!_optionalChain([result, 'optionalAccess',
|
|
7445
|
+
if (!_optionalChain([result, 'optionalAccess', _201 => _201.data])) return;
|
|
7391
7446
|
const text = typeof result.data === "string" ? result.data : result.data.message || "";
|
|
7392
7447
|
console.log("[AutoInterface] Chat message complete, text (" + text.length + " chars):", text.substring(0, 300));
|
|
7393
7448
|
const parsed = parseInterfaceFromText(text);
|
|
@@ -7427,7 +7482,7 @@ function AutoInterface({
|
|
|
7427
7482
|
}).catch((err) => {
|
|
7428
7483
|
if (cancelled) return;
|
|
7429
7484
|
console.error("[AutoInterface] Initial generation failed:", err);
|
|
7430
|
-
_optionalChain([onError, 'optionalCall',
|
|
7485
|
+
_optionalChain([onError, 'optionalCall', _202 => _202(err instanceof Error ? err : new Error(String(err)))]);
|
|
7431
7486
|
setIsGenerating(false);
|
|
7432
7487
|
});
|
|
7433
7488
|
return () => {
|
|
@@ -7593,7 +7648,7 @@ function useInterfaceAI({
|
|
|
7593
7648
|
}
|
|
7594
7649
|
const sendMessage = _react.useCallback.call(void 0, async (message) => {
|
|
7595
7650
|
accumulatedTextRef.current = "";
|
|
7596
|
-
_optionalChain([onStreamStart, 'optionalCall',
|
|
7651
|
+
_optionalChain([onStreamStart, 'optionalCall', _203 => _203()]);
|
|
7597
7652
|
const systemPrompt = [
|
|
7598
7653
|
generateInterfaceContext(),
|
|
7599
7654
|
context || ""
|
|
@@ -7616,27 +7671,27 @@ function useInterfaceAI({
|
|
|
7616
7671
|
accumulatedTextRef.current += chunk.content || "";
|
|
7617
7672
|
const parsed = parseInterfaceFromText(accumulatedTextRef.current);
|
|
7618
7673
|
if (parsed) {
|
|
7619
|
-
_optionalChain([onInterface, 'optionalCall',
|
|
7674
|
+
_optionalChain([onInterface, 'optionalCall', _204 => _204(parsed)]);
|
|
7620
7675
|
}
|
|
7621
7676
|
const updates = parseUpdatesFromText(accumulatedTextRef.current);
|
|
7622
7677
|
if (updates.length > 0) {
|
|
7623
|
-
_optionalChain([onUpdates, 'optionalCall',
|
|
7678
|
+
_optionalChain([onUpdates, 'optionalCall', _205 => _205(updates)]);
|
|
7624
7679
|
}
|
|
7625
7680
|
}
|
|
7626
7681
|
},
|
|
7627
7682
|
// onComplete
|
|
7628
7683
|
() => {
|
|
7629
|
-
_optionalChain([onStreamEnd, 'optionalCall',
|
|
7684
|
+
_optionalChain([onStreamEnd, 'optionalCall', _206 => _206()]);
|
|
7630
7685
|
},
|
|
7631
7686
|
// onError
|
|
7632
7687
|
(error) => {
|
|
7633
|
-
_optionalChain([onError, 'optionalCall',
|
|
7634
|
-
_optionalChain([onStreamEnd, 'optionalCall',
|
|
7688
|
+
_optionalChain([onError, 'optionalCall', _207 => _207(error)]);
|
|
7689
|
+
_optionalChain([onStreamEnd, 'optionalCall', _208 => _208()]);
|
|
7635
7690
|
}
|
|
7636
7691
|
);
|
|
7637
7692
|
} catch (error) {
|
|
7638
|
-
_optionalChain([onError, 'optionalCall',
|
|
7639
|
-
_optionalChain([onStreamEnd, 'optionalCall',
|
|
7693
|
+
_optionalChain([onError, 'optionalCall', _209 => _209(error instanceof Error ? error : new Error("Unknown error"))]);
|
|
7694
|
+
_optionalChain([onStreamEnd, 'optionalCall', _210 => _210()]);
|
|
7640
7695
|
}
|
|
7641
7696
|
}, [agentId, context, onInterface, onUpdates, onError, onStreamStart, onStreamEnd]);
|
|
7642
7697
|
return {
|