@cadraos/sdk 0.3.16-dev.0 → 0.3.16-dev.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.
@@ -1848,7 +1848,7 @@ var AgentMessagesAPI = class extends BaseResourceAPI {
1848
1848
  *
1849
1849
  * @example
1850
1850
  * ```typescript
1851
- * const { messages, knownKeys } = await client.agents.messages.list('agent-uuid');
1851
+ * const { messages, knownKeys, languages, defaultLanguage } = await client.agents.messages.list('agent-uuid');
1852
1852
  * ```
1853
1853
  */
1854
1854
  async list(agentUuid) {
@@ -9673,10 +9673,24 @@ var DEFAULT_LABELS = {
9673
9673
  empty: "No matching messages",
9674
9674
  notSet: "not set",
9675
9675
  useCustom: (key) => `Use "${key}"`,
9676
- invalidCustom: "Keys are lowercase and dotted, like chat.welcome"
9676
+ invalidCustom: "Keys are lowercase and dotted, like chat.welcome",
9677
+ language: "Preview language"
9677
9678
  };
9678
- function previewOf(message, lang) {
9679
- return message.text[lang] ?? message.text.en ?? Object.values(message.text).find(Boolean) ?? null;
9679
+ function previewOf(message, lang, defaultLanguage = "en") {
9680
+ const base = lang.split("-")[0] ?? lang;
9681
+ for (const candidate of [lang, base, defaultLanguage, "en"]) {
9682
+ const text = message.text[candidate];
9683
+ if (text) return text;
9684
+ }
9685
+ return Object.values(message.text).find((t) => Boolean(t)) ?? null;
9686
+ }
9687
+ function languagesOf(list) {
9688
+ if (list.languages && list.languages.length > 0) return list.languages;
9689
+ const seen = /* @__PURE__ */ new Set([list.defaultLanguage ?? "en"]);
9690
+ for (const m of list.messages) {
9691
+ for (const [code, text] of Object.entries(m.text)) if (text) seen.add(code);
9692
+ }
9693
+ return [...seen];
9680
9694
  }
9681
9695
  function AgentMessagePicker({
9682
9696
  client,
@@ -9684,7 +9698,8 @@ function AgentMessagePicker({
9684
9698
  value,
9685
9699
  onChange,
9686
9700
  allowCustom = false,
9687
- lang = "en",
9701
+ lang,
9702
+ onLangChange,
9688
9703
  labels: labelOverrides,
9689
9704
  className = ""
9690
9705
  }) {
@@ -9692,6 +9707,13 @@ function AgentMessagePicker({
9692
9707
  const [data, setData] = react.useState(null);
9693
9708
  const [error, setError] = react.useState(false);
9694
9709
  const [query, setQuery] = react.useState("");
9710
+ const [pickedLang, setPickedLang] = react.useState(null);
9711
+ react.useEffect(() => {
9712
+ setPickedLang(null);
9713
+ }, [lang, agentUuid]);
9714
+ const defaultLanguage = data?.defaultLanguage ?? "en";
9715
+ const languages = react.useMemo(() => data ? languagesOf(data) : [], [data]);
9716
+ const activeLang = pickedLang ?? lang ?? defaultLanguage;
9695
9717
  react.useEffect(() => {
9696
9718
  let cancelled = false;
9697
9719
  setData(null);
@@ -9707,11 +9729,14 @@ function AgentMessagePicker({
9707
9729
  }, [client, agentUuid]);
9708
9730
  const items = react.useMemo(() => {
9709
9731
  if (!data) return [];
9710
- const saved = data.messages.map((m) => ({ key: m.key, preview: previewOf(m, lang) }));
9732
+ const saved = data.messages.map((m) => ({
9733
+ key: m.key,
9734
+ preview: previewOf(m, activeLang, defaultLanguage)
9735
+ }));
9711
9736
  const savedKeys = new Set(saved.map((i) => i.key));
9712
9737
  const unsaved = data.knownKeys.filter((k) => !savedKeys.has(k)).sort().map((key) => ({ key, preview: null }));
9713
9738
  return [...saved, ...unsaved];
9714
- }, [data, lang]);
9739
+ }, [data, activeLang, defaultLanguage]);
9715
9740
  const needle = query.trim().toLowerCase();
9716
9741
  const visible = needle ? items.filter(
9717
9742
  (i) => i.key.includes(needle) || (i.preview?.toLowerCase().includes(needle) ?? false)
@@ -9719,18 +9744,34 @@ function AgentMessagePicker({
9719
9744
  const custom = query.trim();
9720
9745
  const showCustom = allowCustom && custom.length > 0 && !items.some((i) => i.key === custom);
9721
9746
  const customValid = showCustom && isValidMessageKey(custom);
9747
+ const languageChoices = languages.includes(activeLang) ? languages : [...languages, activeLang];
9722
9748
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex flex-col gap-2 text-sm ${className}`, children: [
9723
- /* @__PURE__ */ jsxRuntime.jsx(
9724
- "input",
9725
- {
9726
- type: "search",
9727
- value: query,
9728
- onChange: (e) => setQuery(e.target.value),
9729
- placeholder: labels.search,
9730
- "aria-label": labels.search,
9731
- className: "w-full rounded-lg bg-gray-100 dark:bg-gray-800 px-3 py-2 text-gray-900 dark:text-gray-100 placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500"
9732
- }
9733
- ),
9749
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
9750
+ /* @__PURE__ */ jsxRuntime.jsx(
9751
+ "input",
9752
+ {
9753
+ type: "search",
9754
+ value: query,
9755
+ onChange: (e) => setQuery(e.target.value),
9756
+ placeholder: labels.search,
9757
+ "aria-label": labels.search,
9758
+ className: "w-full min-w-0 flex-1 rounded-lg bg-gray-100 dark:bg-gray-800 px-3 py-2 text-gray-900 dark:text-gray-100 placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500"
9759
+ }
9760
+ ),
9761
+ data && languages.length > 1 && /* @__PURE__ */ jsxRuntime.jsx(
9762
+ "select",
9763
+ {
9764
+ value: activeLang,
9765
+ onChange: (e) => {
9766
+ setPickedLang(e.target.value);
9767
+ onLangChange?.(e.target.value);
9768
+ },
9769
+ "aria-label": labels.language,
9770
+ className: "rounded-lg bg-gray-100 dark:bg-gray-800 px-2 py-2 font-mono text-xs text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500",
9771
+ children: languageChoices.map((code) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: code, children: code }, code))
9772
+ }
9773
+ )
9774
+ ] }),
9734
9775
  error ? /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", className: "px-1 text-red-500", children: labels.loadError }) : !data ? /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "flex items-center gap-2 px-1 text-gray-500 dark:text-gray-400", children: [
9735
9776
  /* @__PURE__ */ jsxRuntime.jsx(LoadingSpinner, { className: "h-4 w-4" }),
9736
9777
  labels.loading