@tradejs/infra 1.0.5 → 1.0.8
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/ai.d.mts +36 -0
- package/dist/ai.d.ts +36 -0
- package/dist/ai.js +456 -0
- package/dist/ai.mjs +386 -0
- package/dist/aiEndpoints.d.mts +10 -0
- package/dist/aiEndpoints.d.ts +10 -0
- package/dist/aiEndpoints.js +159 -0
- package/dist/aiEndpoints.mjs +12 -0
- package/dist/aiLanguages.d.mts +11 -0
- package/dist/aiLanguages.d.ts +11 -0
- package/dist/aiLanguages.js +71 -0
- package/dist/aiLanguages.mjs +12 -0
- package/dist/aiModels.d.mts +12 -0
- package/dist/aiModels.d.ts +12 -0
- package/dist/aiModels.js +272 -0
- package/dist/aiModels.mjs +17 -0
- package/dist/chunk-CCC7DX2T.mjs +44 -0
- package/dist/chunk-DSTV67R5.mjs +345 -0
- package/dist/chunk-DTCLZIBM.mjs +163 -0
- package/dist/chunk-KVEZORMS.mjs +142 -0
- package/dist/chunk-XQ3YBULV.mjs +132 -0
- package/dist/ml.d.mts +2 -20
- package/dist/ml.d.ts +2 -20
- package/dist/ml.js +136 -0
- package/dist/ml.mjs +139 -124
- package/dist/mlDatasetFile-sRGWgR_o.d.mts +24 -0
- package/dist/mlDatasetFile-sRGWgR_o.d.ts +24 -0
- package/dist/redis.d.mts +17 -1
- package/dist/redis.d.ts +17 -1
- package/dist/redis.js +50 -0
- package/dist/redis.mjs +13 -287
- package/dist/timescale.d.mts +18 -7
- package/dist/timescale.d.ts +18 -7
- package/dist/timescale.js +142 -31
- package/dist/timescale.mjs +140 -31
- package/dist/userSettings.d.mts +31 -0
- package/dist/userSettings.d.ts +31 -0
- package/dist/userSettings.js +636 -0
- package/dist/userSettings.mjs +70 -0
- package/package.json +28 -3
package/dist/ai.mjs
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mergeJsonlFiles,
|
|
3
|
+
toFileToken
|
|
4
|
+
} from "./chunk-KVEZORMS.mjs";
|
|
5
|
+
|
|
6
|
+
// src/aiDatasetFile.ts
|
|
7
|
+
import { once } from "events";
|
|
8
|
+
import { createWriteStream } from "fs";
|
|
9
|
+
import fs from "fs/promises";
|
|
10
|
+
import path from "path";
|
|
11
|
+
import { createReadStream } from "fs";
|
|
12
|
+
import readline from "readline";
|
|
13
|
+
var DEFAULT_DIR = "data/ai/export";
|
|
14
|
+
var AI_DATASET_WRITE_BATCH_SIZE = 100;
|
|
15
|
+
var AI_MERGE_SORT_RUN_MAX_ROWS = 2e3;
|
|
16
|
+
var AI_MERGE_SORT_RUN_MAX_BYTES = 16 * 1024 * 1024;
|
|
17
|
+
var AI_CHUNK_FILE_RE = /^ai-dataset-(.+)-chunk-[^.]+\.jsonl$/;
|
|
18
|
+
var writerByPath = /* @__PURE__ */ new Map();
|
|
19
|
+
var getAiChunkFilePath = (strategyName, chunkId, outDir = DEFAULT_DIR) => path.join(
|
|
20
|
+
outDir,
|
|
21
|
+
`ai-dataset-${toFileToken(strategyName)}-chunk-${toFileToken(chunkId)}.jsonl`
|
|
22
|
+
);
|
|
23
|
+
var appendAiDatasetRow = async (params) => {
|
|
24
|
+
const { strategyName, chunkId, row, outDir = DEFAULT_DIR } = params;
|
|
25
|
+
const filePath = getAiChunkFilePath(strategyName, chunkId, outDir);
|
|
26
|
+
let state = writerByPath.get(filePath);
|
|
27
|
+
if (!state) {
|
|
28
|
+
await fs.mkdir(outDir, { recursive: true });
|
|
29
|
+
const stream = createWriteStream(filePath, {
|
|
30
|
+
encoding: "utf8",
|
|
31
|
+
flags: "a"
|
|
32
|
+
});
|
|
33
|
+
state = {
|
|
34
|
+
filePath,
|
|
35
|
+
stream,
|
|
36
|
+
buffer: [],
|
|
37
|
+
writeQueue: Promise.resolve(),
|
|
38
|
+
closed: false
|
|
39
|
+
};
|
|
40
|
+
writerByPath.set(filePath, state);
|
|
41
|
+
}
|
|
42
|
+
if (state.closed) {
|
|
43
|
+
throw new Error(`AI dataset writer is closed: ${filePath}`);
|
|
44
|
+
}
|
|
45
|
+
state.buffer.push(`${JSON.stringify(row)}
|
|
46
|
+
`);
|
|
47
|
+
if (state.buffer.length >= AI_DATASET_WRITE_BATCH_SIZE) {
|
|
48
|
+
await flushAiDatasetWriter(filePath);
|
|
49
|
+
}
|
|
50
|
+
return filePath;
|
|
51
|
+
};
|
|
52
|
+
var flushState = async (state) => {
|
|
53
|
+
if (state.closed || state.buffer.length === 0) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const chunk = state.buffer.join("");
|
|
57
|
+
state.buffer = [];
|
|
58
|
+
if (!state.stream.write(chunk)) {
|
|
59
|
+
await once(state.stream, "drain");
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var flushAiDatasetWriter = async (filePath) => {
|
|
63
|
+
const state = writerByPath.get(filePath);
|
|
64
|
+
if (!state || state.closed) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
state.writeQueue = state.writeQueue.then(() => flushState(state));
|
|
68
|
+
await state.writeQueue;
|
|
69
|
+
};
|
|
70
|
+
var closeState = async (state) => {
|
|
71
|
+
if (state.closed) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
await flushState(state);
|
|
75
|
+
state.closed = true;
|
|
76
|
+
state.stream.end();
|
|
77
|
+
await Promise.all([
|
|
78
|
+
once(state.stream, "finish"),
|
|
79
|
+
once(state.stream, "close")
|
|
80
|
+
]);
|
|
81
|
+
};
|
|
82
|
+
var closeAiDatasetWriter = async (filePath) => {
|
|
83
|
+
const state = writerByPath.get(filePath);
|
|
84
|
+
if (!state) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
state.writeQueue = state.writeQueue.then(() => closeState(state));
|
|
88
|
+
await state.writeQueue;
|
|
89
|
+
writerByPath.delete(filePath);
|
|
90
|
+
};
|
|
91
|
+
var closeAllAiDatasetWriters = async () => {
|
|
92
|
+
const filePaths = [...writerByPath.keys()];
|
|
93
|
+
for (const filePath of filePaths) {
|
|
94
|
+
await closeAiDatasetWriter(filePath);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
var listAiChunkFiles = async (params) => {
|
|
98
|
+
const { strategyName, outDir = DEFAULT_DIR } = params;
|
|
99
|
+
const prefix = `ai-dataset-${toFileToken(strategyName)}-chunk-`;
|
|
100
|
+
let entries = [];
|
|
101
|
+
try {
|
|
102
|
+
entries = await fs.readdir(outDir);
|
|
103
|
+
} catch {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
return entries.filter((name) => name.startsWith(prefix) && name.endsWith(".jsonl")).map((name) => path.join(outDir, name)).sort();
|
|
107
|
+
};
|
|
108
|
+
var listAiChunkStrategies = async (params) => {
|
|
109
|
+
const outDir = params?.outDir ?? DEFAULT_DIR;
|
|
110
|
+
let entries = [];
|
|
111
|
+
try {
|
|
112
|
+
entries = await fs.readdir(outDir);
|
|
113
|
+
} catch {
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
return [
|
|
117
|
+
...new Set(
|
|
118
|
+
entries.map((name) => name.match(AI_CHUNK_FILE_RE)?.[1] || "").filter(Boolean)
|
|
119
|
+
)
|
|
120
|
+
].sort();
|
|
121
|
+
};
|
|
122
|
+
var parseAiDatasetLine = (line, filePath) => {
|
|
123
|
+
try {
|
|
124
|
+
return JSON.parse(line);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
const message = error?.message || String(error);
|
|
127
|
+
throw new Error(
|
|
128
|
+
`Failed to parse AI dataset row from ${filePath}: ${message}`
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
var getAiDatasetSortKey = (row) => {
|
|
133
|
+
const timestamp = Number(row.timestamp);
|
|
134
|
+
return {
|
|
135
|
+
timestamp: Number.isFinite(timestamp) ? timestamp : Number.MAX_SAFE_INTEGER,
|
|
136
|
+
symbol: String(row.symbol || ""),
|
|
137
|
+
signalId: String(row.signalId || "")
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
var compareAiDatasetSortKeys = (left, right) => {
|
|
141
|
+
if (left.timestamp !== right.timestamp) {
|
|
142
|
+
return left.timestamp - right.timestamp;
|
|
143
|
+
}
|
|
144
|
+
const symbolCompare = left.symbol.localeCompare(right.symbol);
|
|
145
|
+
if (symbolCompare !== 0) {
|
|
146
|
+
return symbolCompare;
|
|
147
|
+
}
|
|
148
|
+
return left.signalId.localeCompare(right.signalId);
|
|
149
|
+
};
|
|
150
|
+
var compareSortableAiDatasetLines = (left, right) => {
|
|
151
|
+
const keyCompare = compareAiDatasetSortKeys(left.sortKey, right.sortKey);
|
|
152
|
+
if (keyCompare !== 0) {
|
|
153
|
+
return keyCompare;
|
|
154
|
+
}
|
|
155
|
+
return left.sourceIndex - right.sourceIndex;
|
|
156
|
+
};
|
|
157
|
+
var compareSortedRunHeads = (left, right) => {
|
|
158
|
+
const keyCompare = compareAiDatasetSortKeys(left.sortKey, right.sortKey);
|
|
159
|
+
if (keyCompare !== 0) {
|
|
160
|
+
return keyCompare;
|
|
161
|
+
}
|
|
162
|
+
return left.runIndex - right.runIndex;
|
|
163
|
+
};
|
|
164
|
+
var writeJsonlLines = async (params) => {
|
|
165
|
+
const { filePath, lines } = params;
|
|
166
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
167
|
+
const stream = createWriteStream(filePath, { encoding: "utf8" });
|
|
168
|
+
const done = Promise.all([once(stream, "finish"), once(stream, "close")]);
|
|
169
|
+
try {
|
|
170
|
+
for (const line of lines) {
|
|
171
|
+
if (!stream.write(`${line}
|
|
172
|
+
`)) {
|
|
173
|
+
await once(stream, "drain");
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
} finally {
|
|
177
|
+
stream.end();
|
|
178
|
+
await done;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
var flushSortedRun = async (params) => {
|
|
182
|
+
const { tempDir, runIndex, entries } = params;
|
|
183
|
+
entries.sort(compareSortableAiDatasetLines);
|
|
184
|
+
const filePath = path.join(
|
|
185
|
+
tempDir,
|
|
186
|
+
`run-${String(runIndex).padStart(6, "0")}.jsonl`
|
|
187
|
+
);
|
|
188
|
+
await writeJsonlLines({
|
|
189
|
+
filePath,
|
|
190
|
+
lines: entries.map(({ line }) => line)
|
|
191
|
+
});
|
|
192
|
+
return filePath;
|
|
193
|
+
};
|
|
194
|
+
var readNextNonEmptyLine = async (iterator) => {
|
|
195
|
+
while (true) {
|
|
196
|
+
const next = await iterator.next();
|
|
197
|
+
if (next.done) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
const trimmed = String(next.value || "").trim();
|
|
201
|
+
if (trimmed) {
|
|
202
|
+
return trimmed;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
var mergeSortedRuns = async (params) => {
|
|
207
|
+
const { runPaths, outPath } = params;
|
|
208
|
+
await fs.mkdir(path.dirname(outPath), { recursive: true });
|
|
209
|
+
const output = createWriteStream(outPath, { encoding: "utf8" });
|
|
210
|
+
const outputDone = Promise.all([
|
|
211
|
+
once(output, "finish"),
|
|
212
|
+
once(output, "close")
|
|
213
|
+
]);
|
|
214
|
+
const heads = [];
|
|
215
|
+
try {
|
|
216
|
+
for (let runIndex = 0; runIndex < runPaths.length; runIndex += 1) {
|
|
217
|
+
const runPath = runPaths[runIndex];
|
|
218
|
+
const reader = readline.createInterface({
|
|
219
|
+
input: createReadStream(runPath, { encoding: "utf8" }),
|
|
220
|
+
crlfDelay: Infinity
|
|
221
|
+
});
|
|
222
|
+
const iterator = reader[Symbol.asyncIterator]();
|
|
223
|
+
const line = await readNextNonEmptyLine(iterator);
|
|
224
|
+
if (!line) {
|
|
225
|
+
reader.close();
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
heads.push({
|
|
229
|
+
runIndex,
|
|
230
|
+
line,
|
|
231
|
+
sortKey: getAiDatasetSortKey(parseAiDatasetLine(line, runPath)),
|
|
232
|
+
iterator,
|
|
233
|
+
reader
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
while (heads.length > 0) {
|
|
237
|
+
let bestIndex = 0;
|
|
238
|
+
for (let index = 1; index < heads.length; index += 1) {
|
|
239
|
+
if (compareSortedRunHeads(heads[index], heads[bestIndex]) < 0) {
|
|
240
|
+
bestIndex = index;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const best = heads[bestIndex];
|
|
244
|
+
if (!output.write(`${best.line}
|
|
245
|
+
`)) {
|
|
246
|
+
await once(output, "drain");
|
|
247
|
+
}
|
|
248
|
+
const nextLine = await readNextNonEmptyLine(best.iterator);
|
|
249
|
+
if (!nextLine) {
|
|
250
|
+
best.reader.close();
|
|
251
|
+
heads.splice(bestIndex, 1);
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
best.line = nextLine;
|
|
255
|
+
best.sortKey = getAiDatasetSortKey(
|
|
256
|
+
parseAiDatasetLine(nextLine, runPaths[best.runIndex])
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
} finally {
|
|
260
|
+
for (const head of heads) {
|
|
261
|
+
head.reader.close();
|
|
262
|
+
}
|
|
263
|
+
output.end();
|
|
264
|
+
await outputDone;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
var mergeAiJsonlFiles = async (params) => {
|
|
268
|
+
const {
|
|
269
|
+
filePaths,
|
|
270
|
+
outPath,
|
|
271
|
+
maxRowsInMemory = AI_MERGE_SORT_RUN_MAX_ROWS,
|
|
272
|
+
maxBytesInMemory = AI_MERGE_SORT_RUN_MAX_BYTES
|
|
273
|
+
} = params;
|
|
274
|
+
const tempDir = path.join(
|
|
275
|
+
path.dirname(outPath),
|
|
276
|
+
`.ai-merge-${path.basename(outPath)}-${Date.now()}-${process.pid}`
|
|
277
|
+
);
|
|
278
|
+
let batch = [];
|
|
279
|
+
let batchBytes = 0;
|
|
280
|
+
let sourceIndex = 0;
|
|
281
|
+
let runIndex = 0;
|
|
282
|
+
const runPaths = [];
|
|
283
|
+
const flushBatch = async () => {
|
|
284
|
+
if (!batch.length) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
runPaths.push(
|
|
288
|
+
await flushSortedRun({
|
|
289
|
+
tempDir,
|
|
290
|
+
runIndex,
|
|
291
|
+
entries: batch
|
|
292
|
+
})
|
|
293
|
+
);
|
|
294
|
+
runIndex += 1;
|
|
295
|
+
batch = [];
|
|
296
|
+
batchBytes = 0;
|
|
297
|
+
};
|
|
298
|
+
try {
|
|
299
|
+
await fs.mkdir(tempDir, { recursive: true });
|
|
300
|
+
for (const filePath of filePaths) {
|
|
301
|
+
const reader = readline.createInterface({
|
|
302
|
+
input: createReadStream(filePath, { encoding: "utf8" }),
|
|
303
|
+
crlfDelay: Infinity
|
|
304
|
+
});
|
|
305
|
+
try {
|
|
306
|
+
for await (const line of reader) {
|
|
307
|
+
const trimmed = line.trim();
|
|
308
|
+
if (!trimmed) {
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
batch.push({
|
|
312
|
+
line: trimmed,
|
|
313
|
+
sortKey: getAiDatasetSortKey(parseAiDatasetLine(trimmed, filePath)),
|
|
314
|
+
sourceIndex
|
|
315
|
+
});
|
|
316
|
+
sourceIndex += 1;
|
|
317
|
+
batchBytes += Buffer.byteLength(trimmed, "utf8") + 1;
|
|
318
|
+
if (batch.length >= maxRowsInMemory || batchBytes >= maxBytesInMemory) {
|
|
319
|
+
await flushBatch();
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
} finally {
|
|
323
|
+
reader.close();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
await flushBatch();
|
|
327
|
+
if (!runPaths.length) {
|
|
328
|
+
await fs.mkdir(path.dirname(outPath), { recursive: true });
|
|
329
|
+
await fs.writeFile(outPath, "", "utf8");
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
await mergeSortedRuns({
|
|
333
|
+
runPaths,
|
|
334
|
+
outPath
|
|
335
|
+
});
|
|
336
|
+
} finally {
|
|
337
|
+
await fs.rm(tempDir, { recursive: true, force: true });
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
var readAiDatasetRows = async (params) => {
|
|
341
|
+
const { filePath, limitFromEnd = 0, skipFromEnd = 0 } = params;
|
|
342
|
+
const rows = [];
|
|
343
|
+
const recentLines = [];
|
|
344
|
+
let totalRows = 0;
|
|
345
|
+
const recentWindowLimit = limitFromEnd > 0 ? limitFromEnd + Math.max(0, skipFromEnd) : 0;
|
|
346
|
+
const reader = readline.createInterface({
|
|
347
|
+
input: createReadStream(filePath, { encoding: "utf8" }),
|
|
348
|
+
crlfDelay: Infinity
|
|
349
|
+
});
|
|
350
|
+
for await (const line of reader) {
|
|
351
|
+
const trimmed = line.trim();
|
|
352
|
+
if (!trimmed) {
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
totalRows += 1;
|
|
356
|
+
if (limitFromEnd > 0) {
|
|
357
|
+
if (recentLines.length === recentWindowLimit) {
|
|
358
|
+
recentLines.shift();
|
|
359
|
+
}
|
|
360
|
+
recentLines.push(trimmed);
|
|
361
|
+
} else {
|
|
362
|
+
const row = JSON.parse(trimmed);
|
|
363
|
+
rows.push(row);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
const effectiveSkip = Math.max(0, skipFromEnd);
|
|
367
|
+
const selectedRecentLines = effectiveSkip > 0 ? recentLines.slice(0, Math.max(0, recentLines.length - effectiveSkip)) : recentLines;
|
|
368
|
+
const selectedRows = limitFromEnd > 0 ? selectedRecentLines.map((line) => JSON.parse(line)) : effectiveSkip > 0 ? rows.slice(0, Math.max(0, rows.length - effectiveSkip)) : rows;
|
|
369
|
+
return {
|
|
370
|
+
rows: selectedRows,
|
|
371
|
+
totalRows
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
export {
|
|
375
|
+
appendAiDatasetRow,
|
|
376
|
+
closeAiDatasetWriter,
|
|
377
|
+
closeAllAiDatasetWriters,
|
|
378
|
+
flushAiDatasetWriter,
|
|
379
|
+
getAiChunkFilePath,
|
|
380
|
+
listAiChunkFiles,
|
|
381
|
+
listAiChunkStrategies,
|
|
382
|
+
mergeAiJsonlFiles,
|
|
383
|
+
mergeJsonlFiles,
|
|
384
|
+
readAiDatasetRows,
|
|
385
|
+
toFileToken
|
|
386
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type AiEndpointOption = {
|
|
2
|
+
label: string;
|
|
3
|
+
value: string;
|
|
4
|
+
};
|
|
5
|
+
declare const AI_CUSTOM_ENDPOINT_VALUE = "__custom__";
|
|
6
|
+
declare const AI_ENDPOINT_OPTIONS: AiEndpointOption[];
|
|
7
|
+
declare const normalizeAiEndpoint: (value: unknown) => string;
|
|
8
|
+
declare const isKnownAiEndpoint: (value: unknown) => value is string;
|
|
9
|
+
|
|
10
|
+
export { AI_CUSTOM_ENDPOINT_VALUE, AI_ENDPOINT_OPTIONS, type AiEndpointOption, isKnownAiEndpoint, normalizeAiEndpoint };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type AiEndpointOption = {
|
|
2
|
+
label: string;
|
|
3
|
+
value: string;
|
|
4
|
+
};
|
|
5
|
+
declare const AI_CUSTOM_ENDPOINT_VALUE = "__custom__";
|
|
6
|
+
declare const AI_ENDPOINT_OPTIONS: AiEndpointOption[];
|
|
7
|
+
declare const normalizeAiEndpoint: (value: unknown) => string;
|
|
8
|
+
declare const isKnownAiEndpoint: (value: unknown) => value is string;
|
|
9
|
+
|
|
10
|
+
export { AI_CUSTOM_ENDPOINT_VALUE, AI_ENDPOINT_OPTIONS, type AiEndpointOption, isKnownAiEndpoint, normalizeAiEndpoint };
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/aiEndpoints.ts
|
|
21
|
+
var aiEndpoints_exports = {};
|
|
22
|
+
__export(aiEndpoints_exports, {
|
|
23
|
+
AI_CUSTOM_ENDPOINT_VALUE: () => AI_CUSTOM_ENDPOINT_VALUE,
|
|
24
|
+
AI_ENDPOINT_OPTIONS: () => AI_ENDPOINT_OPTIONS,
|
|
25
|
+
isKnownAiEndpoint: () => isKnownAiEndpoint,
|
|
26
|
+
normalizeAiEndpoint: () => normalizeAiEndpoint
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(aiEndpoints_exports);
|
|
29
|
+
var AI_CUSTOM_ENDPOINT_VALUE = "__custom__";
|
|
30
|
+
var AI_ENDPOINT_OPTIONS = [
|
|
31
|
+
{
|
|
32
|
+
label: "OpenAI",
|
|
33
|
+
value: "https://api.openai.com/v1"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
label: "Claude",
|
|
37
|
+
value: "https://api.anthropic.com/v1"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
label: "OpenRouter",
|
|
41
|
+
value: "https://openrouter.ai/api/v1"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
label: "Gemini",
|
|
45
|
+
value: "https://generativelanguage.googleapis.com/v1beta/openai"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
label: "Together AI",
|
|
49
|
+
value: "https://api.together.xyz/v1"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
label: "Groq",
|
|
53
|
+
value: "https://api.groq.com/openai/v1"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
label: "DeepInfra",
|
|
57
|
+
value: "https://api.deepinfra.com/v1/openai"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
label: "xAI",
|
|
61
|
+
value: "https://api.x.ai/v1"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
label: "Qwen (DashScope Intl)",
|
|
65
|
+
value: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
label: "Qwen (DashScope CN)",
|
|
69
|
+
value: "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
label: "Qwen (DashScope US)",
|
|
73
|
+
value: "https://dashscope-us.aliyuncs.com/compatible-mode/v1"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
label: "Perplexity",
|
|
77
|
+
value: "https://api.perplexity.ai"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
label: "Fireworks",
|
|
81
|
+
value: "https://api.fireworks.ai/inference/v1"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
label: "SambaNova",
|
|
85
|
+
value: "https://api.sambanova.ai/v1"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
label: "Hyperbolic",
|
|
89
|
+
value: "https://api.hyperbolic.xyz/v1"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
label: "Kimi",
|
|
93
|
+
value: "https://api.moonshot.ai/v1"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
label: "ProxyAPI",
|
|
97
|
+
value: "https://openai.api.proxyapi.ru/v1"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
label: "Custom",
|
|
101
|
+
value: AI_CUSTOM_ENDPOINT_VALUE
|
|
102
|
+
}
|
|
103
|
+
];
|
|
104
|
+
var KNOWN_AI_ENDPOINTS = new Set(
|
|
105
|
+
AI_ENDPOINT_OPTIONS.map((option) => option.value).filter(
|
|
106
|
+
(value) => value !== AI_CUSTOM_ENDPOINT_VALUE
|
|
107
|
+
)
|
|
108
|
+
);
|
|
109
|
+
var normalizeUrl = (value) => value.replace(/\/+$/, "");
|
|
110
|
+
var isIpv4Address = (value) => /^(?:\d{1,3}\.){3}\d{1,3}$/.test(value.trim());
|
|
111
|
+
var parseIpv4Address = (value) => value.trim().split(".").map((part) => Number(part));
|
|
112
|
+
var isPrivateIpv4Address = (value) => {
|
|
113
|
+
if (!isIpv4Address(value)) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
const [a, b, c, d] = parseIpv4Address(value);
|
|
117
|
+
if ([a, b, c, d].some(
|
|
118
|
+
(part) => !Number.isInteger(part) || part < 0 || part > 255
|
|
119
|
+
)) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
return a === 10 || a === 127 || a === 0 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 168;
|
|
123
|
+
};
|
|
124
|
+
var isPrivateHostname = (hostname) => {
|
|
125
|
+
const normalized = hostname.trim().toLowerCase();
|
|
126
|
+
if (!normalized) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
return normalized === "localhost" || normalized.endsWith(".localhost") || normalized.endsWith(".local") || normalized.endsWith(".internal") || normalized.endsWith(".lan") || normalized === "::1" || normalized === "[::1]" || isPrivateIpv4Address(normalized);
|
|
130
|
+
};
|
|
131
|
+
var isValidAiEndpointUrl = (value) => {
|
|
132
|
+
try {
|
|
133
|
+
const url = new URL(value);
|
|
134
|
+
return url.protocol === "https:" && !isPrivateHostname(url.hostname);
|
|
135
|
+
} catch {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var normalizeAiEndpoint = (value) => {
|
|
140
|
+
if (typeof value !== "string") {
|
|
141
|
+
return "";
|
|
142
|
+
}
|
|
143
|
+
const trimmed = normalizeUrl(value.trim());
|
|
144
|
+
if (!trimmed) {
|
|
145
|
+
return "";
|
|
146
|
+
}
|
|
147
|
+
if (KNOWN_AI_ENDPOINTS.has(trimmed)) {
|
|
148
|
+
return trimmed;
|
|
149
|
+
}
|
|
150
|
+
return isValidAiEndpointUrl(trimmed) ? trimmed : "";
|
|
151
|
+
};
|
|
152
|
+
var isKnownAiEndpoint = (value) => KNOWN_AI_ENDPOINTS.has(normalizeAiEndpoint(value));
|
|
153
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
154
|
+
0 && (module.exports = {
|
|
155
|
+
AI_CUSTOM_ENDPOINT_VALUE,
|
|
156
|
+
AI_ENDPOINT_OPTIONS,
|
|
157
|
+
isKnownAiEndpoint,
|
|
158
|
+
normalizeAiEndpoint
|
|
159
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type AiResponseLanguageOption = {
|
|
2
|
+
label: string;
|
|
3
|
+
value: string;
|
|
4
|
+
promptName: string;
|
|
5
|
+
};
|
|
6
|
+
declare const AI_RESPONSE_LANGUAGE_OPTIONS: AiResponseLanguageOption[];
|
|
7
|
+
declare const DEFAULT_AI_RESPONSE_LANGUAGE: string;
|
|
8
|
+
declare const normalizeAiResponseLanguage: (value: unknown) => string;
|
|
9
|
+
declare const getAiResponseLanguagePromptName: (value: unknown) => string;
|
|
10
|
+
|
|
11
|
+
export { AI_RESPONSE_LANGUAGE_OPTIONS, type AiResponseLanguageOption, DEFAULT_AI_RESPONSE_LANGUAGE, getAiResponseLanguagePromptName, normalizeAiResponseLanguage };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type AiResponseLanguageOption = {
|
|
2
|
+
label: string;
|
|
3
|
+
value: string;
|
|
4
|
+
promptName: string;
|
|
5
|
+
};
|
|
6
|
+
declare const AI_RESPONSE_LANGUAGE_OPTIONS: AiResponseLanguageOption[];
|
|
7
|
+
declare const DEFAULT_AI_RESPONSE_LANGUAGE: string;
|
|
8
|
+
declare const normalizeAiResponseLanguage: (value: unknown) => string;
|
|
9
|
+
declare const getAiResponseLanguagePromptName: (value: unknown) => string;
|
|
10
|
+
|
|
11
|
+
export { AI_RESPONSE_LANGUAGE_OPTIONS, type AiResponseLanguageOption, DEFAULT_AI_RESPONSE_LANGUAGE, getAiResponseLanguagePromptName, normalizeAiResponseLanguage };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/aiLanguages.ts
|
|
21
|
+
var aiLanguages_exports = {};
|
|
22
|
+
__export(aiLanguages_exports, {
|
|
23
|
+
AI_RESPONSE_LANGUAGE_OPTIONS: () => AI_RESPONSE_LANGUAGE_OPTIONS,
|
|
24
|
+
DEFAULT_AI_RESPONSE_LANGUAGE: () => DEFAULT_AI_RESPONSE_LANGUAGE,
|
|
25
|
+
getAiResponseLanguagePromptName: () => getAiResponseLanguagePromptName,
|
|
26
|
+
normalizeAiResponseLanguage: () => normalizeAiResponseLanguage
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(aiLanguages_exports);
|
|
29
|
+
var AI_RESPONSE_LANGUAGE_OPTIONS = [
|
|
30
|
+
{ label: "English", value: "en", promptName: "English" },
|
|
31
|
+
{ label: "Chinese", value: "zh", promptName: "Chinese" },
|
|
32
|
+
{ label: "Hindi", value: "hi", promptName: "Hindi" },
|
|
33
|
+
{ label: "Spanish", value: "es", promptName: "Spanish" },
|
|
34
|
+
{ label: "French", value: "fr", promptName: "French" },
|
|
35
|
+
{ label: "Arabic", value: "ar", promptName: "Arabic" },
|
|
36
|
+
{ label: "Bengali", value: "bn", promptName: "Bengali" },
|
|
37
|
+
{ label: "Portuguese", value: "pt", promptName: "Portuguese" },
|
|
38
|
+
{ label: "Russian", value: "ru", promptName: "Russian" },
|
|
39
|
+
{ label: "Urdu", value: "ur", promptName: "Urdu" },
|
|
40
|
+
{ label: "Indonesian", value: "id", promptName: "Indonesian" },
|
|
41
|
+
{ label: "German", value: "de", promptName: "German" },
|
|
42
|
+
{ label: "Japanese", value: "ja", promptName: "Japanese" },
|
|
43
|
+
{ label: "Swahili", value: "sw", promptName: "Swahili" },
|
|
44
|
+
{ label: "Marathi", value: "mr", promptName: "Marathi" },
|
|
45
|
+
{ label: "Telugu", value: "te", promptName: "Telugu" },
|
|
46
|
+
{ label: "Turkish", value: "tr", promptName: "Turkish" },
|
|
47
|
+
{ label: "Tamil", value: "ta", promptName: "Tamil" },
|
|
48
|
+
{ label: "Vietnamese", value: "vi", promptName: "Vietnamese" },
|
|
49
|
+
{ label: "Korean", value: "ko", promptName: "Korean" }
|
|
50
|
+
];
|
|
51
|
+
var KNOWN_AI_RESPONSE_LANGUAGES = new Set(
|
|
52
|
+
AI_RESPONSE_LANGUAGE_OPTIONS.map((option) => option.value)
|
|
53
|
+
);
|
|
54
|
+
var DEFAULT_AI_RESPONSE_LANGUAGE = AI_RESPONSE_LANGUAGE_OPTIONS[0].value;
|
|
55
|
+
var normalizeAiResponseLanguage = (value) => {
|
|
56
|
+
if (typeof value !== "string") {
|
|
57
|
+
return DEFAULT_AI_RESPONSE_LANGUAGE;
|
|
58
|
+
}
|
|
59
|
+
const trimmed = value.trim().toLowerCase();
|
|
60
|
+
return KNOWN_AI_RESPONSE_LANGUAGES.has(trimmed) ? trimmed : DEFAULT_AI_RESPONSE_LANGUAGE;
|
|
61
|
+
};
|
|
62
|
+
var getAiResponseLanguagePromptName = (value) => AI_RESPONSE_LANGUAGE_OPTIONS.find(
|
|
63
|
+
(option) => option.value === normalizeAiResponseLanguage(value)
|
|
64
|
+
)?.promptName ?? AI_RESPONSE_LANGUAGE_OPTIONS[0].promptName;
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
AI_RESPONSE_LANGUAGE_OPTIONS,
|
|
68
|
+
DEFAULT_AI_RESPONSE_LANGUAGE,
|
|
69
|
+
getAiResponseLanguagePromptName,
|
|
70
|
+
normalizeAiResponseLanguage
|
|
71
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AI_RESPONSE_LANGUAGE_OPTIONS,
|
|
3
|
+
DEFAULT_AI_RESPONSE_LANGUAGE,
|
|
4
|
+
getAiResponseLanguagePromptName,
|
|
5
|
+
normalizeAiResponseLanguage
|
|
6
|
+
} from "./chunk-CCC7DX2T.mjs";
|
|
7
|
+
export {
|
|
8
|
+
AI_RESPONSE_LANGUAGE_OPTIONS,
|
|
9
|
+
DEFAULT_AI_RESPONSE_LANGUAGE,
|
|
10
|
+
getAiResponseLanguagePromptName,
|
|
11
|
+
normalizeAiResponseLanguage
|
|
12
|
+
};
|