@apteva/apteva-kit 0.1.130 → 0.1.132

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 CHANGED
@@ -2805,17 +2805,36 @@ function ToolCall({ name, status, isReceiving = false, inputLength = 0, streamOu
2805
2805
  // src/components/Chat/ToolCallGroup.tsx
2806
2806
 
2807
2807
 
2808
+ function formatResultPreview(result) {
2809
+ if (result == null) return "";
2810
+ const str = typeof result === "string" ? result : JSON.stringify(result);
2811
+ const oneLine = str.replace(/\s+/g, " ").trim();
2812
+ return oneLine.length > 120 ? oneLine.slice(0, 117) + "..." : oneLine;
2813
+ }
2808
2814
  function ToolCallGroup({ tools }) {
2809
2815
  const completed = tools.filter((t) => t.status === "completed").length;
2810
2816
  const errored = tools.filter((t) => t.status === "error").length;
2811
- const running = tools.filter((t) => t.status === "running").length;
2812
- const preparing = tools.filter((t) => t.status === "preparing").length;
2813
2817
  const total = tools.length;
2814
2818
  const allDone = completed + errored === total;
2815
2819
  const [expanded, setExpanded] = _react.useState.call(void 0, false);
2816
- const isExpanded = allDone ? expanded : true;
2817
- const activeStreamTool = tools.find((t) => t.status === "running" && t.streamOutput);
2818
- const statusText = allDone ? `Used ${total} tools` : `Using ${total} tools${completed > 0 ? ` \xB7 ${completed}/${total} done` : ""}`;
2820
+ const isExpanded = expanded;
2821
+ const activeTool = tools.find((t) => t.status === "running") || tools.find((t) => t.status === "preparing");
2822
+ let statusText;
2823
+ if (allDone) {
2824
+ if (errored > 0) {
2825
+ statusText = `Used ${total} tools \xB7 ${errored} failed`;
2826
+ } else {
2827
+ statusText = `Used ${total} tools`;
2828
+ }
2829
+ } else {
2830
+ const parts = [`Using ${total} tools`];
2831
+ if (completed > 0) parts.push(`${completed} done`);
2832
+ if (activeTool) {
2833
+ const activeLabel = activeTool.streamOutput || (activeTool.status === "preparing" ? "preparing" : "running");
2834
+ parts.push(`${activeTool.name} ${activeLabel === "preparing" || activeLabel === "running" ? activeLabel + "..." : "\xB7 " + activeLabel}`);
2835
+ }
2836
+ statusText = parts.join(" \xB7 ");
2837
+ }
2819
2838
  const cardClass = allDone ? errored > 0 ? "apteva-tool-group apteva-tool-group-error" : "apteva-tool-group apteva-tool-group-completed" : "apteva-tool-group apteva-tool-group-running";
2820
2839
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: cardClass, children: [
2821
2840
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
@@ -2846,18 +2865,20 @@ function ToolCallGroup({ tools }) {
2846
2865
  ]
2847
2866
  }
2848
2867
  ),
2849
- !isExpanded && activeStreamTool && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-tool-group-stream", children: [
2850
- /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "apteva-tool-group-stream-name", children: [
2851
- activeStreamTool.name,
2852
- ":"
2853
- ] }),
2854
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-tool-group-stream-text", children: activeStreamTool.streamOutput })
2855
- ] }),
2856
- isExpanded && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-tool-group-list", children: tools.map((tool) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-tool-group-item", children: [
2857
- tool.status === "completed" ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "apteva-tool-group-item-icon apteva-tool-group-item-done", width: "12", height: "12", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 3, d: "M5 13l4 4L19 7" }) }) : tool.status === "error" ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "apteva-tool-group-item-icon apteva-tool-group-item-error", width: "12", height: "12", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 3, d: "M6 18L18 6M6 6l12 12" }) }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-tool-group-item-icon apteva-tool-group-item-spinner" }),
2858
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-tool-group-item-name", children: tool.name }),
2859
- tool.streamOutput && tool.status === "running" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-tool-group-item-stream", children: tool.streamOutput })
2860
- ] }, tool.id)) })
2868
+ isExpanded && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-tool-group-list", children: tools.map((tool) => {
2869
+ const resultPreview = tool.status === "completed" && tool.result ? formatResultPreview(tool.result) : "";
2870
+ const hasDetail = tool.status === "running" && tool.streamOutput || resultPreview;
2871
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: `apteva-tool-group-item ${hasDetail ? "apteva-tool-group-item-has-detail" : ""}`, children: [
2872
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-tool-group-item-row", children: [
2873
+ tool.status === "completed" ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "apteva-tool-group-item-icon apteva-tool-group-item-done", width: "12", height: "12", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 3, d: "M5 13l4 4L19 7" }) }) : tool.status === "error" ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "apteva-tool-group-item-icon apteva-tool-group-item-error", width: "12", height: "12", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 3, d: "M6 18L18 6M6 6l12 12" }) }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-tool-group-item-icon apteva-tool-group-item-spinner" }),
2874
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-tool-group-item-name", children: tool.name }),
2875
+ tool.status === "running" && !tool.streamOutput && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-tool-group-item-running-label", children: "running..." }),
2876
+ tool.status === "preparing" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-tool-group-item-running-label", children: "preparing..." })
2877
+ ] }),
2878
+ tool.status === "running" && tool.streamOutput && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-tool-group-item-detail", children: tool.streamOutput }),
2879
+ resultPreview && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-tool-group-item-detail apteva-tool-group-item-result-text", children: resultPreview })
2880
+ ] }, tool.id);
2881
+ }) })
2861
2882
  ] });
2862
2883
  }
2863
2884
 
@@ -3108,7 +3129,8 @@ function Message({ message, onAction, enableWidgets, onWidgetRender, persistentW
3108
3129
  name: tool.name,
3109
3130
  status: tool.status || (tool.result !== void 0 ? "completed" : "running"),
3110
3131
  isReceiving: tool.isReceiving,
3111
- streamOutput: tool.streamOutput
3132
+ streamOutput: tool.streamOutput,
3133
+ result: tool.result
3112
3134
  };
3113
3135
  });
