@blocklet/pages-kit 0.2.413 → 0.2.414

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.
@@ -38,7 +38,8 @@ function useRuntimeState() {
38
38
  yield sessionState.getState().load();
39
39
  }), [authSession, sessionState]);
40
40
  const execute = (0, react_1.useCallback)((args) => __awaiter(this, void 0, void 0, function* () {
41
- if (!authSession.user) {
41
+ var _a;
42
+ if (!((_a = agent.access) === null || _a === void 0 ? void 0 : _a.noLoginRequired) && !authSession.user) {
42
43
  yield login();
43
44
  }
44
45
  return exec(Object.assign(Object.assign({}, args), { blockletDid, working }));
@@ -242,12 +242,10 @@ const createSessionState = ({ aid }) => {
242
242
  }),
243
243
  execute: (_a) => __awaiter(void 0, void 0, void 0, function* () {
244
244
  var { blockletDid, aid, working, parameters, onResponseStart } = _a, args = __rest(_a, ["blockletDid", "aid", "working", "parameters", "onResponseStart"]);
245
- const sessionId = args.sessionId ||
246
- get().currentSessionId ||
247
- (yield get().createSession({
248
- name: parameters === null || parameters === void 0 ? void 0 : parameters.question,
249
- })).id;
250
245
  const identity = (0, aid_1.parseIdentity)(aid, { rejectWhenError: true });
246
+ let responseStarted = false;
247
+ let mainTaskId;
248
+ let sessionId = args.sessionId || get().currentSessionId;
251
249
  let message;
252
250
  set((state) => {
253
251
  var _a;
@@ -266,8 +264,6 @@ const createSessionState = ({ aid }) => {
266
264
  inputs: Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() }),
267
265
  responseType: 'stream',
268
266
  });
269
- let responseStarted = false;
270
- let mainTaskId;
271
267
  const reader = res.getReader();
272
268
  for (;;) {
273
269
  const { value, done } = yield reader.read();
@@ -280,6 +276,37 @@ const createSessionState = ({ aid }) => {
280
276
  if ((value === null || value === void 0 ? void 0 : value.type) === 'CHUNK') {
281
277
  if (!message) {
282
278
  mainTaskId = value.taskId;
279
+ sessionId = value.sessionId;
280
+ // set current session state for anonymous session
281
+ if (sessionId && sessionId !== args.sessionId) {
282
+ set((state) => {
283
+ var _a, _b;
284
+ state.sessions = [
285
+ ...((_a = state.sessions) !== null && _a !== void 0 ? _a : []),
286
+ {
287
+ id: sessionId,
288
+ projectId: identity.projectId,
289
+ agentId: identity.agentId,
290
+ createdAt: new Date().toISOString(),
291
+ updatedAt: new Date().toISOString(),
292
+ },
293
+ ];
294
+ state.currentSessionId = sessionId;
295
+ state.sessionMap = Object.fromEntries(state.sessions.map((i) => {
296
+ var _a;
297
+ return [
298
+ i.id,
299
+ Object.assign(Object.assign(Object.assign({}, (_a = state.sessionMap) === null || _a === void 0 ? void 0 : _a[i.id]), { session: i }), (i.id === sessionId ? { messages: [], loaded: true } : {})),
300
+ ];
301
+ }));
302
+ const s = (_b = state.sessionMap) === null || _b === void 0 ? void 0 : _b[sessionId];
303
+ if (!s)
304
+ return;
305
+ s.running = true;
306
+ s.error = undefined;
307
+ state.currentSessionId = sessionId;
308
+ });
309
+ }
283
310
  message = {
284
311
  id: value.messageId,
285
312
  agentId: identity.agentId,