nolo-cli 0.188.0-alpha.1 → 0.188.0

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 (158) hide show
  1. package/{_executeModel-DIRZ5OVD.js → _executeModel-WQ7BV3G7.js} +53 -52
  2. package/{accountResolver-NQJ57BVU.js → accountResolver-42BYPMVY.js} +5 -5
  3. package/{action-GPPJC5TI.js → action-BHWB4MOK.js} +6 -5
  4. package/{addContentAction-XJQEJ4XW.js → addContentAction-BY375D35.js} +11 -10
  5. package/{addDialogAgentAction-5WZX5CAY.js → addDialogAgentAction-HOZYOCWC.js} +13 -12
  6. package/{agentDeleteCommand-YBR3WPMA.js → agentDeleteCommand-4DK6X4S4.js} +91 -90
  7. package/{agentEmailCommands-HCAJUPVT.js → agentEmailCommands-CYPIYPOK.js} +81 -80
  8. package/agentFavoriteCommands-GAFEXKKP.js +187 -0
  9. package/{agentListCommands-6N32GUGS.js → agentListCommands-MAG736RU.js} +53 -52
  10. package/{agentMachineCommands-ICARPI2D.js → agentMachineCommands-7VTOWHHD.js} +36 -35
  11. package/{agentProviderCommands-FXEMNSZ2.js → agentProviderCommands-XSZUCNIR.js} +5 -5
  12. package/{agentPullCommand-7LHBOEYH.js → agentPullCommand-LGASFNH7.js} +5 -5
  13. package/{agentRecordCommands-SCC37ID4.js → agentRecordCommands-VK3NEK5G.js} +74 -73
  14. package/{agentRunCommand-LIEO5YKT.js → agentRunCommand-7MFVUHWX.js} +79 -78
  15. package/{agentRunControl-SBHIICUQ.js → agentRunControl-6HHESKDB.js} +6 -6
  16. package/{agentRuntimeLocal-KMJAV6JL.js → agentRuntimeLocal-NAAYNHCW.js} +25 -24
  17. package/{agentSlice-XZODTFTF.js → agentSlice-TZRLTBEJ.js} +12 -11
  18. package/{appDeleteCommands-KDKRH2S2.js → appDeleteCommands-VDHCDVBF.js} +34 -33
  19. package/{appDeployCommands-YNZIYHDK.js → appDeployCommands-V6UTKVXR.js} +34 -33
  20. package/{appDeployStatusCommands-CPGP7ELY.js → appDeployStatusCommands-4UIFSEPC.js} +34 -33
  21. package/{appGetCommands-VXKSPF54.js → appGetCommands-XKDXLC3C.js} +34 -33
  22. package/{appListCommands-3QHVAMFI.js → appListCommands-BELRVX2Y.js} +34 -33
  23. package/{authCommand-NR6NELQ7.js → authCommand-RV5MQDWN.js} +27 -26
  24. package/{authCommands-PIUTADO5.js → authCommands-MZUXPRYJ.js} +9 -8
  25. package/{builtinSkillRegistry-RR35BY57.js → builtinSkillRegistry-7MBUY5EY.js} +4 -3
  26. package/{chromeCommands-EXJZ5HH5.js → chromeCommands-IVYZCGFL.js} +2 -2
  27. package/{chromeOpsCommands-ITBZEFBX.js → chromeOpsCommands-C46BXHEE.js} +8 -8
  28. package/{chunk-GCOCWLIE.js → chunk-2NAE7IVE.js} +2 -2
  29. package/{chunk-YBTP3PUM.js → chunk-4CEAZRZ4.js} +4 -4
  30. package/{chunk-SJGHZTLV.js → chunk-4MYCKDSI.js} +2 -2
  31. package/{chunk-KHMJI7GE.js → chunk-53RSTB7T.js} +5 -5
  32. package/{chunk-IBZ2HGY7.js → chunk-5DIFZFYF.js} +9 -9
  33. package/{chunk-K3TVMCV3.js → chunk-5DPVRMSY.js} +1 -1
  34. package/{chunk-ZZE2IJ5U.js → chunk-5HAPEKNH.js} +1 -1
  35. package/{chunk-EXAJ6DCR.js → chunk-5ZMIIR23.js} +3 -0
  36. package/{chunk-77IXQ7PZ.js → chunk-63JHZKGZ.js} +56 -54
  37. package/{chunk-62TBKWTV.js → chunk-7DQSP7JU.js} +1 -1
  38. package/{chunk-ESMZW5PE.js → chunk-A5BLRE3G.js} +1 -1
  39. package/{chunk-OKKTPAKC.js → chunk-ABMBNULR.js} +12 -12
  40. package/{chunk-PO4IRXQ7.js → chunk-ADTJJVDJ.js} +239 -72
  41. package/{chunk-CDLP56BS.js → chunk-B2N5GZBU.js} +17 -15
  42. package/{chunk-JWEXJ573.js → chunk-B6EZB6DW.js} +2 -2
  43. package/{chunk-MAYW6V3E.js → chunk-BA2FHPS4.js} +1 -1
  44. package/{chunk-CI5DVWU7.js → chunk-BTBT2566.js} +3 -3
  45. package/{chunk-ZKYRYOPF.js → chunk-CGKSIL4D.js} +12 -10
  46. package/{chunk-YPG7TUQD.js → chunk-CNMQATUF.js} +1 -1
  47. package/{chunk-NMFV26UG.js → chunk-CVMMWN6P.js} +6 -0
  48. package/{chunk-IF7V3CBU.js → chunk-DFF6B7P7.js} +4 -4
  49. package/{chunk-D2J22QSE.js → chunk-DYQXB46J.js} +10 -10
  50. package/{chunk-5EMSBTQ6.js → chunk-ECX3NKRD.js} +526 -224
  51. package/{chunk-4NCLVO4U.js → chunk-EVF6F3QU.js} +3 -3
  52. package/{chunk-V7QTD5MP.js → chunk-EXSR7DXT.js} +3 -3
  53. package/{chunk-W6E5IXIP.js → chunk-GTP6VNWH.js} +1 -1
  54. package/{chunk-IHQ7RMRS.js → chunk-GYVLAHA4.js} +6 -6
  55. package/{chunk-AA5GKA2X.js → chunk-HTLIKE5U.js} +5 -5
  56. package/{chunk-LHRW5KFN.js → chunk-I3HWJODB.js} +1 -1
  57. package/{chunk-KMSMIOOL.js → chunk-IIX6VWLW.js} +2 -2
  58. package/{chunk-GFHDRA4C.js → chunk-IOIPWEL4.js} +22 -22
  59. package/{chunk-UKDHLQHS.js → chunk-JG6IWEAW.js} +21 -19
  60. package/{chunk-BAWAKW7X.js → chunk-JGJVDP2W.js} +19 -19
  61. package/{chunk-NSASNKVD.js → chunk-K6TZSON4.js} +8 -6
  62. package/{chunk-U7BOZFAD.js → chunk-KDBKEYUW.js} +108 -81
  63. package/{chunk-NHEWV5FD.js → chunk-LBXUNNDS.js} +1 -1
  64. package/{chunk-OFFL4DCR.js → chunk-LEC5ALIN.js} +1 -1
  65. package/{chunk-GAGGEA7D.js → chunk-LEJSZV6V.js} +9 -9
  66. package/{chunk-APB44JID.js → chunk-MJWUBTK7.js} +1 -1
  67. package/{chunk-CR5WXQX7.js → chunk-N7E3LQ4A.js} +4 -4
  68. package/{chunk-SQOLMMXQ.js → chunk-NMDAOZRN.js} +57 -55
  69. package/{chunk-QNLRCES2.js → chunk-NVOYW6H4.js} +3 -3
  70. package/{chunk-HEYJFOL6.js → chunk-OHRDHS4N.js} +1 -1
  71. package/{chunk-D6222KXV.js → chunk-OUSUFO5W.js} +2 -2
  72. package/{chunk-FDLDMJTM.js → chunk-P64WRQYV.js} +1 -1
  73. package/{chunk-FSIJK37C.js → chunk-PD2YRFAI.js} +1 -1
  74. package/{chunk-P2BGRAW7.js → chunk-PVD7CRYV.js} +2 -2
  75. package/{chunk-JOUFPRE4.js → chunk-QU3TLYBR.js} +5 -5
  76. package/{chunk-YYKHIX4X.js → chunk-RJ3EYB5G.js} +1 -1
  77. package/{chunk-7XISFN2T.js → chunk-SM56M7N7.js} +1 -1
  78. package/{chunk-KVUMIWLL.js → chunk-TFSMPRAY.js} +28 -28
  79. package/{chunk-QSJLGX7K.js → chunk-TZLPJRNO.js} +15 -15
  80. package/{chunk-6JCZZDET.js → chunk-UC5RISH3.js} +135 -109
  81. package/{chunk-XLQ646HU.js → chunk-UGCQKKXW.js} +13 -13
  82. package/{chunk-YO3O7H2X.js → chunk-UNOILAZP.js} +14 -0
  83. package/{chunk-DEO4FC7J.js → chunk-UVWBGWBO.js} +9 -3
  84. package/{chunk-GUGCJ3DT.js → chunk-V62MBA65.js} +14 -14
  85. package/{chunk-IIGDVODZ.js → chunk-WAZ6BTSC.js} +1 -1
  86. package/{chunk-XAFCJN32.js → chunk-WFUIXNKC.js} +1 -1
  87. package/{chunk-H5EQ2VTC.js → chunk-WVGVGT44.js} +7 -7
  88. package/chunk-XJWWBO34.js +69 -0
  89. package/{chunk-MILA23IG.js → chunk-YARN6MCX.js} +20 -18
  90. package/{chunk-TDBNIGUJ.js → chunk-YHNZZIAH.js} +10 -10
  91. package/{chunk-3L5MSPWX.js → chunk-YIRADHSY.js} +1 -1
  92. package/{chunk-XI7DGLUK.js → chunk-ZSO5B6SW.js} +3 -3
  93. package/cliAuthorityBrokerClient-PM3U6Q6J.js +21 -0
  94. package/cliAuthorityStoreDriver-TKLXNNTG.js +20 -0
  95. package/{commandRegistry-I6CNP54W.js → commandRegistry-RM2Z2DVF.js} +95 -91
  96. package/{contentThunks-U5ZQJBCJ.js → contentThunks-RP4BYNUC.js} +27 -26
  97. package/{cooldownCommands-IUU3ZH3L.js → cooldownCommands-4XKJFEBW.js} +1 -1
  98. package/{createAgentAutomationAction-O5MAEWFH.js → createAgentAutomationAction-AYFAMQ5D.js} +30 -29
  99. package/{createDialogAction-6FEVBVYE.js → createDialogAction-NV5TEAIN.js} +29 -28
  100. package/{createPageAction-QJJX3V2F.js → createPageAction-FJGDX55N.js} +32 -31
  101. package/cursorProvider-YGGNMVWX.js +1 -1
  102. package/{dbSlice-6PVPY44C.js → dbSlice-QAUXABCC.js} +10 -9
  103. package/{deleteFile-YM6NDPAR.js → deleteFile-R5OBP7OM.js} +5 -5
  104. package/{dialogCommands-EDFRNBDA.js → dialogCommands-4BGV6DPD.js} +41 -40
  105. package/{dialogSlice-4J2R6S63.js → dialogSlice-ZUYNLTF6.js} +25 -24
  106. package/dialogUsageCommand-QTG6ILEJ.js +299 -0
  107. package/{docCreateCommands-J6RRFAAL.js → docCreateCommands-3CW75UF2.js} +33 -32
  108. package/{docDeleteCommands-4KIMCR5H.js → docDeleteCommands-NL4ZYMN5.js} +34 -33
  109. package/{docReadCommands-2UZQOOA7.js → docReadCommands-HXCNVDPQ.js} +33 -32
  110. package/{docStore-CMJSEKU5.js → docStore-EPAZ4HLD.js} +12 -11
  111. package/{docUpdateCommands-OLZENBFB.js → docUpdateCommands-RMVBAMDE.js} +33 -32
  112. package/{fetchMessages-IIJWQ3HR.js → fetchMessages-HWBVATSE.js} +4 -3
  113. package/{getPricing-2UPNNW3Y.js → getPricing-E2PLNWCR.js} +3 -3
  114. package/{handleSendMessageAction-ON2OCZ2O.js → handleSendMessageAction-5UH3DA6V.js} +46 -45
  115. package/index.js +9 -9
  116. package/keys-P4ZDOVJW.js +180 -0
  117. package/{localDialogRead-FSOMOPDZ.js → localDialogRead-CT5HGDMC.js} +1 -1
  118. package/{localRuntimeAdapter-KYWEHSY3.js → localRuntimeAdapter-LVPGHOJK.js} +71 -70
  119. package/{localRuntimeAuthority-BPN5OAQG.js → localRuntimeAuthority-NEGF3LRQ.js} +3 -3
  120. package/{localRuntimeDb-QIVAXMUL.js → localRuntimeDb-SDYFAEKA.js} +1 -1
  121. package/{machineCommands-PZYWWGXH.js → machineCommands-O6RDJGLV.js} +79 -78
  122. package/{machineWsRunDispatch-H7OSNRUO.js → machineWsRunDispatch-GVDQO742.js} +72 -71
  123. package/{memberThunks-AZINUM4S.js → memberThunks-QWAAGQBS.js} +167 -63
  124. package/package.json +1 -1
  125. package/{providerPresetApply-MBMGCNKZ.js → providerPresetApply-JGNMO2KX.js} +5 -5
  126. package/{providerRegistry-P4KYS6SE.js → providerRegistry-33J3ZYFJ.js} +5 -5
  127. package/{read-7JPIWRBQ.js → read-D6NEWSGG.js} +5 -5
  128. package/{readDocTool-AAQTB2Y3.js → readDocTool-NTAXO7SX.js} +1 -1
  129. package/{readlineWorkspace-DTAJBA43.js → readlineWorkspace-I5XZFI2E.js} +169 -122
  130. package/{removeDialogAgentAction-RMVRILLK.js → removeDialogAgentAction-YEPO5AYI.js} +15 -14
  131. package/{runAgentClientLoop-KW7EFI6H.js → runAgentClientLoop-LV2HYQPH.js} +49 -48
  132. package/{runtimeDoctorCommands-DXJH5HIB.js → runtimeDoctorCommands-NYBOTA6D.js} +20 -20
  133. package/{secretCommands-UZV7CPJY.js → secretCommands-N6CMCJDZ.js} +1 -1
  134. package/{setDialogExtraReferencesAction-L3V7JTMG.js → setDialogExtraReferencesAction-EH5GWDAJ.js} +12 -11
  135. package/{setPrimaryDialogAgentAction-X52JQGTJ.js → setPrimaryDialogAgentAction-PNWRK6IY.js} +15 -14
  136. package/{settingThunks-N6XFWPOU.js → settingThunks-7VCWB6P7.js} +12 -10
  137. package/{spaceCommands-AUZVTCVH.js → spaceCommands-ZUI4CTSO.js} +32 -31
  138. package/{streamAgentChatTurn-TGC24NGV.js → streamAgentChatTurn-ZCHIQR35.js} +67 -66
  139. package/{switchDialogAgentAction-ZJ5CGU7J.js → switchDialogAgentAction-23BFWJMV.js} +13 -12
  140. package/{tools-N77X52PL.js → tools-2DZDJWHZ.js} +43 -42
  141. package/{tuiSummaryLlmCaller-5D3XCH2C.js → tuiSummaryLlmCaller-FSOADMXK.js} +12 -12
  142. package/{updateCommands-MZCY6FXK.js → updateCommands-KE6LP3QX.js} +5 -5
  143. package/{updateDialogTitleAction-EH3LIVRX.js → updateDialogTitleAction-QZWVKVVW.js} +32 -31
  144. package/{windowsSelfUpdate-XV2MMQAC.js → windowsSelfUpdate-26TSFXEZ.js} +2 -2
  145. package/dialogUsageCommand-ZPESQB6W.js +0 -136
  146. package/{agentGrantCommands-LPVAJ6KR.js → agentGrantCommands-V5FOQKFD.js} +3 -3
  147. package/{chunk-I2QHI2XM.js → chunk-4YMD7B4Y.js} +3 -3
  148. package/{chunk-ZJ7UHBJS.js → chunk-5XBUWM6I.js} +3 -3
  149. package/{chunk-YXTMZQGX.js → chunk-7JWW65DU.js} +3 -3
  150. package/{chunk-43OFVLWJ.js → chunk-7UODCAWW.js} +8 -8
  151. package/{chunk-CSINZLH7.js → chunk-JIFYXQRD.js} +3 -3
  152. package/{chunk-LIQJTQRN.js → chunk-TRZP7JZ7.js} +3 -3
  153. package/{chunk-FKOCI2WR.js → chunk-UBLITLAZ.js} +3 -3
  154. package/{chunk-TDNAAXUQ.js → chunk-ZBCBFOWC.js} +3 -3
  155. package/{memoryCommands-YLT3ADGQ.js → memoryCommands-ASCE5STX.js} +3 -3
  156. package/{offlineMarxistsAgentCommand-3GLX4QQY.js → offlineMarxistsAgentCommand-2QTHJCHV.js} +3 -3
  157. package/{tableCommands-IVC5S7Y3.js → tableCommands-QYB64L5I.js} +7 -7
  158. 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")
