nolo-cli 0.32.0 → 0.33.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 (170) hide show
  1. package/README.md +6 -12
  2. package/{_executeModel-LTMSIBS4.js → _executeModel-RWPVI3YV.js} +76 -67
  3. package/{action-HI3VRQLP.js → action-SMLG6OTB.js} +17 -15
  4. package/{addContentAction-NCURJ6PK.js → addContentAction-SFO244QN.js} +14 -13
  5. package/{addDialogAgentAction-RCY4ECF4.js → addDialogAgentAction-W44ZCEHB.js} +14 -13
  6. package/{agentDeleteCommand-D3MYZK6E.js → agentDeleteCommand-KU2RXQPP.js} +42 -59
  7. package/{agentEmailCommands-6BXS574I.js → agentEmailCommands-MPCMDENS.js} +89 -80
  8. package/{agentGrantCommands-E7ZZFRHK.js → agentGrantCommands-2LEZDADN.js} +2 -2
  9. package/{agentListCommands-SF3HEUTT.js → agentListCommands-EPD4N6FX.js} +73 -78
  10. package/{agentMachineCommands-YARVXRR6.js → agentMachineCommands-AF7C3YRT.js} +40 -57
  11. package/{agentPullCommand-ARSIDNVC.js → agentPullCommand-YH5GEBK4.js} +5 -5
  12. package/agentRecordCommands-EYE6MZZG.js +112 -0
  13. package/agentRunCommand-LL22SGTN.js +130 -0
  14. package/{agentRuntimeLocal-ATGJY6WC.js → agentRuntimeLocal-JX34G47Z.js} +35 -50
  15. package/{agentSlice-4XWW344Y.js → agentSlice-TNMFQQOV.js} +15 -13
  16. package/{appDeleteCommands-63JO7RXS.js → appDeleteCommands-43K5VXQB.js} +38 -55
  17. package/{appDeployCommands-Y7EWYUGM.js → appDeployCommands-FEEJSVDZ.js} +38 -55
  18. package/{appDeployStatusCommands-ZBEY3DWB.js → appDeployStatusCommands-H76CG45R.js} +38 -55
  19. package/{appGetCommands-QSSOSEYL.js → appGetCommands-MDZYFTYZ.js} +38 -55
  20. package/{appListCommands-PH3XWNDX.js → appListCommands-TUJJXPWG.js} +38 -55
  21. package/{authCommand-BBDHMSO6.js → authCommand-T7UK4CWS.js} +18 -18
  22. package/{authCommands-4UDEKRE6.js → authCommands-EAPFGNHN.js} +8 -8
  23. package/chatQueueReduxAdapter-LVQXC4ZY.js +180 -0
  24. package/chunk-2H3XIBY4.js +239 -0
  25. package/{chunk-TEYN42N3.js → chunk-2IVEXF7P.js} +11 -4
  26. package/{chunk-WTGCTVJG.js → chunk-2QTEYCR7.js} +3 -6
  27. package/{chunk-DOISARTV.js → chunk-2UECQ7RE.js} +1 -1
  28. package/{chunk-SWYMCHM7.js → chunk-37V5LNEQ.js} +69 -1
  29. package/{chunk-E3APEOIM.js → chunk-3GZXL6FM.js} +4 -19
  30. package/{chunk-O3JR45Q2.js → chunk-3VAQHAXT.js} +44 -44
  31. package/{chunk-O5OMJPPF.js → chunk-3WXRAHCG.js} +6 -5
  32. package/{chunk-LAXMH7JY.js → chunk-57QJXIB6.js} +18 -15
  33. package/chunk-5CS33IBL.js +301 -0
  34. package/{chunk-3UGKATZQ.js → chunk-5SBK2MTI.js} +8 -369
  35. package/chunk-6PO2SYCS.js +1800 -0
  36. package/{chunk-TA6EA2A3.js → chunk-6SXC35F4.js} +182 -20
  37. package/{chunk-MXFQHRSS.js → chunk-6XIE5ZGI.js} +1 -1
  38. package/{chunk-3GZT3L6F.js → chunk-73GINUCW.js} +326 -481
  39. package/{chunk-VMWR7VNI.js → chunk-7E72JMBB.js} +7 -7
  40. package/{chunk-4PNU7W7K.js → chunk-AAGCMVFT.js} +106 -124
  41. package/chunk-ADLYMQB6.js +642 -0
  42. package/{chunk-ZWJOGMKH.js → chunk-AETZ7AD6.js} +1 -1
  43. package/{chunk-UDA3ZYLW.js → chunk-AFV4FOT2.js} +70 -24
  44. package/{chunk-BGTUGS3T.js → chunk-AOXVOC6D.js} +4 -30
  45. package/{chunk-2ZRP5RUG.js → chunk-B2BSG6QQ.js} +12 -11
  46. package/{chunk-44HACRCK.js → chunk-BANYWEYY.js} +4 -4
  47. package/{chunk-TOW4E763.js → chunk-BJIRLHJR.js} +2 -0
  48. package/{chunk-ZJ2WITOO.js → chunk-BQXOGBFN.js} +2 -2
  49. package/{chunk-G5GVZAXF.js → chunk-CLP2K7U4.js} +15 -19
  50. package/{chunk-2K4NDPT5.js → chunk-DFUPZE6V.js} +20 -12
  51. package/{chunk-YHGHADBQ.js → chunk-DPMBNHOJ.js} +4 -4
  52. package/chunk-EGRJC4ZN.js +91 -0
  53. package/{chunk-K6QEHQZ3.js → chunk-EKLRRZIN.js} +1 -1
  54. package/{chunk-XFG3BAKN.js → chunk-FMEVI5TG.js} +65 -0
  55. package/{chunk-RH53LMEJ.js → chunk-FSSX3XRY.js} +2 -4
  56. package/{chunk-VP4WJWKW.js → chunk-GM6PU7B6.js} +431 -345
  57. package/{chunk-EEF23OOK.js → chunk-GMXWYXAF.js} +7 -7
  58. package/{chunk-SFWZUTCI.js → chunk-GTYM4HKV.js} +1 -1
  59. package/{chunk-MITD7CON.js → chunk-HDKRSRYU.js} +1461 -301
  60. package/chunk-HS7MLR74.js +38 -0
  61. package/{chunk-3AUWC6EM.js → chunk-HUCT7HID.js} +5 -84
  62. package/{chunk-PTHDLIRB.js → chunk-I6N2UVVY.js} +1 -1
  63. package/chunk-IDAU4UFS.js +437 -0
  64. package/{chunk-Q76I4SXI.js → chunk-IHEC7VBF.js} +1 -1
  65. package/{chunk-OWHNFZNW.js → chunk-IL545V3E.js} +4 -4
  66. package/{chunk-3LY4F7SV.js → chunk-INZZJSQF.js} +348 -331
  67. package/{chunk-CF2WZF4N.js → chunk-J6WH4PYZ.js} +0 -8
  68. package/{chunk-2HXKAPH7.js → chunk-JMPYDFHY.js} +6 -6
  69. package/{chunk-V54H24CQ.js → chunk-JTSGWTYZ.js} +3 -3
  70. package/{chunk-ATK5WJOA.js → chunk-JZ5AMMXU.js} +4 -4
  71. package/chunk-KHCLMKZZ.js +3062 -0
  72. package/{chunk-WHLVPK32.js → chunk-KMSZPTM6.js} +27 -3
  73. package/{chunk-L3GCUVOH.js → chunk-KSRFVP36.js} +1 -1
  74. package/{chunk-DLWCWUNW.js → chunk-LOD75GOS.js} +336 -32
  75. package/{chunk-UOJRKY5J.js → chunk-M2YMQOLC.js} +44 -53
  76. package/chunk-M3JEW6N6.js +193 -0
  77. package/{chunk-XDHHF73Q.js → chunk-M4NC7NF6.js} +95 -95
  78. package/{chunk-3FCNXC2J.js → chunk-MPZJVZDC.js} +3735 -1394
  79. package/{chunk-IXZX5CJK.js → chunk-MQRZ5QUH.js} +1 -1
  80. package/{chunk-3ASDTTEI.js → chunk-MRWGHF56.js} +2 -0
  81. package/{chunk-D34RI6NI.js → chunk-NNWHHCVP.js} +75 -1
  82. package/{chunk-6YABCOFU.js → chunk-NUO3QFWD.js} +1 -1
  83. package/{chunk-GAF5X6B7.js → chunk-O6GEBMIY.js} +269 -309
  84. package/{chunk-CAENRKNJ.js → chunk-OR2HNLVO.js} +126 -88
  85. package/chunk-OW765XBU.js +10 -0
  86. package/chunk-PREQU5QV.js +231 -0
  87. package/{chunk-Q3CSL43H.js → chunk-Q5ITEGIN.js} +1 -1
  88. package/{chunk-7S54ZGF6.js → chunk-RAZOLMJR.js} +256 -12
  89. package/chunk-RCFIB45Q.js +28 -0
  90. package/chunk-RY57GLGW.js +188 -0
  91. package/{chunk-KGEVMUMI.js → chunk-TFPUAELY.js} +11 -11
  92. package/{chunk-ZJH3LKEW.js → chunk-UK5JGQVU.js} +94 -15
  93. package/chunk-URMS4XY2.js +10 -0
  94. package/{chunk-RXVX5LFR.js → chunk-VH2F7ZB6.js} +1 -1
  95. package/chunk-VIDPVFP3.js +20 -0
  96. package/{chunk-W367V5CH.js → chunk-WHD6BG7M.js} +400 -115
  97. package/{chunk-5RDLGLAP.js → chunk-WJSW43QZ.js} +4 -7
  98. package/{chunk-CF7S2RYZ.js → chunk-WLH5BAKX.js} +6 -6
  99. package/{chunk-VVEH6XUE.js → chunk-X2DAEZ3X.js} +1 -1
  100. package/{chunk-2IJAKBK2.js → chunk-X664KVEV.js} +426 -246
  101. package/{chunk-43EPBPZ2.js → chunk-XCCGU6QB.js} +2 -2
  102. package/chunk-Y5GCAMGP.js +9 -0
  103. package/{chunk-V42OE5HT.js → chunk-YDTYDA5W.js} +3 -3
  104. package/chunk-YYLHWIW6.js +48 -0
  105. package/{chunk-AOS5IN2I.js → chunk-ZHYK3N56.js} +1 -1
  106. package/{chunk-ODS2MVMU.js → chunk-ZJMME4DS.js} +19 -303
  107. package/{chunk-PJ2DDQQM.js → chunk-ZURFOV5J.js} +2 -2
  108. package/chunk-ZZ2MH7LE.js +84 -0
  109. package/{cliExecutor-BBUVQU4L.js → cliExecutor-DW3PHGEL.js} +2 -2
  110. package/{clipboardy-BVE3LVEH.js → clipboardy-MMBYVRLF.js} +166 -372
  111. package/{codingSkills-V35TRR4Y.js → codingSkills-DY5MINPG.js} +5 -4
  112. package/{createAgentAutomationAction-WLRNE7C4.js → createAgentAutomationAction-INQT23LX.js} +40 -31
  113. package/createDialogAction-LDCPDI73.js +60 -0
  114. package/{createPageAction-7YROVZ3W.js → createPageAction-5YXOG2M4.js} +56 -47
  115. package/{db-6DPSJ6WT.js → db-3H3JECGY.js} +45 -5
  116. package/{dbSlice-BBL3PEVW.js → dbSlice-3SD5L5H2.js} +13 -12
  117. package/{deleteFile-RJTEPOT4.js → deleteFile-XQXPBFFB.js} +7 -6
  118. package/dialogCommands-CHJO47AX.js +81 -0
  119. package/{dialogSlice-N4HPG6HM.js → dialogSlice-DOWKOILN.js} +36 -29
  120. package/{docCreateCommands-GRA5BHSA.js → docCreateCommands-OVZARUFX.js} +40 -55
  121. package/{docDeleteCommands-ONIJM5MD.js → docDeleteCommands-E2XJ62LD.js} +42 -57
  122. package/{docReadCommands-H55VQ2US.js → docReadCommands-I7OSREPJ.js} +40 -55
  123. package/{docStore-B5AHDNW5.js → docStore-UAWSKZ2Y.js} +39 -30
  124. package/{docUpdateCommands-ZQIQVGC2.js → docUpdateCommands-X4Z26VJM.js} +43 -58
  125. package/{fetchMessages-VPPQDDZ4.js → fetchMessages-7QRCCRYK.js} +3 -3
  126. package/{getPricing-QO5TYNCK.js → getPricing-L2ENXWHV.js} +7 -6
  127. package/{handleSendMessageAction-IN5XX5U7.js → handleSendMessageAction-C3TSDWKH.js} +38 -31
  128. package/index.js +67 -67
  129. package/{lib-FYYBQIXS.js → lib-2ZTNRXR4.js} +432 -183
  130. package/{localDialogRead-3DBXVYXS.js → localDialogRead-SLMPV5SK.js} +2 -2
  131. package/{localRuntimeAuthority-NDUA2D7Y.js → localRuntimeAuthority-E3R24J4T.js} +4 -2
  132. package/{localRuntimeDb-GKYRBWLQ.js → localRuntimeDb-DDZCJFQZ.js} +1 -1
  133. package/{machineCommands-H3UMKE76.js → machineCommands-BUOIYJAD.js} +93 -84
  134. package/{machineWsRunDispatch-HONRUK3R.js → machineWsRunDispatch-7CRWAA6O.js} +83 -74
  135. package/{models-WDUTTYFS.js → models-OX2S5C6Q.js} +2 -2
  136. package/{offlineMarxistsAgentCommand-E6LUG63A.js → offlineMarxistsAgentCommand-GEH6SNNA.js} +1 -1
  137. package/package.json +1 -4
  138. package/{read-64OQDO3I.js → read-6G73BMEY.js} +8 -7
  139. package/{readDocTool-MXM3T6PE.js → readDocTool-DK4EI2GA.js} +1 -2
  140. package/{readlineWorkspace-XVJZDCSC.js → readlineWorkspace-ZDWEASJV.js} +265 -428
  141. package/{removeDialogAgentAction-NEKVAMSH.js → removeDialogAgentAction-E7H557UO.js} +19 -17
  142. package/{runAgentClientLoop-H7U53QB6.js → runAgentClientLoop-U7HYA3O5.js} +72 -64
  143. package/{runtimeDoctorCommands-WI2YZUSJ.js → runtimeDoctorCommands-KIKM6BIO.js} +5 -5
  144. package/{setDialogExtraReferencesAction-WTOHQDIV.js → setDialogExtraReferencesAction-RMMGBR5F.js} +15 -14
  145. package/{setPrimaryDialogAgentAction-LDJOYC4F.js → setPrimaryDialogAgentAction-FWBKKLVA.js} +19 -17
  146. package/{settingSlice-4M37TN7V.js → settingSlice-73PV4KG4.js} +16 -14
  147. package/{skillDiscovery-5U6RYAHN.js → skillDiscovery-KLLKXPUO.js} +4 -4
  148. package/{slateUtils-2M7MUTWX.js → slateUtils-VO2FU36K.js} +1 -1
  149. package/{spaceCommands-7VVKJBDV.js → spaceCommands-GEWZXGHM.js} +43 -240
  150. package/{spaceSlice-T6YK6D34.js → spaceSlice-B6MOVY4N.js} +38 -61
  151. package/{streamAgentChatTurn-RQ63QFQ7.js → streamAgentChatTurn-T527EQTT.js} +1261 -150
  152. package/{switchDialogAgentAction-XVWGKR2Z.js → switchDialogAgentAction-US6QNL3N.js} +14 -13
  153. package/syncMapping-RK2MANUX.js +43 -0
  154. package/{tableCommands-RJZ3V4TF.js → tableCommands-QE47K72R.js} +8 -7
  155. package/{toolApiClient-ARGFDJAG.js → toolApiClient-B2MFXMEG.js} +3 -3
  156. package/tools-XMWCVMPM.js +98 -0
  157. package/{tuiSummaryLlmCaller-SRZ4QQUP.js → tuiSummaryLlmCaller-NCAJSVSD.js} +24 -21
  158. package/{updateDialogTitleAction-BBDSWHNG.js → updateDialogTitleAction-XPJZRJEL.js} +48 -38
  159. package/agentRecordCommands-JFZRQJQ4.js +0 -103
  160. package/agentRunCommand-NOX5FLKO.js +0 -121
  161. package/chunk-AYMOSAHE.js +0 -3158
  162. package/chunk-D2BPX6DQ.js +0 -1707
  163. package/chunk-DCDL3GC4.js +0 -171
  164. package/chunk-F3MP7CP6.js +0 -73
  165. package/chunk-WZSRQNQG.js +0 -2587
  166. package/createDialogAction-Y6YV64QB.js +0 -52
  167. package/dialogCommands-XLO5CAHZ.js +0 -95
  168. package/tools-KYZX3BGO.js +0 -90
  169. package/{chunk-Z5MXSEOJ.js → chunk-RQSOAMPJ.js} +2 -2
  170. package/{chunk-JDSUTNYY.js → chunk-SAQQLJZ5.js} +3 -3
