nolo-cli 0.8.0-alpha.2 → 0.8.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.
- package/README.md +1 -1
- package/_executeModel-42U3VOVZ.js +205 -0
- package/action-TLI3V62L.js +28 -0
- package/addContentAction-57RSIIMR.js +26 -0
- package/addDialogAgentAction-G3VWEA6E.js +68 -0
- package/agentDeleteCommand-5DD2IM3J.js +327 -0
- package/agentEmailCommands-6FACJBU4.js +628 -0
- package/agentListCommands-I6KZYCIG.js +223 -0
- package/agentMachineCommands-VKLIGMZA.js +425 -0
- package/agentPullCommand-O2MTUAFR.js +122 -0
- package/agentRecordCommands-7TZICYDT.js +96 -0
- package/agentRunCommand-L4OM23KV.js +114 -0
- package/agentRunControl-K4VKNEHF.js +57 -0
- package/agentRuntimeLocal-ZYEIPTY4.js +104 -0
- package/agentSlice-BX7GXSNO.js +42 -0
- package/authCommand-EB5JSOX5.js +581 -0
- package/authCommands-XPEHTKSM.js +35 -0
- package/chunk-25LCXTML.js +175 -0
- package/chunk-2ECQG4YX.js +22296 -0
- package/chunk-2FTTDCD4.js +675 -0
- package/chunk-2JCXITPK.js +1078 -0
- package/chunk-3ASDTTEI.js +1774 -0
- package/chunk-3EUW3WEO.js +8 -0
- package/chunk-3LY4F7SV.js +9293 -0
- package/chunk-4CQLVGRV.js +50 -0
- package/chunk-4IJYA27C.js +342 -0
- package/chunk-4O3CARJ4.js +231 -0
- package/chunk-4QEWT7KD.js +933 -0
- package/chunk-4SN6J65J.js +38 -0
- package/chunk-4VNS5WPM.js +42 -0
- package/chunk-4XENYTF5.js +222 -0
- package/chunk-4ZDM73SD.js +34 -0
- package/chunk-5CS33IBL.js +301 -0
- package/chunk-5EFXE3O7.js +138 -0
- package/chunk-5KLGBAAR.js +386 -0
- package/chunk-5MIDPSSK.js +206 -0
- package/chunk-5MMAK75Q.js +15 -0
- package/chunk-63W5N6P3.js +150 -0
- package/chunk-6HYVJV7B.js +102 -0
- package/chunk-6KHNO3SK.js +1948 -0
- package/chunk-6WD3OOJS.js +20 -0
- package/chunk-7DAJ4AI4.js +191 -0
- package/chunk-7GNGZRLZ.js +1939 -0
- package/chunk-7KCUSYT2.js +354 -0
- package/chunk-7U44LYTR.js +238 -0
- package/chunk-AFON4QUU.js +112 -0
- package/chunk-AGFH73SK.js +239 -0
- package/chunk-AL2KDGR2.js +27339 -0
- package/chunk-AS4PVWA4.js +221 -0
- package/chunk-ATNTHIZI.js +13 -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-C4FTUXVF.js +146 -0
- package/chunk-CF2WZF4N.js +134 -0
- package/chunk-CF7PE763.js +10 -0
- package/chunk-CKOJQDKR.js +198 -0
- package/chunk-CMKUBIGW.js +1550 -0
- package/chunk-CWMSB67P.js +34 -0
- package/chunk-DCOA4QSN.js +105 -0
- package/chunk-DFFIZ25G.js +30 -0
- package/chunk-DSZUWUYB.js +478 -0
- package/chunk-DWLEOOGR.js +8 -0
- package/chunk-DZ3XJVET.js +231 -0
- package/chunk-EHLHSX7R.js +1433 -0
- package/chunk-ENOG22KJ.js +939 -0
- package/chunk-FSO5B7GH.js +171 -0
- package/chunk-FVYY6MCS.js +1447 -0
- package/chunk-G3SUCT4W.js +8 -0
- package/chunk-GAKEBQD6.js +30 -0
- package/chunk-GBRG75BQ.js +86 -0
- package/chunk-GU3PEVGZ.js +4723 -0
- package/chunk-H33743XH.js +25 -0
- package/chunk-HNMXYYJR.js +12 -0
- package/chunk-HNW7IJSK.js +71 -0
- package/chunk-I42VC5KR.js +15 -0
- package/chunk-I6XMPTMR.js +113 -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-KQHGZWSV.js +63 -0
- package/chunk-KUG52IAP.js +8 -0
- package/chunk-KX6YBIHG.js +8 -0
- package/chunk-LCBAMY2M.js +60 -0
- package/chunk-LM6IYQ3F.js +16 -0
- package/chunk-LTRXGFMS.js +83 -0
- package/chunk-M76ECQRD.js +13658 -0
- package/chunk-MRC4Q34M.js +188 -0
- package/chunk-MTU75CZ2.js +91 -0
- package/chunk-N54XAP77.js +19 -0
- package/chunk-O2ZNTTET.js +3272 -0
- package/chunk-O4BU24WZ.js +3212 -0
- package/chunk-OLZBQWZU.js +6 -0
- package/chunk-OOSFSFMA.js +271 -0
- package/chunk-OPZYGHUC.js +89 -0
- package/chunk-OWOHNGCN.js +50 -0
- package/chunk-P3PKED2I.js +962 -0
- package/chunk-QSJ3HFEF.js +8 -0
- package/chunk-RCSJFQPB.js +9036 -0
- package/chunk-RL776AGR.js +190 -0
- package/chunk-ROWQEJRP.js +139 -0
- package/chunk-S7Z2HMCN.js +25 -0
- package/chunk-SDJDLO5W.js +628 -0
- package/chunk-SOTZ6RDN.js +69 -0
- package/chunk-TILFE6LV.js +381 -0
- package/chunk-U4TRT5V4.js +246 -0
- package/chunk-U6VC4MU4.js +8 -0
- package/chunk-UAD2WT54.js +64 -0
- package/chunk-UB6SN4NJ.js +421 -0
- package/chunk-URUUZLPA.js +807 -0
- package/chunk-UTLZINAP.js +3066 -0
- package/chunk-VC6OZXO5.js +298 -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-VUW5FBDB.js +573 -0
- package/chunk-VVX233PH.js +482 -0
- package/chunk-VX3SXJ3N.js +2052 -0
- package/chunk-W4NVOSFF.js +37 -0
- package/chunk-WWC7I6TA.js +8 -0
- package/chunk-WZSRQNQG.js +2587 -0
- package/chunk-XBUBEFNX.js +34 -0
- package/chunk-XENYHRUE.js +104 -0
- package/chunk-Y5GCAMGP.js +9 -0
- package/chunk-YPRZSPF3.js +148 -0
- package/chunk-Z4NR32XR.js +50 -0
- package/chunk-ZNFJWEN4.js +56 -0
- package/cliExecutor-K3F7DMRO.js +36 -0
- package/clipboardy-BVE3LVEH.js +12001 -0
- package/createAgentAutomationAction-RJF3N2QY.js +866 -0
- package/createDialogAction-DRSPS6CE.js +55 -0
- package/createPageAction-6B2WMNO3.js +172 -0
- package/db-HCJ5PRB5.js +271 -0
- package/dbSlice-Q3TM2FJV.js +60 -0
- package/deleteFile-OW53A6BX.js +41 -0
- package/dialogCommands-4IX4XIZE.js +63 -0
- package/dialogSlice-3M7KX2TX.js +148 -0
- package/docCreateCommands-SIL3NPGT.js +220 -0
- package/docDeleteCommands-7IOMLUS4.js +181 -0
- package/docReadCommands-FNFXUA5L.js +134 -0
- package/docStore-SV7E34D4.js +98 -0
- package/docUpdateCommands-X2HNDVUC.js +318 -0
- package/fetchMessages-KTNM7QAR.js +17 -0
- package/getPricing-3E6UNPKL.js +30 -0
- package/handleSendMessageAction-JYETO5RZ.js +185 -0
- package/index.js +188 -112958
- package/lib-FYYBQIXS.js +19839 -0
- package/localDialogRead-2VRI24F4.js +26 -0
- package/localFirstLog-DHNOY2NA.js +19 -0
- package/localRuntimeAuthority-TEGCOWX4.js +471 -0
- package/localRuntimeDb-LGDF6FQP.js +12 -0
- package/machineCommands-RIO3RP5Q.js +781 -0
- package/machineInfo-M6KB6HZN.js +10 -0
- package/machineWsRunDispatch-W7UYLGB5.js +112 -0
- package/memoryCommands-O4MIPIWQ.js +476 -0
- package/models-4OPOOLFS.js +9 -0
- package/offlineMarxistsAgentCommand-BCPJITJL.js +242 -0
- package/package.json +4 -24
- package/read-GW7ZEI23.js +17 -0
- package/readDocTool-HUFU6OCT.js +16 -0
- package/readlineWorkspace-27JR7WPW.js +5682 -0
- package/removeDialogAgentAction-CXKR4NJI.js +73 -0
- package/runAgentClientLoop-HZFAPJHS.js +293 -0
- package/runtimeDoctorCommands-LRHLPDRC.js +289 -0
- package/setDialogExtraReferencesAction-6RKUSXHX.js +60 -0
- package/setPrimaryDialogAgentAction-T3UTBEFG.js +80 -0
- package/settingSlice-IVKXJXMG.js +199 -0
- package/skillDiscovery-UGSQGX2U.js +16 -0
- package/skillSummaryMarker-42HKSXYY.js +9 -0
- package/slateToRenderMarkdown-Y5IYN73U.js +7 -0
- package/slateUtils-2M7MUTWX.js +19 -0
- package/spaceCommands-E7VOF4LO.js +450 -0
- package/spaceSlice-TSVROA5U.js +149 -0
- package/streamAgentChatTurn-3C5RQZJF.js +4510 -0
- package/tableCommands-O7O2LBEG.js +1286 -0
- package/toolApiClient-QI3YBNWB.js +26 -0
- package/tools-EQDEKR6N.js +87 -0
- package/tuiSummaryLlmCaller-RV3THLZF.js +78 -0
- package/understanding-3CUQQ6SV.js +271 -0
- package/updateCommands-VOSPKXFF.js +31 -0
- package/updateDialogTitleAction-3XV7VWSZ.js +188 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import {
|
|
2
|
+
API_ENDPOINTS,
|
|
3
|
+
NOLO_CLUSTER_SERVERS,
|
|
4
|
+
isLocalDevServerOrigin,
|
|
5
|
+
isNoloClusterServerOrigin,
|
|
6
|
+
normalizeKnownServerOrigin
|
|
7
|
+
} from "./chunk-LCBAMY2M.js";
|
|
8
|
+
import {
|
|
9
|
+
normalizeServerOrigin
|
|
10
|
+
} from "./chunk-CF7PE763.js";
|
|
11
|
+
|
|
12
|
+
// packages/app/utils/env.ts
|
|
13
|
+
var processEnv = typeof process !== "undefined" ? process.env : void 0;
|
|
14
|
+
var reactNativeDev = typeof globalThis !== "undefined" && "__DEV__" in globalThis ? globalThis.__DEV__ : void 0;
|
|
15
|
+
var isProduction = processEnv?.NOLO_FORCE_PRODUCTION === "1" || processEnv?.NODE_ENV === "production" || reactNativeDev === false;
|
|
16
|
+
var getIsDesktopApp = () => (typeof process !== "undefined" ? process.env?.NOLO_DESKTOP : processEnv?.NOLO_DESKTOP) === "1" || typeof window !== "undefined" && window.__NOLO_DESKTOP__ === true;
|
|
17
|
+
var isDesktopApp = getIsDesktopApp();
|
|
18
|
+
|
|
19
|
+
// packages/core/abortError.ts
|
|
20
|
+
function isAbortError(error) {
|
|
21
|
+
if (!error || typeof error !== "object") return false;
|
|
22
|
+
return error.name === "AbortError";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// packages/core/clientLogger.ts
|
|
26
|
+
var LOG_LEVELS = {
|
|
27
|
+
debug: 10,
|
|
28
|
+
info: 20,
|
|
29
|
+
warn: 30,
|
|
30
|
+
error: 40
|
|
31
|
+
};
|
|
32
|
+
var serializeValue = (value, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
33
|
+
if (value instanceof Error) {
|
|
34
|
+
return {
|
|
35
|
+
name: value.name,
|
|
36
|
+
message: value.message,
|
|
37
|
+
...value.stack ? { stack: value.stack } : {}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (typeof value !== "object" || value === null) {
|
|
41
|
+
if (typeof value === "bigint") {
|
|
42
|
+
return value.toString();
|
|
43
|
+
}
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
if (seen.has(value)) {
|
|
47
|
+
return "[Circular]";
|
|
48
|
+
}
|
|
49
|
+
seen.add(value);
|
|
50
|
+
if (Array.isArray(value)) {
|
|
51
|
+
return value.map((item) => serializeValue(item, seen));
|
|
52
|
+
}
|
|
53
|
+
return Object.fromEntries(
|
|
54
|
+
Object.entries(value).map(([key, item]) => [key, serializeValue(item, seen)])
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
var getLogLevel = () => {
|
|
58
|
+
const configured = typeof process !== "undefined" && typeof process.env?.NOLO_LOG_LEVEL === "string" ? process.env.NOLO_LOG_LEVEL : "info";
|
|
59
|
+
return LOG_LEVELS[configured] ?? LOG_LEVELS.info;
|
|
60
|
+
};
|
|
61
|
+
var writeLog = (level, name, fields, message) => {
|
|
62
|
+
if (LOG_LEVELS[level] < getLogLevel()) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const serializedFields = serializeValue(fields);
|
|
66
|
+
const payload = {
|
|
67
|
+
level,
|
|
68
|
+
...name ? { name } : {},
|
|
69
|
+
...serializedFields,
|
|
70
|
+
...message ? { msg: message } : {}
|
|
71
|
+
};
|
|
72
|
+
const output = JSON.stringify(payload);
|
|
73
|
+
const isNodeRuntime = typeof process !== "undefined" && typeof process.stderr?.write === "function";
|
|
74
|
+
if (isNodeRuntime) {
|
|
75
|
+
process.stderr.write(`${output}
|
|
76
|
+
`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const consoleMethod = console[level] ?? console.log;
|
|
80
|
+
if (Object.keys(fields).length === 0 && message) {
|
|
81
|
+
consoleMethod(`[${name}] ${message}`);
|
|
82
|
+
} else {
|
|
83
|
+
consoleMethod(output);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var parseArgs = (first, second) => {
|
|
87
|
+
if (typeof first === "string") {
|
|
88
|
+
return { fields: {}, message: first };
|
|
89
|
+
}
|
|
90
|
+
return { fields: first ?? {}, message: second };
|
|
91
|
+
};
|
|
92
|
+
var createClientLogger = (name, parentFields = {}) => {
|
|
93
|
+
const log = (level, first, second) => {
|
|
94
|
+
const { fields, message } = parseArgs(first, second);
|
|
95
|
+
writeLog(level, name, { ...parentFields, ...fields }, message);
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
debug: (first, second) => log("debug", first, second),
|
|
99
|
+
info: (first, second) => log("info", first, second),
|
|
100
|
+
warn: (first, second) => log("warn", first, second),
|
|
101
|
+
error: (first, second) => log("error", first, second),
|
|
102
|
+
child: (fields) => createClientLogger(name, { ...parentFields, ...fields })
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// packages/app/utils/retryFetch.ts
|
|
107
|
+
var TRANSIENT_READ_RETRY_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
|
|
108
|
+
var DEFAULT_RETRY_DELAYS_MS = [300, 1e3];
|
|
109
|
+
var sleep = (ms) => new Promise((resolve) => {
|
|
110
|
+
setTimeout(resolve, ms);
|
|
111
|
+
});
|
|
112
|
+
var getRequestMethod = (input, init) => {
|
|
113
|
+
if (init?.method) return init.method.toUpperCase();
|
|
114
|
+
if (typeof Request !== "undefined" && input instanceof Request) {
|
|
115
|
+
return input.method.toUpperCase();
|
|
116
|
+
}
|
|
117
|
+
return "GET";
|
|
118
|
+
};
|
|
119
|
+
var isRetryableReadMethod = (method) => method === "GET" || method === "HEAD";
|
|
120
|
+
var fetchWithTransientReadRetry = async (input, init, options = {}) => {
|
|
121
|
+
const method = getRequestMethod(input, init);
|
|
122
|
+
const canRetry = isRetryableReadMethod(method);
|
|
123
|
+
const delaysMs = options.delaysMs ?? DEFAULT_RETRY_DELAYS_MS;
|
|
124
|
+
const retryStatuses = options.retryStatuses ?? TRANSIENT_READ_RETRY_STATUSES;
|
|
125
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
126
|
+
const wait = options.sleep ?? sleep;
|
|
127
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
128
|
+
try {
|
|
129
|
+
const response = await fetchImpl(input, init);
|
|
130
|
+
const shouldRetry = canRetry && retryStatuses.has(response.status) && attempt < delaysMs.length;
|
|
131
|
+
if (!shouldRetry) return response;
|
|
132
|
+
} catch (error) {
|
|
133
|
+
const shouldRetry = canRetry && !isAbortError(error) && attempt < delaysMs.length;
|
|
134
|
+
if (!shouldRetry) throw error;
|
|
135
|
+
}
|
|
136
|
+
await wait(delaysMs[attempt]);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// packages/database/levelNotFoundError.ts
|
|
141
|
+
function isLevelNotFoundError(error) {
|
|
142
|
+
if (!error || typeof error !== "object") return false;
|
|
143
|
+
const e = error;
|
|
144
|
+
return e.notFound === true || e.name === "NotFoundError" || e.code === "LEVEL_NOT_FOUND" || e.code === "LEVEL_NOT_FOUND_ERROR" || e.message === "NotFound";
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// packages/database/actions/common.ts
|
|
148
|
+
var logger = createClientLogger("database");
|
|
149
|
+
var normalizeServer = (server) => normalizeKnownServerOrigin(server) ?? normalizeServerOrigin(server);
|
|
150
|
+
var mergeConfiguredServers = (currentServer, syncServers) => {
|
|
151
|
+
const runtimeOrigin = !getIsDesktopApp() && typeof window !== "undefined" && typeof window.location?.origin === "string" && /^https?:\/\//.test(window.location.origin) ? window.location.origin : void 0;
|
|
152
|
+
const raw = [
|
|
153
|
+
currentServer,
|
|
154
|
+
...Array.isArray(syncServers) ? syncServers : [],
|
|
155
|
+
runtimeOrigin
|
|
156
|
+
].filter(
|
|
157
|
+
(s) => typeof s === "string" && s.trim().length > 0
|
|
158
|
+
);
|
|
159
|
+
const normalized = raw.map(normalizeServer);
|
|
160
|
+
const shouldIncludeClusterPeers = normalized.some(isNoloClusterServerOrigin) || typeof currentServer === "string" && isLocalDevServerOrigin(currentServer);
|
|
161
|
+
if (shouldIncludeClusterPeers) {
|
|
162
|
+
normalized.push(...NOLO_CLUSTER_SERVERS);
|
|
163
|
+
}
|
|
164
|
+
return Array.from(new Set(normalized));
|
|
165
|
+
};
|
|
166
|
+
var getAllServers = (currentServer, syncServers, preferredServer) => {
|
|
167
|
+
const preferredNormalized = typeof preferredServer === "string" && preferredServer.trim().length > 0 ? normalizeServer(preferredServer) : null;
|
|
168
|
+
const servers = mergeConfiguredServers(
|
|
169
|
+
currentServer,
|
|
170
|
+
preferredNormalized && isNoloClusterServerOrigin(preferredNormalized) ? [...Array.isArray(syncServers) ? syncServers : [], preferredNormalized] : syncServers
|
|
171
|
+
);
|
|
172
|
+
if (!preferredServer || typeof preferredServer !== "string") {
|
|
173
|
+
return servers;
|
|
174
|
+
}
|
|
175
|
+
const remaining = servers.filter(
|
|
176
|
+
(server) => normalizeServer(server) !== preferredNormalized
|
|
177
|
+
);
|
|
178
|
+
return preferredNormalized ? [preferredNormalized, ...remaining] : remaining;
|
|
179
|
+
};
|
|
180
|
+
var fetchFromClientDb = async (clientDb, dbKey) => {
|
|
181
|
+
if (!clientDb) {
|
|
182
|
+
logger.error(
|
|
183
|
+
{ dbKey },
|
|
184
|
+
"Client database is undefined in fetchFromClientDb"
|
|
185
|
+
);
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
return await clientDb.get(dbKey);
|
|
190
|
+
} catch (err) {
|
|
191
|
+
if (isLevelNotFoundError(err)) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
logger.error({ err, dbKey }, "Failed to get local data");
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
var SERVER_TIMEOUT = 5e3;
|
|
199
|
+
var READ_TIMEOUT_ERROR_NAME = "ReadTimeoutError";
|
|
200
|
+
var isPublicFileDbKey = (dbKey) => dbKey.startsWith("file-");
|
|
201
|
+
var buildReadUrl = (dbKey) => isPublicFileDbKey(dbKey) ? `${API_ENDPOINTS.DATABASE}/file/metadata/${encodeURIComponent(dbKey)}` : `${API_ENDPOINTS.DATABASE}/read/${encodeURIComponent(dbKey)}`;
|
|
202
|
+
var createReadTimeoutError = (server, dbKey) => {
|
|
203
|
+
const error = new Error(
|
|
204
|
+
`Timed out reading key "${dbKey}" from ${normalizeServer(server)}.`
|
|
205
|
+
);
|
|
206
|
+
error.name = READ_TIMEOUT_ERROR_NAME;
|
|
207
|
+
return error;
|
|
208
|
+
};
|
|
209
|
+
var isReadTimeoutError = (error) => error instanceof Error && error.name === READ_TIMEOUT_ERROR_NAME;
|
|
210
|
+
var fetchFromServer = async (server, dbKey, token, signal) => {
|
|
211
|
+
if (signal?.aborted) {
|
|
212
|
+
throw new DOMException("Aborted", "AbortError");
|
|
213
|
+
}
|
|
214
|
+
const controller = new AbortController();
|
|
215
|
+
let didTimeout = false;
|
|
216
|
+
const timeoutId = setTimeout(() => {
|
|
217
|
+
didTimeout = true;
|
|
218
|
+
controller.abort();
|
|
219
|
+
}, SERVER_TIMEOUT);
|
|
220
|
+
const onExternalAbort = () => controller.abort();
|
|
221
|
+
signal?.addEventListener("abort", onExternalAbort);
|
|
222
|
+
try {
|
|
223
|
+
const res = await fetchWithTransientReadRetry(
|
|
224
|
+
`${server}${buildReadUrl(dbKey)}`,
|
|
225
|
+
{
|
|
226
|
+
signal: controller.signal,
|
|
227
|
+
headers: {
|
|
228
|
+
"Content-Type": "application/json",
|
|
229
|
+
...token && { Authorization: `Bearer ${token}` }
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
);
|
|
233
|
+
clearTimeout(timeoutId);
|
|
234
|
+
signal?.removeEventListener("abort", onExternalAbort);
|
|
235
|
+
if (res.status === 200) {
|
|
236
|
+
return await res.json();
|
|
237
|
+
}
|
|
238
|
+
return null;
|
|
239
|
+
} catch (err) {
|
|
240
|
+
clearTimeout(timeoutId);
|
|
241
|
+
signal?.removeEventListener("abort", onExternalAbort);
|
|
242
|
+
if (didTimeout) {
|
|
243
|
+
throw createReadTimeoutError(server, dbKey);
|
|
244
|
+
}
|
|
245
|
+
if (signal?.aborted || isAbortError(err)) {
|
|
246
|
+
throw err;
|
|
247
|
+
}
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
var normalizeTimeFields = (data) => ({
|
|
252
|
+
...data,
|
|
253
|
+
createdAt: data.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
|
|
254
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
255
|
+
updated_at: void 0,
|
|
256
|
+
created_at: void 0
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
export {
|
|
260
|
+
isProduction,
|
|
261
|
+
getIsDesktopApp,
|
|
262
|
+
createClientLogger,
|
|
263
|
+
isAbortError,
|
|
264
|
+
fetchWithTransientReadRetry,
|
|
265
|
+
logger,
|
|
266
|
+
getAllServers,
|
|
267
|
+
fetchFromClientDb,
|
|
268
|
+
isReadTimeoutError,
|
|
269
|
+
fetchFromServer,
|
|
270
|
+
normalizeTimeFields
|
|
271
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// packages/agent-runtime/thinkTagParser.ts
|
|
2
|
+
var OPEN_TAG = "<think>";
|
|
3
|
+
var CLOSE_TAG = "</think>";
|
|
4
|
+
function longestTagPrefixLength(buffer, tag) {
|
|
5
|
+
const max = Math.min(buffer.length, tag.length - 1);
|
|
6
|
+
for (let len = max; len > 0; len--) {
|
|
7
|
+
if (tag.startsWith(buffer.slice(-len))) {
|
|
8
|
+
return len;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
function extractThinkContent(content) {
|
|
14
|
+
const regex = new RegExp(`${OPEN_TAG}([\\s\\S]*?)${CLOSE_TAG}`, "g");
|
|
15
|
+
const matches = [...content.matchAll(regex)];
|
|
16
|
+
if (matches.length === 0) {
|
|
17
|
+
return { content };
|
|
18
|
+
}
|
|
19
|
+
const reasoning = matches.map((m) => m[1]).join("\n");
|
|
20
|
+
const cleaned = content.replace(regex, "");
|
|
21
|
+
return { content: cleaned.replace(/^\n/, ""), reasoning };
|
|
22
|
+
}
|
|
23
|
+
function createThinkParserState() {
|
|
24
|
+
return { mode: "content", buffer: "", trimNextVisible: false };
|
|
25
|
+
}
|
|
26
|
+
function processThinkChunk(chunk, state) {
|
|
27
|
+
let visible = "";
|
|
28
|
+
let reasoning = "";
|
|
29
|
+
let { mode, buffer, trimNextVisible } = state;
|
|
30
|
+
buffer += chunk;
|
|
31
|
+
while (true) {
|
|
32
|
+
if (mode === "content") {
|
|
33
|
+
const idx = buffer.indexOf(OPEN_TAG);
|
|
34
|
+
if (idx === -1) {
|
|
35
|
+
const keep = longestTagPrefixLength(buffer, OPEN_TAG);
|
|
36
|
+
visible += buffer.slice(0, buffer.length - keep);
|
|
37
|
+
buffer = buffer.slice(buffer.length - keep);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
visible += buffer.slice(0, idx);
|
|
41
|
+
buffer = buffer.slice(idx + OPEN_TAG.length);
|
|
42
|
+
mode = "reasoning";
|
|
43
|
+
} else {
|
|
44
|
+
const idx = buffer.indexOf(CLOSE_TAG);
|
|
45
|
+
if (idx === -1) {
|
|
46
|
+
const keep = longestTagPrefixLength(buffer, CLOSE_TAG);
|
|
47
|
+
reasoning += buffer.slice(0, buffer.length - keep);
|
|
48
|
+
buffer = buffer.slice(buffer.length - keep);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
reasoning += buffer.slice(0, idx);
|
|
52
|
+
buffer = buffer.slice(idx + CLOSE_TAG.length);
|
|
53
|
+
mode = "content";
|
|
54
|
+
trimNextVisible = true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (mode === "content" && visible.length > 0 && trimNextVisible) {
|
|
58
|
+
visible = visible.replace(/^\n/, "");
|
|
59
|
+
trimNextVisible = false;
|
|
60
|
+
}
|
|
61
|
+
return { content: visible, reasoning, state: { mode, buffer, trimNextVisible } };
|
|
62
|
+
}
|
|
63
|
+
function flushThinkParser(state) {
|
|
64
|
+
const { mode, buffer, trimNextVisible } = state;
|
|
65
|
+
if (mode === "reasoning") {
|
|
66
|
+
return {
|
|
67
|
+
content: "",
|
|
68
|
+
reasoning: buffer,
|
|
69
|
+
state: { mode: "content", buffer: "", trimNextVisible: false }
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
let visible = buffer;
|
|
73
|
+
const nextTrim = trimNextVisible;
|
|
74
|
+
if (nextTrim) {
|
|
75
|
+
visible = visible.replace(/^\n/, "");
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
content: visible,
|
|
79
|
+
reasoning: "",
|
|
80
|
+
state: { mode: "content", buffer: "", trimNextVisible: false }
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export {
|
|
85
|
+
extractThinkContent,
|
|
86
|
+
createThinkParserState,
|
|
87
|
+
processThinkChunk,
|
|
88
|
+
flushThinkParser
|
|
89
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
compactWhitespace
|
|
3
|
+
} from "./chunk-DWLEOOGR.js";
|
|
4
|
+
|
|
5
|
+
// packages/chat/dialog/dialogTitle.ts
|
|
6
|
+
var GENERATED_DIALOG_TITLE_MAX_CHARS = 36;
|
|
7
|
+
var FALLBACK_DIALOG_TITLE_MAX_CHARS = 24;
|
|
8
|
+
var WRAPPING_QUOTES_RE = /^[`"'“”‘’「」『』《》]+|[`"'“”‘’「」『』《》]+$/gu;
|
|
9
|
+
var TRAILING_TITLE_PUNCTUATION_RE = /[。!?!?;;,,、::]+$/u;
|
|
10
|
+
var clip = (text, maxChars) => text.length <= maxChars ? text : `${text.slice(0, maxChars - 1).trimEnd()}\u2026`;
|
|
11
|
+
var toSingleLine = (value) => value.replace(/\r\n?/g, "\n").split("\n").map((line) => line.trim()).find(Boolean) ?? "";
|
|
12
|
+
var stripTitleFormatting = (value) => value.replace(/^(?:[-*#>]+\s*|\d+\.\s+)/, "").replace(WRAPPING_QUOTES_RE, "").replace(TRAILING_TITLE_PUNCTUATION_RE, "").trim();
|
|
13
|
+
var pickLeadingClause = (value) => {
|
|
14
|
+
const firstLine = toSingleLine(value);
|
|
15
|
+
if (!firstLine) return "";
|
|
16
|
+
const separatorIndexes = [firstLine.indexOf("\uFF1A"), firstLine.indexOf(":")].filter((index) => index > 0).sort((left, right) => left - right);
|
|
17
|
+
for (const index of separatorIndexes) {
|
|
18
|
+
const clause = firstLine.slice(0, index).trim();
|
|
19
|
+
if (clause.length >= 4) return clause;
|
|
20
|
+
}
|
|
21
|
+
return firstLine;
|
|
22
|
+
};
|
|
23
|
+
var normalizeDialogTitle = (rawTitle, maxChars = GENERATED_DIALOG_TITLE_MAX_CHARS) => {
|
|
24
|
+
if (typeof rawTitle !== "string") return "";
|
|
25
|
+
const normalized = stripTitleFormatting(
|
|
26
|
+
compactWhitespace(toSingleLine(rawTitle))
|
|
27
|
+
);
|
|
28
|
+
if (!normalized) return "";
|
|
29
|
+
return clip(normalized, maxChars);
|
|
30
|
+
};
|
|
31
|
+
var buildDialogFallbackTitleFromUserInput = (userInput, maxChars = FALLBACK_DIALOG_TITLE_MAX_CHARS) => {
|
|
32
|
+
if (typeof userInput !== "string") return "";
|
|
33
|
+
const candidate = pickLeadingClause(userInput);
|
|
34
|
+
return normalizeDialogTitle(candidate || userInput, maxChars);
|
|
35
|
+
};
|
|
36
|
+
var buildDialogFallbackTitleFromMessages = (messages) => {
|
|
37
|
+
for (const message of messages) {
|
|
38
|
+
if (message?.role !== "user") continue;
|
|
39
|
+
const title = buildDialogFallbackTitleFromUserInput(message?.content);
|
|
40
|
+
if (title) return title;
|
|
41
|
+
}
|
|
42
|
+
return "";
|
|
43
|
+
};
|
|
44
|
+
var resolveDialogTitle = (generatedTitle, fallbackTitle) => normalizeDialogTitle(generatedTitle) || fallbackTitle.trim();
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
normalizeDialogTitle,
|
|
48
|
+
buildDialogFallbackTitleFromMessages,
|
|
49
|
+
resolveDialogTitle
|
|
50
|
+
};
|