@@ -2787,6 +2990,47 @@ var createTokenKey = {
2787
2990
  end: createKey("token", userId, "\uFFFF")
2788
2991
  })
2789
2992
  };
2993
+ var TOKEN_DIALOG_INDEX_PREFIX = "idx-token-dialog";
2994
+ var encodeTokenIndexSegment = (segment) => {
2995
+ let out = "";
2996
+ for (const ch of segment) {
2997
+ if (/[A-Za-z0-9]/.test(ch)) {
2998
+ out += ch;
2999
+ continue;
3000
+ }
3001
+ for (const byte of new TextEncoder().encode(ch)) {
3002
+ out += `%${byte.toString(16).toUpperCase().padStart(2, "0")}`;
3003
+ }
3004
+ }
3005
+ return out;
3006
+ };
3007
+ var createTokenDialogIndexKey = Object.assign(
3008
+ (userId, dialogId, callId) => createKey(
3009
+ TOKEN_DIALOG_INDEX_PREFIX,
3010
+ encodeTokenIndexSegment(userId),
3011
+ encodeTokenIndexSegment(dialogId),
3012
+ encodeTokenIndexSegment(callId)
3013
+ ),
3014
+ {
3015
+ /** 某个用户在某个对话下的全部索引项范围(范围扫描用) */
3016
+ rangeOfDialog: (userId, dialogId) => ({
3017
+ start: createKey(
3018
+ TOKEN_DIALOG_INDEX_PREFIX,
3019
+ encodeTokenIndexSegment(userId),
3020
+ encodeTokenIndexSegment(dialogId),
3021
+ ""
3022
+ ),
3023
+ end: createKey(
3024
+ TOKEN_DIALOG_INDEX_PREFIX,
3025
+ encodeTokenIndexSegment(userId),
3026
+ encodeTokenIndexSegment(dialogId),
3027
+ "\uFFFF"
3028
+ )
3029
+ })
3030
+ }
3031
+ );
3032
+ var TOKEN_DIALOG_INDEX_FORMAT = "v2";
3033
+ var createTokenDialogBackfillKey = (userId) => createKey("idx-tokendlg-backfill", encodeTokenIndexSegment(userId));
2790
3034
  var createTokenStatsKey = Object.assign(
2791
3035
  (userId, dateKey) => createKey("token", "stats", "day", "user", userId, dateKey),
2792
3036
  {
@@ -2807,6 +3051,10 @@ var createTokenStatsAppliedKey = Object.assign(
2807
3051
  })
2808
3052
  }
