nolo-cli 0.54.0 → 0.61.0-alpha.3
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.
- package/README.md +3 -3
- package/{_executeModel-OPTKYHJA.js → _executeModel-R26QYY66.js} +50 -46
- package/{action-ORXWW2ZG.js → action-76JX3JX3.js} +7 -6
- package/{addContentAction-53BZ34AE.js → addContentAction-V3NAZRTJ.js} +6 -5
- package/{addDialogAgentAction-JRYUS54Y.js → addDialogAgentAction-RZOAF46K.js} +5 -4
- package/{agentDeleteCommand-FJIWU2BS.js → agentDeleteCommand-6GNQA4J4.js} +30 -27
- package/{agentEmailCommands-CE32L43B.js → agentEmailCommands-HH67CYKD.js} +61 -57
- package/{agentGrantCommands-2LEZDADN.js → agentGrantCommands-R3VQEZJR.js} +1 -1
- package/{agentListCommands-VJNKULIK.js → agentListCommands-23XW3OPZ.js} +61 -31
- package/{agentMachineCommands-HCJ3WQXL.js → agentMachineCommands-HXHASEWO.js} +31 -28
- package/{agentPullCommand-M552CYSI.js → agentPullCommand-N7L2CT7L.js} +2 -2
- package/{agentRecordCommands-QFWERED4.js → agentRecordCommands-UHTQJVGC.js} +59 -55
- package/{agentRunCommand-G3GQMUNN.js → agentRunCommand-OAMT77EX.js} +63 -59
- package/{agentRunControl-INKFDXDA.js → agentRunControl-WECMOO6O.js} +11 -6
- package/{agentRuntimeLocal-K327ELSL.js → agentRuntimeLocal-QBK4H3T2.js} +26 -23
- package/{agentSlice-ODKF4J6M.js → agentSlice-7XJH5WQF.js} +8 -7
- package/{appDeleteCommands-XUXMFDI4.js → appDeleteCommands-AX2O6VDV.js} +30 -27
- package/{appDeployCommands-37F4GPCU.js → appDeployCommands-L5ZR26CB.js} +30 -27
- package/{appDeployStatusCommands-WSPU7TUK.js → appDeployStatusCommands-5HQHELRA.js} +30 -27
- package/{appGetCommands-YLOBA3EM.js → appGetCommands-HVSYOS57.js} +30 -27
- package/{appListCommands-UD62R5ME.js → appListCommands-XV2FPTWX.js} +30 -27
- package/{authCommand-OK6HLHGS.js → authCommand-WOTWLJNF.js} +35 -29
- package/{authCommands-2DUIUEMT.js → authCommands-ILTBI6JV.js} +7 -5
- package/{chatQueueReduxAdapter-TV2TUOQS.js → chatQueueReduxAdapter-F3R253JE.js} +20 -18
- package/{chunk-HPW5MNDQ.js → chunk-22BTGNSP.js} +113 -57
- package/{chunk-UNZDCI3O.js → chunk-2KDR4CWE.js} +35 -4
- package/{chunk-3ZTR7ZO4.js → chunk-2PGGC63K.js} +1 -1
- package/{chunk-EA5OYZVD.js → chunk-37XDGCY7.js} +1 -1
- package/chunk-3BLB7QKO.js +433 -0
- package/{chunk-CS6TCJ7E.js → chunk-3JQ2NRYU.js} +30 -7
- package/{chunk-3LKZRP7E.js → chunk-3QGUVVX5.js} +2 -2
- package/{chunk-SSXTSPSG.js → chunk-45YO6H7P.js} +71 -30
- package/{chunk-YLCUU3WM.js → chunk-4NJEIGBQ.js} +5 -5
- package/{chunk-K4NISKOR.js → chunk-5ZYA4JJ3.js} +47 -17
- package/{chunk-6HIGYUBQ.js → chunk-6XIE5ZGI.js} +1 -1
- package/{chunk-3Y2K5O2R.js → chunk-7A3RRUCQ.js} +125 -40
- package/{chunk-6COJEAYH.js → chunk-7KELZLC2.js} +44 -37
- package/chunk-AETZ7AD6.js +274 -0
- package/chunk-BFU6C242.js +66 -0
- package/{chunk-IA3A5373.js → chunk-C3FZR5EC.js} +1 -1
- package/{chunk-IWUMSAQF.js → chunk-CJCJF5XB.js} +26 -3
- package/{chunk-UGBHDMHI.js → chunk-CP7VIDZ7.js} +1 -1
- package/{chunk-TR4DXUYX.js → chunk-CQ2OZMLQ.js} +1181 -737
- package/{chunk-JON2PHYT.js → chunk-CTCW7U7N.js} +1 -1
- package/{chunk-7NYDJAQ7.js → chunk-DNNSCSA2.js} +5 -5
- package/{chunk-NI2BS6UD.js → chunk-DWUCB2A3.js} +1 -1
- package/{chunk-FJHMLRDQ.js → chunk-DWYSDNOH.js} +22 -28
- package/{chunk-AA564GBL.js → chunk-E3YVTQWT.js} +2 -2
- package/chunk-E4MARS3Q.js +114 -0
- package/{chunk-75MSWWUE.js → chunk-E6RGHPDR.js} +5 -3
- package/chunk-EDKF7RX4.js +30 -0
- package/{chunk-TC6P4NDR.js → chunk-F44FAXP2.js} +6 -6
- package/{chunk-SYYUU7EV.js → chunk-FHAGENAS.js} +2 -3
- package/{chunk-NJUQBYFJ.js → chunk-FKFMIBTT.js} +3 -1
- package/{chunk-INZZJSQF.js → chunk-FZGV4FGK.js} +24 -12
- package/{chunk-6HDYSFLO.js → chunk-GSXDRMDO.js} +3 -3
- package/{chunk-AUVFJGPC.js → chunk-JX5PJCWS.js} +7 -5
- package/{chunk-LYGNQHUW.js → chunk-JYYZCK2Z.js} +2 -4
- package/{chunk-EY7V7REW.js → chunk-KHCLMKZZ.js} +6 -280
- package/{chunk-EJE33XNR.js → chunk-KSCXMC6U.js} +1521 -565
- package/{chunk-XOJRZUPF.js → chunk-KWSQR2KK.js} +14 -29
- package/{chunk-2WBFJHQA.js → chunk-L7B47JXR.js} +34 -39
- package/{chunk-EICIFHVS.js → chunk-LAFC3B2I.js} +1 -1
- package/{chunk-N4JKMCY3.js → chunk-LJKICKVC.js} +2 -2
- package/chunk-M3JEW6N6.js +193 -0
- package/{chunk-LRGKOI5Y.js → chunk-MBOEV4L2.js} +7 -3
- package/{chunk-SVDMVX4G.js → chunk-MMZ6ZTVO.js} +112 -73
- package/{chunk-JDSUTNYY.js → chunk-MP64VFGD.js} +2 -2
- package/{chunk-NFLA6GSU.js → chunk-MXUDQZXQ.js} +44 -5
- package/chunk-N4G4PKQ6.js +23 -0
- package/{chunk-WQHGJHAL.js → chunk-N6HLMLKE.js} +732 -726
- package/{chunk-YQBXOHE6.js → chunk-NO42UD73.js} +1 -1
- package/{chunk-MLEZPE3U.js → chunk-NRRPKMM7.js} +4 -4
- package/{chunk-KXKQO4Q6.js → chunk-NTW5GWDM.js} +58 -1
- package/chunk-ONXOABJR.js +215 -0
- package/{chunk-TY3ADTX5.js → chunk-OZX2IPKM.js} +7 -2
- package/{chunk-Q4XZVZPN.js → chunk-P7OOB7QP.js} +1 -1
- package/{chunk-XIJZOCSP.js → chunk-PEZJEQAO.js} +1 -1
- package/{chunk-SWJGJMTW.js → chunk-PQDIDWGX.js} +1 -1
- package/chunk-PSCNXBYA.js +11 -0
- package/{chunk-BY2FF2C4.js → chunk-QEFJJS2I.js} +55 -73
- package/{chunk-BG7J6Y5X.js → chunk-QEW2MFDQ.js} +1 -1
- package/{chunk-KLIBF3BY.js → chunk-RDBARW6T.js} +8 -3
- package/{chunk-ZVOHVJI3.js → chunk-RJ2SAFB5.js} +82 -35
- package/{chunk-MYMBBB6Q.js → chunk-RVWRKFUB.js} +5 -3
- package/{chunk-43CXXVJD.js → chunk-RXX4GDIH.js} +1 -1
- package/chunk-SEJ5OS6F.js +49 -0
- package/{chunk-JXIP6ZWH.js → chunk-SKIRVYEI.js} +18 -5
- package/{chunk-SAJSBPI2.js → chunk-SOJM57FX.js} +5 -2
- package/{chunk-EKLRRZIN.js → chunk-SPAQ4PVV.js} +0 -5
- package/{chunk-RHMDMTDK.js → chunk-SYNKICCB.js} +2 -2
- package/{chunk-YBFJQC2M.js → chunk-TBHAHL33.js} +65 -42
- package/{chunk-L7NG2M6H.js → chunk-TRV2MIDW.js} +89 -74
- package/{chunk-5UAYZEXO.js → chunk-UZPQSVM6.js} +1 -1
- package/{chunk-7FAS3NEF.js → chunk-VAKVNHK5.js} +19 -15
- package/{chunk-UOWXD4VN.js → chunk-VHO3TMQZ.js} +336 -244
- package/{chunk-SVC3GGUA.js → chunk-VMWYBIXG.js} +7 -5
- package/{chunk-ZHXJ6M7T.js → chunk-W7XHHYWM.js} +4 -0
- package/{chunk-UR66XPVF.js → chunk-XAVSS3KE.js} +21 -3
- package/{chunk-A65UV3M5.js → chunk-XOKOSO35.js} +10 -19
- package/{chunk-VZMUOPYG.js → chunk-XTJTN3RW.js} +46 -3
- package/{chunk-T5HJEUQN.js → chunk-YCDWJX45.js} +1 -1
- package/{chunk-BBTN4NQD.js → chunk-Z4QSJILV.js} +85 -13
- package/{chunk-5FCIPEKT.js → chunk-Z5MHFBJZ.js} +1051 -926
- package/{chunk-O5FLGN2L.js → chunk-ZRSJ3JEH.js} +6 -2
- package/{cliExecutor-BBUVQU4L.js → cliExecutor-HG3S345O.js} +1 -1
- package/{codingSkills-BCQXRZOI.js → codingSkills-TKROLCBA.js} +4 -3
- package/{contentThunks-KNI6VXLT.js → contentThunks-OZPK5B4Z.js} +21 -19
- package/{cooldownCommands-GI5NNWGL.js → cooldownCommands-BSCH2W7P.js} +2 -2
- package/{createAgentAutomationAction-OK4L33KF.js → createAgentAutomationAction-LCIBGE5T.js} +23 -21
- package/{createDialogAction-JDSMY4AY.js → createDialogAction-JPJZMHJE.js} +25 -22
- package/{createPageAction-T7RA3HCG.js → createPageAction-6P2WLNHO.js} +26 -23
- package/{dbSlice-TVX6SN2T.js → dbSlice-IBVOBVMS.js} +5 -4
- package/{deleteFile-JYKRT7C3.js → deleteFile-FWP2PSBG.js} +3 -2
- package/{dialogCommands-UQZYWOOV.js → dialogCommands-WAFKC3KK.js} +30 -27
- package/{dialogSlice-TYW2G7IL.js → dialogSlice-R5RZHFTU.js} +20 -18
- package/{docCreateCommands-OA6HZBWO.js → docCreateCommands-GHGB42S7.js} +32 -28
- package/{docDeleteCommands-KBB3YQI2.js → docDeleteCommands-Y5I7ZEX4.js} +33 -29
- package/{docReadCommands-ZLMFVC67.js → docReadCommands-BMXM6J7T.js} +32 -28
- package/{docStore-2URPBVCS.js → docStore-DKWZ6XJ5.js} +6 -5
- package/{docUpdateCommands-HMH5KUON.js → docUpdateCommands-QNABH3M2.js} +32 -28
- package/{getPricing-RFOPUWHY.js → getPricing-NM3NUTAS.js} +4 -4
- package/handleSendMessageAction-UQGKM4UX.js +675 -0
- package/index.js +79 -88
- package/{lib-2ZTNRXR4.js → lib-FRRS27KN.js} +63 -28
- package/{localRuntimeAuthority-KQDAE64E.js → localRuntimeAuthority-R5UBODT3.js} +6 -4
- package/{localRuntimeDb-PF7CFKDL.js → localRuntimeDb-P37ZTX55.js} +1 -1
- package/{machineCommands-RK6L7ZWL.js → machineCommands-YDAIPYU5.js} +298 -80
- package/{machineWsRunDispatch-3X64DW2Z.js → machineWsRunDispatch-O6RM2ECT.js} +57 -53
- package/{memberThunks-THZYZFSN.js → memberThunks-VZI6G7YZ.js} +10 -8
- package/{models-JVKUEER5.js → models-FAMINFZ7.js} +2 -2
- package/package.json +3 -2
- package/{read-K4JU4MQC.js → read-2BYWW7AA.js} +3 -2
- package/{readDocTool-LQGR6FUN.js → readDocTool-LC3A7QTB.js} +1 -1
- package/{readlineWorkspace-XUFJV3RS.js → readlineWorkspace-5DP3AJWN.js} +4367 -2796
- package/{removeDialogAgentAction-ECHCFB7N.js → removeDialogAgentAction-SFYZXHNK.js} +8 -7
- package/{runAgentClientLoop-24GQ2AW6.js → runAgentClientLoop-Y6HWP2PT.js} +51 -46
- package/{runtimeDoctorCommands-JKTTN723.js → runtimeDoctorCommands-CROTMULY.js} +7 -5
- package/{setDialogExtraReferencesAction-KCVJNGMB.js → setDialogExtraReferencesAction-Q32RGFTA.js} +6 -5
- package/{setPrimaryDialogAgentAction-VDOBOMKC.js → setPrimaryDialogAgentAction-BFYJHUJS.js} +8 -7
- package/{settingSlice-VR2IJSXC.js → settingSlice-IRUU4VFB.js} +6 -5
- package/{skillDiscovery-2QTZINON.js → skillDiscovery-CYUCJMAG.js} +2 -1
- package/{spaceCommands-S5YJJXL7.js → spaceCommands-CLN45IE3.js} +33 -215
- package/{streamAgentChatTurn-QHKP3ABO.js → streamAgentChatTurn-6WFQJ4DY.js} +107 -74
- package/{switchDialogAgentAction-5L4UP7VI.js → switchDialogAgentAction-L2KOKCGG.js} +5 -4
- package/{tableCommands-R6WFRDYF.js → tableCommands-SUNTHAYX.js} +1 -1
- package/{toolApiClient-53U4UDFF.js → toolApiClient-VGYUB4P5.js} +2 -1
- package/{tools-SSXSTC3O.js → tools-RR53D65Q.js} +39 -35
- package/{tuiSummaryLlmCaller-URFJHFC5.js → tuiSummaryLlmCaller-F3DPFFZM.js} +15 -13
- package/{updateCommands-IYKLF3JX.js → updateCommands-AJYSD73Y.js} +2 -2
- package/{updateDialogTitleAction-YFYAEW3T.js → updateDialogTitleAction-WXS3AKOL.js} +23 -21
- package/agentSuperviseCommands-5AR3DKNN.js +0 -640
- package/chunk-6IGD47IC.js +0 -19
- package/chunk-FD36SCCD.js +0 -105
- package/chunk-GRFK2XP4.js +0 -230
- package/chunk-HJTAGT3W.js +0 -370
- package/chunk-SUEIAK5N.js +0 -2574
- package/handleSendMessageAction-GO53TY7U.js +0 -409
|
@@ -0,0 +1,675 @@
|
|
|
1
|
+
import {
|
|
2
|
+
waitForAbortableDelay
|
|
3
|
+
} from "./chunk-N4G4PKQ6.js";
|
|
4
|
+
import {
|
|
5
|
+
messageStreamEnd,
|
|
6
|
+
prepareAndPersistUserMessage,
|
|
7
|
+
resolveHandleSendMessageContext,
|
|
8
|
+
selectAllMsgs
|
|
9
|
+
} from "./chunk-TBHAHL33.js";
|
|
10
|
+
import "./chunk-EVBFYPDC.js";
|
|
11
|
+
import "./chunk-HQUORJTM.js";
|
|
12
|
+
import "./chunk-YYLHWIW6.js";
|
|
13
|
+
import "./chunk-AGGIDPCZ.js";
|
|
14
|
+
import {
|
|
15
|
+
streamAgentChatTurn
|
|
16
|
+
} from "./chunk-F44FAXP2.js";
|
|
17
|
+
import "./chunk-4NJEIGBQ.js";
|
|
18
|
+
import "./chunk-5RGU3J7P.js";
|
|
19
|
+
import {
|
|
20
|
+
addActiveController,
|
|
21
|
+
getActiveDialogKey,
|
|
22
|
+
removeActiveController
|
|
23
|
+
} from "./chunk-6YTOJY35.js";
|
|
24
|
+
import "./chunk-M76ECQRD.js";
|
|
25
|
+
import "./chunk-YDH3FDFQ.js";
|
|
26
|
+
import "./chunk-5ZYA4JJ3.js";
|
|
27
|
+
import "./chunk-Z4QSJILV.js";
|
|
28
|
+
import "./chunk-LJKICKVC.js";
|
|
29
|
+
import "./chunk-PSCNXBYA.js";
|
|
30
|
+
import "./chunk-BYXBJQAS.js";
|
|
31
|
+
import "./chunk-MMZ6ZTVO.js";
|
|
32
|
+
import "./chunk-DWLEOOGR.js";
|
|
33
|
+
import "./chunk-3JQ2NRYU.js";
|
|
34
|
+
import "./chunk-ONXOABJR.js";
|
|
35
|
+
import "./chunk-W7XHHYWM.js";
|
|
36
|
+
import "./chunk-HNMXYYJR.js";
|
|
37
|
+
import "./chunk-BYEJ7K2Z.js";
|
|
38
|
+
import "./chunk-FKFMIBTT.js";
|
|
39
|
+
import "./chunk-22BTGNSP.js";
|
|
40
|
+
import "./chunk-VMWYBIXG.js";
|
|
41
|
+
import "./chunk-Y5GCAMGP.js";
|
|
42
|
+
import "./chunk-UZ6XXCVR.js";
|
|
43
|
+
import "./chunk-KX6YBIHG.js";
|
|
44
|
+
import "./chunk-RVWRKFUB.js";
|
|
45
|
+
import "./chunk-UAD2WT54.js";
|
|
46
|
+
import {
|
|
47
|
+
readAndWait,
|
|
48
|
+
selectById
|
|
49
|
+
} from "./chunk-DNNSCSA2.js";
|
|
50
|
+
import {
|
|
51
|
+
createDialogMessageKeyAndId
|
|
52
|
+
} from "./chunk-NHRQCXIQ.js";
|
|
53
|
+
import "./chunk-WWC7I6TA.js";
|
|
54
|
+
import "./chunk-I42VC5KR.js";
|
|
55
|
+
import "./chunk-SOJM57FX.js";
|
|
56
|
+
import "./chunk-QSJ3HFEF.js";
|
|
57
|
+
import "./chunk-L7B47JXR.js";
|
|
58
|
+
import {
|
|
59
|
+
extractCustomId
|
|
60
|
+
} from "./chunk-BJIRLHJR.js";
|
|
61
|
+
import "./chunk-KWSQR2KK.js";
|
|
62
|
+
import "./chunk-QOKAKDPE.js";
|
|
63
|
+
import "./chunk-OW765XBU.js";
|
|
64
|
+
import "./chunk-SEJ5OS6F.js";
|
|
65
|
+
import "./chunk-GBRG75BQ.js";
|
|
66
|
+
import "./chunk-3EUW3WEO.js";
|
|
67
|
+
import "./chunk-U6VC4MU4.js";
|
|
68
|
+
import "./chunk-KUG52IAP.js";
|
|
69
|
+
import "./chunk-LCBAMY2M.js";
|
|
70
|
+
import "./chunk-4SN6J65J.js";
|
|
71
|
+
import "./chunk-CF7PE763.js";
|
|
72
|
+
import "./chunk-G3SUCT4W.js";
|
|
73
|
+
import "./chunk-4VNS5WPM.js";
|
|
74
|
+
|
|
75
|
+
// packages/chat/dialog/actions/parseOAuthError.ts
|
|
76
|
+
var PROVIDER_NAMES = {
|
|
77
|
+
antigravity: "Antigravity (Google)",
|
|
78
|
+
claude: "Claude",
|
|
79
|
+
chatgpt: "ChatGPT",
|
|
80
|
+
xai: "xAI Grok",
|
|
81
|
+
cursor: "Cursor",
|
|
82
|
+
cloudflare: "Cloudflare"
|
|
83
|
+
};
|
|
84
|
+
function asRecord(value) {
|
|
85
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
function asString(value) {
|
|
91
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
92
|
+
}
|
|
93
|
+
function sanitizeSafeUrl(rawUrl) {
|
|
94
|
+
if (typeof rawUrl !== "string") return void 0;
|
|
95
|
+
const trimmed = rawUrl.trim();
|
|
96
|
+
if (/^https?:\/\//i.test(trimmed)) {
|
|
97
|
+
try {
|
|
98
|
+
const parsed = new URL(trimmed);
|
|
99
|
+
if (parsed.protocol === "http:" || parsed.protocol === "https:") {
|
|
100
|
+
return trimmed;
|
|
101
|
+
}
|
|
102
|
+
} catch {
|
|
103
|
+
return void 0;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return void 0;
|
|
107
|
+
}
|
|
108
|
+
function extractFullErrorText(error) {
|
|
109
|
+
if (!error) return "Unknown error";
|
|
110
|
+
if (typeof error === "string") return error;
|
|
111
|
+
if (error instanceof Error) {
|
|
112
|
+
let msg = error.message || error.name || String(error);
|
|
113
|
+
const seen = /* @__PURE__ */ new Set([error]);
|
|
114
|
+
let current = error.cause;
|
|
115
|
+
while (current && !seen.has(current)) {
|
|
116
|
+
seen.add(current);
|
|
117
|
+
const causeMsg = current instanceof Error ? current.message || String(current) : typeof current === "string" ? current : JSON.stringify(current);
|
|
118
|
+
if (causeMsg && !msg.includes(causeMsg)) {
|
|
119
|
+
msg = `${msg}
|
|
120
|
+
[cause]: ${causeMsg}`;
|
|
121
|
+
}
|
|
122
|
+
current = current?.cause;
|
|
123
|
+
}
|
|
124
|
+
return msg;
|
|
125
|
+
}
|
|
126
|
+
return error?.message || error?.error || String(error);
|
|
127
|
+
}
|
|
128
|
+
function collectValidationFromDetails(details) {
|
|
129
|
+
if (!Array.isArray(details)) return {};
|
|
130
|
+
let url;
|
|
131
|
+
let text;
|
|
132
|
+
let learnMoreUrl;
|
|
133
|
+
for (const detail of details) {
|
|
134
|
+
const rec = asRecord(detail);
|
|
135
|
+
if (!rec) continue;
|
|
136
|
+
const metadata = asRecord(rec.metadata);
|
|
137
|
+
if (metadata) {
|
|
138
|
+
url = url ?? sanitizeSafeUrl(metadata.validation_url);
|
|
139
|
+
text = text ?? asString(metadata.validation_url_link_text);
|
|
140
|
+
learnMoreUrl = learnMoreUrl ?? sanitizeSafeUrl(metadata.validation_learn_more_url);
|
|
141
|
+
}
|
|
142
|
+
const help = asRecord(rec);
|
|
143
|
+
if (Array.isArray(help.links)) {
|
|
144
|
+
for (const link of help.links) {
|
|
145
|
+
const linkRec = asRecord(link);
|
|
146
|
+
if (!linkRec) continue;
|
|
147
|
+
const linkUrl = sanitizeSafeUrl(linkRec.url);
|
|
148
|
+
if (!linkUrl) continue;
|
|
149
|
+
const desc = asString(linkRec.description);
|
|
150
|
+
if (!url && desc && /verify|continue/i.test(desc)) {
|
|
151
|
+
url = linkUrl;
|
|
152
|
+
text = desc;
|
|
153
|
+
} else if (!learnMoreUrl && /learn more/i.test(desc ?? "")) {
|
|
154
|
+
learnMoreUrl = linkUrl;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return { url, text, learnMoreUrl };
|
|
160
|
+
}
|
|
161
|
+
function resolveErrorStage(errorText) {
|
|
162
|
+
if (/127\.0\.0\.1:3233|localhost:3233|desktop daemon|desktop agent runtime|runDesktopAgentRuntime|Local turn stream/i.test(
|
|
163
|
+
errorText
|
|
164
|
+
)) {
|
|
165
|
+
return "desktop_local_runtime";
|
|
166
|
+
}
|
|
167
|
+
if (/\/api\/ai\/chat\/proxy|server proxy|core_draining|fetchWithServerProxy/i.test(
|
|
168
|
+
errorText
|
|
169
|
+
)) {
|
|
170
|
+
return "server_proxy";
|
|
171
|
+
}
|
|
172
|
+
if (/OAuth provider failed|provider failed|antigravity|claude|chatgpt|openai|gemini|deepseek/i.test(
|
|
173
|
+
errorText
|
|
174
|
+
)) {
|
|
175
|
+
return "provider";
|
|
176
|
+
}
|
|
177
|
+
return void 0;
|
|
178
|
+
}
|
|
179
|
+
function parseSendError(errorInput) {
|
|
180
|
+
const fullErrorText = extractFullErrorText(errorInput).trim();
|
|
181
|
+
const firstLine = fullErrorText.replace(/^local\s+/, "").split("\n")[0].trim();
|
|
182
|
+
const providerMatch = fullErrorText.match(/local\s+(\w+)\s+OAuth provider failed/i);
|
|
183
|
+
const providerName = providerMatch ? PROVIDER_NAMES[providerMatch[1].toLowerCase()] ?? providerMatch[1] : void 0;
|
|
184
|
+
const statusMatch = fullErrorText.match(/HTTP\s+(\d{3})/i) || fullErrorText.match(/\bstatus(?:\s+code)?[:=]?\s*(\d{3})\b/i) || fullErrorText.match(/^(?:HTTP\/[\d.]+\s+)?([45]\d{2})\b/i);
|
|
185
|
+
const status = statusMatch?.[1];
|
|
186
|
+
const statusCode = status ? parseInt(status, 10) : void 0;
|
|
187
|
+
const jsonStart = fullErrorText.indexOf("{");
|
|
188
|
+
let payload = null;
|
|
189
|
+
if (jsonStart >= 0) {
|
|
190
|
+
let candidate = fullErrorText.slice(jsonStart);
|
|
191
|
+
for (let depth = 0; depth < 3; depth += 1) {
|
|
192
|
+
try {
|
|
193
|
+
const parsed = JSON.parse(candidate);
|
|
194
|
+
payload = parsed;
|
|
195
|
+
const message = asString(
|
|
196
|
+
parsed?.error?.message ?? parsed?.message
|
|
197
|
+
);
|
|
198
|
+
if (message && message.trim().startsWith("{")) {
|
|
199
|
+
candidate = message;
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
break;
|
|
203
|
+
} catch {
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const errorRec = payload ? asRecord(payload.error) : null;
|
|
209
|
+
const innerMessage = errorRec ? asString(errorRec.message) : void 0;
|
|
210
|
+
const statusFromBody = errorRec ? asString(errorRec.status) : void 0;
|
|
211
|
+
const details = errorRec?.details;
|
|
212
|
+
const { url, text, learnMoreUrl } = collectValidationFromDetails(details);
|
|
213
|
+
let reason = errorRec ? asString(errorRec.reason) : void 0;
|
|
214
|
+
let domain = errorRec ? asString(errorRec.domain) : void 0;
|
|
215
|
+
if (!reason && Array.isArray(details)) {
|
|
216
|
+
const first = asRecord(details[0]);
|
|
217
|
+
reason = first ? asString(first.reason) : void 0;
|
|
218
|
+
domain = first ? asString(first.domain) : void 0;
|
|
219
|
+
}
|
|
220
|
+
const stage = resolveErrorStage(fullErrorText);
|
|
221
|
+
let kind = "unknown";
|
|
222
|
+
let retryable = true;
|
|
223
|
+
const isLocalConnRefused = /ECONNREFUSED/i.test(fullErrorText) && (/127\.0\.0\.1/i.test(fullErrorText) || /localhost/i.test(fullErrorText));
|
|
224
|
+
const hasExplicitAuthKeywords = /unauthorized|unauthenticated|permission_denied|validation_required|invalid_api_key|api key not found|authentication error|forbidden/i.test(
|
|
225
|
+
fullErrorText
|
|
226
|
+
);
|
|
227
|
+
if (statusCode === 429) {
|
|
228
|
+
kind = "rate_limit";
|
|
229
|
+
retryable = true;
|
|
230
|
+
} else if (statusCode === 401 || statusCode === 403 || hasExplicitAuthKeywords) {
|
|
231
|
+
kind = "auth";
|
|
232
|
+
retryable = false;
|
|
233
|
+
} else if (statusCode && statusCode >= 500 && statusCode < 600) {
|
|
234
|
+
kind = "server";
|
|
235
|
+
retryable = true;
|
|
236
|
+
} else if (/timed out|timeout|ETIMEDOUT|deadline exceeded|upstream request timeout/i.test(
|
|
237
|
+
fullErrorText
|
|
238
|
+
) || /aborted due to timeout/i.test(fullErrorText)) {
|
|
239
|
+
kind = "timeout";
|
|
240
|
+
retryable = true;
|
|
241
|
+
} else if (/failed to fetch|network error|fetch failed|load failed|network request failed|networkerror|ECONNREFUSED|ENOTFOUND|ECONNRESET|EHOSTUNREACH|ENETUNREACH|EAI_AGAIN|UND_ERR_CONNECT_TIMEOUT|UND_ERR_SOCKET|socket hang up|socket closed|connection closed|certificate|handshake/i.test(
|
|
242
|
+
fullErrorText
|
|
243
|
+
)) {
|
|
244
|
+
kind = "network";
|
|
245
|
+
retryable = true;
|
|
246
|
+
} else if (/rate limit|too many requests|quota exceeded|resource exhausted|insufficient_quota/i.test(
|
|
247
|
+
fullErrorText
|
|
248
|
+
)) {
|
|
249
|
+
kind = "rate_limit";
|
|
250
|
+
retryable = true;
|
|
251
|
+
} else if (/internal server error|bad gateway|service unavailable|gateway timeout|core_draining/i.test(
|
|
252
|
+
fullErrorText
|
|
253
|
+
)) {
|
|
254
|
+
kind = "server";
|
|
255
|
+
retryable = true;
|
|
256
|
+
} else {
|
|
257
|
+
kind = "unknown";
|
|
258
|
+
retryable = true;
|
|
259
|
+
}
|
|
260
|
+
const parts = [];
|
|
261
|
+
if (providerName) {
|
|
262
|
+
const head = `${providerName} \u8FDE\u63A5\u5931\u8D25`;
|
|
263
|
+
parts.push(
|
|
264
|
+
`${head}${status ? ` (HTTP ${status})` : ""}${statusFromBody ? ` ${statusFromBody}` : ""}`
|
|
265
|
+
);
|
|
266
|
+
} else {
|
|
267
|
+
switch (kind) {
|
|
268
|
+
case "network":
|
|
269
|
+
if (isLocalConnRefused) {
|
|
270
|
+
parts.push("\u672C\u5730\u670D\u52A1\u8FDE\u63A5\u5931\u8D25");
|
|
271
|
+
} else if (/ENOTFOUND/i.test(fullErrorText)) {
|
|
272
|
+
parts.push("\u57DF\u540D\u89E3\u6790\u5931\u8D25");
|
|
273
|
+
} else {
|
|
274
|
+
parts.push("\u8FDE\u63A5\u4E2D\u65AD");
|
|
275
|
+
}
|
|
276
|
+
break;
|
|
277
|
+
case "timeout":
|
|
278
|
+
parts.push("\u8BF7\u6C42\u8D85\u65F6");
|
|
279
|
+
break;
|
|
280
|
+
case "rate_limit":
|
|
281
|
+
parts.push(`\u8BF7\u6C42\u8FC7\u4E8E\u9891\u7E41${status ? ` (HTTP ${status})` : ""}`);
|
|
282
|
+
break;
|
|
283
|
+
case "auth":
|
|
284
|
+
parts.push(`\u8BA4\u8BC1\u6216\u6743\u9650\u6821\u9A8C\u5931\u8D25${status ? ` (HTTP ${status})` : ""}`);
|
|
285
|
+
break;
|
|
286
|
+
case "server":
|
|
287
|
+
parts.push(`\u670D\u52A1\u6682\u65F6\u4E0D\u53EF\u7528${status ? ` (HTTP ${status})` : ""}`);
|
|
288
|
+
break;
|
|
289
|
+
default:
|
|
290
|
+
parts.push(firstLine.length > 0 ? firstLine : "\u53D1\u9001\u9047\u5230\u5F02\u5E38");
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (reason) {
|
|
295
|
+
parts.push(`\u539F\u56E0\uFF1A${reason}`);
|
|
296
|
+
}
|
|
297
|
+
if (domain) {
|
|
298
|
+
parts.push(`\u670D\u52A1\uFF1A${domain}`);
|
|
299
|
+
}
|
|
300
|
+
const humanMessage = innerMessage && innerMessage.trim() !== "Verify your account to continue." ? innerMessage : void 0;
|
|
301
|
+
if (humanMessage) {
|
|
302
|
+
parts.push(`\u63D0\u793A\uFF1A${humanMessage}`);
|
|
303
|
+
}
|
|
304
|
+
let actionHint;
|
|
305
|
+
if (url) {
|
|
306
|
+
actionHint = "\u8BF7\u70B9\u51FB\u94FE\u63A5\u5B8C\u6210\u9A8C\u8BC1";
|
|
307
|
+
} else {
|
|
308
|
+
switch (kind) {
|
|
309
|
+
case "network":
|
|
310
|
+
if (isLocalConnRefused) {
|
|
311
|
+
actionHint = "\u65E0\u6CD5\u8FDE\u63A5\u5230\u672C\u5730\u670D\u52A1\uFF0C\u8BF7\u786E\u8BA4\u684C\u9762\u7AEF\u540E\u53F0\u670D\u52A1\u6B63\u5728\u8FD0\u884C\u540E\u91CD\u8BD5";
|
|
312
|
+
} else if (/ENOTFOUND/i.test(fullErrorText)) {
|
|
313
|
+
actionHint = "\u65E0\u6CD5\u89E3\u6790\u670D\u52A1\u5730\u5740\uFF0C\u53EF\u80FD\u662F DNS \u6216\u7F51\u7EDC\u73AF\u5883\u6CE2\u52A8\uFF0C\u70B9\u51FB\u91CD\u8BD5\u901A\u5E38\u53EF\u6062\u590D";
|
|
314
|
+
} else {
|
|
315
|
+
actionHint = "\u53EF\u80FD\u662F\u7F51\u7EDC\u6CE2\u52A8\u6216\u670D\u52A1\u7AEF\u77AC\u65F6\u95EE\u9898\uFF0C\u70B9\u51FB\u91CD\u8BD5\u901A\u5E38\u53EF\u6062\u590D";
|
|
316
|
+
}
|
|
317
|
+
break;
|
|
318
|
+
case "timeout":
|
|
319
|
+
actionHint = "\u670D\u52A1\u54CD\u5E94\u8D85\u65F6\uFF0C\u53EF\u80FD\u662F\u7F51\u7EDC\u6CE2\u52A8\u6216\u670D\u52A1\u8D1F\u8F7D\u8F83\u9AD8\uFF0C\u70B9\u51FB\u91CD\u8BD5\u901A\u5E38\u53EF\u6062\u590D";
|
|
320
|
+
break;
|
|
321
|
+
case "rate_limit":
|
|
322
|
+
actionHint = "\u5DF2\u8FBE\u5230\u8C03\u7528\u9891\u7387\u6216\u914D\u989D\u9650\u5236\uFF0C\u8BF7\u7A0D\u5019\u7247\u523B\u540E\u91CD\u8BD5";
|
|
323
|
+
break;
|
|
324
|
+
case "auth":
|
|
325
|
+
actionHint = "\u8BF7\u68C0\u67E5\u8D26\u53F7\u767B\u5F55\u72B6\u6001\u6216 API \u5BC6\u94A5\u914D\u7F6E";
|
|
326
|
+
break;
|
|
327
|
+
case "server":
|
|
328
|
+
actionHint = "\u670D\u52A1\u7AEF\u53D1\u751F\u77AC\u65F6\u5F02\u5E38\uFF0C\u70B9\u51FB\u91CD\u8BD5\u901A\u5E38\u53EF\u6062\u590D";
|
|
329
|
+
break;
|
|
330
|
+
case "unknown":
|
|
331
|
+
default:
|
|
332
|
+
actionHint = "\u9047\u5230\u5F02\u5E38\uFF0C\u70B9\u51FB\u91CD\u8BD5\u901A\u5E38\u53EF\u6062\u590D";
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const extraLinks = [];
|
|
337
|
+
if (learnMoreUrl) {
|
|
338
|
+
extraLinks.push({ text: "\u4E86\u89E3\u66F4\u591A", url: learnMoreUrl });
|
|
339
|
+
}
|
|
340
|
+
const summary = parts.join("\n");
|
|
341
|
+
if (url) {
|
|
342
|
+
return {
|
|
343
|
+
kind,
|
|
344
|
+
retryable,
|
|
345
|
+
stage,
|
|
346
|
+
actionHint,
|
|
347
|
+
summary,
|
|
348
|
+
validationUrl: url,
|
|
349
|
+
validationLinkText: text ?? "\u9A8C\u8BC1\u6211\u7684\u8D26\u53F7",
|
|
350
|
+
extraLinks
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
const MAX_FALLBACK = 800;
|
|
354
|
+
const fallbackText = fullErrorText.length > MAX_FALLBACK ? `${fullErrorText.slice(0, MAX_FALLBACK)}\u2026` : fullErrorText;
|
|
355
|
+
return {
|
|
356
|
+
kind,
|
|
357
|
+
retryable,
|
|
358
|
+
stage,
|
|
359
|
+
actionHint,
|
|
360
|
+
summary,
|
|
361
|
+
extraLinks,
|
|
362
|
+
fallbackText
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
function buildSendErrorMessageMarkdown(parsed) {
|
|
366
|
+
const lines = ["[\u53D1\u9001\u5931\u8D25]", "", parsed.summary];
|
|
367
|
+
if (parsed.actionHint && !parsed.validationUrl) {
|
|
368
|
+
lines.push("", `\u5EFA\u8BAE\uFF1A${parsed.actionHint}`);
|
|
369
|
+
}
|
|
370
|
+
if (parsed.validationUrl) {
|
|
371
|
+
lines.push(
|
|
372
|
+
"",
|
|
373
|
+
`\u8BF7\u70B9\u51FB\u94FE\u63A5\u5B8C\u6210\u9A8C\u8BC1\uFF1A`,
|
|
374
|
+
`- [${parsed.validationLinkText ?? "\u9A8C\u8BC1\u6211\u7684\u8D26\u53F7"}](${parsed.validationUrl})`
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
for (const link of parsed.extraLinks) {
|
|
378
|
+
lines.push(`- [${link.text}](${link.url})`);
|
|
379
|
+
}
|
|
380
|
+
if (parsed.fallbackText && !parsed.validationUrl) {
|
|
381
|
+
lines.push("", "```", parsed.fallbackText, "```");
|
|
382
|
+
}
|
|
383
|
+
return lines.join("\n");
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// packages/chat/dialog/actions/handleSendMessageAction.ts
|
|
387
|
+
var getDialogConfig = (state, dialogKey) => {
|
|
388
|
+
const resolvedDialogKey = dialogKey ?? getActiveDialogKey();
|
|
389
|
+
if (!resolvedDialogKey) return null;
|
|
390
|
+
const dialog = selectById(state, resolvedDialogKey);
|
|
391
|
+
return dialog ?? null;
|
|
392
|
+
};
|
|
393
|
+
var ensureDialogConfig = async (dispatch, getState, dialogKey) => {
|
|
394
|
+
const state = getState();
|
|
395
|
+
const resolvedDialogKey = dialogKey ?? getActiveDialogKey();
|
|
396
|
+
if (!resolvedDialogKey) return null;
|
|
397
|
+
try {
|
|
398
|
+
const existingDialog = getDialogConfig(state, resolvedDialogKey);
|
|
399
|
+
if (existingDialog && Array.isArray(existingDialog.cybots) && existingDialog.cybots.length > 0) {
|
|
400
|
+
return existingDialog;
|
|
401
|
+
}
|
|
402
|
+
const persistedDialog = await dispatch(readAndWait(resolvedDialogKey)).unwrap();
|
|
403
|
+
if (persistedDialog) return persistedDialog;
|
|
404
|
+
return existingDialog;
|
|
405
|
+
} catch {
|
|
406
|
+
return getDialogConfig(getState(), resolvedDialogKey);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
var logQuickChatPerfStage = (startedAt, stage, details = {}) => {
|
|
410
|
+
if (!startedAt) return;
|
|
411
|
+
const now = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
412
|
+
console.info("[QuickChatPerf]", {
|
|
413
|
+
stage,
|
|
414
|
+
elapsedMs: now - startedAt,
|
|
415
|
+
...typeof performance !== "undefined" ? { atMs: now } : {},
|
|
416
|
+
...details
|
|
417
|
+
});
|
|
418
|
+
};
|
|
419
|
+
var resolveBrowseContextPrefix = async (message) => {
|
|
420
|
+
try {
|
|
421
|
+
if (typeof window === "undefined" || typeof location === "undefined") return "";
|
|
422
|
+
if (typeof process !== "undefined" && (process.env?.NODE_ENV === "test" || process.env?.BUN_TEST)) return "";
|
|
423
|
+
const host = location.hostname;
|
|
424
|
+
if (host !== "127.0.0.1" && host !== "localhost") return "";
|
|
425
|
+
if (typeof fetch !== "function" || typeof AbortSignal?.timeout !== "function") return "";
|
|
426
|
+
const response = await fetch("/api/desktop/browse-context", {
|
|
427
|
+
method: "POST",
|
|
428
|
+
headers: { "Content-Type": "application/json" },
|
|
429
|
+
body: JSON.stringify({ message }),
|
|
430
|
+
signal: AbortSignal.timeout(2e3)
|
|
431
|
+
});
|
|
432
|
+
if (!response.ok) return "";
|
|
433
|
+
const payload = await response.json();
|
|
434
|
+
if (!payload.context || !payload.context.url) return "";
|
|
435
|
+
const ctx = payload.context;
|
|
436
|
+
const parts = [`[\u5F53\u524D\u6D4F\u89C8\u4E0A\u4E0B\u6587]`, `URL: ${ctx.url}`, `\u6807\u9898: ${ctx.title}`];
|
|
437
|
+
if (ctx.textSnippet) parts.push(`\u6458\u8981: ${ctx.textSnippet.slice(0, 2e3)}`);
|
|
438
|
+
return parts.join("\n");
|
|
439
|
+
} catch {
|
|
440
|
+
return "";
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
var finalizeQuickChatStreamStartupFailure = async (dispatch, dialogConfig, agentKey) => {
|
|
444
|
+
const dialogKey = dialogConfig.dbKey;
|
|
445
|
+
const dialogId = dialogConfig.id ?? (dialogKey ? extractCustomId(dialogKey) : "");
|
|
446
|
+
const { key: msgKey, messageId } = createDialogMessageKeyAndId(dialogId);
|
|
447
|
+
await dispatch(
|
|
448
|
+
messageStreamEnd({
|
|
449
|
+
finalContentBuffer: [
|
|
450
|
+
{
|
|
451
|
+
type: "text",
|
|
452
|
+
text: "[\u9519\u8BEF: \u672A\u80FD\u542F\u52A8\u6A21\u578B\u56DE\u590D\uFF0C\u8BF7\u91CD\u8BD5\u3002]"
|
|
453
|
+
}
|
|
454
|
+
],
|
|
455
|
+
totalUsage: null,
|
|
456
|
+
msgKey,
|
|
457
|
+
agentConfig: {
|
|
458
|
+
dbKey: agentKey
|
|
459
|
+
},
|
|
460
|
+
dialogId,
|
|
461
|
+
dialogKey: dialogKey ?? "",
|
|
462
|
+
messageId,
|
|
463
|
+
reasoningBuffer: ""
|
|
464
|
+
})
|
|
465
|
+
).unwrap?.();
|
|
466
|
+
};
|
|
467
|
+
var finalizeSendFailureInDialog = async (dispatch, dialogConfig, agentKey, errorInput) => {
|
|
468
|
+
const dialogKey = dialogConfig.dbKey;
|
|
469
|
+
const dialogId = dialogConfig.id ?? (dialogKey ? extractCustomId(dialogKey) : "");
|
|
470
|
+
const { key: msgKey, messageId } = createDialogMessageKeyAndId(dialogId);
|
|
471
|
+
const parsed = parseSendError(errorInput);
|
|
472
|
+
const errorMeta = {
|
|
473
|
+
kind: parsed.kind,
|
|
474
|
+
retryable: parsed.retryable,
|
|
475
|
+
stage: parsed.stage,
|
|
476
|
+
summary: parsed.summary,
|
|
477
|
+
actionHint: parsed.actionHint,
|
|
478
|
+
validationUrl: parsed.validationUrl,
|
|
479
|
+
validationLinkText: parsed.validationLinkText,
|
|
480
|
+
extraLinks: parsed.extraLinks,
|
|
481
|
+
fallbackText: parsed.fallbackText,
|
|
482
|
+
rawError: parsed.fallbackText
|
|
483
|
+
};
|
|
484
|
+
await dispatch(
|
|
485
|
+
messageStreamEnd({
|
|
486
|
+
finalContentBuffer: [
|
|
487
|
+
{
|
|
488
|
+
type: "text",
|
|
489
|
+
text: buildSendErrorMessageMarkdown(parsed)
|
|
490
|
+
}
|
|
491
|
+
],
|
|
492
|
+
totalUsage: null,
|
|
493
|
+
msgKey,
|
|
494
|
+
agentConfig: {
|
|
495
|
+
dbKey: agentKey
|
|
496
|
+
},
|
|
497
|
+
dialogId,
|
|
498
|
+
dialogKey: dialogKey ?? "",
|
|
499
|
+
messageId,
|
|
500
|
+
reasoningBuffer: "",
|
|
501
|
+
messageMetadata: {
|
|
502
|
+
errorMeta
|
|
503
|
+
}
|
|
504
|
+
})
|
|
505
|
+
).unwrap?.();
|
|
506
|
+
};
|
|
507
|
+
var handleSendMessageAction = async (args, { dispatch, getState, rejectWithValue }) => {
|
|
508
|
+
let dialogConfig = null;
|
|
509
|
+
let agentKeyToUse;
|
|
510
|
+
try {
|
|
511
|
+
logQuickChatPerfStage(args.quickChatPerfStartedAt, "handle-send-message-entered", {
|
|
512
|
+
dialogKey: args.dialogKey ?? null
|
|
513
|
+
});
|
|
514
|
+
dialogConfig = await ensureDialogConfig(dispatch, getState, args.dialogKey);
|
|
515
|
+
if (!dialogConfig) {
|
|
516
|
+
throw new Error(
|
|
517
|
+
"handleSendMessage: Dialog configuration is missing."
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
logQuickChatPerfStage(args.quickChatPerfStartedAt, "handle-send-message-dialog-ready", {
|
|
521
|
+
dialogKey: dialogConfig.dbKey,
|
|
522
|
+
cybotCount: dialogConfig.cybots?.length ?? 0
|
|
523
|
+
});
|
|
524
|
+
let effectiveRawUserInput = args.userInput;
|
|
525
|
+
if (args.isRetry) {
|
|
526
|
+
if (!effectiveRawUserInput) {
|
|
527
|
+
const dialogId = dialogConfig.id ?? (dialogConfig.dbKey ? extractCustomId(dialogConfig.dbKey) : "");
|
|
528
|
+
const state = getState();
|
|
529
|
+
try {
|
|
530
|
+
const messages = selectAllMsgs(state, dialogId);
|
|
531
|
+
if (Array.isArray(messages) && messages.length > 0) {
|
|
532
|
+
let targetIndex = messages.length - 1;
|
|
533
|
+
if (args.retryMessageId) {
|
|
534
|
+
const foundIdx = messages.findIndex((m) => m?.id === args.retryMessageId);
|
|
535
|
+
if (foundIdx >= 0) {
|
|
536
|
+
targetIndex = foundIdx;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
for (let i = targetIndex; i >= 0; i--) {
|
|
540
|
+
const m = messages[i];
|
|
541
|
+
if (m?.role === "user" && m.content) {
|
|
542
|
+
effectiveRawUserInput = m.content;
|
|
543
|
+
break;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
} catch {
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
if (!effectiveRawUserInput || typeof effectiveRawUserInput === "string" && !effectiveRawUserInput.trim() || Array.isArray(effectiveRawUserInput) && effectiveRawUserInput.length === 0) {
|
|
551
|
+
console.warn("[handleSendMessage] isRetry: No preceding user message found to retry.");
|
|
552
|
+
return rejectWithValue("\u672A\u627E\u5230\u53EF\u91CD\u8BD5\u7684\u7528\u6237\u8F93\u5165");
|
|
553
|
+
}
|
|
554
|
+
} else {
|
|
555
|
+
await dispatch(
|
|
556
|
+
prepareAndPersistUserMessage({
|
|
557
|
+
userInput: args.userInput ?? "",
|
|
558
|
+
dialogConfig
|
|
559
|
+
})
|
|
560
|
+
).unwrap();
|
|
561
|
+
logQuickChatPerfStage(args.quickChatPerfStartedAt, "handle-send-message-user-persisted", {
|
|
562
|
+
dialogKey: dialogConfig.dbKey
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
const resolvedContext = resolveHandleSendMessageContext({
|
|
566
|
+
dialogConfig,
|
|
567
|
+
targetAgentKey: args.targetAgentKey,
|
|
568
|
+
runtimeOptions: args.runtimeOptions
|
|
569
|
+
});
|
|
570
|
+
agentKeyToUse = resolvedContext.agentKeyToUse;
|
|
571
|
+
const agentConfigToUse = resolvedContext.agentConfigToUse;
|
|
572
|
+
const effectiveRuntimeOptions = resolvedContext.effectiveRuntimeOptions;
|
|
573
|
+
if (!agentKeyToUse) {
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
const userInputText = typeof effectiveRawUserInput === "string" ? effectiveRawUserInput : "";
|
|
577
|
+
const isDesktopContext = typeof window !== "undefined" && typeof location !== "undefined" && (location.hostname === "127.0.0.1" || location.hostname === "localhost");
|
|
578
|
+
const browseContextPrefix = isDesktopContext ? await resolveBrowseContextPrefix(userInputText) : "";
|
|
579
|
+
const effectiveUserInput = browseContextPrefix ? `${browseContextPrefix}
|
|
580
|
+
|
|
581
|
+
${userInputText}` : effectiveRawUserInput ?? "";
|
|
582
|
+
let streamResult;
|
|
583
|
+
const maxStartupAttempts = 2;
|
|
584
|
+
for (let attempt = 1; attempt <= maxStartupAttempts; attempt++) {
|
|
585
|
+
try {
|
|
586
|
+
streamResult = await dispatch(
|
|
587
|
+
streamAgentChatTurn({
|
|
588
|
+
agentKey: agentKeyToUse,
|
|
589
|
+
...agentConfigToUse ? { agentConfig: agentConfigToUse } : {},
|
|
590
|
+
userInput: effectiveUserInput,
|
|
591
|
+
dialogKey: dialogConfig.dbKey,
|
|
592
|
+
parentMessageId: void 0,
|
|
593
|
+
runtimeOptions: effectiveRuntimeOptions,
|
|
594
|
+
quickChatPerfStartedAt: args.quickChatPerfStartedAt
|
|
595
|
+
})
|
|
596
|
+
).unwrap();
|
|
597
|
+
if (streamResult && typeof streamResult === "object" && streamResult.aborted) {
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
break;
|
|
601
|
+
} catch (turnErr) {
|
|
602
|
+
const parsed = parseSendError(turnErr);
|
|
603
|
+
if (attempt < maxStartupAttempts && (parsed.kind === "network" || parsed.kind === "timeout")) {
|
|
604
|
+
const delayMs = attempt * 800;
|
|
605
|
+
const retryAbortController = new AbortController();
|
|
606
|
+
const retryKey = `retry:${dialogConfig.dbKey ?? "global"}`;
|
|
607
|
+
try {
|
|
608
|
+
dispatch(
|
|
609
|
+
addActiveController({
|
|
610
|
+
messageId: retryKey,
|
|
611
|
+
controller: retryAbortController,
|
|
612
|
+
dialogKey: dialogConfig.dbKey
|
|
613
|
+
})
|
|
614
|
+
);
|
|
615
|
+
await waitForAbortableDelay(delayMs, retryAbortController.signal);
|
|
616
|
+
} catch {
|
|
617
|
+
} finally {
|
|
618
|
+
dispatch(
|
|
619
|
+
removeActiveController({
|
|
620
|
+
messageId: retryKey,
|
|
621
|
+
dialogKey: dialogConfig.dbKey
|
|
622
|
+
})
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
if (retryAbortController.signal.aborted) {
|
|
626
|
+
console.info("[handleSendMessage] Auto-retry cancelled by user stop during backoff window.");
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
throw turnErr;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
if (args.quickChatPerfStartedAt && streamResult === void 0) {
|
|
635
|
+
logQuickChatPerfStage(args.quickChatPerfStartedAt, "handle-send-message-stream-empty", {
|
|
636
|
+
dialogKey: dialogConfig.dbKey,
|
|
637
|
+
agentKey: agentKeyToUse
|
|
638
|
+
});
|
|
639
|
+
await finalizeQuickChatStreamStartupFailure(
|
|
640
|
+
dispatch,
|
|
641
|
+
dialogConfig,
|
|
642
|
+
agentKeyToUse
|
|
643
|
+
);
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
logQuickChatPerfStage(args.quickChatPerfStartedAt, "handle-send-message-stream-finished", {
|
|
647
|
+
dialogKey: dialogConfig.dbKey,
|
|
648
|
+
agentKey: agentKeyToUse
|
|
649
|
+
});
|
|
650
|
+
return;
|
|
651
|
+
} catch (error) {
|
|
652
|
+
console.error("handleSendMessage failed:", error);
|
|
653
|
+
const errorMessage = error instanceof Error ? error.message : typeof error === "string" ? error : error?.message || error?.error || String(error);
|
|
654
|
+
try {
|
|
655
|
+
if (dialogConfig && agentKeyToUse) {
|
|
656
|
+
await finalizeSendFailureInDialog(
|
|
657
|
+
dispatch,
|
|
658
|
+
dialogConfig,
|
|
659
|
+
agentKeyToUse,
|
|
660
|
+
error
|
|
661
|
+
);
|
|
662
|
+
return rejectWithValue({
|
|
663
|
+
__errorInDialog: true,
|
|
664
|
+
message: errorMessage
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
} catch (writeError) {
|
|
668
|
+
console.error("handleSendMessage: failed to write error into dialog:", writeError);
|
|
669
|
+
}
|
|
670
|
+
return rejectWithValue(errorMessage);
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
export {
|
|
674
|
+
handleSendMessageAction
|
|
675
|
+
};
|