@ai4b-team/fsaos-gateway-sdk 4.2.0 → 4.2.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/dist/iife/ui.js CHANGED
@@ -1,3 +1,3 @@
1
- /* @fsaos/ui v2.0.0 — FSAOS UI Primitives — 2026-10-31T01:05:49.771Z */
1
+ /* @fsaos/ui v2.0.0 — FSAOS UI Primitives — 2026-11-04T20:43:58.926Z */
2
2
  "use strict";var __FSAOS_UI__=(()=>{var m=Object.create;var r=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var y=(e,i)=>()=>(i||e((i={exports:{}}).exports,i),i.exports),N=(e,i)=>{for(var a in i)r(e,a,{get:i[a],enumerable:!0})},s=(e,i,a,l)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of u(i))!h.call(e,t)&&t!==a&&r(e,t,{get:()=>i[t],enumerable:!(l=g(i,t))||l.enumerable});return e};var x=(e,i,a)=>(a=e!=null?m(f(e)):{},s(i||!e||!e.__esModule?r(a,"default",{value:e,enumerable:!0}):a,e)),b=e=>s(r({},"__esModule",{value:!0}),e);var d=y((V,c)=>{c.exports=React});var P={};N(P,{Badge:()=>z,Breadcrumbs:()=>A,Button:()=>D,Card:()=>w,DataView:()=>R,Detail:()=>_,Empty:()=>I,FilePreview:()=>O,Form:()=>F,Grid:()=>k,Image:()=>G,Link:()=>E,Page:()=>v,Router:()=>T,Sidebar:()=>S,Spinner:()=>B,Stack:()=>C,Table:()=>j,Tabs:()=>W,Video:()=>H});var n=x(d(),1);function o(){return(typeof window<"u"&&window.__FSAOS_CONFIG__||{}).edgeBaseUrl||""}function v(e){return(0,n.createElement)("div",{style:{minHeight:"100vh",display:"flex",flexDirection:"column"},className:e.className||""},e.children)}function C(e){let i=e.direction||"vertical";return(0,n.createElement)("div",{style:{display:"flex",flexDirection:i==="horizontal"?"row":"column",gap:e.gap||"0.5rem",padding:e.padding||"0",alignItems:e.align||"stretch",justifyContent:e.justify||"flex-start",flex:e.flex||"initial"},className:e.className||""},e.children)}function k(e){return(0,n.createElement)("div",{style:{display:"grid",gridTemplateColumns:"repeat("+(e.columns||3)+", 1fr)",gap:e.gap||"1rem",padding:e.padding||"0"},className:e.className||""},e.children)}function S(e){return(0,n.createElement)("div",{style:{display:"flex",flexDirection:"row",minHeight:"100vh"},className:e.className||""},e.children)}function w(e){return(0,n.createElement)("div",{style:{border:"1px solid var(--color-border, #e5e7eb)",borderRadius:"var(--border-radius, 0.5rem)",padding:e.padding||"1rem",background:"var(--color-surface, #fff)"},className:e.className||"",onClick:e.onClick},e.children)}function z(e){return(0,n.createElement)("span",{style:{display:"inline-flex",alignItems:"center",padding:"0.125rem 0.5rem",fontSize:"0.75rem",fontWeight:"500",borderRadius:"9999px",background:e.color||"#e5e7eb",color:e.textColor||"#374151"},className:e.className||""},e.children||e.label)}function B(e){let i=e.size||"1.5rem";return(0,n.createElement)("div",{style:{width:i,height:i,border:"2px solid #e5e7eb",borderTopColor:"var(--color-primary, #3b82f6)",borderRadius:"50%",animation:"fsaos-spin 0.6s linear infinite"}})}function D(e){return(0,n.createElement)("button",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"0.5rem 1rem",fontSize:"0.875rem",fontWeight:"500",borderRadius:"var(--border-radius, 0.375rem)",border:e.variant==="outline"?"1px solid var(--color-border, #d1d5db)":"none",background:e.variant==="outline"||e.variant==="ghost"?"transparent":"var(--color-primary, #3b82f6)",color:e.variant==="outline"||e.variant==="ghost"?"var(--color-text, #1a1a1a)":"#fff",cursor:e.disabled?"not-allowed":"pointer",opacity:e.disabled?"0.5":"1",gap:"0.5rem"},className:e.className||"",onClick:e.onClick,disabled:e.disabled},e.children||e.label)}function I(e){return(0,n.createElement)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"3rem",color:"var(--color-text-secondary, #6b7280)",textAlign:"center"}},e.icon?(0,n.createElement)("div",{style:{fontSize:"2rem",marginBottom:"0.5rem"}},e.icon):null,(0,n.createElement)("div",{style:{fontWeight:500,marginBottom:"0.25rem"}},e.title||e.message||e.children||"No items"),e.description?(0,n.createElement)("div",{style:{fontSize:"0.875rem",opacity:.7}},e.description):null)}function R(e){return(0,n.createElement)("div",{className:e.className||""},e.children)}function j(e){return(0,n.createElement)("table",{className:e.className||""},e.children)}function F(e){return(0,n.createElement)("form",{className:e.className||"",onSubmit:e.onSubmit},e.children)}function _(e){return(0,n.createElement)("div",{className:e.className||""},e.children)}function T(e){return(0,n.createElement)("div",null,e.children)}function E(e){return(0,n.createElement)("a",{href:e.href||e.to,className:e.className||"",onClick:e.onClick},e.children)}function W(e){return(0,n.createElement)("div",{className:e.className||""},e.children)}function A(e){return(0,n.createElement)("nav",{className:e.className||""},e.children)}function G(e){return(0,n.createElement)("img",{src:e.src||(e.path?o()+e.path:""),alt:e.alt||"",className:e.className||"",style:e.style})}function H(e){return(0,n.createElement)("video",{src:e.src||(e.path?o()+e.path:""),controls:!0,className:e.className||""})}function O(e){return(0,n.createElement)("div",{className:e.className||""},e.children||"File preview")}return b(P);})();