2809
3053
  );
3054
+ var isTokenStatsKey = (key) => {
3055
+ const parts = splitKey(key);
3056
+ return parts.length >= 2 && parts[0] === "token" && parts[1] === "stats";
3057
+ };
2810
3058
  var DIALOG_AGENT_LIST_INDEX_PREFIX = "dialogidx";
2811
3059
  var DIALOG_LIST_TIMESTAMP_MAX = 9999999999999;
2812
3060
  function parseDialogUpdatedAtMs(value) {
@@ -2845,6 +3093,21 @@ function createDialogAgentListIndexKey(args) {
2845
3093
  dialogId
2846
3094
  );
2847
3095
  }
3096
+ function createDialogAgentListIndexRange(userId, agentKey) {
3097
+ const normalizedUserId = userId.trim();
3098
+ const normalizedAgentKey = agentKey.trim();
3099
+ if (!normalizedUserId || !normalizedAgentKey) {
3100
+ return { start: "", end: "" };
3101
+ }
3102
+ const start = createKey(
3103
+ DIALOG_AGENT_LIST_INDEX_PREFIX,
3104
+ "agent",
3105
+ normalizedUserId,
3106
+ normalizedAgentKey,
3107
+ ""
3108
+ );
3109
+ return { start, end: `${start}\uFFFF` };
3110
+ }
2848
3111
  function expandDialogAgentListIndexAliases(agentKey) {
2849
3112
  const key = agentKey.trim();
2850
3113
  if (!key) return [];
@@ -2973,6 +3236,7 @@ var createAgentAutomationKey = Object.assign(
2973
3236
  })
