nolo-cli 0.188.0-alpha.1 → 0.188.0-alpha.2

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 (152) hide show
  1. package/{_executeModel-DIRZ5OVD.js → _executeModel-7GFCTOFY.js} +53 -52
  2. package/{accountResolver-NQJ57BVU.js → accountResolver-42BYPMVY.js} +5 -5
  3. package/{action-GPPJC5TI.js → action-HQXK4ZT4.js} +6 -5
  4. package/{addContentAction-XJQEJ4XW.js → addContentAction-3WAN3OWY.js} +11 -10
  5. package/{addDialogAgentAction-5WZX5CAY.js → addDialogAgentAction-WNQBFR5G.js} +13 -12
  6. package/{agentDeleteCommand-YBR3WPMA.js → agentDeleteCommand-GETUDKX4.js} +90 -89
  7. package/{agentEmailCommands-HCAJUPVT.js → agentEmailCommands-2EB4DJSA.js} +80 -79
  8. package/{agentListCommands-6N32GUGS.js → agentListCommands-6RONL2YO.js} +52 -51
  9. package/{agentMachineCommands-ICARPI2D.js → agentMachineCommands-J6SX7CPR.js} +36 -35
  10. package/{agentProviderCommands-FXEMNSZ2.js → agentProviderCommands-XSZUCNIR.js} +5 -5
  11. package/{agentPullCommand-7LHBOEYH.js → agentPullCommand-LGASFNH7.js} +5 -5
  12. package/{agentRecordCommands-SCC37ID4.js → agentRecordCommands-UXFGQXD6.js} +73 -72
  13. package/{agentRunCommand-LIEO5YKT.js → agentRunCommand-QTK73QMM.js} +78 -77
  14. package/{agentRunControl-SBHIICUQ.js → agentRunControl-6HHESKDB.js} +6 -6
  15. package/{agentRuntimeLocal-KMJAV6JL.js → agentRuntimeLocal-G4KEXO5D.js} +25 -24
  16. package/{agentSlice-XZODTFTF.js → agentSlice-STUDWJJZ.js} +12 -11
  17. package/{appDeleteCommands-KDKRH2S2.js → appDeleteCommands-6L6PTB6G.js} +33 -32
  18. package/{appDeployCommands-YNZIYHDK.js → appDeployCommands-PLXIHXN3.js} +33 -32
  19. package/{appDeployStatusCommands-CPGP7ELY.js → appDeployStatusCommands-VGYYEBTV.js} +33 -32
  20. package/{appGetCommands-VXKSPF54.js → appGetCommands-NAANWNTG.js} +33 -32
  21. package/{appListCommands-3QHVAMFI.js → appListCommands-ZT5YE2IX.js} +33 -32
  22. package/{authCommand-NR6NELQ7.js → authCommand-NVTKI7QU.js} +26 -25
  23. package/{authCommands-PIUTADO5.js → authCommands-RFLKIPBT.js} +9 -8
  24. package/{builtinSkillRegistry-RR35BY57.js → builtinSkillRegistry-2VN6JG4U.js} +4 -3
  25. package/{chromeCommands-EXJZ5HH5.js → chromeCommands-IVYZCGFL.js} +2 -2
  26. package/{chromeOpsCommands-ITBZEFBX.js → chromeOpsCommands-DOFY2OCF.js} +7 -7
  27. package/{chunk-KVUMIWLL.js → chunk-2RHDAHFX.js} +27 -27
  28. package/{chunk-IBZ2HGY7.js → chunk-3QFOYFJW.js} +9 -9
  29. package/{chunk-YBTP3PUM.js → chunk-4CEAZRZ4.js} +4 -4
  30. package/{chunk-GFHDRA4C.js → chunk-4OTMONZL.js} +22 -22
  31. package/{chunk-KHMJI7GE.js → chunk-53RSTB7T.js} +5 -5
  32. package/{chunk-GCOCWLIE.js → chunk-5LVGXDSL.js} +2 -2
  33. package/{chunk-EXAJ6DCR.js → chunk-5ZMIIR23.js} +3 -0
  34. package/{chunk-6JCZZDET.js → chunk-6G5V4Y3V.js} +89 -87
  35. package/{chunk-62TBKWTV.js → chunk-7DQSP7JU.js} +1 -1
  36. package/{chunk-V7QTD5MP.js → chunk-7N6C3IHF.js} +3 -3
  37. package/{chunk-JWEXJ573.js → chunk-7SJG5ZNX.js} +2 -2
  38. package/{chunk-SQOLMMXQ.js → chunk-A43QYPYN.js} +56 -54
  39. package/{chunk-MAYW6V3E.js → chunk-BA2FHPS4.js} +1 -1
  40. package/{chunk-CI5DVWU7.js → chunk-BTBT2566.js} +3 -3
  41. package/{chunk-YPG7TUQD.js → chunk-CLGAGPEM.js} +1 -1
  42. package/{chunk-NMFV26UG.js → chunk-CVMMWN6P.js} +6 -0
  43. package/{chunk-D2J22QSE.js → chunk-DYQXB46J.js} +10 -10
  44. package/{chunk-IF7V3CBU.js → chunk-ER4UTWWS.js} +4 -4
  45. package/{chunk-SJGHZTLV.js → chunk-FGIJLPZ3.js} +1 -1
  46. package/{chunk-ZZE2IJ5U.js → chunk-GSX7Z46F.js} +1 -1
  47. package/{chunk-W6E5IXIP.js → chunk-GTP6VNWH.js} +1 -1
  48. package/{chunk-ZKYRYOPF.js → chunk-H6FUDBS3.js} +12 -10
  49. package/{chunk-PO4IRXQ7.js → chunk-HVV4B6OL.js} +31 -31
  50. package/{chunk-LHRW5KFN.js → chunk-I3HWJODB.js} +1 -1
  51. package/{chunk-XLQ646HU.js → chunk-IFN7MHWL.js} +13 -13
  52. package/{chunk-KMSMIOOL.js → chunk-IIX6VWLW.js} +2 -2
  53. package/{chunk-ESMZW5PE.js → chunk-JOOWHDGM.js} +1 -1
  54. package/{chunk-K3TVMCV3.js → chunk-KOIGM3KU.js} +1 -1
  55. package/{chunk-NHEWV5FD.js → chunk-LBXUNNDS.js} +1 -1
  56. package/{chunk-OFFL4DCR.js → chunk-LEC5ALIN.js} +1 -1
  57. package/{chunk-GAGGEA7D.js → chunk-LEJSZV6V.js} +9 -9
  58. package/{chunk-BAWAKW7X.js → chunk-LOQYQUM2.js} +4 -4
  59. package/{chunk-APB44JID.js → chunk-MJWUBTK7.js} +1 -1
  60. package/{chunk-GUGCJ3DT.js → chunk-MMOISK6N.js} +14 -14
  61. package/{chunk-CR5WXQX7.js → chunk-N7E3LQ4A.js} +4 -4
  62. package/{chunk-QNLRCES2.js → chunk-NVOYW6H4.js} +3 -3
  63. package/{chunk-H5EQ2VTC.js → chunk-O2MBTX37.js} +7 -7
  64. package/{chunk-HEYJFOL6.js → chunk-OHRDHS4N.js} +1 -1
  65. package/{chunk-7XISFN2T.js → chunk-OXOXPREC.js} +1 -1
  66. package/{chunk-FDLDMJTM.js → chunk-P64WRQYV.js} +1 -1
  67. package/{chunk-FSIJK37C.js → chunk-PCPQWTXJ.js} +1 -1
  68. package/{chunk-P2BGRAW7.js → chunk-PVD7CRYV.js} +2 -2
  69. package/{chunk-TDBNIGUJ.js → chunk-PVZ3GB25.js} +10 -10
  70. package/{chunk-QSJLGX7K.js → chunk-Q54QGYRW.js} +14 -14
  71. package/{chunk-JOUFPRE4.js → chunk-QU3TLYBR.js} +5 -5
  72. package/{chunk-4NCLVO4U.js → chunk-R6AJKHEU.js} +3 -3
  73. package/{chunk-UKDHLQHS.js → chunk-RANCLEEC.js} +21 -19
  74. package/{chunk-77IXQ7PZ.js → chunk-RBVR7P3M.js} +56 -54
  75. package/{chunk-MILA23IG.js → chunk-RGTPR57U.js} +20 -18
  76. package/{chunk-YYKHIX4X.js → chunk-RJ3EYB5G.js} +1 -1
  77. package/{chunk-NSASNKVD.js → chunk-S4W4GV3B.js} +8 -6
  78. package/{chunk-OKKTPAKC.js → chunk-VECM2WX3.js} +12 -12
  79. package/{chunk-U7BOZFAD.js → chunk-VH7PE33C.js} +81 -79
  80. package/{chunk-IHQ7RMRS.js → chunk-WBCYL63M.js} +6 -6
  81. package/{chunk-XAFCJN32.js → chunk-WFUIXNKC.js} +1 -1
  82. package/{chunk-5EMSBTQ6.js → chunk-WMHWFFTE.js} +480 -224
  83. package/chunk-XJWWBO34.js +69 -0
  84. package/{chunk-CDLP56BS.js → chunk-Y2ZDNW2H.js} +17 -15
  85. package/{chunk-3L5MSPWX.js → chunk-YIRADHSY.js} +1 -1
  86. package/{chunk-DEO4FC7J.js → chunk-YUZIPPER.js} +3 -3
  87. package/{chunk-D6222KXV.js → chunk-ZIOYHDYW.js} +2 -2
  88. package/{chunk-XI7DGLUK.js → chunk-ZSO5B6SW.js} +3 -3
  89. package/cliAuthorityBrokerClient-PM3U6Q6J.js +21 -0
  90. package/cliAuthorityStoreDriver-TKLXNNTG.js +20 -0
  91. package/{commandRegistry-I6CNP54W.js → commandRegistry-MTKBHP45.js} +87 -87
  92. package/{contentThunks-U5ZQJBCJ.js → contentThunks-E4DHXF3M.js} +27 -26
  93. package/{createAgentAutomationAction-O5MAEWFH.js → createAgentAutomationAction-2P2II7B3.js} +30 -29
  94. package/{createDialogAction-6FEVBVYE.js → createDialogAction-MFZGE5EO.js} +29 -28
  95. package/{createPageAction-QJJX3V2F.js → createPageAction-SBU2YCNR.js} +32 -31
  96. package/cursorProvider-YGGNMVWX.js +1 -1
  97. package/{dbSlice-6PVPY44C.js → dbSlice-2O3YBVPP.js} +10 -9
  98. package/{deleteFile-YM6NDPAR.js → deleteFile-R5OBP7OM.js} +5 -5
  99. package/{dialogCommands-EDFRNBDA.js → dialogCommands-AWGFKOGS.js} +40 -39
  100. package/{dialogSlice-4J2R6S63.js → dialogSlice-GKPCUQWM.js} +25 -24
  101. package/dialogUsageCommand-44XMU6DD.js +246 -0
  102. package/{docCreateCommands-J6RRFAAL.js → docCreateCommands-4JEKXNST.js} +32 -31
  103. package/{docDeleteCommands-4KIMCR5H.js → docDeleteCommands-Q5K4UJPQ.js} +33 -32
  104. package/{docReadCommands-2UZQOOA7.js → docReadCommands-ZZ7HMGPV.js} +32 -31
  105. package/{docStore-CMJSEKU5.js → docStore-DOZVBVKZ.js} +12 -11
  106. package/{docUpdateCommands-OLZENBFB.js → docUpdateCommands-NUFXB6BD.js} +32 -31
  107. package/{fetchMessages-IIJWQ3HR.js → fetchMessages-QLW7INJJ.js} +4 -3
  108. package/{getPricing-2UPNNW3Y.js → getPricing-E2PLNWCR.js} +3 -3
  109. package/{handleSendMessageAction-ON2OCZ2O.js → handleSendMessageAction-FY4RBJEA.js} +46 -45
  110. package/index.js +7 -7
  111. package/keys-N6HQICY5.js +170 -0
  112. package/{localDialogRead-FSOMOPDZ.js → localDialogRead-55YDVPNU.js} +1 -1
  113. package/{localRuntimeAdapter-KYWEHSY3.js → localRuntimeAdapter-KCS5Y4T6.js} +70 -69
  114. package/{localRuntimeAuthority-BPN5OAQG.js → localRuntimeAuthority-NEGF3LRQ.js} +3 -3
  115. package/{localRuntimeDb-QIVAXMUL.js → localRuntimeDb-SDYFAEKA.js} +1 -1
  116. package/{machineCommands-PZYWWGXH.js → machineCommands-E3HMAMLA.js} +78 -77
  117. package/{machineWsRunDispatch-H7OSNRUO.js → machineWsRunDispatch-MGDBTLDX.js} +71 -70
  118. package/{memberThunks-AZINUM4S.js → memberThunks-VXT36MZP.js} +15 -14
  119. package/package.json +1 -1
  120. package/{providerPresetApply-MBMGCNKZ.js → providerPresetApply-JGNMO2KX.js} +5 -5
  121. package/{providerRegistry-P4KYS6SE.js → providerRegistry-33J3ZYFJ.js} +5 -5
  122. package/{read-7JPIWRBQ.js → read-D6NEWSGG.js} +5 -5
  123. package/{readDocTool-AAQTB2Y3.js → readDocTool-NTAXO7SX.js} +1 -1
  124. package/{readlineWorkspace-DTAJBA43.js → readlineWorkspace-IWWKZK3F.js} +116 -115
  125. package/{removeDialogAgentAction-RMVRILLK.js → removeDialogAgentAction-PK24DJ2J.js} +15 -14
  126. package/{runAgentClientLoop-KW7EFI6H.js → runAgentClientLoop-CFIM6MXT.js} +49 -48
  127. package/{runtimeDoctorCommands-DXJH5HIB.js → runtimeDoctorCommands-NYBOTA6D.js} +20 -20
  128. package/{setDialogExtraReferencesAction-L3V7JTMG.js → setDialogExtraReferencesAction-BN4IBUO6.js} +12 -11
  129. package/{setPrimaryDialogAgentAction-X52JQGTJ.js → setPrimaryDialogAgentAction-JR5SMLZY.js} +15 -14
  130. package/{settingThunks-N6XFWPOU.js → settingThunks-RJZQHL7H.js} +12 -10
  131. package/{spaceCommands-AUZVTCVH.js → spaceCommands-BI3TRIAK.js} +32 -31
  132. package/{streamAgentChatTurn-TGC24NGV.js → streamAgentChatTurn-3BS7IAFR.js} +67 -66
  133. package/{switchDialogAgentAction-ZJ5CGU7J.js → switchDialogAgentAction-TSIXBNRH.js} +13 -12
  134. package/{tools-N77X52PL.js → tools-PCTUYG54.js} +43 -42
  135. package/{tuiSummaryLlmCaller-5D3XCH2C.js → tuiSummaryLlmCaller-FSOADMXK.js} +12 -12
  136. package/{updateCommands-MZCY6FXK.js → updateCommands-Y6CKFKIF.js} +3 -3
  137. package/{updateDialogTitleAction-EH3LIVRX.js → updateDialogTitleAction-ZHFIMEQL.js} +32 -31
  138. package/dialogUsageCommand-ZPESQB6W.js +0 -136
  139. package/{agentGrantCommands-LPVAJ6KR.js → agentGrantCommands-V5FOQKFD.js} +3 -3
  140. package/{chunk-I2QHI2XM.js → chunk-4YMD7B4Y.js} +3 -3
  141. package/{chunk-ZJ7UHBJS.js → chunk-5XBUWM6I.js} +3 -3
  142. package/{chunk-YXTMZQGX.js → chunk-7JWW65DU.js} +3 -3
  143. package/{chunk-43OFVLWJ.js → chunk-7UODCAWW.js} +8 -8
  144. package/{chunk-CSINZLH7.js → chunk-JIFYXQRD.js} +3 -3
  145. package/{chunk-AA5GKA2X.js → chunk-RKLQVXUE.js} +3 -3
  146. package/{chunk-LIQJTQRN.js → chunk-TRZP7JZ7.js} +3 -3
  147. package/{chunk-FKOCI2WR.js → chunk-UBLITLAZ.js} +3 -3
  148. package/{chunk-TDNAAXUQ.js → chunk-ZBCBFOWC.js} +3 -3
  149. package/{memoryCommands-YLT3ADGQ.js → memoryCommands-ASCE5STX.js} +3 -3
  150. package/{offlineMarxistsAgentCommand-3GLX4QQY.js → offlineMarxistsAgentCommand-2QTHJCHV.js} +3 -3
  151. package/{tableCommands-IVC5S7Y3.js → tableCommands-QYB64L5I.js} +7 -7
  152. package/{workloadLifecycle-2F5YKFGW.js → workloadLifecycle-JA75D6JR.js} +3 -3