3
3
  //# sourceMappingURL=ui.js.map
package/dist/index.cjs CHANGED
@@ -2111,7 +2111,7 @@ async function fetchChannelMessages(channelPath, parentMessageId) {
2111
2111
  `[gateway] Failed to fetch channel messages for ${channelPath}:`,
2112
2112
  err
2113
2113
  );
2114
- return [];
2114
+ throw err;
2115
2115
  }
2116
2116
  }
2117
2117
  async function fetchChannelMessagesWithCards(channelPath, parentMessageId) {
@@ -2146,18 +2146,22 @@ async function fetchChannelMessagesWithCards(channelPath, parentMessageId) {
2146
2146
  `[gateway] Failed to fetch channel messages with cards for ${channelPath}:`,
2147
2147
  err
2148
2148
  );
2149
- return { messages: [], messageCards: /* @__PURE__ */ new Map(), siblingCards: [], mode: "top_level" };
2149
+ throw err;
2150
2150
  }
2151
2151
  }
2152
2152
  async function fetchChannelMessagesPage(channelPath, options) {
2153
2153
  try {
2154
2154
  const params = { channel_path: channelPath };
2155
2155
  if (options?.parentMessageId) params.parent_message_id = options.parentMessageId;
2156
+ if (options?.conversationsOnly) params.conversations_only = true;
2156
2157
  if (options?.limit) params.limit = options.limit;
2157
2158
  if (options?.before_seq != null) params.before_seq = options.before_seq;
2158
2159
  if (options?.after_seq != null) params.after_seq = options.after_seq;
2159
2160
  const response = await gatewayCall("get-channel-messages", params);
2160
2161
  const raw = response;
2162
+ if (options?.conversationsOnly && raw.conversations_only !== true) {
2163
+ throw new Error("This server does not support conversation history lists yet. Update the message reader.");
2164
+ }
2161
2165
  const items = raw.messages || [];
2162
2166
  const cards = parseChannelCards(items);
2163
2167
  const messageCards = /* @__PURE__ */ new Map();
@@ -2183,7 +2187,7 @@ async function fetchChannelMessagesPage(channelPath, options) {
2183
2187
  `[gateway] Failed to fetch channel messages page for ${channelPath}:`,
2184
2188
  err
2185
2189
  );
2186
- return { messages: [], messageCards: /* @__PURE__ */ new Map(), siblingCards: [], mode: "top_level" };
2190
+ throw err;
2187
2191
  }
2188
2192
  }
