@xiaou66/vite-plugin-vue-mcp-next 1.1.0 → 1.2.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.
@@ -1092,6 +1092,390 @@ function createTimeout(timeoutMs) {
1092
1092
  });
1093
1093
  }
1094
1094
 
1095
+ // src/runtime/storageBridge.ts
1096
+ function createRuntimeStorageBridge(env) {
1097
+ return {
1098
+ async manageStorage(request) {
1099
+ try {
1100
+ return await manageRuntimeStorage(env, request);
1101
+ } catch (error) {
1102
+ return createRuntimeStorageError(
1103
+ request,
1104
+ error instanceof Error ? error.message : String(error)
1105
+ );
1106
+ }
1107
+ }
1108
+ };
1109
+ }
1110
+ async function manageRuntimeStorage(env, request) {
1111
+ if (request.origin !== env.origin) {
1112
+ return createRuntimeStorageError(
1113
+ request,
1114
+ "Runtime storage access is limited to the current page origin"
1115
+ );
1116
+ }
1117
+ if (request.scope === "cookie") {
1118
+ return manageRuntimeCookie(env, request);
1119
+ }
1120
+ if (request.scope === "indexedDB") {
1121
+ return manageRuntimeIndexedDb(env, request);
1122
+ }
1123
+ return manageRuntimeWebStorage(getWebStorage(env, request.scope), request);
1124
+ }
1125
+ function manageRuntimeCookie(env, request) {
1126
+ if (!env.cookie) {
1127
+ return createRuntimeStorageError(
1128
+ request,
1129
+ "Runtime cookie access is unavailable",
1130
+ ["document.cookie is not available in this runtime environment"]
1131
+ );
1132
+ }
1133
+ if (request.action === "list") {
1134
+ return createRuntimeStorageSuccess(request, {
1135
+ origin: request.origin,
1136
+ cookies: readRuntimeCookies(env.cookie)
1137
+ });
1138
+ }
1139
+ if (request.action === "get") {
1140
+ assertCookieName(request);
1141
+ return createRuntimeStorageSuccess(request, {
1142
+ origin: request.origin,
1143
+ cookies: readRuntimeCookies(env.cookie).filter(
1144
+ (cookie) => cookie.name === request.cookie.name
1145
+ )
1146
+ });
1147
+ }
1148
+ if (request.action === "set") {
1149
+ assertCookieName(request);
1150
+ env.cookie.set(createRuntimeCookieWrite(request));
1151
+ return createRuntimeStorageSuccess(request, { ok: true });
1152
+ }
1153
+ if (request.action === "delete") {
1154
+ assertCookieName(request);
1155
+ env.cookie.set(createRuntimeCookieDelete(request));
1156
+ return createRuntimeStorageSuccess(request, {
1157
+ deletedCount: 1,
1158
+ skippedHttpOnlyCount: 0,
1159
+ limitations: ["HttpOnly cookies are invisible to runtime cookie access"]
1160
+ });
1161
+ }
1162
+ const cookies = readRuntimeCookies(env.cookie);
1163
+ for (const cookie of cookies) {
1164
+ env.cookie.set(
1165
+ createRuntimeCookieDelete({
1166
+ ...request,
1167
+ cookie: {
1168
+ name: cookie.name,
1169
+ path: request.cookie?.path
1170
+ }
1171
+ })
1172
+ );
1173
+ }
1174
+ return createRuntimeStorageSuccess(request, {
1175
+ deletedCount: cookies.length,
1176
+ skippedHttpOnlyCount: 0,
1177
+ limitations: ["HttpOnly cookies are invisible to runtime cookie access"]
1178
+ });
1179
+ }
1180
+ function getWebStorage(env, scope) {
1181
+ return scope === "sessionStorage" ? env.sessionStorage : env.localStorage;
1182
+ }
1183
+ function manageRuntimeWebStorage(storage, request) {
1184
+ if (request.action === "list") {
1185
+ return createRuntimeStorageSuccess(request, {
1186
+ origin: request.origin,
1187
+ scope: request.scope,
1188
+ entries: readStorageEntries(storage)
1189
+ });
1190
+ }
1191
+ if (request.action === "get") {
1192
+ assertStorageKey(request);
1193
+ return createRuntimeStorageSuccess(request, {
1194
+ origin: request.origin,
1195
+ scope: request.scope,
1196
+ key: request.key,
1197
+ value: storage.getItem(request.key)
1198
+ });
1199
+ }
1200
+ if (request.action === "set") {
1201
+ assertStorageKey(request);
1202
+ storage.setItem(request.key, request.value ?? "");
1203
+ return createRuntimeStorageSuccess(request, { ok: true });
1204
+ }
1205
+ if (request.action === "delete") {
1206
+ assertStorageKey(request);
1207
+ storage.removeItem(request.key);
1208
+ return createRuntimeStorageSuccess(request, { ok: true });
1209
+ }
1210
+ storage.clear();
1211
+ return createRuntimeStorageSuccess(request, { ok: true });
1212
+ }
1213
+ async function manageRuntimeIndexedDb(env, request) {
1214
+ if (!env.indexedDB?.databases) {
1215
+ return createRuntimeStorageError(request, "IndexedDB metadata API is unavailable");
1216
+ }
1217
+ if (request.action === "list") {
1218
+ const databases = await env.indexedDB.databases();
1219
+ return createRuntimeStorageSuccess(request, {
1220
+ origin: request.origin,
1221
+ scope: request.scope,
1222
+ databases: databases.map((database) => ({
1223
+ name: database.name,
1224
+ version: database.version
1225
+ }))
1226
+ });
1227
+ }
1228
+ assertIndexedDbTarget(request);
1229
+ if ("stores" in env.indexedDB) {
1230
+ return manageMemoryIndexedDb(env.indexedDB, request);
1231
+ }
1232
+ return manageBrowserIndexedDb(env.indexedDB, request);
1233
+ }
1234
+ function manageMemoryIndexedDb(indexedDB, request) {
1235
+ const storeId = `${request.databaseName}:${request.objectStoreName}`;
1236
+ const store = indexedDB.stores.get(storeId) ?? /* @__PURE__ */ new Map();
1237
+ indexedDB.stores.set(storeId, store);
1238
+ if (request.action === "get") {
1239
+ assertStorageKey(request);
1240
+ return createRuntimeStorageSuccess(request, {
1241
+ key: request.key,
1242
+ value: store.get(request.key) ?? null
1243
+ });
1244
+ }
1245
+ if (request.action === "set") {
1246
+ assertStorageKey(request);
1247
+ store.set(request.key, parseIndexedDbValue(request.value));
1248
+ return createRuntimeStorageSuccess(request, { ok: true });
1249
+ }
1250
+ if (request.action === "delete") {
1251
+ assertStorageKey(request);
1252
+ store.delete(request.key);
1253
+ return createRuntimeStorageSuccess(request, { ok: true });
1254
+ }
1255
+ store.clear();
1256
+ return createRuntimeStorageSuccess(request, { ok: true });
1257
+ }
1258
+ async function manageBrowserIndexedDb(indexedDB, request) {
1259
+ const database = await openIndexedDbForRequest(indexedDB, request);
1260
+ try {
1261
+ return await executeIndexedDbTransaction(database, request);
1262
+ } finally {
1263
+ database.close();
1264
+ }
1265
+ }
1266
+ function openIndexedDb(indexedDB, databaseName) {
1267
+ return new Promise((resolve, reject) => {
1268
+ const request = indexedDB.open(databaseName);
1269
+ request.onerror = () => {
1270
+ reject(request.error ?? new Error("IndexedDB open failed"));
1271
+ };
1272
+ request.onsuccess = () => {
1273
+ resolve(request.result);
1274
+ };
1275
+ });
1276
+ }
1277
+ async function openIndexedDbForRequest(indexedDB, request) {
1278
+ const database = await openIndexedDb(indexedDB, request.databaseName);
1279
+ if (request.action !== "set" || database.objectStoreNames.contains(request.objectStoreName)) {
1280
+ return database;
1281
+ }
1282
+ const version = database.version + 1;
1283
+ database.close();
1284
+ return openIndexedDbWithStore(indexedDB, {
1285
+ databaseName: request.databaseName,
1286
+ objectStoreName: request.objectStoreName,
1287
+ version
1288
+ });
1289
+ }
1290
+ function openIndexedDbWithStore(indexedDB, options) {
1291
+ return new Promise((resolve, reject) => {
1292
+ const request = indexedDB.open(options.databaseName, options.version);
1293
+ request.onupgradeneeded = () => {
1294
+ const database = request.result;
1295
+ if (!database.objectStoreNames.contains(options.objectStoreName)) {
1296
+ database.createObjectStore(options.objectStoreName);
1297
+ }
1298
+ };
1299
+ request.onerror = () => {
1300
+ reject(request.error ?? new Error("IndexedDB upgrade failed"));
1301
+ };
1302
+ request.onsuccess = () => {
1303
+ resolve(request.result);
1304
+ };
1305
+ });
1306
+ }
1307
+ function executeIndexedDbTransaction(database, request) {
1308
+ return new Promise((resolve, reject) => {
1309
+ const mode = request.action === "get" ? "readonly" : "readwrite";
1310
+ const transaction = database.transaction(request.objectStoreName, mode);
1311
+ const store = transaction.objectStore(request.objectStoreName);
1312
+ transaction.onerror = () => {
1313
+ reject(transaction.error ?? new Error("IndexedDB transaction failed"));
1314
+ };
1315
+ if (request.action === "get") {
1316
+ assertStorageKey(request);
1317
+ const getRequest = store.get(request.key);
1318
+ getRequest.onerror = () => {
1319
+ reject(getRequest.error ?? new Error("IndexedDB get failed"));
1320
+ };
1321
+ getRequest.onsuccess = () => {
1322
+ const value = getRequest.result ?? null;
1323
+ resolve(
1324
+ createRuntimeStorageSuccess(request, {
1325
+ key: request.key,
1326
+ value
1327
+ })
1328
+ );
1329
+ };
1330
+ return;
1331
+ }
1332
+ if (request.action === "set") {
1333
+ assertStorageKey(request);
1334
+ store.put(parseIndexedDbValue(request.value), request.key);
1335
+ transaction.oncomplete = () => {
1336
+ resolve(createRuntimeStorageSuccess(request, { ok: true }));
1337
+ };
1338
+ return;
1339
+ }
1340
+ if (request.action === "delete") {
1341
+ assertStorageKey(request);
1342
+ store.delete(request.key);
1343
+ transaction.oncomplete = () => {
1344
+ resolve(createRuntimeStorageSuccess(request, { ok: true }));
1345
+ };
1346
+ return;
1347
+ }
1348
+ store.clear();
1349
+ transaction.oncomplete = () => {
1350
+ resolve(createRuntimeStorageSuccess(request, { ok: true }));
1351
+ };
1352
+ });
1353
+ }
1354
+ function readStorageEntries(storage) {
1355
+ const entries = [];
1356
+ for (let index = 0; index < storage.length; index += 1) {
1357
+ const key = storage.key(index);
1358
+ if (!key) {
1359
+ continue;
1360
+ }
1361
+ const value = storage.getItem(key);
1362
+ if (value === null) {
1363
+ continue;
1364
+ }
1365
+ entries.push({ key, value });
1366
+ }
1367
+ return entries;
1368
+ }
1369
+ function readRuntimeCookies(cookieAccess) {
1370
+ return cookieAccess.get().split(";").map((item) => item.trim()).filter(Boolean).map((item) => {
1371
+ const separatorIndex = item.indexOf("=");
1372
+ if (separatorIndex === -1) {
1373
+ return { name: decodeCookiePart(item), value: "" };
1374
+ }
1375
+ return {
1376
+ name: decodeCookiePart(item.slice(0, separatorIndex)),
1377
+ value: decodeCookiePart(item.slice(separatorIndex + 1))
1378
+ };
1379
+ });
1380
+ }
1381
+ function createRuntimeCookieWrite(request) {
1382
+ const value = request.cookie.value ?? request.value ?? "";
1383
+ const parts = [
1384
+ `${encodeURIComponent(request.cookie.name)}=${encodeURIComponent(value)}`
1385
+ ];
1386
+ appendRuntimeCookieAttributes(parts, request.cookie);
1387
+ return parts.join("; ");
1388
+ }
1389
+ function createRuntimeCookieDelete(request) {
1390
+ const parts = [
1391
+ `${encodeURIComponent(request.cookie.name)}=`,
1392
+ "Expires=Thu, 01 Jan 1970 00:00:00 GMT",
1393
+ "Max-Age=0"
1394
+ ];
1395
+ appendRuntimeCookieAttributes(parts, {
1396
+ path: request.cookie.path,
1397
+ domain: request.cookie.domain
1398
+ });
1399
+ return parts.join("; ");
1400
+ }
1401
+ function appendRuntimeCookieAttributes(parts, cookie) {
1402
+ if (cookie.path) {
1403
+ parts.push(`Path=${cookie.path}`);
1404
+ }
1405
+ if (cookie.domain) {
1406
+ parts.push(`Domain=${cookie.domain}`);
1407
+ }
1408
+ if (cookie.expires !== void 0) {
1409
+ parts.push(`Expires=${new Date(cookie.expires * 1e3).toUTCString()}`);
1410
+ }
1411
+ if (cookie.sameSite) {
1412
+ parts.push(`SameSite=${normalizeRuntimeSameSite(cookie.sameSite)}`);
1413
+ }
1414
+ if (cookie.secure) {
1415
+ parts.push("Secure");
1416
+ }
1417
+ }
1418
+ function normalizeRuntimeSameSite(sameSite) {
1419
+ if (sameSite === "strict") {
1420
+ return "Strict";
1421
+ }
1422
+ if (sameSite === "lax") {
1423
+ return "Lax";
1424
+ }
1425
+ return "None";
1426
+ }
1427
+ function decodeCookiePart(value) {
1428
+ try {
1429
+ return decodeURIComponent(value);
1430
+ } catch {
1431
+ return value;
1432
+ }
1433
+ }
1434
+ function assertStorageKey(request) {
1435
+ if (!request.key) {
1436
+ throw new Error("Storage key is required for this operation");
1437
+ }
1438
+ }
1439
+ function assertCookieName(request) {
1440
+ if (!request.cookie?.name) {
1441
+ throw new Error("Cookie name is required for this operation");
1442
+ }
1443
+ }
1444
+ function assertIndexedDbTarget(request) {
1445
+ if (!request.databaseName || !request.objectStoreName) {
1446
+ throw new Error("IndexedDB databaseName and objectStoreName are required");
1447
+ }
1448
+ }
1449
+ function parseIndexedDbValue(value) {
1450
+ if (value === void 0) {
1451
+ return null;
1452
+ }
1453
+ try {
1454
+ return JSON.parse(value);
1455
+ } catch {
1456
+ return value;
1457
+ }
1458
+ }
1459
+ function createRuntimeStorageSuccess(request, data) {
1460
+ return {
1461
+ ok: true,
1462
+ source: "hook",
1463
+ action: request.action,
1464
+ scope: request.scope,
1465
+ data
1466
+ };
1467
+ }
1468
+ function createRuntimeStorageError(request, error, limitations) {
1469
+ return {
1470
+ ok: false,
1471
+ source: "hook",
1472
+ action: request.action,
1473
+ scope: request.scope,
1474
+ error,
1475
+ limitations
1476
+ };
1477
+ }
1478
+
1095
1479
  // src/runtime/devtoolsBridge.ts
1096
1480
  function createRuntimeDevtoolsRpc(getRpc) {
1097
1481
  return {
@@ -1147,7 +1531,26 @@ function createRuntimeDevtoolsRpc(getRpc) {
1147
1531
  });
1148
1532
  }
1149
1533
  },
1150
- onScreenshotTaken: () => void 0
1534
+ onScreenshotTaken: () => void 0,
1535
+ async manageStorage(options) {
1536
+ const bridge = createRuntimeStorageBridge({
1537
+ origin: window.location.origin,
1538
+ localStorage: window.localStorage,
1539
+ sessionStorage: window.sessionStorage,
1540
+ indexedDB: window.indexedDB,
1541
+ cookie: {
1542
+ get: () => window.document.cookie,
1543
+ set: (value) => {
1544
+ window.document.cookie = value;
1545
+ }
1546
+ }
1547
+ });
1548
+ getRpc().onStorageUpdated(
1549
+ options.event,
1550
+ await bridge.manageStorage(options)
1551
+ );
1552
+ },
1553
+ onStorageUpdated: () => void 0
1151
1554
  };
1152
1555
  }
1153
1556