nolo-cli 0.16.0-alpha.2 → 0.16.0-alpha.21

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 (136) hide show
  1. package/{_executeModel-QAUS6B7J.js → _executeModel-GRCQXT5R.js} +51 -45
  2. package/{action-GUOZYYGN.js → action-LT7BRFLK.js} +10 -9
  3. package/{addContentAction-QDGHGUBH.js → addContentAction-PL3KKBDH.js} +9 -8
  4. package/{addDialogAgentAction-Z4YCYZIV.js → addDialogAgentAction-FCMSKYAF.js} +8 -7
  5. package/{agentDeleteCommand-365DMKHW.js → agentDeleteCommand-WNL3CNQX.js} +32 -29
  6. package/{agentEmailCommands-TQMXL36I.js → agentEmailCommands-MPEUMRAS.js} +63 -57
  7. package/{agentListCommands-6B5X4RC6.js → agentListCommands-YO4AOQMS.js} +31 -28
  8. package/{agentMachineCommands-LOEARB6V.js → agentMachineCommands-WYM6YRYJ.js} +30 -27
  9. package/{agentPullCommand-6HWUT3SW.js → agentPullCommand-ZZGU5KOY.js} +4 -4
  10. package/agentRecordCommands-BVWSHMIY.js +105 -0
  11. package/{agentRunCommand-SGMH67WT.js → agentRunCommand-E3ZI6RSF.js} +64 -55
  12. package/{agentRunControl-6ADXVYMR.js → agentRunControl-Y5AFH5PQ.js} +24 -1
  13. package/{agentRuntimeLocal-YSYZ33ER.js → agentRuntimeLocal-P4VGX6H6.js} +26 -25
  14. package/{agentSlice-IVE735EV.js → agentSlice-D33GU3JL.js} +9 -8
  15. package/{appDeleteCommands-6QYOO3JB.js → appDeleteCommands-VA4R2SWX.js} +29 -26
  16. package/{appDeployCommands-WTCT6XO6.js → appDeployCommands-JWMWQNG6.js} +29 -26
  17. package/{appDeployStatusCommands-CGWGZJKB.js → appDeployStatusCommands-KYXGLZSQ.js} +29 -26
  18. package/{appGetCommands-O4OCAMRW.js → appGetCommands-ELOO3JG6.js} +29 -26
  19. package/{appListCommands-UENFP4XY.js → appListCommands-SJUW4RLW.js} +29 -26
  20. package/{authCommand-YFTR3347.js → authCommand-WJZPOLSS.js} +16 -9
  21. package/{authCommands-YXGOXNBZ.js → authCommands-XTBV7OFZ.js} +6 -5
  22. package/{chunk-RKM3K52F.js → chunk-34WPV75U.js} +23 -2
  23. package/{chunk-VPTJB4HM.js → chunk-3ND52WIL.js} +2 -5
  24. package/{chunk-SOTZ6RDN.js → chunk-3Q7WHGCB.js} +1 -1
  25. package/{chunk-KKY4B2Q2.js → chunk-4PWB7JRR.js} +4 -1
  26. package/{chunk-U7LEGLEB.js → chunk-4T5F7YZQ.js} +1 -1
  27. package/{chunk-OQMPU2ML.js → chunk-5PGGCJGV.js} +6 -6
  28. package/chunk-7BUYEZ6U.js +671 -0
  29. package/{chunk-AS3ZQ3O2.js → chunk-7OBMZCRD.js} +1 -1
  30. package/{chunk-WA6KZL5V.js → chunk-AAODAAUQ.js} +23 -20
  31. package/{chunk-GRTFNYLR.js → chunk-AKVLLMOU.js} +3 -3
  32. package/{chunk-QLUFR47U.js → chunk-AL2V7U3E.js} +1 -1
  33. package/{chunk-MTU75CZ2.js → chunk-B5TOXZAK.js} +1 -1
  34. package/{chunk-QZVGMD5F.js → chunk-BE2GNT5E.js} +2 -8
  35. package/{chunk-JKWWVF2I.js → chunk-D3HVJJIA.js} +1 -1
  36. package/{chunk-B4KT7RN2.js → chunk-DKZFOK24.js} +18 -89
  37. package/chunk-DL6EPNIK.js +50 -0
  38. package/{chunk-YYIRR6QC.js → chunk-E5KQTMMJ.js} +212 -250
  39. package/{chunk-4QQFLN5C.js → chunk-EGPCU42M.js} +58 -8
  40. package/{chunk-XVP3C2KY.js → chunk-ELT65PZW.js} +2 -2
  41. package/{chunk-EMXI3N3Z.js → chunk-ENP2ELIL.js} +5 -5
  42. package/{chunk-6565R2TI.js → chunk-EXAEHRLI.js} +112 -191
  43. package/chunk-FQZZLA3C.js +223 -0
  44. package/{chunk-WPN6RMDF.js → chunk-GMZZ5EKJ.js} +3 -3
  45. package/{chunk-RSYUDGGZ.js → chunk-HQNPCMWL.js} +3 -3
  46. package/{chunk-OGGHETUE.js → chunk-HQPG2PIV.js} +62 -19
  47. package/{chunk-4NLUNENX.js → chunk-IQZ6TGVW.js} +10 -3
  48. package/{chunk-VE6XMVKG.js → chunk-J67FKTTY.js} +330 -213
  49. package/{chunk-G2MKOQCB.js → chunk-JFE7XW4D.js} +1 -1
  50. package/{setDialogExtraReferencesAction-2VLGWQKG.js → chunk-JLA4FXYC.js} +2 -17
  51. package/{chunk-OOIN7HSO.js → chunk-JP7REMYP.js} +19 -1
  52. package/chunk-KFEVY3ST.js +255 -0
  53. package/{chunk-I66RU7P7.js → chunk-KKWJ5VPZ.js} +1 -1
  54. package/{chunk-WRN5EQT7.js → chunk-L2RRMXNJ.js} +13 -4
  55. package/{chunk-ISYE6GZB.js → chunk-L6NVTGI7.js} +1 -1
  56. package/{chunk-HRQCKQA5.js → chunk-MUCU6ATG.js} +8 -257
  57. package/{chunk-BFRVXJJJ.js → chunk-MUIT5AAM.js} +112 -27
  58. package/{chunk-WNLPAOIT.js → chunk-MVQ4TBSD.js} +1 -1
  59. package/{chunk-O53CP2QR.js → chunk-N2HYIBLH.js} +6 -6
  60. package/{chunk-524BDL33.js → chunk-O6W2O2DA.js} +1 -15
  61. package/{chunk-YC3DJILJ.js → chunk-PUSK7HXJ.js} +64 -22
  62. package/{chunk-OOSFSFMA.js → chunk-R5V5G73M.js} +2 -0
  63. package/{chunk-4IJYA27C.js → chunk-RG2U2MTJ.js} +1 -1
  64. package/{chunk-Z24FGIU2.js → chunk-RIDWN7AP.js} +34 -15
  65. package/{chunk-IKXL2HZ3.js → chunk-RK5NYQEL.js} +1 -1
  66. package/{chunk-QLFCNUVQ.js → chunk-RUTSBLDM.js} +1629 -261
  67. package/{chunk-TTGAVETO.js → chunk-RVOUXDFU.js} +5 -5
  68. package/{chunk-JTINRTBT.js → chunk-SKDNBYZK.js} +2 -2
  69. package/{chunk-KMQPSTMJ.js → chunk-TRT4I4UD.js} +2 -2
  70. package/{chunk-EHLHSX7R.js → chunk-UB4RYYNQ.js} +9 -2
  71. package/{chunk-N5424GSW.js → chunk-UGUW3FHG.js} +4 -4
  72. package/{chunk-YNHQIXX5.js → chunk-UIOYWBU7.js} +395 -326
  73. package/chunk-V5R4NZP2.js +78 -0
  74. package/{chunk-MYMMNKYL.js → chunk-VNAEBGDK.js} +156 -6
  75. package/{chunk-J55UHASN.js → chunk-VST53WEL.js} +1 -1
  76. package/{chunk-6MHDWKOT.js → chunk-VVKQFITN.js} +25 -12
  77. package/{chunk-W4NVOSFF.js → chunk-WFHXMLHZ.js} +1 -1
  78. package/{chunk-H33743XH.js → chunk-WJRJDX2W.js} +1 -1
  79. package/chunk-X4Q4UZEY.js +26 -0
  80. package/{chunk-E237VE6U.js → chunk-XFYDGBXL.js} +4 -4
  81. package/{chunk-JS33TCQ3.js → chunk-XHG22OEX.js} +4 -4
  82. package/{chunk-DVRHHFEA.js → chunk-XMLRJUU5.js} +1 -1
  83. package/{chunk-V2J635L5.js → chunk-XOIF2TNF.js} +2 -2
  84. package/{chunk-SFXYKGK2.js → chunk-XRZJGPFI.js} +7 -7
  85. package/chunk-ZHXJ6M7T.js +27 -0
  86. package/chunk-ZZ2MH7LE.js +84 -0
  87. package/{cliExecutor-K3F7DMRO.js → cliExecutor-DNE7TCC4.js} +2 -2
  88. package/codingSkills-36KN5NQT.js +48 -0
  89. package/{createAgentAutomationAction-TS6NNZ4X.js → createAgentAutomationAction-ONKZ46XE.js} +22 -21
  90. package/{createDialogAction-5HVQ33EX.js → createDialogAction-7QWJEBKU.js} +24 -23
  91. package/{createPageAction-4F3ZGQJD.js → createPageAction-PB3KXZIA.js} +28 -27
  92. package/{dbSlice-OP6UPXKA.js → dbSlice-CGSRFJN3.js} +8 -7
  93. package/{deleteFile-WPWVZE4B.js → deleteFile-WDZ3VM7B.js} +3 -3
  94. package/{dialogCommands-ZL6L24BS.js → dialogCommands-YZFU4Q26.js} +30 -27
  95. package/{dialogSlice-FAWUQDJW.js → dialogSlice-53B5ISGQ.js} +22 -21
  96. package/{docCreateCommands-LYROQTFH.js → docCreateCommands-LOUC5PFB.js} +28 -25
  97. package/{docDeleteCommands-6TWGTZNR.js → docDeleteCommands-HHPGT4BR.js} +29 -26
  98. package/{docReadCommands-PRULNF26.js → docReadCommands-YPSN4HEF.js} +28 -25
  99. package/{docStore-2UHVWLTV.js → docStore-LJXXRB5W.js} +23 -22
  100. package/{docUpdateCommands-NNYYWJBI.js → docUpdateCommands-CJCZO54M.js} +28 -25
  101. package/{fetchMessages-KTNM7QAR.js → fetchMessages-BMGVZVSE.js} +4 -3
  102. package/{getPricing-UGDJHI7M.js → getPricing-RYY6OBA4.js} +4 -4
  103. package/handleSendMessageAction-ICGX4QCM.js +402 -0
  104. package/index.js +68 -68
  105. package/{localDialogRead-2VRI24F4.js → localDialogRead-HQZPVIE3.js} +1 -1
  106. package/{localRuntimeDb-LGDF6FQP.js → localRuntimeDb-THJZGAOJ.js} +1 -1
  107. package/{machineCommands-JQPEQFSE.js → machineCommands-YLDZXK4D.js} +64 -58
  108. package/{machineWsRunDispatch-FFFNWVEW.js → machineWsRunDispatch-LTQL3DRE.js} +56 -50
  109. package/{models-LSCRJJ6P.js → models-5K5G2CZI.js} +2 -2
  110. package/package.json +1 -1
  111. package/queryRunOverlay-O4LOMMPO.js +161 -0
  112. package/{read-HXHAZBKH.js → read-3FMPZPER.js} +3 -3
  113. package/{readDocTool-VPBDTO4G.js → readDocTool-VSYHKK3V.js} +1 -1
  114. package/{readlineWorkspace-QSXHSBHA.js → readlineWorkspace-OSPVWNAT.js} +699 -168
  115. package/{removeDialogAgentAction-HUFVN35S.js → removeDialogAgentAction-OAGA2G3U.js} +11 -10
  116. package/{runAgentClientLoop-A75BUU6D.js → runAgentClientLoop-76SUKKPX.js} +46 -40
  117. package/runOverlayPresentation-ZO4VCWEU.js +11 -0
  118. package/{runtimeDoctorCommands-THIHX2SY.js → runtimeDoctorCommands-E2OUORHK.js} +6 -6
  119. package/setDialogExtraReferencesAction-JZEXA5SL.js +27 -0
  120. package/{setPrimaryDialogAgentAction-VB4UV2CC.js → setPrimaryDialogAgentAction-4ZUQQKDG.js} +27 -18
  121. package/{settingSlice-7JYPQNAC.js → settingSlice-7MNKHZ6R.js} +9 -8
  122. package/{skillDiscovery-6M2BZUFN.js → skillDiscovery-KJWT7JBU.js} +3 -3
  123. package/{spaceCommands-4LE45GB7.js → spaceCommands-GIF7MKVD.js} +31 -28
  124. package/{spaceSlice-444MFUP6.js → spaceSlice-M4PVN5PO.js} +22 -21
  125. package/{streamAgentChatTurn-DJAE7USZ.js → streamAgentChatTurn-GCKTFSHQ.js} +96 -55
  126. package/{tableCommands-3P7MJ3PF.js → tableCommands-BEQAGE4I.js} +1 -1
  127. package/{tools-YB6LXSVN.js → tools-RJVFXOLR.js} +35 -30
  128. package/{tuiSummaryLlmCaller-QQL3JA5I.js → tuiSummaryLlmCaller-VUNVBRX3.js} +7 -6
  129. package/types-ZSTJ7MPR.js +7 -0
  130. package/{updateDialogTitleAction-6HGFBM64.js → updateDialogTitleAction-PSR67DLV.js} +25 -24
  131. package/agentRecordCommands-DCH2WBL2.js +0 -99
  132. package/chunk-BYXBJQAS.js +0 -0
  133. package/handleSendMessageAction-LJPUYNOH.js +0 -215
  134. package/{chunk-O4BU24WZ.js → chunk-6Y7A3OQQ.js} +3 -3
  135. package/{chunk-CMKUBIGW.js → chunk-X7W4TNB4.js} +3 -3
  136. package/{localRuntimeAuthority-TEGCOWX4.js → localRuntimeAuthority-4IXJCHZ7.js} +3 -3