2189
2193
  function invalidateChildren(path) {
@@ -3890,31 +3894,31 @@ function useChannelMessages(options) {
3890
3894
  }
3891
3895
  function useInfiniteChannelMessages(options) {
3892
3896
  useScopeKey();
3893
- const { channelPath, parentMessageId, limit = 50, realtime = true, enabled: enabled2 = true } = options;
3897
+ const { channelPath, parentMessageId, limit = 50, realtime = true, enabled: enabled2 = true, conversationsOnly = false } = options;
3894
3898
  const isThread = !!parentMessageId;
3895
3899
  const queryEnabled = enabled2 && !!channelPath;
3896
3900
  const query = reactQuery.useInfiniteQuery({
3897
- queryKey: [...vfsKeys.channelMessages(channelPath || "", parentMessageId), "infinite", limit],
3901
+ queryKey: [...vfsKeys.channelMessages(channelPath || "", parentMessageId), "infinite", limit, "latest-first", ...conversationsOnly ? ["conversations"] : []],
3898
3902
  queryFn: async ({ pageParam }) => {
3899
3903
  return fetchChannelMessagesPage(channelPath, {
3900
3904
  parentMessageId,
3901
3905
  limit,
3902
- before_seq: isThread ? void 0 : pageParam,
3903
- after_seq: isThread ? pageParam : void 0
3906
+ conversationsOnly,
3907
+ before_seq: pageParam?.before_seq,
3908
+ after_seq: pageParam?.after_seq
3904
3909
  });
3905
3910
  },
3906
3911
  initialPageParam: void 0,
3907
- getNextPageParam: (lastPage) => {
3912
+ getPreviousPageParam: (lastPage) => {
3908
3913
  if (!isThread) return void 0;
3909
3914
  if (lastPage.messages.length < limit) return void 0;
3910
3915
  const maxSeq = lastPage.messages[lastPage.messages.length - 1]?.seq;
3911
- return maxSeq;
3916
+ return maxSeq == null ? void 0 : { after_seq: maxSeq };
3912
3917
  },
3913
- getPreviousPageParam: (firstPage) => {
3914
- if (isThread) return void 0;
3918
+ getNextPageParam: (firstPage) => {
3915
3919
  if (firstPage.messages.length < limit) return void 0;
3916
3920
  const minSeq = firstPage.messages[0]?.seq;
3917
- return minSeq;
3921
+ return minSeq == null ? void 0 : { before_seq: minSeq };
3918
3922
  },
3919
3923
  enabled: queryEnabled
3920
3924
  });
@@ -3958,8 +3962,8 @@ function useInfiniteChannelMessages(options) {
3958
3962
  const qc = reactQuery.useQueryClient();
3959
3963
  const debounceRef = React.useRef(null);
3960
3964
  const stableKey = React.useMemo(
3961
- () => [...vfsKeys.channelMessages(channelPath || "", parentMessageId), "infinite", limit],
3962
- [channelPath, parentMessageId, limit]
3965
+ () => [...vfsKeys.channelMessages(channelPath || "", parentMessageId), "infinite", limit, "latest-first", ...conversationsOnly ? ["conversations"] : []],
3966
+ [channelPath, parentMessageId, limit, conversationsOnly]
3963
3967
  );
3964
3968
  React.useEffect(() => {
3965
3969
  if (!realtime || !channelPath || !queryEnabled) return;
@@ -3968,6 +3972,10 @@ function useInfiniteChannelMessages(options) {
3968
3972
  let tailAgain = false;
3969
3973
  let disposed = false;
3970
3974
  const tailOnce = async () => {
3975
+ if (conversationsOnly) {
3976
+ reload();
3977
+ return;
3978
+ }
3971
3979
  const currentData = qc.getQueryData(stableKey);
3972
3980
  if (!currentData?.pages?.length) {
3973
3981
  reload();
@@ -4006,7 +4014,7 @@ function useInfiniteChannelMessages(options) {
4006
4014
  qc.setQueryData(stableKey, (old) => {
4007
4015
  if (!old) return old;
4008
4016
  const pages = [...old.pages];
4009
- const lastIdx = pages.length - 1;
4017
+ const lastIdx = 0;
4010
4018
  const lastPage = pages[lastIdx];
4011
4019
  const existingIds = new Set(lastPage.messages.map((m) => m.id));
4012
4020
  const uniqueNew = newPage.messages.filter((m) => !existingIds.has(m.id));
@@ -4058,7 +4066,7 @@ function useInfiniteChannelMessages(options) {
4058
4066
  void tail();
4059
4067
  }, 500);
4060
4068
  },
4061
- (data) => channelMessageChange(
4069
+ (data) => conversationsOnly && data?.item_type === "message" && (qc.getQueryData(stableKey)?.pages ?? []).some((page) => page.messages.some((root) => root.id === data.parent_id)) || channelMessageChange(
4062
4070
  data,
4063
4071
  channelPath,
4064
4072
  parentMessageId,
@@ -4070,11 +4078,11 @@ function useInfiniteChannelMessages(options) {
4070
4078
  unsub();
4071
4079
  if (debounceRef.current) clearTimeout(debounceRef.current);
4072
4080
  };
4073
- }, [realtime, channelPath, queryEnabled, stableKey, qc, parentMessageId, limit]);
4081
+ }, [realtime, channelPath, queryEnabled, stableKey, qc, parentMessageId, limit, conversationsOnly]);
4074
4082
  return {
4075
4083
  messages,
4076
4084
  // Activity is a current thread snapshot, not another reply page.
4077
- activityMessages: query.data?.pages.at(-1)?.activityMessages ?? [],
4085
+ activityMessages: query.data?.pages[0]?.activityMessages ?? [],
4078
4086
  /** Cards grouped by parent message path (child cards of messages). */
4079
4087
  messageCards,
4080
4088
  /** Cards that are direct siblings of the channel (not nested under a message). */
@@ -4086,14 +4094,14 @@ function useInfiniteChannelMessages(options) {
4086
4094
  isFetching: query.isFetching,
4087
4095
  error: query.error,
4088
4096
  refetch: query.refetch,
4089
- // Backward pagination (top-level: load older)
4090
- hasPreviousPage: query.hasPreviousPage ?? false,
4091
- fetchPreviousPage: query.fetchPreviousPage,
4092
- isFetchingPreviousPage: query.isFetchingPreviousPage ?? false,
4097
+ // Backward pagination (channels and threads: load older)
4098
+ hasPreviousPage: query.hasNextPage ?? false,
4099
+ fetchPreviousPage: query.fetchNextPage,
4100
+ isFetchingPreviousPage: query.isFetchingNextPage ?? false,
4093
4101
  // Forward pagination (thread: load newer)
4094
- hasNextPage: query.hasNextPage ?? false,
4095
- fetchNextPage: query.fetchNextPage,
4096
- isFetchingNextPage: query.isFetchingNextPage ?? false
4102
+ hasNextPage: query.hasPreviousPage ?? false,
4103
+ fetchNextPage: query.fetchPreviousPage,
4104
+ isFetchingNextPage: query.isFetchingPreviousPage ?? false
4097
4105
  };
4098
4106
  }
4099
4107
  var CHANNEL_AI_MODES = ["open", "active", "strict", "hand_raise"];