@@ -1,3 +1,6 @@
1
+ import {
2
+ ulid
3
+ } from "./chunk-XJWWBO34.js";
1
4
  import {
2
5
  asNonEmptyStringArray
3
6
  } from "./chunk-I42VC5KR.js";
@@ -2393,25 +2396,180 @@ var require_rambda = __commonJS({
2393
2396
  }
2394
2397
  });
2395
2398
 
2399
+ // packages/database/keys.ts
2400
+ var import_rambda = __toESM(require_rambda(), 1);
2401
+
2396
2402
  // packages/core/toTrimmedString.ts
2397
2403
  function toTrimmedString(value) {
2398
2404
  return typeof value === "string" ? value.trim() : value == null ? "" : String(value).trim();
2399
2405
  }
2400
2406
 
2401
- // packages/database/utils/ulid.ts
2402
- import { monotonicFactory } from "ulid";
2403
- var prng = () => Math.random();
2404
- var ulid = monotonicFactory(prng);
2405
-
2406
- // packages/database/keys.ts
2407
- var import_rambda = __toESM(require_rambda(), 1);
2408
-
2409
2407
  // packages/core/userId.ts
2410
2408
  function normalizeUserId(value) {
2411
2409
  const text = asTrimmedString(value);
2412
2410
  return text.startsWith("user:") ? text.slice("user:".length) : text;
2413
2411
  }