3114
3136
  elements.push(
@@ -4457,6 +4479,7 @@ function useVoiceSession(config) {
4457
4479
  const [state, setState] = _react.useState.call(void 0, "idle");
4458
4480
  const [partialTranscript, setPartialTranscript] = _react.useState.call(void 0, "");
4459
4481
  const [duration, setDuration] = _react.useState.call(void 0, 0);
4482
+ const [muted, setMuted] = _react.useState.call(void 0, false);
4460
4483
  const wsRef = _react.useRef.call(void 0, null);
4461
4484
  const captureCtxRef = _react.useRef.call(void 0, null);
4462
4485
  const playbackCtxRef = _react.useRef.call(void 0, null);
@@ -4465,6 +4488,7 @@ function useVoiceSession(config) {
4465
4488
  const nextPlayTimeRef = _react.useRef.call(void 0, 0);
4466
4489
  const durationIntervalRef = _react.useRef.call(void 0, null);
4467
4490
  const startTimeRef = _react.useRef.call(void 0, 0);
4491
+ const mutedRef = _react.useRef.call(void 0, false);
4468
4492
  const configRef = _react.useRef.call(void 0, config);
4469
4493
  configRef.current = config;
4470
4494
  const cleanup = _react.useCallback.call(void 0, () => {
@@ -4502,6 +4526,8 @@ function useVoiceSession(config) {
4502
4526
  wsRef.current = null;
4503
4527
  }
4504
4528
  nextPlayTimeRef.current = 0;
4529
+ mutedRef.current = false;
4530
+ setMuted(false);
4505
4531
  setPartialTranscript("");
4506
4532
  setDuration(0);
4507
4533
  }, []);
@@ -4529,6 +4555,8 @@ function useVoiceSession(config) {
4529
4555
  source.start(startTime);
4530
4556
  nextPlayTimeRef.current = startTime + audioBuffer.duration;
4531
4557
  }, []);
4558
+ const startCaptureRef = _react.useRef.call(void 0, () => {
4559
+ });
4532
4560
  const handleMessage = _react.useCallback.call(void 0, (msg) => {
4533
4561
  const cfg = configRef.current;
4534
4562
  switch (msg.type) {
@@ -4538,6 +4566,7 @@ function useVoiceSession(config) {
4538
4566
  durationIntervalRef.current = setInterval(() => {
4539
4567
  setDuration(Math.floor((Date.now() - startTimeRef.current) / 1e3));
4540
4568
  }, 1e3);
4569
+ startCaptureRef.current();
4541
4570
  break;
4542
4571
  case "audio_delta":
4543
4572
  if (_optionalChain([msg, 'access', _93 => _93.data, 'optionalAccess', _94 => _94.chunk])) {
@@ -4594,6 +4623,7 @@ function useVoiceSession(config) {
4594
4623
  processorRef.current = captureCtxRef.current.createScriptProcessor(2048, 1, 1);
4595
4624
  processorRef.current.onaudioprocess = (e) => {
4596
4625
  if (!ws || ws.readyState !== WebSocket.OPEN) return;
4626
+ if (mutedRef.current) return;
4597
4627
  const inputData = e.inputBuffer.getChannelData(0);
4598
4628
  const resampledData = resampleAudio(inputData, nativeSampleRate, 16e3);
4599
4629
  const int16Data = float32ToInt16(resampledData);
@@ -4606,16 +4636,24 @@ function useVoiceSession(config) {
4606
4636
  source.connect(processorRef.current);
4607
4637
  processorRef.current.connect(captureCtxRef.current.destination);
4608
4638
  } catch (e) {
4639
+ console.warn("Microphone access denied:", e);
4609
4640
  _optionalChain([configRef, 'access', _103 => _103.current, 'access', _104 => _104.onError, 'optionalCall', _105 => _105(new Error("Microphone access denied"))]);
4610
- cleanup();
4611
- setState("idle");
4612
4641
  }
4613
4642
  }, [cleanup]);
4643
+ startCaptureRef.current = startCapture;
4614
4644
  const start = _react.useCallback.call(void 0, () => {
4615
4645
  if (state !== "idle") return;
4616
4646
  setState("connecting");
4617
- const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
4618
- const wsUrl = `${protocol}//${window.location.host}${config.apiUrl}/voice`;
4647
+ let wsUrl;
4648
+ if (/^https?:\/\//.test(config.apiUrl)) {
4649
+ wsUrl = config.apiUrl.replace(/^http/, "ws") + "/voice";
4650
+ } else {
4651
+ const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
4652
+ wsUrl = `${protocol}//${window.location.host}${config.apiUrl}/voice`;
4653
+ }
4654
+ if (config.apiKey) {
4655
+ wsUrl += `${wsUrl.includes("?") ? "&" : "?"}token=${encodeURIComponent(config.apiKey)}`;
4656
+ }
4619
4657
  const ws = new WebSocket(wsUrl);
4620
4658
  wsRef.current = ws;
4621
4659
  ws.onopen = () => {
@@ -4625,7 +4663,6 @@ function useVoiceSession(config) {
4625
4663
  type: "start",
4626
4664
  data: { provider, voice }
4627
4665
  }));
4628
- startCapture();
4629
4666
  };
4630
4667
  ws.onmessage = (event) => {
4631
4668
  try {
@@ -4642,11 +4679,20 @@ function useVoiceSession(config) {
4642
4679
  cleanup();
4643
4680
  setState("idle");
4644
4681
  };
4645
- }, [state, config.apiUrl, startCapture, handleMessage, cleanup]);
4682
+ }, [state, config.apiUrl, handleMessage, cleanup]);
4646
4683
  const stop = _react.useCallback.call(void 0, () => {
4647
4684
  cleanup();
4648
4685
  setState("idle");
4649
4686
  }, [cleanup]);
4687
+ const toggleMute = _react.useCallback.call(void 0, () => {
4688
+ const next = !mutedRef.current;
4689
+ mutedRef.current = next;
4690
+ setMuted(next);
4691
+ if (mediaStreamRef.current) {
4692
+ const track = mediaStreamRef.current.getAudioTracks()[0];
4693
+ if (track) track.enabled = !next;
4694
+ }
4695
+ }, []);
4650
4696
  const sendText = _react.useCallback.call(void 0, (text) => {
4651
4697
  const ws = wsRef.current;
4652
4698
  if (!ws || ws.readyState !== WebSocket.OPEN) return;
@@ -4655,7 +4701,7 @@ function useVoiceSession(config) {
4655
4701
  data: { content: text }
4656
4702
  }));
4657
4703
  }, []);
4658
- return { state, partialTranscript, duration, start, stop, sendText };
4704
+ return { state, partialTranscript, duration, muted, start, stop, sendText, toggleMute };
4659
4705
  }
4660
4706
 
4661
4707
  // src/components/Chat/Chat.tsx
@@ -4746,6 +4792,7 @@ var Chat = _react.forwardRef.call(void 0, function Chat2({
4746
4792
  }, []);
4747
4793
  const voice = useVoiceSession({
4748
4794
  apiUrl: apiUrl || "",
4795
+ apiKey,
4749
4796
  provider: voiceProvider,
4750
4797
  voice: voiceId,
4751
4798
  onTranscript: handleVoiceTranscript,
@@ -5439,6 +5486,211 @@ ${planToExecute}`;
5439
5486
 
5440
5487
 
5441
5488
 
5489
+ // src/components/Call/Call.tsx
5490
+
5491
+
5492
+ // src/components/Call/CallStatus.tsx
5493
+
5494
+ function formatDuration(seconds) {
5495
+ const m = Math.floor(seconds / 60);
5496
+ const s = seconds % 60;
5497
+ return `${m.toString().padStart(2, "0")}:${s.toString().padStart(2, "0")}`;
5498
+ }
5499
+ function CallStatus({ agentName = "Agent", agentAvatarUrl, state, duration }) {
5500
+ const initial = agentName.charAt(0).toUpperCase();
5501
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-call-agent", children: [
5502
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-call-avatar-wrap", children: [
5503
+ agentAvatarUrl ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "img", { src: agentAvatarUrl, alt: agentName, className: "apteva-call-avatar" }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-call-avatar-placeholder", children: initial }),
5504
+ state === "active" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-call-pulse-ring" })
5505
+ ] }),
5506
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-call-agent-name", children: agentName }),
5507
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: `apteva-call-status ${state === "active" ? "apteva-call-status-active" : state === "connecting" ? "apteva-call-status-connecting" : state === "error" ? "apteva-call-status-error" : ""}`, children: [
5508
+ state === "idle" && "Ready",
5509
+ state === "connecting" && "Connecting...",
5510
+ state === "active" && "Connected",
5511
+ state === "error" && "Error"
5512
+ ] }),
5513
+ (state === "active" || state === "connecting") && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-call-duration", children: formatDuration(duration) })
5514
+ ] });
5515
+ }
5516
+
5517
+ // src/components/Call/CallTranscript.tsx
5518
+
5519
+
5520
+ function CallTranscript({ entries, partialTranscript }) {
5521
+ const scrollRef = _react.useRef.call(void 0, null);
5522
+ _react.useEffect.call(void 0, () => {
5523
+ if (scrollRef.current) {
5524
+ scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
5525
+ }
5526
+ }, [entries.length, partialTranscript]);
5527
+ if (entries.length === 0 && !partialTranscript) return null;
5528
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-call-transcript", ref: scrollRef, children: [
5529
+ entries.map((entry) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-call-transcript-entry", children: [
5530
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: `apteva-call-transcript-role apteva-call-transcript-role-${entry.role}`, children: entry.role === "user" ? "You" : entry.role === "assistant" ? "Agent" : "System" }),
5531
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-call-transcript-content", children: entry.content })
5532
+ ] }, entry.id)),
5533
+ partialTranscript && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-call-transcript-entry", children: [
5534
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-call-transcript-role apteva-call-transcript-role-user", children: "You" }),
5535
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-call-transcript-partial", children: partialTranscript })
5536
+ ] })
5537
+ ] });
5538
+ }
5539
+
5540
+ // src/components/Call/CallControls.tsx
5541
+
5542
+ function CallControls({ state, muted, mediaMode, onStart, onEnd, onToggleMute }) {
5543
+ const isLive = state === "active" || state === "connecting";
5544
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-call-controls", children: isLive ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
5545
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
5546
+ "button",
5547
+ {
5548
+ onClick: onToggleMute,
5549
+ className: `apteva-call-btn apteva-call-btn-mute ${muted ? "apteva-call-btn-mute-active" : ""}`,
5550
+ title: muted ? "Unmute" : "Mute",
5551
+ children: muted ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
5552
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "1", y1: "1", x2: "23", y2: "23" }),
5553
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M9 9v3a3 3 0 0 0 5.12 2.12M15 9.34V4a3 3 0 0 0-5.94-.6" }),
5554
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M17 16.95A7 7 0 0 1 5 12v-2m14 0v2c0 .76-.13 1.49-.35 2.17" }),
5555
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "12", y1: "19", x2: "12", y2: "23" }),
5556
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "8", y1: "23", x2: "16", y2: "23" })
5557
+ ] }) : /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
5558
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z" }),
5559
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M19 10v2a7 7 0 0 1-14 0v-2" }),
5560
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "12", y1: "19", x2: "12", y2: "23" }),
5561
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "8", y1: "23", x2: "16", y2: "23" })
5562
+ ] })
5563
+ }
5564
+ ),
5565
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
5566
+ "button",
5567
+ {
5568
+ onClick: onEnd,
5569
+ className: "apteva-call-btn apteva-call-btn-end",
5570
+ title: "End call",
5571
+ children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
5572
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M10.68 13.31a16 16 0 0 0 3.41 2.6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7 2 2 0 0 1 1.72 2v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91" }),
5573
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "23", y1: "1", x2: "1", y2: "23" })
5574
+ ] })
5575
+ }
5576
+ )
5577
+ ] }) : (
5578
+ /* Start call button */
5579
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
5580
+ "button",
5581
+ {
5582
+ onClick: onStart,
5583
+ className: "apteva-call-btn apteva-call-btn-start",
5584
+ title: "Start call",
5585
+ disabled: state === "error",
5586
+ children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z" }) })
5587
+ }
5588
+ )
5589
+ ) });
5590
+ }
5591
+
5592
+ // src/components/Call/Call.tsx
5593
+
5594
+ function Call({
5595
+ agentName = "Agent",
5596
+ agentAvatarUrl,
5597
+ apiUrl,
5598
+ apiKey,
5599
+ voiceProvider,
5600
+ voiceId,
5601
+ mediaMode = "voice",
5602
+ autoStart = false,
5603
+ showTranscript = true,
5604
+ maxTranscriptEntries = 50,
5605
+ onCallStart,
5606
+ onCallEnd,
5607
+ onTranscript,
5608
+ onError,
5609
+ onMuteChange,
5610
+ variant = "default",
5611
+ theme,
5612
+ className
5613
+ }) {
5614
+ const [transcripts, setTranscripts] = _react.useState.call(void 0, []);
5615
+ const prevStateRef = _react.useRef.call(void 0, "idle");
5616
+ const durationRef = _react.useRef.call(void 0, 0);
5617
+ const autoStartedRef = _react.useRef.call(void 0, false);
5618
+ const handleTranscript = _react.useCallback.call(void 0, (entry) => {
5619
+ setTranscripts((prev) => {
5620
+ const next = [...prev, entry];
5621
+ return next.length > maxTranscriptEntries ? next.slice(next.length - maxTranscriptEntries) : next;
5622
+ });
5623
+ _optionalChain([onTranscript, 'optionalCall', _136 => _136(entry)]);
5624
+ }, [maxTranscriptEntries, onTranscript]);
5625
+ const voice = useVoiceSession({
5626
+ apiUrl,
5627
+ apiKey,
5628
+ provider: voiceProvider,
5629
+ voice: voiceId,
5630
+ onTranscript: handleTranscript,
5631
+ onError
5632
+ });
5633
+ _react.useEffect.call(void 0, () => {
5634
+ durationRef.current = voice.duration;
5635
+ }, [voice.duration]);
5636
+ _react.useEffect.call(void 0, () => {
5637
+ const prev = prevStateRef.current;
5638
+ if (prev !== "active" && voice.state === "active") {
5639
+ _optionalChain([onCallStart, 'optionalCall', _137 => _137()]);
5640
+ }
5641
+ if (prev === "active" && voice.state === "idle") {
5642
+ _optionalChain([onCallEnd, 'optionalCall', _138 => _138({ duration: durationRef.current, transcripts })]);
5643
+ }
5644
+ prevStateRef.current = voice.state;
5645
+ }, [voice.state, onCallStart, onCallEnd, transcripts]);
5646
+ _react.useEffect.call(void 0, () => {
5647
+ if (autoStart && !autoStartedRef.current && voice.state === "idle") {
5648
+ autoStartedRef.current = true;
5649
+ voice.start();
5650
+ }
5651
+ }, [autoStart, voice.state, voice.start]);
5652
+ _react.useEffect.call(void 0, () => {
5653
+ _optionalChain([onMuteChange, 'optionalCall', _139 => _139(voice.muted)]);
5654
+ }, [voice.muted, onMuteChange]);
5655
+ const cn2 = [
5656
+ "apteva-call",
5657
+ variant !== "default" && `apteva-call-${variant}`,
5658
+ theme === "dark" && "apteva-force-dark",
5659
+ theme === "light" && "apteva-force-light",
5660
+ className
5661
+ ].filter(Boolean).join(" ");
5662
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: cn2, children: [
5663
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
5664
+ CallStatus,
5665
+ {
5666
+ agentName,
5667
+ agentAvatarUrl,
5668
+ state: voice.state,
5669
+ duration: voice.duration
5670
+ }
5671
+ ),
5672
+ mediaMode === "video" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-call-video-area", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", opacity: "0.4", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M16.24 7.76a6 6 0 0 1 0 8.49m-8.48-.01a6 6 0 0 1 0-8.49m11.31-2.82a10 10 0 0 1 0 14.14m-14.14 0a10 10 0 0 1 0-14.14" }) }) }),
5673
+ showTranscript && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
5674
+ CallTranscript,
5675
+ {
5676
+ entries: transcripts,
5677
+ partialTranscript: voice.partialTranscript
5678
+ }
5679
+ ),
5680
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
5681
+ CallControls,
5682
+ {
5683
+ state: voice.state,
5684
+ muted: voice.muted,
5685
+ mediaMode,
5686
+ onStart: voice.start,
5687
+ onEnd: voice.stop,
5688
+ onToggleMute: voice.toggleMute
5689
+ }
5690
+ )
5691
+ ] });
5692
+ }
5693
+
5442
5694
  // src/components/Command/Command.tsx
5443
5695
 
5444
5696
 
@@ -5574,13 +5826,13 @@ ${planningInstruction}` : planningInstruction;
5574
5826
  const error2 = err instanceof Error ? err : new Error("Failed to generate plan");
5575
5827
  setError(error2);
5576
5828
  setState("error");
5577
- _optionalChain([onError, 'optionalCall', _136 => _136(error2)]);
5829
+ _optionalChain([onError, 'optionalCall', _140 => _140(error2)]);
5578
5830
  });
5579
5831
  } catch (err) {
5580
5832
  const error2 = err instanceof Error ? err : new Error("Failed to generate plan");
5581
5833
  setError(error2);
5582
5834
  setState("error");
5583
- _optionalChain([onError, 'optionalCall', _137 => _137(error2)]);
5835
+ _optionalChain([onError, 'optionalCall', _141 => _141(error2)]);
5584
5836
  }
5585
5837
  }
5586
5838
  return;
@@ -5591,7 +5843,7 @@ ${planningInstruction}` : planningInstruction;
5591
5843
  setStreamedContent("");
5592
5844
  setCommand("");
5593
5845
  setUploadedFiles([]);
5594
- _optionalChain([onStart, 'optionalCall', _138 => _138()]);
5846
+ _optionalChain([onStart, 'optionalCall', _142 => _142()]);
5595
5847
  try {
5596
5848
  if (useMock) {
5597
5849
  if (enableStreaming) {
@@ -5602,16 +5854,16 @@ ${planningInstruction}` : planningInstruction;
5602
5854
  if (chunk.type === "token" && chunk.content) {
5603
5855
  accumulatedContent += chunk.content;
5604
5856
  setStreamedContent(accumulatedContent);
5605
- _optionalChain([onChunk, 'optionalCall', _139 => _139(chunk.content)]);
5857
+ _optionalChain([onChunk, 'optionalCall', _143 => _143(chunk.content)]);
5606
5858
  const estimatedProgress = Math.min(Math.round(accumulatedContent.length / 10), 90);
5607
5859
  setProgress(estimatedProgress);
5608
- _optionalChain([onProgress, 'optionalCall', _140 => _140(estimatedProgress)]);
5860
+ _optionalChain([onProgress, 'optionalCall', _144 => _144(estimatedProgress)]);
5609
5861
  } else if (chunk.type === "widget" && chunk.widget) {
5610
5862
  const widget = chunk.widget;
5611
5863
  setResult((prev) => ({
5612
5864
  success: true,
5613
- data: _optionalChain([prev, 'optionalAccess', _141 => _141.data]) || {},
5614
- widgets: [..._optionalChain([prev, 'optionalAccess', _142 => _142.widgets]) || [], widget],
5865
+ data: _optionalChain([prev, 'optionalAccess', _145 => _145.data]) || {},
5866
+ widgets: [..._optionalChain([prev, 'optionalAccess', _146 => _146.widgets]) || [], widget],
5615
5867
  message: accumulatedContent || "Command executed successfully"
5616
5868
  }));
5617
5869
  }
@@ -5631,19 +5883,19 @@ ${planningInstruction}` : planningInstruction;
5631
5883
  setResult(result2);
5632
5884
  setState("success");
5633
5885
  setProgress(100);
5634
- _optionalChain([onComplete, 'optionalCall', _143 => _143(result2)]);
5886
+ _optionalChain([onComplete, 'optionalCall', _147 => _147(result2)]);
5635
5887
  },
5636
5888
  (error2) => {
5637
5889
  setError(error2);
5638
5890
  setState("error");
5639
- _optionalChain([onError, 'optionalCall', _144 => _144(error2)]);
5891
+ _optionalChain([onError, 'optionalCall', _148 => _148(error2)]);
5640
5892
  }
5641
5893
  );
5642
5894
  } else {
5643
5895
  const progressInterval = setInterval(() => {
5644
5896
  setProgress((prev) => {
5645
5897
  const next = Math.min(prev + 10, 90);
5646
- _optionalChain([onProgress, 'optionalCall', _145 => _145(next)]);
5898
+ _optionalChain([onProgress, 'optionalCall', _149 => _149(next)]);
5647
5899
  return next;
5648
5900
  });
5649
5901
  }, 200);
@@ -5667,7 +5919,7 @@ ${planningInstruction}` : planningInstruction;
5667
5919
  setResult(result2);
5668
5920
  setState("success");
5669
5921
  setProgress(100);
5670
- _optionalChain([onComplete, 'optionalCall', _146 => _146(result2)]);
5922
+ _optionalChain([onComplete, 'optionalCall', _150 => _150(result2)]);
5671
5923
  }