2974
3237
  }
2975
3238
  );
3239
+ var agentAutomationKey = createAgentAutomationKey;
2976
3240
  var AGENT_AUTOMATION_OWNER_INDEX_PREFIX = "agent-automation-owner-idx";
2977
3241
  var createAgentAutomationOwnerIndexKey = Object.assign(
2978
3242
  (userId, ownerAgentKey, automationId) => createKey(
@@ -3001,6 +3265,56 @@ function buildAgentAutomationOwnerIndexValue(args) {
3001
3265
  ownerAgentKey: args.ownerAgentKey
3002
3266
  };
3003
3267
  }
3268
+ function isAgentAutomationOwnerIndexKey(key) {
3269
+ return key.startsWith(`${AGENT_AUTOMATION_OWNER_INDEX_PREFIX}-`);
3270
+ }
3271
+ function parseAgentAutomationIdFromKey(key) {
3272
+ if (typeof key !== "string") return "";
3273
+ const trimmed = key.trim();
3274
+ if (!trimmed || !isAgentAutomationKey(trimmed)) return "";
3275
+ const withoutPrefix = trimmed.slice(`${"agent-automation" /* AGENT_AUTOMATION */}-`.length);
3276
+ const lastDash = withoutPrefix.lastIndexOf("-");
3277
+ return lastDash >= 0 ? withoutPrefix.slice(lastDash + 1) : "";
3278
+ }
3279
+ function buildAgentAutomationOwnerIndexDeleteOps(args) {
3280
+ const automationKey = args.automationKey.trim();
3281
+ if (!automationKey || !isAgentAutomationKey(automationKey)) return [];
3282
+ const userIdFromRecord = asTrimmedString(args.record?.createdBy);
3283
+ const userIdFromArg = asTrimmedString(args.userId);
3284
+ const withoutPrefix = automationKey.startsWith(`${"agent-automation" /* AGENT_AUTOMATION */}-`) ? automationKey.slice(`${"agent-automation" /* AGENT_AUTOMATION */}-`.length) : "";
3285
+ const lastDash = withoutPrefix.lastIndexOf("-");
3286
+ const userIdFromKey = lastDash > 0 ? withoutPrefix.slice(0, lastDash) : "";
3287
+ const automationIdFromKey = lastDash > 0 ? withoutPrefix.slice(lastDash + 1) : "";
3288
+ const userId = userIdFromArg || userIdFromRecord || userIdFromKey;
3289
+ const automationId = asOptionalTrimmedString(args.record?.id) || automationIdFromKey;
3290
+ const ownerAgentKey = asTrimmedString(args.record?.ownerAgentKey);
3291
+ if (!userId || !automationId || !ownerAgentKey) return [];
3292
+ return [
3293
+ {
3294
+ type: "del",
3295
+ key: createAgentAutomationOwnerIndexKey(userId, ownerAgentKey, automationId)
3296
+ }
3297
+ ];
3298
+ }
3299
+ var createBudgetKey = (userId) => createKey("budget", userId, "monthly");
3300
+ var createNotificationKey = {
3301
+ single: (userId, notificationId) => createKey("notification" /* NOTIFICATION */, userId, notificationId),
3302
+ rangeOfUser: (userId) => ({
3303
+ start: createKey("notification" /* NOTIFICATION */, userId, ""),
3304
+ end: createKey("notification" /* NOTIFICATION */, userId, "\uFFFF")
3305
+ })
3306
+ };
3307
+ var emailKey = {
3308
+ create: (ownerId) => {
3309
+ const emailId = ulid();
3310
+ return { dbKey: createKey("email" /* EMAIL */, ownerId, emailId), emailId };
3311
+ },
3312
+ single: (ownerId, emailId) => createKey("email" /* EMAIL */, ownerId, emailId),
3313
+ rangeOfOwner: (ownerId) => ({
3314
+ start: createKey("email" /* EMAIL */, ownerId, ""),
3315
+ end: createKey("email" /* EMAIL */, ownerId, "\uFFFF")
3316
+ })
3317
+ };
3004
3318
  var createPageKey = {
3005
3319
  create: (userId) => {
3006
3320
  const id = ulid();
@@ -3021,6 +3335,114 @@ var createAgentKey = {
3021
3335
  end: createKey("agent" /* AGENT */, userId, "\uFFFF")
3022
3336
  })
3023
3337
  };
3338
+ var pubAgentKeys = {
3339
+ single: (agentId) => createAgentKey.public(agentId),
3340
+ list: () => ({
3341
+ start: createKey("agent" /* AGENT */, "pub", ""),
3342
+ end: createKey("agent" /* AGENT */, "pub", "\uFFFF")
3343
+ }),
3344
+ allPublicRanges: () => [
3345
+ {
3346
+ start: createKey("agent" /* AGENT */, "pub", ""),
3347
+ end: createKey("agent" /* AGENT */, "pub", "\uFFFF")
3348
+ }
3349
+ ]
3350
+ };
3351
+ var createAgentGrantKey = {
3352
+ single: (ownerUserId, agentId, granteeUserId) => createKey("grant", "agent", ownerUserId, agentId, granteeUserId),
3353
+ rangeOfAgent: (ownerUserId, agentId) => ({
3354
+ start: createKey("grant", "agent", ownerUserId, agentId, ""),
3355
+ end: createKey("grant", "agent", ownerUserId, agentId, "\uFFFF")
3356
+ })
3357
+ };
3358
+ var FAV_PREFIX = "fav";
3359
+ var createFavoriteKey = {
3360
+ /* ---------- Agent 收藏(按 agentKey 存,当前使用) ---------- */
3361
+ /**
3362
+ * 某个用户收藏了某个 Agent 实例(用完整的 agentKey/dbKey)
3363
+ * key: fav-agent-key-{userId}-{agentKey}
3364
+ */
3365
+ agentByKey: (userId, agentKey) => createKey(FAV_PREFIX, "agent", "key", userId, agentKey),
3366
+ /**
3367
+ * 查询某用户收藏的所有 Agent(基于 agentKey 版本)
3368
+ * 范围: [fav-agent-key-{userId}-, fav-agent-key-{userId}-\uffff]
3369
+ */
3370
+ agentKeyRangeOfUser: (userId) => ({
3371
+ start: createKey(FAV_PREFIX, "agent", "key", userId, ""),
3372
+ end: createKey(FAV_PREFIX, "agent", "key", userId, "\uFFFF")
3373
+ }),
3374
+ userRangeOfAgentKey: (agentKey) => ({
3375
+ start: createKey(FAV_PREFIX, "agent", "key", "by-agent", agentKey, ""),
3376
+ end: createKey(FAV_PREFIX, "agent", "key", "by-agent", agentKey, "\uFFFF")
3377
+ }),
3378
+ agentByKeyReverse: (agentKey, userId) => createKey(FAV_PREFIX, "agent", "key", "by-agent", agentKey, userId),
3379
+ /* ---------- Agent 收藏(按 agentId 存,预留,将来可用) ---------- */
3380
+ /**
3381
+ * 某个用户收藏了某个逻辑 AgentId(当前未使用,预留)
3382
+ * key: fav-agent-id-{userId}-{agentId}
3383
+ */
3384
+ agentById: (userId, agentId) => createKey(FAV_PREFIX, "agent", "id", userId, agentId),
3385
+ /** 查询某用户收藏的所有 AgentId(预留) */
3386
+ agentIdRangeOfUser: (userId) => ({
3387
+ start: createKey(FAV_PREFIX, "agent", "id", userId, ""),
3388
+ end: createKey(FAV_PREFIX, "agent", "id", userId, "\uFFFF")
3389
+ }),
3390
+ userRangeOfAgentId: (agentId) => ({
3391
+ start: createKey(FAV_PREFIX, "agent", "id", "by-agent", agentId, ""),
3392
+ end: createKey(FAV_PREFIX, "agent", "id", "by-agent", agentId, "\uFFFF")
3393
+ }),
3394
+ agentByIdReverse: (agentId, userId) => createKey(FAV_PREFIX, "agent", "id", "by-agent", agentId, userId),
3395
+ /* ---------- Page 收藏(同样区分 key / id,当前可以只用 byKey) ---------- */
3396
+ // Page byKey: fav-page-key-{userId}-{pageKey}
3397
+ pageByKey: (userId, pageKey) => createKey(FAV_PREFIX, "page", "key", userId, pageKey),
3398
+ pageKeyRangeOfUser: (userId) => ({
3399
+ start: createKey(FAV_PREFIX, "page", "key", userId, ""),
3400
+ end: createKey(FAV_PREFIX, "page", "key", userId, "\uFFFF")
3401
+ }),
3402
+ userRangeOfPageKey: (pageKey) => ({
3403
+ start: createKey(FAV_PREFIX, "page", "key", "by-page", pageKey, ""),
3404
+ end: createKey(FAV_PREFIX, "page", "key", "by-page", pageKey, "\uFFFF")
3405
+ }),
3406
+ pageByKeyReverse: (pageKey, userId) => createKey(FAV_PREFIX, "page", "key", "by-page", pageKey, userId),
3407
+ // Page byId(预留)
3408
+ pageById: (userId, pageId) => createKey(FAV_PREFIX, "page", "id", userId, pageId),
3409
+ pageIdRangeOfUser: (userId) => ({
3410
+ start: createKey(FAV_PREFIX, "page", "id", userId, ""),
3411
+ end: createKey(FAV_PREFIX, "page", "id", userId, "\uFFFF")
3412
+ }),
3413
+ userRangeOfPageId: (pageId) => ({
3414
+ start: createKey(FAV_PREFIX, "page", "id", "by-page", pageId, ""),
3415
+ end: createKey(FAV_PREFIX, "page", "id", "by-page", pageId, "\uFFFF")
3416
+ }),
3417
+ pageByIdReverse: (pageId, userId) => createKey(FAV_PREFIX, "page", "id", "by-page", pageId, userId),
3418
+ /** 从 dbKey 中解析出目标标识符 (agentKey/agentId/pageKey/pageId) */
3419
+ getIdentifierFromKey: (key) => {
3420
+ const parts = key.split(SEPARATOR);
3421
+ return parts.slice(4).join(SEPARATOR);
3422
+ }
3423
+ };
3424
+ var createFavoriteStatsKey = {
3425
+ // 被多少人收藏的 Agent(按 agentKey 统计,当前实际使用)
3426
+ agentByKey: (agentKey) => createKey(FAV_PREFIX, "agent-count", "key", agentKey),
3427
+ // 预留:按逻辑 AgentId 统计
3428
+ agentById: (agentId) => createKey(FAV_PREFIX, "agent-count", "id", agentId),
3429
+ // Page:按 pageKey 统计(预留)
3430
+ pageByKey: (pageKey) => createKey(FAV_PREFIX, "page-count", "key", pageKey),
3431
+ pageById: (pageId) => createKey(FAV_PREFIX, "page-count", "id", pageId)
3432
+ };
3433
+ var jobKey = {
3434
+ create: (tenantId, jobId) => {
3435
+ const id = jobId || ulid();
3436
+ const dbKey = createKey("job", tenantId, id);
3437
+ return { dbKey, id };
3438
+ },
3439
+ single: (tenantId, jobId) => createKey("job", tenantId, jobId),
3440
+ rangeOfTenant: (tenantId) => {
3441
+ const start = createKey("job", tenantId, "");
3442
+ return { start, end: start + "\uFFFF" };
3443
+ }
3444
+ };
3445
+ var blobKey = (sha256) => createKey("blob", sha256);
3024
3446
  var fileKey = {
3025
3447
  single: (tenantId, fileId) => createKey("file", tenantId, fileId),
3026
3448
  rangeOfTenant: (tenantId) => {
@@ -3031,173 +3453,17 @@ var fileKey = {
3031
3453
  };
3032
3454
  }
3033
3455
  };
3456
+ var fileIdIndexKey = (fileId) => createKey("file", "id", fileId);
3034
3457
  var getFileIdFromKey = (key) => {
3035
- const parts = key.split(SEPARATOR2);
3458
+ const parts = key.split(SEPARATOR);
3036
3459
  return parts[2];
3037
3460
  };
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;
3461
+ var fileStatKey = {
3462
+ tenantPerDay: (tenantId, dateKey) => createKey("file", "stat", "tenant", tenantId, dateKey),
3463
+ modelPerDay: (modelName, dateKey) => createKey("file", "stat", "model", modelName, dateKey)
3197
3464
  };
3198
3465
 
3199
3466
  export {
3200
- ulid,
3201
3467
  toTrimmedString,
3202
3468
  toNonEmptyString,
3203
3469
  extractAgentInfo,
@@ -3205,41 +3471,77 @@ export {
3205
3471
  resolveShareAuthorIdentity,
3206
3472
  sanitizeShareData,
3207
3473
  shareKey,
3208
- isDialogKey,
3209
- isDialogRecordKey,
3210
- createDialogKey,
3211
- dialogMessageKey,
3212
- createDialogMessageKeyAndId,
3213
- dialogMessagePrefix,
3214
- dialogMessageRange,
3215
- SEPARATOR2 as SEPARATOR,
3474
+ SEPARATOR,
3216
3475
  createKey,
3217
3476
  splitKey,
3218
3477
  TYPE_STORAGE_PREFIXES,
3478
+ inferTypeFromDbKey,
3219
3479
  isTableMetaKey,
3220
3480
  isPageKey,
3221
3481
  isTaskKey,
3482
+ isAgentAutomationKey,
3222
3483
  isFileKey,
3223
- isAgentKey2 as isAgentKey,
3484
+ isAgentKey,
3224
3485
  isAppKey,
3486
+ isEmailKey,
3225
3487
  rowKey,
3488
+ idxKey,
3226
3489
  metaKey,
3490
+ viewKey,
3227
3491
  DB_PREFIX,
3492
+ createOAuthCredentialKey,
3493
+ oauthCredentialUserRange,
3494
+ USER_SETTINGS_KEY_SUFFIX,
3228
3495
  createUserKey,
3229
3496
  createUserPreferenceKey,
3230
3497
  createMemoryKey,
3231
3498
  createMemoryOwnerIndexKey,
3232
3499
  createMemorySubjectKindIndexKey,
3500
+ isMemoryKey,
3233
3501
  memoryOwnerRange,
3234
3502
  memorySubjectKindRange,
3503
+ createTransactionKey,
3235
3504
  createTokenKey,
3505
+ TOKEN_DIALOG_INDEX_PREFIX,
3506
+ encodeTokenIndexSegment,
3507
+ createTokenDialogIndexKey,
3508
+ TOKEN_DIALOG_INDEX_FORMAT,
3509
+ createTokenDialogBackfillKey,
3236
3510
  createTokenStatsKey,
3511
+ createTokenStatsAppliedKey,
3512
+ isTokenStatsKey,
3513
+ DIALOG_AGENT_LIST_INDEX_PREFIX,
3514
+ parseDialogUpdatedAtMs,
3515
+ toDialogListInvertedTimestamp,
3516
+ createDialogAgentListIndexKey,
3517
+ createDialogAgentListIndexRange,
3518
+ expandDialogAgentListIndexAliases,
3519
+ collectDialogAgentListIndexAgentKeys,
3520
+ isDialogAgentListIndexable,
3237
3521
  buildDialogAgentListIndexDeleteOps,
3522
+ buildDialogAgentListIndexOps,
3523
+ createTaskKey,
3238
3524
  createAgentAutomationKey,
3525
+ agentAutomationKey,
3526
+ AGENT_AUTOMATION_OWNER_INDEX_PREFIX,
3239
3527
  createAgentAutomationOwnerIndexKey,
3240
3528
  buildAgentAutomationOwnerIndexValue,
3529
+ isAgentAutomationOwnerIndexKey,
3530
+ parseAgentAutomationIdFromKey,
3531
+ buildAgentAutomationOwnerIndexDeleteOps,
3532
+ createBudgetKey,
3533
+ createNotificationKey,
3534
+ emailKey,
3241
3535
  createPageKey,
3242
3536
  createAgentKey,
3537
+ pubAgentKeys,
3538
+ createAgentGrantKey,
3539
+ createFavoriteKey,
3540
+ createFavoriteStatsKey,
3541
+ jobKey,
3542
+ blobKey,
3243
3543
  fileKey,
3244
- getFileIdFromKey
3544
+ fileIdIndexKey,
3545
+ getFileIdFromKey,
3546
+ fileStatKey
3245
3547
  };