@helpai/elements 0.59.0 → 0.59.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.
package/index.mjs CHANGED
@@ -29,7 +29,7 @@ var BRAND = {
29
29
  };
30
30
 
31
31
  // src/core/version.ts
32
- var ELEMENTS_VERSION = true ? "0.59.0" : "0.0.0-dev";
32
+ var ELEMENTS_VERSION = true ? "0.59.1" : "0.0.0-dev";
33
33
  var ELEMENTS_VERSION_PARAM = "_ev";
34
34
 
35
35
  // src/i18n/strings.ts
@@ -2149,6 +2149,22 @@ var DEFAULT_PATHS = {
2149
2149
  submitForm: "/pai/submit-form"
2150
2150
  };
2151
2151
  var CONTEXT_PARAM = "context";
2152
+ function parseSuggestions(data) {
2153
+ const raw = data?.suggestions;
2154
+ if (!Array.isArray(raw)) return [];
2155
+ const out = [];
2156
+ for (const item of raw) {
2157
+ if (!item || typeof item !== "object") continue;
2158
+ const { id, label, text } = item;
2159
+ if (typeof label !== "string" || !label) continue;
2160
+ out.push({
2161
+ id: typeof id === "string" && id ? id : `s${out.length}`,
2162
+ label,
2163
+ text: typeof text === "string" && text ? text : label
2164
+ });
2165
+ }
2166
+ return out;
2167
+ }
2152
2168
  function buildSendMessageRequest(params) {
2153
2169
  const wire = params.messages.map((m) => ({
2154
2170
  // Use the backend's id when known (adopted from the stream's `start` chunk)
@@ -2240,6 +2256,15 @@ function retryAfterMs(headers) {
2240
2256
  const ms = Number.isFinite(secs) ? secs * 1e3 : Date.parse(raw) - Date.now();
2241
2257
  return Number.isFinite(ms) && ms >= 0 ? Math.min(ms, 3e4) : null;
2242
2258
  }
2259
+ function followupsFromMessages(messages) {
2260
+ for (let i = messages.length - 1; i >= 0; i--) {
2261
+ const m = messages[i];
2262
+ if (!m || m.role !== "assistant") continue;
2263
+ const part = m.parts.find((p36) => p36.type === "data-suggestions");
2264
+ return part?.type === "data-suggestions" ? parseSuggestions(part.data) : void 0;
2265
+ }
2266
+ return void 0;
2267
+ }
2243
2268
  function sleep(ms, signal7) {
2244
2269
  return new Promise((resolve) => {
2245
2270
  if (signal7?.aborted) return resolve();
@@ -2486,7 +2511,10 @@ var AgentTransport = class {
2486
2511
  canContinue: res.canContinue ?? true,
2487
2512
  messages,
2488
2513
  agent: res.agent,
2489
- suggestions: res.suggestions
2514
+ // The latest turn's model follow-ups are persisted ON the assistant message (a `data-suggestions`
2515
+ // part), not in a top-level field — read them off there, falling back to any server-provided
2516
+ // top-level `suggestions` (e.g. resume chips) when the last turn carried none.
2517
+ suggestions: followupsFromMessages(messages) ?? res.suggestions
2490
2518
  };
2491
2519
  }
2492
2520
  /**
@@ -2726,6 +2754,7 @@ var AgentTransport = class {
2726
2754
  * (a drop), so the caller can attempt a resume.
2727
2755
  */
2728
2756
  async *drain(source, seenIds, ctrl) {
2757
+ let terminal = false;
2729
2758
  try {
2730
2759
  for await (const evt of source) {
2731
2760
  if (ctrl.signal.aborted) return true;
@@ -2734,14 +2763,14 @@ var AgentTransport = class {
2734
2763
  seenIds.add(evt.eventId);
2735
2764
  }
2736
2765
  yield evt;
2737
- if (evt.chunk.type === "finish" || evt.chunk.type === "error") return true;
2766
+ if (evt.chunk.type === "finish" || evt.chunk.type === "error") terminal = true;
2738
2767
  }
2739
2768
  } catch (err) {
2740
2769
  if (ctrl.signal.aborted) return true;
2741
2770
  if (err instanceof StreamError && err.status !== void 0) throw err;
2742
2771
  log6.debug("stream segment dropped", { err });
2743
2772
  }
2744
- return false;
2773
+ return terminal;
2745
2774
  }
2746
2775
  /** Abort + fire-and-forget POST to `/pai/cancel-stream`. Idempotent. */
2747
2776
  cancelStream(ctrl, conversationId) {
@@ -2969,6 +2998,9 @@ function fromWireMessage(w) {
2969
2998
  mediaType: part.mediaType
2970
2999
  };
2971
3000
  }
3001
+ if (part.type === "data-suggestions") {
3002
+ return null;
3003
+ }
2972
3004
  if (part.type.startsWith("tool-")) {
2973
3005
  return {
2974
3006
  kind: "tool",
@@ -6840,22 +6872,6 @@ function ConversationList({
6840
6872
  // src/ui/suggestions.tsx
6841
6873
  import { jsx as jsx22 } from "preact/jsx-runtime";
6842
6874
  var p19 = BRAND.cssPrefix;
6843
- function parseSuggestions(data) {
6844
- const raw = data?.suggestions;
6845
- if (!Array.isArray(raw)) return [];
6846
- const out = [];
6847
- for (const item of raw) {
6848
- if (!item || typeof item !== "object") continue;
6849
- const { id, label, text } = item;
6850
- if (typeof label !== "string" || !label) continue;
6851
- out.push({
6852
- id: typeof id === "string" && id ? id : `s${out.length}`,
6853
- label,
6854
- text: typeof text === "string" && text ? text : label
6855
- });
6856
- }
6857
- return out;
6858
- }
6859
6875
  function Suggestions({ suggestions, onPick }) {
6860
6876
  if (suggestions.length === 0) return null;
6861
6877
  return /* @__PURE__ */ jsx22("div", { class: `${p19}-suggestions`, role: "group", "aria-label": "Suggested replies", children: suggestions.map((s, i) => /* @__PURE__ */ jsx22(
package/package.json CHANGED
@@ -80,5 +80,5 @@
80
80
  ],
81
81
  "type": "module",
82
82
  "types": "./index.d.ts",
83
- "version": "0.59.0"
83
+ "version": "0.59.1"
84
84
  }
package/web-component.mjs CHANGED
@@ -1934,7 +1934,7 @@ function createAuth(opts) {
1934
1934
  }
1935
1935
 
1936
1936
  // src/core/version.ts
1937
- var ELEMENTS_VERSION = true ? "0.59.0" : "0.0.0-dev";
1937
+ var ELEMENTS_VERSION = true ? "0.59.1" : "0.0.0-dev";
1938
1938
  var ELEMENTS_VERSION_PARAM = "_ev";
1939
1939
 
1940
1940
  // src/stream/types.ts
@@ -2108,6 +2108,22 @@ var DEFAULT_PATHS = {
2108
2108
  submitForm: "/pai/submit-form"
2109
2109
  };
2110
2110
  var CONTEXT_PARAM = "context";
2111
+ function parseSuggestions(data) {
2112
+ const raw = data?.suggestions;
2113
+ if (!Array.isArray(raw)) return [];
2114
+ const out = [];
2115
+ for (const item of raw) {
2116
+ if (!item || typeof item !== "object") continue;
2117
+ const { id, label, text } = item;
2118
+ if (typeof label !== "string" || !label) continue;
2119
+ out.push({
2120
+ id: typeof id === "string" && id ? id : `s${out.length}`,
2121
+ label,
2122
+ text: typeof text === "string" && text ? text : label
2123
+ });
2124
+ }
2125
+ return out;
2126
+ }
2111
2127
  function buildSendMessageRequest(params) {
2112
2128
  const wire = params.messages.map((m) => ({
2113
2129
  // Use the backend's id when known (adopted from the stream's `start` chunk)
@@ -2199,6 +2215,15 @@ function retryAfterMs(headers) {
2199
2215
  const ms = Number.isFinite(secs) ? secs * 1e3 : Date.parse(raw) - Date.now();
2200
2216
  return Number.isFinite(ms) && ms >= 0 ? Math.min(ms, 3e4) : null;
2201
2217
  }
2218
+ function followupsFromMessages(messages) {
2219
+ for (let i = messages.length - 1; i >= 0; i--) {
2220
+ const m = messages[i];
2221
+ if (!m || m.role !== "assistant") continue;
2222
+ const part = m.parts.find((p36) => p36.type === "data-suggestions");
2223
+ return part?.type === "data-suggestions" ? parseSuggestions(part.data) : void 0;
2224
+ }
2225
+ return void 0;
2226
+ }
2202
2227
  function sleep(ms, signal7) {
2203
2228
  return new Promise((resolve) => {
2204
2229
  if (signal7?.aborted) return resolve();
@@ -2445,7 +2470,10 @@ var AgentTransport = class {
2445
2470
  canContinue: res.canContinue ?? true,
2446
2471
  messages,
2447
2472
  agent: res.agent,
2448
- suggestions: res.suggestions
2473
+ // The latest turn's model follow-ups are persisted ON the assistant message (a `data-suggestions`
2474
+ // part), not in a top-level field — read them off there, falling back to any server-provided
2475
+ // top-level `suggestions` (e.g. resume chips) when the last turn carried none.
2476
+ suggestions: followupsFromMessages(messages) ?? res.suggestions
2449
2477
  };
2450
2478
  }
2451
2479
  /**
@@ -2685,6 +2713,7 @@ var AgentTransport = class {
2685
2713
  * (a drop), so the caller can attempt a resume.
2686
2714
  */
2687
2715
  async *drain(source, seenIds, ctrl) {
2716
+ let terminal = false;
2688
2717
  try {
2689
2718
  for await (const evt of source) {
2690
2719
  if (ctrl.signal.aborted) return true;
@@ -2693,14 +2722,14 @@ var AgentTransport = class {
2693
2722
  seenIds.add(evt.eventId);
2694
2723
  }
2695
2724
  yield evt;
2696
- if (evt.chunk.type === "finish" || evt.chunk.type === "error") return true;
2725
+ if (evt.chunk.type === "finish" || evt.chunk.type === "error") terminal = true;
2697
2726
  }
2698
2727
  } catch (err) {
2699
2728
  if (ctrl.signal.aborted) return true;
2700
2729
  if (err instanceof StreamError && err.status !== void 0) throw err;
2701
2730
  log5.debug("stream segment dropped", { err });
2702
2731
  }
2703
- return false;
2732
+ return terminal;
2704
2733
  }
2705
2734
  /** Abort + fire-and-forget POST to `/pai/cancel-stream`. Idempotent. */
2706
2735
  cancelStream(ctrl, conversationId) {
@@ -2928,6 +2957,9 @@ function fromWireMessage(w) {
2928
2957
  mediaType: part.mediaType
2929
2958
  };
2930
2959
  }
2960
+ if (part.type === "data-suggestions") {
2961
+ return null;
2962
+ }
2931
2963
  if (part.type.startsWith("tool-")) {
2932
2964
  return {
2933
2965
  kind: "tool",
@@ -6799,22 +6831,6 @@ function ConversationList({
6799
6831
  // src/ui/suggestions.tsx
6800
6832
  import { jsx as jsx22 } from "preact/jsx-runtime";
6801
6833
  var p19 = BRAND.cssPrefix;
6802
- function parseSuggestions(data) {
6803
- const raw = data?.suggestions;
6804
- if (!Array.isArray(raw)) return [];
6805
- const out = [];
6806
- for (const item of raw) {
6807
- if (!item || typeof item !== "object") continue;
6808
- const { id, label, text } = item;
6809
- if (typeof label !== "string" || !label) continue;
6810
- out.push({
6811
- id: typeof id === "string" && id ? id : `s${out.length}`,
6812
- label,
6813
- text: typeof text === "string" && text ? text : label
6814
- });
6815
- }
6816
- return out;
6817
- }
6818
6834
  function Suggestions({ suggestions, onPick }) {
6819
6835
  if (suggestions.length === 0) return null;
6820
6836
  return /* @__PURE__ */ jsx22("div", { class: `${p19}-suggestions`, role: "group", "aria-label": "Suggested replies", children: suggestions.map((s, i) => /* @__PURE__ */ jsx22(