5672
5924
  } else {
5673
5925
  if (enableStreaming) {
@@ -5713,16 +5965,16 @@ ${commandInstruction}` : commandInstruction;
5713
5965
  if (chunk.type === "token" && chunk.content) {
5714
5966
  accumulatedContent += chunk.content;
5715
5967
  setStreamedContent(accumulatedContent);
5716
- _optionalChain([onChunk, 'optionalCall', _147 => _147(chunk.content)]);
5968
+ _optionalChain([onChunk, 'optionalCall', _151 => _151(chunk.content)]);
5717
5969
  const estimatedProgress = Math.min(Math.round(accumulatedContent.length / 10), 90);
5718
5970
  setProgress(estimatedProgress);
5719
- _optionalChain([onProgress, 'optionalCall', _148 => _148(estimatedProgress)]);
5971
+ _optionalChain([onProgress, 'optionalCall', _152 => _152(estimatedProgress)]);
5720
5972
  } else if (chunk.type === "widget" && chunk.widget) {
5721
5973
  const widget = chunk.widget;
5722
5974
  setResult((prev) => ({
5723
5975
  success: true,
5724
- data: _optionalChain([prev, 'optionalAccess', _149 => _149.data]) || {},
5725
- widgets: [..._optionalChain([prev, 'optionalAccess', _150 => _150.widgets]) || [], widget],
5976
+ data: _optionalChain([prev, 'optionalAccess', _153 => _153.data]) || {},
5977
+ widgets: [..._optionalChain([prev, 'optionalAccess', _154 => _154.widgets]) || [], widget],
5726
5978
  message: accumulatedContent || "Command executed successfully"
5727
5979
  }));
5728
5980
  }
@@ -5742,20 +5994,20 @@ ${commandInstruction}` : commandInstruction;
5742
5994
  setResult(result2);
5743
5995
  setState("success");
5744
5996
  setProgress(100);
5745
- _optionalChain([onComplete, 'optionalCall', _151 => _151(result2)]);
5997
+ _optionalChain([onComplete, 'optionalCall', _155 => _155(result2)]);
5746
5998
  },
5747
5999
  (error2) => {
5748
6000
  const err = error2 instanceof Error ? error2 : new Error("Unknown error");
5749
6001
  setError(err);
5750
6002
  setState("error");
5751
- _optionalChain([onError, 'optionalCall', _152 => _152(err)]);
6003
+ _optionalChain([onError, 'optionalCall', _156 => _156(err)]);
5752
6004
  }
5753
6005
  );