@@ -0,0 +1,38 @@
1
+ // packages/shared/providerSecrets.ts
2
+ function providerSecretKey(presetId) {
3
+ const normalized = presetId.trim().replace(/[^a-zA-Z0-9]+/g, "_").toUpperCase();
4
+ return `${normalized}_KEY`;
5
+ }
6
+
7
+ // packages/ai/agent/providerSecrets.ts
8
+ var STORAGE_KEY = "nolo-local-secrets";
9
+ function readLocalSecrets() {
10
+ if (typeof localStorage === "undefined") return {};
11
+ try {
12
+ const value = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? "{}");
13
+ return value && typeof value === "object" ? value : {};
14
+ } catch {
15
+ return {};
16
+ }
17
+ }
18
+ function getLocalProviderSecret(presetId) {
19
+ return readLocalSecrets()[providerSecretKey(presetId)] ?? null;
20
+ }
21
+ async function getServerProviderSecret(args) {
22
+ try {
23
+ const response = await fetch(
24
+ `${args.serverOrigin}/api/user-secrets/get?presetId=${encodeURIComponent(args.presetId)}`,
25
+ { cache: "no-store", headers: { Authorization: `Bearer ${args.token}` } }
26
+ );
27
+ if (!response.ok) return null;
28
+ const body = await response.json();
29
+ return body.value ?? null;
30
+ } catch {
31
+ return null;
32
+ }
33
+ }
34
+
35
+ export {
36
+ getLocalProviderSecret,
37
+ getServerProviderSecret
38
+ };
@@ -1,11 +1,14 @@
1
1
  import {
2
2
  TOOL_PACKS,
3
3
  buildCodeWorkDiscipline
4
- } from "./chunk-CF7S2RYZ.js";
4
+ } from "./chunk-WLH5BAKX.js";
5
5
  import {
6
6
  buildSkillDocMarkdown,
7
7
  resolvePageSkillMetadata
8
- } from "./chunk-ZWJOGMKH.js";
8
+ } from "./chunk-AETZ7AD6.js";
9
+ import {
10
+ canonicalizeToolNames
11
+ } from "./chunk-ZZ2MH7LE.js";
9
12
  import {
10
13
  asNonEmptyStringArray
11
14
  } from "./chunk-I42VC5KR.js";