@@ -0,0 +1,402 @@
1
+ import {
2
+ messageStreamEnd,
3
+ prepareAndPersistUserMessage,
4
+ resolveHandleSendMessageContext
5
+ } from "./chunk-UIOYWBU7.js";
6
+ import "./chunk-XOIF2TNF.js";
7
+ import "./chunk-B5TOXZAK.js";
8
+ import "./chunk-MRC4Q34M.js";
9
+ import {
10
+ streamAgentChatTurn
11
+ } from "./chunk-5PGGCJGV.js";
12
+ import "./chunk-CWMSB67P.js";
13
+ import "./chunk-XHG22OEX.js";
14
+ import "./chunk-Z4NR32XR.js";
15
+ import "./chunk-M76ECQRD.js";
16
+ import "./chunk-3Q7WHGCB.js";
17
+ import "./chunk-EGPCU42M.js";
18
+ import "./chunk-5MMAK75Q.js";
19
+ import "./chunk-5CS33IBL.js";
20
+ import "./chunk-JZPBVBIY.js";
21
+ import "./chunk-HQPG2PIV.js";
22
+ import "./chunk-ZHXJ6M7T.js";
23
+ import "./chunk-HNMXYYJR.js";
24
+ import "./chunk-ELT65PZW.js";
25
+ import {
26
+ extractCustomId
27
+ } from "./chunk-DFFIZ25G.js";
28
+ import {
29
+ getActiveDialogKey
30
+ } from "./chunk-3ASDTTEI.js";
31
+ import "./chunk-DWLEOOGR.js";
32
+ import "./chunk-RK5NYQEL.js";
33
+ import "./chunk-O6W2O2DA.js";
34
+ import "./chunk-RVOUXDFU.js";
35
+ import "./chunk-Y5GCAMGP.js";
36
+ import "./chunk-KX6YBIHG.js";
37
+ import {
38
+ readAndWait,
39
+ selectById
40
+ } from "./chunk-XRZJGPFI.js";
41
+ import {
42
+ createDialogMessageKeyAndId
43
+ } from "./chunk-6Y7A3OQQ.js";
44
+ import "./chunk-WWC7I6TA.js";
45
+ import "./chunk-SKDNBYZK.js";
46
+ import "./chunk-I42VC5KR.js";
47
+ import "./chunk-QSJ3HFEF.js";
48
+ import "./chunk-X4Q4UZEY.js";
49
+ import "./chunk-3ND52WIL.js";
50
+ import "./chunk-XMLRJUU5.js";
51
+ import "./chunk-R5V5G73M.js";
52
+ import "./chunk-GBRG75BQ.js";
53
+ import "./chunk-3EUW3WEO.js";
54
+ import "./chunk-U6VC4MU4.js";
55
+ import "./chunk-KUG52IAP.js";
56
+ import "./chunk-LCBAMY2M.js";
57
+ import "./chunk-4SN6J65J.js";
58
+ import "./chunk-CF7PE763.js";
59
+ import "./chunk-G3SUCT4W.js";
60
+ import "./chunk-4VNS5WPM.js";
61
+
62
+ // packages/chat/dialog/actions/parseOAuthError.ts
63
+ var PROVIDER_NAMES = {
64
+ antigravity: "Antigravity (Google)",
65
+ claude: "Claude",
66
+ chatgpt: "ChatGPT",
67
+ xai: "xAI Grok",
68
+ cursor: "Cursor",
69
+ cloudflare: "Cloudflare"
70
+ };
71
+ function asRecord(value) {
72
+ if (value && typeof value === "object" && !Array.isArray(value)) {
73
+ return value;
74
+ }
75
+ return null;
76
+ }
77
+ function asString(value) {
78
+ return typeof value === "string" && value.length > 0 ? value : void 0;
79
+ }
80
+ function collectValidationFromDetails(details) {
81
+ if (!Array.isArray(details)) return {};
82
+ let url;
83
+ let text;
84
+ let learnMoreUrl;
85
+ for (const detail of details) {
86
+ const rec = asRecord(detail);
87
+ if (!rec) continue;
88
+ const metadata = asRecord(rec.metadata);
89
+ if (metadata) {
90
+ url = url ?? asString(metadata.validation_url);
91
+ text = text ?? asString(metadata.validation_url_link_text);
92
+ learnMoreUrl = learnMoreUrl ?? asString(metadata.validation_learn_more_url);
93
+ }
94
+ const help = asRecord(rec);
95
+ if (Array.isArray(help.links)) {
96
+ for (const link of help.links) {
97
+ const linkRec = asRecord(link);
98
+ if (!linkRec) continue;
99
+ const linkUrl = asString(linkRec.url);
100
+ if (!linkUrl) continue;
101
+ const desc = asString(linkRec.description);
102
+ if (!url && desc && /verify|continue/i.test(desc)) {
103
+ url = linkUrl;
104
+ text = desc;
105
+ } else if (!learnMoreUrl && /learn more/i.test(desc ?? "")) {
106
+ learnMoreUrl = linkUrl;
107
+ }
108
+ }
109
+ }
110
+ }
111
+ return { url, text, learnMoreUrl };
112
+ }
113
+ function parseSendError(errorMessage) {
114
+ const summary = errorMessage.replace(/^local\s+/, "").split("\n")[0].trim();
115
+ const providerMatch = errorMessage.match(/local\s+(\w+)\s+OAuth provider failed/i);
116
+ const providerName = providerMatch ? PROVIDER_NAMES[providerMatch[1].toLowerCase()] ?? providerMatch[1] : void 0;
117
+ const statusMatch = errorMessage.match(/HTTP\s+(\d{3})/);
118
+ const status = statusMatch?.[1];
119
+ const jsonStart = errorMessage.indexOf("{");
120
+ let payload = null;
121
+ if (jsonStart >= 0) {
122
+ let candidate = errorMessage.slice(jsonStart);
123
+ for (let depth = 0; depth < 3; depth += 1) {
124
+ try {
125
+ const parsed = JSON.parse(candidate);
126
+ payload = parsed;
127
+ const message = asString(parsed?.error?.message);
128
+ if (message && message.trim().startsWith("{")) {
129
+ candidate = message;
130
+ continue;
131
+ }
132
+ break;
133
+ } catch {
134
+ break;
135
+ }
136
+ }
137
+ }
138
+ const errorRec = payload ? asRecord(payload.error) : null;
139
+ const innerMessage = errorRec ? asString(errorRec.message) : void 0;
140
+ const statusFromBody = errorRec ? asString(errorRec.status) : void 0;
141
+ const details = errorRec?.details;
142
+ const { url, text, learnMoreUrl } = collectValidationFromDetails(details);
143
+ let reason = errorRec ? asString(errorRec.reason) : void 0;
144
+ let domain = errorRec ? asString(errorRec.domain) : void 0;
145
+ if (!reason && Array.isArray(details)) {
146
+ const first = asRecord(details[0]);
147
+ reason = first ? asString(first.reason) : void 0;
148
+ domain = first ? asString(first.domain) : void 0;
149
+ }
150
+ const parts = [];
151
+ const head = providerName ? `${providerName} \u8FDE\u63A5\u5931\u8D25` : "\u53D1\u9001\u5931\u8D25";
152
+ parts.push(
153
+ `${head}${status ? ` (HTTP ${status})` : ""}${statusFromBody ? ` ${statusFromBody}` : ""}`
154
+ );
155
+ if (reason) {
156
+ parts.push(`\u539F\u56E0\uFF1A${reason}`);
157
+ }
158
+ if (domain) {
159
+ parts.push(`\u670D\u52A1\uFF1A${domain}`);
160
+ }
161
+ const humanMessage = innerMessage && innerMessage.trim() !== "Verify your account to continue." ? innerMessage : void 0;
162
+ if (humanMessage) {
163
+ parts.push(`\u63D0\u793A\uFF1A${humanMessage}`);
164
+ }
165
+ const extraLinks = [];
166
+ if (learnMoreUrl) {
167
+ extraLinks.push({ text: "\u4E86\u89E3\u66F4\u591A", url: learnMoreUrl });
168
+ }
169
+ if (url) {
170
+ return {
171
+ summary: parts.join("\n"),
172
+ validationUrl: url,
173
+ validationLinkText: text ?? "\u9A8C\u8BC1\u6211\u7684\u8D26\u53F7",
174
+ extraLinks
175
+ };
176
+ }
177
+ const MAX_FALLBACK = 500;
178
+ const fallbackText = errorMessage.length > MAX_FALLBACK ? `${errorMessage.slice(0, MAX_FALLBACK)}\u2026` : errorMessage;
179
+ return { summary: parts.join("\n"), extraLinks, fallbackText };
180
+ }
181
+ function buildSendErrorMessageMarkdown(parsed) {
182
+ const lines = ["[\u53D1\u9001\u5931\u8D25]", "", parsed.summary];
183
+ if (parsed.validationUrl) {
184
+ lines.push(
185
+ "",
186
+ `\u8BF7\u70B9\u51FB\u94FE\u63A5\u5B8C\u6210\u9A8C\u8BC1\uFF1A`,
187
+ `- [${parsed.validationLinkText ?? "\u9A8C\u8BC1\u6211\u7684\u8D26\u53F7"}](${parsed.validationUrl})`
188
+ );
189
+ }
190
+ for (const link of parsed.extraLinks) {
191
+ lines.push(`- [${link.text}](${link.url})`);
192
+ }
193
+ if (parsed.fallbackText && !parsed.validationUrl) {
194
+ lines.push("", "```", parsed.fallbackText, "```");
195
+ }
196
+ return lines.join("\n");
197
+ }
198
+
199
+ // packages/chat/dialog/actions/handleSendMessageAction.ts
200
+ var getDialogConfig = (state, dialogKey) => {
201
+ const resolvedDialogKey = dialogKey ?? getActiveDialogKey();
202
+ if (!resolvedDialogKey) return null;
203
+ const dialog = selectById(state, resolvedDialogKey);
204
+ return dialog ?? null;
205
+ };
206
+ var ensureDialogConfig = async (dispatch, getState, dialogKey) => {
207
+ const state = getState();
208
+ const resolvedDialogKey = dialogKey ?? getActiveDialogKey();
209
+ if (!resolvedDialogKey) return null;
210
+ try {
211
+ const existingDialog = getDialogConfig(state, resolvedDialogKey);
212
+ if (existingDialog && Array.isArray(existingDialog.cybots) && existingDialog.cybots.length > 0) {
213
+ return existingDialog;
214
+ }
215
+ const persistedDialog = await dispatch(readAndWait(resolvedDialogKey)).unwrap();
216
+ if (persistedDialog) return persistedDialog;
217
+ return existingDialog;
218
+ } catch {
219
+ return getDialogConfig(getState(), resolvedDialogKey);
220
+ }
221
+ };
222
+ var logQuickChatPerfStage = (startedAt, stage, details = {}) => {
223
+ if (!startedAt) return;
224
+ const now = typeof performance !== "undefined" ? performance.now() : Date.now();
225
+ console.info("[QuickChatPerf]", {
226
+ stage,
227
+ elapsedMs: now - startedAt,
228
+ ...typeof performance !== "undefined" ? { atMs: now } : {},
229
+ ...details
230
+ });
231
+ };
232
+ var resolveBrowseContextPrefix = async (message) => {
233
+ try {
234
+ if (typeof window === "undefined" || typeof location === "undefined") return "";
235
+ if (typeof process !== "undefined" && (process.env?.NODE_ENV === "test" || process.env?.BUN_TEST)) return "";
236
+ const host = location.hostname;
237
+ if (host !== "127.0.0.1" && host !== "localhost") return "";
238
+ if (typeof fetch !== "function" || typeof AbortSignal?.timeout !== "function") return "";
239
+ const response = await fetch("/api/desktop/browse-context", {
240
+ method: "POST",
241
+ headers: { "Content-Type": "application/json" },
242
+ body: JSON.stringify({ message }),
243
+ signal: AbortSignal.timeout(2e3)
244
+ });
245
+ if (!response.ok) return "";
246
+ const payload = await response.json();
247
+ if (!payload.context || !payload.context.url) return "";
248
+ const ctx = payload.context;
249
+ const parts = [`[\u5F53\u524D\u6D4F\u89C8\u4E0A\u4E0B\u6587]`, `URL: ${ctx.url}`, `\u6807\u9898: ${ctx.title}`];
250
+ if (ctx.textSnippet) parts.push(`\u6458\u8981: ${ctx.textSnippet.slice(0, 2e3)}`);
251
+ return parts.join("\n");
252
+ } catch {
253
+ return "";
254
+ }
255
+ };
256
+ var finalizeQuickChatStreamStartupFailure = async (dispatch, dialogConfig, agentKey) => {
257
+ const dialogKey = dialogConfig.dbKey;
258
+ const dialogId = dialogConfig.id ?? (dialogKey ? extractCustomId(dialogKey) : "");
259
+ const { key: msgKey, messageId } = createDialogMessageKeyAndId(dialogId);
260
+ await dispatch(
261
+ messageStreamEnd({
262
+ finalContentBuffer: [
263
+ {
264
+ type: "text",
265
+ text: "[\u9519\u8BEF: \u672A\u80FD\u542F\u52A8\u6A21\u578B\u56DE\u590D\uFF0C\u8BF7\u91CD\u8BD5\u3002]"
266
+ }
267
+ ],
268
+ totalUsage: null,
269
+ msgKey,
270
+ agentConfig: {
271
+ dbKey: agentKey
272
+ },
273
+ dialogId,
274
+ dialogKey: dialogKey ?? "",
275
+ messageId,
276
+ reasoningBuffer: ""
277
+ })
278
+ ).unwrap?.();
279
+ };
280
+ var buildActionableErrorText = (errorMessage) => {
281
+ return buildSendErrorMessageMarkdown(parseSendError(errorMessage));
282
+ };
283
+ var finalizeSendFailureInDialog = async (dispatch, dialogConfig, agentKey, errorMessage) => {
284
+ const dialogKey = dialogConfig.dbKey;
285
+ const dialogId = dialogConfig.id ?? (dialogKey ? extractCustomId(dialogKey) : "");
286
+ const { key: msgKey, messageId } = createDialogMessageKeyAndId(dialogId);
287
+ await dispatch(
288
+ messageStreamEnd({
289
+ finalContentBuffer: [
290
+ {
291
+ type: "text",
292
+ text: `[\u53D1\u9001\u5931\u8D25]
293
+
294
+ ${buildActionableErrorText(errorMessage)}`
295
+ }
296
+ ],
297
+ totalUsage: null,
298
+ msgKey,
299
+ agentConfig: {
300
+ dbKey: agentKey
301
+ },
302
+ dialogId,
303
+ dialogKey: dialogKey ?? "",
304
+ messageId,
305
+ reasoningBuffer: ""
306
+ })
307
+ ).unwrap?.();
308
+ };
309
+ var handleSendMessageAction = async (args, { dispatch, getState, rejectWithValue }) => {
310
+ let dialogConfig = null;
311
+ let agentKeyToUse;
312
+ try {
313
+ logQuickChatPerfStage(args.quickChatPerfStartedAt, "handle-send-message-entered", {
314
+ dialogKey: args.dialogKey ?? null
315
+ });
316
+ dialogConfig = await ensureDialogConfig(dispatch, getState, args.dialogKey);
317
+ if (!dialogConfig) {
318
+ throw new Error(
319
+ "handleSendMessage: Dialog configuration is missing."
320
+ );
321
+ }
322
+ logQuickChatPerfStage(args.quickChatPerfStartedAt, "handle-send-message-dialog-ready", {
323
+ dialogKey: dialogConfig.dbKey,
324
+ cybotCount: dialogConfig.cybots?.length ?? 0
325
+ });
326
+ await dispatch(
327
+ prepareAndPersistUserMessage({
328
+ userInput: args.userInput,
329
+ dialogConfig
330
+ })
331
+ ).unwrap();
332
+ logQuickChatPerfStage(args.quickChatPerfStartedAt, "handle-send-message-user-persisted", {
333
+ dialogKey: dialogConfig.dbKey
334
+ });
335
+ const resolvedContext = resolveHandleSendMessageContext({
336
+ dialogConfig,
337
+ targetAgentKey: args.targetAgentKey,
338
+ runtimeOptions: args.runtimeOptions
339
+ });
340
+ agentKeyToUse = resolvedContext.agentKeyToUse;
341
+ const effectiveRuntimeOptions = resolvedContext.effectiveRuntimeOptions;
342
+ if (!agentKeyToUse) {
343
+ return;
344
+ }
345
+ const userInputText = typeof args.userInput === "string" ? args.userInput : "";
346
+ const isDesktopContext = typeof window !== "undefined" && typeof location !== "undefined" && (location.hostname === "127.0.0.1" || location.hostname === "localhost");
347
+ const browseContextPrefix = isDesktopContext ? await resolveBrowseContextPrefix(userInputText) : "";
348
+ const effectiveUserInput = browseContextPrefix ? `${browseContextPrefix}
349
+
350
+ ${userInputText}` : args.userInput;
351
+ const streamResult = await dispatch(
352
+ streamAgentChatTurn({
353
+ agentKey: agentKeyToUse,
354
+ userInput: effectiveUserInput,
355
+ dialogKey: dialogConfig.dbKey,
356
+ parentMessageId: void 0,
357
+ runtimeOptions: effectiveRuntimeOptions,
358
+ quickChatPerfStartedAt: args.quickChatPerfStartedAt
359
+ })
360
+ ).unwrap();
361
+ if (args.quickChatPerfStartedAt && streamResult === void 0) {
362
+ logQuickChatPerfStage(args.quickChatPerfStartedAt, "handle-send-message-stream-empty", {
363
+ dialogKey: dialogConfig.dbKey,
364
+ agentKey: agentKeyToUse
365
+ });
366
+ await finalizeQuickChatStreamStartupFailure(
367
+ dispatch,
368
+ dialogConfig,
369
+ agentKeyToUse
370
+ );
371
+ return;
372
+ }
373
+ logQuickChatPerfStage(args.quickChatPerfStartedAt, "handle-send-message-stream-finished", {
374
+ dialogKey: dialogConfig.dbKey,
375
+ agentKey: agentKeyToUse
376
+ });
377
+ return;
378
+ } catch (error) {
379
+ console.error("handleSendMessage failed:", error);
380
+ const errorMessage = error instanceof Error ? error.message : typeof error === "string" ? error : error?.message || error?.error || String(error);
381
+ try {
382
+ if (dialogConfig && agentKeyToUse) {
383
+ await finalizeSendFailureInDialog(
384
+ dispatch,
385
+ dialogConfig,
386
+ agentKeyToUse,
387
+ errorMessage
388
+ );
389
+ return rejectWithValue({
390
+ __errorInDialog: true,
391
+ message: errorMessage
392
+ });
393
+ }
394
+ } catch (writeError) {
395
+ console.error("handleSendMessage: failed to write error into dialog:", writeError);
396
+ }
397
+ return rejectWithValue(errorMessage);
398
+ }
399
+ };
400
+ export {
401
+ handleSendMessageAction
402
+ };