@cadraos/sdk 0.3.15 → 0.3.16-dev.0

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.
@@ -1830,13 +1830,69 @@ function executionCancelPath(executionId) {
1830
1830
  return `${EXECUTION_PATH}/${executionId}/cancel`;
1831
1831
  }
1832
1832
 
1833
+ // src/utils/message-key.ts
1834
+ var MESSAGE_KEY_PATTERN = /^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+$/;
1835
+ function isValidMessageKey(key) {
1836
+ return MESSAGE_KEY_PATTERN.test(key);
1837
+ }
1838
+
1839
+ // src/resources/agent-messages.ts
1840
+ var AgentMessagesAPI = class extends BaseResourceAPI {
1841
+ constructor(http) {
1842
+ super(http, "/api/v1/agents");
1843
+ }
1844
+ /**
1845
+ * List an agent's saved messages and the known keys
1846
+ *
1847
+ * @param agentUuid - Agent UUID (a team UUID resolves to its lead agent)
1848
+ *
1849
+ * @example
1850
+ * ```typescript
1851
+ * const { messages, knownKeys } = await client.agents.messages.list('agent-uuid');
1852
+ * ```
1853
+ */
1854
+ async list(agentUuid) {
1855
+ return this.httpGet(`/${agentUuid}/messages`);
1856
+ }
1857
+ /**
1858
+ * Render one message with placeholders filled
1859
+ *
1860
+ * Resolves with `text: null` when the agent has no message for the key.
1861
+ * Throws `ValidationError` before any request when the key is not a
1862
+ * lowercase dotted key (see `MESSAGE_KEY_PATTERN`).
1863
+ *
1864
+ * @example
1865
+ * ```typescript
1866
+ * const { text } = await client.agents.messages.render('agent-uuid', 'handoff.requested', {
1867
+ * lang: 'es',
1868
+ * vars: { agentName: 'Ana' },
1869
+ * });
1870
+ * ```
1871
+ */
1872
+ async render(agentUuid, key, options = {}) {
1873
+ if (!isValidMessageKey(key)) {
1874
+ throw new ValidationError(`Invalid message key "${key}"`, [
1875
+ { field: "key", message: "Must be a lowercase dotted key, e.g. chat.welcome" }
1876
+ ]);
1877
+ }
1878
+ return this.httpPost(`/${agentUuid}/messages/render`, {
1879
+ key,
1880
+ ...options.lang ? { lang: options.lang } : {},
1881
+ ...options.vars ? { vars: options.vars } : {}
1882
+ });
1883
+ }
1884
+ };
1885
+
1833
1886
  // src/resources/agents.ts