@@ -13,85 +16,6 @@ import {
13
16
  asOptionalTrimmedString
14
17
  } from "./chunk-G3SUCT4W.js";
15
18
 
16
- // packages/agent-runtime/toolNameAliases.ts
17
- var LEGACY_TOOL_NAME_ALIASES = {
18
- createPage: "createDoc",
19
- updatePage: "updateDoc",
20
- update_page: "updateDoc",
21
- create_page: "createDoc",
22
- fetchwebpage: "fetchWebpage",
23
- fetch_webpage: "fetchWebpage",
24
- "fetch-page": "fetchWebpage",
25
- exasearch: "exa_search",
26
- "exa-search": "exa_search",
27
- exa_search: "exa_search",
28
- firecrawlscrape: "firecrawl_scrape",
29
- "firecrawl-scrape": "firecrawl_scrape",
30
- firecrawl_scrape: "firecrawl_scrape",
31
- firecrawlsearch: "firecrawl_search",
32
- "firecrawl-search": "firecrawl_search",
33
- firecrawl_search: "firecrawl_search",
34
- readDoc: "readDoc",
35
- readpage: "readDoc",
36
- read_page: "readDoc",
37
- read_doc: "readDoc",
38
- createdoc: "createDoc",
39
- updateDocTool: "updateDoc",
40
- terminalCommand: "execShell",
41
- terminal_command: "execShell",
42
- runCommand: "execShell",
43
- run_command: "execShell",
44
- runInBash: "execShell",
45
- run_in_bash: "execShell",
46
- executeCommand: "execShell",
47
- execute_command: "execShell",
48
- // Codex CLI 风格工具名 → nolo 原生工具名
49
- bash: "execShell",
50
- shell: "execShell",
51
- read: "readFile",
52
- edit: "editFile",
53
- write: "writeFile",
54
- glob: "globFiles",
55
- grep: "searchFiles",
56
- // 联网搜索别名
57
- web_search: "exa_search",
58
- websearch: "exa_search",
59
- search_web: "exa_search",
60
- searchweb: "exa_search",
61
- webfetch: "fetchWebpage",
62
- web_fetch: "fetchWebpage",
63
- fetchweb: "fetchWebpage",
64
- fetch_web: "fetchWebpage",
65
- // 模型偶尔会把 loadSkill 幻觉成 readSkill(参数风格 name= 一致),
66
- // 规范化到 loadSkill,避免 localToolPolicy 把这种调用直接拦死。
67
- readSkill: "loadSkill"
68
- };
69
- var normalizeToolName = (name) => name.replace(/[-_]/g, "").toLowerCase();
70
- var canonicalizeToolName = (rawName) => {
71
- const trimmedName = rawName.trim();
72
- if (!trimmedName) return rawName;
73
- if (LEGACY_TOOL_NAME_ALIASES[trimmedName]) {
74
- return LEGACY_TOOL_NAME_ALIASES[trimmedName];
75
- }
76
- const normalizedRawName = normalizeToolName(trimmedName);
77
- const matchedAlias = Object.entries(LEGACY_TOOL_NAME_ALIASES).find(
78
- ([alias]) => normalizeToolName(alias) === normalizedRawName
79
- );
80
- return matchedAlias?.[1] ?? trimmedName;
81
- };
82
- var canonicalizeToolNames = (toolNames) => Array.from(
83
- new Set(
84
- toolNames.filter((toolName) => typeof toolName === "string").map(canonicalizeToolName)
85
- )
86
- );
87
- var prioritizeToolNames = (toolNames, preferredToolNames) => {
88
- const canonicalTools = canonicalizeToolNames(toolNames);
89
- const preferred = new Set(canonicalizeToolNames(preferredToolNames));
90
- const prioritized = canonicalTools.filter((toolName) => preferred.has(toolName));
91
- const remaining = canonicalTools.filter((toolName) => !preferred.has(toolName));
92
- return [...prioritized, ...remaining];
93
- };
94
-
95
19
  // packages/ai/skills/referenceRuntime.ts