5754
6006
  } else {
5755
6007
  const progressInterval = setInterval(() => {
5756
6008
  setProgress((prev) => {
5757
6009
  const next = Math.min(prev + 10, 90);
5758
- _optionalChain([onProgress, 'optionalCall', _153 => _153(next)]);
6010
+ _optionalChain([onProgress, 'optionalCall', _157 => _157(next)]);
5759
6011
  return next;
5760
6012
  });
5761
6013
  }, 200);
@@ -5811,14 +6063,14 @@ ${commandInstruction}` : commandInstruction;
5811
6063
  setResult(result2);
5812
6064
  setState("success");
5813
6065
  setProgress(100);
5814
- _optionalChain([onComplete, 'optionalCall', _154 => _154(result2)]);
6066
+ _optionalChain([onComplete, 'optionalCall', _158 => _158(result2)]);
5815
6067
  }
5816
6068
  }
5817
6069
  } catch (err) {
5818
6070
  const error2 = err instanceof Error ? err : new Error("Unknown error");
5819
6071
  setError(error2);
5820
6072
  setState("error");
5821
- _optionalChain([onError, 'optionalCall', _155 => _155(error2)]);
6073
+ _optionalChain([onError, 'optionalCall', _159 => _159(error2)]);
5822
6074
  }
5823
6075
  };
5824
6076
  const resetCommand = () => {
@@ -5851,14 +6103,14 @@ ${planToExecute}`;
5851
6103
  };
