@lobehub/lobehub 2.0.0-next.251 → 2.0.0-next.252

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/changelog/v1.json +9 -0
  3. package/package.json +1 -1
  4. package/packages/builtin-tool-notebook/src/client/Render/CreateDocument/DocumentCard.tsx +0 -2
  5. package/packages/database/migrations/meta/_journal.json +1 -1
  6. package/packages/database/src/models/__tests__/topics/topic.create.test.ts +37 -8
  7. package/packages/database/src/models/topic.ts +71 -4
  8. package/packages/database/src/schemas/agentCronJob.ts +1 -2
  9. package/packages/memory-user-memory/src/extractors/context.ts +1 -4
  10. package/packages/memory-user-memory/src/extractors/experience.ts +2 -8
  11. package/packages/memory-user-memory/src/extractors/preference.ts +2 -8
  12. package/packages/memory-user-memory/src/prompts/gatekeeper.ts +123 -123
  13. package/packages/memory-user-memory/src/prompts/layers/context.ts +152 -152
  14. package/packages/memory-user-memory/src/prompts/layers/experience.ts +159 -159
  15. package/packages/memory-user-memory/src/prompts/layers/identity.ts +213 -213
  16. package/packages/memory-user-memory/src/prompts/layers/preference.ts +160 -160
  17. package/packages/memory-user-memory/src/services/extractExecutor.ts +33 -30
  18. package/packages/memory-user-memory/src/types.ts +10 -8
  19. package/packages/types/src/topic/topic.ts +9 -0
  20. package/src/app/[variants]/(main)/chat/_layout/Sidebar/Body.tsx +4 -1
  21. package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/CronTopicList/CronTopicGroup.tsx +74 -0
  22. package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/CronTopicList/CronTopicItem.tsx +40 -0
  23. package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/CronTopicList/index.tsx +140 -0
  24. package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/List/index.tsx +1 -1
  25. package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/TopicListContent/index.tsx +1 -1
  26. package/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/index.tsx +1 -1
  27. package/src/app/[variants]/(main)/chat/cron/[cronId]/index.tsx +664 -0
  28. package/src/app/[variants]/(main)/chat/profile/features/AgentCronJobs/CronJobCards.tsx +160 -0
  29. package/src/app/[variants]/(main)/chat/profile/features/AgentCronJobs/CronJobForm.tsx +202 -0
  30. package/src/app/[variants]/(main)/chat/profile/features/AgentCronJobs/CronJobList.tsx +137 -0
  31. package/src/app/[variants]/(main)/chat/profile/features/AgentCronJobs/hooks/useAgentCronJobs.ts +138 -0
  32. package/src/app/[variants]/(main)/chat/profile/features/AgentCronJobs/index.tsx +130 -0
  33. package/src/app/[variants]/(main)/chat/profile/features/ProfileEditor/index.tsx +33 -3
  34. package/src/app/[variants]/router/desktopRouter.config.tsx +7 -0
  35. package/src/hooks/useFetchCronTopics.ts +29 -0
  36. package/src/hooks/useFetchCronTopicsWithJobInfo.ts +56 -0
  37. package/src/hooks/useFetchTopics.ts +4 -1
  38. package/src/locales/default/setting.ts +44 -1
  39. package/src/server/routers/lambda/agentCronJob.ts +367 -0
  40. package/src/server/routers/lambda/image/index.test.ts +2 -2
  41. package/src/server/routers/lambda/index.ts +2 -0
  42. package/src/server/routers/lambda/topic.ts +15 -3
  43. package/src/server/services/aiAgent/index.ts +18 -1
  44. package/src/server/services/memory/userMemory/extract.ts +14 -6
  45. package/src/services/agentCronJob.ts +95 -0
  46. package/src/services/topic/index.ts +1 -0
  47. package/src/store/chat/slices/topic/action.ts +53 -2
  48. package/src/store/chat/slices/topic/initialState.ts +1 -0
  49. package/src/store/chat/slices/topic/selectors.ts +14 -6
  50. package/src/tools/placeholders.ts +1 -4
@@ -38,6 +38,11 @@ const n = setNamespace('t');
38
38
 
39
39
  const SWR_USE_FETCH_TOPIC = 'SWR_USE_FETCH_TOPIC';
40
40
  const SWR_USE_SEARCH_TOPIC = 'SWR_USE_SEARCH_TOPIC';
41
+ type CronTopicsGroupWithJobInfo = {
42
+ cronJob: unknown;
43
+ cronJobId: string;
44
+ topics: ChatTopic[];
45
+ };
41
46
 
