@allmodels/dsh-speech 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/client.js +37 -2
  2. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -408,6 +408,12 @@ var SpeechController = class {
408
408
  }, 5e3);
409
409
  await stoppingCapture;
410
410
  }
411
+ cancel() {
412
+ const active = this.active;
413
+ if (active === void 0 || active.finished) return;
414
+ active.inputActions.setDraft(active.draft);
415
+ this.finish(active);
416
+ }
411
417
  async switchMicrophone(deviceId) {
412
418
  const active = this.active;
413
419
  if (active === void 0 || active.finished || this.snapshot.phase !== "recording") return;
@@ -660,6 +666,7 @@ const styles = {
660
666
  recordingTakeover: "dsh-speech-recording-takeover",
661
667
  recordingTrack: "dsh-speech-recording-track",
662
668
  recordingCanvas: "dsh-speech-recording-canvas",
669
+ recordingCancel: "dsh-speech-recording-cancel",
663
670
  recordingStop: "dsh-speech-recording-stop",
664
671
  recordingProgress: "dsh-speech-recording-progress",
665
672
  deviceDock: "dsh-speech-device-dock",
@@ -692,7 +699,7 @@ const STYLE_TEXT = String.raw`
692
699
  .dsh-speech-primary,.dsh-speech-secondary,.dsh-speech-checkout{border:1px solid transparent;border-radius:8px;padding:8px 12px;font:inherit;font-size:13px;font-weight:600;cursor:pointer;text-decoration:none;text-align:center}.dsh-speech-primary{background:#e8e8e8;color:#151515}.dsh-speech-secondary,.dsh-speech-checkout{border-color:var(--color-border,#4a4a4a);background:transparent;color:inherit}.dsh-speech-primary:disabled,.dsh-speech-secondary:disabled{cursor:default;opacity:.45}.dsh-speech-good{color:#65c88a}.dsh-speech-warning{margin:0;color:#efb85c}.dsh-speech-danger,.dsh-speech-dock-error{margin:0;color:#f07878}
693
700
  .dsh-speech-top-up{justify-content:flex-start;align-items:end;flex-wrap:wrap}.dsh-speech-top-up .dsh-speech-field{max-width:180px}
694
701
  .dsh-speech-mic-wrap{position:relative;display:inline-flex;align-items:center;gap:5px;order:1}[data-slot="conversation.input.right"]:has(>.dsh-speech-mic-wrap)~button:last-child{order:2}.dsh-speech-mic{width:30px;height:30px;display:inline-grid;place-items:center;padding:0;border:0;border-radius:7px;background:transparent;color:var(--color-text-secondary,#a8a8a8);cursor:pointer}.dsh-speech-mic:hover:not(:disabled),.dsh-speech-mic:focus-visible{background:var(--color-background-hover,rgba(255,255,255,.08));color:var(--color-text,#eee)}.dsh-speech-mic[aria-disabled="true"]{opacity:.48}.dsh-speech-mic:disabled{cursor:default}.dsh-speech-mic svg{width:18px;height:18px;fill:currentColor}.dsh-speech-mic-active{color:#ef6666;background:rgba(239,102,102,.12)}.dsh-speech-mic-tooltip{position:absolute;right:0;bottom:calc(100% + 8px);z-index:40;width:max-content;max-width:260px;padding:6px 9px;border:1px solid var(--color-border,#343434);border-radius:7px;background:var(--color-background-elevated,#202020);color:var(--color-text,#eee);font-size:12px;line-height:1.35;box-shadow:0 6px 18px rgba(0,0,0,.24);opacity:0;visibility:hidden;transform:translateY(2px);pointer-events:none;transition:opacity .12s ease,transform .12s ease,visibility .12s}.dsh-speech-mic-wrap:hover .dsh-speech-mic-tooltip,.dsh-speech-mic-wrap:focus-within .dsh-speech-mic-tooltip,.dsh-speech-mic-wrap[data-explanation-open="true"] .dsh-speech-mic-tooltip{opacity:1;visibility:visible;transform:translateY(0)}
695
- :where(div):has(>:where(div)>[data-slot="conversation.input.right"]>.dsh-speech-recording-takeover){position:relative}:where(div):has(>:where(div)>[data-slot="conversation.input.right"]>.dsh-speech-recording-takeover)>*{visibility:hidden}.dsh-speech-recording-takeover{position:absolute;inset:0;z-index:8;visibility:visible;display:flex;align-items:center;gap:10px;padding:4px 8px;box-sizing:border-box;color:var(--color-text-secondary,#a8a8a8)}.dsh-speech-recording-track{height:30px;min-width:0;flex:1;display:flex;align-items:center}.dsh-speech-recording-canvas{display:block;width:100%;height:30px;color:var(--color-text-secondary,#a8a8a8)}.dsh-speech-recording-stop{flex:none;border-radius:999px;color:#ef6666;background:rgba(239,102,102,.12)}.dsh-speech-recording-stop:hover:not(:disabled),.dsh-speech-recording-stop:focus-visible{color:#ff7777;background:rgba(239,102,102,.2)}.dsh-speech-recording-progress{display:flex;align-items:center;justify-content:flex-end;gap:8px;width:100%;color:var(--color-text-secondary,#a8a8a8);font-size:12px}.dsh-speech-recording-takeover[data-phase="starting"] .dsh-speech-recording-progress{justify-content:center}.dsh-speech-recording-progress i{width:13px;height:13px;border:2px solid currentColor;border-right-color:transparent;border-radius:50%;animation:dsh-speech-spin .8s linear infinite}.dsh-speech-sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}@keyframes dsh-speech-spin{to{transform:rotate(360deg)}}
702
+ :where(div):has(>:where(div)>[data-slot="conversation.input.right"]>.dsh-speech-recording-takeover){position:relative}:where(div):has(>:where(div)>[data-slot="conversation.input.right"]>.dsh-speech-recording-takeover)>*{visibility:hidden}.dsh-speech-recording-takeover{position:absolute;inset:0;z-index:8;visibility:visible;display:flex;align-items:center;gap:10px;padding:4px 8px;box-sizing:border-box;color:var(--color-text-secondary,#a8a8a8)}.dsh-speech-recording-track{height:30px;min-width:0;flex:1;display:flex;align-items:center}.dsh-speech-recording-canvas{display:block;width:100%;height:30px;color:var(--color-text-secondary,#a8a8a8)}.dsh-speech-recording-cancel,.dsh-speech-recording-stop{flex:none;border-radius:999px}.dsh-speech-recording-cancel{color:var(--color-text-secondary,#a8a8a8);background:transparent}.dsh-speech-recording-cancel:hover:not(:disabled),.dsh-speech-recording-cancel:focus-visible{background:var(--color-background-hover,rgba(255,255,255,.08));color:var(--color-text,#eee)}.dsh-speech-recording-stop{color:#ef6666;background:rgba(239,102,102,.12)}.dsh-speech-recording-stop:hover:not(:disabled),.dsh-speech-recording-stop:focus-visible{color:#ff7777;background:rgba(239,102,102,.2)}.dsh-speech-recording-progress{display:flex;align-items:center;justify-content:flex-end;gap:8px;width:100%;color:var(--color-text-secondary,#a8a8a8);font-size:12px}.dsh-speech-recording-takeover[data-phase="starting"] .dsh-speech-recording-progress{justify-content:center}.dsh-speech-recording-progress i{width:13px;height:13px;border:2px solid currentColor;border-right-color:transparent;border-radius:50%;animation:dsh-speech-spin .8s linear infinite}.dsh-speech-sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}@keyframes dsh-speech-spin{to{transform:rotate(360deg)}}
696
703
  .dsh-speech-device-marker{display:none}[data-slot="conversation.composer.dock"]>:has(>.dsh-speech-device-dock){overflow:visible}.dsh-speech-device-fallback{min-height:22px;display:flex;align-items:center;justify-content:flex-start;padding:0 8px;overflow:visible}.dsh-speech-device-fallback .dsh-speech-device-dock{margin-left:0}.dsh-speech-device-separator{margin-left:4px;color:var(--dsw-alias-label-tertiary,var(--color-text-secondary,#888))}.dsh-speech-device-dock{position:relative;display:inline-flex;vertical-align:middle;margin-left:5px;color:var(--dsw-alias-label-secondary,var(--color-text-secondary,#a8a8a8));font:inherit}.dsh-speech-device-trigger{max-width:126px;height:20px;display:inline-flex;align-items:center;gap:4px;padding:0 5px;border:0;border-radius:6px;background:transparent;color:inherit;font:inherit;font-size:11px;line-height:20px;cursor:pointer}.dsh-speech-device-trigger:hover,.dsh-speech-device-trigger:focus-visible,.dsh-speech-device-trigger[aria-expanded="true"]{outline:0;background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.08));color:var(--dsw-alias-label-primary,var(--color-text,#eee))}.dsh-speech-device-trigger:disabled{cursor:wait;opacity:.6}.dsh-speech-device-dock[data-error="true"] .dsh-speech-device-trigger{color:var(--dsw-alias-state-error-primary,#f07878)}.dsh-speech-device-icon,.dsh-speech-device-chevron{display:inline-flex;flex:none}.dsh-speech-device-icon svg{width:12px;height:12px}.dsh-speech-device-chevron svg{width:10px;height:10px}.dsh-speech-device-label{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dsh-speech-device-menu{position:absolute;right:0;bottom:calc(100% + 6px);z-index:80;min-width:240px;max-width:min(320px,calc(100vw - 32px));display:grid;box-sizing:border-box;padding:4px;border:1px solid var(--dsw-alias-border-l2-darkmode-thin,rgba(255,255,255,.06));border-radius:12px;background:var(--dsw-alias-bg-layer-3,#353638);color:var(--dsw-alias-label-primary,#f9fafb);box-shadow:0 0 1px rgba(0,0,0,.2),0 0 4px rgba(0,0,0,.02),0 12px 32px rgba(0,0,0,.08);font:13px/20px -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif}.dsh-speech-device-menu-item{width:100%;min-width:0;height:38px;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:0 10px;border:0;border-radius:10px;background:transparent;color:inherit;font:inherit;text-align:left;cursor:pointer}.dsh-speech-device-menu-item:hover,.dsh-speech-device-menu-item:focus-visible{outline:0;background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.08))}.dsh-speech-device-menu-item>span:first-child{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dsh-speech-device-check{width:14px;height:14px;display:inline-flex;flex:none;color:var(--dsw-alias-brand-primary,var(--dsw-alias-label-primary,#f9fafb))}.dsh-speech-device-check svg{width:14px;height:14px}.dsh-speech-device-dock[data-variant="hero"]{margin-left:0;color:var(--dsw-alias-label-primary,var(--color-text,#f9fafb));font:500 13px/20px -apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Hiragino Sans GB","Microsoft YaHei","Helvetica Neue",Helvetica,Arial,sans-serif}.dsh-speech-device-dock[data-variant="hero"] .dsh-speech-device-trigger{max-width:220px;height:28px;padding:0 8px;gap:4px;border-radius:16px;font:inherit;line-height:20px}.dsh-speech-device-dock[data-variant="hero"] .dsh-speech-device-icon svg{width:16px;height:16px}.dsh-speech-device-dock[data-variant="hero"] .dsh-speech-device-chevron svg{width:14px;height:14px}.dsh-speech-device-dock[data-variant="hero"] .dsh-speech-device-menu{left:0;right:auto;top:calc(100% + 6px);bottom:auto;min-width:218px}
697
704
  [data-dsh-speech-nav]>svg{display:none}[data-dsh-speech-nav]::before{content:"";width:16px;height:16px;flex:none;background:currentColor;mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Crect x='7' y='2' width='6' height='11' rx='3' fill='none' stroke='black' stroke-width='1.7'/%3E%3Cpath d='M4.5 9.5a5.5 5.5 0 0 0 11 0M10 15v3M7 18h6' fill='none' stroke='black' stroke-width='1.7' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat}
698
705
  .dsh-speech-dock,.dsh-speech-dock-error{min-height:22px;display:flex;align-items:center;gap:9px;padding:4px 8px 0;font-size:12px}.dsh-speech-dock-detail{color:var(--color-text-secondary,#8d8d8d)}
@@ -762,6 +769,19 @@ function CheckIcon() {
762
769
  })
763
770
  });
764
771
  }
772
+ function CloseIcon() {
773
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
774
+ viewBox: "0 0 20 20",
775
+ "aria-hidden": "true",
776
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
777
+ d: "m5.5 5.5 9 9m0-9-9 9",
778
+ fill: "none",
779
+ stroke: "currentColor",
780
+ strokeWidth: "1.7",
781
+ strokeLinecap: "round"
782
+ })
783
+ });
784
+ }
765
785
  const WAVEFORM_PITCH = 4;
766
786
  const WAVEFORM_BASELINE = .025;
767
787
  function RecordingWaveform({ amplitude }) {
@@ -831,12 +851,21 @@ function RecordingWaveform({ amplitude }) {
831
851
  "aria-hidden": "true"
832
852
  });
833
853
  }
834
- function RecordingTakeover({ amplitude, disabled, phase, label, onStop, stopLabel }) {
854
+ function RecordingTakeover({ amplitude, cancelLabel, disabled, phase, label, onCancel, onStop, stopLabel }) {
835
855
  const recording = phase === "recording";
836
856
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
837
857
  className: styles.recordingTakeover,
838
858
  "data-phase": phase,
839
859
  children: [
860
+ recording ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
861
+ type: "button",
862
+ className: `${styles.mic} ${styles.recordingCancel}`,
863
+ disabled,
864
+ "aria-label": cancelLabel,
865
+ title: cancelLabel,
866
+ onClick: onCancel,
867
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CloseIcon, {})
868
+ }) : null,
840
869
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
841
870
  className: styles.recordingTrack,
842
871
  children: recording ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RecordingWaveform, { amplitude }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
@@ -907,9 +936,13 @@ function SpeechMic({ controller, getLocale, sessionId, input, inputActions, t })
907
936
  const takeoverPhase = state.phase === "starting" || state.phase === "finalizing" ? state.phase : "recording";
908
937
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RecordingTakeover, {
909
938
  amplitude: state.amplitude,
939
+ cancelLabel: t("micCancel"),
910
940
  disabled,
911
941
  phase: takeoverPhase,
912
942
  label: state.phase === "starting" ? t("starting") : state.phase === "finalizing" ? t("finalizing") : t("listening"),
943
+ onCancel: () => {
944
+ controller.cancel();
945
+ },
913
946
  onStop: toggle,
914
947
  stopLabel: title
915
948
  });
@@ -1619,6 +1652,7 @@ const en = {
1619
1652
  saved: "Saved",
1620
1653
  micStart: "Start voice input",
1621
1654
  micStop: "Stop voice input",
1655
+ micCancel: "Cancel voice input",
1622
1656
  starting: "Preparing microphone…",
1623
1657
  listening: "Listening…",
1624
1658
  finalizing: "Finishing transcription…",
@@ -1680,6 +1714,7 @@ const zh = {
1680
1714
  saved: "已保存",
1681
1715
  micStart: "开始语音输入",
1682
1716
  micStop: "停止语音输入",
1717
+ micCancel: "取消语音输入",
1683
1718
  starting: "正在准备麦克风…",
1684
1719
  listening: "正在聆听…",
1685
1720
  finalizing: "正在完成转写…",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allmodels/dsh-speech",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Streaming speech-to-text for DeepSeek Harness using AllModels.io.",
5
5
  "keywords": [
6
6
  "dsh-plugin",