5852
6104
  const handleFileSelect = async (e) => {
5853
6105
  if (e.target.files && e.target.files.length > 0) {
5854
- _optionalChain([onFileUpload, 'optionalCall', _156 => _156(e.target.files)]);
6106
+ _optionalChain([onFileUpload, 'optionalCall', _160 => _160(e.target.files)]);
5855
6107
  const files = [];
5856
6108
  for (let i = 0; i < e.target.files.length; i++) {
5857
6109
  const file = e.target.files[i];
5858
6110
  const reader = new FileReader();
5859
6111
  await new Promise((resolve) => {
5860
6112
  reader.onload = (event) => {
5861
- if (_optionalChain([event, 'access', _157 => _157.target, 'optionalAccess', _158 => _158.result])) {
6113
+ if (_optionalChain([event, 'access', _161 => _161.target, 'optionalAccess', _162 => _162.result])) {
5862
6114
  const fullDataUrl = event.target.result;
5863
6115
  const base64Data = fullDataUrl.split(",")[1];
5864
6116
  if (file.type.startsWith("image/")) {
@@ -5952,7 +6204,7 @@ ${planToExecute}`;
5952
6204
  enableFileUpload && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
5953
6205
  "button",
5954
6206
  {
5955
- onClick: () => _optionalChain([fileInputRef, 'access', _159 => _159.current, 'optionalAccess', _160 => _160.click, 'call', _161 => _161()]),
6207
+ onClick: () => _optionalChain([fileInputRef, 'access', _163 => _163.current, 'optionalAccess', _164 => _164.click, 'call', _165 => _165()]),
5956
6208
  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",
5957
6209
  title: "Attach file",
5958
6210
  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)" }) })
@@ -6171,7 +6423,7 @@ ${planToExecute}`;
6171
6423
  /* @__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" }) }),
6172
6424
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
6173
6425
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h3", { className: "text-sm font-semibold text-red-800 dark:text-red-400", children: "Error" }),
6174
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-red-700 dark:text-red-300 text-sm mt-1", children: _optionalChain([error, 'optionalAccess', _162 => _162.message]) })
6426
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-red-700 dark:text-red-300 text-sm mt-1", children: _optionalChain([error, 'optionalAccess', _166 => _166.message]) })
6175
6427
  ] })
6176
6428
  ] }) }),
6177
6429
  allowInput && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
@@ -6199,7 +6451,7 @@ ${planToExecute}`;
6199
6451
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-green-700 dark:text-green-300 text-sm", children: "Command executed successfully" })
6200
6452
  ] })
6201
6453
  ] }),
6202
- _optionalChain([result, 'access', _163 => _163.data, 'optionalAccess', _164 => _164.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 }),
6454
+ _optionalChain([result, 'access', _167 => _167.data, 'optionalAccess', _168 => _168.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 }),
6203
6455
  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,
6204
6456
  WidgetRenderer,
6205
6457
  {
@@ -6250,7 +6502,7 @@ ${planToExecute}`;
6250
6502
  enableFileUpload && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
6251
6503
  "button",
6252
6504
  {
6253
- onClick: () => _optionalChain([fileInputRef, 'access', _165 => _165.current, 'optionalAccess', _166 => _166.click, 'call', _167 => _167()]),
6505
+ onClick: () => _optionalChain([fileInputRef, 'access', _169 => _169.current, 'optionalAccess', _170 => _170.click, 'call', _171 => _171()]),
6254
6506
  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",
6255
6507
  title: "Attach file",
6256
6508
  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)" }) })
@@ -6436,25 +6688,25 @@ function Prompt({
6436
6688
  const newValue = e.target.value;
6437
6689
  if (!maxLength || newValue.length <= maxLength) {
6438
6690
  setValue(newValue);
6439
- _optionalChain([onChange, 'optionalCall', _168 => _168(newValue)]);
6691
+ _optionalChain([onChange, 'optionalCall', _172 => _172(newValue)]);
6440
6692
  }
6441
6693
  };
6442
6694
  const handleSubmit = async () => {
6443
6695
  if (value.length < minLength) return;
6444
- _optionalChain([onSubmit, 'optionalCall', _169 => _169(value)]);
6696
+ _optionalChain([onSubmit, 'optionalCall', _173 => _173(value)]);
6445
6697
  setIsLoading(true);
6446
6698
  try {
6447
6699
  if (useMock) {
6448
6700
  await new Promise((resolve) => setTimeout(resolve, 1500));
6449
6701
  const mockResult = `Enhanced version: ${value} [AI-generated content]`;
6450
- _optionalChain([onResult, 'optionalCall', _170 => _170(mockResult)]);
6702
+ _optionalChain([onResult, 'optionalCall', _174 => _174(mockResult)]);
6451
6703
  setValue("");
6452
6704
  } else {
6453
6705
  const response = await aptevaClient.chat({
6454
6706
  agent_id: agentId,
6455
6707
  message: value
6456
6708
  });
6457
- _optionalChain([onResult, 'optionalCall', _171 => _171(response.message)]);
6709
+ _optionalChain([onResult, 'optionalCall', _175 => _175(response.message)]);
6458
6710
  setValue("");
6459
6711
  }
6460
6712
  } catch (error) {
@@ -6549,7 +6801,7 @@ function Stream({
6549
6801
  }, [autoStart]);
6550
6802
  const startStreaming = async () => {
6551
6803
  setIsStreaming(true);
6552
- _optionalChain([onStart, 'optionalCall', _172 => _172()]);
6804
+ _optionalChain([onStart, 'optionalCall', _176 => _176()]);
6553
6805
  try {
6554
6806
  if (useMock) {
6555
6807
  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.";
@@ -6557,13 +6809,13 @@ function Stream({
6557
6809
  mockText,
6558
6810
  (chunk) => {
6559
6811
  setText((prev) => prev + chunk);
6560
- _optionalChain([onChunk, 'optionalCall', _173 => _173(chunk)]);
6812
+ _optionalChain([onChunk, 'optionalCall', _177 => _177(chunk)]);
6561
6813
  },
6562
6814
  typingSpeed
6563
6815
  );
6564
6816
  setIsComplete(true);
6565
6817
  setIsStreaming(false);
6566
- _optionalChain([onComplete, 'optionalCall', _174 => _174(text + mockText)]);
6818
+ _optionalChain([onComplete, 'optionalCall', _178 => _178(text + mockText)]);
6567
6819
  } else {
6568
6820
  let accumulatedText = "";
6569
6821
  await aptevaClient.chatStream(
@@ -6576,24 +6828,24 @@ function Stream({
6576
6828
  if (chunk.type === "token" && chunk.content) {
6577
6829
  accumulatedText += chunk.content;
6578
6830
  setText(accumulatedText);
6579
- _optionalChain([onChunk, 'optionalCall', _175 => _175(chunk.content)]);
6831
+ _optionalChain([onChunk, 'optionalCall', _179 => _179(chunk.content)]);
6580
6832
  }
6581
6833
  },
6582
6834
  () => {
6583
6835
  setIsComplete(true);
6584
6836
  setIsStreaming(false);
6585
- _optionalChain([onComplete, 'optionalCall', _176 => _176(accumulatedText)]);
6837
+ _optionalChain([onComplete, 'optionalCall', _180 => _180(accumulatedText)]);
6586
6838
  },
6587
6839
  (error) => {
6588
6840
  const err = error instanceof Error ? error : new Error("Streaming error");
6589
- _optionalChain([onError, 'optionalCall', _177 => _177(err)]);
6841
+ _optionalChain([onError, 'optionalCall', _181 => _181(err)]);
6590
6842
  setIsStreaming(false);
6591
6843
  }
6592
6844
  );
6593
6845
  }
6594
6846
  } catch (error) {
6595
6847
  const err = error instanceof Error ? error : new Error("Streaming error");
6596
- _optionalChain([onError, 'optionalCall', _178 => _178(err)]);
6848
+ _optionalChain([onError, 'optionalCall', _182 => _182(err)]);
6597
6849
  setIsStreaming(false);
6598
6850
  }
6599
6851
  };
@@ -6685,7 +6937,7 @@ function ThreadList({
6685
6937
  }) {
6686
6938
  const [searchQuery, setSearchQuery] = _react.useState.call(void 0, "");
6687
6939
  const filteredThreads = threads.filter(
6688
- (thread) => thread.title.toLowerCase().includes(searchQuery.toLowerCase()) || _optionalChain([thread, 'access', _179 => _179.preview, 'optionalAccess', _180 => _180.toLowerCase, 'call', _181 => _181(), 'access', _182 => _182.includes, 'call', _183 => _183(searchQuery.toLowerCase())])
6940
+ (thread) => thread.title.toLowerCase().includes(searchQuery.toLowerCase()) || _optionalChain([thread, 'access', _183 => _183.preview, 'optionalAccess', _184 => _184.toLowerCase, 'call', _185 => _185(), 'access', _186 => _186.includes, 'call', _187 => _187(searchQuery.toLowerCase())])
6689
6941
  );
6690
6942
  const groupedThreads = groupBy === "date" ? groupThreadsByDate(filteredThreads) : { All: filteredThreads };
6691
6943
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col h-full", children: [
@@ -6707,8 +6959,8 @@ function ThreadList({
6707
6959
  {
6708
6960
  thread,
6709
6961
  isActive: thread.id === currentThreadId,
6710
- onSelect: () => _optionalChain([onThreadSelect, 'optionalCall', _184 => _184(thread.id)]),
6711
- onDelete: () => _optionalChain([onThreadDelete, 'optionalCall', _185 => _185(thread.id)])
6962
+ onSelect: () => _optionalChain([onThreadSelect, 'optionalCall', _188 => _188(thread.id)]),
6963
+ onDelete: () => _optionalChain([onThreadDelete, 'optionalCall', _189 => _189(thread.id)])
6712
6964
  },
6713
6965
  thread.id
6714
6966
  ))
@@ -6770,7 +7022,7 @@ function Threads({
6770
7022
  threads.slice(0, 5).map((thread) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
6771
7023
  "button",
6772
7024
  {
6773
- onClick: () => _optionalChain([onThreadSelect, 'optionalCall', _186 => _186(thread.id)]),
7025
+ onClick: () => _optionalChain([onThreadSelect, 'optionalCall', _190 => _190(thread.id)]),
6774
7026
  className: cn(
6775
7027
  "px-4 py-2 whitespace-nowrap font-medium transition-colors",
6776
7028
  thread.id === currentThreadId ? "border-b-2 border-apteva-500 text-apteva-500" : "text-neutral-600 hover:text-neutral-900"
@@ -6955,7 +7207,7 @@ function TabsLayout({ node, renderNode }) {
6955
7207
  var STRUCTURAL_KEYS = /* @__PURE__ */ new Set(["type", "id", "layout", "props", "children", "actions", "metadata", "isStreaming"]);
6956
7208
  function normalizeNode(n) {
6957
7209
  let node = { ...n };
6958
- if (node.type === "widget" && _optionalChain([node, 'access', _187 => _187.props, 'optionalAccess', _188 => _188.widget])) {
7210
+ if (node.type === "widget" && _optionalChain([node, 'access', _191 => _191.props, 'optionalAccess', _192 => _192.widget])) {
6959
7211
  node.type = node.props.widget;
6960
7212
  const { widget: _, ...rest } = node.props;
6961
7213
  node.props = rest;
@@ -7093,10 +7345,10 @@ function AutoInterface({
7093
7345
  ].filter(Boolean).join("\n\n");
7094
7346
  const updateInterface = _react.useCallback.call(void 0, (newSpec) => {
7095
7347
  setInterfaceSpec(newSpec);
7096
- _optionalChain([onInterfaceChange, 'optionalCall', _189 => _189(newSpec)]);
7348
+ _optionalChain([onInterfaceChange, 'optionalCall', _193 => _193(newSpec)]);
7097
7349
  }, [onInterfaceChange]);
7098
7350
  const handleAction = _react.useCallback.call(void 0, (action) => {
7099
- _optionalChain([onAction, 'optionalCall', _190 => _190(action)]);
7351
+ _optionalChain([onAction, 'optionalCall', _194 => _194(action)]);
7100
7352
  if (chatRef.current) {
7101
7353
  chatRef.current.sendMessage(
7102
7354
  `[Action: ${action.type} on widget ${action.widgetId || "unknown"}. Payload: ${JSON.stringify(action.payload)}]`
@@ -7104,7 +7356,7 @@ function AutoInterface({
7104
7356
  }
7105
7357
  }, [onAction]);
7106
7358
  const handleMessageComplete = _react.useCallback.call(void 0, (result) => {
7107
- if (!_optionalChain([result, 'optionalAccess', _191 => _191.data])) return;
7359
+ if (!_optionalChain([result, 'optionalAccess', _195 => _195.data])) return;
7108
7360
  const text = typeof result.data === "string" ? result.data : result.data.message || "";
7109
7361
  console.log("[AutoInterface] Chat message complete, text (" + text.length + " chars):", text.substring(0, 300));
7110
7362
  const parsed = parseInterfaceFromText(text);
@@ -7144,7 +7396,7 @@ function AutoInterface({
7144
7396
  }).catch((err) => {
7145
7397
  if (cancelled) return;
7146
7398
  console.error("[AutoInterface] Initial generation failed:", err);
7147
- _optionalChain([onError, 'optionalCall', _192 => _192(err instanceof Error ? err : new Error(String(err)))]);
7399
+ _optionalChain([onError, 'optionalCall', _196 => _196(err instanceof Error ? err : new Error(String(err)))]);
7148
7400
  setIsGenerating(false);
7149
7401
  });
7150
7402
  return () => {
@@ -7310,7 +7562,7 @@ function useInterfaceAI({
7310
7562
  }
7311
7563
  const sendMessage = _react.useCallback.call(void 0, async (message) => {
7312
7564
  accumulatedTextRef.current = "";
7313
- _optionalChain([onStreamStart, 'optionalCall', _193 => _193()]);
7565
+ _optionalChain([onStreamStart, 'optionalCall', _197 => _197()]);
7314
7566
  const systemPrompt = [
7315
7567
  generateInterfaceContext(),
7316
7568
  context || ""
@@ -7333,27 +7585,27 @@ function useInterfaceAI({
7333
7585
  accumulatedTextRef.current += chunk.content || "";
7334
7586
  const parsed = parseInterfaceFromText(accumulatedTextRef.current);
7335
7587
  if (parsed) {
7336
- _optionalChain([onInterface, 'optionalCall', _194 => _194(parsed)]);
7588
+ _optionalChain([onInterface, 'optionalCall', _198 => _198(parsed)]);
7337
7589
  }
7338
7590
  const updates = parseUpdatesFromText(accumulatedTextRef.current);
7339
7591
  if (updates.length > 0) {
7340
- _optionalChain([onUpdates, 'optionalCall', _195 => _195(updates)]);
7592
+ _optionalChain([onUpdates, 'optionalCall', _199 => _199(updates)]);
7341
7593
  }
7342
7594
  }
7343
7595
  },
7344
7596
  // onComplete
7345
7597
  () => {
7346
- _optionalChain([onStreamEnd, 'optionalCall', _196 => _196()]);
7598
+ _optionalChain([onStreamEnd, 'optionalCall', _200 => _200()]);
7347
7599
  },
7348
7600
  // onError
7349
7601
  (error) => {
7350
- _optionalChain([onError, 'optionalCall', _197 => _197(error)]);
7351
- _optionalChain([onStreamEnd, 'optionalCall', _198 => _198()]);
7602
+ _optionalChain([onError, 'optionalCall', _201 => _201(error)]);
7603
+ _optionalChain([onStreamEnd, 'optionalCall', _202 => _202()]);
7352
7604
  }
7353
7605
  );
7354
7606
  } catch (error) {
7355
- _optionalChain([onError, 'optionalCall', _199 => _199(error instanceof Error ? error : new Error("Unknown error"))]);
7356
- _optionalChain([onStreamEnd, 'optionalCall', _200 => _200()]);
7607
+ _optionalChain([onError, 'optionalCall', _203 => _203(error instanceof Error ? error : new Error("Unknown error"))]);
7608
+ _optionalChain([onStreamEnd, 'optionalCall', _204 => _204()]);
7357
7609
  }
7358
7610
  }, [agentId, context, onInterface, onUpdates, onError, onStreamStart, onStreamEnd]);
7359
7611
  return {
@@ -7399,5 +7651,6 @@ function useInterfaceAI({
7399
7651
 
7400
7652
 
7401
7653
 
7402
- exports.AptevaClient = AptevaClient; exports.AutoInterface = AutoInterface; exports.Button = Button; exports.Card = Card; exports.Chat = Chat; exports.Command = Command; exports.InterfaceRenderer = InterfaceRenderer; exports.InterfaceSkeleton = InterfaceSkeleton; exports.Kpi = Kpi; exports.LayoutRenderer = LayoutRenderer; exports.List = List; exports.LiveView = LiveView; exports.PersistentWidgetPanel = PersistentWidgetPanel; exports.Prompt = Prompt; exports.Spacer = Spacer; exports.Stream = Stream; exports.TextBlock = TextBlock; exports.Threads = Threads; exports.Widgets = Widgets; exports.applyUpdate = applyUpdate; exports.applyUpdates = applyUpdates; exports.aptevaClient = aptevaClient; exports.cn = cn; exports.containsInterface = containsInterface; exports.convertApiMessages = convertApiMessages; exports.findNode = findNode; exports.generateCompactInterfaceContext = generateCompactInterfaceContext; exports.generateInterfaceContext = generateInterfaceContext; exports.getThemeScript = getThemeScript; exports.mockMessages = mockMessages; exports.mockThreads = mockThreads; exports.mockWidgets = mockWidgets; exports.parseInterfaceFromText = parseInterfaceFromText; exports.parseUpdatesFromText = parseUpdatesFromText; exports.stripInterface = stripInterface; exports.useInterfaceAI = useInterfaceAI; exports.useInterfaceState = useInterfaceState;
7654
+
7655
+ exports.AptevaClient = AptevaClient; exports.AutoInterface = AutoInterface; exports.Button = Button; exports.Call = Call; exports.Card = Card; exports.Chat = Chat; exports.Command = Command; exports.InterfaceRenderer = InterfaceRenderer; exports.InterfaceSkeleton = InterfaceSkeleton; exports.Kpi = Kpi; exports.LayoutRenderer = LayoutRenderer; exports.List = List; exports.LiveView = LiveView; exports.PersistentWidgetPanel = PersistentWidgetPanel; exports.Prompt = Prompt; exports.Spacer = Spacer; exports.Stream = Stream; exports.TextBlock = TextBlock; exports.Threads = Threads; exports.Widgets = Widgets; exports.applyUpdate = applyUpdate; exports.applyUpdates = applyUpdates; exports.aptevaClient = aptevaClient; exports.cn = cn; exports.containsInterface = containsInterface; exports.convertApiMessages = convertApiMessages; exports.findNode = findNode; exports.generateCompactInterfaceContext = generateCompactInterfaceContext; exports.generateInterfaceContext = generateInterfaceContext; exports.getThemeScript = getThemeScript; exports.mockMessages = mockMessages; exports.mockThreads = mockThreads; exports.mockWidgets = mockWidgets; exports.parseInterfaceFromText = parseInterfaceFromText; exports.parseUpdatesFromText = parseUpdatesFromText; exports.stripInterface = stripInterface; exports.useInterfaceAI = useInterfaceAI; exports.useInterfaceState = useInterfaceState;
7403
7656
  //# sourceMappingURL=index.js.map