1834
1887
  var AgentsAPI = class extends BaseResourceAPI {
1835
1888
  constructor(http, getStreamConfig) {
1836
1889
  super(http, "/api/v1/agents");
1837
1890
  this.getStreamConfig = getStreamConfig;
1891
+ this.messages = new AgentMessagesAPI(http);
1838
1892
  }
1839
1893
  getStreamConfig;
1894
+ /** Saved agent messages (p13): `list()` and `render()` */
1895
+ messages;
1840
1896
  // ===== LIST Operations =====
1841
1897
  /**
1842
1898
  * List all agents in the organization
@@ -9610,6 +9666,106 @@ function useImageStream(options) {
9610
9666
  }, [client, providedExecutionId, agentUuid, inputKey, sessionId, shouldConnect]);
9611
9667
  return { images, status, error, executionId, output, cancel };
9612
9668
  }
9669
+ var DEFAULT_LABELS = {
9670
+ search: "Search messages",
9671
+ loading: "Loading messages",
9672
+ loadError: "Could not load messages",
9673
+ empty: "No matching messages",
9674
+ notSet: "not set",
9675
+ useCustom: (key) => `Use "${key}"`,
9676
+ invalidCustom: "Keys are lowercase and dotted, like chat.welcome"
9677
+ };
9678
+ function previewOf(message, lang) {
9679
+ return message.text[lang] ?? message.text.en ?? Object.values(message.text).find(Boolean) ?? null;
9680
+ }
9681
+ function AgentMessagePicker({
9682
+ client,
9683
+ agentUuid,
9684
+ value,
9685
+ onChange,
9686
+ allowCustom = false,
9687
+ lang = "en",
9688
+ labels: labelOverrides,
9689
+ className = ""
9690
+ }) {
9691
+ const labels = { ...DEFAULT_LABELS, ...labelOverrides };
9692
+ const [data, setData] = react.useState(null);
9693
+ const [error, setError] = react.useState(false);
9694
+ const [query, setQuery] = react.useState("");
9695
+ react.useEffect(() => {
9696
+ let cancelled = false;
9697
+ setData(null);
9698
+ setError(false);
9699
+ client.agents.messages.list(agentUuid).then((result) => {
9700
+ if (!cancelled) setData(result);
9701
+ }).catch(() => {
9702
+ if (!cancelled) setError(true);
9703
+ });
9704
+ return () => {
9705
+ cancelled = true;
9706
+ };
9707
+ }, [client, agentUuid]);
9708
+ const items = react.useMemo(() => {
9709
+ if (!data) return [];
9710
+ const saved = data.messages.map((m) => ({ key: m.key, preview: previewOf(m, lang) }));
9711
+ const savedKeys = new Set(saved.map((i) => i.key));
9712
+ const unsaved = data.knownKeys.filter((k) => !savedKeys.has(k)).sort().map((key) => ({ key, preview: null }));
9713
+ return [...saved, ...unsaved];
9714
+ }, [data, lang]);
9715
+ const needle = query.trim().toLowerCase();
9716
+ const visible = needle ? items.filter(
9717
+ (i) => i.key.includes(needle) || (i.preview?.toLowerCase().includes(needle) ?? false)
9718
+ ) : items;
9719
+ const custom = query.trim();
9720
+ const showCustom = allowCustom && custom.length > 0 && !items.some((i) => i.key === custom);
9721
+ const customValid = showCustom && isValidMessageKey(custom);
9722
+ 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
+ ),
9734
+ 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
+ /* @__PURE__ */ jsxRuntime.jsx(LoadingSpinner, { className: "h-4 w-4" }),
9736
+ labels.loading
9737
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs("ul", { role: "listbox", "aria-label": labels.search, className: "flex max-h-72 flex-col gap-0.5 overflow-y-auto", children: [
9738
+ visible.map((item) => {
9739
+ const selected = item.key === value;
9740
+ return /* @__PURE__ */ jsxRuntime.jsx("li", { role: "option", "aria-selected": selected, children: /* @__PURE__ */ jsxRuntime.jsxs(
9741
+ "button",
9742
+ {
9743
+ type: "button",
9744
+ onClick: () => onChange(item.key),
9745
+ className: `flex w-full items-start gap-2 rounded-lg px-3 py-2 text-left transition-colors ${selected ? "bg-blue-50 dark:bg-blue-900/30" : "hover:bg-gray-100 dark:hover:bg-gray-800"}`,
9746
+ children: [
9747
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex min-w-0 flex-1 flex-col", children: [
9748
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-mono text-xs text-gray-900 dark:text-gray-100", children: item.key }),
9749
+ item.preview !== null ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate text-gray-500 dark:text-gray-400", children: item.preview }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "italic text-gray-400 dark:text-gray-500", children: labels.notSet })
9750
+ ] }),
9751
+ selected && /* @__PURE__ */ jsxRuntime.jsx(CheckIcon, { className: "h-4 w-4 flex-shrink-0 text-blue-500" })
9752
+ ]
9753
+ }
9754
+ ) }, item.key);
9755
+ }),
9756
+ visible.length === 0 && !showCustom && /* @__PURE__ */ jsxRuntime.jsx("li", { className: "px-3 py-2 text-gray-500 dark:text-gray-400", children: labels.empty })
9757
+ ] }),
9758
+ data && showCustom && (customValid ? /* @__PURE__ */ jsxRuntime.jsx(
9759
+ "button",
9760
+ {
9761
+ type: "button",
9762
+ onClick: () => onChange(custom),
9763
+ className: "rounded-lg bg-gray-100 dark:bg-gray-800 px-3 py-2 text-left font-mono text-xs text-blue-600 dark:text-blue-400 hover:bg-gray-200 dark:hover:bg-gray-700",
9764
+ children: labels.useCustom(custom)
9765
+ }
9766
+ ) : /* @__PURE__ */ jsxRuntime.jsx("p", { className: "px-1 text-xs text-gray-500 dark:text-gray-400", children: labels.invalidCustom }))
9767
+ ] });
9768
+ }
9613
9769
  function cn13(...classes) {
9614
9770
  return classes.filter(Boolean).join(" ");
9615
9771
  }
@@ -9706,6 +9862,7 @@ function TodoList({
9706
9862
  }
9707
9863
 
9708
9864
  exports.AgentChat = AgentChat;
9865
+ exports.AgentMessagePicker = AgentMessagePicker;
9709
9866
  exports.AlertCircleIcon = AlertCircleIcon;
9710
9867
  exports.AskUserPrompt = AskUserPrompt;
9711
9868
  exports.BotIcon = BotIcon;
@@ -9738,6 +9895,7 @@ exports.ImageLightbox = ImageLightbox;
9738
9895
  exports.ImagesIcon = ImagesIcon;
9739
9896
  exports.ListTodoIcon = ListTodoIcon;
9740
9897
  exports.LoadingSpinner = LoadingSpinner;
9898
+ exports.MESSAGE_KEY_PATTERN = MESSAGE_KEY_PATTERN;
9741
9899
  exports.MarkdownContent = MarkdownContent;
9742
9900
  exports.Maximize2Icon = Maximize2Icon;
9743
9901
  exports.MessageCircleIcon = MessageCircleIcon;
@@ -9758,6 +9916,7 @@ exports.ZoomOutIcon = ZoomOutIcon;
9758
9916
  exports.compressImage = compressImage;
9759
9917
  exports.createDefaultAdapter = createDefaultAdapter;
9760
9918
  exports.isInternalTool = isInternalTool;
9919
+ exports.isValidMessageKey = isValidMessageKey;
9761
9920
  exports.useAgentChat = useAgentChat;
9762
9921
  exports.useChatConfig = useChatConfig;
9763
9922
  exports.useChatConfigOptional = useChatConfigOptional;