@aomi-labs/react 0.2.2 → 0.2.3
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.cjs +23 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +23 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
/**
|
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
|
/**
|
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",
|
|
@@ -1455,7 +1458,7 @@ var MessageController = class {
|
|
|
1455
1458
|
this.getThreadContextApi().setThreadMessages(threadId, threadMessages);
|
|
1456
1459
|
}
|
|
1457
1460
|
async outbound(message, threadId) {
|
|
1458
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1461
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1459
1462
|
const backendState = this.config.backendStateRef.current;
|
|
1460
1463
|
const text = message.content.filter(
|
|
1461
1464
|
(part) => part.type === "text"
|
|
@@ -1483,6 +1486,7 @@ var MessageController = class {
|
|
|
1483
1486
|
const namespace = this.config.getNamespace();
|
|
1484
1487
|
const publicKey = (_b = (_a = this.config).getPublicKey) == null ? void 0 : _b.call(_a);
|
|
1485
1488
|
const apiKey = (_e = (_d = (_c = this.config).getApiKey) == null ? void 0 : _d.call(_c)) != null ? _e : void 0;
|
|
1489
|
+
const userState = (_g = (_f = this.config).getUserState) == null ? void 0 : _g.call(_f);
|
|
1486
1490
|
try {
|
|
1487
1491
|
this.markRunning(threadId, true);
|
|
1488
1492
|
const response = await this.config.backendApiRef.current.postChatMessage(
|
|
@@ -1490,12 +1494,13 @@ var MessageController = class {
|
|
|
1490
1494
|
text,
|
|
1491
1495
|
namespace,
|
|
1492
1496
|
publicKey,
|
|
1493
|
-
apiKey
|
|
1497
|
+
apiKey,
|
|
1498
|
+
userState
|
|
1494
1499
|
);
|
|
1495
1500
|
if (response == null ? void 0 : response.messages) {
|
|
1496
1501
|
this.inbound(threadId, response.messages);
|
|
1497
1502
|
}
|
|
1498
|
-
if (((
|
|
1503
|
+
if (((_h = response == null ? void 0 : response.system_events) == null ? void 0 : _h.length) && this.config.onSyncEvents) {
|
|
1499
1504
|
this.config.onSyncEvents(backendThreadId, response.system_events);
|
|
1500
1505
|
}
|
|
1501
1506
|
if (response == null ? void 0 : response.is_processing) {
|
|
@@ -1509,7 +1514,7 @@ var MessageController = class {
|
|
|
1509
1514
|
}
|
|
1510
1515
|
}
|
|
1511
1516
|
async flushPendingChat(threadId) {
|
|
1512
|
-
var _a, _b, _c, _d, _e;
|
|
1517
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1513
1518
|
const backendState = this.config.backendStateRef.current;
|
|
1514
1519
|
const pending = dequeuePendingChat(backendState, threadId);
|
|
1515
1520
|
if (!pending.length) return;
|
|
@@ -1517,6 +1522,7 @@ var MessageController = class {
|
|
|
1517
1522
|
const namespace = this.config.getNamespace();
|
|
1518
1523
|
const publicKey = (_b = (_a = this.config).getPublicKey) == null ? void 0 : _b.call(_a);
|
|
1519
1524
|
const apiKey = (_e = (_d = (_c = this.config).getApiKey) == null ? void 0 : _d.call(_c)) != null ? _e : void 0;
|
|
1525
|
+
const userState = (_g = (_f = this.config).getUserState) == null ? void 0 : _g.call(_f);
|
|
1520
1526
|
for (const text of pending) {
|
|
1521
1527
|
try {
|
|
1522
1528
|
await this.config.backendApiRef.current.postChatMessage(
|
|
@@ -1524,7 +1530,8 @@ var MessageController = class {
|
|
|
1524
1530
|
text,
|
|
1525
1531
|
namespace,
|
|
1526
1532
|
publicKey,
|
|
1527
|
-
apiKey
|
|
1533
|
+
apiKey,
|
|
1534
|
+
userState
|
|
1528
1535
|
);
|
|
1529
1536
|
} catch (error) {
|
|
1530
1537
|
console.error("Failed to send queued message:", error);
|
|
@@ -1679,6 +1686,7 @@ function useRuntimeOrchestrator(backendApi, options) {
|
|
|
1679
1686
|
getPublicKey: options.getPublicKey,
|
|
1680
1687
|
getNamespace: options.getNamespace,
|
|
1681
1688
|
getApiKey: options.getApiKey,
|
|
1689
|
+
getUserState: options.getUserState,
|
|
1682
1690
|
onSyncEvents: options.onSyncEvents
|
|
1683
1691
|
});
|
|
1684
1692
|
}
|
|
@@ -1774,7 +1782,8 @@ function buildThreadListAdapter({
|
|
|
1774
1782
|
userAddress,
|
|
1775
1783
|
setIsRunning,
|
|
1776
1784
|
getNamespace,
|
|
1777
|
-
getApiKey
|
|
1785
|
+
getApiKey,
|
|
1786
|
+
getUserState
|
|
1778
1787
|
}) {
|
|
1779
1788
|
const backendState = backendStateRef.current;
|
|
1780
1789
|
const { regularThreads, archivedThreads } = buildThreadLists(
|
|
@@ -1867,6 +1876,7 @@ function buildThreadListAdapter({
|
|
|
1867
1876
|
backendState.pendingChat.delete(uiThreadId);
|
|
1868
1877
|
const namespace = getNamespace();
|
|
1869
1878
|
const apiKey = (_b = getApiKey == null ? void 0 : getApiKey()) != null ? _b : void 0;
|
|
1879
|
+
const userState = getUserState == null ? void 0 : getUserState();
|
|
1870
1880
|
for (const text of pendingMessages) {
|
|
1871
1881
|
try {
|
|
1872
1882
|
await backendApiRef.current.postChatMessage(
|
|
@@ -1874,7 +1884,8 @@ function buildThreadListAdapter({
|
|
|
1874
1884
|
text,
|
|
1875
1885
|
namespace,
|
|
1876
1886
|
userAddress,
|
|
1877
|
-
apiKey
|
|
1887
|
+
apiKey,
|
|
1888
|
+
userState
|
|
1878
1889
|
);
|
|
1879
1890
|
} catch (error) {
|
|
1880
1891
|
console.error("Failed to send queued message:", error);
|
|
@@ -2137,7 +2148,8 @@ function AomiRuntimeCore({
|
|
|
2137
2148
|
var _a, _b;
|
|
2138
2149
|
return (_b = (_a = getCurrentThreadControl().namespace) != null ? _a : getControlState().defaultNamespace) != null ? _b : "default";
|
|
2139
2150
|
},
|
|
2140
|
-
getApiKey: () => getControlState().apiKey
|
|
2151
|
+
getApiKey: () => getControlState().apiKey,
|
|
2152
|
+
getUserState
|
|
2141
2153
|
}),
|
|
2142
2154
|
[
|
|
2143
2155
|
backendApiRef,
|
|
@@ -2148,7 +2160,8 @@ function AomiRuntimeCore({
|
|
|
2148
2160
|
threadContext,
|
|
2149
2161
|
threadContext.currentThreadId,
|
|
2150
2162
|
threadContext.allThreadsMetadata,
|
|
2151
|
-
getControlState
|
|
2163
|
+
getControlState,
|
|
2164
|
+
getUserState
|
|
2152
2165
|
]
|
|
2153
2166
|
);
|
|
2154
2167
|
useEffect3(() => {
|