96
20
  var joinUniqueStrings = (...groups) => Array.from(new Set(groups.flatMap((items) => asNonEmptyStringArray(items))));
97
21
  var extractRuntimePageCapabilities = (content) => {
@@ -663,9 +587,6 @@ async function resolveCodingEffectiveTools(userId) {
663
587
  }
664
588
 
665
589
  export {
666
- canonicalizeToolName,
667
- canonicalizeToolNames,
668
- prioritizeToolNames,
669
590
  extractRuntimePageCapabilities,
670
591
  buildSkillGuidancePromptBlock,
671
592
  resolveSkillGraphFromRoots,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  generatePkcePair,
3
3
  startCallbackServer
4
- } from "./chunk-SFWZUTCI.js";
4
+ } from "./chunk-GTYM4HKV.js";
5
5
  import {
6
6
  toErrorMessage
7
7
  } from "./chunk-HNMXYYJR.js";
@@ -0,0 +1,437 @@
1
+ import {
2
+ asOptionalFiniteNumber
3
+ } from "./chunk-WWC7I6TA.js";
4
+ import {
5
+ isLevelNotFoundError
6
+ } from "./chunk-OW765XBU.js";
7
+ import {
8
+ asTrimmedString
9
+ } from "./chunk-3EUW3WEO.js";
10
+ import {
11
+ asOptionalPositiveFiniteNumber
12
+ } from "./chunk-U6VC4MU4.js";
13
+
14
+ // packages/database/sync/syncMappingKeys.ts
15
+ var SYNC_MAPPING_KEY_PREFIX = "syncmap-local-";
16
+ var SYNC_MAPPING_KEY_SEPARATOR = "::";
17
+ var SYNC_MAPPING_RECORD_TYPE = "sync_mapping";
18
+ var normalizeSegment = (value) => asTrimmedString(value);
19
+ function buildSyncMappingRecordKey(accountUserId, localDbKey) {
20
+ const account = normalizeSegment(accountUserId);
21
+ const local = normalizeSegment(localDbKey);
22
+ if (!account) {
23
+ throw new Error("syncMapping record key requires accountUserId");
24
+ }
25
+ if (!local) {
26
+ throw new Error("syncMapping record key requires localDbKey");
27
+ }
28
+ if (account.includes(SYNC_MAPPING_KEY_SEPARATOR)) {
29
+ throw new Error(
30
+ `syncMapping accountUserId must not contain "${SYNC_MAPPING_KEY_SEPARATOR}"`
31
+ );
32
+ }
33
+ return `${SYNC_MAPPING_KEY_PREFIX}${account}${SYNC_MAPPING_KEY_SEPARATOR}${local}`;
34
+ }
35
+ function isSyncMappingRecordKey(dbKey) {
36
+ const key = normalizeSegment(dbKey);
37
+ return key.startsWith(SYNC_MAPPING_KEY_PREFIX);
38
+ }
39
+ function syncMappingRecordKeyRange() {
40
+ const start = SYNC_MAPPING_KEY_PREFIX;
41
+ return {
42
+ gte: start,
43
+ lte: `${start}\uFFFF`
44
+ };
45
+ }
46
+
47
+ // packages/database/sync/syncMappingDurable.ts
48
+ var clean = (value) => asTrimmedString(value);
49
+ function toDurableSyncMappingRecord(input) {
50
+ const localDbKey = clean(input.localDbKey);
51
+ const remoteDbKey = clean(input.remoteDbKey);
52
+ const accountUserId = clean(input.accountUserId);
53
+ const contentType = clean(input.contentType) || "unknown";
54
+ const updatedAt = asOptionalFiniteNumber(input.updatedAt) ?? Date.now();
55
+ if (!localDbKey || !remoteDbKey || !accountUserId) {
56
+ throw new Error("durable syncMapping requires local/remote/account keys");
57
+ }
58
+ const dbKey = buildSyncMappingRecordKey(accountUserId, localDbKey);
59
+ return {
60
+ type: SYNC_MAPPING_RECORD_TYPE,
61
+ userId: "local",
62
+ dbKey,
63
+ localDbKey,
64
+ remoteDbKey,
65
+ accountUserId,
66
+ contentType,
67
+ updatedAt
68
+ };
69
+ }
70
+ function parseDurableSyncMappingRecord(value) {
71
+ if (!value || typeof value !== "object") return null;
72
+ const row = value;
73
+ if (row.type !== SYNC_MAPPING_RECORD_TYPE) return null;
74
+ if (row.userId !== "local" && row.userId !== void 0) {
75
+ return null;
76
+ }
77
+ const localDbKey = clean(row.localDbKey);
78
+ const remoteDbKey = clean(row.remoteDbKey);
79
+ const accountUserId = clean(row.accountUserId);
80
+ const contentType = clean(row.contentType) || "unknown";
81
+ const updatedAt = asOptionalFiniteNumber(row.updatedAt) ?? Date.now();
82
+ if (!localDbKey || !remoteDbKey || !accountUserId) return null;
83
+ if (localDbKey === remoteDbKey) return null;
84
+ if (accountUserId === "local") return null;
85
+ return {
86
+ localDbKey,
87
+ remoteDbKey,
88
+ accountUserId,
89
+ contentType,
90
+ updatedAt
91
+ };
92
+ }
93
+ async function persistSyncMappingToDb(db, input) {
94
+ const record = toDurableSyncMappingRecord(input);
95
+ await db.put(record.dbKey, record);
96
+ return record;
97
+ }
98
+ async function removeSyncMappingFromDb(db, accountUserId, localDbKey) {
99
+ const dbKey = buildSyncMappingRecordKey(accountUserId, localDbKey);
100
+ try {
101
+ if (typeof db.del === "function") {
102
+ await db.del(dbKey);
103
+ return true;
104
+ }
105
+ await db.put(dbKey, null);
106
+ return true;
107
+ } catch (err) {
108
+ if (isLevelNotFoundError(err)) return false;
109
+ throw err;
110
+ }
111
+ }
112
+ async function loadSyncMappingsFromDb(db) {
113
+ if (typeof db.iterator !== "function") {
114
+ return [];
115
+ }
116
+ const range = syncMappingRecordKeyRange();
117
+ let iterator = db.iterator(range);
118
+ if (iterator && typeof iterator.then === "function") {
119
+ iterator = await iterator;
120
+ }
121
+ if (!iterator) return [];
122
+ const out = [];
123
+ for await (const entry of iterator) {
124
+ const pair = entry;
125
+ const key = Array.isArray(pair) ? pair[0] : "";
126
+ const value = Array.isArray(pair) ? pair[1] : null;
127
+ if (!isSyncMappingRecordKey(key)) continue;
128
+ if (value == null) continue;
129
+ const mapping = parseDurableSyncMappingRecord(value);
130
+ if (mapping) out.push(mapping);
131
+ }
132
+ return out;
133
+ }
134
+
135
+ // packages/database/sync/syncMapping.ts
136
+ var normalizeKey = (value) => asTrimmedString(value);
137
+ var normalizeContentType = (value) => {
138
+ const trimmed = normalizeKey(value);
139
+ return trimmed.length > 0 ? trimmed : "unknown";
140
+ };
141
+ var toUpdatedAt = (value, fallback) => {
142
+ const asNumber = asOptionalPositiveFiniteNumber(value);
143
+ if (asNumber !== void 0) return asNumber;
144
+ if (typeof value === "string" && value.trim()) {
145
+ return asOptionalPositiveFiniteNumber(Date.parse(value)) ?? fallback;
146
+ }
147
+ return fallback;
148
+ };
149
+ var pairKey = (accountUserId, localDbKey) => `${accountUserId}\0${localDbKey}`;
150
+ function normalizeSyncMapping(input, now = Date.now()) {
151
+ const localDbKey = normalizeKey(input.localDbKey);
152
+ const remoteDbKey = normalizeKey(input.remoteDbKey);
153
+ const accountUserId = normalizeKey(input.accountUserId);
154
+ const contentType = normalizeContentType(input.contentType);
155
+ if (!localDbKey) {
156
+ throw new Error("syncMapping.localDbKey is required");
157
+ }
158
+ if (!remoteDbKey) {
159
+ throw new Error("syncMapping.remoteDbKey is required");
160
+ }
161
+ if (!accountUserId) {
162
+ throw new Error("syncMapping.accountUserId is required");
163
+ }
164
+ if (localDbKey === remoteDbKey) {
165
+ throw new Error("syncMapping.localDbKey and remoteDbKey must differ");
166
+ }
167
+ if (accountUserId === "local") {
168
+ throw new Error(
169
+ "syncMapping.accountUserId must be a non-local account user id"
170
+ );
171
+ }
172
+ return {
173
+ localDbKey,
174
+ remoteDbKey,
175
+ accountUserId,
176
+ contentType,
177
+ updatedAt: toUpdatedAt(input.updatedAt, now)
178
+ };
179
+ }
180
+ function createSyncMappingStore(options) {
181
+ const now = options?.now ?? Date.now;
182
+ const byPair = /* @__PURE__ */ new Map();
183
+ const remoteToPair = /* @__PURE__ */ new Map();
184
+ const forgetRemoteIndex = (mapping) => {
185
+ if (!mapping) return;
186
+ const current = remoteToPair.get(mapping.remoteDbKey);
187
+ if (current === pairKey(mapping.accountUserId, mapping.localDbKey)) {
188
+ remoteToPair.delete(mapping.remoteDbKey);
189
+ }
190
+ };
191
+ return {
192
+ put(input) {
193
+ const mapping = normalizeSyncMapping(input, now());
194
+ const key = pairKey(mapping.accountUserId, mapping.localDbKey);
195
+ const previousLocal = byPair.get(key);
196
+ if (previousLocal) {
197
+ forgetRemoteIndex(previousLocal);
198
+ }
199
+ const previousPairForRemote = remoteToPair.get(mapping.remoteDbKey);
200
+ if (previousPairForRemote && previousPairForRemote !== key) {
201
+ const displaced = byPair.get(previousPairForRemote);
202
+ if (displaced) {
203
+ byPair.delete(previousPairForRemote);
204
+ }
205
+ }
206
+ byPair.set(key, mapping);
207
+ remoteToPair.set(mapping.remoteDbKey, key);
208
+ return { ...mapping };
209
+ },
210
+ get(localDbKey, accountUserId) {
211
+ const local = normalizeKey(localDbKey);
212
+ if (!local) return null;
213
+ const account = normalizeKey(accountUserId);
214
+ if (account) {
215
+ const mapping = byPair.get(pairKey(account, local));
216
+ return mapping ? { ...mapping } : null;
217
+ }
218
+ let best = null;
219
+ for (const mapping of byPair.values()) {
220
+ if (mapping.localDbKey !== local) continue;
221
+ if (!best || mapping.updatedAt > best.updatedAt) {
222
+ best = mapping;
223
+ }
224
+ }
225
+ return best ? { ...best } : null;
226
+ },
227
+ getByRemoteDbKey(remoteDbKey, accountUserId) {
228
+ const key = normalizeKey(remoteDbKey);
229
+ if (!key) return null;
230
+ const pair = remoteToPair.get(key);
231
+ if (!pair) return null;
232
+ const mapping = byPair.get(pair);
233
+ if (!mapping) return null;
234
+ const account = normalizeKey(accountUserId);
235
+ if (account && mapping.accountUserId !== account) return null;
236
+ return { ...mapping };
237
+ },
238
+ list(filter) {
239
+ const accountUserId = normalizeKey(filter?.accountUserId);
240
+ const contentType = normalizeKey(filter?.contentType);
241
+ const rows = Array.from(byPair.values()).filter((mapping) => {
242
+ if (accountUserId && mapping.accountUserId !== accountUserId) {
243
+ return false;
244
+ }
245
+ if (contentType && mapping.contentType !== contentType) return false;
246
+ return true;
247
+ });
248
+ return rows.map((mapping) => ({ ...mapping })).sort(
249
+ (left, right) => right.updatedAt - left.updatedAt || left.localDbKey.localeCompare(right.localDbKey) || left.accountUserId.localeCompare(right.accountUserId)
250
+ );
251
+ },
252
+ remove(localDbKey, accountUserId) {
253
+ const local = normalizeKey(localDbKey);
254
+ if (!local) return false;
255
+ const account = normalizeKey(accountUserId);
256
+ if (account) {
257
+ const key = pairKey(account, local);
258
+ const existing = byPair.get(key);
259
+ if (!existing) return false;
260
+ byPair.delete(key);
261
+ forgetRemoteIndex(existing);
262
+ return true;
263
+ }
264
+ let removed = false;
265
+ for (const [key, mapping] of Array.from(byPair.entries())) {
266
+ if (mapping.localDbKey !== local) continue;
267
+ byPair.delete(key);
268
+ forgetRemoteIndex(mapping);
269
+ removed = true;
270
+ }
271
+ return removed;
272
+ },
273
+ clear() {
274
+ byPair.clear();
275
+ remoteToPair.clear();
276
+ },
277
+ size() {
278
+ return byPair.size;
279
+ }
280
+ };
281
+ }
282
+ var defaultSyncMappingStore = createSyncMappingStore();
283
+ var mappingVersion = 0;
284
+ var mappingListeners = /* @__PURE__ */ new Set();
285
+ var sameConsumerMapping = (a, b) => {
286
+ if (a === b) return true;
287
+ if (!a || !b) return false;
288
+ return a.localDbKey === b.localDbKey && a.remoteDbKey === b.remoteDbKey && a.accountUserId === b.accountUserId && a.contentType === b.contentType;
289
+ };
290
+ var notifySyncMappingListeners = () => {
291
+ mappingVersion += 1;
292
+ for (const listener of mappingListeners) {
293
+ try {
294
+ listener();
295
+ } catch {
296
+ }
297
+ }
298
+ };
299
+ function subscribeSyncMappingVersion(listener) {
300
+ mappingListeners.add(listener);
301
+ return () => {
302
+ mappingListeners.delete(listener);
303
+ };
304
+ }
305
+ function getSyncMappingVersion() {
306
+ return mappingVersion;
307
+ }
308
+ var boundClientDb = null;
309
+ var mappingsHydrated = false;
310
+ var hydrateEpoch = 0;
311
+ var hydrateInFlight = null;
312
+ function bindSyncMappingClientDb(db) {
313
+ boundClientDb = db;
314
+ mappingsHydrated = false;
315
+ hydrateEpoch += 1;
316
+ }
317
+ function getBoundSyncMappingClientDb() {
318
+ return boundClientDb;
319
+ }
320
+ async function ensureSyncMappingsHydrated(db) {
321
+ const client = db ?? boundClientDb;
322
+ if (!client) return false;
323
+ if (mappingsHydrated) return false;
324
+ if (hydrateInFlight && hydrateInFlight.epoch === hydrateEpoch) {
325
+ await hydrateInFlight.promise;
326
+ return false;
327
+ }
328
+ const epoch = hydrateEpoch;
329
+ const clientAtStart = client;
330
+ const promise = (async () => {
331
+ const rows = await loadSyncMappingsFromDb(clientAtStart);
332
+ if (epoch !== hydrateEpoch) {
333
+ return false;
334
+ }
335
+ const beforeSize = defaultSyncMappingStore.size();
336
+ defaultSyncMappingStore.clear();
337
+ for (const row of rows) {
338
+ try {
339
+ defaultSyncMappingStore.put(row);
340
+ } catch {
341
+ }
342
+ }
343
+ mappingsHydrated = true;
344
+ if (beforeSize > 0 || rows.length > 0 || defaultSyncMappingStore.size() > 0) {
345
+ notifySyncMappingListeners();
346
+ }
347
+ return true;
348
+ })();
349
+ hydrateInFlight = { epoch, promise };
350
+ try {
351
+ return await promise;
352
+ } finally {
353
+ if (hydrateInFlight?.promise === promise) {
354
+ hydrateInFlight = null;
355
+ }
356
+ }
357
+ }
358
+ function putSyncMapping(mapping) {
359
+ const account = normalizeKey(mapping.accountUserId);
360
+ const local = normalizeKey(mapping.localDbKey);
361
+ const previous = account && local ? defaultSyncMappingStore.get(local, account) : null;
362
+ const next = defaultSyncMappingStore.put(mapping);
363
+ if (!sameConsumerMapping(previous, next)) {
364
+ notifySyncMappingListeners();
365
+ }
366
+ return next;
367
+ }
368
+ async function putSyncMappingDurable(mapping) {
369
+ const normalized = normalizeSyncMapping(mapping);
370
+ if (!boundClientDb) {
371
+ throw new Error(
372
+ "putSyncMappingDurable requires a bound client DB; refuse silent memory-only durability"
373
+ );
374
+ }
375
+ await persistSyncMappingToDb(boundClientDb, normalized);
376
+ return putSyncMapping(normalized);
377
+ }
378
+ function getSyncMapping(localDbKey, accountUserId) {
379
+ return defaultSyncMappingStore.get(localDbKey, accountUserId);
380
+ }
381
+ function getSyncMappingByRemoteDbKey(remoteDbKey, accountUserId) {
382
+ return defaultSyncMappingStore.getByRemoteDbKey(remoteDbKey, accountUserId);
383
+ }
384
+ function listSyncMappings(filter) {
385
+ return defaultSyncMappingStore.list(filter);
386
+ }
387
+ function removeSyncMapping(localDbKey, accountUserId) {
388
+ const removed = defaultSyncMappingStore.remove(localDbKey, accountUserId);
389
+ if (removed) {
390
+ notifySyncMappingListeners();
391
+ }
392
+ return removed;
393
+ }
394
+ async function removeSyncMappingDurable(localDbKey, accountUserId) {
395
+ const account = normalizeKey(accountUserId);
396
+ const local = normalizeKey(localDbKey);
397
+ if (!account || !local) return false;
398
+ if (boundClientDb) {
399
+ await removeSyncMappingFromDb(boundClientDb, account, local);
400
+ }
401
+ return removeSyncMapping(local, account);
402
+ }
403
+ function clearSyncMappings() {
404
+ const hadRows = defaultSyncMappingStore.size() > 0;
405
+ defaultSyncMappingStore.clear();
406
+ mappingsHydrated = false;
407
+ hydrateEpoch += 1;
408
+ if (hadRows) {
409
+ notifySyncMappingListeners();
410
+ }
411
+ }
412
+ function getDefaultSyncMappingStore() {
413
+ return defaultSyncMappingStore;
414
+ }
415
+ function areSyncMappingsHydrated() {
416
+ return mappingsHydrated;
417
+ }
418
+
419
+ export {
420
+ normalizeSyncMapping,
421
+ createSyncMappingStore,
422
+ subscribeSyncMappingVersion,
423
+ getSyncMappingVersion,
424
+ bindSyncMappingClientDb,
425
+ getBoundSyncMappingClientDb,
426
+ ensureSyncMappingsHydrated,
427
+ putSyncMapping,
428
+ putSyncMappingDurable,
429
+ getSyncMapping,
430
+ getSyncMappingByRemoteDbKey,
431
+ listSyncMappings,
432
+ removeSyncMapping,
433
+ removeSyncMappingDurable,
434
+ clearSyncMappings,
435
+ getDefaultSyncMappingStore,
436
+ areSyncMappingsHydrated
437
+ };
@@ -2,7 +2,7 @@ import {
2
2
  deleteDbRecord,
3
3
  queryUserRecords,
4
4
  readDbRecord
5
- } from "./chunk-V42OE5HT.js";
5
+ } from "./chunk-YDTYDA5W.js";
6
6
  import {
7
7
  mergeAndDedupUserData
8
8
  } from "./chunk-KQHGZWSV.js";
@@ -1,10 +1,7 @@
1
1
  import {
2
2
  readDbRecord,
3
3
  writeAgentRecord
4
- } from "./chunk-V42OE5HT.js";
5
- import {
6
- createSpaceKey
7
- } from "./chunk-V54H24CQ.js";
4
+ } from "./chunk-YDTYDA5W.js";
8
5
  import {
9
6
  buildSkillSummaryMarker
10
7
  } from "./chunk-VF4K2QE6.js";
@@ -14,6 +11,9 @@ import {
14
11
  resolveAuthToken,
15
12
  resolveServerUrl
16
13
  } from "./chunk-A7GB5UGH.js";
14
+ import {
15
+ createSpaceKey
16
+ } from "./chunk-JTSGWTYZ.js";
17
17
  import {
18
18
  asTrimmedLowercaseString
19
19
  } from "./chunk-QSJ3HFEF.js";