@automagik/omni 2.260704.12 → 2.260705.2
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.js +1 -1
- package/dist/server/index.js +381 -234
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -35134,9 +35134,17 @@ var init_config = __esm(() => {
|
|
|
35134
35134
|
});
|
|
35135
35135
|
});
|
|
35136
35136
|
|
|
35137
|
+
// ../channel-sdk/src/media-backends/types.ts
|
|
35138
|
+
function isMediaNotFoundError(error) {
|
|
35139
|
+
if (!error || typeof error !== "object")
|
|
35140
|
+
return false;
|
|
35141
|
+
const code = error.code;
|
|
35142
|
+
return code === "ENOENT" || code === "NoSuchKey";
|
|
35143
|
+
}
|
|
35144
|
+
|
|
35137
35145
|
// ../channel-sdk/src/media-backends/local-backend.ts
|
|
35138
35146
|
import { createWriteStream, existsSync, mkdirSync, writeFileSync } from "fs";
|
|
35139
|
-
import { mkdir as mkdir2, readFile, rm } from "fs/promises";
|
|
35147
|
+
import { mkdir as mkdir2, open, readFile, rm, stat as stat2 } from "fs/promises";
|
|
35140
35148
|
import { dirname, resolve, sep } from "path";
|
|
35141
35149
|
import { Transform } from "stream";
|
|
35142
35150
|
import { pipeline } from "stream/promises";
|
|
@@ -35192,6 +35200,32 @@ class LocalMediaBackend {
|
|
|
35192
35200
|
async read(key) {
|
|
35193
35201
|
return readFile(this.getSafePath(key));
|
|
35194
35202
|
}
|
|
35203
|
+
async stat(key) {
|
|
35204
|
+
try {
|
|
35205
|
+
const info = await stat2(this.getSafePath(key));
|
|
35206
|
+
return { size: Number(info.size) };
|
|
35207
|
+
} catch (error) {
|
|
35208
|
+
if (isMediaNotFoundError(error))
|
|
35209
|
+
return null;
|
|
35210
|
+
throw error;
|
|
35211
|
+
}
|
|
35212
|
+
}
|
|
35213
|
+
async readRange(key, start, endInclusive) {
|
|
35214
|
+
const length = endInclusive - start + 1;
|
|
35215
|
+
const handle = await open(this.getSafePath(key), "r");
|
|
35216
|
+
try {
|
|
35217
|
+
const buffer2 = Buffer.alloc(length);
|
|
35218
|
+
const { bytesRead } = await handle.read(buffer2, 0, length, start);
|
|
35219
|
+
return bytesRead === length ? buffer2 : buffer2.subarray(0, bytesRead);
|
|
35220
|
+
} finally {
|
|
35221
|
+
await handle.close();
|
|
35222
|
+
}
|
|
35223
|
+
}
|
|
35224
|
+
async readStream(key) {
|
|
35225
|
+
const path = this.getSafePath(key);
|
|
35226
|
+
await stat2(path);
|
|
35227
|
+
return Bun.file(path).stream();
|
|
35228
|
+
}
|
|
35195
35229
|
async presignedUrl(_key, _ttlSeconds) {
|
|
35196
35230
|
throw new Error("presignedUrl is only available in remote mode (set OMNI_MEDIA_MODE=remote)");
|
|
35197
35231
|
}
|
|
@@ -35270,6 +35304,23 @@ class S3MediaBackend {
|
|
|
35270
35304
|
log19.debug("Read media from S3", { key, size: bytes.byteLength });
|
|
35271
35305
|
return Buffer.from(bytes);
|
|
35272
35306
|
}
|
|
35307
|
+
async stat(key) {
|
|
35308
|
+
try {
|
|
35309
|
+
const info = await this.client.file(key).stat();
|
|
35310
|
+
return { size: info.size };
|
|
35311
|
+
} catch (error) {
|
|
35312
|
+
if (isMediaNotFoundError(error))
|
|
35313
|
+
return null;
|
|
35314
|
+
throw error;
|
|
35315
|
+
}
|
|
35316
|
+
}
|
|
35317
|
+
async readRange(key, start, endInclusive) {
|
|
35318
|
+
const bytes = await this.client.file(key).slice(start, endInclusive + 1).arrayBuffer();
|
|
35319
|
+
return Buffer.from(bytes);
|
|
35320
|
+
}
|
|
35321
|
+
async readStream(key) {
|
|
35322
|
+
return this.client.file(key).stream();
|
|
35323
|
+
}
|
|
35273
35324
|
async presignedUrl(key, ttlSeconds = this.presignTtlSeconds) {
|
|
35274
35325
|
return this.presignClient.presign(key, { expiresIn: ttlSeconds, method: "GET" });
|
|
35275
35326
|
}
|
|
@@ -35315,6 +35366,7 @@ __export(exports_src, {
|
|
|
35315
35366
|
isVoiceCapable: () => isVoiceCapable,
|
|
35316
35367
|
isValidInstanceId: () => isValidInstanceId,
|
|
35317
35368
|
isValidChannelType: () => isValidChannelType,
|
|
35369
|
+
isMediaNotFoundError: () => isMediaNotFoundError,
|
|
35318
35370
|
getDefaultPackagesDir: () => getDefaultPackagesDir,
|
|
35319
35371
|
formatValidationErrors: () => formatValidationErrors,
|
|
35320
35372
|
eventTypeToPattern: () => eventTypeToPattern,
|
|
@@ -84898,12 +84950,12 @@ var require_form_data = __commonJS((exports, module) => {
|
|
|
84898
84950
|
if (value.end != null && value.end != Infinity && value.start != null) {
|
|
84899
84951
|
callback(null, value.end + 1 - (value.start ? value.start : 0));
|
|
84900
84952
|
} else {
|
|
84901
|
-
fs.stat(value.path, function(err,
|
|
84953
|
+
fs.stat(value.path, function(err, stat3) {
|
|
84902
84954
|
if (err) {
|
|
84903
84955
|
callback(err);
|
|
84904
84956
|
return;
|
|
84905
84957
|
}
|
|
84906
|
-
var fileSize =
|
|
84958
|
+
var fileSize = stat3.size - (value.start ? value.start : 0);
|
|
84907
84959
|
callback(null, fileSize);
|
|
84908
84960
|
});
|
|
84909
84961
|
}
|
|
@@ -119075,13 +119127,13 @@ var require_view2 = __commonJS((exports, module) => {
|
|
|
119075
119127
|
View.prototype.resolve = function resolve3(dir, file) {
|
|
119076
119128
|
var ext = this.ext;
|
|
119077
119129
|
var path2 = join3(dir, file);
|
|
119078
|
-
var
|
|
119079
|
-
if (
|
|
119130
|
+
var stat3 = tryStat(path2);
|
|
119131
|
+
if (stat3 && stat3.isFile()) {
|
|
119080
119132
|
return path2;
|
|
119081
119133
|
}
|
|
119082
119134
|
path2 = join3(dir, basename(file, ext), "index" + ext);
|
|
119083
|
-
|
|
119084
|
-
if (
|
|
119135
|
+
stat3 = tryStat(path2);
|
|
119136
|
+
if (stat3 && stat3.isFile()) {
|
|
119085
119137
|
return path2;
|
|
119086
119138
|
}
|
|
119087
119139
|
};
|
|
@@ -119132,9 +119184,9 @@ var require_etag = __commonJS((exports, module) => {
|
|
|
119132
119184
|
}
|
|
119133
119185
|
return obj && typeof obj === "object" && "ctime" in obj && toString2.call(obj.ctime) === "[object Date]" && "mtime" in obj && toString2.call(obj.mtime) === "[object Date]" && "ino" in obj && typeof obj.ino === "number" && "size" in obj && typeof obj.size === "number";
|
|
119134
119186
|
}
|
|
119135
|
-
function stattag(
|
|
119136
|
-
var mtime =
|
|
119137
|
-
var size =
|
|
119187
|
+
function stattag(stat3) {
|
|
119188
|
+
var mtime = stat3.mtime.getTime().toString(16);
|
|
119189
|
+
var size = stat3.size.toString(16);
|
|
119138
119190
|
return '"' + size + "-" + mtime + '"';
|
|
119139
119191
|
}
|
|
119140
119192
|
});
|
|
@@ -122670,8 +122722,8 @@ var require_send = __commonJS((exports, module) => {
|
|
|
122670
122722
|
this.sendFile(path2);
|
|
122671
122723
|
return res;
|
|
122672
122724
|
};
|
|
122673
|
-
SendStream.prototype.send = function send2(path2,
|
|
122674
|
-
var len =
|
|
122725
|
+
SendStream.prototype.send = function send2(path2, stat3) {
|
|
122726
|
+
var len = stat3.size;
|
|
122675
122727
|
var options = this.options;
|
|
122676
122728
|
var opts = {};
|
|
122677
122729
|
var res = this.res;
|
|
@@ -122683,7 +122735,7 @@ var require_send = __commonJS((exports, module) => {
|
|
|
122683
122735
|
return;
|
|
122684
122736
|
}
|
|
122685
122737
|
debug2('pipe "%s"', path2);
|
|
122686
|
-
this.setHeader(path2,
|
|
122738
|
+
this.setHeader(path2, stat3);
|
|
122687
122739
|
this.type(path2);
|
|
122688
122740
|
if (this.isConditionalGET()) {
|
|
122689
122741
|
if (this.isPreconditionFailure()) {
|
|
@@ -122740,19 +122792,19 @@ var require_send = __commonJS((exports, module) => {
|
|
|
122740
122792
|
var i = 0;
|
|
122741
122793
|
var self2 = this;
|
|
122742
122794
|
debug2('stat "%s"', path2);
|
|
122743
|
-
fs.stat(path2, function onstat(err,
|
|
122795
|
+
fs.stat(path2, function onstat(err, stat3) {
|
|
122744
122796
|
var pathEndsWithSep = path2[path2.length - 1] === sep2;
|
|
122745
122797
|
if (err && err.code === "ENOENT" && !extname(path2) && !pathEndsWithSep) {
|
|
122746
122798
|
return next(err);
|
|
122747
122799
|
}
|
|
122748
122800
|
if (err)
|
|
122749
122801
|
return self2.onStatError(err);
|
|
122750
|
-
if (
|
|
122802
|
+
if (stat3.isDirectory())
|
|
122751
122803
|
return self2.redirect(path2);
|
|
122752
122804
|
if (pathEndsWithSep)
|
|
122753
122805
|
return self2.error(404);
|
|
122754
|
-
self2.emit("file", path2,
|
|
122755
|
-
self2.send(path2,
|
|
122806
|
+
self2.emit("file", path2, stat3);
|
|
122807
|
+
self2.send(path2, stat3);
|
|
122756
122808
|
});
|
|
122757
122809
|
function next(err) {
|
|
122758
122810
|
if (self2._extensions.length <= i) {
|
|
@@ -122760,13 +122812,13 @@ var require_send = __commonJS((exports, module) => {
|
|
|
122760
122812
|
}
|
|
122761
122813
|
var p2 = path2 + "." + self2._extensions[i++];
|
|
122762
122814
|
debug2('stat "%s"', p2);
|
|
122763
|
-
fs.stat(p2, function(err2,
|
|
122815
|
+
fs.stat(p2, function(err2, stat3) {
|
|
122764
122816
|
if (err2)
|
|
122765
122817
|
return next(err2);
|
|
122766
|
-
if (
|
|
122818
|
+
if (stat3.isDirectory())
|
|
122767
122819
|
return next();
|
|
122768
|
-
self2.emit("file", p2,
|
|
122769
|
-
self2.send(p2,
|
|
122820
|
+
self2.emit("file", p2, stat3);
|
|
122821
|
+
self2.send(p2, stat3);
|
|
122770
122822
|
});
|
|
122771
122823
|
}
|
|
122772
122824
|
};
|
|
@@ -122781,13 +122833,13 @@ var require_send = __commonJS((exports, module) => {
|
|
|
122781
122833
|
}
|
|
122782
122834
|
var p2 = join3(path2, self2._index[i]);
|
|
122783
122835
|
debug2('stat "%s"', p2);
|
|
122784
|
-
fs.stat(p2, function(err2,
|
|
122836
|
+
fs.stat(p2, function(err2, stat3) {
|
|
122785
122837
|
if (err2)
|
|
122786
122838
|
return next(err2);
|
|
122787
|
-
if (
|
|
122839
|
+
if (stat3.isDirectory())
|
|
122788
122840
|
return next();
|
|
122789
|
-
self2.emit("file", p2,
|
|
122790
|
-
self2.send(p2,
|
|
122841
|
+
self2.emit("file", p2, stat3);
|
|
122842
|
+
self2.send(p2, stat3);
|
|
122791
122843
|
});
|
|
122792
122844
|
}
|
|
122793
122845
|
next();
|
|
@@ -122819,9 +122871,9 @@ var require_send = __commonJS((exports, module) => {
|
|
|
122819
122871
|
debug2("content-type %s", type2);
|
|
122820
122872
|
res.setHeader("Content-Type", type2);
|
|
122821
122873
|
};
|
|
122822
|
-
SendStream.prototype.setHeader = function setHeader(path2,
|
|
122874
|
+
SendStream.prototype.setHeader = function setHeader(path2, stat3) {
|
|
122823
122875
|
var res = this.res;
|
|
122824
|
-
this.emit("headers", res, path2,
|
|
122876
|
+
this.emit("headers", res, path2, stat3);
|
|
122825
122877
|
if (this._acceptRanges && !res.getHeader("Accept-Ranges")) {
|
|
122826
122878
|
debug2("accept ranges");
|
|
122827
122879
|
res.setHeader("Accept-Ranges", "bytes");
|
|
@@ -122835,12 +122887,12 @@ var require_send = __commonJS((exports, module) => {
|
|
|
122835
122887
|
res.setHeader("Cache-Control", cacheControl);
|
|
122836
122888
|
}
|
|
122837
122889
|
if (this._lastModified && !res.getHeader("Last-Modified")) {
|
|
122838
|
-
var modified =
|
|
122890
|
+
var modified = stat3.mtime.toUTCString();
|
|
122839
122891
|
debug2("modified %s", modified);
|
|
122840
122892
|
res.setHeader("Last-Modified", modified);
|
|
122841
122893
|
}
|
|
122842
122894
|
if (this._etag && !res.getHeader("ETag")) {
|
|
122843
|
-
var val = etag(
|
|
122895
|
+
var val = etag(stat3);
|
|
122844
122896
|
debug2("etag %s", val);
|
|
122845
122897
|
res.setHeader("ETag", val);
|
|
122846
122898
|
}
|
|
@@ -137100,8 +137152,8 @@ var init_FileTokenizer = __esm(() => {
|
|
|
137100
137152
|
FileTokenizer = class FileTokenizer extends AbstractTokenizer {
|
|
137101
137153
|
static async fromFile(sourceFilePath) {
|
|
137102
137154
|
const fileHandle = await fsOpen(sourceFilePath, "r");
|
|
137103
|
-
const
|
|
137104
|
-
return new FileTokenizer(fileHandle, { fileInfo: { path: sourceFilePath, size:
|
|
137155
|
+
const stat3 = await fileHandle.stat();
|
|
137156
|
+
return new FileTokenizer(fileHandle, { fileInfo: { path: sourceFilePath, size: stat3.size } });
|
|
137105
137157
|
}
|
|
137106
137158
|
constructor(fileHandle, options) {
|
|
137107
137159
|
super(options);
|
|
@@ -137146,9 +137198,9 @@ import { stat as fsStat } from "fs/promises";
|
|
|
137146
137198
|
async function fromStream2(stream, options) {
|
|
137147
137199
|
const rst = fromStream(stream, options);
|
|
137148
137200
|
if (stream.path) {
|
|
137149
|
-
const
|
|
137201
|
+
const stat3 = await fsStat(stream.path);
|
|
137150
137202
|
rst.fileInfo.path = stream.path;
|
|
137151
|
-
rst.fileInfo.size =
|
|
137203
|
+
rst.fileInfo.size = stat3.size;
|
|
137152
137204
|
}
|
|
137153
137205
|
return rst;
|
|
137154
137206
|
}
|
|
@@ -155536,7 +155588,7 @@ __export(exports_audio_converter, {
|
|
|
155536
155588
|
import { spawn as spawn2 } from "child_process";
|
|
155537
155589
|
import { promises as fs5, createWriteStream as createWriteStream5 } from "fs";
|
|
155538
155590
|
import { tmpdir as tmpdir5 } from "os";
|
|
155539
|
-
import { join as
|
|
155591
|
+
import { join as join9 } from "path";
|
|
155540
155592
|
import { Readable as Readable2 } from "stream";
|
|
155541
155593
|
import { pipeline as pipeline4 } from "stream/promises";
|
|
155542
155594
|
function spawnWithEvents2(command, args) {
|
|
@@ -155586,7 +155638,7 @@ async function downloadToTemp(url) {
|
|
|
155586
155638
|
if (!response.ok) {
|
|
155587
155639
|
throw new Error(`Failed to download audio: ${response.status} ${response.statusText}`);
|
|
155588
155640
|
}
|
|
155589
|
-
const tempPath =
|
|
155641
|
+
const tempPath = join9(tmpdir5(), `omni-audio-${Date.now()}-input`);
|
|
155590
155642
|
const body = response.body;
|
|
155591
155643
|
if (!body) {
|
|
155592
155644
|
throw new Error("No response body");
|
|
@@ -155597,7 +155649,7 @@ async function downloadToTemp(url) {
|
|
|
155597
155649
|
return tempPath;
|
|
155598
155650
|
}
|
|
155599
155651
|
async function convertToOggOpus(inputPath) {
|
|
155600
|
-
const outputPath =
|
|
155652
|
+
const outputPath = join9(tmpdir5(), `omni-audio-${Date.now()}-output.ogg`);
|
|
155601
155653
|
return new Promise((resolve2, reject) => {
|
|
155602
155654
|
const ffmpeg = spawnWithEvents2("ffmpeg", [
|
|
155603
155655
|
"-i",
|
|
@@ -155673,7 +155725,7 @@ async function convertBufferForVoiceNote(buffer2, mimeType) {
|
|
|
155673
155725
|
let inputPath = null;
|
|
155674
155726
|
let outputPath = null;
|
|
155675
155727
|
try {
|
|
155676
|
-
inputPath =
|
|
155728
|
+
inputPath = join9(tmpdir5(), `omni-audio-${Date.now()}-input`);
|
|
155677
155729
|
await fs5.writeFile(inputPath, buffer2);
|
|
155678
155730
|
outputPath = await convertToOggOpus(inputPath);
|
|
155679
155731
|
const convertedBuffer = await fs5.readFile(outputPath);
|
|
@@ -171985,14 +172037,14 @@ var require_require_in_the_middle = __commonJS((exports, module) => {
|
|
|
171985
172037
|
moduleName = parsedPath.name;
|
|
171986
172038
|
basedir = parsedPath.dir;
|
|
171987
172039
|
} else {
|
|
171988
|
-
const
|
|
171989
|
-
if (
|
|
172040
|
+
const stat3 = moduleDetailsFromPath(filename);
|
|
172041
|
+
if (stat3 === undefined) {
|
|
171990
172042
|
debug34("could not parse filename: %s", filename);
|
|
171991
172043
|
return exports2;
|
|
171992
172044
|
}
|
|
171993
|
-
moduleName =
|
|
171994
|
-
basedir =
|
|
171995
|
-
const fullModuleName = resolveModuleName(
|
|
172045
|
+
moduleName = stat3.name;
|
|
172046
|
+
basedir = stat3.basedir;
|
|
172047
|
+
const fullModuleName = resolveModuleName(stat3);
|
|
171996
172048
|
debug34("resolved filename to module: %s (id: %s, resolved: %s, basedir: %s)", moduleName, id, fullModuleName, basedir);
|
|
171997
172049
|
let matchFound = false;
|
|
171998
172050
|
if (hasWhitelist) {
|
|
@@ -172054,9 +172106,9 @@ var require_require_in_the_middle = __commonJS((exports, module) => {
|
|
|
172054
172106
|
}
|
|
172055
172107
|
}
|
|
172056
172108
|
};
|
|
172057
|
-
function resolveModuleName(
|
|
172058
|
-
const normalizedPath = path.sep !== "/" ?
|
|
172059
|
-
return path.posix.join(
|
|
172109
|
+
function resolveModuleName(stat3) {
|
|
172110
|
+
const normalizedPath = path.sep !== "/" ? stat3.path.split(path.sep).join("/") : stat3.path;
|
|
172111
|
+
return path.posix.join(stat3.name, normalizedPath).replace(normalize3, "");
|
|
172060
172112
|
}
|
|
172061
172113
|
});
|
|
172062
172114
|
|
|
@@ -176960,7 +177012,7 @@ var init_childProcess = __esm(() => {
|
|
|
176960
177012
|
import { execFile } from "child_process";
|
|
176961
177013
|
import { readFile as readFile2, readdir as readdir2 } from "fs";
|
|
176962
177014
|
import * as os2 from "os";
|
|
176963
|
-
import { join as
|
|
177015
|
+
import { join as join11 } from "path";
|
|
176964
177016
|
import { promisify as promisify4 } from "util";
|
|
176965
177017
|
function _updateContext(contexts) {
|
|
176966
177018
|
if (contexts.app?.app_memory) {
|
|
@@ -177160,7 +177212,7 @@ async function getLinuxInfo() {
|
|
|
177160
177212
|
if (!distroFile) {
|
|
177161
177213
|
return linuxInfo;
|
|
177162
177214
|
}
|
|
177163
|
-
const distroPath =
|
|
177215
|
+
const distroPath = join11("/etc", distroFile.name);
|
|
177164
177216
|
const contents = (await readFileAsync(distroPath, { encoding: "utf-8" })).toLowerCase();
|
|
177165
177217
|
const { distros } = distroFile;
|
|
177166
177218
|
linuxInfo.name = distros.find((d2) => contents.indexOf(getLinuxDistroId(d2)) >= 0) || distros[0];
|
|
@@ -178071,7 +178123,7 @@ var init_detection = __esm(() => {
|
|
|
178071
178123
|
|
|
178072
178124
|
// ../../node_modules/.bun/@sentry+node-core@10.52.0+6488de8736d8e524/node_modules/@sentry/node-core/build/esm/integrations/modules.js
|
|
178073
178125
|
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
178074
|
-
import { dirname as dirname4, join as
|
|
178126
|
+
import { dirname as dirname4, join as join12 } from "path";
|
|
178075
178127
|
function getRequireCachePaths() {
|
|
178076
178128
|
try {
|
|
178077
178129
|
return __require.cache ? Object.keys(__require.cache) : [];
|
|
@@ -178102,7 +178154,7 @@ function collectRequireModules() {
|
|
|
178102
178154
|
if (mainPaths.indexOf(dir) < 0) {
|
|
178103
178155
|
return updir();
|
|
178104
178156
|
}
|
|
178105
|
-
const pkgfile =
|
|
178157
|
+
const pkgfile = join12(orig, "package.json");
|
|
178106
178158
|
seen.add(orig);
|
|
178107
178159
|
if (!existsSync2(pkgfile)) {
|
|
178108
178160
|
return updir();
|
|
@@ -178124,7 +178176,7 @@ function _getModules() {
|
|
|
178124
178176
|
}
|
|
178125
178177
|
function getPackageJson() {
|
|
178126
178178
|
try {
|
|
178127
|
-
const filePath =
|
|
178179
|
+
const filePath = join12(process.cwd(), "package.json");
|
|
178128
178180
|
const packageJson = JSON.parse(readFileSync(filePath, "utf8"));
|
|
178129
178181
|
return packageJson;
|
|
178130
178182
|
} catch {
|
|
@@ -183545,10 +183597,10 @@ var require_commonjs3 = __commonJS((exports) => {
|
|
|
183545
183597
|
}
|
|
183546
183598
|
return filtered.join("/");
|
|
183547
183599
|
}).join("|");
|
|
183548
|
-
const [
|
|
183549
|
-
re = "^" +
|
|
183600
|
+
const [open2, close2] = set.length > 1 ? ["(?:", ")"] : ["", ""];
|
|
183601
|
+
re = "^" + open2 + re + close2 + "$";
|
|
183550
183602
|
if (this.partial) {
|
|
183551
|
-
re = "^(?:\\/|" +
|
|
183603
|
+
re = "^(?:\\/|" + open2 + re.slice(1, -1) + close2 + ")$";
|
|
183552
183604
|
}
|
|
183553
183605
|
if (this.negate)
|
|
183554
183606
|
re = "^(?!" + re + ").+$";
|
|
@@ -205361,7 +205413,7 @@ var require_path = __commonJS((exports) => {
|
|
|
205361
205413
|
function isAbsolute2(path) {
|
|
205362
205414
|
return path.charAt(0) === "/";
|
|
205363
205415
|
}
|
|
205364
|
-
function
|
|
205416
|
+
function join13(...args) {
|
|
205365
205417
|
return normalizePath2(args.join("/"));
|
|
205366
205418
|
}
|
|
205367
205419
|
function dirname5(path) {
|
|
@@ -205386,7 +205438,7 @@ var require_path = __commonJS((exports) => {
|
|
|
205386
205438
|
exports.basename = basename3;
|
|
205387
205439
|
exports.dirname = dirname5;
|
|
205388
205440
|
exports.isAbsolute = isAbsolute2;
|
|
205389
|
-
exports.join =
|
|
205441
|
+
exports.join = join13;
|
|
205390
205442
|
exports.normalizePath = normalizePath2;
|
|
205391
205443
|
exports.relative = relative2;
|
|
205392
205444
|
exports.resolve = resolve3;
|
|
@@ -225538,7 +225590,7 @@ var init_sentry_scrub = __esm(() => {
|
|
|
225538
225590
|
var require_package7 = __commonJS((exports, module) => {
|
|
225539
225591
|
module.exports = {
|
|
225540
225592
|
name: "@omni/api",
|
|
225541
|
-
version: "2.
|
|
225593
|
+
version: "2.260705.2",
|
|
225542
225594
|
type: "module",
|
|
225543
225595
|
exports: {
|
|
225544
225596
|
".": {
|
|
@@ -242241,9 +242293,9 @@ var require_async2 = __commonJS((exports, module) => {
|
|
|
242241
242293
|
];
|
|
242242
242294
|
}
|
|
242243
242295
|
var defaultIsFile = function isFile(file, cb) {
|
|
242244
|
-
fs6.stat(file, function(err,
|
|
242296
|
+
fs6.stat(file, function(err, stat3) {
|
|
242245
242297
|
if (!err) {
|
|
242246
|
-
return cb(null,
|
|
242298
|
+
return cb(null, stat3.isFile() || stat3.isFIFO());
|
|
242247
242299
|
}
|
|
242248
242300
|
if (err.code === "ENOENT" || err.code === "ENOTDIR")
|
|
242249
242301
|
return cb(null, false);
|
|
@@ -242251,9 +242303,9 @@ var require_async2 = __commonJS((exports, module) => {
|
|
|
242251
242303
|
});
|
|
242252
242304
|
};
|
|
242253
242305
|
var defaultIsDir = function isDirectory(dir, cb) {
|
|
242254
|
-
fs6.stat(dir, function(err,
|
|
242306
|
+
fs6.stat(dir, function(err, stat3) {
|
|
242255
242307
|
if (!err) {
|
|
242256
|
-
return cb(null,
|
|
242308
|
+
return cb(null, stat3.isDirectory());
|
|
242257
242309
|
}
|
|
242258
242310
|
if (err.code === "ENOENT" || err.code === "ENOTDIR")
|
|
242259
242311
|
return cb(null, false);
|
|
@@ -242762,23 +242814,23 @@ var require_sync = __commonJS((exports, module) => {
|
|
|
242762
242814
|
}
|
|
242763
242815
|
var defaultIsFile = function isFile(file) {
|
|
242764
242816
|
try {
|
|
242765
|
-
var
|
|
242817
|
+
var stat3 = fs6.statSync(file, { throwIfNoEntry: false });
|
|
242766
242818
|
} catch (e) {
|
|
242767
242819
|
if (e && (e.code === "ENOENT" || e.code === "ENOTDIR"))
|
|
242768
242820
|
return false;
|
|
242769
242821
|
throw e;
|
|
242770
242822
|
}
|
|
242771
|
-
return !!
|
|
242823
|
+
return !!stat3 && (stat3.isFile() || stat3.isFIFO());
|
|
242772
242824
|
};
|
|
242773
242825
|
var defaultIsDir = function isDirectory(dir) {
|
|
242774
242826
|
try {
|
|
242775
|
-
var
|
|
242827
|
+
var stat3 = fs6.statSync(dir, { throwIfNoEntry: false });
|
|
242776
242828
|
} catch (e) {
|
|
242777
242829
|
if (e && (e.code === "ENOENT" || e.code === "ENOTDIR"))
|
|
242778
242830
|
return false;
|
|
242779
242831
|
throw e;
|
|
242780
242832
|
}
|
|
242781
|
-
return !!
|
|
242833
|
+
return !!stat3 && stat3.isDirectory();
|
|
242782
242834
|
};
|
|
242783
242835
|
var defaultRealpathSync = function realpathSync(x) {
|
|
242784
242836
|
try {
|
|
@@ -243187,14 +243239,14 @@ var require_require_in_the_middle2 = __commonJS((exports, module) => {
|
|
|
243187
243239
|
moduleName = parsedPath.name;
|
|
243188
243240
|
basedir = parsedPath.dir;
|
|
243189
243241
|
} else {
|
|
243190
|
-
const
|
|
243191
|
-
if (
|
|
243242
|
+
const stat3 = moduleDetailsFromPath(filename);
|
|
243243
|
+
if (stat3 === undefined) {
|
|
243192
243244
|
debug34("could not parse filename: %s", filename);
|
|
243193
243245
|
return exports2;
|
|
243194
243246
|
}
|
|
243195
|
-
moduleName =
|
|
243196
|
-
basedir =
|
|
243197
|
-
const fullModuleName = resolveModuleName(
|
|
243247
|
+
moduleName = stat3.name;
|
|
243248
|
+
basedir = stat3.basedir;
|
|
243249
|
+
const fullModuleName = resolveModuleName(stat3);
|
|
243198
243250
|
debug34("resolved filename to module: %s (id: %s, resolved: %s, basedir: %s)", moduleName, id, fullModuleName, basedir);
|
|
243199
243251
|
let matchFound = false;
|
|
243200
243252
|
if (hasWhitelist) {
|
|
@@ -243256,9 +243308,9 @@ var require_require_in_the_middle2 = __commonJS((exports, module) => {
|
|
|
243256
243308
|
}
|
|
243257
243309
|
}
|
|
243258
243310
|
};
|
|
243259
|
-
function resolveModuleName(
|
|
243260
|
-
const normalizedPath = path.sep !== "/" ?
|
|
243261
|
-
return path.posix.join(
|
|
243311
|
+
function resolveModuleName(stat3) {
|
|
243312
|
+
const normalizedPath = path.sep !== "/" ? stat3.path.split(path.sep).join("/") : stat3.path;
|
|
243313
|
+
return path.posix.join(stat3.name, normalizedPath).replace(normalize3, "");
|
|
243262
243314
|
}
|
|
243263
243315
|
});
|
|
243264
243316
|
|
|
@@ -273280,7 +273332,7 @@ var init_sql = __esm(() => {
|
|
|
273280
273332
|
return new SQL([new StringChunk(str)]);
|
|
273281
273333
|
}
|
|
273282
273334
|
sql2.raw = raw;
|
|
273283
|
-
function
|
|
273335
|
+
function join13(chunks, separator) {
|
|
273284
273336
|
const result = [];
|
|
273285
273337
|
for (const [i, chunk2] of chunks.entries()) {
|
|
273286
273338
|
if (i > 0 && separator !== undefined) {
|
|
@@ -273290,7 +273342,7 @@ var init_sql = __esm(() => {
|
|
|
273290
273342
|
}
|
|
273291
273343
|
return new SQL(result);
|
|
273292
273344
|
}
|
|
273293
|
-
sql2.join =
|
|
273345
|
+
sql2.join = join13;
|
|
273294
273346
|
function identifier(value) {
|
|
273295
273347
|
return new Name(value);
|
|
273296
273348
|
}
|
|
@@ -276522,7 +276574,7 @@ var init_select2 = __esm(() => {
|
|
|
276522
276574
|
return (table2, on) => {
|
|
276523
276575
|
const baseTableName = this.tableName;
|
|
276524
276576
|
const tableName = getTableLikeName(table2);
|
|
276525
|
-
if (typeof tableName === "string" && this.config.joins?.some((
|
|
276577
|
+
if (typeof tableName === "string" && this.config.joins?.some((join13) => join13.alias === tableName)) {
|
|
276526
276578
|
throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
276527
276579
|
}
|
|
276528
276580
|
if (!this.isPartialSelect) {
|
|
@@ -277033,7 +277085,7 @@ var init_update = __esm(() => {
|
|
|
277033
277085
|
createJoin(joinType) {
|
|
277034
277086
|
return (table2, on) => {
|
|
277035
277087
|
const tableName = getTableLikeName(table2);
|
|
277036
|
-
if (typeof tableName === "string" && this.config.joins.some((
|
|
277088
|
+
if (typeof tableName === "string" && this.config.joins.some((join13) => join13.alias === tableName)) {
|
|
277037
277089
|
throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
277038
277090
|
}
|
|
277039
277091
|
if (typeof on === "function") {
|
|
@@ -277083,10 +277135,10 @@ var init_update = __esm(() => {
|
|
|
277083
277135
|
const fromFields = this.getTableLikeFields(this.config.from);
|
|
277084
277136
|
fields[tableName] = fromFields;
|
|
277085
277137
|
}
|
|
277086
|
-
for (const
|
|
277087
|
-
const tableName2 = getTableLikeName(
|
|
277088
|
-
if (typeof tableName2 === "string" && !is(
|
|
277089
|
-
const fromFields = this.getTableLikeFields(
|
|
277138
|
+
for (const join13 of this.config.joins) {
|
|
277139
|
+
const tableName2 = getTableLikeName(join13.table);
|
|
277140
|
+
if (typeof tableName2 === "string" && !is(join13.table, SQL)) {
|
|
277141
|
+
const fromFields = this.getTableLikeFields(join13.table);
|
|
277090
277142
|
fields[tableName2] = fromFields;
|
|
277091
277143
|
}
|
|
277092
277144
|
}
|
|
@@ -280694,7 +280746,7 @@ import fs6 from "fs";
|
|
|
280694
280746
|
function Postgres(a, b3) {
|
|
280695
280747
|
const options = parseOptions(a, b3), subscribe6 = options.no_subscribe || Subscribe(Postgres, { ...options });
|
|
280696
280748
|
let ending = false;
|
|
280697
|
-
const queries = queue_default(), connecting = queue_default(), reserved = queue_default(), closed = queue_default(), ended = queue_default(),
|
|
280749
|
+
const queries = queue_default(), connecting = queue_default(), reserved = queue_default(), closed = queue_default(), ended = queue_default(), open2 = queue_default(), busy = queue_default(), full = queue_default(), queues = { connecting, reserved, closed, ended, open: open2, busy, full };
|
|
280698
280750
|
const connections = [...Array(options.max)].map(() => connection_default(options, queues, { onopen, onend, onclose }));
|
|
280699
280751
|
const sql4 = Sql(handler);
|
|
280700
280752
|
Object.assign(sql4, {
|
|
@@ -280806,7 +280858,7 @@ function Postgres(a, b3) {
|
|
|
280806
280858
|
}
|
|
280807
280859
|
async function reserve() {
|
|
280808
280860
|
const queue = queue_default();
|
|
280809
|
-
const c =
|
|
280861
|
+
const c = open2.length ? open2.shift() : await new Promise((resolve3, reject) => {
|
|
280810
280862
|
const query = { reserve: resolve3, reject };
|
|
280811
280863
|
queries.push(query);
|
|
280812
280864
|
closed.length && connect5(closed.shift(), query);
|
|
@@ -280879,7 +280931,7 @@ function Postgres(a, b3) {
|
|
|
280879
280931
|
c.queue.remove(c);
|
|
280880
280932
|
queue.push(c);
|
|
280881
280933
|
c.queue = queue;
|
|
280882
|
-
queue ===
|
|
280934
|
+
queue === open2 ? c.idleTimer.start() : c.idleTimer.cancel();
|
|
280883
280935
|
return c;
|
|
280884
280936
|
}
|
|
280885
280937
|
function json3(x) {
|
|
@@ -280893,8 +280945,8 @@ function Postgres(a, b3) {
|
|
|
280893
280945
|
function handler(query) {
|
|
280894
280946
|
if (ending)
|
|
280895
280947
|
return query.reject(Errors.connection("CONNECTION_ENDED", options, options));
|
|
280896
|
-
if (
|
|
280897
|
-
return go(
|
|
280948
|
+
if (open2.length)
|
|
280949
|
+
return go(open2.shift(), query);
|
|
280898
280950
|
if (closed.length)
|
|
280899
280951
|
return connect5(closed.shift(), query);
|
|
280900
280952
|
busy.length ? go(busy.shift(), query) : queries.push(query);
|
|
@@ -280936,7 +280988,7 @@ function Postgres(a, b3) {
|
|
|
280936
280988
|
}
|
|
280937
280989
|
function onopen(c) {
|
|
280938
280990
|
if (queries.length === 0)
|
|
280939
|
-
return move(c,
|
|
280991
|
+
return move(c, open2);
|
|
280940
280992
|
let max = Math.ceil(queries.length / (connecting.length + 1)), ready = true;
|
|
280941
280993
|
while (ready && queries.length && max-- > 0) {
|
|
280942
280994
|
const query = queries.shift();
|
|
@@ -283268,7 +283320,7 @@ var init_path2 = () => {};
|
|
|
283268
283320
|
var ENCODINGS, ENCODINGS_ORDERED_KEYS, DEFAULT_DOCUMENT = "index.html", serveStatic = (options) => {
|
|
283269
283321
|
const root = options.root ?? "./";
|
|
283270
283322
|
const optionPath = options.path;
|
|
283271
|
-
const
|
|
283323
|
+
const join14 = options.join ?? defaultJoin;
|
|
283272
283324
|
return async (c, next) => {
|
|
283273
283325
|
if (c.finalized) {
|
|
283274
283326
|
return next();
|
|
@@ -283287,9 +283339,9 @@ var ENCODINGS, ENCODINGS_ORDERED_KEYS, DEFAULT_DOCUMENT = "index.html", serveSta
|
|
|
283287
283339
|
return next();
|
|
283288
283340
|
}
|
|
283289
283341
|
}
|
|
283290
|
-
let path2 =
|
|
283342
|
+
let path2 = join14(root, !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename);
|
|
283291
283343
|
if (options.isDir && await options.isDir(path2)) {
|
|
283292
|
-
path2 =
|
|
283344
|
+
path2 = join14(path2, DEFAULT_DOCUMENT);
|
|
283293
283345
|
}
|
|
283294
283346
|
const getContent = options.getContent;
|
|
283295
283347
|
let content = await getContent(path2, c);
|
|
@@ -283336,8 +283388,8 @@ var init_serve_static = __esm(() => {
|
|
|
283336
283388
|
});
|
|
283337
283389
|
|
|
283338
283390
|
// ../../node_modules/.bun/hono@4.12.18/node_modules/hono/dist/adapter/bun/serve-static.js
|
|
283339
|
-
import { stat as
|
|
283340
|
-
import { join as
|
|
283391
|
+
import { stat as stat3 } from "fs/promises";
|
|
283392
|
+
import { join as join14 } from "path";
|
|
283341
283393
|
var serveStatic2 = (options) => {
|
|
283342
283394
|
return async function serveStatic22(c, next) {
|
|
283343
283395
|
const getContent = async (path2) => {
|
|
@@ -283347,7 +283399,7 @@ var serveStatic2 = (options) => {
|
|
|
283347
283399
|
const isDir = async (path2) => {
|
|
283348
283400
|
let isDir2;
|
|
283349
283401
|
try {
|
|
283350
|
-
const stats = await
|
|
283402
|
+
const stats = await stat3(path2);
|
|
283351
283403
|
isDir2 = stats.isDirectory();
|
|
283352
283404
|
} catch {}
|
|
283353
283405
|
return isDir2;
|
|
@@ -283355,7 +283407,7 @@ var serveStatic2 = (options) => {
|
|
|
283355
283407
|
return serveStatic({
|
|
283356
283408
|
...options,
|
|
283357
283409
|
getContent,
|
|
283358
|
-
join:
|
|
283410
|
+
join: join14,
|
|
283359
283411
|
isDir
|
|
283360
283412
|
})(c, next);
|
|
283361
283413
|
};
|
|
@@ -285293,6 +285345,11 @@ function enforceInstanceAllowlist(apiKey, target) {
|
|
|
285293
285345
|
function enforceOutboundRecipientAllowlist(apiKey, target) {
|
|
285294
285346
|
return enforceAllowlist(apiKey.profile ?? null, "outboundRecipientAllowlist", apiKey.outboundRecipientAllowlist ?? [], target);
|
|
285295
285347
|
}
|
|
285348
|
+
function mediaPathInstance(method, cleanPath2) {
|
|
285349
|
+
if (method !== "GET")
|
|
285350
|
+
return null;
|
|
285351
|
+
return firstPathSegment(cleanPath2, PATH_MEDIA_INSTANCE_PREFIX);
|
|
285352
|
+
}
|
|
285296
285353
|
function firstPathSegment(cleanPath2, prefix) {
|
|
285297
285354
|
if (!cleanPath2.startsWith(prefix))
|
|
285298
285355
|
return null;
|
|
@@ -285325,7 +285382,7 @@ function readHeaderTargets(c) {
|
|
|
285325
285382
|
function extractLockTargets(method, rawPath, body, headers) {
|
|
285326
285383
|
const cleanPath2 = normalizePath2(rawPath);
|
|
285327
285384
|
const { instanceId, to, chatId } = readBodyTargets(body);
|
|
285328
|
-
const pathInstance = PATH_INSTANCE_PREFIXES.map((p2) => firstPathSegment(cleanPath2, p2)).find((v2) => v2 != null) ??
|
|
285385
|
+
const pathInstance = PATH_INSTANCE_PREFIXES.map((p2) => firstPathSegment(cleanPath2, p2)).find((v2) => v2 != null) ?? mediaPathInstance(method, cleanPath2);
|
|
285329
285386
|
const pathChat = PATH_CHAT_PREFIXES.map((p2) => firstPathSegment(cleanPath2, p2)).find((v2) => v2 != null) ?? null;
|
|
285330
285387
|
const headerInstance = headers?.instance && headers.instance.length > 0 ? headers.instance : null;
|
|
285331
285388
|
const headerChat = headers?.chat && headers.chat.length > 0 ? headers.chat : null;
|
|
@@ -285367,7 +285424,7 @@ function lockDenyResponse(c, lock, result) {
|
|
|
285367
285424
|
}
|
|
285368
285425
|
}, 403);
|
|
285369
285426
|
}
|
|
285370
|
-
var log60, OUTBOUND_SEND_PREFIXES, PATH_INSTANCE_PREFIXES, PATH_CHAT_PREFIXES, scopeEnforcerMiddleware;
|
|
285427
|
+
var log60, OUTBOUND_SEND_PREFIXES, PATH_INSTANCE_PREFIXES, PATH_CHAT_PREFIXES, PATH_MEDIA_INSTANCE_PREFIX = "/media/", scopeEnforcerMiddleware;
|
|
285371
285428
|
var init_scope_enforcer = __esm(() => {
|
|
285372
285429
|
init_src();
|
|
285373
285430
|
init_factory2();
|
|
@@ -294316,7 +294373,7 @@ var require_src64 = __commonJS((exports) => {
|
|
|
294316
294373
|
// ../../node_modules/.bun/@google+genai@1.52.0+6dc9e9ccb27012c9/node_modules/@google/genai/dist/node/index.mjs
|
|
294317
294374
|
import { createWriteStream as createWriteStream6 } from "fs";
|
|
294318
294375
|
import * as fs9 from "fs/promises";
|
|
294319
|
-
import { writeFile as
|
|
294376
|
+
import { writeFile as writeFile3 } from "fs/promises";
|
|
294320
294377
|
import { Readable as Readable4 } from "stream";
|
|
294321
294378
|
import { finished } from "stream/promises";
|
|
294322
294379
|
import * as NodeWs from "ws";
|
|
@@ -305768,7 +305825,7 @@ class NodeDownloader {
|
|
|
305768
305825
|
await finished(writer);
|
|
305769
305826
|
} else {
|
|
305770
305827
|
try {
|
|
305771
|
-
await
|
|
305828
|
+
await writeFile3(params.downloadPath, response, {
|
|
305772
305829
|
encoding: "base64"
|
|
305773
305830
|
});
|
|
305774
305831
|
} catch (error3) {
|
|
@@ -311384,7 +311441,7 @@ var init_stt = __esm(() => {
|
|
|
311384
311441
|
import { spawn as spawn3 } from "child_process";
|
|
311385
311442
|
import { promises as fs10 } from "fs";
|
|
311386
311443
|
import { tmpdir as tmpdir6 } from "os";
|
|
311387
|
-
import { join as
|
|
311444
|
+
import { join as join15 } from "path";
|
|
311388
311445
|
function spawnWithEvents3(command, args) {
|
|
311389
311446
|
return spawn3(command, args);
|
|
311390
311447
|
}
|
|
@@ -311553,8 +311610,8 @@ function estimatePcmDurationMs(byteCount, sampleRate, channels, bitsPerSample) {
|
|
|
311553
311610
|
}
|
|
311554
311611
|
async function convertWavToOggOpus(wavBuffer) {
|
|
311555
311612
|
const stamp = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
311556
|
-
const inputPath =
|
|
311557
|
-
const outputPath =
|
|
311613
|
+
const inputPath = join15(tmpdir6(), `omni-gemini-tts-${stamp}-input.wav`);
|
|
311614
|
+
const outputPath = join15(tmpdir6(), `omni-gemini-tts-${stamp}-output.ogg`);
|
|
311558
311615
|
try {
|
|
311559
311616
|
await fs10.writeFile(inputPath, wavBuffer);
|
|
311560
311617
|
await new Promise((resolve3, reject) => {
|
|
@@ -311600,7 +311657,7 @@ async function convertWavToOggOpus(wavBuffer) {
|
|
|
311600
311657
|
}
|
|
311601
311658
|
}
|
|
311602
311659
|
async function getAudioDurationMs(audioBuffer) {
|
|
311603
|
-
const tempPath =
|
|
311660
|
+
const tempPath = join15(tmpdir6(), `omni-gemini-tts-${Date.now()}-duration.ogg`);
|
|
311604
311661
|
try {
|
|
311605
311662
|
await fs10.writeFile(tempPath, audioBuffer);
|
|
311606
311663
|
return await new Promise((resolve3) => {
|
|
@@ -312078,7 +312135,7 @@ var init_imagegen2 = __esm(() => {
|
|
|
312078
312135
|
import { execFile as execFile2 } from "child_process";
|
|
312079
312136
|
import { promises as fs11 } from "fs";
|
|
312080
312137
|
import { tmpdir as tmpdir7 } from "os";
|
|
312081
|
-
import { join as
|
|
312138
|
+
import { join as join16 } from "path";
|
|
312082
312139
|
import { promisify as promisify5 } from "util";
|
|
312083
312140
|
|
|
312084
312141
|
class OpenAiSttProvider {
|
|
@@ -312233,9 +312290,9 @@ async function normalizeForOpenAiAudioChat(audio, mimeType) {
|
|
|
312233
312290
|
if (format === "mp3" || format === "wav") {
|
|
312234
312291
|
return { audio, format };
|
|
312235
312292
|
}
|
|
312236
|
-
const dir = await fs11.mkdtemp(
|
|
312237
|
-
const input =
|
|
312238
|
-
const output =
|
|
312293
|
+
const dir = await fs11.mkdtemp(join16(tmpdir7(), "omni-openai-audio-"));
|
|
312294
|
+
const input = join16(dir, `input.${sourceExtension(mimeType)}`);
|
|
312295
|
+
const output = join16(dir, "output.mp3");
|
|
312239
312296
|
try {
|
|
312240
312297
|
await fs11.writeFile(input, audio);
|
|
312241
312298
|
await execFileAsync("ffmpeg", [
|
|
@@ -312311,7 +312368,7 @@ var init_stt3 = __esm(() => {
|
|
|
312311
312368
|
import { spawn as spawn4 } from "child_process";
|
|
312312
312369
|
import { promises as fs12 } from "fs";
|
|
312313
312370
|
import { tmpdir as tmpdir8 } from "os";
|
|
312314
|
-
import { join as
|
|
312371
|
+
import { join as join17 } from "path";
|
|
312315
312372
|
function spawnWithEvents4(command, args) {
|
|
312316
312373
|
return spawn4(command, args);
|
|
312317
312374
|
}
|
|
@@ -312428,8 +312485,8 @@ function mimeForFormat(format) {
|
|
|
312428
312485
|
}
|
|
312429
312486
|
async function convertAudio(input, from, to) {
|
|
312430
312487
|
const stamp = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
312431
|
-
const inputPath =
|
|
312432
|
-
const outputPath =
|
|
312488
|
+
const inputPath = join17(tmpdir8(), `omni-openai-tts-${stamp}.${from === "pcm" ? "wav" : from}`);
|
|
312489
|
+
const outputPath = join17(tmpdir8(), `omni-openai-tts-${stamp}.${to}`);
|
|
312433
312490
|
try {
|
|
312434
312491
|
await fs12.writeFile(inputPath, input);
|
|
312435
312492
|
await new Promise((resolve3, reject) => {
|
|
@@ -316103,7 +316160,7 @@ import { execFile as execFile3 } from "child_process";
|
|
|
316103
316160
|
import { promises as fs13 } from "fs";
|
|
316104
316161
|
import { statSync } from "fs";
|
|
316105
316162
|
import { tmpdir as tmpdir9 } from "os";
|
|
316106
|
-
import { basename as basename4, join as
|
|
316163
|
+
import { basename as basename4, join as join18 } from "path";
|
|
316107
316164
|
import { promisify as promisify6 } from "util";
|
|
316108
316165
|
function shouldStopAudioFallback(result) {
|
|
316109
316166
|
return result.success || Boolean(result.errorMessage?.includes("Normalized audio still exceeds provider upload limit"));
|
|
@@ -316156,8 +316213,8 @@ async function normalizeAudioFileForProvider(filePath, mimeType) {
|
|
|
316156
316213
|
if ((format === "mp3" || format === "wav") && stats.size <= PROVIDER_AUDIO_TARGET_BYTES) {
|
|
316157
316214
|
return { filePath, mimeType: format === "wav" ? "audio/wav" : "audio/mpeg", format };
|
|
316158
316215
|
}
|
|
316159
|
-
const dir = await fs13.mkdtemp(
|
|
316160
|
-
const output =
|
|
316216
|
+
const dir = await fs13.mkdtemp(join18(tmpdir9(), "omni-provider-audio-"));
|
|
316217
|
+
const output = join18(dir, `${basename4(filePath)}.provider.mp3`);
|
|
316161
316218
|
try {
|
|
316162
316219
|
await execFileAsync2("ffmpeg", [
|
|
316163
316220
|
"-y",
|
|
@@ -323388,14 +323445,14 @@ import { execFile as execFile4 } from "child_process";
|
|
|
323388
323445
|
import { readFileSync as readFileSync4, statSync as statSync2 } from "fs";
|
|
323389
323446
|
import { promises as fs14 } from "fs";
|
|
323390
323447
|
import { tmpdir as tmpdir10 } from "os";
|
|
323391
|
-
import { basename as basename5, join as
|
|
323448
|
+
import { basename as basename5, join as join19 } from "path";
|
|
323392
323449
|
import { promisify as promisify7 } from "util";
|
|
323393
323450
|
async function prepareVideoForGemini(filePath, mimeType, sizeBytes) {
|
|
323394
323451
|
if (sizeBytes <= MAX_VIDEO_SIZE_MB * 1024 * 1024) {
|
|
323395
323452
|
return { filePath, mimeType, size: sizeBytes, normalized: false };
|
|
323396
323453
|
}
|
|
323397
|
-
const dir = await fs14.mkdtemp(
|
|
323398
|
-
const output =
|
|
323454
|
+
const dir = await fs14.mkdtemp(join19(tmpdir10(), "omni-gemini-video-"));
|
|
323455
|
+
const output = join19(dir, `${basename5(filePath)}.provider.mp4`);
|
|
323399
323456
|
const durationSeconds = await probeDurationSeconds(filePath);
|
|
323400
323457
|
const targetDurationSeconds = Math.min(durationSeconds ?? MAX_VIDEO_PROVIDER_DURATION_SECONDS, MAX_VIDEO_PROVIDER_DURATION_SECONDS);
|
|
323401
323458
|
const targetKbps = Math.max(96, Math.floor(TARGET_VIDEO_SIZE_BYTES * 8 / 1000 / Math.max(1, targetDurationSeconds)) - 48);
|
|
@@ -323751,7 +323808,7 @@ var require_BufferList = __commonJS((exports, module) => {
|
|
|
323751
323808
|
this.head = this.tail = null;
|
|
323752
323809
|
this.length = 0;
|
|
323753
323810
|
};
|
|
323754
|
-
BufferList.prototype.join = function
|
|
323811
|
+
BufferList.prototype.join = function join20(s) {
|
|
323755
323812
|
if (this.length === 0)
|
|
323756
323813
|
return "";
|
|
323757
323814
|
var p2 = this.head;
|
|
@@ -333215,28 +333272,77 @@ var init_batch_pricing = __esm(() => {
|
|
|
333215
333272
|
};
|
|
333216
333273
|
});
|
|
333217
333274
|
|
|
333218
|
-
// ../api/src/
|
|
333219
|
-
import {
|
|
333220
|
-
import {
|
|
333221
|
-
|
|
333222
|
-
|
|
333223
|
-
import { extname as extname2, join as join21 } from "path";
|
|
333224
|
-
function normalizeMimeType2(value) {
|
|
333225
|
-
return value?.split(";")[0]?.trim().toLowerCase() || undefined;
|
|
333275
|
+
// ../api/src/utils/safe-media-fetch.ts
|
|
333276
|
+
import { lookup } from "dns/promises";
|
|
333277
|
+
import { isIP as isIP3 } from "net";
|
|
333278
|
+
function isMediaUrlGuardEnabled(env2 = process.env) {
|
|
333279
|
+
return env2.OMNI_MEDIA_URL_GUARD?.trim().toLowerCase() !== "off";
|
|
333226
333280
|
}
|
|
333227
|
-
function
|
|
333228
|
-
const
|
|
333229
|
-
|
|
333281
|
+
function isDeniedIpv4(address) {
|
|
333282
|
+
const octets = address.split(".").map((part) => Number.parseInt(part, 10));
|
|
333283
|
+
const [a, b3] = octets;
|
|
333284
|
+
if (a === undefined || b3 === undefined)
|
|
333285
|
+
return true;
|
|
333286
|
+
if (a === 0)
|
|
333287
|
+
return true;
|
|
333288
|
+
if (a === 10)
|
|
333289
|
+
return true;
|
|
333290
|
+
if (a === 127)
|
|
333291
|
+
return true;
|
|
333292
|
+
if (a === 169 && b3 === 254)
|
|
333293
|
+
return true;
|
|
333294
|
+
if (a === 172 && b3 >= 16 && b3 <= 31)
|
|
333295
|
+
return true;
|
|
333296
|
+
if (a === 192 && b3 === 168)
|
|
333297
|
+
return true;
|
|
333298
|
+
return false;
|
|
333230
333299
|
}
|
|
333231
|
-
function
|
|
333232
|
-
const
|
|
333233
|
-
|
|
333300
|
+
function isDeniedIpv6(address) {
|
|
333301
|
+
const normalized = address.toLowerCase();
|
|
333302
|
+
if (normalized === "::" || normalized === "::1")
|
|
333303
|
+
return true;
|
|
333304
|
+
const mapped = normalized.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/);
|
|
333305
|
+
if (mapped?.[1])
|
|
333306
|
+
return isDeniedIpv4(mapped[1]);
|
|
333307
|
+
const firstHextet = normalized.split(":", 1)[0] ?? "";
|
|
333308
|
+
if (firstHextet.startsWith("fc") || firstHextet.startsWith("fd"))
|
|
333309
|
+
return true;
|
|
333310
|
+
if (/^fe[89ab]/.test(firstHextet))
|
|
333311
|
+
return true;
|
|
333312
|
+
return false;
|
|
333234
333313
|
}
|
|
333235
|
-
function
|
|
333236
|
-
const
|
|
333237
|
-
if (
|
|
333238
|
-
return
|
|
333239
|
-
|
|
333314
|
+
function isPrivateOrReservedAddress(address) {
|
|
333315
|
+
const family = isIP3(address);
|
|
333316
|
+
if (family === 4)
|
|
333317
|
+
return isDeniedIpv4(address);
|
|
333318
|
+
if (family === 6)
|
|
333319
|
+
return isDeniedIpv6(address);
|
|
333320
|
+
return true;
|
|
333321
|
+
}
|
|
333322
|
+
async function assertSafeMediaUrl(url, resolveAddresses = defaultLookup, env2 = process.env) {
|
|
333323
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
333324
|
+
throw new UnsafeMediaUrlError(url.toString(), `scheme ${url.protocol} is not allowed`);
|
|
333325
|
+
}
|
|
333326
|
+
if (!isMediaUrlGuardEnabled(env2))
|
|
333327
|
+
return;
|
|
333328
|
+
const hostname3 = url.hostname.replace(/^\[|\]$/g, "");
|
|
333329
|
+
if (isIP3(hostname3) !== 0) {
|
|
333330
|
+
if (isPrivateOrReservedAddress(hostname3)) {
|
|
333331
|
+
throw new UnsafeMediaUrlError(url.toString(), `address ${hostname3} is in a private or reserved range`);
|
|
333332
|
+
}
|
|
333333
|
+
return;
|
|
333334
|
+
}
|
|
333335
|
+
let addresses;
|
|
333336
|
+
try {
|
|
333337
|
+
addresses = await resolveAddresses(hostname3);
|
|
333338
|
+
} catch {
|
|
333339
|
+
return;
|
|
333340
|
+
}
|
|
333341
|
+
for (const { address } of addresses) {
|
|
333342
|
+
if (isPrivateOrReservedAddress(address)) {
|
|
333343
|
+
throw new UnsafeMediaUrlError(url.toString(), `host ${hostname3} resolves to private address ${address}`);
|
|
333344
|
+
}
|
|
333345
|
+
}
|
|
333240
333346
|
}
|
|
333241
333347
|
function hostMatchesSuffix2(hostname3, suffix) {
|
|
333242
333348
|
const normalizedHost = hostname3.toLowerCase();
|
|
@@ -333252,14 +333358,12 @@ function headersWithOptionalAuthorization2(headers, preserveAuthorization) {
|
|
|
333252
333358
|
nextHeaders.delete("authorization");
|
|
333253
333359
|
return nextHeaders;
|
|
333254
333360
|
}
|
|
333255
|
-
async function
|
|
333361
|
+
async function fetchMediaUrl(url, fetchOptions) {
|
|
333256
333362
|
const { preserveAuthRedirectHostSuffixes, ...init5 } = fetchOptions ?? {};
|
|
333257
|
-
if (!preserveAuthRedirectHostSuffixes?.length) {
|
|
333258
|
-
return fetch(url, init5);
|
|
333259
|
-
}
|
|
333260
333363
|
let currentUrl = new URL(url);
|
|
333364
|
+
await assertSafeMediaUrl(currentUrl);
|
|
333261
333365
|
let currentHeaders = new Headers(init5.headers);
|
|
333262
|
-
for (let redirects = 0;redirects <=
|
|
333366
|
+
for (let redirects = 0;redirects <= MAX_MEDIA_REDIRECTS; redirects++) {
|
|
333263
333367
|
const response = await fetch(currentUrl.toString(), {
|
|
333264
333368
|
...init5,
|
|
333265
333369
|
headers: currentHeaders,
|
|
@@ -333271,12 +333375,46 @@ async function fetchWithOptionalAuthenticatedRedirects(url, fetchOptions) {
|
|
|
333271
333375
|
if (!location)
|
|
333272
333376
|
return response;
|
|
333273
333377
|
const nextUrl = new URL(location, currentUrl);
|
|
333274
|
-
|
|
333378
|
+
await assertSafeMediaUrl(nextUrl);
|
|
333379
|
+
const preserveAuthorization = nextUrl.origin === currentUrl.origin || shouldPreserveAuthForRedirect(currentUrl, preserveAuthRedirectHostSuffixes) && shouldPreserveAuthForRedirect(nextUrl, preserveAuthRedirectHostSuffixes);
|
|
333275
333380
|
currentHeaders = headersWithOptionalAuthorization2(init5.headers, preserveAuthorization);
|
|
333276
333381
|
currentUrl = nextUrl;
|
|
333277
333382
|
}
|
|
333278
333383
|
throw new Error("Failed to download media: too many redirects");
|
|
333279
333384
|
}
|
|
333385
|
+
var UnsafeMediaUrlError, defaultLookup = async (hostname3) => lookup(hostname3, { all: true }), MAX_MEDIA_REDIRECTS = 5;
|
|
333386
|
+
var init_safe_media_fetch = __esm(() => {
|
|
333387
|
+
UnsafeMediaUrlError = class UnsafeMediaUrlError extends Error {
|
|
333388
|
+
constructor(url, reason) {
|
|
333389
|
+
super(`Refusing to fetch media URL: ${reason} (${url})`);
|
|
333390
|
+
this.name = "UnsafeMediaUrlError";
|
|
333391
|
+
}
|
|
333392
|
+
};
|
|
333393
|
+
});
|
|
333394
|
+
|
|
333395
|
+
// ../api/src/services/media-storage.ts
|
|
333396
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
333397
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync2 } from "fs";
|
|
333398
|
+
import { rm as rm3, writeFile as writeFile4 } from "fs/promises";
|
|
333399
|
+
import { tmpdir as tmpdir11 } from "os";
|
|
333400
|
+
import { extname as extname2, join as join20 } from "path";
|
|
333401
|
+
function normalizeMimeType2(value) {
|
|
333402
|
+
return value?.split(";")[0]?.trim().toLowerCase() || undefined;
|
|
333403
|
+
}
|
|
333404
|
+
function isHtmlMime2(value) {
|
|
333405
|
+
const mimeType = normalizeMimeType2(value);
|
|
333406
|
+
return mimeType === "text/html" || mimeType === "application/xhtml+xml";
|
|
333407
|
+
}
|
|
333408
|
+
function looksLikeHtml2(buffer3) {
|
|
333409
|
+
const preview = buffer3.subarray(0, 512).toString("utf8").trimStart().toLowerCase();
|
|
333410
|
+
return preview.startsWith("<!doctype html") || preview.startsWith("<html>") || preview.startsWith("<html ");
|
|
333411
|
+
}
|
|
333412
|
+
function shouldRejectHtmlMedia(expectedMimeType, responseMimeType, buffer3) {
|
|
333413
|
+
const expected = normalizeMimeType2(expectedMimeType);
|
|
333414
|
+
if (!expected || isHtmlMime2(expected))
|
|
333415
|
+
return false;
|
|
333416
|
+
return isHtmlMime2(responseMimeType) || looksLikeHtml2(buffer3);
|
|
333417
|
+
}
|
|
333280
333418
|
function getExtensionFromMime2(mimeType) {
|
|
333281
333419
|
const mimeToExt = {
|
|
333282
333420
|
"image/jpeg": ".jpg",
|
|
@@ -333335,10 +333473,10 @@ class MediaStorageService {
|
|
|
333335
333473
|
const date3 = timestamp3 ?? new Date;
|
|
333336
333474
|
const yearMonth = `${date3.getFullYear()}-${String(date3.getMonth() + 1).padStart(2, "0")}`;
|
|
333337
333475
|
const ext = mimeType ? getExtensionFromMime2(mimeType) : ".bin";
|
|
333338
|
-
return
|
|
333476
|
+
return join20(instanceId, yearMonth, `${messageId}${ext}`);
|
|
333339
333477
|
}
|
|
333340
333478
|
buildPath(instanceId, messageId, mimeType, timestamp3) {
|
|
333341
|
-
return
|
|
333479
|
+
return join20(this.basePath, this.buildKey(instanceId, messageId, mimeType, timestamp3));
|
|
333342
333480
|
}
|
|
333343
333481
|
async storeFromBase64(instanceId, messageId, base64Data, mimeType, timestamp3) {
|
|
333344
333482
|
const buffer3 = Buffer.from(base64Data, "base64");
|
|
@@ -333362,7 +333500,7 @@ class MediaStorageService {
|
|
|
333362
333500
|
};
|
|
333363
333501
|
}
|
|
333364
333502
|
async storeFromUrl(instanceId, messageId, url, mimeType, timestamp3, fetchOptions) {
|
|
333365
|
-
const response = await
|
|
333503
|
+
const response = await fetchMediaUrl(url, fetchOptions);
|
|
333366
333504
|
if (!response.ok) {
|
|
333367
333505
|
throw new Error(`Failed to download media: ${response.status}`);
|
|
333368
333506
|
}
|
|
@@ -333377,30 +333515,25 @@ class MediaStorageService {
|
|
|
333377
333515
|
async updateMessageLocalPath(messageId, localPath) {
|
|
333378
333516
|
await this.db.update(messages2).set({ mediaLocalPath: localPath }).where(eq(messages2.id, messageId));
|
|
333379
333517
|
}
|
|
333380
|
-
readMedia(relativePath) {
|
|
333381
|
-
const fullPath = join21(this.basePath, relativePath);
|
|
333382
|
-
if (!existsSync3(fullPath)) {
|
|
333383
|
-
return null;
|
|
333384
|
-
}
|
|
333385
|
-
try {
|
|
333386
|
-
const buffer3 = readFileSync6(fullPath);
|
|
333387
|
-
const stat4 = statSync3(fullPath);
|
|
333388
|
-
return {
|
|
333389
|
-
buffer: buffer3,
|
|
333390
|
-
size: Number(stat4.size)
|
|
333391
|
-
};
|
|
333392
|
-
} catch {
|
|
333393
|
-
return null;
|
|
333394
|
-
}
|
|
333395
|
-
}
|
|
333396
333518
|
async readMediaViaBackend(relativePath) {
|
|
333397
333519
|
try {
|
|
333398
333520
|
const buffer3 = await this.backend.read(relativePath);
|
|
333399
333521
|
return { buffer: buffer3, size: buffer3.length };
|
|
333400
|
-
} catch {
|
|
333401
|
-
|
|
333522
|
+
} catch (error3) {
|
|
333523
|
+
if (isMediaNotFoundError(error3))
|
|
333524
|
+
return null;
|
|
333525
|
+
throw error3;
|
|
333402
333526
|
}
|
|
333403
333527
|
}
|
|
333528
|
+
async statMedia(reference) {
|
|
333529
|
+
return this.backend.stat(reference);
|
|
333530
|
+
}
|
|
333531
|
+
async readMediaRange(reference, start, endInclusive) {
|
|
333532
|
+
return this.backend.readRange(reference, start, endInclusive);
|
|
333533
|
+
}
|
|
333534
|
+
async readMediaStream(reference) {
|
|
333535
|
+
return this.backend.readStream(reference);
|
|
333536
|
+
}
|
|
333404
333537
|
getMimeType(filePath) {
|
|
333405
333538
|
const ext = extname2(filePath).toLowerCase();
|
|
333406
333539
|
const extToMime = {
|
|
@@ -333457,13 +333590,13 @@ class MediaStorageService {
|
|
|
333457
333590
|
}
|
|
333458
333591
|
async materializeForProcessing(reference) {
|
|
333459
333592
|
if (this.backend.mode === "local") {
|
|
333460
|
-
return { path:
|
|
333593
|
+
return { path: join20(this.basePath, reference), cleanup: async () => {} };
|
|
333461
333594
|
}
|
|
333462
333595
|
const buffer3 = await this.backend.read(reference);
|
|
333463
333596
|
const ext = extname2(reference) || ".bin";
|
|
333464
|
-
const tempPath =
|
|
333597
|
+
const tempPath = join20(tmpdir11(), `omni-media-${randomUUID2()}${ext}`);
|
|
333465
333598
|
try {
|
|
333466
|
-
await
|
|
333599
|
+
await writeFile4(tempPath, buffer3);
|
|
333467
333600
|
} catch (error3) {
|
|
333468
333601
|
await rm3(tempPath, { force: true }).catch(() => {});
|
|
333469
333602
|
throw error3;
|
|
@@ -333482,6 +333615,7 @@ var init_media_storage = __esm(() => {
|
|
|
333482
333615
|
init_src();
|
|
333483
333616
|
init_src5();
|
|
333484
333617
|
init_drizzle_orm();
|
|
333618
|
+
init_safe_media_fetch();
|
|
333485
333619
|
log83 = createLogger("services:media-storage");
|
|
333486
333620
|
});
|
|
333487
333621
|
|
|
@@ -337676,12 +337810,12 @@ var init_context3 = __esm(() => {
|
|
|
337676
337810
|
|
|
337677
337811
|
// ../api/src/plugins/loader.ts
|
|
337678
337812
|
import { existsSync as existsSync4 } from "fs";
|
|
337679
|
-
import { dirname as dirname6, join as
|
|
337813
|
+
import { dirname as dirname6, join as join21 } from "path";
|
|
337680
337814
|
import { fileURLToPath } from "url";
|
|
337681
337815
|
function findMonorepoRoot(startDir) {
|
|
337682
337816
|
let current = startDir;
|
|
337683
337817
|
while (current !== dirname6(current)) {
|
|
337684
|
-
if (existsSync4(
|
|
337818
|
+
if (existsSync4(join21(current, "turbo.json"))) {
|
|
337685
337819
|
return current;
|
|
337686
337820
|
}
|
|
337687
337821
|
current = dirname6(current);
|
|
@@ -337700,7 +337834,7 @@ function getMonorepoPackagesDir() {
|
|
|
337700
337834
|
if (!monorepoRoot) {
|
|
337701
337835
|
throw new Error("Could not find monorepo root (no turbo.json found). " + "Ensure you run from repo root or set OMNI_PACKAGES_DIR env var.");
|
|
337702
337836
|
}
|
|
337703
|
-
return
|
|
337837
|
+
return join21(monorepoRoot, "packages");
|
|
337704
337838
|
}
|
|
337705
337839
|
async function loadChannelPlugins2(options) {
|
|
337706
337840
|
const { eventBus, db: db2 } = options;
|
|
@@ -338589,9 +338723,9 @@ var init_session_storage = __esm(() => {
|
|
|
338589
338723
|
|
|
338590
338724
|
// ../api/src/plugins/agent-dispatcher.ts
|
|
338591
338725
|
import { createHash as createHash10 } from "crypto";
|
|
338592
|
-
import { unlink, writeFile as
|
|
338726
|
+
import { unlink, writeFile as writeFile5 } from "fs/promises";
|
|
338593
338727
|
import { tmpdir as tmpdir12 } from "os";
|
|
338594
|
-
import { join as
|
|
338728
|
+
import { join as join22, resolve as resolve3 } from "path";
|
|
338595
338729
|
function sha256Digest(value) {
|
|
338596
338730
|
return `sha256:${createHash10("sha256").update(value).digest("hex")}`;
|
|
338597
338731
|
}
|
|
@@ -339042,7 +339176,7 @@ async function resolveDispatchMediaPath(mediaStorage, reference) {
|
|
|
339042
339176
|
return null;
|
|
339043
339177
|
}
|
|
339044
339178
|
}
|
|
339045
|
-
return resolve3(
|
|
339179
|
+
return resolve3(join22(MEDIA_BASE_PATH3, reference));
|
|
339046
339180
|
}
|
|
339047
339181
|
async function remoteMediaFile(m2, mimeType, mediaStorage, allowedTypes) {
|
|
339048
339182
|
const key = m2.payload.rawPayload?.mediaLocalPath;
|
|
@@ -339101,7 +339235,7 @@ function checkProcessedColumn(msg, column2) {
|
|
|
339101
339235
|
if (typeof processed === "string" && processed.startsWith("[error"))
|
|
339102
339236
|
return "error";
|
|
339103
339237
|
if (processed) {
|
|
339104
|
-
const localPath = msg.mediaLocalPath ? resolve3(
|
|
339238
|
+
const localPath = msg.mediaLocalPath ? resolve3(join22(MEDIA_BASE_PATH3, msg.mediaLocalPath)) : null;
|
|
339105
339239
|
return {
|
|
339106
339240
|
content: processed,
|
|
339107
339241
|
localPath
|
|
@@ -340268,13 +340402,13 @@ function mimeToContentType(mimeType) {
|
|
|
340268
340402
|
}
|
|
340269
340403
|
async function downloadToTempFile(url, mimeType) {
|
|
340270
340404
|
try {
|
|
340271
|
-
const res = await
|
|
340405
|
+
const res = await fetchMediaUrl(url);
|
|
340272
340406
|
if (!res.ok)
|
|
340273
340407
|
return null;
|
|
340274
340408
|
const buffer3 = Buffer.from(await res.arrayBuffer());
|
|
340275
340409
|
const ext = (mimeType.split("/")[1]?.split(";")[0] ?? "bin").replace(/[^a-z0-9]/gi, "");
|
|
340276
|
-
const tmpPath =
|
|
340277
|
-
await
|
|
340410
|
+
const tmpPath = join22(tmpdir12(), `omni-hist-${Date.now()}-${Math.random().toString(36).slice(2)}.${ext}`);
|
|
340411
|
+
await writeFile5(tmpPath, buffer3);
|
|
340278
340412
|
return tmpPath;
|
|
340279
340413
|
} catch {
|
|
340280
340414
|
return null;
|
|
@@ -341722,6 +341856,7 @@ var init_agent_dispatcher = __esm(() => {
|
|
|
341722
341856
|
init_sentry_scrub();
|
|
341723
341857
|
init_agent_runner();
|
|
341724
341858
|
init_turn_events();
|
|
341859
|
+
init_safe_media_fetch();
|
|
341725
341860
|
init_agent_dispatch_limiter();
|
|
341726
341861
|
init_loader2();
|
|
341727
341862
|
init_message_debouncer();
|
|
@@ -342736,7 +342871,7 @@ var init_sync_jobs = __esm(() => {
|
|
|
342736
342871
|
import { spawn as spawn5 } from "child_process";
|
|
342737
342872
|
import { promises as fs15 } from "fs";
|
|
342738
342873
|
import { tmpdir as tmpdir13 } from "os";
|
|
342739
|
-
import { join as
|
|
342874
|
+
import { join as join23 } from "path";
|
|
342740
342875
|
function spawnWithEvents5(command, args) {
|
|
342741
342876
|
return spawn5(command, args);
|
|
342742
342877
|
}
|
|
@@ -342844,8 +342979,8 @@ var init_tts3 = __esm(() => {
|
|
|
342844
342979
|
return Buffer.from(await response.arrayBuffer());
|
|
342845
342980
|
}
|
|
342846
342981
|
async convertToOggOpus(mp3Buffer) {
|
|
342847
|
-
const inputPath =
|
|
342848
|
-
const outputPath =
|
|
342982
|
+
const inputPath = join23(tmpdir13(), `omni-tts-${Date.now()}-input.mp3`);
|
|
342983
|
+
const outputPath = join23(tmpdir13(), `omni-tts-${Date.now()}-output.ogg`);
|
|
342849
342984
|
try {
|
|
342850
342985
|
await fs15.writeFile(inputPath, mp3Buffer);
|
|
342851
342986
|
await new Promise((resolve4, reject) => {
|
|
@@ -342891,7 +343026,7 @@ var init_tts3 = __esm(() => {
|
|
|
342891
343026
|
}
|
|
342892
343027
|
}
|
|
342893
343028
|
async getAudioDurationMs(audioBuffer) {
|
|
342894
|
-
const tempPath =
|
|
343029
|
+
const tempPath = join23(tmpdir13(), `omni-tts-${Date.now()}-duration.ogg`);
|
|
342895
343030
|
try {
|
|
342896
343031
|
await fs15.writeFile(tempPath, audioBuffer);
|
|
342897
343032
|
return await new Promise((resolve4) => {
|
|
@@ -343711,17 +343846,17 @@ var init_timeout = __esm(() => {
|
|
|
343711
343846
|
});
|
|
343712
343847
|
|
|
343713
343848
|
// ../api/src/middleware/version-headers.ts
|
|
343714
|
-
import { existsSync as existsSync5, readFileSync as
|
|
343715
|
-
import { join as
|
|
343849
|
+
import { existsSync as existsSync5, readFileSync as readFileSync6 } from "fs";
|
|
343850
|
+
import { join as join24 } from "path";
|
|
343716
343851
|
function loadRepoPackageVersion() {
|
|
343717
343852
|
try {
|
|
343718
343853
|
for (const candidate of [
|
|
343719
|
-
|
|
343720
|
-
|
|
343854
|
+
join24(import.meta.dir, "..", "..", "..", "..", "package.json"),
|
|
343855
|
+
join24(process.cwd(), "package.json")
|
|
343721
343856
|
]) {
|
|
343722
343857
|
if (!existsSync5(candidate))
|
|
343723
343858
|
continue;
|
|
343724
|
-
const parsed = JSON.parse(
|
|
343859
|
+
const parsed = JSON.parse(readFileSync6(candidate, "utf-8"));
|
|
343725
343860
|
if (parsed.version)
|
|
343726
343861
|
return parsed.version;
|
|
343727
343862
|
}
|
|
@@ -343739,13 +343874,13 @@ function resolveFallbackVersion() {
|
|
|
343739
343874
|
function loadServerVersionInfo() {
|
|
343740
343875
|
try {
|
|
343741
343876
|
for (const candidate of [
|
|
343742
|
-
|
|
343743
|
-
|
|
343877
|
+
join24(import.meta.dir, "..", "..", "..", "..", "version.json"),
|
|
343878
|
+
join24(process.cwd(), "version.json")
|
|
343744
343879
|
]) {
|
|
343745
343880
|
if (!existsSync5(candidate)) {
|
|
343746
343881
|
continue;
|
|
343747
343882
|
}
|
|
343748
|
-
const parsed = JSON.parse(
|
|
343883
|
+
const parsed = JSON.parse(readFileSync6(candidate, "utf-8"));
|
|
343749
343884
|
return {
|
|
343750
343885
|
version: parsed.version ?? resolveFallbackVersion(),
|
|
343751
343886
|
commit: parsed.commit ?? FALLBACK_COMMIT
|
|
@@ -354677,7 +354812,7 @@ var init_instances3 = __esm(() => {
|
|
|
354677
354812
|
});
|
|
354678
354813
|
instancesRoutes.post("/:id/sync", instanceAccess2, zValidator("json", syncRequestSchema), async (c) => {
|
|
354679
354814
|
const id = c.req.param("id");
|
|
354680
|
-
const { type, depth, channelId, downloadMedia
|
|
354815
|
+
const { type, depth, channelId, downloadMedia, chatJids } = c.req.valid("json");
|
|
354681
354816
|
const services = c.get("services");
|
|
354682
354817
|
const instance4 = await services.instances.getById(id);
|
|
354683
354818
|
if (type === "profile") {
|
|
@@ -354726,7 +354861,7 @@ var init_instances3 = __esm(() => {
|
|
|
354726
354861
|
config: {
|
|
354727
354862
|
depth: depth ?? "7d",
|
|
354728
354863
|
channelId,
|
|
354729
|
-
downloadMedia:
|
|
354864
|
+
downloadMedia: downloadMedia ?? instance4.downloadMediaOnSync,
|
|
354730
354865
|
...chatJids?.length ? { chatJids } : {}
|
|
354731
354866
|
}
|
|
354732
354867
|
});
|
|
@@ -356978,40 +357113,52 @@ var init_media = __esm(() => {
|
|
|
356978
357113
|
const relativePath = `${instanceId}/${path3}`;
|
|
356979
357114
|
const db2 = c.get("services");
|
|
356980
357115
|
const storage = getMediaStorage(db2);
|
|
356981
|
-
|
|
356982
|
-
|
|
356983
|
-
|
|
356984
|
-
|
|
356985
|
-
|
|
356986
|
-
|
|
356987
|
-
|
|
356988
|
-
|
|
356989
|
-
|
|
356990
|
-
|
|
356991
|
-
|
|
356992
|
-
|
|
356993
|
-
|
|
356994
|
-
|
|
356995
|
-
|
|
356996
|
-
|
|
356997
|
-
|
|
356998
|
-
|
|
356999
|
-
|
|
357000
|
-
"Content-Range": `bytes ${start}-${end}/${fileSize}`,
|
|
357001
|
-
"Accept-Ranges": "bytes"
|
|
357116
|
+
try {
|
|
357117
|
+
const stat5 = await storage.statMedia(relativePath);
|
|
357118
|
+
if (!stat5) {
|
|
357119
|
+
return c.json({ error: { code: "NOT_FOUND", message: "Media not found" } }, 404);
|
|
357120
|
+
}
|
|
357121
|
+
const fileSize = stat5.size;
|
|
357122
|
+
const mimeType = storage.getMimeType(path3);
|
|
357123
|
+
const rangeHeader = c.req.header("Range");
|
|
357124
|
+
if (rangeHeader) {
|
|
357125
|
+
const matches = rangeHeader.match(/bytes=(\d+)-(\d*)/);
|
|
357126
|
+
if (matches?.[1]) {
|
|
357127
|
+
const start = Number.parseInt(matches[1], 10);
|
|
357128
|
+
const requestedEnd = matches[2] ? Number.parseInt(matches[2], 10) : fileSize - 1;
|
|
357129
|
+
const end = Math.min(requestedEnd, fileSize - 1);
|
|
357130
|
+
if (start >= fileSize || start > end) {
|
|
357131
|
+
return new Response(null, {
|
|
357132
|
+
status: 416,
|
|
357133
|
+
headers: { "Content-Range": `bytes */${fileSize}`, "Accept-Ranges": "bytes" }
|
|
357134
|
+
});
|
|
357002
357135
|
}
|
|
357003
|
-
|
|
357136
|
+
const chunk2 = await storage.readMediaRange(relativePath, start, end);
|
|
357137
|
+
return new Response(chunk2, {
|
|
357138
|
+
status: 206,
|
|
357139
|
+
headers: {
|
|
357140
|
+
"Content-Type": mimeType,
|
|
357141
|
+
"Content-Length": String(end - start + 1),
|
|
357142
|
+
"Content-Range": `bytes ${start}-${end}/${fileSize}`,
|
|
357143
|
+
"Accept-Ranges": "bytes"
|
|
357144
|
+
}
|
|
357145
|
+
});
|
|
357146
|
+
}
|
|
357004
357147
|
}
|
|
357148
|
+
const stream2 = await storage.readMediaStream(relativePath);
|
|
357149
|
+
return new Response(stream2, {
|
|
357150
|
+
status: 200,
|
|
357151
|
+
headers: {
|
|
357152
|
+
"Content-Type": mimeType,
|
|
357153
|
+
"Content-Length": String(fileSize),
|
|
357154
|
+
"Accept-Ranges": "bytes",
|
|
357155
|
+
"Cache-Control": "public, max-age=31536000"
|
|
357156
|
+
}
|
|
357157
|
+
});
|
|
357158
|
+
} catch (err) {
|
|
357159
|
+
log110.error("Media backend read failed", { relativePath, error: String(err) });
|
|
357160
|
+
return c.json({ error: { code: "MEDIA_BACKEND_UNAVAILABLE", message: "Media storage backend unavailable, retry later" } }, 503);
|
|
357005
357161
|
}
|
|
357006
|
-
return new Response(buffer3, {
|
|
357007
|
-
status: 200,
|
|
357008
|
-
headers: {
|
|
357009
|
-
"Content-Type": mimeType,
|
|
357010
|
-
"Content-Length": String(fileSize),
|
|
357011
|
-
"Accept-Ranges": "bytes",
|
|
357012
|
-
"Cache-Control": "public, max-age=31536000"
|
|
357013
|
-
}
|
|
357014
|
-
});
|
|
357015
357162
|
});
|
|
357016
357163
|
});
|
|
357017
357164
|
|
|
@@ -357049,7 +357196,7 @@ var init__close_contact_config = __esm(() => {
|
|
|
357049
357196
|
|
|
357050
357197
|
// ../api/src/routes/v2/messages.ts
|
|
357051
357198
|
import { existsSync as existsSync6 } from "fs";
|
|
357052
|
-
import { extname as extname3, join as
|
|
357199
|
+
import { extname as extname3, join as join25 } from "path";
|
|
357053
357200
|
function inferMediaMimeType(type, filename) {
|
|
357054
357201
|
if (filename) {
|
|
357055
357202
|
const fromExtension = MIME_BY_EXTENSION[extname3(filename).toLowerCase()];
|
|
@@ -357608,7 +357755,7 @@ var init_messages5 = __esm(() => {
|
|
|
357608
357755
|
let mediaLocalPath = message2.mediaLocalPath;
|
|
357609
357756
|
let cached = false;
|
|
357610
357757
|
if (mediaLocalPath) {
|
|
357611
|
-
const fullPath =
|
|
357758
|
+
const fullPath = join25(mediaStorage2.getBasePath(), mediaLocalPath);
|
|
357612
357759
|
if (existsSync6(fullPath)) {
|
|
357613
357760
|
cached = true;
|
|
357614
357761
|
} else {
|
|
@@ -371273,9 +371420,9 @@ function popStackToMatchingTag(openStack, name) {
|
|
|
371273
371420
|
}
|
|
371274
371421
|
function appendTagTokenToState(state, tokenValue) {
|
|
371275
371422
|
const close = parseClosingTag(tokenValue);
|
|
371276
|
-
const
|
|
371277
|
-
if (
|
|
371278
|
-
if (!canAppendPlainHtml(state, tokenValue,
|
|
371423
|
+
const open2 = parseOpeningTag(tokenValue);
|
|
371424
|
+
if (open2) {
|
|
371425
|
+
if (!canAppendPlainHtml(state, tokenValue, open2))
|
|
371279
371426
|
flushPlainHtmlState(state);
|
|
371280
371427
|
} else if (!canAppendPlainHtml(state, tokenValue)) {
|
|
371281
371428
|
flushPlainHtmlState(state);
|
|
@@ -371285,8 +371432,8 @@ function appendTagTokenToState(state, tokenValue) {
|
|
|
371285
371432
|
popStackToMatchingTag(state.openStack, close.name);
|
|
371286
371433
|
return;
|
|
371287
371434
|
}
|
|
371288
|
-
if (
|
|
371289
|
-
state.openStack.push(
|
|
371435
|
+
if (open2)
|
|
371436
|
+
state.openStack.push(open2);
|
|
371290
371437
|
}
|
|
371291
371438
|
function appendTextTokenToState(state, text) {
|
|
371292
371439
|
let remaining = text;
|
|
@@ -476016,9 +476163,9 @@ function makeLibSignalRepository(auth, logger5, pnToLIDFunc) {
|
|
|
476016
476163
|
if (!session) {
|
|
476017
476164
|
return null;
|
|
476018
476165
|
}
|
|
476019
|
-
const
|
|
476020
|
-
const baseKey =
|
|
476021
|
-
const registrationId =
|
|
476166
|
+
const open2 = session.getOpenSession?.();
|
|
476167
|
+
const baseKey = open2?.indexInfo?.baseKey;
|
|
476168
|
+
const registrationId = open2?.registrationId;
|
|
476022
476169
|
if (!baseKey || typeof registrationId !== "number") {
|
|
476023
476170
|
return null;
|
|
476024
476171
|
}
|
|
@@ -484632,13 +484779,13 @@ function resetConnectionState2(instanceId) {
|
|
|
484632
484779
|
// ../channel-whatsapp/src/handlers/messages.ts
|
|
484633
484780
|
init_src2();
|
|
484634
484781
|
init_src();
|
|
484635
|
-
import { basename, join as
|
|
484782
|
+
import { basename, join as join8 } from "path";
|
|
484636
484783
|
|
|
484637
484784
|
// ../channel-whatsapp/src/utils/download.ts
|
|
484638
484785
|
init_src2();
|
|
484639
484786
|
import { createWriteStream as createWriteStream4 } from "fs";
|
|
484640
|
-
import { mkdir as mkdir3, rm as rm2
|
|
484641
|
-
import { dirname as dirname2
|
|
484787
|
+
import { mkdir as mkdir3, rm as rm2 } from "fs/promises";
|
|
484788
|
+
import { dirname as dirname2 } from "path";
|
|
484642
484789
|
import { Transform as Transform3 } from "stream";
|
|
484643
484790
|
import { pipeline as pipeline3 } from "stream/promises";
|
|
484644
484791
|
|
|
@@ -485176,8 +485323,8 @@ async function tryDownloadMedia(msg, instanceId, externalId, apiBaseUrl, backend
|
|
|
485176
485323
|
const yearMonth = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}`;
|
|
485177
485324
|
const ext = getExtension2(mediaInfo.mimeType);
|
|
485178
485325
|
const safeExternalId = basename(externalId).replace(/[^a-zA-Z0-9_\-]/g, "_");
|
|
485179
|
-
const relativePath =
|
|
485180
|
-
const result = backend.mode === "remote" ? await streamMediaWithRetry(() => downloadMediaToBackend(msg, backend, relativePath, downloadGuard5.maxSizeBytes)) : await streamMediaWithRetry(() => downloadMediaToFile(msg,
|
|
485326
|
+
const relativePath = join8(instanceId, yearMonth, `${safeExternalId}${ext}`);
|
|
485327
|
+
const result = backend.mode === "remote" ? await streamMediaWithRetry(() => downloadMediaToBackend(msg, backend, relativePath, downloadGuard5.maxSizeBytes)) : await streamMediaWithRetry(() => downloadMediaToFile(msg, join8(MEDIA_BASE_PATH2, relativePath), downloadGuard5.maxSizeBytes));
|
|
485181
485328
|
if (!result)
|
|
485182
485329
|
return null;
|
|
485183
485330
|
log51.debug("Downloaded media", { externalId, path: relativePath, size: result.size, mode: backend.mode });
|