42
47
  /**
43
48
  * Options for switchTopic action
@@ -91,6 +96,7 @@ export interface ChatTopicAction {
91
96
  enable: boolean,
92
97
  params: {
93
98
  agentId?: string;
99
+ excludeTriggers?: string[];
94
100
  groupId?: string;
95
101
  isInbox?: boolean;
96
102
  pageSize?: number;
@@ -282,7 +288,34 @@ export const chatTopic: StateCreator<
282
288
  });
283
289
  },
284
290
  favoriteTopic: async (id, favorite) => {
291
+ const { activeAgentId } = get();
285
292
  await get().internal_updateTopic(id, { favorite });
293
+
294
+ if (!activeAgentId) return;
295
+
296
+ await mutate(
297
+ ['cronTopicsWithJobInfo', activeAgentId],
298
+ (groups?: CronTopicsGroupWithJobInfo[]) => {
299
+ if (!groups) return groups;
300
+
301
+ let updated = false;
302
+ const next = groups.map((group) => {
303
+ let groupUpdated = false;
304
+ const topics = group.topics.map((topic) => {
305
+ if (topic.id !== id) return topic;
306
+ if (topic.favorite === favorite) return topic;
307
+ groupUpdated = true;
308
+ updated = true;
309
+ return { ...topic, favorite };
310
+ });
311
+
312
+ return groupUpdated ? { ...group, topics } : group;
313
+ });
314
+
315
+ return updated ? next : groups;
316
+ },
317
+ { revalidate: false },
318
+ );
286
319
  },
287
320
 
288
321
  updateTopicMetadata: async (id, metadata) => {
@@ -314,15 +347,28 @@ export const chatTopic: StateCreator<
314
347
  },
315
348
 
316
349
  // query
317
- useFetchTopics: (enable, { agentId, groupId, pageSize: customPageSize, isInbox }) => {
350
+ useFetchTopics: (
351
+ enable,
352
+ { agentId, excludeTriggers, groupId, pageSize: customPageSize, isInbox },
353
+ ) => {
318
354
  const pageSize = customPageSize || 20;
355
+ const effectiveExcludeTriggers =
356
+ excludeTriggers && excludeTriggers.length > 0 ? excludeTriggers : undefined;
319
357
  // Use topicMapKey to generate the container key for topic data map
320
358
  const containerKey = topicMapKey({ agentId, groupId });
321
359
  const hasValidContainer = !!(groupId || agentId);
322
360
 
323
361
  return useClientDataSWRWithSync<{ items: ChatTopic[]; total: number }>(
324
362
  enable && hasValidContainer
325
- ? [SWR_USE_FETCH_TOPIC, containerKey, { isInbox, pageSize }]
363
+ ? [
364
+ SWR_USE_FETCH_TOPIC,
365
+ containerKey,
366
+ {
367
+ isInbox,
368
+ pageSize,
369
+ ...(effectiveExcludeTriggers ? { excludeTriggers: effectiveExcludeTriggers } : {}),
370
+ },
371
+ ]
326
372
  : null,
327
373
  async () => {
328
374
  // agentId, groupId, isInbox, pageSize come from the outer scope closure
@@ -343,6 +389,7 @@ export const chatTopic: StateCreator<
343
389
  const result = await topicService.getTopics({
344
390
  agentId,
345
391
  current: 0,
392
+ excludeTriggers: effectiveExcludeTriggers,
346
393
  groupId,
347
394
  isInbox,
348
395
  pageSize,
@@ -374,6 +421,7 @@ export const chatTopic: StateCreator<
374
421
  ...get().topicDataMap,
375
422
  [containerKey]: {
376
423
  currentPage: 0,
424
+ excludeTriggers: effectiveExcludeTriggers,
377
425
  hasMore,
378
426
  isExpandingPageSize: false,
379
427
  items: topics,
@@ -413,9 +461,11 @@ export const chatTopic: StateCreator<
413
461
 
414
462
  try {
415
463
  const pageSize = useGlobalStore.getState().status.topicPageSize || 20;
464
+ const excludeTriggers = currentData?.excludeTriggers;
416
465
  const result = await topicService.getTopics({
417
466
  agentId: activeAgentId,
418
467
  current: nextPage,
468
+ excludeTriggers,
419
469
  groupId: activeGroupId,
420
470
  pageSize,
421
471
  });
@@ -429,6 +479,7 @@ export const chatTopic: StateCreator<
429
479
  ...get().topicDataMap,
430
480
  [key]: {
431
481
  currentPage: nextPage,
482
+ excludeTriggers,
432
483
  hasMore,
433
484
  isLoadingMore: false,
434
485
  items: [...currentTopics, ...result.items],
@@ -5,6 +5,7 @@ import { type ChatTopic } from '@/types/topic';
5
5
  */
