@exulu/backend 3.7.2 → 3.7.3
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.cjs +58 -1
- package/dist/index.js +56 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -16786,7 +16786,59 @@ function dropEmptyMessages(messages) {
|
|
|
16786
16786
|
return kept.length === messages.length ? messages : kept;
|
|
16787
16787
|
}
|
|
16788
16788
|
|
|
16789
|
+
// src/exulu/stored-file-url.ts
|
|
16790
|
+
init_cjs_shims();
|
|
16791
|
+
var stripTrailingSlash = (s) => s.replace(/\/+$/, "");
|
|
16792
|
+
function decodeKey(rawPath) {
|
|
16793
|
+
const key = rawPath.replace(/^\/+/, "");
|
|
16794
|
+
try {
|
|
16795
|
+
return decodeURIComponent(key);
|
|
16796
|
+
} catch {
|
|
16797
|
+
return key;
|
|
16798
|
+
}
|
|
16799
|
+
}
|
|
16800
|
+
function parseStoredFileUrl(url, store) {
|
|
16801
|
+
if (!url || !store.bucket) return void 0;
|
|
16802
|
+
let parsed;
|
|
16803
|
+
try {
|
|
16804
|
+
parsed = new URL(url);
|
|
16805
|
+
} catch {
|
|
16806
|
+
return void 0;
|
|
16807
|
+
}
|
|
16808
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return void 0;
|
|
16809
|
+
if (store.endpoint) {
|
|
16810
|
+
let endpoint;
|
|
16811
|
+
try {
|
|
16812
|
+
endpoint = new URL(store.endpoint);
|
|
16813
|
+
} catch {
|
|
16814
|
+
return void 0;
|
|
16815
|
+
}
|
|
16816
|
+
if (parsed.host !== endpoint.host) return void 0;
|
|
16817
|
+
const base = stripTrailingSlash(endpoint.pathname);
|
|
16818
|
+
const prefix = `${base}/${store.bucket}/`;
|
|
16819
|
+
if (!parsed.pathname.startsWith(prefix)) return void 0;
|
|
16820
|
+
const key2 = decodeKey(parsed.pathname.slice(prefix.length));
|
|
16821
|
+
return key2 ? { bucket: store.bucket, key: key2 } : void 0;
|
|
16822
|
+
}
|
|
16823
|
+
if (!parsed.host.startsWith(`${store.bucket}.s3`) || !parsed.host.endsWith(".amazonaws.com")) {
|
|
16824
|
+
return void 0;
|
|
16825
|
+
}
|
|
16826
|
+
const key = decodeKey(parsed.pathname);
|
|
16827
|
+
return key ? { bucket: store.bucket, key } : void 0;
|
|
16828
|
+
}
|
|
16829
|
+
async function resolveFreshFileUrl(url, opts) {
|
|
16830
|
+
const location = parseStoredFileUrl(url, opts);
|
|
16831
|
+
if (!location) return url;
|
|
16832
|
+
try {
|
|
16833
|
+
return await opts.sign(location.bucket, location.key);
|
|
16834
|
+
} catch (err) {
|
|
16835
|
+
console.warn(`[EXULU] could not re-sign stored file URL for key "${location.key}":`, err);
|
|
16836
|
+
return url;
|
|
16837
|
+
}
|
|
16838
|
+
}
|
|
16839
|
+
|
|
16789
16840
|
// src/exulu/generate-stream.ts
|
|
16841
|
+
init_uppy();
|
|
16790
16842
|
var import_ai6 = require("ai");
|
|
16791
16843
|
|
|
16792
16844
|
// src/exulu/context-guard.ts
|
|
@@ -17104,7 +17156,12 @@ var processFilePartsInMessages = async (messages, offloadCtx) => {
|
|
|
17104
17156
|
return part;
|
|
17105
17157
|
}
|
|
17106
17158
|
console.log(`[EXULU] Processing part`, part);
|
|
17107
|
-
const
|
|
17159
|
+
const uploads = offloadCtx.exuluConfig?.fileUploads;
|
|
17160
|
+
const url = uploads?.s3Bucket ? await resolveFreshFileUrl(part.url, {
|
|
17161
|
+
endpoint: uploads.s3endpoint,
|
|
17162
|
+
bucket: uploads.s3Bucket,
|
|
17163
|
+
sign: (bucket, key) => getPresignedUrl(bucket, key, offloadCtx.exuluConfig)
|
|
17164
|
+
}) : part.url;
|
|
17108
17165
|
const classified = classifyFilePart(part);
|
|
17109
17166
|
console.log(`[EXULU] File part classified as ${classified.kind}: ${classified.filename}`);
|
|
17110
17167
|
if (classified.kind === "image") {
|
package/dist/index.js
CHANGED
|
@@ -7796,6 +7796,56 @@ function dropEmptyMessages(messages) {
|
|
|
7796
7796
|
return kept.length === messages.length ? messages : kept;
|
|
7797
7797
|
}
|
|
7798
7798
|
|
|
7799
|
+
// src/exulu/stored-file-url.ts
|
|
7800
|
+
var stripTrailingSlash = (s) => s.replace(/\/+$/, "");
|
|
7801
|
+
function decodeKey(rawPath) {
|
|
7802
|
+
const key = rawPath.replace(/^\/+/, "");
|
|
7803
|
+
try {
|
|
7804
|
+
return decodeURIComponent(key);
|
|
7805
|
+
} catch {
|
|
7806
|
+
return key;
|
|
7807
|
+
}
|
|
7808
|
+
}
|
|
7809
|
+
function parseStoredFileUrl(url, store) {
|
|
7810
|
+
if (!url || !store.bucket) return void 0;
|
|
7811
|
+
let parsed;
|
|
7812
|
+
try {
|
|
7813
|
+
parsed = new URL(url);
|
|
7814
|
+
} catch {
|
|
7815
|
+
return void 0;
|
|
7816
|
+
}
|
|
7817
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return void 0;
|
|
7818
|
+
if (store.endpoint) {
|
|
7819
|
+
let endpoint;
|
|
7820
|
+
try {
|
|
7821
|
+
endpoint = new URL(store.endpoint);
|
|
7822
|
+
} catch {
|
|
7823
|
+
return void 0;
|
|
7824
|
+
}
|
|
7825
|
+
if (parsed.host !== endpoint.host) return void 0;
|
|
7826
|
+
const base = stripTrailingSlash(endpoint.pathname);
|
|
7827
|
+
const prefix = `${base}/${store.bucket}/`;
|
|
7828
|
+
if (!parsed.pathname.startsWith(prefix)) return void 0;
|
|
7829
|
+
const key2 = decodeKey(parsed.pathname.slice(prefix.length));
|
|
7830
|
+
return key2 ? { bucket: store.bucket, key: key2 } : void 0;
|
|
7831
|
+
}
|
|
7832
|
+
if (!parsed.host.startsWith(`${store.bucket}.s3`) || !parsed.host.endsWith(".amazonaws.com")) {
|
|
7833
|
+
return void 0;
|
|
7834
|
+
}
|
|
7835
|
+
const key = decodeKey(parsed.pathname);
|
|
7836
|
+
return key ? { bucket: store.bucket, key } : void 0;
|
|
7837
|
+
}
|
|
7838
|
+
async function resolveFreshFileUrl(url, opts) {
|
|
7839
|
+
const location = parseStoredFileUrl(url, opts);
|
|
7840
|
+
if (!location) return url;
|
|
7841
|
+
try {
|
|
7842
|
+
return await opts.sign(location.bucket, location.key);
|
|
7843
|
+
} catch (err) {
|
|
7844
|
+
console.warn(`[EXULU] could not re-sign stored file URL for key "${location.key}":`, err);
|
|
7845
|
+
return url;
|
|
7846
|
+
}
|
|
7847
|
+
}
|
|
7848
|
+
|
|
7799
7849
|
// src/exulu/generate-stream.ts
|
|
7800
7850
|
import {
|
|
7801
7851
|
convertToModelMessages,
|
|
@@ -8099,7 +8149,12 @@ var processFilePartsInMessages = async (messages, offloadCtx) => {
|
|
|
8099
8149
|
return part;
|
|
8100
8150
|
}
|
|
8101
8151
|
console.log(`[EXULU] Processing part`, part);
|
|
8102
|
-
const
|
|
8152
|
+
const uploads = offloadCtx.exuluConfig?.fileUploads;
|
|
8153
|
+
const url = uploads?.s3Bucket ? await resolveFreshFileUrl(part.url, {
|
|
8154
|
+
endpoint: uploads.s3endpoint,
|
|
8155
|
+
bucket: uploads.s3Bucket,
|
|
8156
|
+
sign: (bucket, key) => getPresignedUrl(bucket, key, offloadCtx.exuluConfig)
|
|
8157
|
+
}) : part.url;
|
|
8103
8158
|
const classified = classifyFilePart(part);
|
|
8104
8159
|
console.log(`[EXULU] File part classified as ${classified.kind}: ${classified.filename}`);
|
|
8105
8160
|
if (classified.kind === "image") {
|