@apteva/apteva-kit 0.1.136 → 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 +202 -116
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +115 -29
- 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,6 +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;
|
|
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);
|
|
4494
4482
|
const cleanup = _react.useCallback.call(void 0, () => {
|
|
4495
4483
|
if (durationIntervalRef.current) {
|
|
4496
4484
|
clearInterval(durationIntervalRef.current);
|
|
@@ -4527,10 +4515,26 @@ function useVoiceSession(config) {
|
|
|
4527
4515
|
}
|
|
4528
4516
|
nextPlayTimeRef.current = 0;
|
|
4529
4517
|
mutedRef.current = false;
|
|
4518
|
+
activeSourcesRef.current = [];
|
|
4519
|
+
responseStartTimeRef.current = 0;
|
|
4520
|
+
totalAudioDurationMsRef.current = 0;
|
|
4521
|
+
interruptedRef.current = false;
|
|
4530
4522
|
setMuted(false);
|
|
4531
4523
|
setPartialTranscript("");
|
|
4532
4524
|
setDuration(0);
|
|
4533
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
|
+
}, []);
|
|
4534
4538
|
_react.useEffect.call(void 0, () => {
|
|
4535
4539
|
return () => {
|
|
4536
4540
|
cleanup();
|
|
@@ -4550,10 +4554,18 @@ function useVoiceSession(config) {
|
|
|
4550
4554
|
const source = ctx.createBufferSource();
|
|
4551
4555
|
source.buffer = audioBuffer;
|
|
4552
4556
|
source.connect(ctx.destination);
|
|
4557
|
+
activeSourcesRef.current.push(source);
|
|
4558
|
+
source.onended = () => {
|
|
4559
|
+
activeSourcesRef.current = activeSourcesRef.current.filter((s) => s !== source);
|
|
4560
|
+
};
|
|
4553
4561
|
const currentTime = ctx.currentTime;
|
|
4554
4562
|
const startTime = Math.max(currentTime, nextPlayTimeRef.current);
|
|
4555
4563
|
source.start(startTime);
|
|
4556
4564
|
nextPlayTimeRef.current = startTime + audioBuffer.duration;
|
|
4565
|
+
if (responseStartTimeRef.current === 0) {
|
|
4566
|
+
responseStartTimeRef.current = startTime;
|
|
4567
|
+
}
|
|
4568
|
+
totalAudioDurationMsRef.current += Math.floor(audioBuffer.duration * 1e3);
|
|
4557
4569
|
}, []);
|
|
4558
4570
|
const startCaptureRef = _react.useRef.call(void 0, () => {
|
|
4559
4571
|
});
|
|
@@ -4569,17 +4581,50 @@ function useVoiceSession(config) {
|
|
|
4569
4581
|
startCaptureRef.current();
|
|
4570
4582
|
break;
|
|
4571
4583
|
case "audio_delta":
|
|
4584
|
+
if (interruptedRef.current) break;
|
|
4572
4585
|
if (_optionalChain([msg, 'access', _93 => _93.data, 'optionalAccess', _94 => _94.chunk])) {
|
|
4573
4586
|
playAudioChunk(msg.data.chunk);
|
|
4574
4587
|
}
|
|
4575
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
|
+
}
|
|
4576
4621
|
case "transcript":
|
|
4577
4622
|
if (msg.data) {
|
|
4578
4623
|
if (msg.data.partial) {
|
|
4579
4624
|
setPartialTranscript(msg.data.content);
|
|
4580
4625
|
} else {
|
|
4581
4626
|
setPartialTranscript("");
|
|
4582
|
-
_optionalChain([cfg, 'access',
|
|
4627
|
+
_optionalChain([cfg, 'access', _99 => _99.onTranscript, 'optionalCall', _100 => _100({
|
|
4583
4628
|
id: `vt-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
|
|
4584
4629
|
role: msg.data.role,
|
|
4585
4630
|
content: msg.data.content,
|
|
@@ -4591,8 +4636,8 @@ function useVoiceSession(config) {
|
|
|
4591
4636
|
break;
|
|
4592
4637
|
case "tool_call":
|
|
4593
4638
|
if (msg.data) {
|
|
4594
|
-
|
|
4595
|
-
_optionalChain([cfg, 'access',
|
|
4639
|
+
resetPlayback();
|
|
4640
|
+
_optionalChain([cfg, 'access', _101 => _101.onTranscript, 'optionalCall', _102 => _102({
|
|
4596
4641
|
id: `vt-tool-${Date.now()}`,
|
|
4597
4642
|
role: "system",
|
|
4598
4643
|
content: `Using ${msg.data.name}...`,
|
|
@@ -4603,43 +4648,78 @@ function useVoiceSession(config) {
|
|
|
4603
4648
|
break;
|
|
4604
4649
|
case "tool_result":
|
|
4605
4650
|
if (msg.data) {
|
|
4606
|
-
|
|
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
|
+
})]);
|
|
4607
4659
|
}
|
|
4608
4660
|
break;
|
|
4661
|
+
case "turn_end":
|
|
4662
|
+
interruptedRef.current = false;
|
|
4663
|
+
break;
|
|
4609
4664
|
case "error":
|
|
4610
4665
|
setState("error");
|
|
4611
|
-
_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"))]);
|
|
4612
4667
|
break;
|
|
4613
4668
|
}
|
|
4614
|
-
}, [playAudioChunk]);
|
|
4669
|
+
}, [playAudioChunk, resetPlayback]);
|
|
4615
4670
|
const startCapture = _react.useCallback.call(void 0, async () => {
|
|
4616
4671
|
const ws = wsRef.current;
|
|
4617
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
|
+
}
|
|
4618
4688
|
try {
|
|
4619
|
-
captureCtxRef.current = new AudioContext();
|
|
4620
|
-
|
|
4621
|
-
|
|
4689
|
+
captureCtxRef.current = new AudioContext({ sampleRate: 24e3 });
|
|
4690
|
+
if (captureCtxRef.current.state === "suspended") {
|
|
4691
|
+
await captureCtxRef.current.resume();
|
|
4692
|
+
}
|
|
4693
|
+
mediaStreamRef.current = await navigator.mediaDevices.getUserMedia({
|
|
4694
|
+
audio: {
|
|
4695
|
+
echoCancellation: true,
|
|
4696
|
+
noiseSuppression: true,
|
|
4697
|
+
autoGainControl: true
|
|
4698
|
+
}
|
|
4699
|
+
});
|
|
4622
4700
|
const source = captureCtxRef.current.createMediaStreamSource(mediaStreamRef.current);
|
|
4623
|
-
processorRef.current = captureCtxRef.current.createScriptProcessor(
|
|
4701
|
+
processorRef.current = captureCtxRef.current.createScriptProcessor(4096, 1, 1);
|
|
4624
4702
|
processorRef.current.onaudioprocess = (e) => {
|
|
4625
4703
|
if (!ws || ws.readyState !== WebSocket.OPEN) return;
|
|
4626
4704
|
if (mutedRef.current) return;
|
|
4627
4705
|
const inputData = e.inputBuffer.getChannelData(0);
|
|
4628
|
-
const
|
|
4629
|
-
const int16Data = float32ToInt16(resampledData);
|
|
4706
|
+
const int16Data = float32ToInt16(inputData);
|
|
4630
4707
|
const base64Data = int16ToBase64(int16Data);
|
|
4631
4708
|
ws.send(JSON.stringify({
|
|
4632
4709
|
type: "audio",
|
|
4633
|
-
data: { chunk: base64Data }
|
|
4710
|
+
data: { chunk: base64Data, sample_rate: 24e3 }
|
|
4634
4711
|
}));
|
|
4635
4712
|
};
|
|
4636
4713
|
source.connect(processorRef.current);
|
|
4637
|
-
|
|
4714
|
+
const silentGain = captureCtxRef.current.createGain();
|
|
4715
|
+
silentGain.gain.value = 0;
|
|
4716
|
+
processorRef.current.connect(silentGain);
|
|
4717
|
+
silentGain.connect(captureCtxRef.current.destination);
|
|
4638
4718
|
} catch (e) {
|
|
4639
4719
|
console.warn("Microphone access denied:", e);
|
|
4640
|
-
_optionalChain([configRef, 'access',
|
|
4720
|
+
_optionalChain([configRef, 'access', _109 => _109.current, 'access', _110 => _110.onError, 'optionalCall', _111 => _111(new Error("Microphone access denied"))]);
|
|
4641
4721
|
}
|
|
4642
|
-
}, [
|
|
4722
|
+
}, []);
|
|
4643
4723
|
startCaptureRef.current = startCapture;
|
|
4644
4724
|
const start = _react.useCallback.call(void 0, () => {
|
|
4645
4725
|
if (state !== "idle") return;
|
|
@@ -4656,6 +4736,12 @@ function useVoiceSession(config) {
|
|
|
4656
4736
|
}
|
|
4657
4737
|
const ws = new WebSocket(wsUrl);
|
|
4658
4738
|
wsRef.current = ws;
|
|
4739
|
+
if (!playbackCtxRef.current) {
|
|
4740
|
+
playbackCtxRef.current = new AudioContext({ sampleRate: 24e3 });
|
|
4741
|
+
}
|
|
4742
|
+
if (playbackCtxRef.current.state === "suspended") {
|
|
4743
|
+
playbackCtxRef.current.resume();
|
|
4744
|
+
}
|
|
4659
4745
|
ws.onopen = () => {
|
|
4660
4746
|
const provider = configRef.current.provider || "openai";
|
|
4661
4747
|
const voice = configRef.current.voice || "ash";
|
|
@@ -4673,13 +4759,13 @@ function useVoiceSession(config) {
|
|
|
4673
4759
|
};
|
|
4674
4760
|
ws.onerror = () => {
|
|
4675
4761
|
setState("error");
|
|
4676
|
-
_optionalChain([configRef, 'access',
|
|
4762
|
+
_optionalChain([configRef, 'access', _112 => _112.current, 'access', _113 => _113.onError, 'optionalCall', _114 => _114(new Error("WebSocket connection failed"))]);
|
|
4677
4763
|
};
|
|
4678
4764
|
ws.onclose = () => {
|
|
4679
4765
|
cleanup();
|
|
4680
4766
|
setState("idle");
|
|
4681
4767
|
};
|
|
4682
|
-
}, [state, config.apiUrl, handleMessage, cleanup]);
|
|
4768
|
+
}, [state, config.apiUrl, config.apiKey, handleMessage, cleanup]);
|
|
4683
4769
|
const stop = _react.useCallback.call(void 0, () => {
|
|
4684
4770
|
cleanup();
|
|
4685
4771
|
setState("idle");
|
|
@@ -4853,7 +4939,7 @@ ${widgetContext}` : widgetContext;
|
|
|
4853
4939
|
}, [apiUrl, apiKey]);
|
|
4854
4940
|
_react.useEffect.call(void 0, () => {
|
|
4855
4941
|
if (threadId) {
|
|
4856
|
-
_optionalChain([onThreadChange, 'optionalCall',
|
|
4942
|
+
_optionalChain([onThreadChange, 'optionalCall', _115 => _115(threadId)]);
|
|
4857
4943
|
}
|
|
4858
4944
|
}, [threadId, onThreadChange]);
|
|
4859
4945
|
_react.useEffect.call(void 0, () => {
|
|
@@ -4871,7 +4957,7 @@ ${widgetContext}` : widgetContext;
|
|
|
4871
4957
|
}, [showSettingsMenu]);
|
|
4872
4958
|
const handleModeChange = (newMode) => {
|
|
4873
4959
|
setMode(newMode);
|
|
4874
|
-
_optionalChain([onModeChange, 'optionalCall',
|
|
4960
|
+
_optionalChain([onModeChange, 'optionalCall', _116 => _116(newMode)]);
|
|
4875
4961
|
if (newMode === "command") {
|
|
4876
4962
|
setCommandState("idle");
|
|
4877
4963
|
setCommandResult(null);
|
|
@@ -4880,8 +4966,8 @@ ${widgetContext}` : widgetContext;
|
|
|
4880
4966
|
};
|
|
4881
4967
|
const defaultPlaceholder = mode === "chat" ? "Type a message..." : "Enter your command...";
|
|
4882
4968
|
const handleWidgetAction = _react.useCallback.call(void 0, (action) => {
|
|
4883
|
-
_optionalChain([onAction, 'optionalCall',
|
|
4884
|
-
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])) {
|
|
4885
4971
|
const formData = action.payload.formData;
|
|
4886
4972
|
const lines = [];
|
|
4887
4973
|
for (const [key, value] of Object.entries(formData)) {
|
|
@@ -4920,7 +5006,7 @@ ${widgetContext}` : widgetContext;
|
|
|
4920
5006
|
metadata: hasFiles ? { attachments } : void 0
|
|
4921
5007
|
};
|
|
4922
5008
|
setMessages((prev) => [...prev, userMessage]);
|
|
4923
|
-
_optionalChain([onMessageSent, 'optionalCall',
|
|
5009
|
+
_optionalChain([onMessageSent, 'optionalCall', _120 => _120(userMessage)]);
|
|
4924
5010
|
}
|
|
4925
5011
|
setIsLoading(true);
|
|
4926
5012
|
try {
|
|
@@ -4988,7 +5074,7 @@ ${widgetContext}` : widgetContext;
|
|
|
4988
5074
|
responseThreadId = chunk.thread_id;
|
|
4989
5075
|
if (!currentThreadId) {
|
|
4990
5076
|
setCurrentThreadId(chunk.thread_id);
|
|
4991
|
-
_optionalChain([onThreadChange, 'optionalCall',
|
|
5077
|
+
_optionalChain([onThreadChange, 'optionalCall', _121 => _121(chunk.thread_id)]);
|
|
4992
5078
|
}
|
|
4993
5079
|
}
|
|
4994
5080
|
break;
|
|
@@ -5020,7 +5106,7 @@ ${widgetContext}` : widgetContext;
|
|
|
5020
5106
|
contentSegments.push({ type: "tool", id: chunk.tool_id, name: displayName, status: "preparing" });
|
|
5021
5107
|
toolInputBuffers[chunk.tool_id] = "";
|
|
5022
5108
|
setChatToolName(displayName);
|
|
5023
|
-
_optionalChain([onToolCall, 'optionalCall',
|
|
5109
|
+
_optionalChain([onToolCall, 'optionalCall', _122 => _122(chunk.tool_name, chunk.tool_id)]);
|
|
5024
5110
|
updateMessage();
|
|
5025
5111
|
}
|
|
5026
5112
|
break;
|
|
@@ -5080,7 +5166,7 @@ ${widgetContext}` : widgetContext;
|
|
|
5080
5166
|
toolSegment.result = chunk.content;
|
|
5081
5167
|
toolSegment.status = "completed";
|
|
5082
5168
|
toolSegment.isReceiving = false;
|
|
5083
|
-
_optionalChain([onToolResult, 'optionalCall',
|
|
5169
|
+
_optionalChain([onToolResult, 'optionalCall', _123 => _123(toolSegment.name, chunk.content)]);
|
|
5084
5170
|
}
|
|
5085
5171
|
setChatToolName(null);
|
|
5086
5172
|
updateMessage();
|
|
@@ -5124,7 +5210,7 @@ ${widgetContext}` : widgetContext;
|
|
|
5124
5210
|
});
|
|
5125
5211
|
if (threadId2 && threadId2 !== currentThreadId) {
|
|
5126
5212
|
setCurrentThreadId(threadId2);
|
|
5127
|
-
_optionalChain([onThreadChange, 'optionalCall',
|
|
5213
|
+
_optionalChain([onThreadChange, 'optionalCall', _124 => _124(threadId2)]);
|
|
5128
5214
|
}
|
|
5129
5215
|
setIsLoading(false);
|
|
5130
5216
|
setCurrentRequestId(null);
|
|
@@ -5148,7 +5234,7 @@ ${widgetContext}` : widgetContext;
|
|
|
5148
5234
|
setIsLoading(false);
|
|
5149
5235
|
setCurrentRequestId(null);
|
|
5150
5236
|
setChatToolName(null);
|
|
5151
|
-
_optionalChain([onError, 'optionalCall',
|
|
5237
|
+
_optionalChain([onError, 'optionalCall', _125 => _125(error)]);
|
|
5152
5238
|
}
|
|
5153
5239
|
);
|
|
5154
5240
|
}
|
|
@@ -5161,7 +5247,7 @@ ${widgetContext}` : widgetContext;
|
|
|
5161
5247
|
metadata: { error: true }
|
|
5162
5248
|
};
|
|
5163
5249
|
setMessages((prev) => [...prev, errorMessage]);
|
|
5164
|
-
_optionalChain([onError, 'optionalCall',
|
|
5250
|
+
_optionalChain([onError, 'optionalCall', _126 => _126(error instanceof Error ? error : new Error("Unknown error"))]);
|
|
5165
5251
|
} finally {
|
|
5166
5252
|
setIsLoading(false);
|
|
5167
5253
|
}
|
|
@@ -5207,7 +5293,7 @@ ${planningInstruction}` : planningInstruction;
|
|
|
5207
5293
|
const error = err instanceof Error ? err : new Error("Failed to generate plan");
|
|
5208
5294
|
setCommandError(error);
|
|
5209
5295
|
setCommandState("error");
|
|
5210
|
-
_optionalChain([onError, 'optionalCall',
|
|
5296
|
+
_optionalChain([onError, 'optionalCall', _127 => _127(error)]);
|
|
5211
5297
|
}
|
|
5212
5298
|
}
|
|
5213
5299
|
return;
|
|
@@ -5240,12 +5326,12 @@ ${planningInstruction}` : planningInstruction;
|
|
|
5240
5326
|
setCommandResult(result);
|
|
5241
5327
|
setCommandState("success");
|
|
5242
5328
|
setProgress(100);
|
|
5243
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
5329
|
+
_optionalChain([onComplete, 'optionalCall', _128 => _128(result)]);
|
|
5244
5330
|
},
|
|
5245
5331
|
(error) => {
|
|
5246
5332
|
setCommandError(error);
|
|
5247
5333
|
setCommandState("error");
|
|
5248
|
-
_optionalChain([onError, 'optionalCall',
|
|
5334
|
+
_optionalChain([onError, 'optionalCall', _129 => _129(error)]);
|
|
5249
5335
|
}
|
|
5250
5336
|
);
|
|
5251
5337
|
} else {
|
|
@@ -5258,7 +5344,7 @@ ${planningInstruction}` : planningInstruction;
|
|
|
5258
5344
|
setCommandResult(result);
|
|
5259
5345
|
setCommandState("success");
|
|
5260
5346
|
setProgress(100);
|
|
5261
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
5347
|
+
_optionalChain([onComplete, 'optionalCall', _130 => _130(result)]);
|
|
5262
5348
|
}
|
|
5263
5349
|
} else {
|
|
5264
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.`;
|
|
@@ -5288,16 +5374,16 @@ ${commandInstruction}` : commandInstruction;
|
|
|
5288
5374
|
const displayName = chunk.tool_display_name || chunk.tool_name;
|
|
5289
5375
|
lastToolName = chunk.tool_name;
|
|
5290
5376
|
setCurrentToolName(displayName);
|
|
5291
|
-
_optionalChain([onToolCall, 'optionalCall',
|
|
5377
|
+
_optionalChain([onToolCall, 'optionalCall', _131 => _131(chunk.tool_name, chunk.tool_id || "")]);
|
|
5292
5378
|
accumulatedContent = "";
|
|
5293
5379
|
setStreamedContent("");
|
|
5294
5380
|
} else if (chunk.type === "tool_result") {
|
|
5295
|
-
_optionalChain([onToolResult, 'optionalCall',
|
|
5381
|
+
_optionalChain([onToolResult, 'optionalCall', _132 => _132(lastToolName, chunk.content)]);
|
|
5296
5382
|
setCurrentToolName(null);
|
|
5297
5383
|
} else if (chunk.type === "thread_id" && chunk.thread_id) {
|
|
5298
5384
|
if (!currentThreadId) {
|
|
5299
5385
|
setCurrentThreadId(chunk.thread_id);
|
|
5300
|
-
_optionalChain([onThreadChange, 'optionalCall',
|
|
5386
|
+
_optionalChain([onThreadChange, 'optionalCall', _133 => _133(chunk.thread_id)]);
|
|
5301
5387
|
}
|
|
5302
5388
|
} else if (chunk.type === "request_id" && chunk.request_id) {
|
|
5303
5389
|
setCurrentRequestId(chunk.request_id);
|
|
@@ -5313,13 +5399,13 @@ ${commandInstruction}` : commandInstruction;
|
|
|
5313
5399
|
setCommandState("success");
|
|
5314
5400
|
setProgress(100);
|
|
5315
5401
|
setCurrentRequestId(null);
|
|
5316
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
5402
|
+
_optionalChain([onComplete, 'optionalCall', _134 => _134(result)]);
|
|
5317
5403
|
},
|
|
5318
5404
|
(error) => {
|
|
5319
5405
|
setCommandError(error);
|
|
5320
5406
|
setCommandState("error");
|
|
5321
5407
|
setCurrentRequestId(null);
|
|
5322
|
-
_optionalChain([onError, 'optionalCall',
|
|
5408
|
+
_optionalChain([onError, 'optionalCall', _135 => _135(error)]);
|
|
5323
5409
|
}
|
|
5324
5410
|
);
|
|
5325
5411
|
} else {
|
|
@@ -5339,14 +5425,14 @@ ${commandInstruction}` : commandInstruction;
|
|
|
5339
5425
|
setCommandResult(result);
|
|
5340
5426
|
setCommandState("success");
|
|
5341
5427
|
setProgress(100);
|
|
5342
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
5428
|
+
_optionalChain([onComplete, 'optionalCall', _136 => _136(result)]);
|
|
5343
5429
|
}
|
|
5344
5430
|
}
|
|
5345
5431
|
} catch (err) {
|
|
5346
5432
|
const error = err instanceof Error ? err : new Error("Unknown error");
|
|
5347
5433
|
setCommandError(error);
|
|
5348
5434
|
setCommandState("error");
|
|
5349
|
-
_optionalChain([onError, 'optionalCall',
|
|
5435
|
+
_optionalChain([onError, 'optionalCall', _137 => _137(error)]);
|
|
5350
5436
|
}
|
|
5351
5437
|
};
|
|
5352
5438
|
const resetCommand = () => {
|
|
@@ -5452,8 +5538,8 @@ ${planToExecute}`;
|
|
|
5452
5538
|
executeCommand(text, files);
|
|
5453
5539
|
},
|
|
5454
5540
|
state: commandState,
|
|
5455
|
-
response: _optionalChain([commandResult, 'optionalAccess',
|
|
5456
|
-
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]),
|
|
5457
5543
|
plan,
|
|
5458
5544
|
streamedContent,
|
|
5459
5545
|
toolName: currentToolName,
|
|
@@ -5620,7 +5706,7 @@ function Call({
|
|
|
5620
5706
|
const next = [...prev, entry];
|
|
5621
5707
|
return next.length > maxTranscriptEntries ? next.slice(next.length - maxTranscriptEntries) : next;
|
|
5622
5708
|
});
|
|
5623
|
-
_optionalChain([onTranscript, 'optionalCall',
|
|
5709
|
+
_optionalChain([onTranscript, 'optionalCall', _142 => _142(entry)]);
|
|
5624
5710
|
}, [maxTranscriptEntries, onTranscript]);
|
|
5625
5711
|
const voice = useVoiceSession({
|
|
5626
5712
|
apiUrl,
|
|
@@ -5636,10 +5722,10 @@ function Call({
|
|
|
5636
5722
|
_react.useEffect.call(void 0, () => {
|
|
5637
5723
|
const prev = prevStateRef.current;
|
|
5638
5724
|
if (prev !== "active" && voice.state === "active") {
|
|
5639
|
-
_optionalChain([onCallStart, 'optionalCall',
|
|
5725
|
+
_optionalChain([onCallStart, 'optionalCall', _143 => _143()]);
|
|
5640
5726
|
}
|
|
5641
5727
|
if (prev === "active" && voice.state === "idle") {
|
|
5642
|
-
_optionalChain([onCallEnd, 'optionalCall',
|
|
5728
|
+
_optionalChain([onCallEnd, 'optionalCall', _144 => _144({ duration: durationRef.current, transcripts })]);
|
|
5643
5729
|
}
|
|
5644
5730
|
prevStateRef.current = voice.state;
|
|
5645
5731
|
}, [voice.state, onCallStart, onCallEnd, transcripts]);
|
|
@@ -5650,7 +5736,7 @@ function Call({
|
|
|
5650
5736
|
}
|
|
5651
5737
|
}, [autoStart, voice.state, voice.start]);
|
|
5652
5738
|
_react.useEffect.call(void 0, () => {
|
|
5653
|
-
_optionalChain([onMuteChange, 'optionalCall',
|
|
5739
|
+
_optionalChain([onMuteChange, 'optionalCall', _145 => _145(voice.muted)]);
|
|
5654
5740
|
}, [voice.muted, onMuteChange]);
|
|
5655
5741
|
const cn2 = [
|
|
5656
5742
|
"apteva-call",
|
|
@@ -5826,13 +5912,13 @@ ${planningInstruction}` : planningInstruction;
|
|
|
5826
5912
|
const error2 = err instanceof Error ? err : new Error("Failed to generate plan");
|
|
5827
5913
|
setError(error2);
|
|
5828
5914
|
setState("error");
|
|
5829
|
-
_optionalChain([onError, 'optionalCall',
|
|
5915
|
+
_optionalChain([onError, 'optionalCall', _146 => _146(error2)]);
|
|
5830
5916
|
});
|
|
5831
5917
|
} catch (err) {
|
|
5832
5918
|
const error2 = err instanceof Error ? err : new Error("Failed to generate plan");
|
|
5833
5919
|
setError(error2);
|
|
5834
5920
|
setState("error");
|
|
5835
|
-
_optionalChain([onError, 'optionalCall',
|
|
5921
|
+
_optionalChain([onError, 'optionalCall', _147 => _147(error2)]);
|
|
5836
5922
|
}
|
|
5837
5923
|
}
|
|
5838
5924
|
return;
|
|
@@ -5843,7 +5929,7 @@ ${planningInstruction}` : planningInstruction;
|
|
|
5843
5929
|
setStreamedContent("");
|
|
5844
5930
|
setCommand("");
|
|
5845
5931
|
setUploadedFiles([]);
|
|
5846
|
-
_optionalChain([onStart, 'optionalCall',
|
|
5932
|
+
_optionalChain([onStart, 'optionalCall', _148 => _148()]);
|
|
5847
5933
|
try {
|
|
5848
5934
|
if (useMock) {
|
|
5849
5935
|
if (enableStreaming) {
|
|
@@ -5854,16 +5940,16 @@ ${planningInstruction}` : planningInstruction;
|
|
|
5854
5940
|
if (chunk.type === "token" && chunk.content) {
|
|
5855
5941
|
accumulatedContent += chunk.content;
|
|
5856
5942
|
setStreamedContent(accumulatedContent);
|
|
5857
|
-
_optionalChain([onChunk, 'optionalCall',
|
|
5943
|
+
_optionalChain([onChunk, 'optionalCall', _149 => _149(chunk.content)]);
|
|
5858
5944
|
const estimatedProgress = Math.min(Math.round(accumulatedContent.length / 10), 90);
|
|
5859
5945
|
setProgress(estimatedProgress);
|
|
5860
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
5946
|
+
_optionalChain([onProgress, 'optionalCall', _150 => _150(estimatedProgress)]);
|
|
5861
5947
|
} else if (chunk.type === "widget" && chunk.widget) {
|
|
5862
5948
|
const widget = chunk.widget;
|
|
5863
5949
|
setResult((prev) => ({
|
|
5864
5950
|
success: true,
|
|
5865
|
-
data: _optionalChain([prev, 'optionalAccess',
|
|
5866
|
-
widgets: [..._optionalChain([prev, 'optionalAccess',
|
|
5951
|
+
data: _optionalChain([prev, 'optionalAccess', _151 => _151.data]) || {},
|
|
5952
|
+
widgets: [..._optionalChain([prev, 'optionalAccess', _152 => _152.widgets]) || [], widget],
|
|
5867
5953
|
message: accumulatedContent || "Command executed successfully"
|
|
5868
5954
|
}));
|
|
5869
5955
|
}
|
|
@@ -5883,19 +5969,19 @@ ${planningInstruction}` : planningInstruction;
|
|
|
5883
5969
|
setResult(result2);
|
|
5884
5970
|
setState("success");
|
|
5885
5971
|
setProgress(100);
|
|
5886
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
5972
|
+
_optionalChain([onComplete, 'optionalCall', _153 => _153(result2)]);
|
|
5887
5973
|
},
|
|
5888
5974
|
(error2) => {
|
|
5889
5975
|
setError(error2);
|
|
5890
5976
|
setState("error");
|
|
5891
|
-
_optionalChain([onError, 'optionalCall',
|
|
5977
|
+
_optionalChain([onError, 'optionalCall', _154 => _154(error2)]);
|
|
5892
5978
|
}
|
|
5893
5979
|
);
|
|
5894
5980
|
} else {
|
|
5895
5981
|
const progressInterval = setInterval(() => {
|
|
5896
5982
|
setProgress((prev) => {
|
|
5897
5983
|
const next = Math.min(prev + 10, 90);
|
|
5898
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
5984
|
+
_optionalChain([onProgress, 'optionalCall', _155 => _155(next)]);
|
|
5899
5985
|
return next;
|
|
5900
5986
|
});
|
|
5901
5987
|
}, 200);
|
|
@@ -5919,7 +6005,7 @@ ${planningInstruction}` : planningInstruction;
|
|
|
5919
6005
|
setResult(result2);
|
|
5920
6006
|
setState("success");
|
|
5921
6007
|
setProgress(100);
|
|
5922
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
6008
|
+
_optionalChain([onComplete, 'optionalCall', _156 => _156(result2)]);
|
|
5923
6009
|
}
|
|
5924
6010
|
} else {
|
|
5925
6011
|
if (enableStreaming) {
|
|
@@ -5965,16 +6051,16 @@ ${commandInstruction}` : commandInstruction;
|
|
|
5965
6051
|
if (chunk.type === "token" && chunk.content) {
|
|
5966
6052
|
accumulatedContent += chunk.content;
|
|
5967
6053
|
setStreamedContent(accumulatedContent);
|
|
5968
|
-
_optionalChain([onChunk, 'optionalCall',
|
|
6054
|
+
_optionalChain([onChunk, 'optionalCall', _157 => _157(chunk.content)]);
|
|
5969
6055
|
const estimatedProgress = Math.min(Math.round(accumulatedContent.length / 10), 90);
|
|
5970
6056
|
setProgress(estimatedProgress);
|
|
5971
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
6057
|
+
_optionalChain([onProgress, 'optionalCall', _158 => _158(estimatedProgress)]);
|
|
5972
6058
|
} else if (chunk.type === "widget" && chunk.widget) {
|
|
5973
6059
|
const widget = chunk.widget;
|
|
5974
6060
|
setResult((prev) => ({
|
|
5975
6061
|
success: true,
|
|
5976
|
-
data: _optionalChain([prev, 'optionalAccess',
|
|
5977
|
-
widgets: [..._optionalChain([prev, 'optionalAccess',
|
|
6062
|
+
data: _optionalChain([prev, 'optionalAccess', _159 => _159.data]) || {},
|
|
6063
|
+
widgets: [..._optionalChain([prev, 'optionalAccess', _160 => _160.widgets]) || [], widget],
|
|
5978
6064
|
message: accumulatedContent || "Command executed successfully"
|
|
5979
6065
|
}));
|
|
5980
6066
|
}
|
|
@@ -5994,20 +6080,20 @@ ${commandInstruction}` : commandInstruction;
|
|
|
5994
6080
|
setResult(result2);
|
|
5995
6081
|
setState("success");
|
|
5996
6082
|
setProgress(100);
|
|
5997
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
6083
|
+
_optionalChain([onComplete, 'optionalCall', _161 => _161(result2)]);
|
|
5998
6084
|
},
|
|
5999
6085
|
(error2) => {
|
|
6000
6086
|
const err = error2 instanceof Error ? error2 : new Error("Unknown error");
|
|
6001
6087
|
setError(err);
|
|
6002
6088
|
setState("error");
|
|
6003
|
-
_optionalChain([onError, 'optionalCall',
|
|
6089
|
+
_optionalChain([onError, 'optionalCall', _162 => _162(err)]);
|
|
6004
6090
|
}
|
|
6005
6091
|
);
|
|
6006
6092
|
} else {
|
|
6007
6093
|
const progressInterval = setInterval(() => {
|
|
6008
6094
|
setProgress((prev) => {
|
|
6009
6095
|
const next = Math.min(prev + 10, 90);
|
|
6010
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
6096
|
+
_optionalChain([onProgress, 'optionalCall', _163 => _163(next)]);
|
|
6011
6097
|
return next;
|
|
6012
6098
|
});
|
|
6013
6099
|
}, 200);
|
|
@@ -6063,14 +6149,14 @@ ${commandInstruction}` : commandInstruction;
|
|
|
6063
6149
|
setResult(result2);
|
|
6064
6150
|
setState("success");
|
|
6065
6151
|
setProgress(100);
|
|
6066
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
6152
|
+
_optionalChain([onComplete, 'optionalCall', _164 => _164(result2)]);
|
|
6067
6153
|
}
|
|
6068
6154
|
}
|
|
6069
6155
|
} catch (err) {
|
|
6070
6156
|
const error2 = err instanceof Error ? err : new Error("Unknown error");
|
|
6071
6157
|
setError(error2);
|
|
6072
6158
|
setState("error");
|
|
6073
|
-
_optionalChain([onError, 'optionalCall',
|
|
6159
|
+
_optionalChain([onError, 'optionalCall', _165 => _165(error2)]);
|
|
6074
6160
|
}
|
|
6075
6161
|
};
|
|
6076
6162
|
const resetCommand = () => {
|
|
@@ -6103,14 +6189,14 @@ ${planToExecute}`;
|
|
|
6103
6189
|
};
|
|
6104
6190
|
const handleFileSelect = async (e) => {
|
|
6105
6191
|
if (e.target.files && e.target.files.length > 0) {
|
|
6106
|
-
_optionalChain([onFileUpload, 'optionalCall',
|
|
6192
|
+
_optionalChain([onFileUpload, 'optionalCall', _166 => _166(e.target.files)]);
|
|
6107
6193
|
const files = [];
|
|
6108
6194
|
for (let i = 0; i < e.target.files.length; i++) {
|
|
6109
6195
|
const file = e.target.files[i];
|
|
6110
6196
|
const reader = new FileReader();
|
|
6111
6197
|
await new Promise((resolve) => {
|
|
6112
6198
|
reader.onload = (event) => {
|
|
6113
|
-
if (_optionalChain([event, 'access',
|
|
6199
|
+
if (_optionalChain([event, 'access', _167 => _167.target, 'optionalAccess', _168 => _168.result])) {
|
|
6114
6200
|
const fullDataUrl = event.target.result;
|
|
6115
6201
|
const base64Data = fullDataUrl.split(",")[1];
|
|
6116
6202
|
if (file.type.startsWith("image/")) {
|
|
@@ -6204,7 +6290,7 @@ ${planToExecute}`;
|
|
|
6204
6290
|
enableFileUpload && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
6205
6291
|
"button",
|
|
6206
6292
|
{
|
|
6207
|
-
onClick: () => _optionalChain([fileInputRef, 'access',
|
|
6293
|
+
onClick: () => _optionalChain([fileInputRef, 'access', _169 => _169.current, 'optionalAccess', _170 => _170.click, 'call', _171 => _171()]),
|
|
6208
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",
|
|
6209
6295
|
title: "Attach file",
|
|
6210
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)" }) })
|
|
@@ -6423,7 +6509,7 @@ ${planToExecute}`;
|
|
|
6423
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" }) }),
|
|
6424
6510
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
|
|
6425
6511
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h3", { className: "text-sm font-semibold text-red-800 dark:text-red-400", children: "Error" }),
|
|
6426
|
-
/* @__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]) })
|
|
6427
6513
|
] })
|
|
6428
6514
|
] }) }),
|
|
6429
6515
|
allowInput && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
@@ -6451,7 +6537,7 @@ ${planToExecute}`;
|
|
|
6451
6537
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-green-700 dark:text-green-300 text-sm", children: "Command executed successfully" })
|
|
6452
6538
|
] })
|
|
6453
6539
|
] }),
|
|
6454
|
-
_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 }),
|
|
6455
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,
|
|
6456
6542
|
WidgetRenderer,
|
|
6457
6543
|
{
|
|
@@ -6502,7 +6588,7 @@ ${planToExecute}`;
|
|
|
6502
6588
|
enableFileUpload && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
6503
6589
|
"button",
|
|
6504
6590
|
{
|
|
6505
|
-
onClick: () => _optionalChain([fileInputRef, 'access',
|
|
6591
|
+
onClick: () => _optionalChain([fileInputRef, 'access', _175 => _175.current, 'optionalAccess', _176 => _176.click, 'call', _177 => _177()]),
|
|
6506
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",
|
|
6507
6593
|
title: "Attach file",
|
|
6508
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)" }) })
|
|
@@ -6688,25 +6774,25 @@ function Prompt({
|
|
|
6688
6774
|
const newValue = e.target.value;
|
|
6689
6775
|
if (!maxLength || newValue.length <= maxLength) {
|
|
6690
6776
|
setValue(newValue);
|
|
6691
|
-
_optionalChain([onChange, 'optionalCall',
|
|
6777
|
+
_optionalChain([onChange, 'optionalCall', _178 => _178(newValue)]);
|
|
6692
6778
|
}
|
|
6693
6779
|
};
|
|
6694
6780
|
const handleSubmit = async () => {
|
|
6695
6781
|
if (value.length < minLength) return;
|
|
6696
|
-
_optionalChain([onSubmit, 'optionalCall',
|
|
6782
|
+
_optionalChain([onSubmit, 'optionalCall', _179 => _179(value)]);
|
|
6697
6783
|
setIsLoading(true);
|
|
6698
6784
|
try {
|
|
6699
6785
|
if (useMock) {
|
|
6700
6786
|
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
6701
6787
|
const mockResult = `Enhanced version: ${value} [AI-generated content]`;
|
|
6702
|
-
_optionalChain([onResult, 'optionalCall',
|
|
6788
|
+
_optionalChain([onResult, 'optionalCall', _180 => _180(mockResult)]);
|
|
6703
6789
|
setValue("");
|
|
6704
6790
|
} else {
|
|
6705
6791
|
const response = await aptevaClient.chat({
|
|
6706
6792
|
agent_id: agentId,
|
|
6707
6793
|
message: value
|
|
6708
6794
|
});
|
|
6709
|
-
_optionalChain([onResult, 'optionalCall',
|
|
6795
|
+
_optionalChain([onResult, 'optionalCall', _181 => _181(response.message)]);
|
|
6710
6796
|
setValue("");
|
|
6711
6797
|
}
|
|
6712
6798
|
} catch (error) {
|
|
@@ -6801,7 +6887,7 @@ function Stream({
|
|
|
6801
6887
|
}, [autoStart]);
|
|
6802
6888
|
const startStreaming = async () => {
|
|
6803
6889
|
setIsStreaming(true);
|
|
6804
|
-
_optionalChain([onStart, 'optionalCall',
|
|
6890
|
+
_optionalChain([onStart, 'optionalCall', _182 => _182()]);
|
|
6805
6891
|
try {
|
|
6806
6892
|
if (useMock) {
|
|
6807
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.";
|
|
@@ -6809,13 +6895,13 @@ function Stream({
|
|
|
6809
6895
|
mockText,
|
|
6810
6896
|
(chunk) => {
|
|
6811
6897
|
setText((prev) => prev + chunk);
|
|
6812
|
-
_optionalChain([onChunk, 'optionalCall',
|
|
6898
|
+
_optionalChain([onChunk, 'optionalCall', _183 => _183(chunk)]);
|
|
6813
6899
|
},
|
|
6814
6900
|
typingSpeed
|
|
6815
6901
|
);
|
|
6816
6902
|
setIsComplete(true);
|
|
6817
6903
|
setIsStreaming(false);
|
|
6818
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
6904
|
+
_optionalChain([onComplete, 'optionalCall', _184 => _184(text + mockText)]);
|
|
6819
6905
|
} else {
|
|
6820
6906
|
let accumulatedText = "";
|
|
6821
6907
|
await aptevaClient.chatStream(
|
|
@@ -6828,24 +6914,24 @@ function Stream({
|
|
|
6828
6914
|
if (chunk.type === "token" && chunk.content) {
|
|
6829
6915
|
accumulatedText += chunk.content;
|
|
6830
6916
|
setText(accumulatedText);
|
|
6831
|
-
_optionalChain([onChunk, 'optionalCall',
|
|
6917
|
+
_optionalChain([onChunk, 'optionalCall', _185 => _185(chunk.content)]);
|
|
6832
6918
|
}
|
|
6833
6919
|
},
|
|
6834
6920
|
() => {
|
|
6835
6921
|
setIsComplete(true);
|
|
6836
6922
|
setIsStreaming(false);
|
|
6837
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
6923
|
+
_optionalChain([onComplete, 'optionalCall', _186 => _186(accumulatedText)]);
|
|
6838
6924
|
},
|
|
6839
6925
|
(error) => {
|
|
6840
6926
|
const err = error instanceof Error ? error : new Error("Streaming error");
|
|
6841
|
-
_optionalChain([onError, 'optionalCall',
|
|
6927
|
+
_optionalChain([onError, 'optionalCall', _187 => _187(err)]);
|
|
6842
6928
|
setIsStreaming(false);
|
|
6843
6929
|
}
|
|
6844
6930
|
);
|
|
6845
6931
|
}
|
|
6846
6932
|
} catch (error) {
|
|
6847
6933
|
const err = error instanceof Error ? error : new Error("Streaming error");
|
|
6848
|
-
_optionalChain([onError, 'optionalCall',
|
|
6934
|
+
_optionalChain([onError, 'optionalCall', _188 => _188(err)]);
|
|
6849
6935
|
setIsStreaming(false);
|
|
6850
6936
|
}
|
|
6851
6937
|
};
|
|
@@ -6937,7 +7023,7 @@ function ThreadList({
|
|
|
6937
7023
|
}) {
|
|
6938
7024
|
const [searchQuery, setSearchQuery] = _react.useState.call(void 0, "");
|
|
6939
7025
|
const filteredThreads = threads.filter(
|
|
6940
|
-
(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())])
|
|
6941
7027
|
);
|
|
6942
7028
|
const groupedThreads = groupBy === "date" ? groupThreadsByDate(filteredThreads) : { All: filteredThreads };
|
|
6943
7029
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col h-full", children: [
|
|
@@ -6959,8 +7045,8 @@ function ThreadList({
|
|
|
6959
7045
|
{
|
|
6960
7046
|
thread,
|
|
6961
7047
|
isActive: thread.id === currentThreadId,
|
|
6962
|
-
onSelect: () => _optionalChain([onThreadSelect, 'optionalCall',
|
|
6963
|
-
onDelete: () => _optionalChain([onThreadDelete, 'optionalCall',
|
|
7048
|
+
onSelect: () => _optionalChain([onThreadSelect, 'optionalCall', _194 => _194(thread.id)]),
|
|
7049
|
+
onDelete: () => _optionalChain([onThreadDelete, 'optionalCall', _195 => _195(thread.id)])
|
|
6964
7050
|
},
|
|
6965
7051
|
thread.id
|
|
6966
7052
|
))
|
|
@@ -7022,7 +7108,7 @@ function Threads({
|
|
|
7022
7108
|
threads.slice(0, 5).map((thread) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
7023
7109
|
"button",
|
|
7024
7110
|
{
|
|
7025
|
-
onClick: () => _optionalChain([onThreadSelect, 'optionalCall',
|
|
7111
|
+
onClick: () => _optionalChain([onThreadSelect, 'optionalCall', _196 => _196(thread.id)]),
|
|
7026
7112
|
className: cn(
|
|
7027
7113
|
"px-4 py-2 whitespace-nowrap font-medium transition-colors",
|
|
7028
7114
|
thread.id === currentThreadId ? "border-b-2 border-apteva-500 text-apteva-500" : "text-neutral-600 hover:text-neutral-900"
|
|
@@ -7207,7 +7293,7 @@ function TabsLayout({ node, renderNode }) {
|
|
|
7207
7293
|
var STRUCTURAL_KEYS = /* @__PURE__ */ new Set(["type", "id", "layout", "props", "children", "actions", "metadata", "isStreaming"]);
|
|
7208
7294
|
function normalizeNode(n) {
|
|
7209
7295
|
let node = { ...n };
|
|
7210
|
-
if (node.type === "widget" && _optionalChain([node, 'access',
|
|
7296
|
+
if (node.type === "widget" && _optionalChain([node, 'access', _197 => _197.props, 'optionalAccess', _198 => _198.widget])) {
|
|
7211
7297
|
node.type = node.props.widget;
|
|
7212
7298
|
const { widget: _, ...rest } = node.props;
|
|
7213
7299
|
node.props = rest;
|
|
@@ -7345,10 +7431,10 @@ function AutoInterface({
|
|
|
7345
7431
|
].filter(Boolean).join("\n\n");
|
|
7346
7432
|
const updateInterface = _react.useCallback.call(void 0, (newSpec) => {
|
|
7347
7433
|
setInterfaceSpec(newSpec);
|
|
7348
|
-
_optionalChain([onInterfaceChange, 'optionalCall',
|
|
7434
|
+
_optionalChain([onInterfaceChange, 'optionalCall', _199 => _199(newSpec)]);
|
|
7349
7435
|
}, [onInterfaceChange]);
|
|
7350
7436
|
const handleAction = _react.useCallback.call(void 0, (action) => {
|
|
7351
|
-
_optionalChain([onAction, 'optionalCall',
|
|
7437
|
+
_optionalChain([onAction, 'optionalCall', _200 => _200(action)]);
|
|
7352
7438
|
if (chatRef.current) {
|
|
7353
7439
|
chatRef.current.sendMessage(
|
|
7354
7440
|
`[Action: ${action.type} on widget ${action.widgetId || "unknown"}. Payload: ${JSON.stringify(action.payload)}]`
|
|
@@ -7356,7 +7442,7 @@ function AutoInterface({
|
|
|
7356
7442
|
}
|
|
7357
7443
|
}, [onAction]);
|
|
7358
7444
|
const handleMessageComplete = _react.useCallback.call(void 0, (result) => {
|
|
7359
|
-
if (!_optionalChain([result, 'optionalAccess',
|
|
7445
|
+
if (!_optionalChain([result, 'optionalAccess', _201 => _201.data])) return;
|
|
7360
7446
|
const text = typeof result.data === "string" ? result.data : result.data.message || "";
|
|
7361
7447
|
console.log("[AutoInterface] Chat message complete, text (" + text.length + " chars):", text.substring(0, 300));
|
|
7362
7448
|
const parsed = parseInterfaceFromText(text);
|
|
@@ -7396,7 +7482,7 @@ function AutoInterface({
|
|
|
7396
7482
|
}).catch((err) => {
|
|
7397
7483
|
if (cancelled) return;
|
|
7398
7484
|
console.error("[AutoInterface] Initial generation failed:", err);
|
|
7399
|
-
_optionalChain([onError, 'optionalCall',
|
|
7485
|
+
_optionalChain([onError, 'optionalCall', _202 => _202(err instanceof Error ? err : new Error(String(err)))]);
|
|
7400
7486
|
setIsGenerating(false);
|
|
7401
7487
|
});
|
|
7402
7488
|
return () => {
|
|
@@ -7562,7 +7648,7 @@ function useInterfaceAI({
|
|
|
7562
7648
|
}
|
|
7563
7649
|
const sendMessage = _react.useCallback.call(void 0, async (message) => {
|
|
7564
7650
|
accumulatedTextRef.current = "";
|
|
7565
|
-
_optionalChain([onStreamStart, 'optionalCall',
|
|
7651
|
+
_optionalChain([onStreamStart, 'optionalCall', _203 => _203()]);
|
|
7566
7652
|
const systemPrompt = [
|
|
7567
7653
|
generateInterfaceContext(),
|
|
7568
7654
|
context || ""
|
|
@@ -7585,27 +7671,27 @@ function useInterfaceAI({
|
|
|
7585
7671
|
accumulatedTextRef.current += chunk.content || "";
|
|
7586
7672
|
const parsed = parseInterfaceFromText(accumulatedTextRef.current);
|
|
7587
7673
|
if (parsed) {
|
|
7588
|
-
_optionalChain([onInterface, 'optionalCall',
|
|
7674
|
+
_optionalChain([onInterface, 'optionalCall', _204 => _204(parsed)]);
|
|
7589
7675
|
}
|
|
7590
7676
|
const updates = parseUpdatesFromText(accumulatedTextRef.current);
|
|
7591
7677
|
if (updates.length > 0) {
|
|
7592
|
-
_optionalChain([onUpdates, 'optionalCall',
|
|
7678
|
+
_optionalChain([onUpdates, 'optionalCall', _205 => _205(updates)]);
|
|
7593
7679
|
}
|
|
7594
7680
|
}
|
|
7595
7681
|
},
|
|
7596
7682
|
// onComplete
|
|
7597
7683
|
() => {
|
|
7598
|
-
_optionalChain([onStreamEnd, 'optionalCall',
|
|
7684
|
+
_optionalChain([onStreamEnd, 'optionalCall', _206 => _206()]);
|
|
7599
7685
|
},
|
|
7600
7686
|
// onError
|
|
7601
7687
|
(error) => {
|
|
7602
|
-
_optionalChain([onError, 'optionalCall',
|
|
7603
|
-
_optionalChain([onStreamEnd, 'optionalCall',
|
|
7688
|
+
_optionalChain([onError, 'optionalCall', _207 => _207(error)]);
|
|
7689
|
+
_optionalChain([onStreamEnd, 'optionalCall', _208 => _208()]);
|
|
7604
7690
|
}
|
|
7605
7691
|
);
|
|
7606
7692
|
} catch (error) {
|
|
7607
|
-
_optionalChain([onError, 'optionalCall',
|
|
7608
|
-
_optionalChain([onStreamEnd, 'optionalCall',
|
|
7693
|
+
_optionalChain([onError, 'optionalCall', _209 => _209(error instanceof Error ? error : new Error("Unknown error"))]);
|
|
7694
|
+
_optionalChain([onStreamEnd, 'optionalCall', _210 => _210()]);
|
|
7609
7695
|
}
|
|
7610
7696
|
}, [agentId, context, onInterface, onUpdates, onError, onStreamStart, onStreamEnd]);
|
|
7611
7697
|
return {
|