6
6
  export interface TopicData {
7
7
  currentPage: number;
8
+ excludeTriggers?: string[];
8
9
  hasMore: boolean;
9
10
  isExpandingPageSize?: boolean;
10
11
  isLoadingMore?: boolean;
@@ -18,27 +18,34 @@ const currentTopicData = (s: ChatStoreState): TopicData | undefined => {
18
18
 
19
19
  const currentTopics = (s: ChatStoreState): ChatTopic[] | undefined => currentTopicData(s)?.items;
20
20
 
21
+ // Get topics without cron-triggered ones
22
+ const currentTopicsWithoutCron = (s: ChatStoreState): ChatTopic[] | undefined => {
23
+ const topics = currentTopics(s);
24
+ if (!topics) return undefined;
25
+ return topics.filter((topic) => topic.trigger !== 'cron');
26
+ };
27
+
21
28
  const currentActiveTopic = (s: ChatStoreState): ChatTopic | undefined => {
22
29
  return currentTopics(s)?.find((topic) => topic.id === s.activeTopicId);
23
30
  };
24
31
  const searchTopics = (s: ChatStoreState): ChatTopic[] => s.searchTopics;
25
32
 
26
- const displayTopics = (s: ChatStoreState): ChatTopic[] | undefined => currentTopics(s);
33
+ const displayTopics = (s: ChatStoreState): ChatTopic[] | undefined => currentTopicsWithoutCron(s);
27
34
 
28
35
  const currentFavTopics = (s: ChatStoreState): ChatTopic[] =>
29
- currentTopics(s)?.filter((s) => s.favorite) || [];
36
+ currentTopicsWithoutCron(s)?.filter((s) => s.favorite) || [];
30
37
 
31
38
  const currentUnFavTopics = (s: ChatStoreState): ChatTopic[] =>
32
- currentTopics(s)?.filter((s) => !s.favorite) || [];
39
+ currentTopicsWithoutCron(s)?.filter((s) => !s.favorite) || [];
33
40
 
34
- const currentTopicLength = (s: ChatStoreState): number => currentTopicData(s)?.items?.length || 0;
41
+ const currentTopicLength = (s: ChatStoreState): number => currentTopicsWithoutCron(s)?.length || 0;
35
42
 
36
43
  const currentTopicCount = (s: ChatStoreState): number => currentTopicData(s)?.total || 0;
37
44
 
38
45
  const getTopicById =
39
46
  (id: string) =>
40
47
  (s: ChatStoreState): ChatTopic | undefined =>
41
- currentTopics(s)?.find((topic) => topic.id === id);
48
+ currentTopics(s)?.find((topic) => topic.id === id); // Don't filter here, need to access all topics by ID
42
49
 
43
50
  /**
44
51
  * Get topics by specific agentId (for AgentBuilder scenarios where agentId differs from activeAgentId)
@@ -79,7 +86,7 @@ const isSearchingTopic = (s: ChatStoreState) => s.isSearchingTopic;
79
86
  const displayTopicsForSidebar =
80
87
  (pageSize: number) =>
81
88
  (s: ChatStoreState): ChatTopic[] | undefined => {
82
- const topics = currentTopics(s);
89
+ const topics = currentTopicsWithoutCron(s);
83
90
  if (!topics) return undefined;
84
91
 
85
92
  // Return only the first page worth of topics for sidebar
@@ -143,6 +150,7 @@ export const topicSelectors = {
143
150
  currentTopicLength,
144
151
  currentTopicWorkingDirectory,
145
152
  currentTopics,
153
+ currentTopicsWithoutCron,
146
154
  currentUnFavTopics,
147
155
  displayTopics,
148
156
  displayTopicsForSidebar,
@@ -4,10 +4,7 @@ import {
4
4
  LocalSystemListFilesPlaceholder,
5
5
  LocalSystemSearchFilesPlaceholder,
6
6
  } from '@lobechat/builtin-tool-local-system/client';
7
- import {
8
- NotebookIdentifier,
9
- NotebookPlaceholders,
10
- } from '@lobechat/builtin-tool-notebook/client';
7
+ import { NotebookIdentifier, NotebookPlaceholders } from '@lobechat/builtin-tool-notebook/client';
11
8
  import {
12
9
  WebBrowsingManifest,
13
10
  WebBrowsingPlaceholders,