@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.cjs
CHANGED
|
@@ -301,11 +301,14 @@ var BackendApi = class {
|
|
|
301
301
|
}
|
|
302
302
|
return await response.json();
|
|
303
303
|
}
|
|
304
|
-
async postChatMessage(sessionId, message, namespace, publicKey, apiKey) {
|
|
304
|
+
async postChatMessage(sessionId, message, namespace, publicKey, apiKey, userState) {
|
|
305
305
|
const payload = { message, namespace };
|
|
306
306
|
if (publicKey) {
|
|
307
307
|
payload.public_key = publicKey;
|
|
308
308
|
}
|
|
309
|
+
if (userState) {
|
|
310
|
+
payload.user_state = JSON.stringify(userState);
|
|
311
|
+
}
|
|
309
312
|
return postState(
|
|
310
313
|
this.backendUrl,
|
|
311
314
|
"/api/chat",
|
|
@@ -1464,7 +1467,7 @@ var MessageController = class {
|
|
|
1464
1467
|
this.getThreadContextApi().setThreadMessages(threadId, threadMessages);
|
|
1465
1468
|
}
|
|
1466
1469
|
async outbound(message, threadId) {
|
|
1467
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1470
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1468
1471
|
const backendState = this.config.backendStateRef.current;
|
|
1469
1472
|
const text = message.content.filter(
|
|
1470
1473
|
(part) => part.type === "text"
|
|
@@ -1492,6 +1495,7 @@ var MessageController = class {
|
|
|
1492
1495
|
const namespace = this.config.getNamespace();
|
|
1493
1496
|
const publicKey = (_b = (_a = this.config).getPublicKey) == null ? void 0 : _b.call(_a);
|
|
1494
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);
|
|
1495
1499
|
try {
|
|
1496
1500
|
this.markRunning(threadId, true);
|
|
1497
1501
|
const response = await this.config.backendApiRef.current.postChatMessage(
|
|
@@ -1499,12 +1503,13 @@ var MessageController = class {
|
|
|
1499
1503
|
text,
|
|
1500
1504
|
namespace,
|
|
1501
1505
|
publicKey,
|
|
1502
|
-
apiKey
|
|
1506
|
+
apiKey,
|
|
1507
|
+
userState
|
|
1503
1508
|
);
|
|
1504
1509
|
if (response == null ? void 0 : response.messages) {
|
|
1505
1510
|
this.inbound(threadId, response.messages);
|
|
1506
1511
|
}
|
|
1507
|
-
if (((
|
|
1512
|
+
if (((_h = response == null ? void 0 : response.system_events) == null ? void 0 : _h.length) && this.config.onSyncEvents) {
|
|
1508
1513
|
this.config.onSyncEvents(backendThreadId, response.system_events);
|
|
1509
1514
|
}
|
|
1510
1515
|
if (response == null ? void 0 : response.is_processing) {
|
|
@@ -1518,7 +1523,7 @@ var MessageController = class {
|
|
|
1518
1523
|
}
|
|
1519
1524
|
}
|
|
1520
1525
|
async flushPendingChat(threadId) {
|
|
1521
|
-
var _a, _b, _c, _d, _e;
|
|
1526
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1522
1527
|
const backendState = this.config.backendStateRef.current;
|
|
1523
1528
|
const pending = dequeuePendingChat(backendState, threadId);
|
|
1524
1529
|
if (!pending.length) return;
|
|
@@ -1526,6 +1531,7 @@ var MessageController = class {
|
|
|
1526
1531
|
const namespace = this.config.getNamespace();
|
|
1527
1532
|
const publicKey = (_b = (_a = this.config).getPublicKey) == null ? void 0 : _b.call(_a);
|
|
1528
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);
|
|
1529
1535
|
for (const text of pending) {
|
|
1530
1536
|
try {
|
|
1531
1537
|
await this.config.backendApiRef.current.postChatMessage(
|
|
@@ -1533,7 +1539,8 @@ var MessageController = class {
|
|
|
1533
1539
|
text,
|
|
1534
1540
|
namespace,
|
|
1535
1541
|
publicKey,
|
|
1536
|
-
apiKey
|
|
1542
|
+
apiKey,
|
|
1543
|
+
userState
|
|
1537
1544
|
);
|
|
1538
1545
|
} catch (error) {
|
|
1539
1546
|
console.error("Failed to send queued message:", error);
|
|
@@ -1688,6 +1695,7 @@ function useRuntimeOrchestrator(backendApi, options) {
|
|
|
1688
1695
|
getPublicKey: options.getPublicKey,
|
|
1689
1696
|
getNamespace: options.getNamespace,
|
|
1690
1697
|
getApiKey: options.getApiKey,
|
|
1698
|
+
getUserState: options.getUserState,
|
|
1691
1699
|
onSyncEvents: options.onSyncEvents
|
|
1692
1700
|
});
|
|
1693
1701
|
}
|
|
@@ -1783,7 +1791,8 @@ function buildThreadListAdapter({
|
|
|
1783
1791
|
userAddress,
|
|
1784
1792
|
setIsRunning,
|
|
1785
1793
|
getNamespace,
|
|
1786
|
-
getApiKey
|
|
1794
|
+
getApiKey,
|
|
1795
|
+
getUserState
|
|
1787
1796
|
}) {
|
|
1788
1797
|
const backendState = backendStateRef.current;
|
|
1789
1798
|
const { regularThreads, archivedThreads } = buildThreadLists(
|
|
@@ -1876,6 +1885,7 @@ function buildThreadListAdapter({
|
|
|
1876
1885
|
backendState.pendingChat.delete(uiThreadId);
|
|
1877
1886
|
const namespace = getNamespace();
|
|
1878
1887
|
const apiKey = (_b = getApiKey == null ? void 0 : getApiKey()) != null ? _b : void 0;
|
|
1888
|
+
const userState = getUserState == null ? void 0 : getUserState();
|
|
1879
1889
|
for (const text of pendingMessages) {
|
|
1880
1890
|
try {
|
|
1881
1891
|
await backendApiRef.current.postChatMessage(
|
|
@@ -1883,7 +1893,8 @@ function buildThreadListAdapter({
|
|
|
1883
1893
|
text,
|
|
1884
1894
|
namespace,
|
|
1885
1895
|
userAddress,
|
|
1886
|
-
apiKey
|
|
1896
|
+
apiKey,
|
|
1897
|
+
userState
|
|
1887
1898
|
);
|
|
1888
1899
|
} catch (error) {
|
|
1889
1900
|
console.error("Failed to send queued message:", error);
|
|
@@ -2146,7 +2157,8 @@ function AomiRuntimeCore({
|
|
|
2146
2157
|
var _a, _b;
|
|
2147
2158
|
return (_b = (_a = getCurrentThreadControl().namespace) != null ? _a : getControlState().defaultNamespace) != null ? _b : "default";
|
|
2148
2159
|
},
|
|
2149
|
-
getApiKey: () => getControlState().apiKey
|
|
2160
|
+
getApiKey: () => getControlState().apiKey,
|
|
2161
|
+
getUserState
|
|
2150
2162
|
}),
|
|
2151
2163
|
[
|
|
2152
2164
|
backendApiRef,
|
|
@@ -2157,7 +2169,8 @@ function AomiRuntimeCore({
|
|
|
2157
2169
|
threadContext,
|
|
2158
2170
|
threadContext.currentThreadId,
|
|
2159
2171
|
threadContext.allThreadsMetadata,
|
|
2160
|
-
getControlState
|
|
2172
|
+
getControlState,
|
|
2173
|
+
getUserState
|
|
2161
2174
|
]
|
|
2162
2175
|
);
|
|
2163
2176
|
(0, import_react8.useEffect)(() => {
|