nolo-cli 0.264.0-alpha.1 → 0.265.0-alpha.1
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-YQNZNR2Y.js → _executeModel-B3ENLKM4.js} +14 -14
- package/{agentDeleteCommand-MJF6BWP5.js → agentDeleteCommand-R4LKLXQR.js} +12 -12
- package/{agentEmailCommands-KX3OQQAW.js → agentEmailCommands-SUEXVAY4.js} +13 -13
- package/{agentMachineCommands-X5ZLRVTF.js → agentMachineCommands-AXPZRHUY.js} +2 -2
- package/{agentRecordCommands-KETL6CLV.js → agentRecordCommands-NE4OPX5K.js} +13 -13
- package/{agentRun-DSQD2VC5.js → agentRun-NSNLIOM7.js} +13 -13
- package/{agentRunCommand-COJOJSNF.js → agentRunCommand-T6QTKMCJ.js} +14 -14
- package/{agentSlice-HHNKNNYM.js → agentSlice-FZJZONCT.js} +1 -1
- package/{chunk-LYPJYBE5.js → chunk-2QKIWEZS.js} +2 -2
- package/{chunk-7E6YXSFZ.js → chunk-4TDUT2LC.js} +2 -2
- package/{chunk-CWOZIF6Z.js → chunk-6A6CTCMC.js} +1 -1
- package/{chunk-DBEOW57U.js → chunk-APOIIIB4.js} +2 -2
- package/{chunk-MALPQFGT.js → chunk-B7CTVEUV.js} +5 -5
- package/{chunk-7422ZLGL.js → chunk-BY2CHBIZ.js} +6 -6
- package/{chunk-ZSZBHRLP.js → chunk-CYS6HOJ2.js} +4 -4
- package/{chunk-JUMQJSQF.js → chunk-DALXH7BG.js} +211 -177
- package/{chunk-DBCWXGOC.js → chunk-DKEOYC4L.js} +8 -8
- package/{chunk-EN6WNK2M.js → chunk-DXDCL3Z6.js} +6 -6
- package/{chunk-WLRDY5OG.js → chunk-DZJWSGCV.js} +1 -1
- package/{chunk-TGVVE5BA.js → chunk-FRFFUKGH.js} +1 -1
- package/{chunk-4RUQ2PFX.js → chunk-G5KDYBTG.js} +3 -3
- package/chunk-GBXRKW26.js +613 -0
- package/{chunk-QG2ALEDQ.js → chunk-IHU2ZFCQ.js} +3 -3
- package/{chunk-R5PN5DE2.js → chunk-JGUHOA42.js} +3 -3
- package/{chunk-TKLBBR7P.js → chunk-L2DHCG6C.js} +3 -3
- package/{chunk-HXEO5DNV.js → chunk-LBPW6OCD.js} +2 -2
- package/{chunk-PDSXYHNI.js → chunk-NACE7NWO.js} +2 -2
- package/{chunk-U7OULUMF.js → chunk-S52BPZ7A.js} +2 -2
- package/{chunk-EBH4RFJ6.js → chunk-SCEPD46O.js} +20 -14
- package/{chunk-6K4V4R2I.js → chunk-XGYQCBWS.js} +5 -5
- package/{chunk-EODBQPRM.js → chunk-Z6LVL5MC.js} +2 -2
- package/{cliExecutor-Z62UBJ5S.js → cliExecutor-N3445G2Z.js} +1 -1
- package/{commandRegistry-WOKBQU6B.js → commandRegistry-XPLM5SWC.js} +18 -18
- package/{contentThunks-ERA42OXW.js → contentThunks-RK6MJWBY.js} +3 -3
- package/{createAgentAutomationAction-DMD2VDPI.js → createAgentAutomationAction-KN7XLCU2.js} +3 -3
- package/{createDialogAction-3SPOJQAK.js → createDialogAction-KAG6DBVM.js} +4 -4
- package/{createPageAction-AVXUMZVT.js → createPageAction-7XNPH76L.js} +4 -4
- package/{deleteDbKey-KV6MYBAI.js → deleteDbKey-MUCJP6DK.js} +4 -4
- package/{dialogSlice-Q7H2YVNO.js → dialogSlice-BD6WOOD3.js} +2 -2
- package/{docStore-GWPFDV6Y.js → docStore-RK4CD4QN.js} +1 -1
- package/{handleSendMessageAction-FHGUFT2X.js → handleSendMessageAction-VQP5HT5I.js} +8 -8
- package/{hostCredentialCreate-T6SOV4FN.js → hostCredentialCreate-CPIWBALC.js} +13 -13
- package/index.js +3 -3
- package/{localAutomationCommands-TJCH7ZSF.js → localAutomationCommands-WPYIYTDP.js} +1 -1
- package/{localAutomationRuntime-RBAKV5LR.js → localAutomationRuntime-M7WWU6WY.js} +1 -1
- package/{localRuntimeAdapter-KH6UHNAO.js → localRuntimeAdapter-SNE2NUDN.js} +12 -12
- package/{machineCommands-F2Z4PV5E.js → machineCommands-LHJMILRA.js} +15 -15
- package/{machineWsRunDispatch-YY2FJP2O.js → machineWsRunDispatch-VHEIHXWY.js} +13 -13
- package/{memberThunks-NEZRAW5K.js → memberThunks-IPS3SLOF.js} +1 -1
- package/package.json +1 -1
- package/{projectArchive-WE3VVPZ2.js → projectArchive-HUET56SH.js} +4 -4
- package/{readlineWorkspace-CJ5M7SU6.js → readlineWorkspace-5EASNOQ4.js} +17 -17
- package/{runAgentClientLoop-2SFASHDS.js → runAgentClientLoop-ELTV5MSJ.js} +12 -12
- package/{streamAgentChatTurn-KOUWITHH.js → streamAgentChatTurn-BL3ESUEN.js} +14 -14
- package/{tools-WN4AVSNS.js → tools-KB6CJ2KT.js} +9 -9
- package/{updateDialogTitleAction-XOSLNRT3.js → updateDialogTitleAction-OPAZF5VC.js} +3 -3
- package/chunk-ZCMAKAZM.js +0 -184
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCurrentSpaceIdRaw,
|
|
3
|
+
setCurrentSpaceBoth,
|
|
4
|
+
setSpaceInitialized
|
|
5
|
+
} from "./chunk-JDMWYVUF.js";
|
|
6
|
+
import {
|
|
7
|
+
createSpaceKey,
|
|
8
|
+
normalizeSpaceId
|
|
9
|
+
} from "./chunk-UAD2WT54.js";
|
|
10
|
+
import {
|
|
11
|
+
getRuntimeServerSnapshot,
|
|
12
|
+
selectIdentityToken,
|
|
13
|
+
selectIdentityUserId
|
|
14
|
+
} from "./chunk-HI5RS2O4.js";
|
|
15
|
+
import {
|
|
16
|
+
fetchFromServer,
|
|
17
|
+
getAllServers,
|
|
18
|
+
googleSessionRequestToken,
|
|
19
|
+
isGoogleAuthoritySession,
|
|
20
|
+
scopeGoogleSessionServers
|
|
21
|
+
} from "./chunk-K7HLFORE.js";
|
|
22
|
+
import {
|
|
23
|
+
isTombstoneRecord
|
|
24
|
+
} from "./chunk-BV3FLP2L.js";
|
|
25
|
+
import {
|
|
26
|
+
API_ENDPOINTS
|
|
27
|
+
} from "./chunk-JKVOKKMQ.js";
|
|
28
|
+
|
|
29
|
+
// packages/create/space/spaceDirectoryScan.ts
|
|
30
|
+
var replicaStore = /* @__PURE__ */ new Map();
|
|
31
|
+
var userSpacesReplicaStore = /* @__PURE__ */ new Map();
|
|
32
|
+
var unsupportedScanOrigins = /* @__PURE__ */ new Set();
|
|
33
|
+
var WATERMARK_OVERLAP_MS = 5e3;
|
|
34
|
+
var DEFAULT_SCAN_PAGE_SIZE = 500;
|
|
35
|
+
var DEFAULT_MAX_SCAN_PAGES = 200;
|
|
36
|
+
var replicaCacheKey = (server, userId, spaceId) => `${server}|${userId}|${spaceId}`;
|
|
37
|
+
var userSpacesCacheKey = (server, userId) => `${server}|${userId}`;
|
|
38
|
+
function projectReplicaToSpaceData(spaceId, replica) {
|
|
39
|
+
if (replica.tombstoned) return null;
|
|
40
|
+
if (!replica.meta && replica.categories.size === 0 && replica.items.size === 0 && replica.members.size === 0) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const meta = replica.meta ?? {};
|
|
44
|
+
const categories = {};
|
|
45
|
+
for (const [catId, catVal] of replica.categories) {
|
|
46
|
+
categories[catId] = catVal;
|
|
47
|
+
}
|
|
48
|
+
const contents = {};
|
|
49
|
+
for (const [contentKey, itemVal] of replica.items) {
|
|
50
|
+
contents[contentKey] = itemVal;
|
|
51
|
+
}
|
|
52
|
+
const ownerId = typeof meta.ownerId === "string" ? meta.ownerId : "";
|
|
53
|
+
let members;
|
|
54
|
+
if (replica.hasObservedMembers) {
|
|
55
|
+
const memberSet = new Set(replica.members.keys());
|
|
56
|
+
if (ownerId) memberSet.add(ownerId);
|
|
57
|
+
members = Array.from(memberSet);
|
|
58
|
+
} else {
|
|
59
|
+
members = Array.isArray(meta.members) ? meta.members : [];
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
id: spaceId,
|
|
63
|
+
name: typeof meta.name === "string" && meta.name.trim() ? meta.name : spaceId,
|
|
64
|
+
description: typeof meta.description === "string" ? meta.description : "",
|
|
65
|
+
ownerId,
|
|
66
|
+
visibility: meta.visibility ?? "private",
|
|
67
|
+
members,
|
|
68
|
+
categories,
|
|
69
|
+
contents,
|
|
70
|
+
createdAt: typeof meta.createdAt === "number" ? meta.createdAt : 0,
|
|
71
|
+
updatedAt: typeof meta.updatedAt === "number" ? meta.updatedAt : replica.watermark
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function applyScanEntriesToReplica(spaceId, replica, entries, isFullSnapshot) {
|
|
75
|
+
if (isFullSnapshot) {
|
|
76
|
+
replica.meta = null;
|
|
77
|
+
replica.categories.clear();
|
|
78
|
+
replica.items.clear();
|
|
79
|
+
replica.members.clear();
|
|
80
|
+
replica.hasObservedMembers = false;
|
|
81
|
+
replica.tombstoned = false;
|
|
82
|
+
}
|
|
83
|
+
const metaKey = `sp:${spaceId}:meta`;
|
|
84
|
+
const catPrefix = `sp:${spaceId}:cat:`;
|
|
85
|
+
const itemPrefix = `sp:${spaceId}:item:`;
|
|
86
|
+
const memPrefix = `sp:${spaceId}:mem:`;
|
|
87
|
+
for (const entry of entries) {
|
|
88
|
+
if (!entry || typeof entry.key !== "string") continue;
|
|
89
|
+
const isDeleted = Boolean(entry.tombstone) || (entry.value ? isTombstoneRecord(entry.value) : false);
|
|
90
|
+
if (!isDeleted && !entry.value) continue;
|
|
91
|
+
if (entry.key === metaKey) {
|
|
92
|
+
if (isDeleted) {
|
|
93
|
+
replica.tombstoned = true;
|
|
94
|
+
replica.meta = null;
|
|
95
|
+
replica.categories.clear();
|
|
96
|
+
replica.items.clear();
|
|
97
|
+
replica.members.clear();
|
|
98
|
+
replica.hasObservedMembers = false;
|
|
99
|
+
} else {
|
|
100
|
+
replica.tombstoned = false;
|
|
101
|
+
replica.meta = entry.value;
|
|
102
|
+
}
|
|
103
|
+
} else if (entry.key.startsWith(catPrefix)) {
|
|
104
|
+
const catId = entry.key.slice(catPrefix.length);
|
|
105
|
+
if (!catId) continue;
|
|
106
|
+
if (isDeleted) {
|
|
107
|
+
replica.categories.delete(catId);
|
|
108
|
+
} else {
|
|
109
|
+
replica.categories.set(catId, {
|
|
110
|
+
name: typeof entry.value.name === "string" ? entry.value.name : "",
|
|
111
|
+
order: typeof entry.value.order === "number" ? entry.value.order : 0,
|
|
112
|
+
updatedAt: entry.updatedAt
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
} else if (entry.key.startsWith(itemPrefix)) {
|
|
116
|
+
const contentKey = entry.key.slice(itemPrefix.length);
|
|
117
|
+
if (!contentKey) continue;
|
|
118
|
+
if (isDeleted) {
|
|
119
|
+
replica.items.delete(contentKey);
|
|
120
|
+
} else {
|
|
121
|
+
replica.items.set(contentKey, {
|
|
122
|
+
...entry.value,
|
|
123
|
+
contentKey: typeof entry.value.contentKey === "string" ? entry.value.contentKey : contentKey
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
} else if (entry.key.startsWith(memPrefix)) {
|
|
127
|
+
const memberUserId = entry.key.slice(memPrefix.length);
|
|
128
|
+
if (!memberUserId) continue;
|
|
129
|
+
if (isFullSnapshot) {
|
|
130
|
+
replica.hasObservedMembers = true;
|
|
131
|
+
}
|
|
132
|
+
if (isDeleted) {
|
|
133
|
+
replica.members.delete(memberUserId);
|
|
134
|
+
} else {
|
|
135
|
+
replica.members.set(memberUserId, entry.value);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async function scanSpaceDirectoryOnServer(args) {
|
|
141
|
+
const {
|
|
142
|
+
server,
|
|
143
|
+
token,
|
|
144
|
+
userId,
|
|
145
|
+
timeoutMs = 5e3,
|
|
146
|
+
fetchImpl = fetch,
|
|
147
|
+
pageSize = DEFAULT_SCAN_PAGE_SIZE,
|
|
148
|
+
maxPages = DEFAULT_MAX_SCAN_PAGES
|
|
149
|
+
} = args;
|
|
150
|
+
const normalizedSpaceId = normalizeSpaceId(args.spaceId);
|
|
151
|
+
if (!normalizedSpaceId || !server || !token || !userId) {
|
|
152
|
+
return { status: "ok", record: null, membersAuthoritative: false };
|
|
153
|
+
}
|
|
154
|
+
const cleanOrigin = server.replace(/\/+$/, "");
|
|
155
|
+
if (unsupportedScanOrigins.has(cleanOrigin)) {
|
|
156
|
+
return { status: "unsupported" };
|
|
157
|
+
}
|
|
158
|
+
googleSessionRequestToken(token, cleanOrigin);
|
|
159
|
+
const cacheKey = replicaCacheKey(cleanOrigin, userId, normalizedSpaceId);
|
|
160
|
+
const existing = replicaStore.get(cacheKey);
|
|
161
|
+
const since = existing && existing.watermark > 0 ? Math.max(0, existing.watermark - WATERMARK_OVERLAP_MS) : 0;
|
|
162
|
+
const prefix = `sp:${normalizedSpaceId}:`;
|
|
163
|
+
const collectedEntries = [];
|
|
164
|
+
let cursor = null;
|
|
165
|
+
let firstPageWatermark = null;
|
|
166
|
+
let completedAllPages = false;
|
|
167
|
+
const controller = new AbortController();
|
|
168
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
169
|
+
try {
|
|
170
|
+
for (let pageIndex = 0; pageIndex < maxPages; pageIndex++) {
|
|
171
|
+
const params = new URLSearchParams({
|
|
172
|
+
prefix,
|
|
173
|
+
limit: String(pageSize)
|
|
174
|
+
});
|
|
175
|
+
if (since > 0) params.set("since", String(since));
|
|
176
|
+
if (cursor) params.set("cursor", cursor);
|
|
177
|
+
const response = await fetchImpl(
|
|
178
|
+
`${cleanOrigin}${API_ENDPOINTS.DATABASE}/scan?${params.toString()}`,
|
|
179
|
+
{
|
|
180
|
+
method: "GET",
|
|
181
|
+
...isGoogleAuthoritySession(token) ? { redirect: "error", credentials: "omit" } : {},
|
|
182
|
+
headers: {
|
|
183
|
+
Authorization: `Bearer ${token}`,
|
|
184
|
+
Accept: "application/json"
|
|
185
|
+
},
|
|
186
|
+
signal: controller.signal
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
if (response.status === 404 || response.status === 405 || response.status === 501) {
|
|
190
|
+
unsupportedScanOrigins.add(cleanOrigin);
|
|
191
|
+
return { status: "unsupported" };
|
|
192
|
+
}
|
|
193
|
+
if (response.status === 401 || response.status === 403) {
|
|
194
|
+
replicaStore.delete(cacheKey);
|
|
195
|
+
return {
|
|
196
|
+
status: "forbidden",
|
|
197
|
+
message: `Access denied scanning space ${normalizedSpaceId} (${response.status})`
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
if (!response.ok) {
|
|
201
|
+
throw new Error(`db/scan failed on ${cleanOrigin} (${response.status})`);
|
|
202
|
+
}
|
|
203
|
+
const payload = await response.json();
|
|
204
|
+
if (!payload || typeof payload !== "object" || payload.schemaVersion !== 1 || !Array.isArray(payload.entries)) {
|
|
205
|
+
unsupportedScanOrigins.add(cleanOrigin);
|
|
206
|
+
return { status: "unsupported" };
|
|
207
|
+
}
|
|
208
|
+
if (firstPageWatermark === null && typeof payload.serverWatermark === "number" && Number.isFinite(payload.serverWatermark)) {
|
|
209
|
+
firstPageWatermark = payload.serverWatermark;
|
|
210
|
+
}
|
|
211
|
+
for (const item of payload.entries) {
|
|
212
|
+
collectedEntries.push(item);
|
|
213
|
+
}
|
|
214
|
+
if (payload.hasMore) {
|
|
215
|
+
if (typeof payload.nextCursor !== "string" || !payload.nextCursor) {
|
|
216
|
+
throw new Error(`db/scan on ${cleanOrigin} reported hasMore without nextCursor`);
|
|
217
|
+
}
|
|
218
|
+
cursor = payload.nextCursor;
|
|
219
|
+
} else {
|
|
220
|
+
completedAllPages = true;
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
} finally {
|
|
225
|
+
clearTimeout(timer);
|
|
226
|
+
}
|
|
227
|
+
const latestWatermark = Math.max(existing?.watermark ?? 0, firstPageWatermark ?? 0);
|
|
228
|
+
if (!completedAllPages) {
|
|
229
|
+
throw new Error(
|
|
230
|
+
`db/scan exceeded page budget (${maxPages} pages) for space ${normalizedSpaceId}; refusing partial watermark commit`
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
const replica = existing ?? {
|
|
234
|
+
watermark: 0,
|
|
235
|
+
meta: null,
|
|
236
|
+
categories: /* @__PURE__ */ new Map(),
|
|
237
|
+
items: /* @__PURE__ */ new Map(),
|
|
238
|
+
members: /* @__PURE__ */ new Map(),
|
|
239
|
+
hasObservedMembers: false,
|
|
240
|
+
tombstoned: false
|
|
241
|
+
};
|
|
242
|
+
applyScanEntriesToReplica(normalizedSpaceId, replica, collectedEntries, since === 0);
|
|
243
|
+
replica.watermark = latestWatermark;
|
|
244
|
+
replicaStore.set(cacheKey, replica);
|
|
245
|
+
return {
|
|
246
|
+
status: "ok",
|
|
247
|
+
record: projectReplicaToSpaceData(normalizedSpaceId, replica),
|
|
248
|
+
membersAuthoritative: replica.hasObservedMembers
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
async function scanUserSpaceMembershipsOnServer(args) {
|
|
252
|
+
const {
|
|
253
|
+
server,
|
|
254
|
+
token,
|
|
255
|
+
userId,
|
|
256
|
+
timeoutMs = 5e3,
|
|
257
|
+
fetchImpl = fetch,
|
|
258
|
+
pageSize = DEFAULT_SCAN_PAGE_SIZE,
|
|
259
|
+
maxPages = DEFAULT_MAX_SCAN_PAGES
|
|
260
|
+
} = args;
|
|
261
|
+
if (!server || !token || !userId) {
|
|
262
|
+
return { status: "forbidden", message: "Missing server, token, or userId" };
|
|
263
|
+
}
|
|
264
|
+
const cleanOrigin = server.replace(/\/+$/, "");
|
|
265
|
+
if (unsupportedScanOrigins.has(cleanOrigin)) {
|
|
266
|
+
return { status: "unsupported" };
|
|
267
|
+
}
|
|
268
|
+
googleSessionRequestToken(token, cleanOrigin);
|
|
269
|
+
const cacheKey = userSpacesCacheKey(cleanOrigin, userId);
|
|
270
|
+
const existing = userSpacesReplicaStore.get(cacheKey);
|
|
271
|
+
const since = existing && existing.watermark > 0 ? Math.max(0, existing.watermark - WATERMARK_OVERLAP_MS) : 0;
|
|
272
|
+
const prefix = `usr:${userId}:sp:`;
|
|
273
|
+
const collectedEntries = [];
|
|
274
|
+
let cursor = null;
|
|
275
|
+
let firstPageWatermark = null;
|
|
276
|
+
let completedAllPages = false;
|
|
277
|
+
const controller = new AbortController();
|
|
278
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
279
|
+
try {
|
|
280
|
+
for (let pageIndex = 0; pageIndex < maxPages; pageIndex++) {
|
|
281
|
+
const params = new URLSearchParams({
|
|
282
|
+
prefix,
|
|
283
|
+
limit: String(pageSize)
|
|
284
|
+
});
|
|
285
|
+
if (since > 0) params.set("since", String(since));
|
|
286
|
+
if (cursor) params.set("cursor", cursor);
|
|
287
|
+
const response = await fetchImpl(
|
|
288
|
+
`${cleanOrigin}${API_ENDPOINTS.DATABASE}/scan?${params.toString()}`,
|
|
289
|
+
{
|
|
290
|
+
method: "GET",
|
|
291
|
+
...isGoogleAuthoritySession(token) ? { redirect: "error", credentials: "omit" } : {},
|
|
292
|
+
headers: {
|
|
293
|
+
Authorization: `Bearer ${token}`,
|
|
294
|
+
Accept: "application/json"
|
|
295
|
+
},
|
|
296
|
+
signal: controller.signal
|
|
297
|
+
}
|
|
298
|
+
);
|
|
299
|
+
if (response.status === 404 || response.status === 405 || response.status === 501) {
|
|
300
|
+
unsupportedScanOrigins.add(cleanOrigin);
|
|
301
|
+
return { status: "unsupported" };
|
|
302
|
+
}
|
|
303
|
+
if (response.status === 401 || response.status === 403) {
|
|
304
|
+
userSpacesReplicaStore.delete(cacheKey);
|
|
305
|
+
return {
|
|
306
|
+
status: "forbidden",
|
|
307
|
+
message: `Access denied scanning user spaces for ${userId} (${response.status})`
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
if (!response.ok) {
|
|
311
|
+
return {
|
|
312
|
+
status: "error",
|
|
313
|
+
message: `db/scan failed on ${cleanOrigin} (${response.status})`
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
let payload;
|
|
317
|
+
try {
|
|
318
|
+
payload = await response.json();
|
|
319
|
+
} catch {
|
|
320
|
+
return {
|
|
321
|
+
status: "error",
|
|
322
|
+
message: `db/scan returned non-JSON payload on ${cleanOrigin}`
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
if (!payload || typeof payload !== "object" || payload.schemaVersion !== 1 || !Array.isArray(payload.entries)) {
|
|
326
|
+
unsupportedScanOrigins.add(cleanOrigin);
|
|
327
|
+
return { status: "unsupported" };
|
|
328
|
+
}
|
|
329
|
+
if (firstPageWatermark === null && typeof payload.serverWatermark === "number" && Number.isFinite(payload.serverWatermark)) {
|
|
330
|
+
firstPageWatermark = payload.serverWatermark;
|
|
331
|
+
}
|
|
332
|
+
for (const item of payload.entries) {
|
|
333
|
+
collectedEntries.push(item);
|
|
334
|
+
}
|
|
335
|
+
if (payload.hasMore) {
|
|
336
|
+
if (typeof payload.nextCursor !== "string" || !payload.nextCursor) {
|
|
337
|
+
return {
|
|
338
|
+
status: "error",
|
|
339
|
+
message: `db/scan on ${cleanOrigin} reported hasMore without nextCursor`
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
cursor = payload.nextCursor;
|
|
343
|
+
} else {
|
|
344
|
+
completedAllPages = true;
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
} catch (err) {
|
|
349
|
+
return {
|
|
350
|
+
status: "error",
|
|
351
|
+
message: err instanceof Error ? err.message : String(err)
|
|
352
|
+
};
|
|
353
|
+
} finally {
|
|
354
|
+
clearTimeout(timer);
|
|
355
|
+
}
|
|
356
|
+
if (!completedAllPages) {
|
|
357
|
+
return {
|
|
358
|
+
status: "error",
|
|
359
|
+
message: `db/scan exceeded page budget (${maxPages} pages) for user ${userId}`
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
const replica = existing ?? {
|
|
363
|
+
watermark: 0,
|
|
364
|
+
memberships: /* @__PURE__ */ new Map()
|
|
365
|
+
};
|
|
366
|
+
if (since === 0) {
|
|
367
|
+
replica.memberships.clear();
|
|
368
|
+
}
|
|
369
|
+
for (const entry of collectedEntries) {
|
|
370
|
+
if (!entry || typeof entry.key !== "string" || !entry.key.startsWith(prefix)) {
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
const rawSpaceId = entry.key.slice(prefix.length);
|
|
374
|
+
const normalizedSpaceId = normalizeSpaceId(rawSpaceId);
|
|
375
|
+
if (!normalizedSpaceId) continue;
|
|
376
|
+
const isDeleted = Boolean(entry.tombstone) || (entry.value ? isTombstoneRecord(entry.value) : false);
|
|
377
|
+
if (!isDeleted && !entry.value) continue;
|
|
378
|
+
if (isDeleted) {
|
|
379
|
+
replica.memberships.delete(normalizedSpaceId);
|
|
380
|
+
} else {
|
|
381
|
+
replica.memberships.set(normalizedSpaceId, {
|
|
382
|
+
...entry.value,
|
|
383
|
+
userId: typeof entry.value.userId === "string" ? entry.value.userId : userId,
|
|
384
|
+
spaceId: normalizedSpaceId
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
replica.watermark = Math.max(existing?.watermark ?? 0, firstPageWatermark ?? 0);
|
|
389
|
+
userSpacesReplicaStore.set(cacheKey, replica);
|
|
390
|
+
return {
|
|
391
|
+
status: "ok",
|
|
392
|
+
memberships: Array.from(replica.memberships.values())
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// packages/create/space/spaceAccess.ts
|
|
397
|
+
var resolveSpaceRemoteServers = (state) => {
|
|
398
|
+
const { currentServer, syncServers } = getRuntimeServerSnapshot(state);
|
|
399
|
+
return scopeGoogleSessionServers(selectIdentityToken(state), currentServer, getAllServers(currentServer, [...syncServers]));
|
|
400
|
+
};
|
|
401
|
+
var selectSpaceRemoteAuth = (state) => ({
|
|
402
|
+
token: selectIdentityToken(state) ?? null,
|
|
403
|
+
userId: selectIdentityUserId(state) ?? null,
|
|
404
|
+
servers: resolveSpaceRemoteServers(state)
|
|
405
|
+
});
|
|
406
|
+
var spaceListsUser = (spaceData, userId) => {
|
|
407
|
+
if (!spaceData || isTombstoneRecord(spaceData)) return false;
|
|
408
|
+
if (spaceData.ownerId === userId) return true;
|
|
409
|
+
return Array.isArray(spaceData.members) && spaceData.members.includes(userId);
|
|
410
|
+
};
|
|
411
|
+
var membershipBelongsToUser = (membership, userId) => !membership.userId || membership.userId === userId;
|
|
412
|
+
var membershipFetchCache = /* @__PURE__ */ new Map();
|
|
413
|
+
var MEMBERSHIP_FETCH_CACHE_TTL_MS = 3e4;
|
|
414
|
+
var resolveDesktopShellRuntime = () => {
|
|
415
|
+
if (typeof window === "undefined") return { isEmbeddedRuntime: false };
|
|
416
|
+
const shellWindow = window;
|
|
417
|
+
return {
|
|
418
|
+
isEmbeddedRuntime: shellWindow.__NOLO_EMBEDDED_RUNTIME__ === true,
|
|
419
|
+
runtimeOrigin: shellWindow.location?.origin
|
|
420
|
+
};
|
|
421
|
+
};
|
|
422
|
+
var isEmbeddedRuntimeServer = (server, runtime = resolveDesktopShellRuntime()) => {
|
|
423
|
+
if (!runtime.isEmbeddedRuntime || !runtime.runtimeOrigin) return false;
|
|
424
|
+
try {
|
|
425
|
+
return new URL(server).origin === runtime.runtimeOrigin;
|
|
426
|
+
} catch {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
async function fetchMembershipsFromServer(server, token, userId, timeoutMs) {
|
|
431
|
+
if (!token) return { ok: false, memberships: [] };
|
|
432
|
+
const scanOutcome = await scanUserSpaceMembershipsOnServer({
|
|
433
|
+
server,
|
|
434
|
+
token,
|
|
435
|
+
userId,
|
|
436
|
+
timeoutMs
|
|
437
|
+
});
|
|
438
|
+
if (scanOutcome.status === "ok") {
|
|
439
|
+
return { ok: true, server, memberships: scanOutcome.memberships };
|
|
440
|
+
}
|
|
441
|
+
if (scanOutcome.status === "forbidden" || scanOutcome.status === "error") {
|
|
442
|
+
console.error(`Failed to scan memberships from ${server}: ${scanOutcome.message}`);
|
|
443
|
+
return { ok: false, memberships: [] };
|
|
444
|
+
}
|
|
445
|
+
googleSessionRequestToken(token, server);
|
|
446
|
+
const controller = new AbortController();
|
|
447
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
448
|
+
try {
|
|
449
|
+
const response = await fetch(`${server}/rpc/getUserSpaceMemberships`, {
|
|
450
|
+
method: "POST",
|
|
451
|
+
...isGoogleAuthoritySession(token) ? { redirect: "error", credentials: "omit" } : {},
|
|
452
|
+
headers: {
|
|
453
|
+
Authorization: `Bearer ${token}`,
|
|
454
|
+
"Content-Type": "application/json"
|
|
455
|
+
},
|
|
456
|
+
body: JSON.stringify({ userId, pureRead: true }),
|
|
457
|
+
signal: controller.signal
|
|
458
|
+
});
|
|
459
|
+
clearTimeout(timeoutId);
|
|
460
|
+
if (!response.ok) {
|
|
461
|
+
console.error(
|
|
462
|
+
`Failed to fetch memberships from ${server}: ${response.statusText}`
|
|
463
|
+
);
|
|
464
|
+
return { ok: false, memberships: [] };
|
|
465
|
+
}
|
|
466
|
+
const data = await response.json();
|
|
467
|
+
return {
|
|
468
|
+
ok: true,
|
|
469
|
+
server,
|
|
470
|
+
memberships: Array.isArray(data) ? data : []
|
|
471
|
+
};
|
|
472
|
+
} catch (error) {
|
|
473
|
+
clearTimeout(timeoutId);
|
|
474
|
+
console.error(`Error fetching memberships from ${server}:`, error);
|
|
475
|
+
return { ok: false, memberships: [] };
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
var fetchRemoteUserSpaceMemberships = (server, token, userId, timeoutMs = 5e3) => {
|
|
479
|
+
if (isEmbeddedRuntimeServer(server)) {
|
|
480
|
+
return Promise.resolve({ ok: false, memberships: [] });
|
|
481
|
+
}
|
|
482
|
+
const cacheKey = `${server}|${userId}`;
|
|
483
|
+
const cached = membershipFetchCache.get(cacheKey);
|
|
484
|
+
if (cached) return cached;
|
|
485
|
+
const promise = fetchMembershipsFromServer(server, token, userId, timeoutMs);
|
|
486
|
+
membershipFetchCache.set(cacheKey, promise);
|
|
487
|
+
promise.catch(() => {
|
|
488
|
+
}).finally(() => {
|
|
489
|
+
setTimeout(() => {
|
|
490
|
+
if (membershipFetchCache.get(cacheKey) === promise) {
|
|
491
|
+
membershipFetchCache.delete(cacheKey);
|
|
492
|
+
}
|
|
493
|
+
}, MEMBERSHIP_FETCH_CACHE_TTL_MS);
|
|
494
|
+
});
|
|
495
|
+
return promise;
|
|
496
|
+
};
|
|
497
|
+
var fetchRemoteSpace = async (server, token, spaceId) => {
|
|
498
|
+
try {
|
|
499
|
+
const space = await fetchFromServer(
|
|
500
|
+
server,
|
|
501
|
+
createSpaceKey.space(normalizeSpaceId(spaceId)),
|
|
502
|
+
token ?? void 0
|
|
503
|
+
);
|
|
504
|
+
return space && typeof space === "object" ? space : null;
|
|
505
|
+
} catch {
|
|
506
|
+
return null;
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
var hasActiveRemoteMembership = async (server, token, userId, spaceId) => {
|
|
510
|
+
const result = await fetchRemoteUserSpaceMemberships(server, token, userId);
|
|
511
|
+
if (!result.ok) return false;
|
|
512
|
+
const normalizedSpaceId = normalizeSpaceId(spaceId);
|
|
513
|
+
return result.memberships.some((membership) => {
|
|
514
|
+
const membershipSpaceId = typeof membership?.spaceId === "string" ? normalizeSpaceId(membership.spaceId) : "";
|
|
515
|
+
return membershipSpaceId === normalizedSpaceId && membershipBelongsToUser(membership, userId) && !isTombstoneRecord(membership);
|
|
516
|
+
});
|
|
517
|
+
};
|
|
518
|
+
var fetchAuthoritativeRemoteSpace = async ({
|
|
519
|
+
servers,
|
|
520
|
+
token,
|
|
521
|
+
userId,
|
|
522
|
+
spaceId
|
|
523
|
+
}) => {
|
|
524
|
+
const normalizedSpaceId = normalizeSpaceId(spaceId);
|
|
525
|
+
for (const server of servers) {
|
|
526
|
+
const space = await fetchRemoteSpace(server, token, normalizedSpaceId);
|
|
527
|
+
if (!space) continue;
|
|
528
|
+
if (!spaceListsUser(space, userId)) {
|
|
529
|
+
throw new Error(`Current user is not a member of space: ${normalizedSpaceId}`);
|
|
530
|
+
}
|
|
531
|
+
if (space.ownerId !== userId) {
|
|
532
|
+
const hasMembership = await hasActiveRemoteMembership(
|
|
533
|
+
server,
|
|
534
|
+
token,
|
|
535
|
+
userId,
|
|
536
|
+
normalizedSpaceId
|
|
537
|
+
);
|
|
538
|
+
if (!hasMembership) {
|
|
539
|
+
throw new Error(
|
|
540
|
+
`Current user has no active membership for space: ${normalizedSpaceId}`
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return space;
|
|
545
|
+
}
|
|
546
|
+
return null;
|
|
547
|
+
};
|
|
548
|
+
var fetchAuthoritativeSpaceDirectory = async ({
|
|
549
|
+
servers,
|
|
550
|
+
token,
|
|
551
|
+
userId,
|
|
552
|
+
spaceId
|
|
553
|
+
}) => {
|
|
554
|
+
const normalizedSpaceId = normalizeSpaceId(spaceId);
|
|
555
|
+
if (!normalizedSpaceId) return null;
|
|
556
|
+
let sawForbidden = null;
|
|
557
|
+
for (const server of servers) {
|
|
558
|
+
const outcome = await scanSpaceDirectoryOnServer({
|
|
559
|
+
server,
|
|
560
|
+
token,
|
|
561
|
+
userId,
|
|
562
|
+
spaceId: normalizedSpaceId
|
|
563
|
+
});
|
|
564
|
+
if (outcome.status === "unsupported") {
|
|
565
|
+
const legacySpace = await fetchAuthoritativeRemoteSpace({
|
|
566
|
+
servers: [server],
|
|
567
|
+
token,
|
|
568
|
+
userId,
|
|
569
|
+
spaceId: normalizedSpaceId
|
|
570
|
+
});
|
|
571
|
+
if (legacySpace) return legacySpace;
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
if (outcome.status === "forbidden") {
|
|
575
|
+
sawForbidden = outcome.message;
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
if (outcome.record) {
|
|
579
|
+
if (outcome.membersAuthoritative) {
|
|
580
|
+
return outcome.record;
|
|
581
|
+
}
|
|
582
|
+
const body = await fetchRemoteSpace(server, token, normalizedSpaceId);
|
|
583
|
+
return {
|
|
584
|
+
...outcome.record,
|
|
585
|
+
members: body && !isTombstoneRecord(body) && Array.isArray(body.members) ? body.members : []
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
if (sawForbidden) {
|
|
590
|
+
throw new Error(sawForbidden);
|
|
591
|
+
}
|
|
592
|
+
return null;
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
// packages/create/space/applyFetchSpaceFulfilled.ts
|
|
596
|
+
function applyFetchSpaceFulfilled(payload) {
|
|
597
|
+
const { spaceId, spaceData } = payload;
|
|
598
|
+
const currentSpaceId = getCurrentSpaceIdRaw();
|
|
599
|
+
if (!currentSpaceId || currentSpaceId === spaceId) {
|
|
600
|
+
setCurrentSpaceBoth(spaceId, spaceData);
|
|
601
|
+
setSpaceInitialized();
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
export {
|
|
606
|
+
selectSpaceRemoteAuth,
|
|
607
|
+
spaceListsUser,
|
|
608
|
+
membershipBelongsToUser,
|
|
609
|
+
fetchRemoteUserSpaceMemberships,
|
|
610
|
+
fetchRemoteSpace,
|
|
611
|
+
fetchAuthoritativeSpaceDirectory,
|
|
612
|
+
applyFetchSpaceFulfilled
|
|
613
|
+
};
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
runAgentTurn,
|
|
11
11
|
shouldPrintLocalRunSummary,
|
|
12
12
|
unknownLocalRunAcceptance
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-XGYQCBWS.js";
|
|
14
14
|
import {
|
|
15
15
|
getReadableCliDb
|
|
16
16
|
} from "./chunk-LRLLWD4P.js";
|
|
@@ -28,10 +28,10 @@ import {
|
|
|
28
28
|
resolveServerUrl,
|
|
29
29
|
validateInstaboxWorkspaceSelection,
|
|
30
30
|
writeUsage
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-DXDCL3Z6.js";
|
|
32
32
|
import {
|
|
33
33
|
CliProviderQuotaError
|
|
34
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-DALXH7BG.js";
|
|
35
35
|
import {
|
|
36
36
|
parsePositiveFiniteNumberOrFallback
|
|
37
37
|
} from "./chunk-Y5GCAMGP.js";
|
|
@@ -3,17 +3,17 @@ import {
|
|
|
3
3
|
getOrCreateSharedStore,
|
|
4
4
|
isCliProviderAgentConfig,
|
|
5
5
|
summarizeEndpoint
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-DXDCL3Z6.js";
|
|
7
7
|
import {
|
|
8
8
|
attachExecutionStoppedPromise,
|
|
9
9
|
getExecutionStoppedPromise
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-DALXH7BG.js";
|
|
11
11
|
import {
|
|
12
12
|
isCursorOAuthAgent
|
|
13
13
|
} from "./chunk-VIWDGTDA.js";
|
|
14
14
|
import {
|
|
15
15
|
clipMultilineText
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-CYS6HOJ2.js";
|
|
17
17
|
import {
|
|
18
18
|
DialogTurnBusyError,
|
|
19
19
|
acquireLocalDialogTurnLease,
|
|
@@ -538,7 +538,7 @@ var runLlm = agentOperation("runLlm", async (args, thunkApi) => {
|
|
|
538
538
|
const overrides = {};
|
|
539
539
|
if (args.systemPromptOverride !== void 0) overrides.prompt = args.systemPromptOverride;
|
|
540
540
|
if (args.toolsOverride !== void 0) overrides.tools = args.toolsOverride;
|
|
541
|
-
const { _executeModel } = await import("./_executeModel-
|
|
541
|
+
const { _executeModel } = await import("./_executeModel-B3ENLKM4.js");
|
|
542
542
|
return _executeModel(
|
|
543
543
|
{
|
|
544
544
|
isStreaming: args.isStreaming ?? false,
|
|
@@ -551,7 +551,7 @@ var runLlm = agentOperation("runLlm", async (args, thunkApi) => {
|
|
|
551
551
|
);
|
|
552
552
|
});
|
|
553
553
|
var runAgent = agentOperation("runAgent", async (args, thunkApi) => {
|
|
554
|
-
const { runAgentClientLoop } = await import("./runAgentClientLoop-
|
|
554
|
+
const { runAgentClientLoop } = await import("./runAgentClientLoop-ELTV5MSJ.js");
|
|
555
555
|
const { content: loopContent, toolCallCount } = await runAgentClientLoop(
|
|
556
556
|
{
|
|
557
557
|
agentKey: args.agentKey,
|
|
@@ -564,7 +564,7 @@ var runAgent = agentOperation("runAgent", async (args, thunkApi) => {
|
|
|
564
564
|
return loopContent;
|
|
565
565
|
});
|
|
566
566
|
var streamAgentChatTurn = agentOperation("streamAgentChatTurn", async (args, thunkApi) => {
|
|
567
|
-
const { streamAgentChatTurnHandler } = await import("./streamAgentChatTurn-
|
|
567
|
+
const { streamAgentChatTurnHandler } = await import("./streamAgentChatTurn-BL3ESUEN.js");
|
|
568
568
|
return streamAgentChatTurnHandler(args, thunkApi);
|
|
569
569
|
});
|
|
570
570
|
var createAgent = agentOperation(
|