@aomi-labs/react 0.3.3 → 0.3.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.cjs +52 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +52 -14
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -325,6 +325,8 @@ declare const getChainInfo: (chainId: number | undefined) => ChainInfo | undefin
|
|
|
325
325
|
type ControlState = {
|
|
326
326
|
/** API key for authenticated requests */
|
|
327
327
|
apiKey: string | null;
|
|
328
|
+
/** Stable client identifier for this browser tab (associates sessions with secrets) */
|
|
329
|
+
clientId: string | null;
|
|
328
330
|
/** Available models fetched from backend */
|
|
329
331
|
availableModels: string[];
|
|
330
332
|
/** Authorized apps fetched from backend */
|
|
@@ -335,10 +337,14 @@ type ControlState = {
|
|
|
335
337
|
defaultApp: string | null;
|
|
336
338
|
};
|
|
337
339
|
type ControlContextApi = {
|
|
338
|
-
/** Global state (apiKey, available models/apps) */
|
|
340
|
+
/** Global state (apiKey, clientId, available models/apps) */
|
|
339
341
|
state: ControlState;
|
|
340
342
|
/** Update global state (apiKey only) */
|
|
341
343
|
setApiKey: (apiKey: string | null) => void;
|
|
344
|
+
/** Ingest secrets into the backend vault, returns opaque handles */
|
|
345
|
+
ingestSecrets: (secrets: Record<string, string>) => Promise<Record<string, string>>;
|
|
346
|
+
/** Clear all secrets from the backend vault */
|
|
347
|
+
clearSecrets: () => Promise<void>;
|
|
342
348
|
/** Fetch available models from backend */
|
|
343
349
|
getAvailableModels: () => Promise<string[]>;
|
|
344
350
|
/** Fetch authorized apps from backend */
|
package/dist/index.d.ts
CHANGED
|
@@ -325,6 +325,8 @@ declare const getChainInfo: (chainId: number | undefined) => ChainInfo | undefin
|
|
|
325
325
|
type ControlState = {
|
|
326
326
|
/** API key for authenticated requests */
|
|
327
327
|
apiKey: string | null;
|
|
328
|
+
/** Stable client identifier for this browser tab (associates sessions with secrets) */
|
|
329
|
+
clientId: string | null;
|
|
328
330
|
/** Available models fetched from backend */
|
|
329
331
|
availableModels: string[];
|
|
330
332
|
/** Authorized apps fetched from backend */
|
|
@@ -335,10 +337,14 @@ type ControlState = {
|
|
|
335
337
|
defaultApp: string | null;
|
|
336
338
|
};
|
|
337
339
|
type ControlContextApi = {
|
|
338
|
-
/** Global state (apiKey, available models/apps) */
|
|
340
|
+
/** Global state (apiKey, clientId, available models/apps) */
|
|
339
341
|
state: ControlState;
|
|
340
342
|
/** Update global state (apiKey only) */
|
|
341
343
|
setApiKey: (apiKey: string | null) => void;
|
|
344
|
+
/** Ingest secrets into the backend vault, returns opaque handles */
|
|
345
|
+
ingestSecrets: (secrets: Record<string, string>) => Promise<Record<string, string>>;
|
|
346
|
+
/** Clear all secrets from the backend vault */
|
|
347
|
+
clearSecrets: () => Promise<void>;
|
|
342
348
|
/** Fetch available models from backend */
|
|
343
349
|
getAvailableModels: () => Promise<string[]>;
|
|
344
350
|
/** Fetch authorized apps from backend */
|
package/dist/index.js
CHANGED
|
@@ -239,6 +239,7 @@ function ControlContextProvider({
|
|
|
239
239
|
var _a, _b;
|
|
240
240
|
const [state, setStateInternal] = useState(() => ({
|
|
241
241
|
apiKey: null,
|
|
242
|
+
clientId: null,
|
|
242
243
|
availableModels: [],
|
|
243
244
|
authorizedApps: [],
|
|
244
245
|
defaultModel: null,
|
|
@@ -259,6 +260,11 @@ function ControlContextProvider({
|
|
|
259
260
|
const callbacks = useRef(/* @__PURE__ */ new Set());
|
|
260
261
|
const currentThreadMetadata = getThreadMetadata(sessionId);
|
|
261
262
|
const isProcessing = (_b = (_a = currentThreadMetadata == null ? void 0 : currentThreadMetadata.control) == null ? void 0 : _a.isProcessing) != null ? _b : false;
|
|
263
|
+
useEffect(() => {
|
|
264
|
+
var _a2, _b2, _c;
|
|
265
|
+
const clientId = (_c = (_b2 = (_a2 = globalThis.crypto) == null ? void 0 : _a2.randomUUID) == null ? void 0 : _b2.call(_a2)) != null ? _c : `client-${Date.now()}`;
|
|
266
|
+
setStateInternal((prev) => __spreadProps(__spreadValues({}, prev), { clientId }));
|
|
267
|
+
}, []);
|
|
262
268
|
useEffect(() => {
|
|
263
269
|
var _a2, _b2;
|
|
264
270
|
try {
|
|
@@ -332,6 +338,24 @@ function ControlContextProvider({
|
|
|
332
338
|
return next;
|
|
333
339
|
});
|
|
334
340
|
}, []);
|
|
341
|
+
const ingestSecrets = useCallback(
|
|
342
|
+
async (secrets) => {
|
|
343
|
+
const clientId = stateRef.current.clientId;
|
|
344
|
+
if (!clientId) throw new Error("clientId not initialized");
|
|
345
|
+
const { handles } = await aomiClientRef.current.ingestSecrets(
|
|
346
|
+
clientId,
|
|
347
|
+
secrets
|
|
348
|
+
);
|
|
349
|
+
return handles;
|
|
350
|
+
},
|
|
351
|
+
[]
|
|
352
|
+
);
|
|
353
|
+
const clearSecrets = useCallback(async () => {
|
|
354
|
+
var _a2, _b2;
|
|
355
|
+
const clientId = stateRef.current.clientId;
|
|
356
|
+
if (!clientId) return;
|
|
357
|
+
await ((_b2 = (_a2 = aomiClientRef.current).clearSecrets) == null ? void 0 : _b2.call(_a2, clientId));
|
|
358
|
+
}, []);
|
|
335
359
|
const getAvailableModels = useCallback(async () => {
|
|
336
360
|
try {
|
|
337
361
|
const models = await aomiClientRef.current.getModels(
|
|
@@ -512,6 +536,8 @@ function ControlContextProvider({
|
|
|
512
536
|
value: {
|
|
513
537
|
state,
|
|
514
538
|
setApiKey,
|
|
539
|
+
ingestSecrets,
|
|
540
|
+
clearSecrets,
|
|
515
541
|
getAvailableModels,
|
|
516
542
|
getAuthorizedApps,
|
|
517
543
|
getCurrentThreadControl,
|
|
@@ -1065,7 +1091,7 @@ var MessageController = class {
|
|
|
1065
1091
|
this.getThreadContextApi().setThreadMessages(threadId, threadMessages);
|
|
1066
1092
|
}
|
|
1067
1093
|
async outbound(message, threadId) {
|
|
1068
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1094
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1069
1095
|
const backendState = this.config.backendStateRef.current;
|
|
1070
1096
|
const text = message.content.filter(
|
|
1071
1097
|
(part) => part.type === "text"
|
|
@@ -1088,18 +1114,19 @@ var MessageController = class {
|
|
|
1088
1114
|
const app = this.config.getApp();
|
|
1089
1115
|
const publicKey = (_b = (_a = this.config).getPublicKey) == null ? void 0 : _b.call(_a);
|
|
1090
1116
|
const apiKey = (_e = (_d = (_c = this.config).getApiKey) == null ? void 0 : _d.call(_c)) != null ? _e : void 0;
|
|
1091
|
-
const
|
|
1117
|
+
const clientId = (_g = (_f = this.config).getClientId) == null ? void 0 : _g.call(_f);
|
|
1118
|
+
const userState = (_i = (_h = this.config).getUserState) == null ? void 0 : _i.call(_h);
|
|
1092
1119
|
try {
|
|
1093
1120
|
this.markRunning(threadId, true);
|
|
1094
1121
|
const response = await this.config.aomiClientRef.current.sendMessage(
|
|
1095
1122
|
backendThreadId,
|
|
1096
1123
|
text,
|
|
1097
|
-
{ app, publicKey, apiKey, userState }
|
|
1124
|
+
{ app, publicKey, apiKey, userState, clientId }
|
|
1098
1125
|
);
|
|
1099
1126
|
if (response == null ? void 0 : response.messages) {
|
|
1100
1127
|
this.inbound(threadId, response.messages);
|
|
1101
1128
|
}
|
|
1102
|
-
if (((
|
|
1129
|
+
if (((_j = response == null ? void 0 : response.system_events) == null ? void 0 : _j.length) && this.config.onSyncEvents) {
|
|
1103
1130
|
this.config.onSyncEvents(backendThreadId, response.system_events);
|
|
1104
1131
|
}
|
|
1105
1132
|
if (response == null ? void 0 : response.is_processing) {
|
|
@@ -1158,7 +1185,7 @@ var PollingController = class {
|
|
|
1158
1185
|
const backendThreadId = resolveThreadId(backendState, threadId);
|
|
1159
1186
|
setThreadRunning(backendState, threadId, true);
|
|
1160
1187
|
const tick = async () => {
|
|
1161
|
-
var _a2, _b2;
|
|
1188
|
+
var _a2, _b2, _c, _d;
|
|
1162
1189
|
if (!this.intervals.has(threadId)) return;
|
|
1163
1190
|
try {
|
|
1164
1191
|
console.log(
|
|
@@ -1166,9 +1193,11 @@ var PollingController = class {
|
|
|
1166
1193
|
threadId
|
|
1167
1194
|
);
|
|
1168
1195
|
const userState = (_b2 = (_a2 = this.config).getUserState) == null ? void 0 : _b2.call(_a2);
|
|
1196
|
+
const clientId = (_d = (_c = this.config).getClientId) == null ? void 0 : _d.call(_c);
|
|
1169
1197
|
const state = await this.config.aomiClientRef.current.fetchState(
|
|
1170
1198
|
backendThreadId,
|
|
1171
|
-
userState
|
|
1199
|
+
userState,
|
|
1200
|
+
clientId
|
|
1172
1201
|
);
|
|
1173
1202
|
if (!this.intervals.has(threadId)) return;
|
|
1174
1203
|
this.handleState(threadId, state);
|
|
@@ -1235,6 +1264,7 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1235
1264
|
},
|
|
1236
1265
|
onSyncEvents: options.onSyncEvents,
|
|
1237
1266
|
getUserState: options.getUserState,
|
|
1267
|
+
getClientId: options.getClientId,
|
|
1238
1268
|
onStart: (threadId) => {
|
|
1239
1269
|
if (threadContextRef.current.currentThreadId === threadId) {
|
|
1240
1270
|
setIsRunning(true);
|
|
@@ -1257,29 +1287,32 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1257
1287
|
getPublicKey: options.getPublicKey,
|
|
1258
1288
|
getApp: options.getApp,
|
|
1259
1289
|
getApiKey: options.getApiKey,
|
|
1290
|
+
getClientId: options.getClientId,
|
|
1260
1291
|
getUserState: options.getUserState,
|
|
1261
1292
|
onSyncEvents: options.onSyncEvents
|
|
1262
1293
|
});
|
|
1263
1294
|
}
|
|
1264
1295
|
const ensureInitialState = useCallback5(async (threadId) => {
|
|
1265
|
-
var _a, _b, _c, _d;
|
|
1296
|
+
var _a, _b, _c, _d, _e;
|
|
1266
1297
|
if (pendingFetches.current.has(threadId)) return;
|
|
1267
1298
|
const backendThreadId = resolveThreadId(backendStateRef.current, threadId);
|
|
1268
1299
|
pendingFetches.current.add(threadId);
|
|
1269
1300
|
try {
|
|
1270
1301
|
const userState = (_a = options.getUserState) == null ? void 0 : _a.call(options);
|
|
1302
|
+
const clientId = (_b = options.getClientId) == null ? void 0 : _b.call(options);
|
|
1271
1303
|
const state = await aomiClientRef.current.fetchState(
|
|
1272
1304
|
backendThreadId,
|
|
1273
|
-
userState
|
|
1305
|
+
userState,
|
|
1306
|
+
clientId
|
|
1274
1307
|
);
|
|
1275
|
-
(
|
|
1276
|
-
if (((
|
|
1308
|
+
(_c = messageControllerRef.current) == null ? void 0 : _c.inbound(threadId, state.messages);
|
|
1309
|
+
if (((_d = state.system_events) == null ? void 0 : _d.length) && options.onSyncEvents) {
|
|
1277
1310
|
options.onSyncEvents(backendThreadId, state.system_events);
|
|
1278
1311
|
}
|
|
1279
1312
|
if (threadContextRef.current.currentThreadId === threadId) {
|
|
1280
1313
|
if (state.is_processing) {
|
|
1281
1314
|
setIsRunning(true);
|
|
1282
|
-
(
|
|
1315
|
+
(_e = pollingRef.current) == null ? void 0 : _e.start(threadId);
|
|
1283
1316
|
} else {
|
|
1284
1317
|
setIsRunning(false);
|
|
1285
1318
|
}
|
|
@@ -1615,7 +1648,7 @@ function AomiRuntimeCore({
|
|
|
1615
1648
|
const notificationContext = useNotification();
|
|
1616
1649
|
const { dispatchInboundSystem: dispatchSystemEvents } = eventContext;
|
|
1617
1650
|
const { user, onUserStateChange, getUserState } = useUser();
|
|
1618
|
-
const { getControlState, getCurrentThreadApp } = useControl();
|
|
1651
|
+
const { getControlState, getCurrentThreadApp, clearSecrets } = useControl();
|
|
1619
1652
|
const {
|
|
1620
1653
|
backendStateRef,
|
|
1621
1654
|
polling,
|
|
@@ -1629,7 +1662,11 @@ function AomiRuntimeCore({
|
|
|
1629
1662
|
getPublicKey: () => getUserState().address,
|
|
1630
1663
|
getUserState,
|
|
1631
1664
|
getApp: getCurrentThreadApp,
|
|
1632
|
-
getApiKey: () => getControlState().apiKey
|
|
1665
|
+
getApiKey: () => getControlState().apiKey,
|
|
1666
|
+
getClientId: () => {
|
|
1667
|
+
var _a;
|
|
1668
|
+
return (_a = getControlState().clientId) != null ? _a : void 0;
|
|
1669
|
+
}
|
|
1633
1670
|
});
|
|
1634
1671
|
const walletSnapshot = useCallback7(
|
|
1635
1672
|
(nextUser) => ({
|
|
@@ -1856,8 +1893,9 @@ function AomiRuntimeCore({
|
|
|
1856
1893
|
useEffect4(() => {
|
|
1857
1894
|
return () => {
|
|
1858
1895
|
polling.stopAll();
|
|
1896
|
+
void clearSecrets();
|
|
1859
1897
|
};
|
|
1860
|
-
}, [polling]);
|
|
1898
|
+
}, [polling, clearSecrets]);
|
|
1861
1899
|
const userContext = useUser();
|
|
1862
1900
|
const sendMessage = useCallback7(
|
|
1863
1901
|
async (text) => {
|