nolo-cli 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_executeModel-UD44KGZ4.js +203 -0
- package/action-ZJWE3Y5S.js +28 -0
- package/addContentAction-TVDBNJM5.js +26 -0
- package/addDialogAgentAction-EKH774VT.js +68 -0
- package/agentDeleteCommand-TCPEFJTF.js +327 -0
- package/agentEmailCommands-CZ3UILZ4.js +626 -0
- package/agentListCommands-SJKO2FFB.js +223 -0
- package/agentMachineCommands-PSNABISZ.js +425 -0
- package/agentPullCommand-O2MTUAFR.js +122 -0
- package/agentRecordCommands-MH2JKFHS.js +94 -0
- package/agentRunCommand-4KH6MIZR.js +110 -0
- package/agentRunControl-K4VKNEHF.js +57 -0
- package/agentRuntimeLocal-SKHJUWSS.js +104 -0
- package/agentSlice-3WXXN4VK.js +42 -0
- package/authCommand-PXFX6JDT.js +581 -0
- package/authCommands-356AYWEK.js +35 -0
- package/chunk-2EISRLRC.js +238 -0
- package/chunk-2FTTDCD4.js +675 -0
- package/chunk-2K2ECKSG.js +222 -0
- package/chunk-2PUGVR6E.js +19 -0
- package/chunk-3ASDTTEI.js +1774 -0
- package/chunk-3EUW3WEO.js +8 -0
- package/chunk-3LY4F7SV.js +9293 -0
- package/chunk-3TZDXYSF.js +71 -0
- package/chunk-3WYQEUBI.js +34 -0
- package/chunk-4CQLVGRV.js +50 -0
- package/chunk-4IJYA27C.js +342 -0
- package/chunk-4K2KKCSD.js +577 -0
- package/chunk-4SN6J65J.js +38 -0
- package/chunk-4VNS5WPM.js +42 -0
- package/chunk-4ZDM73SD.js +34 -0
- package/chunk-5CS33IBL.js +301 -0
- package/chunk-5KLGBAAR.js +386 -0
- package/chunk-5MIDPSSK.js +206 -0
- package/chunk-5MMAK75Q.js +15 -0
- package/chunk-5PJ3VWCS.js +360 -0
- package/chunk-63SLEOLK.js +175 -0
- package/chunk-63W5N6P3.js +150 -0
- package/chunk-6GANEXVO.js +231 -0
- package/chunk-6HYVJV7B.js +102 -0
- package/chunk-6WD3OOJS.js +20 -0
- package/chunk-7OOXPE3N.js +628 -0
- package/chunk-7QRKCBOP.js +1078 -0
- package/chunk-ATNTHIZI.js +13 -0
- package/chunk-AUQ747NZ.js +902 -0
- package/chunk-AVMKZHBC.js +85 -0
- package/chunk-AZPCASRE.js +36 -0
- package/chunk-BBYVOSU2.js +792 -0
- package/chunk-C3RUNRHT.js +51 -0
- package/chunk-CF2WZF4N.js +134 -0
- package/chunk-CF7PE763.js +10 -0
- package/chunk-CKOJQDKR.js +198 -0
- package/chunk-COMXDWNM.js +807 -0
- package/chunk-CPB2YM4D.js +171 -0
- package/chunk-CWMSB67P.js +34 -0
- package/chunk-DCOA4QSN.js +105 -0
- package/chunk-DFFIZ25G.js +30 -0
- package/chunk-DWLEOOGR.js +8 -0
- package/chunk-DZ3XJVET.js +231 -0
- package/chunk-EHLHSX7R.js +1433 -0
- package/chunk-ELRRLDWI.js +478 -0
- package/chunk-EXTIQUCI.js +482 -0
- package/chunk-EYEEHCU4.js +3066 -0
- package/chunk-G3SUCT4W.js +8 -0
- package/chunk-G43KEVSC.js +1447 -0
- package/chunk-GAKEBQD6.js +30 -0
- package/chunk-GBRG75BQ.js +86 -0
- package/chunk-GG4AJPSR.js +191 -0
- package/chunk-H33743XH.js +25 -0
- package/chunk-HNMXYYJR.js +12 -0
- package/chunk-I42VC5KR.js +15 -0
- package/chunk-IDZTNRP2.js +85 -0
- package/chunk-ISNCLGUZ.js +146 -0
- package/chunk-IWX4UW2E.js +548 -0
- package/chunk-JBTJAPUF.js +35 -0
- package/chunk-JEXVIMYZ.js +55 -0
- package/chunk-JRKKFRAV.js +537 -0
- package/chunk-JZPBVBIY.js +94 -0
- package/chunk-KKY4B2Q2.js +21 -0
- package/chunk-KOCA5FCS.js +4750 -0
- package/chunk-KQHGZWSV.js +63 -0
- package/chunk-KTVVPRJS.js +138 -0
- package/chunk-KUG52IAP.js +8 -0
- package/chunk-KX6YBIHG.js +8 -0
- package/chunk-LARL2V6G.js +9017 -0
- package/chunk-LCBAMY2M.js +60 -0
- package/chunk-LM6IYQ3F.js +16 -0
- package/chunk-M76ECQRD.js +13658 -0
- package/chunk-MGOJ5R6J.js +113 -0
- package/chunk-MKMWT7SA.js +27196 -0
- package/chunk-MRC4Q34M.js +188 -0
- package/chunk-OLZBQWZU.js +6 -0
- package/chunk-OPZYGHUC.js +89 -0
- package/chunk-OWOHNGCN.js +50 -0
- package/chunk-PAKN26FP.js +239 -0
- package/chunk-PCWC3JTN.js +91 -0
- package/chunk-PG5PNA7Y.js +939 -0
- package/chunk-Q2YZULBH.js +104 -0
- package/chunk-QSJ3HFEF.js +8 -0
- package/chunk-QYXLLLGL.js +4519 -0
- package/chunk-ROWQEJRP.js +139 -0
- package/chunk-S7Z2HMCN.js +25 -0
- package/chunk-SBR32ZZS.js +1901 -0
- package/chunk-SH2CFQOH.js +3391 -0
- package/chunk-SL35K7AH.js +226 -0
- package/chunk-TILFE6LV.js +381 -0
- package/chunk-TSS3XJY4.js +2052 -0
- package/chunk-U4TRT5V4.js +246 -0
- package/chunk-U6VC4MU4.js +8 -0
- package/chunk-UAD2WT54.js +64 -0
- package/chunk-UUJDGGAK.js +421 -0
- package/chunk-VF4K2QE6.js +21 -0
- package/chunk-VHBWHNVT.js +59 -0
- package/chunk-VIDPVFP3.js +20 -0
- package/chunk-VP4WJWKW.js +8882 -0
- package/chunk-W4NVOSFF.js +37 -0
- package/chunk-WKM6FH35.js +190 -0
- package/chunk-WWC7I6TA.js +8 -0
- package/chunk-X7W4TNB4.js +1550 -0
- package/chunk-XE635NI4.js +1948 -0
- package/chunk-XKIMRZO2.js +221 -0
- package/chunk-XS466O7S.js +933 -0
- package/chunk-Y5GCAMGP.js +9 -0
- package/chunk-YBWOP46I.js +3272 -0
- package/chunk-YPRZSPF3.js +148 -0
- package/chunk-YYUCRDOK.js +69 -0
- package/chunk-Z4NR32XR.js +50 -0
- package/chunk-ZIG5LJ7X.js +24765 -0
- package/chunk-ZNFJWEN4.js +56 -0
- package/chunk-ZQ2UM4KG.js +2878 -0
- package/cliExecutor-DNE7TCC4.js +36 -0
- package/clipboardy-BVE3LVEH.js +12001 -0
- package/createAgentAutomationAction-63OIP6X5.js +866 -0
- package/createDialogAction-ZLYZDYBB.js +54 -0
- package/createPageAction-AL5FSDCK.js +171 -0
- package/db-HCJ5PRB5.js +271 -0
- package/dbSlice-PR44QPXY.js +60 -0
- package/deleteFile-4SKGPHOZ.js +41 -0
- package/dialogCommands-F6YI5742.js +63 -0
- package/dialogSlice-JSBNZRLR.js +148 -0
- package/docCreateCommands-4CTO7ERT.js +219 -0
- package/docDeleteCommands-VBWERDRG.js +180 -0
- package/docReadCommands-KNP4MFYB.js +133 -0
- package/docStore-ADP5VYY4.js +98 -0
- package/docUpdateCommands-4BCBJQHA.js +317 -0
- package/fetchMessages-U6ZHN56A.js +17 -0
- package/getPricing-3E6UNPKL.js +30 -0
- package/handleSendMessageAction-IJDQ6ARA.js +185 -0
- package/index.js +188 -112943
- package/lib-FYYBQIXS.js +19839 -0
- package/localDialogRead-Z5UTAJPU.js +26 -0
- package/localFirstLog-DHNOY2NA.js +19 -0
- package/localRuntimeAuthority-TEGCOWX4.js +471 -0
- package/localRuntimeDb-LGDF6FQP.js +12 -0
- package/machineCommands-EA3M4XTN.js +779 -0
- package/machineInfo-M6KB6HZN.js +10 -0
- package/machineWsRunDispatch-NAPKE5ZA.js +110 -0
- package/memoryCommands-O4MIPIWQ.js +476 -0
- package/models-4OPOOLFS.js +9 -0
- package/offlineMarxistsAgentCommand-BCPJITJL.js +242 -0
- package/package.json +3 -25
- package/read-RIJCIVKX.js +17 -0
- package/readDocTool-GZD2N3LO.js +16 -0
- package/readlineWorkspace-KMWT4T4S.js +5509 -0
- package/removeDialogAgentAction-GJQJNDW6.js +73 -0
- package/runAgentClientLoop-U5Q6NDTJ.js +291 -0
- package/runtimeDoctorCommands-LRHLPDRC.js +289 -0
- package/setDialogExtraReferencesAction-M7OQG54N.js +60 -0
- package/setPrimaryDialogAgentAction-46UNFJDL.js +80 -0
- package/settingSlice-FVUUH4JA.js +199 -0
- package/skillSummaryMarker-42HKSXYY.js +9 -0
- package/slateToRenderMarkdown-Y5IYN73U.js +7 -0
- package/slateUtils-2M7MUTWX.js +19 -0
- package/spaceCommands-E2CFRPZJ.js +454 -0
- package/spaceSlice-L3R6IMXE.js +147 -0
- package/streamAgentChatTurn-UBDAOQWE.js +4528 -0
- package/tableCommands-GOFP7QKA.js +1286 -0
- package/toolApiClient-QI3YBNWB.js +26 -0
- package/tools-TMJXZTCA.js +85 -0
- package/tuiSummaryLlmCaller-RV3THLZF.js +78 -0
- package/understanding-GQKNDDWM.js +271 -0
- package/updateCommands-VOSPKXFF.js +31 -0
- package/updateDialogTitleAction-ZTWRDXI2.js +188 -0
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateCloudflareEmailRoutingToken,
|
|
3
|
+
upsertEnvVariable
|
|
4
|
+
} from "./chunk-4IJYA27C.js";
|
|
5
|
+
import {
|
|
6
|
+
positionalArgs,
|
|
7
|
+
readFlagValue
|
|
8
|
+
} from "./chunk-DZ3XJVET.js";
|
|
9
|
+
import {
|
|
10
|
+
runAgentCreateCommand
|
|
11
|
+
} from "./chunk-2K2ECKSG.js";
|
|
12
|
+
import "./chunk-LARL2V6G.js";
|
|
13
|
+
import "./chunk-EHLHSX7R.js";
|
|
14
|
+
import {
|
|
15
|
+
getReadableCliDb
|
|
16
|
+
} from "./chunk-W4NVOSFF.js";
|
|
17
|
+
import {
|
|
18
|
+
fetchWithTransportFallback,
|
|
19
|
+
resolveAgentRecordFromHybridStore
|
|
20
|
+
} from "./chunk-7OOXPE3N.js";
|
|
21
|
+
import "./chunk-2PUGVR6E.js";
|
|
22
|
+
import {
|
|
23
|
+
resolveCliAgentKeyInput
|
|
24
|
+
} from "./chunk-VHBWHNVT.js";
|
|
25
|
+
import "./chunk-6GANEXVO.js";
|
|
26
|
+
import "./chunk-X7W4TNB4.js";
|
|
27
|
+
import "./chunk-ATNTHIZI.js";
|
|
28
|
+
import "./chunk-JBTJAPUF.js";
|
|
29
|
+
import "./chunk-CPB2YM4D.js";
|
|
30
|
+
import "./chunk-C3RUNRHT.js";
|
|
31
|
+
import "./chunk-MKMWT7SA.js";
|
|
32
|
+
import "./chunk-GAKEBQD6.js";
|
|
33
|
+
import "./chunk-KQHGZWSV.js";
|
|
34
|
+
import "./chunk-XKIMRZO2.js";
|
|
35
|
+
import "./chunk-3LY4F7SV.js";
|
|
36
|
+
import "./chunk-VP4WJWKW.js";
|
|
37
|
+
import "./chunk-63W5N6P3.js";
|
|
38
|
+
import "./chunk-UUJDGGAK.js";
|
|
39
|
+
import "./chunk-PG5PNA7Y.js";
|
|
40
|
+
import "./chunk-ZQ2UM4KG.js";
|
|
41
|
+
import "./chunk-OWOHNGCN.js";
|
|
42
|
+
import "./chunk-Q2YZULBH.js";
|
|
43
|
+
import "./chunk-ZIG5LJ7X.js";
|
|
44
|
+
import "./chunk-4ZDM73SD.js";
|
|
45
|
+
import "./chunk-MRC4Q34M.js";
|
|
46
|
+
import "./chunk-PCWC3JTN.js";
|
|
47
|
+
import "./chunk-CWMSB67P.js";
|
|
48
|
+
import "./chunk-4K2KKCSD.js";
|
|
49
|
+
import "./chunk-KTVVPRJS.js";
|
|
50
|
+
import "./chunk-Z4NR32XR.js";
|
|
51
|
+
import "./chunk-M76ECQRD.js";
|
|
52
|
+
import "./chunk-YYUCRDOK.js";
|
|
53
|
+
import "./chunk-MGOJ5R6J.js";
|
|
54
|
+
import "./chunk-UAD2WT54.js";
|
|
55
|
+
import "./chunk-DCOA4QSN.js";
|
|
56
|
+
import "./chunk-IDZTNRP2.js";
|
|
57
|
+
import {
|
|
58
|
+
parseUserIdFromAuthToken,
|
|
59
|
+
resolveAuthToken,
|
|
60
|
+
resolveServerUrl
|
|
61
|
+
} from "./chunk-ISNCLGUZ.js";
|
|
62
|
+
import "./chunk-OLZBQWZU.js";
|
|
63
|
+
import "./chunk-YBWOP46I.js";
|
|
64
|
+
import "./chunk-5KLGBAAR.js";
|
|
65
|
+
import "./chunk-ZNFJWEN4.js";
|
|
66
|
+
import "./chunk-TILFE6LV.js";
|
|
67
|
+
import "./chunk-XS466O7S.js";
|
|
68
|
+
import "./chunk-OPZYGHUC.js";
|
|
69
|
+
import "./chunk-PAKN26FP.js";
|
|
70
|
+
import "./chunk-JRKKFRAV.js";
|
|
71
|
+
import "./chunk-AUQ747NZ.js";
|
|
72
|
+
import "./chunk-5MMAK75Q.js";
|
|
73
|
+
import "./chunk-BBYVOSU2.js";
|
|
74
|
+
import "./chunk-5CS33IBL.js";
|
|
75
|
+
import {
|
|
76
|
+
createOAuthTokenStore
|
|
77
|
+
} from "./chunk-JZPBVBIY.js";
|
|
78
|
+
import "./chunk-IWX4UW2E.js";
|
|
79
|
+
import "./chunk-5MIDPSSK.js";
|
|
80
|
+
import "./chunk-DFFIZ25G.js";
|
|
81
|
+
import "./chunk-3ASDTTEI.js";
|
|
82
|
+
import "./chunk-DWLEOOGR.js";
|
|
83
|
+
import {
|
|
84
|
+
toErrorMessage
|
|
85
|
+
} from "./chunk-HNMXYYJR.js";
|
|
86
|
+
import "./chunk-H33743XH.js";
|
|
87
|
+
import "./chunk-LM6IYQ3F.js";
|
|
88
|
+
import "./chunk-63SLEOLK.js";
|
|
89
|
+
import "./chunk-TSS3XJY4.js";
|
|
90
|
+
import "./chunk-Y5GCAMGP.js";
|
|
91
|
+
import "./chunk-COMXDWNM.js";
|
|
92
|
+
import "./chunk-AZPCASRE.js";
|
|
93
|
+
import "./chunk-2EISRLRC.js";
|
|
94
|
+
import "./chunk-KX6YBIHG.js";
|
|
95
|
+
import {
|
|
96
|
+
createAgentKey
|
|
97
|
+
} from "./chunk-SH2CFQOH.js";
|
|
98
|
+
import "./chunk-I42VC5KR.js";
|
|
99
|
+
import "./chunk-WWC7I6TA.js";
|
|
100
|
+
import "./chunk-QSJ3HFEF.js";
|
|
101
|
+
import "./chunk-ELRRLDWI.js";
|
|
102
|
+
import "./chunk-EYEEHCU4.js";
|
|
103
|
+
import "./chunk-QYXLLLGL.js";
|
|
104
|
+
import "./chunk-GBRG75BQ.js";
|
|
105
|
+
import "./chunk-4SN6J65J.js";
|
|
106
|
+
import "./chunk-LCBAMY2M.js";
|
|
107
|
+
import "./chunk-3EUW3WEO.js";
|
|
108
|
+
import "./chunk-U6VC4MU4.js";
|
|
109
|
+
import "./chunk-CF7PE763.js";
|
|
110
|
+
import "./chunk-G3SUCT4W.js";
|
|
111
|
+
import {
|
|
112
|
+
isRecord
|
|
113
|
+
} from "./chunk-KUG52IAP.js";
|
|
114
|
+
import "./chunk-4VNS5WPM.js";
|
|
115
|
+
|
|
116
|
+
// packages/cli/agentEmailRpc.ts
|
|
117
|
+
function readRpcErrorMessage(body, status) {
|
|
118
|
+
if (isRecord(body) && "message" in body) {
|
|
119
|
+
const message = body.message;
|
|
120
|
+
if (typeof message === "string" && message.trim()) {
|
|
121
|
+
return message;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return `RPC failed (${status})`;
|
|
125
|
+
}
|
|
126
|
+
function readOptionalString(body, key) {
|
|
127
|
+
const value = body[key];
|
|
128
|
+
return typeof value === "string" ? value : void 0;
|
|
129
|
+
}
|
|
130
|
+
function readNullableString(body, key) {
|
|
131
|
+
const value = body[key];
|
|
132
|
+
if (value === null || value === void 0) return null;
|
|
133
|
+
return typeof value === "string" ? value : null;
|
|
134
|
+
}
|
|
135
|
+
function parseAgentEmailIdentityRpcData(body) {
|
|
136
|
+
if (!isRecord(body)) {
|
|
137
|
+
throw new Error("RPC response was not a JSON object");
|
|
138
|
+
}
|
|
139
|
+
const agentId = body.agentId;
|
|
140
|
+
const emailAddress = body.emailAddress;
|
|
141
|
+
if (typeof agentId !== "string" || !agentId.trim()) {
|
|
142
|
+
throw new Error("RPC response missing agentId");
|
|
143
|
+
}
|
|
144
|
+
if (typeof emailAddress !== "string" || !emailAddress.trim()) {
|
|
145
|
+
throw new Error("RPC response missing emailAddress");
|
|
146
|
+
}
|
|
147
|
+
const parsed = {
|
|
148
|
+
agentId,
|
|
149
|
+
emailAddress,
|
|
150
|
+
readinessStatus: readNullableString(body, "readinessStatus"),
|
|
151
|
+
ingressReadyAt: readNullableString(body, "ingressReadyAt"),
|
|
152
|
+
lastWarmupAt: readNullableString(body, "lastWarmupAt"),
|
|
153
|
+
lastWarmupError: readNullableString(body, "lastWarmupError")
|
|
154
|
+
};
|
|
155
|
+
const localPart = readOptionalString(body, "localPart");
|
|
156
|
+
const domain = readOptionalString(body, "domain");
|
|
157
|
+
const provider = readOptionalString(body, "provider");
|
|
158
|
+
const delegationResourcePrefix = readOptionalString(
|
|
159
|
+
body,
|
|
160
|
+
"delegationResourcePrefix"
|
|
161
|
+
);
|
|
162
|
+
if (localPart) parsed.localPart = localPart;
|
|
163
|
+
if (domain) parsed.domain = domain;
|
|
164
|
+
if (provider) parsed.provider = provider;
|
|
165
|
+
if ("purpose" in body) {
|
|
166
|
+
const purpose = body.purpose;
|
|
167
|
+
parsed.purpose = purpose === null || purpose === void 0 ? null : typeof purpose === "string" ? purpose : null;
|
|
168
|
+
}
|
|
169
|
+
if (delegationResourcePrefix) {
|
|
170
|
+
parsed.delegationResourcePrefix = delegationResourcePrefix;
|
|
171
|
+
}
|
|
172
|
+
return parsed;
|
|
173
|
+
}
|
|
174
|
+
function readAgentRecordFromRpcBody(body) {
|
|
175
|
+
if (!isRecord(body) || !("agent" in body)) {
|
|
176
|
+
throw new Error("RPC response missing agent record");
|
|
177
|
+
}
|
|
178
|
+
const agent = body.agent;
|
|
179
|
+
if (!isRecord(agent)) {
|
|
180
|
+
throw new Error("RPC response agent field is invalid");
|
|
181
|
+
}
|
|
182
|
+
return agent;
|
|
183
|
+
}
|
|
184
|
+
async function resolveAgentIdForEmailRpc(args) {
|
|
185
|
+
const resolvedInput = resolveCliAgentKeyInput(args.agentInput);
|
|
186
|
+
if (resolvedInput.startsWith("agent-")) {
|
|
187
|
+
return resolvedInput;
|
|
188
|
+
}
|
|
189
|
+
const userId = parseUserIdFromAuthToken(args.authToken);
|
|
190
|
+
if (!userId) {
|
|
191
|
+
throw new Error("Could not read userId from auth token");
|
|
192
|
+
}
|
|
193
|
+
const resolved = await resolveAgentRecordFromHybridStore({
|
|
194
|
+
agentInput: args.agentInput,
|
|
195
|
+
cliArgs: args.cliArgs,
|
|
196
|
+
env: args.env,
|
|
197
|
+
db: args.db,
|
|
198
|
+
fetchImpl: args.fetchImpl,
|
|
199
|
+
fallbackFetchImpl: args.fallbackFetchImpl
|
|
200
|
+
});
|
|
201
|
+
if (resolved?.agentKey) {
|
|
202
|
+
return resolved.agentKey;
|
|
203
|
+
}
|
|
204
|
+
return createAgentKey.private(userId, resolvedInput);
|
|
205
|
+
}
|
|
206
|
+
async function postAgentEmailRpc(args) {
|
|
207
|
+
const baseUrl = args.cliArgs ? resolveServerUrl(args.cliArgs, args.env) : resolveServerUrl(args.env);
|
|
208
|
+
const url = `${baseUrl}/rpc/${args.method}`;
|
|
209
|
+
const response = await fetchWithTransportFallback(
|
|
210
|
+
url,
|
|
211
|
+
{
|
|
212
|
+
method: "POST",
|
|
213
|
+
headers: {
|
|
214
|
+
Authorization: `Bearer ${args.authToken}`,
|
|
215
|
+
"Content-Type": "application/json"
|
|
216
|
+
},
|
|
217
|
+
body: JSON.stringify(args.body)
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
fetchImpl: args.fetchImpl,
|
|
221
|
+
fallbackFetchImpl: args.fallbackFetchImpl
|
|
222
|
+
}
|
|
223
|
+
);
|
|
224
|
+
const raw = await response.json().catch(() => null);
|
|
225
|
+
if (!response.ok) {
|
|
226
|
+
throw new Error(readRpcErrorMessage(raw, response.status));
|
|
227
|
+
}
|
|
228
|
+
const data = parseAgentEmailIdentityRpcData(raw);
|
|
229
|
+
const agent = readAgentRecordFromRpcBody(raw);
|
|
230
|
+
return { data, agent, baseUrl };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// packages/cli/agentEmailCommands.ts
|
|
234
|
+
var PROVISION_USAGE = "Usage: nolo agent email provision <agent> [--purpose <label>] [--local-part <part>] [--domain <domain>] [--provider <name>] [--no-primary] [--cloudflare-oauth]\n";
|
|
235
|
+
var BIND_USAGE = "Usage: nolo agent email bind <agent> --email <address> [--provider <name>] [--cloudflare-oauth]\n";
|
|
236
|
+
var TRANSFER_USAGE = "Usage: nolo agent email transfer --from <source-agent> --to <target-agent> --email <address> [--no-move-history] [--primary|--no-primary] [--cloudflare-oauth]\n \u6CE8\u610F\uFF1Atransfer \u4E0D\u662F\u4E8B\u52A1\u64CD\u4F5C\uFF0C\u4E2D\u9014\u5931\u8D25\u53EF\u80FD\u7559\u4E0B\u90E8\u5206\u8FC1\u79FB\u72B6\u6001\uFF0C\u9700\u4EBA\u5DE5\u6838\u67E5\u3002\n";
|
|
237
|
+
function wantsHelp(args) {
|
|
238
|
+
return args.includes("--help") || args.includes("-h");
|
|
239
|
+
}
|
|
240
|
+
async function ensureCloudflareEmailRoutingToken(args, env, output) {
|
|
241
|
+
const existing = env.CLOUDFLARE_EMAIL_ROUTING_API_TOKEN?.trim();
|
|
242
|
+
if (existing) {
|
|
243
|
+
return { token: existing, wasGenerated: false };
|
|
244
|
+
}
|
|
245
|
+
if (!args.includes("--cloudflare-oauth")) {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
const credential = createOAuthTokenStore().read("cloudflare");
|
|
249
|
+
if (!credential) {
|
|
250
|
+
throw new Error(
|
|
251
|
+
"No Cloudflare OAuth credential. Run: nolo auth cloudflare --client-id <id>"
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
const zoneName = env.CLOUDFLARE_ZONE_NAME?.trim() ?? "nolo.chat";
|
|
255
|
+
const tokenName = `nolo-email-routing-${zoneName}`;
|
|
256
|
+
const { token } = await generateCloudflareEmailRoutingToken({
|
|
257
|
+
accessToken: credential.accessToken,
|
|
258
|
+
zoneName,
|
|
259
|
+
tokenName
|
|
260
|
+
});
|
|
261
|
+
upsertEnvVariable(".env", "CLOUDFLARE_EMAIL_ROUTING_API_TOKEN", token);
|
|
262
|
+
output.write(
|
|
263
|
+
"[nolo] Generated CLOUDFLARE_EMAIL_ROUTING_API_TOKEN and updated .env.\n"
|
|
264
|
+
);
|
|
265
|
+
output.write(
|
|
266
|
+
"[nolo] If your server is already running, restart it so the new token takes effect.\n"
|
|
267
|
+
);
|
|
268
|
+
return { token, wasGenerated: true };
|
|
269
|
+
}
|
|
270
|
+
function resolveAgentInput(args) {
|
|
271
|
+
return readFlagValue(args, "--agent") ?? positionalArgs(args)[0]?.trim();
|
|
272
|
+
}
|
|
273
|
+
async function runAgentEmailProvisionCommand(args, deps = {}) {
|
|
274
|
+
const env = deps.env ?? process.env;
|
|
275
|
+
const output = deps.output ?? process.stdout;
|
|
276
|
+
if (wantsHelp(args) || args.length === 0) {
|
|
277
|
+
output.write(PROVISION_USAGE);
|
|
278
|
+
return args.length === 0 ? 1 : 0;
|
|
279
|
+
}
|
|
280
|
+
const agentInput = resolveAgentInput(args);
|
|
281
|
+
if (!agentInput) {
|
|
282
|
+
output.write(PROVISION_USAGE);
|
|
283
|
+
return 1;
|
|
284
|
+
}
|
|
285
|
+
const authToken = resolveAuthToken(args, env);
|
|
286
|
+
if (!authToken) {
|
|
287
|
+
output.write(
|
|
288
|
+
"[nolo] agent email provision requires an auth token. Run `nolo login` or set AUTH_TOKEN.\n"
|
|
289
|
+
);
|
|
290
|
+
return 1;
|
|
291
|
+
}
|
|
292
|
+
const userId = parseUserIdFromAuthToken(authToken);
|
|
293
|
+
if (!userId) {
|
|
294
|
+
output.write(
|
|
295
|
+
"[nolo] agent email provision could not read userId from AUTH_TOKEN.\n"
|
|
296
|
+
);
|
|
297
|
+
return 1;
|
|
298
|
+
}
|
|
299
|
+
const purpose = readFlagValue(args, "--purpose");
|
|
300
|
+
const localPart = readFlagValue(args, "--local-part");
|
|
301
|
+
const domain = readFlagValue(args, "--domain");
|
|
302
|
+
const provider = readFlagValue(args, "--provider");
|
|
303
|
+
const makePrimary = !args.includes("--no-primary");
|
|
304
|
+
const db = deps.db ?? await getReadableCliDb(output);
|
|
305
|
+
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
306
|
+
const fallbackFetchImpl = deps.fallbackFetchImpl;
|
|
307
|
+
try {
|
|
308
|
+
const tokenResult = await ensureCloudflareEmailRoutingToken(args, env, output);
|
|
309
|
+
if (tokenResult?.wasGenerated) {
|
|
310
|
+
env.CLOUDFLARE_EMAIL_ROUTING_API_TOKEN = tokenResult.token;
|
|
311
|
+
}
|
|
312
|
+
const agentId = await resolveAgentIdForEmailRpc({
|
|
313
|
+
agentInput,
|
|
314
|
+
cliArgs: args,
|
|
315
|
+
env,
|
|
316
|
+
db,
|
|
317
|
+
authToken,
|
|
318
|
+
fetchImpl,
|
|
319
|
+
fallbackFetchImpl
|
|
320
|
+
});
|
|
321
|
+
const result = await postAgentEmailRpc({
|
|
322
|
+
method: "provisionAgentEmailIdentity",
|
|
323
|
+
body: {
|
|
324
|
+
agentId,
|
|
325
|
+
...purpose ? { purpose } : {},
|
|
326
|
+
...localPart ? { localPart } : {},
|
|
327
|
+
...domain ? { domain } : {},
|
|
328
|
+
...provider ? { provider } : {},
|
|
329
|
+
makePrimary
|
|
330
|
+
},
|
|
331
|
+
cliArgs: args,
|
|
332
|
+
env,
|
|
333
|
+
authToken,
|
|
334
|
+
fetchImpl,
|
|
335
|
+
fallbackFetchImpl
|
|
336
|
+
});
|
|
337
|
+
await db.put(agentId, {
|
|
338
|
+
...result.agent,
|
|
339
|
+
dbKey: agentId,
|
|
340
|
+
key: agentId,
|
|
341
|
+
serverOrigin: result.baseUrl,
|
|
342
|
+
cachedAt: Date.now()
|
|
343
|
+
});
|
|
344
|
+
output.write(
|
|
345
|
+
JSON.stringify(
|
|
346
|
+
{
|
|
347
|
+
ok: true,
|
|
348
|
+
action: "provision",
|
|
349
|
+
agentId: result.data.agentId,
|
|
350
|
+
emailAddress: result.data.emailAddress,
|
|
351
|
+
localPart: result.data.localPart,
|
|
352
|
+
domain: result.data.domain,
|
|
353
|
+
provider: result.data.provider,
|
|
354
|
+
purpose: result.data.purpose,
|
|
355
|
+
readinessStatus: result.data.readinessStatus,
|
|
356
|
+
baseUrl: result.baseUrl
|
|
357
|
+
},
|
|
358
|
+
null,
|
|
359
|
+
2
|
|
360
|
+
)
|
|
361
|
+
);
|
|
362
|
+
output.write("\n");
|
|
363
|
+
return 0;
|
|
364
|
+
} catch (error) {
|
|
365
|
+
output.write(
|
|
366
|
+
`[nolo] agent email provision failed: ${toErrorMessage(error)}
|
|
367
|
+
`
|
|
368
|
+
);
|
|
369
|
+
return 1;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
async function runAgentEmailBindCommand(args, deps = {}) {
|
|
373
|
+
const env = deps.env ?? process.env;
|
|
374
|
+
const output = deps.output ?? process.stdout;
|
|
375
|
+
if (wantsHelp(args) || args.length === 0) {
|
|
376
|
+
output.write(BIND_USAGE);
|
|
377
|
+
return args.length === 0 ? 1 : 0;
|
|
378
|
+
}
|
|
379
|
+
const agentInput = resolveAgentInput(args);
|
|
380
|
+
const emailAddress = readFlagValue(args, "--email")?.trim();
|
|
381
|
+
if (!agentInput || !emailAddress) {
|
|
382
|
+
output.write(BIND_USAGE);
|
|
383
|
+
return 1;
|
|
384
|
+
}
|
|
385
|
+
const authToken = resolveAuthToken(args, env);
|
|
386
|
+
if (!authToken) {
|
|
387
|
+
output.write(
|
|
388
|
+
"[nolo] agent email bind requires an auth token. Run `nolo login` or set AUTH_TOKEN.\n"
|
|
389
|
+
);
|
|
390
|
+
return 1;
|
|
391
|
+
}
|
|
392
|
+
const userId = parseUserIdFromAuthToken(authToken);
|
|
393
|
+
if (!userId) {
|
|
394
|
+
output.write(
|
|
395
|
+
"[nolo] agent email bind could not read userId from AUTH_TOKEN.\n"
|
|
396
|
+
);
|
|
397
|
+
return 1;
|
|
398
|
+
}
|
|
399
|
+
const provider = readFlagValue(args, "--provider");
|
|
400
|
+
const db = deps.db ?? await getReadableCliDb(output);
|
|
401
|
+
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
402
|
+
const fallbackFetchImpl = deps.fallbackFetchImpl;
|
|
403
|
+
try {
|
|
404
|
+
const tokenResult = await ensureCloudflareEmailRoutingToken(args, env, output);
|
|
405
|
+
if (tokenResult?.wasGenerated) {
|
|
406
|
+
env.CLOUDFLARE_EMAIL_ROUTING_API_TOKEN = tokenResult.token;
|
|
407
|
+
}
|
|
408
|
+
const agentId = await resolveAgentIdForEmailRpc({
|
|
409
|
+
agentInput,
|
|
410
|
+
cliArgs: args,
|
|
411
|
+
env,
|
|
412
|
+
db,
|
|
413
|
+
authToken,
|
|
414
|
+
fetchImpl,
|
|
415
|
+
fallbackFetchImpl
|
|
416
|
+
});
|
|
417
|
+
const result = await postAgentEmailRpc({
|
|
418
|
+
method: "bindAgentEmailIdentity",
|
|
419
|
+
body: {
|
|
420
|
+
agentId,
|
|
421
|
+
emailAddress,
|
|
422
|
+
...provider ? { provider } : {}
|
|
423
|
+
},
|
|
424
|
+
cliArgs: args,
|
|
425
|
+
env,
|
|
426
|
+
authToken,
|
|
427
|
+
fetchImpl,
|
|
428
|
+
fallbackFetchImpl
|
|
429
|
+
});
|
|
430
|
+
await db.put(agentId, {
|
|
431
|
+
...result.agent,
|
|
432
|
+
dbKey: agentId,
|
|
433
|
+
key: agentId,
|
|
434
|
+
serverOrigin: result.baseUrl,
|
|
435
|
+
cachedAt: Date.now()
|
|
436
|
+
});
|
|
437
|
+
output.write(
|
|
438
|
+
JSON.stringify(
|
|
439
|
+
{
|
|
440
|
+
ok: true,
|
|
441
|
+
action: "bind",
|
|
442
|
+
agentId: result.data.agentId,
|
|
443
|
+
emailAddress: result.data.emailAddress,
|
|
444
|
+
readinessStatus: result.data.readinessStatus,
|
|
445
|
+
baseUrl: result.baseUrl
|
|
446
|
+
},
|
|
447
|
+
null,
|
|
448
|
+
2
|
|
449
|
+
)
|
|
450
|
+
);
|
|
451
|
+
output.write("\n");
|
|
452
|
+
return 0;
|
|
453
|
+
} catch (error) {
|
|
454
|
+
output.write(
|
|
455
|
+
`[nolo] agent email bind failed: ${toErrorMessage(error)}
|
|
456
|
+
`
|
|
457
|
+
);
|
|
458
|
+
return 1;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
async function runAgentEmailTransferCommand(args, deps = {}) {
|
|
462
|
+
const env = deps.env ?? process.env;
|
|
463
|
+
const output = deps.output ?? process.stdout;
|
|
464
|
+
if (wantsHelp(args) || args.length === 0) {
|
|
465
|
+
output.write(TRANSFER_USAGE);
|
|
466
|
+
return args.length === 0 ? 1 : 0;
|
|
467
|
+
}
|
|
468
|
+
const sourceInput = readFlagValue(args, "--from")?.trim();
|
|
469
|
+
const targetInput = readFlagValue(args, "--to")?.trim();
|
|
470
|
+
const emailAddress = readFlagValue(args, "--email")?.trim();
|
|
471
|
+
if (!sourceInput || !targetInput || !emailAddress) {
|
|
472
|
+
output.write(TRANSFER_USAGE);
|
|
473
|
+
return 1;
|
|
474
|
+
}
|
|
475
|
+
const authToken = resolveAuthToken(args, env);
|
|
476
|
+
if (!authToken) {
|
|
477
|
+
output.write(
|
|
478
|
+
"[nolo] agent email transfer requires an auth token. Run `nolo login` or set AUTH_TOKEN.\n"
|
|
479
|
+
);
|
|
480
|
+
return 1;
|
|
481
|
+
}
|
|
482
|
+
const userId = parseUserIdFromAuthToken(authToken);
|
|
483
|
+
if (!userId) {
|
|
484
|
+
output.write(
|
|
485
|
+
"[nolo] agent email transfer could not read userId from AUTH_TOKEN.\n"
|
|
486
|
+
);
|
|
487
|
+
return 1;
|
|
488
|
+
}
|
|
489
|
+
const moveHistoryEmails = !args.includes("--no-move-history");
|
|
490
|
+
const makePrimary = args.includes("--primary") ? true : args.includes("--no-primary") ? false : void 0;
|
|
491
|
+
const db = deps.db ?? await getReadableCliDb(output);
|
|
492
|
+
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
493
|
+
const fallbackFetchImpl = deps.fallbackFetchImpl;
|
|
494
|
+
try {
|
|
495
|
+
const tokenResult = await ensureCloudflareEmailRoutingToken(args, env, output);
|
|
496
|
+
if (tokenResult?.wasGenerated) {
|
|
497
|
+
env.CLOUDFLARE_EMAIL_ROUTING_API_TOKEN = tokenResult.token;
|
|
498
|
+
}
|
|
499
|
+
const [sourceAgentId, targetAgentId] = await Promise.all([
|
|
500
|
+
resolveAgentIdForEmailRpc({
|
|
501
|
+
agentInput: sourceInput,
|
|
502
|
+
cliArgs: args,
|
|
503
|
+
env,
|
|
504
|
+
db,
|
|
505
|
+
authToken,
|
|
506
|
+
fetchImpl,
|
|
507
|
+
fallbackFetchImpl
|
|
508
|
+
}),
|
|
509
|
+
resolveAgentIdForEmailRpc({
|
|
510
|
+
agentInput: targetInput,
|
|
511
|
+
cliArgs: args,
|
|
512
|
+
env,
|
|
513
|
+
db,
|
|
514
|
+
authToken,
|
|
515
|
+
fetchImpl,
|
|
516
|
+
fallbackFetchImpl
|
|
517
|
+
})
|
|
518
|
+
]);
|
|
519
|
+
const result = await postAgentEmailRpc({
|
|
520
|
+
method: "transferAgentEmailIdentity",
|
|
521
|
+
body: {
|
|
522
|
+
sourceAgentId,
|
|
523
|
+
targetAgentId,
|
|
524
|
+
emailAddress,
|
|
525
|
+
moveHistoryEmails,
|
|
526
|
+
...makePrimary === void 0 ? {} : { makePrimary }
|
|
527
|
+
},
|
|
528
|
+
cliArgs: args,
|
|
529
|
+
env,
|
|
530
|
+
authToken,
|
|
531
|
+
fetchImpl,
|
|
532
|
+
fallbackFetchImpl
|
|
533
|
+
});
|
|
534
|
+
await db.put(targetAgentId, {
|
|
535
|
+
...result.agent,
|
|
536
|
+
dbKey: targetAgentId,
|
|
537
|
+
key: targetAgentId,
|
|
538
|
+
serverOrigin: result.baseUrl,
|
|
539
|
+
cachedAt: Date.now()
|
|
540
|
+
});
|
|
541
|
+
output.write(
|
|
542
|
+
JSON.stringify(
|
|
543
|
+
{
|
|
544
|
+
ok: true,
|
|
545
|
+
action: "transfer",
|
|
546
|
+
sourceAgentId: result.data.sourceAgentId,
|
|
547
|
+
targetAgentId: result.data.targetAgentId,
|
|
548
|
+
emailAddress: result.data.emailAddress,
|
|
549
|
+
movedEmails: result.data.movedEmails,
|
|
550
|
+
delegationResourcePrefix: result.data.delegationResourcePrefix,
|
|
551
|
+
baseUrl: result.baseUrl
|
|
552
|
+
},
|
|
553
|
+
null,
|
|
554
|
+
2
|
|
555
|
+
)
|
|
556
|
+
);
|
|
557
|
+
output.write("\n");
|
|
558
|
+
return 0;
|
|
559
|
+
} catch (error) {
|
|
560
|
+
output.write(
|
|
561
|
+
`[nolo] agent email transfer failed: ${toErrorMessage(error)}
|
|
562
|
+
`
|
|
563
|
+
);
|
|
564
|
+
return 1;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
async function runAgentEmailCreateAndProvisionCommand(args, deps = {}) {
|
|
568
|
+
const env = deps.env ?? process.env;
|
|
569
|
+
const output = deps.output ?? process.stdout;
|
|
570
|
+
if (wantsHelp(args)) {
|
|
571
|
+
output.write(
|
|
572
|
+
"Usage: nolo agent email create-and-provision <agent-id-or-slug> --name <display name> [--prompt <text>] [--copy-provider-from <agent>] [--purpose <label>] [--local-part <part>] [--domain <domain>] [--provider <name>]\n"
|
|
573
|
+
);
|
|
574
|
+
return 0;
|
|
575
|
+
}
|
|
576
|
+
const agentSlug = resolveAgentInput(args);
|
|
577
|
+
const name = readFlagValue(args, "--name")?.trim();
|
|
578
|
+
if (!agentSlug || !name) {
|
|
579
|
+
output.write(
|
|
580
|
+
"[nolo] agent email create-and-provision requires <agent> and --name.\n"
|
|
581
|
+
);
|
|
582
|
+
output.write(
|
|
583
|
+
"Usage: nolo agent email create-and-provision <agent> --name <display name> [--prompt <text>] [--copy-provider-from <agent>] [--purpose <label>] [--local-part pay]\n"
|
|
584
|
+
);
|
|
585
|
+
return 1;
|
|
586
|
+
}
|
|
587
|
+
const createArgs = [agentSlug, "--name", name];
|
|
588
|
+
const prompt = readFlagValue(args, "--prompt");
|
|
589
|
+
const copyFrom = readFlagValue(args, "--copy-provider-from");
|
|
590
|
+
if (prompt) {
|
|
591
|
+
createArgs.push("--prompt", prompt);
|
|
592
|
+
}
|
|
593
|
+
if (copyFrom) {
|
|
594
|
+
createArgs.push("--copy-provider-from", copyFrom);
|
|
595
|
+
}
|
|
596
|
+
const createExit = await runAgentCreateCommand(createArgs, deps);
|
|
597
|
+
if (createExit !== 0) {
|
|
598
|
+
return createExit;
|
|
599
|
+
}
|
|
600
|
+
const provisionArgs = [agentSlug];
|
|
601
|
+
for (const flag of [
|
|
602
|
+
"--purpose",
|
|
603
|
+
"--local-part",
|
|
604
|
+
"--domain",
|
|
605
|
+
"--provider",
|
|
606
|
+
"--server",
|
|
607
|
+
"--server-url",
|
|
608
|
+
"--token",
|
|
609
|
+
"--machine-key"
|
|
610
|
+
]) {
|
|
611
|
+
const value = readFlagValue(args, flag);
|
|
612
|
+
if (value) {
|
|
613
|
+
provisionArgs.push(flag, value);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
if (args.includes("--no-primary")) {
|
|
617
|
+
provisionArgs.push("--no-primary");
|
|
618
|
+
}
|
|
619
|
+
return runAgentEmailProvisionCommand(provisionArgs, deps);
|
|
620
|
+
}
|
|
621
|
+
export {
|
|
622
|
+
runAgentEmailBindCommand,
|
|
623
|
+
runAgentEmailCreateAndProvisionCommand,
|
|
624
|
+
runAgentEmailProvisionCommand,
|
|
625
|
+
runAgentEmailTransferCommand
|
|
626
|
+
};
|