@axiom-lattice/gateway 2.1.101 → 2.1.103

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/dist/index.mjs CHANGED
@@ -3,6 +3,10 @@ import {
3
3
  getQrCode,
4
4
  getQrCodeStatus
5
5
  } from "./chunk-6CUQGDJI.mjs";
6
+ import {
7
+ getContentTypeFromFilename,
8
+ getFilenameFromPath
9
+ } from "./chunk-R4ZO3HZ3.mjs";
6
10
 
7
11
  // src/index.ts
8
12
  import fastify from "fastify";
@@ -3058,31 +3062,6 @@ var sandboxService = new SandboxService();
3058
3062
 
3059
3063
  // src/controllers/sandbox.ts
3060
3064
  import { getSandBoxManager as getSandBoxManager2 } from "@axiom-lattice/core";
3061
- function getFilenameFromPath(path3) {
3062
- const segments = path3.replace(/\/+$/, "").split("/");
3063
- return segments[segments.length - 1] || "download";
3064
- }
3065
- var EXT_TO_MIME = {
3066
- ".txt": "text/plain",
3067
- ".html": "text/html",
3068
- ".css": "text/css",
3069
- ".js": "application/javascript",
3070
- ".json": "application/json",
3071
- ".pdf": "application/pdf",
3072
- ".png": "image/png",
3073
- ".jpg": "image/jpeg",
3074
- ".jpeg": "image/jpeg",
3075
- ".gif": "image/gif",
3076
- ".webp": "image/webp",
3077
- ".svg": "image/svg+xml",
3078
- ".zip": "application/zip",
3079
- ".csv": "text/csv",
3080
- ".xml": "application/xml"
3081
- };
3082
- function getContentTypeFromFilename(filename) {
3083
- const ext = filename.includes(".") ? filename.slice(filename.lastIndexOf(".")).toLowerCase() : "";
3084
- return EXT_TO_MIME[ext] ?? "application/octet-stream";
3085
- }
3086
3065
  function registerSandboxProxyRoutes(app2) {
3087
3066
  app2.post(
3088
3067
  "/api/assistants/:assistantId/threads/:threadId/sandbox/uploadfile",
@@ -3352,32 +3331,6 @@ var WorkspaceController = class {
3352
3331
  };
3353
3332
  }
3354
3333
  }
