@aomi-labs/react 0.2.2 → 0.2.4

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/index.d.cts CHANGED
@@ -110,7 +110,7 @@ declare class BackendApi {
110
110
  private sseSubscriber;
111
111
  constructor(backendUrl: string);
112
112
  fetchState(sessionId: string, userState?: UserState): Promise<ApiStateResponse>;
113
- postChatMessage(sessionId: string, message: string, namespace: string, publicKey?: string, apiKey?: string): Promise<ApiChatResponse>;
113
+ postChatMessage(sessionId: string, message: string, namespace: string, publicKey?: string, apiKey?: string, userState?: UserState): Promise<ApiChatResponse>;
114
114
  postSystemMessage(sessionId: string, message: string): Promise<ApiSystemResponse>;
115
115
  postInterrupt(sessionId: string): Promise<ApiInterruptResponse>;
116
116
  /**
@@ -412,6 +412,16 @@ type UserConfig = {
412
412
  };
413
413
  declare const getNetworkName: (chainId: number | string | undefined) => string;
414
414
  declare const formatAddress: (addr?: string) => string;
415
+ /** Static metadata for a supported chain */
416
+ type ChainInfo = {
417
+ id: number;
418
+ name: string;
419
+ ticker: string;
420
+ };
421
+ /** All chains supported by the application. Single source of truth. */
422
+ declare const SUPPORTED_CHAINS: ChainInfo[];
423
+ /** Look up ChainInfo by chain ID. Returns undefined for unknown chains. */
424
+ declare const getChainInfo: (chainId: number | undefined) => ChainInfo | undefined;
415
425
 
416
426
  /** Global control state (shared across all threads) */
417
427
  type ControlState = {
@@ -468,4 +478,4 @@ type ControlContextProviderProps = {
468
478
  };
469
479
  declare function ControlContextProvider({ children, backendApi, sessionId, publicKey, getThreadMetadata, updateThreadMetadata, }: ControlContextProviderProps): react_jsx_runtime.JSX.Element;
470
480
 
471
- export { type AomiMessage, type AomiRuntimeApi, AomiRuntimeProvider, type AomiRuntimeProviderProps, type ApiChatResponse, type ApiCreateThreadResponse, type ApiInterruptResponse, type ApiSSEEvent, type ApiStateResponse, type ApiSystemEvent, type ApiSystemResponse, type ApiThread, BackendApi, type ControlContextApi, ControlContextProvider, type ControlContextProviderProps, type ControlState, type EventBuffer, type EventContext, EventContextProvider, type EventContextProviderProps, type EventSubscriber, type Notification as HandlerNotification, type InboundEvent, type Notification$1 as Notification, type NotificationApi, NotificationContextProvider, type NotificationContextProviderProps, type NotificationContextApi as NotificationContextValue, type NotificationHandlerConfig, type NotificationType, type OutboundEvent, type SSEStatus, type NotificationData as ShowNotificationParams, type ThreadContext, ThreadContextProvider, type ThreadControlState, type ThreadMetadata, type UserConfig, UserContextProvider, type UserState, type UserState as WalletButtonState, type WalletConnectionStatus, type WalletHanderApi, type WalletHandlerConfig, type WalletTxComplete, type WalletTxRequest, cn, formatAddress, getNetworkName, initThreadControl, useAomiRuntime, useControl, useCurrentThreadMessages, useCurrentThreadMetadata, useEventContext, useNotification, useNotificationHandler, useThreadContext, useUser, useWalletHandler };
481
+ export { type AomiMessage, type AomiRuntimeApi, AomiRuntimeProvider, type AomiRuntimeProviderProps, type ApiChatResponse, type ApiCreateThreadResponse, type ApiInterruptResponse, type ApiSSEEvent, type ApiStateResponse, type ApiSystemEvent, type ApiSystemResponse, type ApiThread, BackendApi, type ChainInfo, type ControlContextApi, ControlContextProvider, type ControlContextProviderProps, type ControlState, type EventBuffer, type EventContext, EventContextProvider, type EventContextProviderProps, type EventSubscriber, type Notification as HandlerNotification, type InboundEvent, type Notification$1 as Notification, type NotificationApi, NotificationContextProvider, type NotificationContextProviderProps, type NotificationContextApi as NotificationContextValue, type NotificationHandlerConfig, type NotificationType, type OutboundEvent, type SSEStatus, SUPPORTED_CHAINS, type NotificationData as ShowNotificationParams, type ThreadContext, ThreadContextProvider, type ThreadControlState, type ThreadMetadata, type UserConfig, UserContextProvider, type UserState, type UserState as WalletButtonState, type WalletConnectionStatus, type WalletHanderApi, type WalletHandlerConfig, type WalletTxComplete, type WalletTxRequest, cn, formatAddress, getChainInfo, getNetworkName, initThreadControl, useAomiRuntime, useControl, useCurrentThreadMessages, useCurrentThreadMetadata, useEventContext, useNotification, useNotificationHandler, useThreadContext, useUser, useWalletHandler };
package/dist/index.d.ts CHANGED
@@ -110,7 +110,7 @@ declare class BackendApi {
110
110
  private sseSubscriber;
111
111
  constructor(backendUrl: string);
112
112
  fetchState(sessionId: string, userState?: UserState): Promise<ApiStateResponse>;
113
- postChatMessage(sessionId: string, message: string, namespace: string, publicKey?: string, apiKey?: string): Promise<ApiChatResponse>;
113
+ postChatMessage(sessionId: string, message: string, namespace: string, publicKey?: string, apiKey?: string, userState?: UserState): Promise<ApiChatResponse>;
114
114
  postSystemMessage(sessionId: string, message: string): Promise<ApiSystemResponse>;
115
115
  postInterrupt(sessionId: string): Promise<ApiInterruptResponse>;
116
116
  /**
@@ -412,6 +412,16 @@ type UserConfig = {
412
412
  };
413
413
  declare const getNetworkName: (chainId: number | string | undefined) => string;
414
414
  declare const formatAddress: (addr?: string) => string;
415
+ /** Static metadata for a supported chain */
416
+ type ChainInfo = {
417
+ id: number;
418
+ name: string;
419
+ ticker: string;
420
+ };
421
+ /** All chains supported by the application. Single source of truth. */
422
+ declare const SUPPORTED_CHAINS: ChainInfo[];
423
+ /** Look up ChainInfo by chain ID. Returns undefined for unknown chains. */
424
+ declare const getChainInfo: (chainId: number | undefined) => ChainInfo | undefined;
415
425
 
416
426
  /** Global control state (shared across all threads) */
417
427
  type ControlState = {
@@ -468,4 +478,4 @@ type ControlContextProviderProps = {
468
478
  };
469
479
  declare function ControlContextProvider({ children, backendApi, sessionId, publicKey, getThreadMetadata, updateThreadMetadata, }: ControlContextProviderProps): react_jsx_runtime.JSX.Element;
470
480
 
471
- export { type AomiMessage, type AomiRuntimeApi, AomiRuntimeProvider, type AomiRuntimeProviderProps, type ApiChatResponse, type ApiCreateThreadResponse, type ApiInterruptResponse, type ApiSSEEvent, type ApiStateResponse, type ApiSystemEvent, type ApiSystemResponse, type ApiThread, BackendApi, type ControlContextApi, ControlContextProvider, type ControlContextProviderProps, type ControlState, type EventBuffer, type EventContext, EventContextProvider, type EventContextProviderProps, type EventSubscriber, type Notification as HandlerNotification, type InboundEvent, type Notification$1 as Notification, type NotificationApi, NotificationContextProvider, type NotificationContextProviderProps, type NotificationContextApi as NotificationContextValue, type NotificationHandlerConfig, type NotificationType, type OutboundEvent, type SSEStatus, type NotificationData as ShowNotificationParams, type ThreadContext, ThreadContextProvider, type ThreadControlState, type ThreadMetadata, type UserConfig, UserContextProvider, type UserState, type UserState as WalletButtonState, type WalletConnectionStatus, type WalletHanderApi, type WalletHandlerConfig, type WalletTxComplete, type WalletTxRequest, cn, formatAddress, getNetworkName, initThreadControl, useAomiRuntime, useControl, useCurrentThreadMessages, useCurrentThreadMetadata, useEventContext, useNotification, useNotificationHandler, useThreadContext, useUser, useWalletHandler };
481
+ export { type AomiMessage, type AomiRuntimeApi, AomiRuntimeProvider, type AomiRuntimeProviderProps, type ApiChatResponse, type ApiCreateThreadResponse, type ApiInterruptResponse, type ApiSSEEvent, type ApiStateResponse, type ApiSystemEvent, type ApiSystemResponse, type ApiThread, BackendApi, type ChainInfo, type ControlContextApi, ControlContextProvider, type ControlContextProviderProps, type ControlState, type EventBuffer, type EventContext, EventContextProvider, type EventContextProviderProps, type EventSubscriber, type Notification as HandlerNotification, type InboundEvent, type Notification$1 as Notification, type NotificationApi, NotificationContextProvider, type NotificationContextProviderProps, type NotificationContextApi as NotificationContextValue, type NotificationHandlerConfig, type NotificationType, type OutboundEvent, type SSEStatus, SUPPORTED_CHAINS, type NotificationData as ShowNotificationParams, type ThreadContext, ThreadContextProvider, type ThreadControlState, type ThreadMetadata, type UserConfig, UserContextProvider, type UserState, type UserState as WalletButtonState, type WalletConnectionStatus, type WalletHanderApi, type WalletHandlerConfig, type WalletTxComplete, type WalletTxRequest, cn, formatAddress, getChainInfo, getNetworkName, initThreadControl, useAomiRuntime, useControl, useCurrentThreadMessages, useCurrentThreadMetadata, useEventContext, useNotification, useNotificationHandler, useThreadContext, useUser, useWalletHandler };
package/dist/index.js CHANGED
@@ -258,11 +258,14 @@ var BackendApi = class {
258
258
  }
259
259
  return await response.json();
260
260
  }
261
- async postChatMessage(sessionId, message, namespace, publicKey, apiKey) {
261
+ async postChatMessage(sessionId, message, namespace, publicKey, apiKey, userState) {
262
262
  const payload = { message, namespace };
263
263
  if (publicKey) {
264
264
  payload.public_key = publicKey;
265
265
  }
266
+ if (userState) {
267
+ payload.user_state = JSON.stringify(userState);
268
+ }
266
269
  return postState(
267
270
  this.backendUrl,
268
271
  "/api/chat",
@@ -1382,6 +1385,15 @@ var getNetworkName = (chainId) => {
1382
1385
  }
1383
1386
  };
1384
1387
  var formatAddress = (addr) => addr ? `${addr.slice(0, 6)}...${addr.slice(-4)}` : "Connect Wallet";
1388
+ var SUPPORTED_CHAINS = [
1389
+ { id: 1, name: "Ethereum", ticker: "ETH" },
1390
+ { id: 137, name: "Polygon", ticker: "MATIC" },
1391
+ { id: 42161, name: "Arbitrum", ticker: "ARB" },
1392
+ { id: 8453, name: "Base", ticker: "BASE" },
1393
+ { id: 10, name: "Optimism", ticker: "OP" },
1394
+ { id: 11155111, name: "Sepolia", ticker: "SEP" }
1395
+ ];
1396
+ var getChainInfo = (chainId) => chainId === void 0 ? void 0 : SUPPORTED_CHAINS.find((c) => c.id === chainId);
1385
1397
 
1386
1398
  // packages/react/src/state/backend-state.ts
1387
1399
  function createBackendState() {
@@ -1455,7 +1467,7 @@ var MessageController = class {
1455
1467
  this.getThreadContextApi().setThreadMessages(threadId, threadMessages);
1456
1468
  }
1457
1469
  async outbound(message, threadId) {
1458
- var _a, _b, _c, _d, _e, _f;
1470
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1459
1471
  const backendState = this.config.backendStateRef.current;
1460
1472
  const text = message.content.filter(
1461
1473
  (part) => part.type === "text"
@@ -1483,6 +1495,7 @@ var MessageController = class {
1483
1495
  const namespace = this.config.getNamespace();
1484
1496
  const publicKey = (_b = (_a = this.config).getPublicKey) == null ? void 0 : _b.call(_a);
1485
1497
  const apiKey = (_e = (_d = (_c = this.config).getApiKey) == null ? void 0 : _d.call(_c)) != null ? _e : void 0;
1498
+ const userState = (_g = (_f = this.config).getUserState) == null ? void 0 : _g.call(_f);
1486
1499
  try {
1487
1500
  this.markRunning(threadId, true);
1488
1501
  const response = await this.config.backendApiRef.current.postChatMessage(
@@ -1490,12 +1503,13 @@ var MessageController = class {
1490
1503
  text,
1491
1504
  namespace,
1492
1505
  publicKey,
1493
- apiKey
1506
+ apiKey,
1507
+ userState
1494
1508
  );
1495
1509
  if (response == null ? void 0 : response.messages) {
1496
1510
  this.inbound(threadId, response.messages);
1497
1511
  }
1498
- if (((_f = response == null ? void 0 : response.system_events) == null ? void 0 : _f.length) && this.config.onSyncEvents) {
1512
+ if (((_h = response == null ? void 0 : response.system_events) == null ? void 0 : _h.length) && this.config.onSyncEvents) {
1499
1513
  this.config.onSyncEvents(backendThreadId, response.system_events);
1500
1514
  }
1501
1515
  if (response == null ? void 0 : response.is_processing) {
@@ -1509,7 +1523,7 @@ var MessageController = class {
1509
1523
  }
1510
1524
  }
1511
1525
  async flushPendingChat(threadId) {
1512
- var _a, _b, _c, _d, _e;
1526
+ var _a, _b, _c, _d, _e, _f, _g;
1513
1527
  const backendState = this.config.backendStateRef.current;
1514
1528
  const pending = dequeuePendingChat(backendState, threadId);
1515
1529
  if (!pending.length) return;
@@ -1517,6 +1531,7 @@ var MessageController = class {
1517
1531
  const namespace = this.config.getNamespace();
1518
1532
  const publicKey = (_b = (_a = this.config).getPublicKey) == null ? void 0 : _b.call(_a);
1519
1533
  const apiKey = (_e = (_d = (_c = this.config).getApiKey) == null ? void 0 : _d.call(_c)) != null ? _e : void 0;
1534
+ const userState = (_g = (_f = this.config).getUserState) == null ? void 0 : _g.call(_f);
1520
1535
  for (const text of pending) {
1521
1536
  try {
1522
1537
  await this.config.backendApiRef.current.postChatMessage(
@@ -1524,7 +1539,8 @@ var MessageController = class {
1524
1539
  text,
1525
1540
  namespace,
1526
1541
  publicKey,
1527
- apiKey
1542
+ apiKey,
1543
+ userState
1528
1544
  );
1529
1545
  } catch (error) {
1530
1546
  console.error("Failed to send queued message:", error);
@@ -1679,6 +1695,7 @@ function useRuntimeOrchestrator(backendApi, options) {
1679
1695
  getPublicKey: options.getPublicKey,
1680
1696
  getNamespace: options.getNamespace,
1681
1697
  getApiKey: options.getApiKey,
1698
+ getUserState: options.getUserState,
1682
1699
  onSyncEvents: options.onSyncEvents
1683
1700
  });
1684
1701
  }
@@ -1774,7 +1791,8 @@ function buildThreadListAdapter({
1774
1791
  userAddress,
1775
1792
  setIsRunning,
1776
1793
  getNamespace,
1777
- getApiKey
1794
+ getApiKey,
1795
+ getUserState
1778
1796
  }) {
1779
1797
  const backendState = backendStateRef.current;
1780
1798
  const { regularThreads, archivedThreads } = buildThreadLists(
@@ -1867,6 +1885,7 @@ function buildThreadListAdapter({
1867
1885
  backendState.pendingChat.delete(uiThreadId);
1868
1886
  const namespace = getNamespace();
1869
1887
  const apiKey = (_b = getApiKey == null ? void 0 : getApiKey()) != null ? _b : void 0;
1888
+ const userState = getUserState == null ? void 0 : getUserState();
1870
1889
  for (const text of pendingMessages) {
1871
1890
  try {
1872
1891
  await backendApiRef.current.postChatMessage(
@@ -1874,7 +1893,8 @@ function buildThreadListAdapter({
1874
1893
  text,
1875
1894
  namespace,
1876
1895
  userAddress,
1877
- apiKey
1896
+ apiKey,
1897
+ userState
1878
1898
  );
1879
1899
  } catch (error) {
1880
1900
  console.error("Failed to send queued message:", error);
@@ -2137,7 +2157,8 @@ function AomiRuntimeCore({
2137
2157
  var _a, _b;
2138
2158
  return (_b = (_a = getCurrentThreadControl().namespace) != null ? _a : getControlState().defaultNamespace) != null ? _b : "default";
2139
2159
  },
2140
- getApiKey: () => getControlState().apiKey
2160
+ getApiKey: () => getControlState().apiKey,
2161
+ getUserState
2141
2162
  }),
2142
2163
  [
2143
2164
  backendApiRef,
@@ -2148,7 +2169,8 @@ function AomiRuntimeCore({
2148
2169
  threadContext,
2149
2170
  threadContext.currentThreadId,
2150
2171
  threadContext.allThreadsMetadata,
2151
- getControlState
2172
+ getControlState,
2173
+ getUserState
2152
2174
  ]
2153
2175
  );
2154
2176
  useEffect3(() => {
@@ -2532,10 +2554,12 @@ export {
2532
2554
  ControlContextProvider,
2533
2555
  EventContextProvider,
2534
2556
  NotificationContextProvider,
2557
+ SUPPORTED_CHAINS,
2535
2558
  ThreadContextProvider,
2536
2559
  UserContextProvider,
2537
2560
  cn,
2538
2561
  formatAddress,
2562
+ getChainInfo,
2539
2563
  getNetworkName,
2540
2564
  initThreadControl,
2541
2565
  useAomiRuntime,