2414
2412
 
2413
+ // packages/share/helpers.ts
2414
+ var toSafeString = (value) => asTrimmedString(value);
2415
+ var toNonEmptyString = (value) => {
2416
+ const text = toSafeString(value);
2417
+ return text || void 0;
2418
+ };
2419
+ var toSafeAgentKey = (value) => {
2420
+ const text = toSafeString(value);
2421
+ return text && isAgentKey(text) ? text : "";
2422
+ };
2423
+ var SHARE_TIME_FORMATTER = new Intl.DateTimeFormat("zh-CN", {
2424
+ timeZone: "Asia/Shanghai",
2425
+ year: "numeric",
2426
+ month: "2-digit",
2427
+ day: "2-digit",
2428
+ hour: "2-digit",
2429
+ minute: "2-digit",
2430
+ second: "2-digit",
2431
+ hour12: false
2432
+ });
2433
+ var findAgentKeyInMessages = (messages) => {
2434
+ for (const raw of messages) {
2435
+ if (!raw || typeof raw !== "object") continue;
2436
+ const key = toSafeAgentKey(raw.cybotKey);
2437
+ if (key) return key;
2438
+ }
2439
+ return "";
2440
+ };
2441
+ var findAgentKeyInArray = (items) => {
2442
+ for (const raw of items) {
2443
+ const direct = toSafeAgentKey(raw);
2444
+ if (direct) return direct;
2445
+ if (!raw || typeof raw !== "object") continue;
2446
+ const item = raw;
2447
+ const key = toSafeAgentKey(item.dbKey) || toSafeAgentKey(item.id);
2448
+ if (key) return key;
2449
+ }
2450
+ return "";
2451
+ };
2452
+ var findAgentNameInMessages = (messages) => {
2453
+ for (const raw of messages) {
2454
+ if (!raw || typeof raw !== "object") continue;
2455
+ const msg = raw;
2456
+ const name = toSafeString(msg.agentName) || toSafeString(msg.cybotName) || toSafeString(msg.sourceAgentName);
2457
+ if (name) return name;
2458
+ }
2459
+ return "";
2460
+ };
2461
+ var findAgentNameInArray = (items) => {
2462
+ for (const raw of items) {
2463
+ if (!raw || typeof raw !== "object") continue;
2464
+ const item = raw;
2465
+ const name = toSafeString(item.name) || toSafeString(item.agentName) || toSafeString(item.cybotName) || toSafeString(item.sourceAgentName);
2466
+ if (name) return name;
2467
+ }
2468
+ return "";
2469
+ };
2470
+ var extractAgentInfo = (type, data) => {
2471
+ const meta = data.meta;
2472
+ const keyCandidates = [
2473
+ meta?.sourceAgentKey,
2474
+ meta?.agentKey,
2475
+ data.sourceAgentKey,
2476
+ data.agentKey,
2477
+ data.cybotKey,
2478
+ type === "cybot" ? data.dbKey ?? data.id : void 0
2479
+ ];
2480
+ let agentKey = "";
2481
+ for (const candidate of keyCandidates) {
2482
+ agentKey = toSafeAgentKey(candidate);
2483
+ if (agentKey) break;
2484
+ }
2485
+ if (!agentKey && Array.isArray(data.cybots)) {
2486
+ agentKey = findAgentKeyInArray(data.cybots);
2487
+ }
2488
+ if (!agentKey && Array.isArray(data.messages)) {
2489
+ agentKey = findAgentKeyInMessages(data.messages);
2490
+ }
2491
+ if (!agentKey && Array.isArray(data.history)) {
2492
+ agentKey = findAgentKeyInMessages(data.history);
2493
+ }
2494
+ const nameCandidates = [
2495
+ meta?.sourceAgentName,
2496
+ meta?.agentName,
2497
+ meta?.cybotName,
2498
+ data.sourceAgentName,
2499
+ data.agentName,
2500
+ data.cybotName,
2501
+ type === "cybot" ? data.name : void 0
2502
+ ];
2503
+ let agentName = "";
2504
+ for (const candidate of nameCandidates) {
2505
+ agentName = toSafeString(candidate);
2506
+ if (agentName) break;
2507
+ }
2508
+ if (!agentName && Array.isArray(data.cybots)) {
2509
+ agentName = findAgentNameInArray(data.cybots);
2510
+ }
2511
+ if (!agentName && Array.isArray(data.messages)) {
2512
+ agentName = findAgentNameInMessages(data.messages);
2513
+ }
2514
+ if (!agentName && Array.isArray(data.history)) {
2515
+ agentName = findAgentNameInMessages(data.history);
2516
+ }
2517
+ return {
2518
+ ...agentKey ? { sourceAgentKey: agentKey } : {},
2519
+ ...agentName ? { sourceAgentName: agentName } : {}
2520
+ };
2521
+ };
2522
+ var extractImageFromContent = (content) => {
2523
+ if (Array.isArray(content)) {
2524
+ const part = content.find(
2525
+ (p) => p?.type === "image_url" && typeof p?.image_url?.url === "string"
2526
+ );
2527
+ if (part?.image_url?.url) return part.image_url.url;
2528
+ }
2529
+ if (typeof content === "string") {
2530
+ const match = content.match(/!\[.*?\]\((.*?)\)/);
2531
+ if (match?.[1]) return match[1];
2532
+ }
2533
+ return void 0;
2534
+ };
2535
+ var extractCoverImage = (type, data) => {
2536
+ if (type === "image" /* IMAGE */) {
2537
+ return toNonEmptyString(data.url);
2538
+ }
2539
+ if (type === "app" /* APP */) {
2540
+ return toNonEmptyString(data.coverImage);
2541
+ }
2542
+ if (type !== "dialog" /* DIALOG */) return void 0;
2543
+ const messages = Array.isArray(data.messages) ? data.messages : Array.isArray(data.history) ? data.history : [];
2544
+ for (const msg of messages) {
2545
+ const fromContent = extractImageFromContent(msg.content);
2546
+ if (fromContent) return fromContent;
2547
+ const image = toNonEmptyString(msg.image);
2548
+ if (image) return image;
2549
+ if (Array.isArray(msg.images)) {
2550
+ const first = asNonEmptyStringArray(msg.images)[0];
2551
+ if (first) return first;
2552
+ }
2553
+ }
2554
+ return void 0;
2555
+ };
2556
+ var resolveShareAuthorIdentity = (args) => {
2557
+ const authorName = toNonEmptyString(args.profile?.nickname) ?? toNonEmptyString(args.user?.name) ?? toNonEmptyString(args.user?.nickname) ?? toNonEmptyString(args.user?.username) ?? toNonEmptyString(args.fallbackName);
2558
+ const authorAvatar = toNonEmptyString(args.profile?.avatar) ?? toNonEmptyString(args.user?.avatar) ?? toNonEmptyString(args.fallbackAvatar);
2559
+ return {
2560
+ ...authorName ? { authorName } : {},
2561
+ ...authorAvatar ? { authorAvatar } : {}
2562
+ };
2563
+ };
2564
+ var SENSITIVE_FIELDS = ["apiKey", "secret", "password"];
2565
+ var sanitizeShareData = (data) => {
2566
+ const snapshot = { ...data };
2567
+ for (const field of SENSITIVE_FIELDS) {
2568
+ delete snapshot[field];
2569
+ }
2570
+ return snapshot;
2571
+ };
2572
+
2415
2573
  // packages/share/keys.ts