3355
- getFilenameFromPath(filePath) {
3356
- const segments = filePath.split("/");
3357
- return segments[segments.length - 1] || "download";
3358
- }
3359
- getMimeType(filename) {
3360
- const ext = filename.split(".").pop()?.toLowerCase() || "";
3361
- const mimeTypes = {
3362
- pdf: "application/pdf",
3363
- csv: "text/csv",
3364
- xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
3365
- xls: "application/vnd.ms-excel",
3366
- txt: "text/plain",
3367
- json: "application/json",
3368
- png: "image/png",
3369
- jpg: "image/jpeg",
3370
- jpeg: "image/jpeg",
3371
- gif: "image/gif",
3372
- svg: "image/svg+xml",
3373
- html: "text/html",
3374
- htm: "text/html",
3375
- mp3: "audio/mpeg",
3376
- mp4: "video/mp4",
3377
- webm: "video/webm"
3378
- };
3379
- return mimeTypes[ext] || "application/octet-stream";
3380
- }
3381
3334
  isBinaryContentType(filename) {
3382
3335
  const ext = filename.split(".").pop()?.toLowerCase() || "";
3383
3336
  const binaryExtensions = /* @__PURE__ */ new Set([
@@ -3430,7 +3383,7 @@ var WorkspaceController = class {
3430
3383
  workspaceId,
3431
3384
  projectId
3432
3385
  };
3433
- const filename2 = this.getFilenameFromPath(resolvedPath);
3386
+ const filename2 = getFilenameFromPath(resolvedPath);
3434
3387
  const isBinary = this.isBinaryContentType(filename2);
3435
3388
  const volumeBackend = await sandboxManager.getVolumeBackendForPath(volumeConfig, resolvedPath);
3436
3389
  let buf;
@@ -3445,14 +3398,14 @@ var WorkspaceController = class {
3445
3398
  const sandbox = await sandboxManager.getSandboxFromConfig(volumeConfig);
3446
3399
  buf = await sandbox.file.downloadFile({ file: resolvedPath });
3447
3400
  }
3448
- const inferredContentType = this.getMimeType(filename2);
3401
+ const inferredContentType = getContentTypeFromFilename(filename2);
3449
3402
  const contentDisposition = `attachment; filename*=UTF-8''${encodeURIComponent(filename2)}`;
3450
3403
  return reply.status(200).type(inferredContentType).header("Content-Disposition", contentDisposition).send(buf);
3451
3404
  }
3452
3405
  const { backend } = await this.getBackend(tenantId, workspaceId, projectId, assistantId, resolvedPath);
3453
3406
  const content = await backend.read(resolvedPath, 0, Infinity);
3454
- const filename = this.getFilenameFromPath(resolvedPath);
3455
- const mimeType = this.getMimeType(filename);
3407
+ const filename = getFilenameFromPath(resolvedPath);
3408
+ const mimeType = getContentTypeFromFilename(filename);
3456
3409
  const buffer = Buffer.from(content, "utf-8");
3457
3410
  return reply.status(200).type(mimeType).header("Content-Disposition", `attachment; filename*=UTF-8''${encodeURIComponent(filename)}`).send(buffer);
3458
3411
  } catch (error) {
@@ -3484,7 +3437,7 @@ var WorkspaceController = class {
3484
3437
  workspaceId,
3485
3438
  projectId
3486
3439
  };
3487
- const filename2 = this.getFilenameFromPath(resolvedPath);
3440
+ const filename2 = getFilenameFromPath(resolvedPath);
3488
3441
  const isBinary = this.isBinaryContentType(filename2);
3489
3442
  const volumeBackend = await sandboxManager.getVolumeBackendForPath(volumeConfig, resolvedPath);
3490
3443
  let buf;
@@ -3499,7 +3452,7 @@ var WorkspaceController = class {
3499
3452
  const sandbox = await sandboxManager.getSandboxFromConfig(volumeConfig);
3500
3453
  buf = await sandbox.file.downloadFile({ file: resolvedPath });
3501
3454
  }
3502
- const inferredContentType = this.getMimeType(filename2);
3455
+ const inferredContentType = getContentTypeFromFilename(filename2);
3503
3456
  try {
3504
3457
  const contentType = inferredContentType;
3505
3458
  const isHtml = contentType?.toLowerCase().includes("text/html") || filename2.toLowerCase().endsWith(".html") || filename2.toLowerCase().endsWith(".htm");
@@ -3532,8 +3485,8 @@ var WorkspaceController = class {
3532
3485
  }
3533
3486
  const { backend } = await this.getBackend(tenantId, workspaceId, projectId, assistantId, resolvedPath);
3534
3487
  const content = await backend.read(resolvedPath, 0, Infinity);
3535
- const filename = this.getFilenameFromPath(resolvedPath);
3536
- const mimeType = this.getMimeType(filename);
3488
+ const filename = getFilenameFromPath(resolvedPath);
3489
+ const mimeType = getContentTypeFromFilename(filename);
3537
3490
  let finalContent = content;
3538
3491
  const isHtmlFs = mimeType?.toLowerCase().includes("text/html") || filename.toLowerCase().endsWith(".html") || filename.toLowerCase().endsWith(".htm");
3539
3492
  if (isHtmlFs) {
@@ -7345,6 +7298,23 @@ var registerLatticeRoutes = (app2, channelDeps) => {
7345
7298
  );
7346
7299
  };
7347
7300
 
7301
+ // src/routes/resource-routes.ts
7302
+ function registerResourceRoutes(app2, controller) {
7303
+ app2.get("/s/:token", controller.resolveResource.bind(controller));
7304
+ app2.get("/s/:token/*", controller.resolveResource.bind(controller));
7305
+ app2.post("/s/:token/unlock", controller.unlockShare.bind(controller));
7306
+ app2.options("/s/:token", async (_req, reply) => {
7307
+ reply.header("Access-Control-Allow-Origin", "*");
7308
+ reply.header("Access-Control-Allow-Methods", "GET, OPTIONS, POST");
7309
+ reply.header("Access-Control-Allow-Headers", "Content-Type");
7310
+ return reply.status(204).send();
7311
+ });
7312
+ app2.post("/api/resources/share", controller.createShare.bind(controller));
7313
+ app2.get("/api/resources/shares", controller.listShares.bind(controller));
7314
+ app2.patch("/api/resources/share/:token", controller.updateShare.bind(controller));
7315
+ app2.delete("/api/resources/share/:token", controller.revokeShare.bind(controller));
7316
+ }
7317
+
7348
7318
  // src/router/MessageRouter.ts
7349
7319
  import {
7350
7320
  getStoreLattice as getStoreLattice16,
@@ -8155,7 +8125,8 @@ import {
8155
8125
  sandboxLatticeManager as sandboxLatticeManager2,
8156
8126
  getStoreLattice as getStoreLattice17,
8157
8127
  agentInstanceManager as agentInstanceManager8,
8158
- createSandboxProvider
8128
+ createSandboxProvider,
8129
+ TokenCache
8159
8130
  } from "@axiom-lattice/core";
8160
8131
  import {
8161
8132
  LoggerType
@@ -8214,6 +8185,7 @@ app.addHook("preHandler", async (request, reply) => {
8214
8185
  if (!authRequired) return;
8215
8186
  if (request.method === "OPTIONS") return;
8216
8187
  if (PUBLIC_ROUTES.some((r) => request.url === r)) return;
8188
+ if (request.url.startsWith("/s/")) return;
8217
8189
  const urlPath = request.url.split("?")[0];
8218
8190
  if (urlPath.includes("/viewfile") || urlPath.includes("/downloadfile")) return;
8219
8191
  return reply.status(401).send({
@@ -8363,6 +8335,23 @@ var start = async (config) => {
8363
8335
  sandboxLatticeManager2.registerLattice("default", getConfiguredSandboxProvider());
8364
8336
  logger4.info("Registered sandbox manager from env configuration");
8365
8337
  }
8338
+ try {
8339
+ const { ResourceController } = await import("./resources-NE6DFF5I.mjs");
8340
+ const sharedResourceStore = getStoreLattice17("default", "sharedResource").store;
8341
+ const cache = new TokenCache();
8342
+ const resourceController = new ResourceController({
8343
+ store: sharedResourceStore,
8344
+ sandboxManager: sandboxLatticeManager2,
8345
+ cache,
8346
+ logger: logger4
8347
+ });
8348
+ registerResourceRoutes(app, resourceController);
8349
+ logger4.info("Resource share routes registered");
8350
+ } catch (err) {
8351
+ logger4.warn("Resource share infrastructure unavailable", {
8352
+ error: err instanceof Error ? err.message : String(err)
8353
+ });
8354
+ }
8366
8355
  if (channelDeps && process.env.CHANNELS_ENABLED !== "false") {
8367
8356
  const { connectAllChannels } = await import("@axiom-lattice/core");
8368
8357
  try {