2416
2574
  var SHARE_PREFIX = "share";
2417
2575
  var SHARE_INDEX_PREFIX = "shareidx";
@@ -2457,14 +2615,14 @@ var createOwnerRange = (rawUserId) => {
2457
2615
  const start = createKey(SHARE_INDEX_PREFIX, "owner", userId, "");
2458
2616
  return { start, end: start + "\uFFFF" };
2459
2617
  };
2460
- var findAgentKeyInArray = (arr) => {
2618
+ var findAgentKeyInArray2 = (arr) => {
2461
2619
  for (const item of arr) {
2462
2620
  const key = toSafeAgentKey(item);
2463
2621
  if (key) return key;
2464
2622
  }
2465
2623
  return "";
2466
2624
  };
2467
- var findAgentKeyInMessages = (messages) => {
2625
+ var findAgentKeyInMessages2 = (messages) => {
2468
2626
  for (const raw of messages) {
2469
2627
  if (!raw || typeof raw !== "object") continue;
2470
2628
  const key = toSafeAgentKey(raw.cybotKey);
@@ -2502,15 +2660,15 @@ var resolveAgentKeyFromPayload = (data) => {
2502
2660
  if (key) return key;
2503
2661
  }
2504
2662
  if (Array.isArray(payload?.cybots)) {
2505
- const key = findAgentKeyInArray(payload.cybots);
2663
+ const key = findAgentKeyInArray2(payload.cybots);
2506
2664
  if (key) return key;
2507
2665
  }
2508
2666
  if (Array.isArray(payload?.messages)) {
2509
- const key = findAgentKeyInMessages(payload.messages);
2667
+ const key = findAgentKeyInMessages2(payload.messages);
2510
2668
  if (key) return key;
2511
2669
  }
2512
2670
  if (Array.isArray(payload?.history)) {
2513
- const key = findAgentKeyInMessages(payload.history);
2671
+ const key = findAgentKeyInMessages2(payload.history);
2514
2672
  if (key) return key;
2515
2673
  }
2516
2674
  }
@@ -2580,45 +2738,10 @@ var shareKey = {
2580
2738
  }
2581
2739
  };
2582
2740
 
2583
- // packages/database/dialogKey.ts
2584
- var SEPARATOR = "-";
2585
- var createKey2 = (...parts) => parts.join(SEPARATOR);
2586
- var splitKey2 = (key) => key.split(SEPARATOR);
2587
- var isDialogKey = (key) => {
2588
- const parts = splitKey2(key);
2589
- return parts.length >= 3 && parts[0] === "dialog" /* DIALOG */;
2590
- };
2591
- var isDialogRecordKey = (key) => {
2592
- if (typeof key !== "string" || !key.startsWith(`${"dialog" /* DIALOG */}-`)) return false;
2593
- if (key.includes("-msg-")) return false;
2594
- const parts = splitKey2(key);
2595
- return parts.length >= 3 && parts[0] === "dialog" /* DIALOG */;
2596
- };
2597
- var createDialogKey = Object.assign(
2598
- (userId) => createKey2("dialog" /* DIALOG */, userId, ulid()),
2599
- {
2600
- single: (userId, dialogId) => createKey2("dialog" /* DIALOG */, userId, dialogId),
2601
- rangeOfUser: (userId) => ({
2602
- start: createKey2("dialog" /* DIALOG */, userId, ""),
2603
- end: createKey2("dialog" /* DIALOG */, userId, "\uFFFF")
2604
- })
2605
- }
2606
- );
2607
- var dialogMessageKey = (dialogId, messageId) => createKey2("dialog" /* DIALOG */, dialogId, "msg", messageId);
2608
- var createDialogMessageKeyAndId = (dialogId, ulidFn = ulid) => {
2609
- const messageId = ulidFn();
2610
- return { key: dialogMessageKey(dialogId, messageId), messageId };
2611
- };
2612
- var dialogMessagePrefix = (dialogId) => createKey2("dialog" /* DIALOG */, dialogId, "msg");
2613
- var dialogMessageRange = (dialogId) => ({
2614
- start: createKey2("dialog" /* DIALOG */, dialogId, "msg", ""),
2615
- end: createKey2("dialog" /* DIALOG */, dialogId, "msg", "\uFFFF")
2616
- });
2617
-
2618
2741
  // packages/database/keys.ts
2619
- var SEPARATOR2 = "-";
2620
- var createKey = (...parts) => parts.join(SEPARATOR2);
2621
- var splitKey = (key) => key.split(SEPARATOR2);
2742
+ var SEPARATOR = "-";
2743
+ var createKey = (...parts) => parts.join(SEPARATOR);
2744
+ var splitKey = (key) => key.split(SEPARATOR);
2622
2745
  var TYPE_STORAGE_PREFIXES = {
2623
2746
  ["app" /* APP */]: ["app"],
2624
2747
  ["page" /* DOC */]: ["page"],
@@ -2637,6 +2760,13 @@ var _PREFIX_TO_TYPE = (() => {
2637
2760
  }
2638
2761
  return map;
2639
2762
  })();
2763
+ function inferTypeFromDbKey(dbKey) {
2764
+ if (!dbKey) return null;
2765
+ const firstSep = dbKey.indexOf(SEPARATOR);
2766
+ if (firstSep < 0) return null;
2767
+ const prefix = dbKey.slice(0, firstSep);
2768
+ return _PREFIX_TO_TYPE.get(prefix) ?? null;
2769
+ }
2640
2770
  var isTableMetaKey = (key) => {
2641
2771
  const parts = splitKey(key);
2642
2772
  return parts.length >= 3 && parts[0] === "meta";
@@ -2649,11 +2779,14 @@ var isTaskKey = (key) => {
2649
2779
  const parts = splitKey(key);
2650
2780
  return parts.length >= 3 && parts[0] === "task" /* TASK */;
2651
2781
  };
2782
+ var isAgentAutomationKey = (key) => {
2783
+ return key.startsWith(`${"agent-automation" /* AGENT_AUTOMATION */}-`);
2784
+ };
2652
2785
  var isFileKey = (key) => {
2653
2786
  const parts = splitKey(key);
2654
2787
  return parts.length >= 3 && (parts[0] === "file" /* FILE */ || parts[0] === "image" /* IMAGE */);
2655
2788
  };
2656
- var isAgentKey2 = (key) => {
2789
+ var isAgentKey = (key) => {
2657
2790
  const parts = splitKey(key);
2658
2791
  return parts.length >= 3 && parts[0] === "agent" /* AGENT */;
2659
2792
  };
@@ -2661,6 +2794,10 @@ var isAppKey = (key) => {
2661
2794
  const parts = splitKey(key);
2662
2795
  return parts.length >= 2 && parts[0] === "app" /* APP */;
2663
2796
  };
2797
+ var isEmailKey = (key) => {
2798
+ const parts = splitKey(key);
2799
+ return parts.length >= 3 && parts[0] === "email" /* EMAIL */;
2800
+ };
2664
2801
  var rowKey = {
2665
2802
  /** 生成新行主键 + rowId */
2666
2803
  create: (tenantId, tableId) => {
@@ -2694,6 +2831,37 @@ var rowKey = {
2694
2831
  };
2695
2832
  }
2696
2833
  };
2834
+ var idxKey = {
2835
+ /** 写入单条索引 */
2836
+ put: (tenantId, tableId, indexName, indexKey, rowId) => createKey("idx", tenantId, tableId, indexName, indexKey, rowId),
2837
+ /** 某一索引名前缀的范围(start / end)—— 供前缀扫描 */
2838
+ range: (tenantId, tableId, indexName, indexKeyPrefix = "") => {
2839
+ const start = createKey(
2840
+ "idx",
2841
+ tenantId,
2842
+ tableId,
2843
+ indexName,
2844
+ indexKeyPrefix
2845
+ );
2846
+ return { start, end: start + "\uFFFF" };
2847
+ },
2848
+ /** 整张表所有索引的范围(gte / lte)—— 供整表删除 */
2849
+ prefix: (tenantId, tableId) => {
2850
+ const start = createKey("idx", tenantId, tableId, "");
2851
+ return {
2852
+ gte: start,
2853
+ lte: start + "\uFFFF"
2854
+ };
2855
+ },
2856
+ /** 某个租户的所有索引范围 */
2857
+ rangeOfTenant: (tenantId) => {
2858
+ const start = createKey("idx", tenantId, "");
2859
+ return {
2860
+ start,
2861
+ end: start + "\uFFFF"
2862
+ };
2863
+ }
2864
+ };
2697
2865
  var metaKey = Object.assign(
2698
2866
  (tenantId, tableId) => createKey("meta", tenantId, tableId),
2699
2867
  {
@@ -2707,10 +2875,41 @@ var metaKey = Object.assign(
2707
2875
  }
2708
2876
  }
2709
2877
  );
2878
+ var viewKey = {
2879
+ /** 创建一个新视图 key + viewId(由调用方生成或传入) */
2880
+ create: (tenantId, tableId, viewId) => {
2881
+ const id = viewId || ulid();
2882
+ const dbKey = createKey("view", tenantId, tableId, id);
2883
+ return { dbKey, id };
2884
+ },
2885
+ /** 某一视图的单键 */
2886
+ single: (tenantId, tableId, viewId) => createKey("view", tenantId, tableId, viewId),
2887
+ /** 某张表下面的所有视图范围 */
2888
+ rangeOfTable: (tenantId, tableId) => {
2889
+ const start = createKey("view", tenantId, tableId, "");
2890
+ return {
2891
+ start,
2892
+ end: start + "\uFFFF"
2893
+ };
2894
+ },
2895
+ /** 某个租户的所有视图范围 */
2896
+ rangeOfTenant: (tenantId) => {
2897
+ const start = createKey("view", tenantId, "");
2898
+ return {
2899
+ start,
2900
+ end: start + "\uFFFF"
2901
+ };
2902
+ }
2903
+ };
2710
2904
  var DB_PREFIX = {
2711
2905
  USER: "user:"
2712
2906
  };
2713
- var USER_SETTINGS_KEY_SUFFIX = `${SEPARATOR2}settings`;
2907
+ var createOAuthCredentialKey = (userId, provider) => createKey("oauth", userId, provider);
2908
+ var oauthCredentialUserRange = (userId) => ({
2909
+ start: createKey("oauth", userId, ""),
2910
+ end: createKey("oauth", userId, "\uFFFF")
2911
+ });
2912
+ var USER_SETTINGS_KEY_SUFFIX = `${SEPARATOR}settings`;
2714
2913
  var createUserKey = {
2715
2914
  settings: (userId) => `${userId}${USER_SETTINGS_KEY_SUFFIX}`,
2716
2915
  profile: (userId) => createKey(userId, "profile")
@@ -2735,6 +2934,10 @@ var createMemorySubjectKindIndexKey = (subjectType, subjectId, kind, createdAt,
2735
2934
  createdAt,
2736
2935
  memoryId
2737
2936
  );
2937
+ var isMemoryKey = (key) => {
2938
+ const parts = splitKey(key);
2939
+ return parts.length >= 4 && parts[0] === "mem";
2940
+ };
2738
2941
  var memoryOwnerRange = (ownerType, ownerId) => ({
2739
2942
  start: createKey("memidx", "owner", ownerType, ownerId, ""),
2740
2943
  end: createKey("memidx", "owner", ownerType, ownerId, "\uFFFF")
@@ -2807,6 +3010,10 @@ var createTokenStatsAppliedKey = Object.assign(
2807
3010
  })
2808
3011
  }
2809
3012
  );
3013
+ var isTokenStatsKey = (key) => {
3014
+ const parts = splitKey(key);
3015
+ return parts.length >= 2 && parts[0] === "token" && parts[1] === "stats";
3016
+ };
2810
3017
  var DIALOG_AGENT_LIST_INDEX_PREFIX = "dialogidx";
2811
3018
  var DIALOG_LIST_TIMESTAMP_MAX = 9999999999999;
2812
3019
  function parseDialogUpdatedAtMs(value) {
@@ -2845,6 +3052,21 @@ function createDialogAgentListIndexKey(args) {
2845
3052
  dialogId
2846
3053
  );
2847
3054
  }
3055
+ function createDialogAgentListIndexRange(userId, agentKey) {
3056
+ const normalizedUserId = userId.trim();
3057
+ const normalizedAgentKey = agentKey.trim();
3058
+ if (!normalizedUserId || !normalizedAgentKey) {
3059
+ return { start: "", end: "" };
3060
+ }
3061
+ const start = createKey(
3062
+ DIALOG_AGENT_LIST_INDEX_PREFIX,
3063
+ "agent",
3064
+ normalizedUserId,
3065
+ normalizedAgentKey,
3066
+ ""
3067
+ );
3068
+ return { start, end: `${start}\uFFFF` };
3069
+ }
2848
3070
  function expandDialogAgentListIndexAliases(agentKey) {
2849
3071
  const key = agentKey.trim();
2850
3072
  if (!key) return [];
@@ -2973,6 +3195,7 @@ var createAgentAutomationKey = Object.assign(
2973
3195
  })
2974
3196
  }
2975
3197
  );
3198
+ var agentAutomationKey = createAgentAutomationKey;
2976
3199
  var AGENT_AUTOMATION_OWNER_INDEX_PREFIX = "agent-automation-owner-idx";
2977
3200
  var createAgentAutomationOwnerIndexKey = Object.assign(
2978
3201
  (userId, ownerAgentKey, automationId) => createKey(
@@ -3001,6 +3224,56 @@ function buildAgentAutomationOwnerIndexValue(args) {
3001
3224
  ownerAgentKey: args.ownerAgentKey
3002
3225
  };
3003
3226
  }
3227
+ function isAgentAutomationOwnerIndexKey(key) {
3228
+ return key.startsWith(`${AGENT_AUTOMATION_OWNER_INDEX_PREFIX}-`);
3229
+ }
3230
+ function parseAgentAutomationIdFromKey(key) {
3231
+ if (typeof key !== "string") return "";
3232
+ const trimmed = key.trim();
3233
+ if (!trimmed || !isAgentAutomationKey(trimmed)) return "";
3234
+ const withoutPrefix = trimmed.slice(`${"agent-automation" /* AGENT_AUTOMATION */}-`.length);
3235
+ const lastDash = withoutPrefix.lastIndexOf("-");
3236
+ return lastDash >= 0 ? withoutPrefix.slice(lastDash + 1) : "";
3237
+ }
3238
+ function buildAgentAutomationOwnerIndexDeleteOps(args) {
3239
+ const automationKey = args.automationKey.trim();
3240
+ if (!automationKey || !isAgentAutomationKey(automationKey)) return [];
3241
+ const userIdFromRecord = asTrimmedString(args.record?.createdBy);
3242
+ const userIdFromArg = asTrimmedString(args.userId);
3243
+ const withoutPrefix = automationKey.startsWith(`${"agent-automation" /* AGENT_AUTOMATION */}-`) ? automationKey.slice(`${"agent-automation" /* AGENT_AUTOMATION */}-`.length) : "";
3244
+ const lastDash = withoutPrefix.lastIndexOf("-");
3245
+ const userIdFromKey = lastDash > 0 ? withoutPrefix.slice(0, lastDash) : "";
3246
+ const automationIdFromKey = lastDash > 0 ? withoutPrefix.slice(lastDash + 1) : "";
3247
+ const userId = userIdFromArg || userIdFromRecord || userIdFromKey;
3248
+ const automationId = asOptionalTrimmedString(args.record?.id) || automationIdFromKey;
3249
+ const ownerAgentKey = asTrimmedString(args.record?.ownerAgentKey);
3250
+ if (!userId || !automationId || !ownerAgentKey) return [];
3251
+ return [
3252
+ {
3253
+ type: "del",
3254
+ key: createAgentAutomationOwnerIndexKey(userId, ownerAgentKey, automationId)
3255
+ }
3256
+ ];
3257
+ }
3258
+ var createBudgetKey = (userId) => createKey("budget", userId, "monthly");
3259
+ var createNotificationKey = {
3260
+ single: (userId, notificationId) => createKey("notification" /* NOTIFICATION */, userId, notificationId),
3261
+ rangeOfUser: (userId) => ({
3262
+ start: createKey("notification" /* NOTIFICATION */, userId, ""),
3263
+ end: createKey("notification" /* NOTIFICATION */, userId, "\uFFFF")
3264
+ })
3265
+ };
3266
+ var emailKey = {
3267
+ create: (ownerId) => {
3268
+ const emailId = ulid();
3269
+ return { dbKey: createKey("email" /* EMAIL */, ownerId, emailId), emailId };
3270
+ },
3271
+ single: (ownerId, emailId) => createKey("email" /* EMAIL */, ownerId, emailId),
3272
+ rangeOfOwner: (ownerId) => ({
3273
+ start: createKey("email" /* EMAIL */, ownerId, ""),
3274
+ end: createKey("email" /* EMAIL */, ownerId, "\uFFFF")
3275
+ })
3276
+ };
3004
3277
  var createPageKey = {
3005
3278
  create: (userId) => {
3006
3279
  const id = ulid();
@@ -3021,6 +3294,114 @@ var createAgentKey = {
3021
3294
  end: createKey("agent" /* AGENT */, userId, "\uFFFF")
3022
3295
  })
3023
3296
  };
3297
+ var pubAgentKeys = {
3298
+ single: (agentId) => createAgentKey.public(agentId),
3299
+ list: () => ({
3300
+ start: createKey("agent" /* AGENT */, "pub", ""),
3301
+ end: createKey("agent" /* AGENT */, "pub", "\uFFFF")
3302
+ }),
3303
+ allPublicRanges: () => [
3304
+ {
3305
+ start: createKey("agent" /* AGENT */, "pub", ""),
3306
+ end: createKey("agent" /* AGENT */, "pub", "\uFFFF")
3307
+ }
3308
+ ]
3309
+ };
3310
+ var createAgentGrantKey = {
3311
+ single: (ownerUserId, agentId, granteeUserId) => createKey("grant", "agent", ownerUserId, agentId, granteeUserId),
3312
+ rangeOfAgent: (ownerUserId, agentId) => ({
3313
+ start: createKey("grant", "agent", ownerUserId, agentId, ""),
3314
+ end: createKey("grant", "agent", ownerUserId, agentId, "\uFFFF")
3315
+ })
3316
+ };
3317
+ var FAV_PREFIX = "fav";
3318
+ var createFavoriteKey = {
3319
+ /* ---------- Agent 收藏(按 agentKey 存,当前使用) ---------- */
3320
+ /**
3321
+ * 某个用户收藏了某个 Agent 实例(用完整的 agentKey/dbKey)
3322
+ * key: fav-agent-key-{userId}-{agentKey}
3323
+ */
3324
+ agentByKey: (userId, agentKey) => createKey(FAV_PREFIX, "agent", "key", userId, agentKey),
3325
+ /**
3326
+ * 查询某用户收藏的所有 Agent(基于 agentKey 版本)
3327
+ * 范围: [fav-agent-key-{userId}-, fav-agent-key-{userId}-\uffff]
3328
+ */
3329
+ agentKeyRangeOfUser: (userId) => ({
3330
+ start: createKey(FAV_PREFIX, "agent", "key", userId, ""),
3331
+ end: createKey(FAV_PREFIX, "agent", "key", userId, "\uFFFF")
3332
+ }),
3333
+ userRangeOfAgentKey: (agentKey) => ({
3334
+ start: createKey(FAV_PREFIX, "agent", "key", "by-agent", agentKey, ""),
3335
+ end: createKey(FAV_PREFIX, "agent", "key", "by-agent", agentKey, "\uFFFF")
3336
+ }),
3337
+ agentByKeyReverse: (agentKey, userId) => createKey(FAV_PREFIX, "agent", "key", "by-agent", agentKey, userId),
3338
+ /* ---------- Agent 收藏(按 agentId 存,预留,将来可用) ---------- */
3339
+ /**
3340
+ * 某个用户收藏了某个逻辑 AgentId(当前未使用,预留)
3341
+ * key: fav-agent-id-{userId}-{agentId}
3342
+ */
3343
+ agentById: (userId, agentId) => createKey(FAV_PREFIX, "agent", "id", userId, agentId),
3344
+ /** 查询某用户收藏的所有 AgentId(预留) */
3345
+ agentIdRangeOfUser: (userId) => ({
3346
+ start: createKey(FAV_PREFIX, "agent", "id", userId, ""),
3347
+ end: createKey(FAV_PREFIX, "agent", "id", userId, "\uFFFF")
3348
+ }),
3349
+ userRangeOfAgentId: (agentId) => ({
3350
+ start: createKey(FAV_PREFIX, "agent", "id", "by-agent", agentId, ""),
3351
+ end: createKey(FAV_PREFIX, "agent", "id", "by-agent", agentId, "\uFFFF")
3352
+ }),
3353
+ agentByIdReverse: (agentId, userId) => createKey(FAV_PREFIX, "agent", "id", "by-agent", agentId, userId),
3354
+ /* ---------- Page 收藏(同样区分 key / id,当前可以只用 byKey) ---------- */
3355
+ // Page byKey: fav-page-key-{userId}-{pageKey}
3356
+ pageByKey: (userId, pageKey) => createKey(FAV_PREFIX, "page", "key", userId, pageKey),
3357
+ pageKeyRangeOfUser: (userId) => ({
3358
+ start: createKey(FAV_PREFIX, "page", "key", userId, ""),
3359
+ end: createKey(FAV_PREFIX, "page", "key", userId, "\uFFFF")
3360
+ }),
3361
+ userRangeOfPageKey: (pageKey) => ({
3362
+ start: createKey(FAV_PREFIX, "page", "key", "by-page", pageKey, ""),
3363
+ end: createKey(FAV_PREFIX, "page", "key", "by-page", pageKey, "\uFFFF")
3364
+ }),
3365
+ pageByKeyReverse: (pageKey, userId) => createKey(FAV_PREFIX, "page", "key", "by-page", pageKey, userId),
3366
+ // Page byId(预留)
3367
+ pageById: (userId, pageId) => createKey(FAV_PREFIX, "page", "id", userId, pageId),
3368
+ pageIdRangeOfUser: (userId) => ({
3369
+ start: createKey(FAV_PREFIX, "page", "id", userId, ""),
3370
+ end: createKey(FAV_PREFIX, "page", "id", userId, "\uFFFF")
3371
+ }),
3372
+ userRangeOfPageId: (pageId) => ({
3373
+ start: createKey(FAV_PREFIX, "page", "id", "by-page", pageId, ""),
3374
+ end: createKey(FAV_PREFIX, "page", "id", "by-page", pageId, "\uFFFF")
3375
+ }),
3376
+ pageByIdReverse: (pageId, userId) => createKey(FAV_PREFIX, "page", "id", "by-page", pageId, userId),
3377
+ /** 从 dbKey 中解析出目标标识符 (agentKey/agentId/pageKey/pageId) */
3378
+ getIdentifierFromKey: (key) => {
3379
+ const parts = key.split(SEPARATOR);
3380
+ return parts.slice(4).join(SEPARATOR);
3381
+ }
3382
+ };
3383
+ var createFavoriteStatsKey = {
3384
+ // 被多少人收藏的 Agent(按 agentKey 统计,当前实际使用)
3385
+ agentByKey: (agentKey) => createKey(FAV_PREFIX, "agent-count", "key", agentKey),
3386
+ // 预留:按逻辑 AgentId 统计
3387
+ agentById: (agentId) => createKey(FAV_PREFIX, "agent-count", "id", agentId),
3388
+ // Page:按 pageKey 统计(预留)
3389
+ pageByKey: (pageKey) => createKey(FAV_PREFIX, "page-count", "key", pageKey),
3390
+ pageById: (pageId) => createKey(FAV_PREFIX, "page-count", "id", pageId)
3391
+ };
3392
+ var jobKey = {
3393
+ create: (tenantId, jobId) => {
3394
+ const id = jobId || ulid();
3395
+ const dbKey = createKey("job", tenantId, id);
3396
+ return { dbKey, id };
3397
+ },
3398
+ single: (tenantId, jobId) => createKey("job", tenantId, jobId),
3399
+ rangeOfTenant: (tenantId) => {
3400
+ const start = createKey("job", tenantId, "");
3401
+ return { start, end: start + "\uFFFF" };
3402
+ }
3403
+ };
3404
+ var blobKey = (sha256) => createKey("blob", sha256);
3024
3405
  var fileKey = {
3025
3406
  single: (tenantId, fileId) => createKey("file", tenantId, fileId),
3026
3407
  rangeOfTenant: (tenantId) => {
@@ -3031,173 +3412,17 @@ var fileKey = {
3031
3412
  };
3032
3413
  }
3033
3414
  };
3415
+ var fileIdIndexKey = (fileId) => createKey("file", "id", fileId);
3034
3416
  var getFileIdFromKey = (key) => {
3035
- const parts = key.split(SEPARATOR2);
3417
+ const parts = key.split(SEPARATOR);
3036
3418
  return parts[2];
3037
3419
  };
3038
-
3039
- // packages/share/helpers.ts
3040
- var toSafeString = (value) => asTrimmedString(value);
3041
- var toNonEmptyString = (value) => {
3042
- const text = toSafeString(value);
3043
- return text || void 0;
3044
- };
3045
- var toSafeAgentKey = (value) => {
3046
- const text = toSafeString(value);
3047
- return text && isAgentKey2(text) ? text : "";
3048
- };
3049
- var SHARE_TIME_FORMATTER = new Intl.DateTimeFormat("zh-CN", {
3050
- timeZone: "Asia/Shanghai",
3051
- year: "numeric",
3052
- month: "2-digit",
3053
- day: "2-digit",
3054
- hour: "2-digit",
3055
- minute: "2-digit",
3056
- second: "2-digit",
3057
- hour12: false
3058
- });
3059
- var findAgentKeyInMessages2 = (messages) => {
3060
- for (const raw of messages) {
3061
- if (!raw || typeof raw !== "object") continue;
3062
- const key = toSafeAgentKey(raw.cybotKey);
3063
- if (key) return key;
3064
- }
3065
- return "";
3066
- };
3067
- var findAgentKeyInArray2 = (items) => {
3068
- for (const raw of items) {
3069
- const direct = toSafeAgentKey(raw);
3070
- if (direct) return direct;
3071
- if (!raw || typeof raw !== "object") continue;
3072
- const item = raw;
3073
- const key = toSafeAgentKey(item.dbKey) || toSafeAgentKey(item.id);
3074
- if (key) return key;
3075
- }
3076
- return "";
3077
- };
3078
- var findAgentNameInMessages = (messages) => {
3079
- for (const raw of messages) {
3080
- if (!raw || typeof raw !== "object") continue;
3081
- const msg = raw;
3082
- const name = toSafeString(msg.agentName) || toSafeString(msg.cybotName) || toSafeString(msg.sourceAgentName);
3083
- if (name) return name;
3084
- }
3085
- return "";
3086
- };
3087
- var findAgentNameInArray = (items) => {
3088
- for (const raw of items) {
3089
- if (!raw || typeof raw !== "object") continue;
3090
- const item = raw;
3091
- const name = toSafeString(item.name) || toSafeString(item.agentName) || toSafeString(item.cybotName) || toSafeString(item.sourceAgentName);
3092
- if (name) return name;
3093
- }
3094
- return "";
3095
- };
3096
- var extractAgentInfo = (type, data) => {
3097
- const meta = data.meta;
3098
- const keyCandidates = [
3099
- meta?.sourceAgentKey,
3100
- meta?.agentKey,
3101
- data.sourceAgentKey,
3102
- data.agentKey,
3103
- data.cybotKey,
3104
- type === "cybot" ? data.dbKey ?? data.id : void 0
3105
- ];
3106
- let agentKey = "";
3107
- for (const candidate of keyCandidates) {
3108
- agentKey = toSafeAgentKey(candidate);
3109
- if (agentKey) break;
3110
- }
3111
- if (!agentKey && Array.isArray(data.cybots)) {
3112
- agentKey = findAgentKeyInArray2(data.cybots);
3113
- }
3114
- if (!agentKey && Array.isArray(data.messages)) {
3115
- agentKey = findAgentKeyInMessages2(data.messages);
3116
- }
3117
- if (!agentKey && Array.isArray(data.history)) {
3118
- agentKey = findAgentKeyInMessages2(data.history);
3119
- }
3120
- const nameCandidates = [
3121
- meta?.sourceAgentName,
3122
- meta?.agentName,
3123
- meta?.cybotName,
3124
- data.sourceAgentName,
3125
- data.agentName,
3126
- data.cybotName,
3127
- type === "cybot" ? data.name : void 0
3128
- ];
3129
- let agentName = "";
3130
- for (const candidate of nameCandidates) {
3131
- agentName = toSafeString(candidate);
3132
- if (agentName) break;
3133
- }
3134
- if (!agentName && Array.isArray(data.cybots)) {
3135
- agentName = findAgentNameInArray(data.cybots);
3136
- }
3137
- if (!agentName && Array.isArray(data.messages)) {
3138
- agentName = findAgentNameInMessages(data.messages);
3139
- }
3140
- if (!agentName && Array.isArray(data.history)) {
3141
- agentName = findAgentNameInMessages(data.history);
3142
- }
3143
- return {
3144
- ...agentKey ? { sourceAgentKey: agentKey } : {},
3145
- ...agentName ? { sourceAgentName: agentName } : {}
3146
- };
3147
- };
3148
- var extractImageFromContent = (content) => {
3149
- if (Array.isArray(content)) {
3150
- const part = content.find(
3151
- (p) => p?.type === "image_url" && typeof p?.image_url?.url === "string"
3152
- );
3153
- if (part?.image_url?.url) return part.image_url.url;
3154
- }
3155
- if (typeof content === "string") {
3156
- const match = content.match(/!\[.*?\]\((.*?)\)/);
3157
- if (match?.[1]) return match[1];
3158
- }
3159
- return void 0;
3160
- };
3161
- var extractCoverImage = (type, data) => {
3162
- if (type === "image" /* IMAGE */) {
3163
- return toNonEmptyString(data.url);
3164
- }
3165
- if (type === "app" /* APP */) {
3166
- return toNonEmptyString(data.coverImage);
3167
- }
3168
- if (type !== "dialog" /* DIALOG */) return void 0;
3169
- const messages = Array.isArray(data.messages) ? data.messages : Array.isArray(data.history) ? data.history : [];
3170
- for (const msg of messages) {
3171
- const fromContent = extractImageFromContent(msg.content);
3172
- if (fromContent) return fromContent;
3173
- const image = toNonEmptyString(msg.image);
3174
- if (image) return image;
3175
- if (Array.isArray(msg.images)) {
3176
- const first = asNonEmptyStringArray(msg.images)[0];
3177
- if (first) return first;
3178
- }
3179
- }
3180
- return void 0;
3181
- };
3182
- var resolveShareAuthorIdentity = (args) => {
3183
- const authorName = toNonEmptyString(args.profile?.nickname) ?? toNonEmptyString(args.user?.name) ?? toNonEmptyString(args.user?.nickname) ?? toNonEmptyString(args.user?.username) ?? toNonEmptyString(args.fallbackName);
3184
- const authorAvatar = toNonEmptyString(args.profile?.avatar) ?? toNonEmptyString(args.user?.avatar) ?? toNonEmptyString(args.fallbackAvatar);
3185
- return {
3186
- ...authorName ? { authorName } : {},
3187
- ...authorAvatar ? { authorAvatar } : {}
3188
- };
3189
- };
3190
- var SENSITIVE_FIELDS = ["apiKey", "secret", "password"];
3191
- var sanitizeShareData = (data) => {
3192
- const snapshot = { ...data };
3193
- for (const field of SENSITIVE_FIELDS) {
3194
- delete snapshot[field];
3195
- }
3196
- return snapshot;
3420
+ var fileStatKey = {
3421
+ tenantPerDay: (tenantId, dateKey) => createKey("file", "stat", "tenant", tenantId, dateKey),
3422
+ modelPerDay: (modelName, dateKey) => createKey("file", "stat", "model", modelName, dateKey)
3197
3423
  };
3198
3424
 
3199
3425
  export {
3200
- ulid,
3201
3426
  toTrimmedString,
3202
3427
  toNonEmptyString,
3203
3428
  extractAgentInfo,
@@ -3205,41 +3430,72 @@ export {
3205
3430
  resolveShareAuthorIdentity,
3206
3431
  sanitizeShareData,
3207
3432
  shareKey,
3208
- isDialogKey,
3209
- isDialogRecordKey,
3210
- createDialogKey,
3211
- dialogMessageKey,
3212
- createDialogMessageKeyAndId,
3213
- dialogMessagePrefix,
3214
- dialogMessageRange,
3215
- SEPARATOR2 as SEPARATOR,
3433
+ SEPARATOR,
3216
3434
  createKey,
3217
3435
  splitKey,
3218
3436
  TYPE_STORAGE_PREFIXES,
3437
+ inferTypeFromDbKey,
3219
3438
  isTableMetaKey,
3220
3439
  isPageKey,
3221
3440
  isTaskKey,
3441
+ isAgentAutomationKey,
3222
3442
  isFileKey,
3223
- isAgentKey2 as isAgentKey,
3443
+ isAgentKey,
3224
3444
  isAppKey,
3445
+ isEmailKey,
3225
3446
  rowKey,
3447
+ idxKey,
3226
3448
  metaKey,
3449
+ viewKey,
3227
3450
  DB_PREFIX,
3451
+ createOAuthCredentialKey,
3452
+ oauthCredentialUserRange,
3453
+ USER_SETTINGS_KEY_SUFFIX,
3228
3454
  createUserKey,
3229
3455
  createUserPreferenceKey,
3230
3456
  createMemoryKey,
3231
3457
  createMemoryOwnerIndexKey,
3232
3458
  createMemorySubjectKindIndexKey,
3459
+ isMemoryKey,
3233
3460
  memoryOwnerRange,
3234
3461
  memorySubjectKindRange,
3462
+ createTransactionKey,
3235
3463
  createTokenKey,
3236
3464
  createTokenStatsKey,
3465
+ createTokenStatsAppliedKey,
3466
+ isTokenStatsKey,
3467
+ DIALOG_AGENT_LIST_INDEX_PREFIX,
3468
+ parseDialogUpdatedAtMs,
3469
+ toDialogListInvertedTimestamp,
3470
+ createDialogAgentListIndexKey,
3471
+ createDialogAgentListIndexRange,
3472
+ expandDialogAgentListIndexAliases,
3473
+ collectDialogAgentListIndexAgentKeys,
3474
+ isDialogAgentListIndexable,
3237
3475
  buildDialogAgentListIndexDeleteOps,
3476
+ buildDialogAgentListIndexOps,
3477
+ createTaskKey,
3238
3478
  createAgentAutomationKey,
3479
+ agentAutomationKey,
3480
+ AGENT_AUTOMATION_OWNER_INDEX_PREFIX,
3239
3481
  createAgentAutomationOwnerIndexKey,
3240
3482
  buildAgentAutomationOwnerIndexValue,
3483
+ isAgentAutomationOwnerIndexKey,
3484
+ parseAgentAutomationIdFromKey,
3485
+ buildAgentAutomationOwnerIndexDeleteOps,
3486
+ createBudgetKey,
3487
+ createNotificationKey,
3488
+ emailKey,
3241
3489
  createPageKey,
3242
3490
  createAgentKey,
3491
+ pubAgentKeys,
3492
+ createAgentGrantKey,
3493
+ createFavoriteKey,
3494
+ createFavoriteStatsKey,
3495
+ jobKey,
3496
+ blobKey,
3243
3497
  fileKey,
3244
- getFileIdFromKey
3498
+ fileIdIndexKey,
3499
+ getFileIdFromKey,
3500
+ fileStatKey
3245
3501
  };