@exulu/backend 5.5.0 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-ZWFL6YUH.js → chunk-SJNP75II.js} +112 -5
- package/dist/{convert-exulu-tools-to-ai-sdk-tools-C5LYP4UN.js → convert-exulu-tools-to-ai-sdk-tools-7TYZVHEQ.js} +1 -1
- package/dist/index.cjs +1771 -550
- package/dist/index.js +1474 -378
- package/ee/queues/import-queue.ts +27 -0
- package/ee/queues/prune-job-results.test.ts +105 -1
- package/ee/queues/prune-job-results.ts +85 -9
- package/ee/queues/queues.ts +1 -0
- package/ee/workers.ts +186 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -162,11 +162,11 @@ async function postgresClient() {
|
|
|
162
162
|
// Log pool events to help debug connection issues
|
|
163
163
|
afterCreate: (conn, done) => {
|
|
164
164
|
console.log("[EXULU] New database connection created");
|
|
165
|
-
conn.query("SET statement_timeout = 1800000; SET hnsw.ef_search = 20", (
|
|
166
|
-
if (
|
|
167
|
-
console.error("[EXULU] Error setting connection parameters:",
|
|
165
|
+
conn.query("SET statement_timeout = 1800000; SET hnsw.ef_search = 20", (err4) => {
|
|
166
|
+
if (err4) {
|
|
167
|
+
console.error("[EXULU] Error setting connection parameters:", err4);
|
|
168
168
|
}
|
|
169
|
-
done(
|
|
169
|
+
done(err4, conn);
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
172
|
}
|
|
@@ -525,7 +525,7 @@ function sanitizeMetadata(metadata) {
|
|
|
525
525
|
}
|
|
526
526
|
return sanitized;
|
|
527
527
|
}
|
|
528
|
-
var import_express, import_client_s3, import_s3_request_presigner, import_client_sts, import_node_crypto, expiresIn, s3Client, getPresignedUrl, addGeneralPrefixToKey, addUserPrefixToKey, addBucketPrefixToKey, uploadFile, listS3ObjectsByPrefix, copyS3Object, getS3ObjectContent, getS3ObjectEtag, getS3ObjectBytes, deleteS3Object, getS3SignedUploadUrl, createUppyRoutes;
|
|
528
|
+
var import_express, import_client_s3, import_s3_request_presigner, import_client_sts, import_node_crypto, expiresIn, s3Client, getPresignedUrl, addGeneralPrefixToKey, addUserPrefixToKey, addBucketPrefixToKey, uploadFile, listS3ObjectsByPrefix, copyS3Object, getS3ObjectContent, getS3ObjectStream, getS3ObjectEtag, getS3ObjectBytes, deleteS3Object, getS3SignedUploadUrl, createUppyRoutes;
|
|
529
529
|
var init_uppy = __esm({
|
|
530
530
|
"src/uppy/index.ts"() {
|
|
531
531
|
"use strict";
|
|
@@ -684,6 +684,19 @@ var init_uppy = __esm({
|
|
|
684
684
|
}
|
|
685
685
|
return response.Body.transformToString("utf-8");
|
|
686
686
|
};
|
|
687
|
+
getS3ObjectStream = async (key, config) => {
|
|
688
|
+
if (!config.fileUploads) {
|
|
689
|
+
throw new Error("File uploads are not configured");
|
|
690
|
+
}
|
|
691
|
+
const client2 = getS3Client(config);
|
|
692
|
+
const bucket = config.fileUploads.s3Bucket;
|
|
693
|
+
const command = new import_client_s3.GetObjectCommand({ Bucket: bucket, Key: key });
|
|
694
|
+
const response = await client2.send(command);
|
|
695
|
+
if (!response.Body) {
|
|
696
|
+
throw new Error(`Empty body for S3 key: ${key}`);
|
|
697
|
+
}
|
|
698
|
+
return response.Body;
|
|
699
|
+
};
|
|
687
700
|
getS3ObjectEtag = async (key, config) => {
|
|
688
701
|
if (!config.fileUploads) {
|
|
689
702
|
throw new Error("File uploads are not configured");
|
|
@@ -866,8 +879,8 @@ var init_uppy = __esm({
|
|
|
866
879
|
const url = await getPresignedUrl(bucket, key, config);
|
|
867
880
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
868
881
|
res.json({ url, method: "GET", expiresIn });
|
|
869
|
-
} catch (
|
|
870
|
-
next(
|
|
882
|
+
} catch (err4) {
|
|
883
|
+
next(err4);
|
|
871
884
|
}
|
|
872
885
|
});
|
|
873
886
|
app.post("/s3/object", async (req, res) => {
|
|
@@ -1135,9 +1148,9 @@ var init_uppy = __esm({
|
|
|
1135
1148
|
Metadata: sanitizeMetadata(metadata)
|
|
1136
1149
|
};
|
|
1137
1150
|
const command = new import_client_s3.CreateMultipartUploadCommand(params);
|
|
1138
|
-
return client2.send(command, (
|
|
1139
|
-
if (
|
|
1140
|
-
next(
|
|
1151
|
+
return client2.send(command, (err4, data) => {
|
|
1152
|
+
if (err4) {
|
|
1153
|
+
next(err4);
|
|
1141
1154
|
return;
|
|
1142
1155
|
}
|
|
1143
1156
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
@@ -1207,9 +1220,9 @@ var init_uppy = __esm({
|
|
|
1207
1220
|
UploadId: uploadId,
|
|
1208
1221
|
PartNumberMarker: startAt
|
|
1209
1222
|
}),
|
|
1210
|
-
(
|
|
1211
|
-
if (
|
|
1212
|
-
next(
|
|
1223
|
+
(err4, data) => {
|
|
1224
|
+
if (err4) {
|
|
1225
|
+
next(err4);
|
|
1213
1226
|
return;
|
|
1214
1227
|
}
|
|
1215
1228
|
parts.push(...data?.Parts ?? []);
|
|
@@ -1251,9 +1264,9 @@ var init_uppy = __esm({
|
|
|
1251
1264
|
Parts: parts
|
|
1252
1265
|
}
|
|
1253
1266
|
}),
|
|
1254
|
-
(
|
|
1255
|
-
if (
|
|
1256
|
-
next(
|
|
1267
|
+
(err4, data) => {
|
|
1268
|
+
if (err4) {
|
|
1269
|
+
next(err4);
|
|
1257
1270
|
return;
|
|
1258
1271
|
}
|
|
1259
1272
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
@@ -1282,9 +1295,9 @@ var init_uppy = __esm({
|
|
|
1282
1295
|
Key: key,
|
|
1283
1296
|
UploadId: uploadId
|
|
1284
1297
|
}),
|
|
1285
|
-
(
|
|
1286
|
-
if (
|
|
1287
|
-
next(
|
|
1298
|
+
(err4) => {
|
|
1299
|
+
if (err4) {
|
|
1300
|
+
next(err4);
|
|
1288
1301
|
return;
|
|
1289
1302
|
}
|
|
1290
1303
|
res.json({
|
|
@@ -2224,8 +2237,8 @@ var init_supervisor = __esm({
|
|
|
2224
2237
|
pollHealth(cfg.host, cfg.port).then(() => "ready"),
|
|
2225
2238
|
exitPromise.then((code2) => ({ exited: code2 }))
|
|
2226
2239
|
]);
|
|
2227
|
-
} catch (
|
|
2228
|
-
log2(`Readiness probe failed: ${
|
|
2240
|
+
} catch (err4) {
|
|
2241
|
+
log2(`Readiness probe failed: ${err4.message}`);
|
|
2229
2242
|
try {
|
|
2230
2243
|
internal.child?.kill("SIGTERM");
|
|
2231
2244
|
} catch {
|
|
@@ -2322,9 +2335,9 @@ var init_supervisor = __esm({
|
|
|
2322
2335
|
let res;
|
|
2323
2336
|
try {
|
|
2324
2337
|
res = await fetch(url, { method: "GET", headers: remote ? authHeaders : {} });
|
|
2325
|
-
} catch (
|
|
2338
|
+
} catch (err4) {
|
|
2326
2339
|
throw new Error(
|
|
2327
|
-
`LiteLLM proxy not reachable at ${url} (is the Exulu server process running?): ${
|
|
2340
|
+
`LiteLLM proxy not reachable at ${url} (is the Exulu server process running?): ${err4.message}`
|
|
2328
2341
|
);
|
|
2329
2342
|
}
|
|
2330
2343
|
if (!res.ok) {
|
|
@@ -2499,8 +2512,8 @@ function createTaggedFetch(tags) {
|
|
|
2499
2512
|
headers: stripContentLengthHeader(init.headers)
|
|
2500
2513
|
};
|
|
2501
2514
|
return globalThis.fetch(input, nextInit);
|
|
2502
|
-
} catch (
|
|
2503
|
-
console.warn("[vertex-labels] label injection failed, forwarding unchanged",
|
|
2515
|
+
} catch (err4) {
|
|
2516
|
+
console.warn("[vertex-labels] label injection failed, forwarding unchanged", err4);
|
|
2504
2517
|
return globalThis.fetch(input, init);
|
|
2505
2518
|
}
|
|
2506
2519
|
};
|
|
@@ -2620,11 +2633,11 @@ async function tagInfo(names) {
|
|
|
2620
2633
|
let json;
|
|
2621
2634
|
try {
|
|
2622
2635
|
json = await call("/tag/info", { names });
|
|
2623
|
-
} catch (
|
|
2624
|
-
if (
|
|
2636
|
+
} catch (err4) {
|
|
2637
|
+
if (err4 instanceof LiteLLMAdminError && /not found/i.test(err4.message)) {
|
|
2625
2638
|
return out;
|
|
2626
2639
|
}
|
|
2627
|
-
throw
|
|
2640
|
+
throw err4;
|
|
2628
2641
|
}
|
|
2629
2642
|
for (const name of names) {
|
|
2630
2643
|
const raw = json?.[name];
|
|
@@ -2838,8 +2851,8 @@ async function enrichSpendFromActivity(map) {
|
|
|
2838
2851
|
map[name].spend = spend;
|
|
2839
2852
|
}
|
|
2840
2853
|
}
|
|
2841
|
-
} catch (
|
|
2842
|
-
console.warn("[EXULU] enrichSpendFromActivity failed",
|
|
2854
|
+
} catch (err4) {
|
|
2855
|
+
console.warn("[EXULU] enrichSpendFromActivity failed", err4);
|
|
2843
2856
|
}
|
|
2844
2857
|
}
|
|
2845
2858
|
function isEnabled() {
|
|
@@ -2925,8 +2938,8 @@ async function getTagBudgetMap() {
|
|
|
2925
2938
|
await enrichSpendFromActivity(map);
|
|
2926
2939
|
tagMapCache = { expiry: Date.now() + TAG_MAP_TTL_MS, map };
|
|
2927
2940
|
return map;
|
|
2928
|
-
} catch (
|
|
2929
|
-
console.warn("[EXULU] getTagBudgetMap failed",
|
|
2941
|
+
} catch (err4) {
|
|
2942
|
+
console.warn("[EXULU] getTagBudgetMap failed", err4);
|
|
2930
2943
|
return {};
|
|
2931
2944
|
} finally {
|
|
2932
2945
|
tagMapInflight = void 0;
|
|
@@ -2957,8 +2970,8 @@ async function provisionDefaultUserBudget(userId) {
|
|
|
2957
2970
|
budget_duration: g.budget_duration
|
|
2958
2971
|
});
|
|
2959
2972
|
provisionCache.set(tag, Date.now() + PROVISION_TTL_MS);
|
|
2960
|
-
} catch (
|
|
2961
|
-
console.warn("[EXULU] ensureUserBudget failed",
|
|
2973
|
+
} catch (err4) {
|
|
2974
|
+
console.warn("[EXULU] ensureUserBudget failed", err4);
|
|
2962
2975
|
}
|
|
2963
2976
|
}
|
|
2964
2977
|
async function getUserBudgetView(userId) {
|
|
@@ -2988,8 +3001,8 @@ async function getUserBudgetView(userId) {
|
|
|
2988
3001
|
} : null;
|
|
2989
3002
|
readCache.set(tag, { expiry: Date.now() + READ_TTL_MS, view });
|
|
2990
3003
|
return view;
|
|
2991
|
-
} catch (
|
|
2992
|
-
console.warn("[EXULU] getUserBudgetView failed",
|
|
3004
|
+
} catch (err4) {
|
|
3005
|
+
console.warn("[EXULU] getUserBudgetView failed", err4);
|
|
2993
3006
|
return null;
|
|
2994
3007
|
}
|
|
2995
3008
|
}
|
|
@@ -3028,10 +3041,10 @@ async function resolveEmbedder(input) {
|
|
|
3028
3041
|
}
|
|
3029
3042
|
try {
|
|
3030
3043
|
await waitForLiteLLMReady();
|
|
3031
|
-
} catch (
|
|
3044
|
+
} catch (err4) {
|
|
3032
3045
|
throw new ResolveEmbedderError(
|
|
3033
3046
|
"LITELLM_NOT_READY",
|
|
3034
|
-
`LiteLLM is not ready: ${
|
|
3047
|
+
`LiteLLM is not ready: ${err4.message}`
|
|
3035
3048
|
);
|
|
3036
3049
|
}
|
|
3037
3050
|
const { baseUrl, authHeaders } = resolveLiteLLMTarget();
|
|
@@ -3585,10 +3598,10 @@ var init_embedder_settings = __esm({
|
|
|
3585
3598
|
model: model.trim(),
|
|
3586
3599
|
queue: typeof queue === "string" && queue.trim() ? queue.trim() : null
|
|
3587
3600
|
};
|
|
3588
|
-
} catch (
|
|
3601
|
+
} catch (err4) {
|
|
3589
3602
|
console.warn(
|
|
3590
3603
|
`[EXULU] Could not read the embedder setting for "${contextId}":`,
|
|
3591
|
-
|
|
3604
|
+
err4.message
|
|
3592
3605
|
);
|
|
3593
3606
|
return null;
|
|
3594
3607
|
}
|
|
@@ -3671,9 +3684,9 @@ var init_hydrate_embedders = __esm({
|
|
|
3671
3684
|
}
|
|
3672
3685
|
try {
|
|
3673
3686
|
modelInfo(info.databaseModel);
|
|
3674
|
-
} catch (
|
|
3687
|
+
} catch (err4) {
|
|
3675
3688
|
console.error(
|
|
3676
|
-
`[EXULU] Context "${context.id}" has a stored embedder "${info.databaseModel}" that is not a usable embedding model (${
|
|
3689
|
+
`[EXULU] Context "${context.id}" has a stored embedder "${info.databaseModel}" that is not a usable embedding model (${err4.message.split("\n")[0]}). Ignoring the override and falling back to the model declared in code${info.codeModel ? ` ("${info.codeModel}")` : " (none)"}.`
|
|
3677
3690
|
);
|
|
3678
3691
|
context.embedder = codeEmbedder;
|
|
3679
3692
|
continue;
|
|
@@ -3692,10 +3705,10 @@ var init_hydrate_embedders = __esm({
|
|
|
3692
3705
|
}
|
|
3693
3706
|
}
|
|
3694
3707
|
context.embedder = { model: info.databaseModel, queue };
|
|
3695
|
-
} catch (
|
|
3708
|
+
} catch (err4) {
|
|
3696
3709
|
console.error(
|
|
3697
3710
|
`[EXULU] Could not hydrate the embedder for context "${context.id}":`,
|
|
3698
|
-
|
|
3711
|
+
err4.message
|
|
3699
3712
|
);
|
|
3700
3713
|
}
|
|
3701
3714
|
}
|
|
@@ -4790,7 +4803,7 @@ CREATE TABLE IF NOT EXISTS user_credentials (
|
|
|
4790
4803
|
);
|
|
4791
4804
|
`;
|
|
4792
4805
|
}
|
|
4793
|
-
var agentMessagesSchema, agentSessionsSchema, skillsSchema, variablesSchema, projectsSchema, agentsSchema, modelsSchema, usersSchema, platformConfigurationsSchema, entityTypeSettingsSchema, promptLibrarySchema, promptFavoritesSchema, memoryUsagesSchema, memoryConflictsSchema, memoryJudgementsSchema, memoryConflictScansSchema, contextProjectionsSchema, contextMapTopicsSchema, transcriptionJobsSchema, imageGenerationsSchema, sharedArtifactsSchema, contextPresetsSchema, addCoreFields, otpSendAttemptsSchema, coreSchemas;
|
|
4806
|
+
var agentMessagesSchema, agentSessionsSchema, skillsSchema, variablesSchema, projectsSchema, agentsSchema, modelsSchema, usersSchema, platformConfigurationsSchema, entityTypeSettingsSchema, promptLibrarySchema, promptFavoritesSchema, memoryUsagesSchema, memoryConflictsSchema, memoryJudgementsSchema, memoryConflictScansSchema, contextProjectionsSchema, contextMapTopicsSchema, transcriptionJobsSchema, imageGenerationsSchema, sharedArtifactsSchema, contextPresetsSchema, contextFoldersSchema, addCoreFields, otpSendAttemptsSchema, coreSchemas;
|
|
4794
4807
|
var init_core_schema = __esm({
|
|
4795
4808
|
"src/postgres/core-schema.ts"() {
|
|
4796
4809
|
"use strict";
|
|
@@ -5745,6 +5758,58 @@ var init_core_schema = __esm({
|
|
|
5745
5758
|
}
|
|
5746
5759
|
]
|
|
5747
5760
|
};
|
|
5761
|
+
contextFoldersSchema = {
|
|
5762
|
+
type: "context_folders",
|
|
5763
|
+
name: {
|
|
5764
|
+
plural: "context_folders",
|
|
5765
|
+
singular: "context_folder"
|
|
5766
|
+
},
|
|
5767
|
+
RBAC: false,
|
|
5768
|
+
apiWrites: "super_admin",
|
|
5769
|
+
fields: [
|
|
5770
|
+
{
|
|
5771
|
+
// `index: true` is advisory here, not a DB index: init-exulu-db.ts's
|
|
5772
|
+
// mapType call for core tables only forwards `unique`, never `index`,
|
|
5773
|
+
// to knex. Kept on the field because it documents intent (and other,
|
|
5774
|
+
// non-core-table callers of mapType do read it) and the schema test
|
|
5775
|
+
// asserts it, but creating this table does not add a Postgres index.
|
|
5776
|
+
name: "name",
|
|
5777
|
+
type: "text",
|
|
5778
|
+
required: true,
|
|
5779
|
+
index: true
|
|
5780
|
+
},
|
|
5781
|
+
{
|
|
5782
|
+
name: "description",
|
|
5783
|
+
type: "text"
|
|
5784
|
+
},
|
|
5785
|
+
{
|
|
5786
|
+
name: "icon",
|
|
5787
|
+
type: "text"
|
|
5788
|
+
},
|
|
5789
|
+
{
|
|
5790
|
+
// `default: 0` is advisory here, not a DB default: map-types.ts's
|
|
5791
|
+
// json/number branches only call `.defaultTo(defaultValue)` when
|
|
5792
|
+
// defaultValue is truthy, and 0 is falsy, so no column default is ever
|
|
5793
|
+
// emitted for this field. New rows rely on the GraphQL input/resolver
|
|
5794
|
+
// defaulting sort_order, not a Postgres-level default.
|
|
5795
|
+
name: "sort_order",
|
|
5796
|
+
type: "number",
|
|
5797
|
+
default: 0
|
|
5798
|
+
},
|
|
5799
|
+
{
|
|
5800
|
+
// Unlike sort_order's `0`, "[]" is a truthy string, so map-types.ts's
|
|
5801
|
+
// json branch does emit `.defaultTo("[]")`: a CreateOne that omits
|
|
5802
|
+
// context_ids stores an empty array instead of NULL. That matters
|
|
5803
|
+
// because the generated GraphQL output type is JSON! (non-null) —
|
|
5804
|
+
// without this default a bare NULL would break context_foldersPagination
|
|
5805
|
+
// for every reader, not just the row that omitted the field.
|
|
5806
|
+
name: "context_ids",
|
|
5807
|
+
type: "json",
|
|
5808
|
+
required: true,
|
|
5809
|
+
default: "[]"
|
|
5810
|
+
}
|
|
5811
|
+
]
|
|
5812
|
+
};
|
|
5748
5813
|
addCoreFields = (schema7) => {
|
|
5749
5814
|
schema7.fields.forEach((field) => {
|
|
5750
5815
|
if (field.type === "file") {
|
|
@@ -5829,6 +5894,7 @@ var init_core_schema = __esm({
|
|
|
5829
5894
|
contextProjectionsSchema: () => addCoreFields(contextProjectionsSchema),
|
|
5830
5895
|
contextMapTopicsSchema: () => addCoreFields(contextMapTopicsSchema),
|
|
5831
5896
|
contextPresetsSchema: () => addCoreFields(contextPresetsSchema),
|
|
5897
|
+
contextFoldersSchema: () => addCoreFields(contextFoldersSchema),
|
|
5832
5898
|
sharedArtifactsSchema: () => addCoreFields(sharedArtifactsSchema),
|
|
5833
5899
|
transcriptionJobsSchema: () => addCoreFields(transcriptionJobsSchema),
|
|
5834
5900
|
imageGenerationsSchema: () => addCoreFields(imageGenerationsSchema),
|
|
@@ -5965,7 +6031,7 @@ var init_embedder_not_configured = __esm({
|
|
|
5965
6031
|
this.contextId = contextId;
|
|
5966
6032
|
}
|
|
5967
6033
|
};
|
|
5968
|
-
isEmbedderNotConfigured = (
|
|
6034
|
+
isEmbedderNotConfigured = (err4) => !!err4 && err4.name === "ContextEmbedderNotConfiguredError";
|
|
5969
6035
|
}
|
|
5970
6036
|
});
|
|
5971
6037
|
|
|
@@ -6006,8 +6072,8 @@ var init_config = __esm({
|
|
|
6006
6072
|
description: row.description || ""
|
|
6007
6073
|
});
|
|
6008
6074
|
}
|
|
6009
|
-
} catch (
|
|
6010
|
-
console.warn("[EXULU] Could not read entity_type_settings:",
|
|
6075
|
+
} catch (err4) {
|
|
6076
|
+
console.warn("[EXULU] Could not read entity_type_settings:", err4.message);
|
|
6011
6077
|
}
|
|
6012
6078
|
return Array.from(byName.values());
|
|
6013
6079
|
};
|
|
@@ -6036,10 +6102,10 @@ var init_config = __esm({
|
|
|
6036
6102
|
if (rows.length) {
|
|
6037
6103
|
await db2.from("entity_type_settings").insert(rows);
|
|
6038
6104
|
}
|
|
6039
|
-
} catch (
|
|
6105
|
+
} catch (err4) {
|
|
6040
6106
|
console.warn(
|
|
6041
6107
|
"[EXULU] Could not persist entity suggestions:",
|
|
6042
|
-
|
|
6108
|
+
err4.message
|
|
6043
6109
|
);
|
|
6044
6110
|
}
|
|
6045
6111
|
};
|
|
@@ -6059,8 +6125,8 @@ var init_config = __esm({
|
|
|
6059
6125
|
}
|
|
6060
6126
|
}
|
|
6061
6127
|
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
6062
|
-
} catch (
|
|
6063
|
-
console.warn("[EXULU] Could not read entity model setting:",
|
|
6128
|
+
} catch (err4) {
|
|
6129
|
+
console.warn("[EXULU] Could not read entity model setting:", err4.message);
|
|
6064
6130
|
return null;
|
|
6065
6131
|
}
|
|
6066
6132
|
};
|
|
@@ -6104,10 +6170,10 @@ async function resolveModel(input) {
|
|
|
6104
6170
|
}
|
|
6105
6171
|
try {
|
|
6106
6172
|
await waitForLiteLLMReady();
|
|
6107
|
-
} catch (
|
|
6173
|
+
} catch (err4) {
|
|
6108
6174
|
throw new ResolveModelError(
|
|
6109
6175
|
"LITELLM_NOT_READY",
|
|
6110
|
-
`LiteLLM is not ready: ${
|
|
6176
|
+
`LiteLLM is not ready: ${err4.message}`
|
|
6111
6177
|
);
|
|
6112
6178
|
}
|
|
6113
6179
|
if (user?.id) await provisionDefaultUserBudget(user.id);
|
|
@@ -6303,10 +6369,10 @@ ${c.content}`).join("\n\n");
|
|
|
6303
6369
|
rbacBypass: true
|
|
6304
6370
|
});
|
|
6305
6371
|
languageModel = resolved.languageModel;
|
|
6306
|
-
} catch (
|
|
6372
|
+
} catch (err4) {
|
|
6307
6373
|
console.error(
|
|
6308
6374
|
`[EXULU] Entity extraction skipped for context ${context.id}: could not resolve model ${modelId}:`,
|
|
6309
|
-
|
|
6375
|
+
err4.message
|
|
6310
6376
|
);
|
|
6311
6377
|
return empty;
|
|
6312
6378
|
}
|
|
@@ -6371,10 +6437,10 @@ ${c.content}`).join("\n\n");
|
|
|
6371
6437
|
});
|
|
6372
6438
|
}
|
|
6373
6439
|
}
|
|
6374
|
-
} catch (
|
|
6440
|
+
} catch (err4) {
|
|
6375
6441
|
console.error(
|
|
6376
6442
|
`[EXULU] Entity extraction batch failed for context ${context.id} (continuing):`,
|
|
6377
|
-
|
|
6443
|
+
err4.message
|
|
6378
6444
|
);
|
|
6379
6445
|
}
|
|
6380
6446
|
}
|
|
@@ -6763,8 +6829,8 @@ var init_entities = __esm({
|
|
|
6763
6829
|
try {
|
|
6764
6830
|
if (!await chunkEntitiesTableExists(context)) return [];
|
|
6765
6831
|
return await getEntityIdsForItem(context, itemId);
|
|
6766
|
-
} catch (
|
|
6767
|
-
console.error("[EXULU] captureEntitiesBeforeReembed failed (continuing):",
|
|
6832
|
+
} catch (err4) {
|
|
6833
|
+
console.error("[EXULU] captureEntitiesBeforeReembed failed (continuing):", err4.message);
|
|
6768
6834
|
return [];
|
|
6769
6835
|
}
|
|
6770
6836
|
};
|
|
@@ -6794,10 +6860,10 @@ var init_entities = __esm({
|
|
|
6794
6860
|
`[EXULU] Entity ingestion complete for item ${itemId} in context ${context.id}: ${mentions.length} mentions.`
|
|
6795
6861
|
);
|
|
6796
6862
|
return mentions.length;
|
|
6797
|
-
} catch (
|
|
6863
|
+
} catch (err4) {
|
|
6798
6864
|
console.error(
|
|
6799
6865
|
`[EXULU] Entity ingestion failed for item ${itemId} in context ${context.id} (non-fatal):`,
|
|
6800
|
-
|
|
6866
|
+
err4.message
|
|
6801
6867
|
);
|
|
6802
6868
|
return 0;
|
|
6803
6869
|
}
|
|
@@ -7200,8 +7266,8 @@ var init_vector_search = __esm({
|
|
|
7200
7266
|
return { r, score: base + boost };
|
|
7201
7267
|
}).sort((a, b) => b.score - a.score).map((x) => x.r);
|
|
7202
7268
|
}
|
|
7203
|
-
} catch (
|
|
7204
|
-
console.error("[EXULU] Entity boost step failed (continuing):",
|
|
7269
|
+
} catch (err4) {
|
|
7270
|
+
console.error("[EXULU] Entity boost step failed (continuing):", err4.message);
|
|
7205
7271
|
}
|
|
7206
7272
|
}
|
|
7207
7273
|
results = results.slice(0, limit);
|
|
@@ -7228,8 +7294,8 @@ var init_vector_search = __esm({
|
|
|
7228
7294
|
results = results.map((r) => ({ ...r, chunk_entities: entMap.get(r.chunk_id) || [] }));
|
|
7229
7295
|
}
|
|
7230
7296
|
entityInsights = queryEntities.length ? await buildEntityInsights(context, queryEntities, finalIds) : { queryEntities: [] };
|
|
7231
|
-
} catch (
|
|
7232
|
-
console.error("[EXULU] Entity insights step failed (continuing):",
|
|
7297
|
+
} catch (err4) {
|
|
7298
|
+
console.error("[EXULU] Entity insights step failed (continuing):", err4.message);
|
|
7233
7299
|
}
|
|
7234
7300
|
}
|
|
7235
7301
|
await updateStatistic({
|
|
@@ -7394,22 +7460,61 @@ async function maybePruneJobResults(db2) {
|
|
|
7394
7460
|
sinceLastPrune = 0;
|
|
7395
7461
|
pruning = true;
|
|
7396
7462
|
try {
|
|
7397
|
-
|
|
7463
|
+
await pruneGenericJobResults(db2);
|
|
7464
|
+
await pruneImportJobResults(db2);
|
|
7465
|
+
} finally {
|
|
7466
|
+
pruning = false;
|
|
7467
|
+
}
|
|
7468
|
+
}
|
|
7469
|
+
function excludeImportType(builder) {
|
|
7470
|
+
return builder.where(function() {
|
|
7471
|
+
this.whereNot({ type: "import" }).orWhereNull("type");
|
|
7472
|
+
});
|
|
7473
|
+
}
|
|
7474
|
+
async function pruneGenericJobResults(db2) {
|
|
7475
|
+
try {
|
|
7476
|
+
const boundary = await excludeImportType(
|
|
7477
|
+
db2("job_results").whereIn("state", TERMINAL_JOB_STATES)
|
|
7478
|
+
).orderBy("createdAt", "desc").offset(MAX_TERMINAL).limit(1).first();
|
|
7398
7479
|
if (boundary?.createdAt) {
|
|
7399
|
-
const deleted = await
|
|
7480
|
+
const deleted = await excludeImportType(
|
|
7481
|
+
db2("job_results").whereIn("state", TERMINAL_JOB_STATES)
|
|
7482
|
+
).where("createdAt", "<=", boundary.createdAt).del();
|
|
7400
7483
|
if (deleted) {
|
|
7401
7484
|
console.log(
|
|
7402
7485
|
`[EXULU] pruned ${deleted} terminal job_results rows (cap ${MAX_TERMINAL}).`
|
|
7403
7486
|
);
|
|
7404
7487
|
}
|
|
7405
7488
|
}
|
|
7406
|
-
} catch (
|
|
7407
|
-
console.error("[EXULU] job_results prune failed",
|
|
7408
|
-
}
|
|
7409
|
-
|
|
7489
|
+
} catch (err4) {
|
|
7490
|
+
console.error("[EXULU] job_results prune failed", err4);
|
|
7491
|
+
}
|
|
7492
|
+
}
|
|
7493
|
+
async function pruneImportJobResults(db2) {
|
|
7494
|
+
if (db2.client?.config?.client !== "pg") return;
|
|
7495
|
+
try {
|
|
7496
|
+
const statePlaceholders = TERMINAL_JOB_STATES.map(() => "?").join(", ");
|
|
7497
|
+
const deleted = await db2("job_results").where({ type: "import" }).whereRaw(
|
|
7498
|
+
`id in (
|
|
7499
|
+
select id from (
|
|
7500
|
+
select id, row_number() over (partition by context order by "createdAt" desc) as rn
|
|
7501
|
+
from job_results
|
|
7502
|
+
where type = 'import' and state in (${statePlaceholders})
|
|
7503
|
+
) ranked
|
|
7504
|
+
where rn > ?
|
|
7505
|
+
)`,
|
|
7506
|
+
[...TERMINAL_JOB_STATES, MAX_IMPORT_PER_CONTEXT]
|
|
7507
|
+
).del();
|
|
7508
|
+
if (deleted) {
|
|
7509
|
+
console.log(
|
|
7510
|
+
`[EXULU] pruned ${deleted} terminal import job_results rows (cap ${MAX_IMPORT_PER_CONTEXT}/context).`
|
|
7511
|
+
);
|
|
7512
|
+
}
|
|
7513
|
+
} catch (err4) {
|
|
7514
|
+
console.error("[EXULU] import job_results prune failed", err4);
|
|
7410
7515
|
}
|
|
7411
7516
|
}
|
|
7412
|
-
var MAX_TERMINAL, PRUNE_EVERY, sinceLastPrune, pruning;
|
|
7517
|
+
var MAX_TERMINAL, PRUNE_EVERY, MAX_IMPORT_PER_CONTEXT, sinceLastPrune, pruning;
|
|
7413
7518
|
var init_prune_job_results = __esm({
|
|
7414
7519
|
"ee/queues/prune-job-results.ts"() {
|
|
7415
7520
|
"use strict";
|
|
@@ -7417,6 +7522,7 @@ var init_prune_job_results = __esm({
|
|
|
7417
7522
|
init_jobs();
|
|
7418
7523
|
MAX_TERMINAL = 1e4;
|
|
7419
7524
|
PRUNE_EVERY = 100;
|
|
7525
|
+
MAX_IMPORT_PER_CONTEXT = 200;
|
|
7420
7526
|
sinceLastPrune = 0;
|
|
7421
7527
|
pruning = false;
|
|
7422
7528
|
}
|
|
@@ -7500,8 +7606,8 @@ var init_decorator = __esm({
|
|
|
7500
7606
|
metadata: {}
|
|
7501
7607
|
});
|
|
7502
7608
|
void maybePruneJobResults(db2);
|
|
7503
|
-
} catch (
|
|
7504
|
-
console.error("[EXULU] enqueue job_results insert failed",
|
|
7609
|
+
} catch (err4) {
|
|
7610
|
+
console.error("[EXULU] enqueue job_results insert failed", err4);
|
|
7505
7611
|
}
|
|
7506
7612
|
}
|
|
7507
7613
|
const job = await queue.add(`${embedder || workflow || processor || evaluation}`, jobData, {
|
|
@@ -9128,11 +9234,11 @@ var init_session_items_retrieval_tool = __esm({
|
|
|
9128
9234
|
limit: 10,
|
|
9129
9235
|
page: 1
|
|
9130
9236
|
});
|
|
9131
|
-
} catch (
|
|
9132
|
-
if (isEmbedderNotConfigured(
|
|
9133
|
-
return
|
|
9237
|
+
} catch (err4) {
|
|
9238
|
+
if (isEmbedderNotConfigured(err4)) {
|
|
9239
|
+
return err4.message;
|
|
9134
9240
|
}
|
|
9135
|
-
throw
|
|
9241
|
+
throw err4;
|
|
9136
9242
|
}
|
|
9137
9243
|
})
|
|
9138
9244
|
);
|
|
@@ -11195,10 +11301,10 @@ var init_os_environ_names = __esm({
|
|
|
11195
11301
|
try {
|
|
11196
11302
|
if (!(0, import_node_fs5.existsSync)(configPath)) return [];
|
|
11197
11303
|
return parseOsEnvironNames((0, import_node_fs5.readFileSync)(configPath, "utf8"));
|
|
11198
|
-
} catch (
|
|
11304
|
+
} catch (err4) {
|
|
11199
11305
|
console.warn(
|
|
11200
11306
|
`[SKILLS] Could not read LiteLLM config at ${configPath} to collect os.environ/ credential names; the skill environment falls back to the static secret inventory.`,
|
|
11201
|
-
|
|
11307
|
+
err4
|
|
11202
11308
|
);
|
|
11203
11309
|
return [];
|
|
11204
11310
|
}
|
|
@@ -11623,7 +11729,7 @@ var init_tool_call = __esm({
|
|
|
11623
11729
|
ctx.tool.id
|
|
11624
11730
|
);
|
|
11625
11731
|
}
|
|
11626
|
-
const
|
|
11732
|
+
const err4 = ctx.error;
|
|
11627
11733
|
return {
|
|
11628
11734
|
v: 1,
|
|
11629
11735
|
ts: nowIso(),
|
|
@@ -11645,7 +11751,7 @@ var init_tool_call = __esm({
|
|
|
11645
11751
|
...ctx.client ? { client: ctx.client } : {},
|
|
11646
11752
|
...credential ? { credential } : {},
|
|
11647
11753
|
status,
|
|
11648
|
-
...status === "error" ? { error: { name:
|
|
11754
|
+
...status === "error" ? { error: { name: err4?.name, message: String(err4?.message ?? err4 ?? "unknown error") } } : {},
|
|
11649
11755
|
data,
|
|
11650
11756
|
durationMs: ctx.durationMs,
|
|
11651
11757
|
...Object.keys(truncated).length ? { truncated } : {}
|
|
@@ -12042,8 +12148,8 @@ function probeSandboxSupport() {
|
|
|
12042
12148
|
child.stderr.on("data", (chunk2) => {
|
|
12043
12149
|
stderr += chunk2.toString();
|
|
12044
12150
|
});
|
|
12045
|
-
child.on("error", (
|
|
12046
|
-
resolve8({ canSandbox: false, reason: `bwrap not executable: ${
|
|
12151
|
+
child.on("error", (err4) => {
|
|
12152
|
+
resolve8({ canSandbox: false, reason: `bwrap not executable: ${err4.message}` });
|
|
12047
12153
|
});
|
|
12048
12154
|
child.on("exit", (code) => {
|
|
12049
12155
|
if (code === 0) resolve8({ canSandbox: true });
|
|
@@ -12118,10 +12224,10 @@ async function restoreArtifactsFromS3(sessionDir, sessionId, userId, config, opt
|
|
|
12118
12224
|
let objects;
|
|
12119
12225
|
try {
|
|
12120
12226
|
objects = await listS3ObjectsByPrefix(userPrefix, config);
|
|
12121
|
-
} catch (
|
|
12227
|
+
} catch (err4) {
|
|
12122
12228
|
console.error(
|
|
12123
12229
|
`[SKILLS] Failed to list S3 artifacts for session ${sessionId} (user ${userId}); proceeding with empty session dir.`,
|
|
12124
|
-
|
|
12230
|
+
err4
|
|
12125
12231
|
);
|
|
12126
12232
|
return;
|
|
12127
12233
|
}
|
|
@@ -12148,10 +12254,10 @@ async function restoreArtifactsFromS3(sessionDir, sessionId, userId, config, opt
|
|
|
12148
12254
|
const bytes = await getS3ObjectBytes(obj.key, config);
|
|
12149
12255
|
await (0, import_promises2.mkdir)((0, import_node_path5.dirname)(localPath), { recursive: true });
|
|
12150
12256
|
await (0, import_promises2.writeFile)(localPath, bytes);
|
|
12151
|
-
} catch (
|
|
12257
|
+
} catch (err4) {
|
|
12152
12258
|
console.error(
|
|
12153
12259
|
`[SKILLS] Failed to restore artifact ${obj.key} -> ${localPath}; continuing.`,
|
|
12154
|
-
|
|
12260
|
+
err4
|
|
12155
12261
|
);
|
|
12156
12262
|
}
|
|
12157
12263
|
}
|
|
@@ -12181,8 +12287,8 @@ async function resolvePythonVenvPath() {
|
|
|
12181
12287
|
try {
|
|
12182
12288
|
const { getPythonVenvPath: getPythonVenvPath2 } = await Promise.resolve().then(() => (init_python_setup(), python_setup_exports));
|
|
12183
12289
|
return getPythonVenvPath2();
|
|
12184
|
-
} catch (
|
|
12185
|
-
console.warn("[SKILLS] Could not resolve the Python venv for the session sandbox; skill scripts fall back to the system python.",
|
|
12290
|
+
} catch (err4) {
|
|
12291
|
+
console.warn("[SKILLS] Could not resolve the Python venv for the session sandbox; skill scripts fall back to the system python.", err4);
|
|
12186
12292
|
return void 0;
|
|
12187
12293
|
}
|
|
12188
12294
|
}
|
|
@@ -12215,8 +12321,8 @@ async function createSessionSandbox(sessionId, skills, config, userId, agent) {
|
|
|
12215
12321
|
if (userId && config.fileUploads) {
|
|
12216
12322
|
try {
|
|
12217
12323
|
await restoreArtifactsFromS3(cached.handle.sessionDir, sessionId, userId, config, { onlyMissing: true });
|
|
12218
|
-
} catch (
|
|
12219
|
-
console.error(`[SKILLS] Failed to re-sync S3 session files for session ${sessionId}; continuing.`,
|
|
12324
|
+
} catch (err4) {
|
|
12325
|
+
console.error(`[SKILLS] Failed to re-sync S3 session files for session ${sessionId}; continuing.`, err4);
|
|
12220
12326
|
}
|
|
12221
12327
|
}
|
|
12222
12328
|
return cached.handle;
|
|
@@ -12305,10 +12411,10 @@ Probe error: ${probe.reason ?? "(no detail)"}`
|
|
|
12305
12411
|
const loaded = await getAllExuluVariables();
|
|
12306
12412
|
configuredVariables = loaded.granted;
|
|
12307
12413
|
withheldNames = loaded.withheldNames;
|
|
12308
|
-
} catch (
|
|
12414
|
+
} catch (err4) {
|
|
12309
12415
|
console.error(
|
|
12310
12416
|
`[SKILLS] Failed to load configured variables for session ${sessionId}; bash env will not include them.`,
|
|
12311
|
-
|
|
12417
|
+
err4
|
|
12312
12418
|
);
|
|
12313
12419
|
}
|
|
12314
12420
|
const { env: sandboxedExecEnv, strippedSecretNames, grantedNames, skippedNames } = buildSkillEnv({
|
|
@@ -12341,10 +12447,10 @@ Probe error: ${probe.reason ?? "(no detail)"}`
|
|
|
12341
12447
|
degradedSandbox: useDirectExec
|
|
12342
12448
|
})
|
|
12343
12449
|
);
|
|
12344
|
-
} catch (
|
|
12450
|
+
} catch (err4) {
|
|
12345
12451
|
console.error(
|
|
12346
12452
|
`[SKILLS] audit: skill-sandbox emit failed for session ${sessionId}; continuing.`,
|
|
12347
|
-
|
|
12453
|
+
err4
|
|
12348
12454
|
);
|
|
12349
12455
|
}
|
|
12350
12456
|
}
|
|
@@ -12417,17 +12523,17 @@ Probe error: ${probe.reason ?? "(no detail)"}`
|
|
|
12417
12523
|
const keyOnly = fullKey.slice(slashIdx + 1);
|
|
12418
12524
|
try {
|
|
12419
12525
|
out.url = await getPresignedUrl(bucket, keyOnly, config);
|
|
12420
|
-
} catch (
|
|
12526
|
+
} catch (err4) {
|
|
12421
12527
|
console.error(
|
|
12422
12528
|
`[SKILLS] Upload succeeded but presign failed for ${fullKey}; continuing without URL.`,
|
|
12423
|
-
|
|
12529
|
+
err4
|
|
12424
12530
|
);
|
|
12425
12531
|
}
|
|
12426
12532
|
}
|
|
12427
|
-
} catch (
|
|
12533
|
+
} catch (err4) {
|
|
12428
12534
|
console.error(
|
|
12429
12535
|
`[SKILLS] Failed to upload artifact ${s3Key} for session ${sessionId} (user ${userId}); continuing.`,
|
|
12430
|
-
|
|
12536
|
+
err4
|
|
12431
12537
|
);
|
|
12432
12538
|
}
|
|
12433
12539
|
return out;
|
|
@@ -12563,10 +12669,10 @@ Probe error: ${probe.reason ?? "(no detail)"}`
|
|
|
12563
12669
|
key: persisted.key,
|
|
12564
12670
|
url: persisted.url
|
|
12565
12671
|
});
|
|
12566
|
-
} catch (
|
|
12672
|
+
} catch (err4) {
|
|
12567
12673
|
console.error(
|
|
12568
12674
|
`[SKILLS] Failed to mirror bash-produced artifact ${path4} to S3; continuing.`,
|
|
12569
|
-
|
|
12675
|
+
err4
|
|
12570
12676
|
);
|
|
12571
12677
|
}
|
|
12572
12678
|
}
|
|
@@ -12644,10 +12750,10 @@ var init_create_sandbox = __esm({
|
|
|
12644
12750
|
try {
|
|
12645
12751
|
const bytes = import_crypto_js3.default.AES.decrypt(value, process.env.NEXTAUTH_SECRET);
|
|
12646
12752
|
value = bytes.toString(import_crypto_js3.default.enc.Utf8);
|
|
12647
|
-
} catch (
|
|
12753
|
+
} catch (err4) {
|
|
12648
12754
|
console.error(
|
|
12649
12755
|
`[VARIABLES] Failed to decrypt variable "${row.name}"; skipping.`,
|
|
12650
|
-
|
|
12756
|
+
err4
|
|
12651
12757
|
);
|
|
12652
12758
|
continue;
|
|
12653
12759
|
}
|
|
@@ -12843,8 +12949,8 @@ var init_tool_output_offload = __esm({
|
|
|
12843
12949
|
ctx.user?.id
|
|
12844
12950
|
);
|
|
12845
12951
|
return name;
|
|
12846
|
-
} catch (
|
|
12847
|
-
console.error("[EXULU] Failed to offload oversized tool output to session files.",
|
|
12952
|
+
} catch (err4) {
|
|
12953
|
+
console.error("[EXULU] Failed to offload oversized tool output to session files.", err4);
|
|
12848
12954
|
return void 0;
|
|
12849
12955
|
}
|
|
12850
12956
|
};
|
|
@@ -12970,8 +13076,8 @@ var init_session_file_read_tool = __esm({
|
|
|
12970
13076
|
offset: start + 1,
|
|
12971
13077
|
linesReturned
|
|
12972
13078
|
};
|
|
12973
|
-
} catch (
|
|
12974
|
-
return { error: `Failed to read session file "${safeName}": ${
|
|
13079
|
+
} catch (err4) {
|
|
13080
|
+
return { error: `Failed to read session file "${safeName}": ${err4 instanceof Error ? err4.message : "unknown error"}` };
|
|
12975
13081
|
}
|
|
12976
13082
|
};
|
|
12977
13083
|
return ExuluTool.internal({
|
|
@@ -13015,9 +13121,9 @@ async function convertLegacyOfficeToModern(bytes, ext) {
|
|
|
13015
13121
|
["--headless", "--convert-to", target, inputPath, "--outdir", dir],
|
|
13016
13122
|
{ timeout: 6e4, maxBuffer: MAX_STDOUT_BYTES }
|
|
13017
13123
|
);
|
|
13018
|
-
} catch (
|
|
13124
|
+
} catch (err4) {
|
|
13019
13125
|
throw new Error(
|
|
13020
|
-
`LibreOffice could not convert the legacy "${ext}" file to ${target}: ` + (
|
|
13126
|
+
`LibreOffice could not convert the legacy "${ext}" file to ${target}: ` + (err4 instanceof Error ? err4.message : String(err4))
|
|
13021
13127
|
);
|
|
13022
13128
|
}
|
|
13023
13129
|
const outputPath = (0, import_node_path6.join)(dir, `input.${target}`);
|
|
@@ -13054,9 +13160,9 @@ async function renderPdfPageToPng(pdf, page, scaleTo) {
|
|
|
13054
13160
|
["-png", "-f", String(page), "-l", String(page), "-scale-to", String(scaleTo), inputPath, (0, import_node_path6.join)(dir, "page")],
|
|
13055
13161
|
{ timeout: 6e4, maxBuffer: MAX_STDOUT_BYTES }
|
|
13056
13162
|
);
|
|
13057
|
-
} catch (
|
|
13058
|
-
if (
|
|
13059
|
-
throw
|
|
13163
|
+
} catch (err4) {
|
|
13164
|
+
if (err4?.code === 99) return null;
|
|
13165
|
+
throw err4;
|
|
13060
13166
|
}
|
|
13061
13167
|
const produced = (await (0, import_promises3.readdir)(dir)).find((f) => f.startsWith("page") && f.endsWith(".png"));
|
|
13062
13168
|
if (!produced) return null;
|
|
@@ -13235,8 +13341,8 @@ ${text.trim()}`).join("\n");
|
|
|
13235
13341
|
offset: start + 1,
|
|
13236
13342
|
linesReturned
|
|
13237
13343
|
};
|
|
13238
|
-
} catch (
|
|
13239
|
-
return { error: `Failed to parse "${safeName}": ${
|
|
13344
|
+
} catch (err4) {
|
|
13345
|
+
return { error: `Failed to parse "${safeName}": ${err4 instanceof Error ? err4.message : "unknown error"}` };
|
|
13240
13346
|
}
|
|
13241
13347
|
};
|
|
13242
13348
|
return ExuluTool.internal({
|
|
@@ -13293,9 +13399,9 @@ async function getPdfPreviewBytes(opts) {
|
|
|
13293
13399
|
`soffice --headless --convert-to pdf "${inputPath}" --outdir "${CACHE_OUT}"`,
|
|
13294
13400
|
{ timeout: 6e4, maxBuffer: 16 * 1024 * 1024 }
|
|
13295
13401
|
);
|
|
13296
|
-
} catch (
|
|
13402
|
+
} catch (err4) {
|
|
13297
13403
|
throw new PreviewRenderError(
|
|
13298
|
-
`LibreOffice conversion failed for ${sourceKey} (etag ${etag}): ${
|
|
13404
|
+
`LibreOffice conversion failed for ${sourceKey} (etag ${etag}): ${err4?.stderr ?? err4?.message ?? "unknown error"}`
|
|
13299
13405
|
);
|
|
13300
13406
|
}
|
|
13301
13407
|
if (!(0, import_node_fs8.existsSync)(outputPath)) {
|
|
@@ -13417,8 +13523,8 @@ var init_catalog = __esm({
|
|
|
13417
13523
|
const uniqueItems = Array.from(map.values());
|
|
13418
13524
|
_cache = { expiresAt: Date.now() + CACHE_TTL_MS, items: uniqueItems };
|
|
13419
13525
|
return uniqueItems;
|
|
13420
|
-
} catch (
|
|
13421
|
-
console.error("[EXULU] litellmCatalog: failed to fetch /model/info:",
|
|
13526
|
+
} catch (err4) {
|
|
13527
|
+
console.error("[EXULU] litellmCatalog: failed to fetch /model/info:", err4);
|
|
13422
13528
|
return [];
|
|
13423
13529
|
}
|
|
13424
13530
|
};
|
|
@@ -13644,8 +13750,8 @@ var init_view_document_page_tool = __esm({
|
|
|
13644
13750
|
page: pageNumber,
|
|
13645
13751
|
note: "The rendered image follows this tool result as an attached user message \u2014 analyze it there. If no image message follows, the attachment has expired; call this tool again to re-render it."
|
|
13646
13752
|
};
|
|
13647
|
-
} catch (
|
|
13648
|
-
return { error: `Failed to render "${safeName}": ${
|
|
13753
|
+
} catch (err4) {
|
|
13754
|
+
return { error: `Failed to render "${safeName}": ${err4 instanceof Error ? err4.message : "unknown error"}` };
|
|
13649
13755
|
}
|
|
13650
13756
|
};
|
|
13651
13757
|
return ExuluTool.internal({
|
|
@@ -13825,10 +13931,10 @@ var init_convert_exulu_tools_to_ai_sdk_tools = __esm({
|
|
|
13825
13931
|
}
|
|
13826
13932
|
try {
|
|
13827
13933
|
toolConfig.value = JSON.parse(toolConfig.variable.toString());
|
|
13828
|
-
} catch (
|
|
13934
|
+
} catch (err4) {
|
|
13829
13935
|
console.warn(
|
|
13830
13936
|
`[EXULU] Config option "${toolConfig.name}" holds invalid JSON \u2014 falling back to the tool's declared default.`,
|
|
13831
|
-
|
|
13937
|
+
err4
|
|
13832
13938
|
);
|
|
13833
13939
|
toolConfig.value = void 0;
|
|
13834
13940
|
}
|
|
@@ -13873,10 +13979,10 @@ var init_convert_exulu_tools_to_ai_sdk_tools = __esm({
|
|
|
13873
13979
|
// skill.sandbox.created event can be joined to the agent that caused it.
|
|
13874
13980
|
agent ? { id: agent.id, name: agent.name, slug: agent.slug } : void 0
|
|
13875
13981
|
);
|
|
13876
|
-
} catch (
|
|
13982
|
+
} catch (err4) {
|
|
13877
13983
|
console.error(
|
|
13878
13984
|
"[EXULU] Failed to eagerly create shared skill sandbox; outer agent will not have readFile/writeFile available.",
|
|
13879
|
-
|
|
13985
|
+
err4
|
|
13880
13986
|
);
|
|
13881
13987
|
}
|
|
13882
13988
|
}
|
|
@@ -14443,10 +14549,10 @@ async function resolveReranker(input) {
|
|
|
14443
14549
|
}
|
|
14444
14550
|
try {
|
|
14445
14551
|
await waitForLiteLLMReady();
|
|
14446
|
-
} catch (
|
|
14552
|
+
} catch (err4) {
|
|
14447
14553
|
throw new ResolveRerankerError(
|
|
14448
14554
|
"LITELLM_NOT_READY",
|
|
14449
|
-
`LiteLLM is not ready: ${
|
|
14555
|
+
`LiteLLM is not ready: ${err4.message}`
|
|
14450
14556
|
);
|
|
14451
14557
|
}
|
|
14452
14558
|
const { baseUrl, authHeaders } = resolveLiteLLMTarget();
|
|
@@ -14513,8 +14619,8 @@ async function resolveReranker(input) {
|
|
|
14513
14619
|
}));
|
|
14514
14620
|
reranked.sort((a, b) => b.rerank_score - a.rerank_score);
|
|
14515
14621
|
return reranked;
|
|
14516
|
-
} catch (
|
|
14517
|
-
console.error("[EXULU] Error reranking:",
|
|
14622
|
+
} catch (err4) {
|
|
14623
|
+
console.error("[EXULU] Error reranking:", err4);
|
|
14518
14624
|
return [];
|
|
14519
14625
|
}
|
|
14520
14626
|
};
|
|
@@ -14562,8 +14668,8 @@ function jsonVal(name, schema7, v) {
|
|
|
14562
14668
|
if (typeof v === "string" && v.trim().length > 0) {
|
|
14563
14669
|
try {
|
|
14564
14670
|
candidate = JSON.parse(v);
|
|
14565
|
-
} catch (
|
|
14566
|
-
console.warn(`[EXULU pipeline] config "${name}" is not valid JSON \u2014 using defaults.`,
|
|
14671
|
+
} catch (err4) {
|
|
14672
|
+
console.warn(`[EXULU pipeline] config "${name}" is not valid JSON \u2014 using defaults.`, err4);
|
|
14567
14673
|
candidate = void 0;
|
|
14568
14674
|
}
|
|
14569
14675
|
} else if (typeof v !== "object" || v === null) {
|
|
@@ -14576,8 +14682,8 @@ function jsonVal(name, schema7, v) {
|
|
|
14576
14682
|
}
|
|
14577
14683
|
try {
|
|
14578
14684
|
return schema7.parse(defaultFor(name));
|
|
14579
|
-
} catch (
|
|
14580
|
-
console.warn(`[EXULU pipeline] failed to parse fallback for option "${name}" \u2014 falling back to schema.parse(undefined).`,
|
|
14685
|
+
} catch (err4) {
|
|
14686
|
+
console.warn(`[EXULU pipeline] failed to parse fallback for option "${name}" \u2014 falling back to schema.parse(undefined).`, err4);
|
|
14581
14687
|
try {
|
|
14582
14688
|
return schema7.parse(void 0);
|
|
14583
14689
|
} catch {
|
|
@@ -15127,10 +15233,10 @@ async function resolveIdentifierPins({
|
|
|
15127
15233
|
});
|
|
15128
15234
|
})
|
|
15129
15235
|
);
|
|
15130
|
-
} catch (
|
|
15236
|
+
} catch (err4) {
|
|
15131
15237
|
console.warn(
|
|
15132
15238
|
`[EXULU pipeline] identifier extraction for "${set.name}" failed \u2014 skipping.`,
|
|
15133
|
-
|
|
15239
|
+
err4
|
|
15134
15240
|
);
|
|
15135
15241
|
}
|
|
15136
15242
|
})
|
|
@@ -15285,8 +15391,8 @@ If explicit, return the knowledge base ids. If not, return an empty array.`;
|
|
|
15285
15391
|
enabledContexts,
|
|
15286
15392
|
routingRules: wantsClassification ? routingRules : [],
|
|
15287
15393
|
extraInstructions
|
|
15288
|
-
}).catch((
|
|
15289
|
-
console.warn("[EXULU pipeline] merged routing call failed \u2014 falling back to the v1 hops.",
|
|
15394
|
+
}).catch((err4) => {
|
|
15395
|
+
console.warn("[EXULU pipeline] merged routing call failed \u2014 falling back to the v1 hops.", err4);
|
|
15290
15396
|
return null;
|
|
15291
15397
|
})
|
|
15292
15398
|
) : null;
|
|
@@ -15304,7 +15410,7 @@ If explicit, return the knowledge base ids. If not, return an empty array.`;
|
|
|
15304
15410
|
pageNumber: import_zod14.z.number().int().nullable().optional()
|
|
15305
15411
|
})
|
|
15306
15412
|
});
|
|
15307
|
-
} catch (
|
|
15413
|
+
} catch (err4) {
|
|
15308
15414
|
steps.push({ text: "Doc/page detection failed \u2014 skipping filename and page hints." });
|
|
15309
15415
|
return {
|
|
15310
15416
|
output: {
|
|
@@ -15328,7 +15434,7 @@ If explicit, return the knowledge base ids. If not, return an empty array.`;
|
|
|
15328
15434
|
}),
|
|
15329
15435
|
messages: [{ role: "user", content: question }]
|
|
15330
15436
|
});
|
|
15331
|
-
} catch (
|
|
15437
|
+
} catch (err4) {
|
|
15332
15438
|
return { output: { explicitlyRequestedKnowledgeBases: [] } };
|
|
15333
15439
|
}
|
|
15334
15440
|
})()
|
|
@@ -15370,8 +15476,8 @@ If explicit, return the knowledge base ids. If not, return an empty array.`;
|
|
|
15370
15476
|
text: totalMatched > 0 ? `User referenced specific document(s); pinning ${totalMatched} file(s): ${matchedNames.join(", ")}` : `User referenced document(s) ${hints.join(", ")} but no matching file was found.`
|
|
15371
15477
|
});
|
|
15372
15478
|
}
|
|
15373
|
-
} catch (
|
|
15374
|
-
console.warn("[EXULU pipeline] Document reference resolution failed:",
|
|
15479
|
+
} catch (err4) {
|
|
15480
|
+
console.warn("[EXULU pipeline] Document reference resolution failed:", err4);
|
|
15375
15481
|
steps.push({ text: "Document reference resolution failed \u2014 continuing without file pins." });
|
|
15376
15482
|
}
|
|
15377
15483
|
}
|
|
@@ -15440,7 +15546,7 @@ ${extraInstructions}
|
|
|
15440
15546
|
text: "Classification returned unknown rule \u2014 using implicit all-main rule."
|
|
15441
15547
|
});
|
|
15442
15548
|
}
|
|
15443
|
-
} catch (
|
|
15549
|
+
} catch (err4) {
|
|
15444
15550
|
mainContexts = enabledContexts.map((c) => c.id);
|
|
15445
15551
|
fallbackContexts = [];
|
|
15446
15552
|
steps.push({
|
|
@@ -15459,8 +15565,8 @@ ${extraInstructions}
|
|
|
15459
15565
|
hasExplicitDocAndPage,
|
|
15460
15566
|
steps
|
|
15461
15567
|
};
|
|
15462
|
-
} catch (
|
|
15463
|
-
console.warn("[EXULU pipeline] runRoutingPhase failed:",
|
|
15568
|
+
} catch (err4) {
|
|
15569
|
+
console.warn("[EXULU pipeline] runRoutingPhase failed:", err4);
|
|
15464
15570
|
return {
|
|
15465
15571
|
mainContexts: enabledContexts.map((c) => c.id),
|
|
15466
15572
|
fallbackContexts: [],
|
|
@@ -15922,8 +16028,8 @@ ${glossary.map((g) => `${g.term} : ${g.meaning}`).join("\n")}` : "";
|
|
|
15922
16028
|
updatedImportantKeyword,
|
|
15923
16029
|
steps
|
|
15924
16030
|
};
|
|
15925
|
-
} catch (
|
|
15926
|
-
console.warn("[EXULU pipeline] memory phase failed \u2014 continuing without memory.",
|
|
16031
|
+
} catch (err4) {
|
|
16032
|
+
console.warn("[EXULU pipeline] memory phase failed \u2014 continuing without memory.", err4);
|
|
15927
16033
|
return neutralResult(question, keywords, importantKeyword);
|
|
15928
16034
|
}
|
|
15929
16035
|
}
|
|
@@ -16225,13 +16331,13 @@ async function searchContexts(opts) {
|
|
|
16225
16331
|
return tagContext(await singleSearch({ query: keywordQuery, config: searchConfig, user, role, pinnedItemIds, context: ctx }), ctx);
|
|
16226
16332
|
}
|
|
16227
16333
|
return [];
|
|
16228
|
-
} catch (
|
|
16229
|
-
if (isEmbedderNotConfigured(
|
|
16334
|
+
} catch (err4) {
|
|
16335
|
+
if (isEmbedderNotConfigured(err4)) {
|
|
16230
16336
|
console.warn(
|
|
16231
|
-
`[EXULU pipeline] context "${ctxId}" is not searchable: ${
|
|
16337
|
+
`[EXULU pipeline] context "${ctxId}" is not searchable: ${err4.message}`
|
|
16232
16338
|
);
|
|
16233
16339
|
} else {
|
|
16234
|
-
console.warn(`[EXULU pipeline] searchContexts failed for context "${ctxId}":`,
|
|
16340
|
+
console.warn(`[EXULU pipeline] searchContexts failed for context "${ctxId}":`, err4);
|
|
16235
16341
|
}
|
|
16236
16342
|
return [];
|
|
16237
16343
|
}
|
|
@@ -16384,8 +16490,8 @@ async function rerankResults(opts) {
|
|
|
16384
16490
|
duplicateOf.set(a, [...duplicateOf.get(a) ?? [], b]);
|
|
16385
16491
|
duplicateOf.set(b, [...duplicateOf.get(b) ?? [], a]);
|
|
16386
16492
|
}
|
|
16387
|
-
} catch (
|
|
16388
|
-
console.warn("[EXULU pipeline] near-duplicate lookup failed \u2014 selecting without suppression:",
|
|
16493
|
+
} catch (err4) {
|
|
16494
|
+
console.warn("[EXULU pipeline] near-duplicate lookup failed \u2014 selecting without suppression:", err4);
|
|
16389
16495
|
duplicateOf = /* @__PURE__ */ new Map();
|
|
16390
16496
|
}
|
|
16391
16497
|
}
|
|
@@ -16471,15 +16577,15 @@ function makeNearDuplicateFinder(opts) {
|
|
|
16471
16577
|
[ids, ids, threshold]
|
|
16472
16578
|
);
|
|
16473
16579
|
return (res.rows ?? []).map((r) => [r.a, r.b]);
|
|
16474
|
-
} catch (
|
|
16475
|
-
console.warn(`[EXULU pipeline] near-duplicate query failed for "${ctxId}":`,
|
|
16580
|
+
} catch (err4) {
|
|
16581
|
+
console.warn(`[EXULU pipeline] near-duplicate query failed for "${ctxId}":`, err4);
|
|
16476
16582
|
return [];
|
|
16477
16583
|
}
|
|
16478
16584
|
})
|
|
16479
16585
|
);
|
|
16480
16586
|
return results.flat();
|
|
16481
|
-
} catch (
|
|
16482
|
-
console.warn("[EXULU pipeline] near-duplicate lookup failed to acquire a database connection:",
|
|
16587
|
+
} catch (err4) {
|
|
16588
|
+
console.warn("[EXULU pipeline] near-duplicate lookup failed to acquire a database connection:", err4);
|
|
16483
16589
|
return [];
|
|
16484
16590
|
}
|
|
16485
16591
|
};
|
|
@@ -16837,10 +16943,10 @@ function createAgenticRetrievalTool(opts) {
|
|
|
16837
16943
|
if (rerankerId && rerankerId !== "none") {
|
|
16838
16944
|
try {
|
|
16839
16945
|
reranker = await resolveReranker({ model: rerankerId, user, roleId: role });
|
|
16840
|
-
} catch (
|
|
16946
|
+
} catch (err4) {
|
|
16841
16947
|
console.warn(
|
|
16842
16948
|
`[EXULU pipeline] could not resolve reranker "${rerankerId}", continuing without reranking:`,
|
|
16843
|
-
|
|
16949
|
+
err4
|
|
16844
16950
|
);
|
|
16845
16951
|
}
|
|
16846
16952
|
}
|
|
@@ -16853,10 +16959,10 @@ function createAgenticRetrievalTool(opts) {
|
|
|
16853
16959
|
rbacBypass: true
|
|
16854
16960
|
});
|
|
16855
16961
|
utilityModel = resolved.languageModel ?? model;
|
|
16856
|
-
} catch (
|
|
16962
|
+
} catch (err4) {
|
|
16857
16963
|
console.warn(
|
|
16858
16964
|
`[EXULU pipeline] could not resolve utility model "${cfg.utilityModel}", falling back to agent model:`,
|
|
16859
|
-
|
|
16965
|
+
err4
|
|
16860
16966
|
);
|
|
16861
16967
|
}
|
|
16862
16968
|
}
|
|
@@ -17196,8 +17302,8 @@ Verified answer:
|
|
|
17196
17302
|
}
|
|
17197
17303
|
yield { result: serializeOutput(result, hideSources) };
|
|
17198
17304
|
return { result: serializeOutput(result, hideSources) };
|
|
17199
|
-
} catch (
|
|
17200
|
-
console.warn("[EXULU pipeline] retrieval pipeline failed:",
|
|
17305
|
+
} catch (err4) {
|
|
17306
|
+
console.warn("[EXULU pipeline] retrieval pipeline failed:", err4);
|
|
17201
17307
|
result.steps.push({
|
|
17202
17308
|
stepNumber: 1,
|
|
17203
17309
|
text: "Retrieval degraded due to an internal error \u2014 returning partial results.",
|
|
@@ -17308,11 +17414,11 @@ var describeError = (e) => {
|
|
|
17308
17414
|
function logRedisErrors(source, label) {
|
|
17309
17415
|
let count = 0;
|
|
17310
17416
|
let lastLoggedAt = 0;
|
|
17311
|
-
source.on("error", (
|
|
17417
|
+
source.on("error", (err4) => {
|
|
17312
17418
|
count += 1;
|
|
17313
17419
|
const now = Date.now();
|
|
17314
17420
|
if (count === 1 || now - lastLoggedAt >= ERROR_LOG_THROTTLE_MS) {
|
|
17315
|
-
errorLog(`${label} connection error (${redisAddress()}): ${describeError(
|
|
17421
|
+
errorLog(`${label} connection error (${redisAddress()}): ${describeError(err4)}${count > 1 ? ` (x${count})` : ""}`);
|
|
17316
17422
|
lastLoggedAt = now;
|
|
17317
17423
|
}
|
|
17318
17424
|
});
|
|
@@ -17322,8 +17428,8 @@ async function guardRedisStartup(label, run, source) {
|
|
|
17322
17428
|
log(`Connecting to Redis (${addr}) for ${label}\u2026`);
|
|
17323
17429
|
const startedAt = Date.now();
|
|
17324
17430
|
let lastError;
|
|
17325
|
-
const onError = (
|
|
17326
|
-
lastError =
|
|
17431
|
+
const onError = (err4) => {
|
|
17432
|
+
lastError = err4;
|
|
17327
17433
|
};
|
|
17328
17434
|
source?.on("error", onError);
|
|
17329
17435
|
const watchdog = setInterval(() => {
|
|
@@ -17686,7 +17792,8 @@ var import_bullmq_otel = require("bullmq-otel");
|
|
|
17686
17792
|
init_entitlements();
|
|
17687
17793
|
var global_queues = {
|
|
17688
17794
|
eval_runs: "eval_runs",
|
|
17689
|
-
email_intake: "email_intake"
|
|
17795
|
+
email_intake: "email_intake",
|
|
17796
|
+
import: "import"
|
|
17690
17797
|
};
|
|
17691
17798
|
var ExuluQueues = class {
|
|
17692
17799
|
queues;
|
|
@@ -17748,10 +17855,10 @@ var ExuluQueues = class {
|
|
|
17748
17855
|
logRedisErrors(newQueue, `queue "${name}"`);
|
|
17749
17856
|
try {
|
|
17750
17857
|
await guardRedisStartup(`queue "${name}"`, () => newQueue.waitUntilReady(), newQueue);
|
|
17751
|
-
} catch (
|
|
17858
|
+
} catch (err4) {
|
|
17752
17859
|
void newQueue.close().catch(() => {
|
|
17753
17860
|
});
|
|
17754
|
-
throw
|
|
17861
|
+
throw err4;
|
|
17755
17862
|
}
|
|
17756
17863
|
await newQueue.setGlobalConcurrency(queueConcurrency);
|
|
17757
17864
|
this.queues.push({
|
|
@@ -18960,6 +19067,507 @@ async function deleteRoutineRunRow(db2, row, queues2) {
|
|
|
18960
19067
|
await db2.from("job_results").where({ id: row.id }).del();
|
|
18961
19068
|
}
|
|
18962
19069
|
|
|
19070
|
+
// ee/queues/import-queue.ts
|
|
19071
|
+
init_cjs_shims();
|
|
19072
|
+
var IMPORT_QUEUE_CONCURRENCY = { worker: 1, queue: 1 };
|
|
19073
|
+
var IMPORT_QUEUE_RATELIMIT = 1;
|
|
19074
|
+
var IMPORT_QUEUE_TIMEOUT_SECONDS = 6 * 3600;
|
|
19075
|
+
function registerImportQueue() {
|
|
19076
|
+
return queues.register(
|
|
19077
|
+
global_queues.import,
|
|
19078
|
+
IMPORT_QUEUE_CONCURRENCY,
|
|
19079
|
+
IMPORT_QUEUE_RATELIMIT,
|
|
19080
|
+
IMPORT_QUEUE_TIMEOUT_SECONDS
|
|
19081
|
+
);
|
|
19082
|
+
}
|
|
19083
|
+
|
|
19084
|
+
// src/exulu/import/start-import.ts
|
|
19085
|
+
init_cjs_shims();
|
|
19086
|
+
var import_node_crypto8 = require("crypto");
|
|
19087
|
+
|
|
19088
|
+
// src/utils/serialize-error.ts
|
|
19089
|
+
init_cjs_shims();
|
|
19090
|
+
var MAX_CAUSE_DEPTH = 3;
|
|
19091
|
+
function serializeError(err4, depth = 0) {
|
|
19092
|
+
if (err4 instanceof Error) {
|
|
19093
|
+
const out = { name: err4.name, message: err4.message };
|
|
19094
|
+
if (err4.stack) out.stack = err4.stack;
|
|
19095
|
+
for (const [key, value] of Object.entries(err4)) {
|
|
19096
|
+
if (key !== "cause") out[key] = value;
|
|
19097
|
+
}
|
|
19098
|
+
const cause = err4.cause;
|
|
19099
|
+
if (cause !== void 0 && depth < MAX_CAUSE_DEPTH) {
|
|
19100
|
+
out.cause = serializeError(cause, depth + 1);
|
|
19101
|
+
}
|
|
19102
|
+
return out;
|
|
19103
|
+
}
|
|
19104
|
+
if (typeof err4 === "string") {
|
|
19105
|
+
return { message: err4 };
|
|
19106
|
+
}
|
|
19107
|
+
if (err4 !== null && typeof err4 === "object") {
|
|
19108
|
+
let message;
|
|
19109
|
+
try {
|
|
19110
|
+
message = JSON.stringify(err4);
|
|
19111
|
+
} catch {
|
|
19112
|
+
message = "[unserializable error object]";
|
|
19113
|
+
}
|
|
19114
|
+
return { ...err4, message };
|
|
19115
|
+
}
|
|
19116
|
+
return { message: String(err4) };
|
|
19117
|
+
}
|
|
19118
|
+
|
|
19119
|
+
// src/exulu/import/rows.ts
|
|
19120
|
+
init_cjs_shims();
|
|
19121
|
+
|
|
19122
|
+
// src/exulu/import/coerce.ts
|
|
19123
|
+
init_cjs_shims();
|
|
19124
|
+
var TEXTUAL = /* @__PURE__ */ new Set(["text", "longText", "shortText", "markdown", "code"]);
|
|
19125
|
+
function err3(raw, code, params) {
|
|
19126
|
+
return { raw, value: null, error: { code, params } };
|
|
19127
|
+
}
|
|
19128
|
+
function coerceValue(field, raw) {
|
|
19129
|
+
const trimmed = raw.trim();
|
|
19130
|
+
if (trimmed === "") {
|
|
19131
|
+
return { raw, value: TEXTUAL.has(field.type) ? "" : null };
|
|
19132
|
+
}
|
|
19133
|
+
switch (field.type) {
|
|
19134
|
+
case "number": {
|
|
19135
|
+
const hasComma = trimmed.includes(",");
|
|
19136
|
+
const hasDot = trimmed.includes(".");
|
|
19137
|
+
if (hasComma && hasDot) return err3(raw, "number");
|
|
19138
|
+
let candidate = trimmed;
|
|
19139
|
+
if (hasComma) {
|
|
19140
|
+
const parts = trimmed.split(",");
|
|
19141
|
+
if (parts.length !== 2 || (parts[1]?.length ?? 0) === 3) return err3(raw, "numberAmbiguous");
|
|
19142
|
+
candidate = parts.join(".");
|
|
19143
|
+
}
|
|
19144
|
+
const n = Number(candidate);
|
|
19145
|
+
if (!Number.isFinite(n)) return err3(raw, "number");
|
|
19146
|
+
return { raw, value: n };
|
|
19147
|
+
}
|
|
19148
|
+
case "boolean": {
|
|
19149
|
+
const v = trimmed.toLowerCase();
|
|
19150
|
+
if (["true", "yes", "ja", "1"].includes(v)) return { raw, value: true };
|
|
19151
|
+
if (["false", "no", "nein", "0"].includes(v)) return { raw, value: false };
|
|
19152
|
+
return err3(raw, "boolean");
|
|
19153
|
+
}
|
|
19154
|
+
case "enum": {
|
|
19155
|
+
const match = (field.enumValues ?? []).find((e) => e.toLowerCase() === trimmed.toLowerCase());
|
|
19156
|
+
if (!match) return err3(raw, "enum", { values: (field.enumValues ?? []).join(", ") });
|
|
19157
|
+
return { raw, value: match };
|
|
19158
|
+
}
|
|
19159
|
+
case "date": {
|
|
19160
|
+
if (/^\d{4}-\d{2}-\d{2}(T[\d:.]+(Z|[+-]\d{2}:?\d{2})?)?$/.test(trimmed)) {
|
|
19161
|
+
return Number.isNaN(Date.parse(trimmed)) ? err3(raw, "date") : { raw, value: trimmed };
|
|
19162
|
+
}
|
|
19163
|
+
if (trimmed.includes("/")) return err3(raw, "date");
|
|
19164
|
+
return Number.isNaN(Date.parse(trimmed)) ? err3(raw, "date") : { raw, value: new Date(trimmed).toISOString() };
|
|
19165
|
+
}
|
|
19166
|
+
case "json": {
|
|
19167
|
+
try {
|
|
19168
|
+
JSON.parse(trimmed);
|
|
19169
|
+
return { raw, value: trimmed };
|
|
19170
|
+
} catch {
|
|
19171
|
+
return err3(raw, "json");
|
|
19172
|
+
}
|
|
19173
|
+
}
|
|
19174
|
+
case "uuid": {
|
|
19175
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(trimmed) ? { raw, value: trimmed } : err3(raw, "uuid");
|
|
19176
|
+
}
|
|
19177
|
+
default:
|
|
19178
|
+
return { raw, value: raw };
|
|
19179
|
+
}
|
|
19180
|
+
}
|
|
19181
|
+
|
|
19182
|
+
// src/exulu/import/rows.ts
|
|
19183
|
+
function tentativeAction(cells) {
|
|
19184
|
+
const id = cells.id?.value;
|
|
19185
|
+
if (typeof id === "string" && id !== "") return "update";
|
|
19186
|
+
const externalId = cells.external_id?.value;
|
|
19187
|
+
if (typeof externalId === "string" && externalId !== "") return "update";
|
|
19188
|
+
return "create";
|
|
19189
|
+
}
|
|
19190
|
+
function buildRow(index, cells, byIndex, fields) {
|
|
19191
|
+
const byName = new Map(fields.map((f) => [f.name, f]));
|
|
19192
|
+
const rowCells = {};
|
|
19193
|
+
for (let i = 0; i < byIndex.length; i++) {
|
|
19194
|
+
const fieldName = byIndex[i];
|
|
19195
|
+
if (!fieldName) continue;
|
|
19196
|
+
const field = byName.get(fieldName);
|
|
19197
|
+
if (!field) continue;
|
|
19198
|
+
rowCells[fieldName] = coerceValue(field, cells[i] ?? "");
|
|
19199
|
+
}
|
|
19200
|
+
const action = tentativeAction(rowCells);
|
|
19201
|
+
const errors = [];
|
|
19202
|
+
for (const f of fields) {
|
|
19203
|
+
const cell = rowCells[f.name];
|
|
19204
|
+
const mustHaveValue = action === "create" || cell !== void 0;
|
|
19205
|
+
if (f.required && mustHaveValue && (cell === void 0 || cell.raw.trim() === "")) {
|
|
19206
|
+
errors.push(`required:${f.name}`);
|
|
19207
|
+
continue;
|
|
19208
|
+
}
|
|
19209
|
+
if (cell?.error) {
|
|
19210
|
+
errors.push(`${f.name}:${cell.error.code}`);
|
|
19211
|
+
}
|
|
19212
|
+
}
|
|
19213
|
+
return { index, cells: rowCells, errors };
|
|
19214
|
+
}
|
|
19215
|
+
function rowIsValid(row) {
|
|
19216
|
+
return row.errors.length === 0;
|
|
19217
|
+
}
|
|
19218
|
+
function rowAction(row) {
|
|
19219
|
+
const id = row.cells.id?.value;
|
|
19220
|
+
if (typeof id === "string" && id !== "") {
|
|
19221
|
+
return { action: "update", by: "id", key: id };
|
|
19222
|
+
}
|
|
19223
|
+
const externalId = row.cells.external_id?.value;
|
|
19224
|
+
if (typeof externalId === "string" && externalId !== "") {
|
|
19225
|
+
return { action: "update", by: "external_id", key: externalId };
|
|
19226
|
+
}
|
|
19227
|
+
return { action: "create" };
|
|
19228
|
+
}
|
|
19229
|
+
function cellValues(row) {
|
|
19230
|
+
const input = {};
|
|
19231
|
+
for (const [name, cell] of Object.entries(row.cells)) {
|
|
19232
|
+
if (name === "id") continue;
|
|
19233
|
+
if (name === "external_id" && (cell.value == null || cell.value === "")) continue;
|
|
19234
|
+
input[name] = cell.value;
|
|
19235
|
+
}
|
|
19236
|
+
return input;
|
|
19237
|
+
}
|
|
19238
|
+
function asGrantList(value) {
|
|
19239
|
+
return Array.isArray(value) ? value : [];
|
|
19240
|
+
}
|
|
19241
|
+
function rbacGrantsFor(access) {
|
|
19242
|
+
const hasGrants = access.rights_mode === "users" || access.rights_mode === "roles" || access.rights_mode === "teams";
|
|
19243
|
+
if (!hasGrants) return void 0;
|
|
19244
|
+
return {
|
|
19245
|
+
users: asGrantList(access.users),
|
|
19246
|
+
roles: asGrantList(access.roles),
|
|
19247
|
+
teams: asGrantList(access.teams)
|
|
19248
|
+
};
|
|
19249
|
+
}
|
|
19250
|
+
function buildCreateInput(row, access) {
|
|
19251
|
+
const input = cellValues(row);
|
|
19252
|
+
input.rights_mode = access.rights_mode;
|
|
19253
|
+
return input;
|
|
19254
|
+
}
|
|
19255
|
+
function buildUpdateInput(row) {
|
|
19256
|
+
return cellValues(row);
|
|
19257
|
+
}
|
|
19258
|
+
|
|
19259
|
+
// src/exulu/import/worker-deps.ts
|
|
19260
|
+
init_cjs_shims();
|
|
19261
|
+
init_table_names();
|
|
19262
|
+
init_uppy();
|
|
19263
|
+
init_rbac_update();
|
|
19264
|
+
init_jobs();
|
|
19265
|
+
function grantsOf(existing) {
|
|
19266
|
+
const raw = existing.RBAC;
|
|
19267
|
+
return Array.isArray(raw) ? raw : [];
|
|
19268
|
+
}
|
|
19269
|
+
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
19270
|
+
function isUuid(value) {
|
|
19271
|
+
return UUID_RE.test(value);
|
|
19272
|
+
}
|
|
19273
|
+
function idOf(value) {
|
|
19274
|
+
if (typeof value === "string") return value;
|
|
19275
|
+
if (value != null && typeof value === "object" && "id" in value) {
|
|
19276
|
+
const id = value.id;
|
|
19277
|
+
if (typeof id === "string") return id;
|
|
19278
|
+
if (typeof id === "number") return String(id);
|
|
19279
|
+
}
|
|
19280
|
+
return void 0;
|
|
19281
|
+
}
|
|
19282
|
+
function canWrite(existing, user) {
|
|
19283
|
+
if (user.super_admin === true) return true;
|
|
19284
|
+
if (existing.rights_mode === "public") return true;
|
|
19285
|
+
const isCreator = existing.created_by != null && String(existing.created_by) === String(user.id);
|
|
19286
|
+
if (existing.rights_mode === "private") return isCreator;
|
|
19287
|
+
if (isCreator) return true;
|
|
19288
|
+
if (existing.rights_mode === "users") {
|
|
19289
|
+
return grantsOf(existing).some(
|
|
19290
|
+
(g) => g.access_type === "User" && String(g.user_id) === String(user.id) && g.rights === "write"
|
|
19291
|
+
);
|
|
19292
|
+
}
|
|
19293
|
+
if (existing.rights_mode === "roles") {
|
|
19294
|
+
const roleId = idOf(user.role);
|
|
19295
|
+
if (!roleId) return false;
|
|
19296
|
+
return grantsOf(existing).some(
|
|
19297
|
+
(g) => g.access_type === "Role" && String(g.role_id) === roleId && g.rights === "write"
|
|
19298
|
+
);
|
|
19299
|
+
}
|
|
19300
|
+
if (existing.rights_mode === "teams") {
|
|
19301
|
+
const teamId = idOf(user.team);
|
|
19302
|
+
if (!teamId) return false;
|
|
19303
|
+
return grantsOf(existing).some(
|
|
19304
|
+
(g) => g.access_type === "Team" && String(g.team_id) === teamId && g.rights === "write"
|
|
19305
|
+
);
|
|
19306
|
+
}
|
|
19307
|
+
return false;
|
|
19308
|
+
}
|
|
19309
|
+
async function selectItemsBy(db2, tableName, column, values) {
|
|
19310
|
+
if (values.length === 0) return [];
|
|
19311
|
+
return db2(tableName).select("id", "external_id", "rights_mode", "created_by").whereIn(column, values);
|
|
19312
|
+
}
|
|
19313
|
+
async function lookupExisting(db2, tableName, ids, externalIds) {
|
|
19314
|
+
const [byId, byExternalId] = await Promise.all([
|
|
19315
|
+
selectItemsBy(db2, tableName, "id", ids.filter(isUuid)),
|
|
19316
|
+
selectItemsBy(db2, tableName, "external_id", externalIds)
|
|
19317
|
+
]);
|
|
19318
|
+
const merged = /* @__PURE__ */ new Map();
|
|
19319
|
+
for (const row of [...byId, ...byExternalId]) merged.set(row.id, row);
|
|
19320
|
+
const rows = [...merged.values()];
|
|
19321
|
+
if (rows.length === 0) return [];
|
|
19322
|
+
const needsGrants = rows.some(
|
|
19323
|
+
(r) => r.rights_mode === "users" || r.rights_mode === "roles" || r.rights_mode === "teams"
|
|
19324
|
+
);
|
|
19325
|
+
if (!needsGrants) {
|
|
19326
|
+
return rows.map((r) => ({ ...r, RBAC: [] }));
|
|
19327
|
+
}
|
|
19328
|
+
const grants = await db2("rbac").select("target_resource_id", "access_type", "user_id", "role_id", "team_id", "rights").where({ entity: tableName }).whereIn(
|
|
19329
|
+
"target_resource_id",
|
|
19330
|
+
rows.map((r) => r.id)
|
|
19331
|
+
);
|
|
19332
|
+
const grantsByItem = /* @__PURE__ */ new Map();
|
|
19333
|
+
for (const g of grants) {
|
|
19334
|
+
const list = grantsByItem.get(g.target_resource_id) ?? [];
|
|
19335
|
+
list.push(g);
|
|
19336
|
+
grantsByItem.set(g.target_resource_id, list);
|
|
19337
|
+
}
|
|
19338
|
+
return rows.map((r) => ({ ...r, RBAC: grantsByItem.get(r.id) ?? [] }));
|
|
19339
|
+
}
|
|
19340
|
+
function parseMetadata(value) {
|
|
19341
|
+
if (value == null) return {};
|
|
19342
|
+
let parsed = value;
|
|
19343
|
+
if (typeof value === "string") {
|
|
19344
|
+
try {
|
|
19345
|
+
parsed = JSON.parse(value);
|
|
19346
|
+
} catch {
|
|
19347
|
+
return {};
|
|
19348
|
+
}
|
|
19349
|
+
}
|
|
19350
|
+
return typeof parsed === "object" && parsed !== null ? parsed : {};
|
|
19351
|
+
}
|
|
19352
|
+
function mergeMetadataRaw(db2, patch) {
|
|
19353
|
+
return db2.raw("coalesce(metadata, '{}'::jsonb) || ?::jsonb", [JSON.stringify(patch)]);
|
|
19354
|
+
}
|
|
19355
|
+
async function writeProgress(db2, jobResultId, m) {
|
|
19356
|
+
await db2("job_results").where({ id: jobResultId }).update({ metadata: mergeMetadataRaw(db2, m) });
|
|
19357
|
+
}
|
|
19358
|
+
async function isCancelRequested(db2, jobResultId) {
|
|
19359
|
+
const row = await db2("job_results").where({ id: jobResultId }).select("metadata").first();
|
|
19360
|
+
return parseMetadata(row?.metadata).cancelRequested === true;
|
|
19361
|
+
}
|
|
19362
|
+
async function finalizeCancelled(db2, jobResultId, result) {
|
|
19363
|
+
await db2("job_results").where({ id: jobResultId }).whereIn("state", [JOB_STATUS_ENUM.active]).update({
|
|
19364
|
+
state: JOB_STATUS_ENUM.cancelled,
|
|
19365
|
+
result: JSON.stringify(result),
|
|
19366
|
+
metadata: mergeMetadataRaw(db2, result)
|
|
19367
|
+
});
|
|
19368
|
+
}
|
|
19369
|
+
async function uploadErrorReport(csv, contextId, jobResultId, config, user) {
|
|
19370
|
+
const buffer = Buffer.from(csv, "utf-8");
|
|
19371
|
+
const fileName = `imports/${contextId}/${jobResultId}-errors.csv`;
|
|
19372
|
+
return uploadFile(buffer, fileName, config, { contentType: "text/csv" }, user, void 0, true);
|
|
19373
|
+
}
|
|
19374
|
+
function buildWorkerDeps(input) {
|
|
19375
|
+
const { db: db2, config, context, contextId, jobResultId, stream, fields, mapping, access, options, user, log: log7 } = input;
|
|
19376
|
+
const tableName = getTableName(contextId);
|
|
19377
|
+
const roleId = idOf(user.role);
|
|
19378
|
+
const generateEmbeddingsOverwrite = options.skipEmbeddings ? false : void 0;
|
|
19379
|
+
const rbac = rbacGrantsFor(access);
|
|
19380
|
+
const total = typeof input.total === "number" && input.total > 0 ? input.total : void 0;
|
|
19381
|
+
return {
|
|
19382
|
+
stream,
|
|
19383
|
+
fields,
|
|
19384
|
+
mapping,
|
|
19385
|
+
access,
|
|
19386
|
+
options,
|
|
19387
|
+
user,
|
|
19388
|
+
log: log7,
|
|
19389
|
+
total,
|
|
19390
|
+
lookupExisting: (ids, externalIds) => lookupExisting(db2, tableName, ids, externalIds),
|
|
19391
|
+
canWrite: (existing) => canWrite(existing, user),
|
|
19392
|
+
createItem: async (itemInput) => {
|
|
19393
|
+
const { RBAC: _droppedRbacColumn, ...columns } = itemInput;
|
|
19394
|
+
const created = await context.createItem(
|
|
19395
|
+
{ ...columns, created_by: user.id },
|
|
19396
|
+
config,
|
|
19397
|
+
user.id,
|
|
19398
|
+
roleId,
|
|
19399
|
+
false,
|
|
19400
|
+
generateEmbeddingsOverwrite
|
|
19401
|
+
);
|
|
19402
|
+
const createdId = created?.item?.id;
|
|
19403
|
+
if (rbac && typeof createdId === "string") {
|
|
19404
|
+
await handleRBACUpdate(db2, tableName, createdId, rbac, []);
|
|
19405
|
+
}
|
|
19406
|
+
},
|
|
19407
|
+
// buildUpdateInput (rows.ts) never carries an id/rights_mode/RBAC -- the
|
|
19408
|
+
// target's id is threaded in here, same as the GraphQL updateOne path.
|
|
19409
|
+
// `created_by` is deliberately left untouched on an update.
|
|
19410
|
+
updateItem: async (id, itemInput) => {
|
|
19411
|
+
await context.updateItem({ id, ...itemInput }, config, user.id, roleId, generateEmbeddingsOverwrite);
|
|
19412
|
+
},
|
|
19413
|
+
writeProgress: (m) => writeProgress(db2, jobResultId, m),
|
|
19414
|
+
isCancelRequested: () => isCancelRequested(db2, jobResultId),
|
|
19415
|
+
uploadErrorReport: (csv) => uploadErrorReport(csv, contextId, jobResultId, config, user.id)
|
|
19416
|
+
};
|
|
19417
|
+
}
|
|
19418
|
+
|
|
19419
|
+
// src/exulu/import/start-import.ts
|
|
19420
|
+
function idOrSelf(value) {
|
|
19421
|
+
if (value != null && typeof value === "object" && "id" in value) {
|
|
19422
|
+
return value.id;
|
|
19423
|
+
}
|
|
19424
|
+
return value;
|
|
19425
|
+
}
|
|
19426
|
+
var VALID_RIGHTS_MODES2 = ["private", "users", "roles", "teams", "public"];
|
|
19427
|
+
var StartImportError = class extends Error {
|
|
19428
|
+
constructor(code) {
|
|
19429
|
+
super(code);
|
|
19430
|
+
this.code = code;
|
|
19431
|
+
this.name = "StartImportError";
|
|
19432
|
+
}
|
|
19433
|
+
};
|
|
19434
|
+
async function startImport(deps, args) {
|
|
19435
|
+
const { db: db2, config, queue, user, contextExists, uuid } = deps;
|
|
19436
|
+
if (!contextExists(args.contextId)) {
|
|
19437
|
+
throw new StartImportError("CONTEXT_NOT_FOUND");
|
|
19438
|
+
}
|
|
19439
|
+
if (!VALID_RIGHTS_MODES2.includes(args.access.rights_mode)) {
|
|
19440
|
+
throw new StartImportError("INVALID_RIGHTS_MODE");
|
|
19441
|
+
}
|
|
19442
|
+
const access = {
|
|
19443
|
+
...args.access,
|
|
19444
|
+
users: asGrantList(args.access.users),
|
|
19445
|
+
roles: asGrantList(args.access.roles),
|
|
19446
|
+
teams: asGrantList(args.access.teams)
|
|
19447
|
+
};
|
|
19448
|
+
if (args.options?.delimiter != null && args.options.delimiter.length !== 1) {
|
|
19449
|
+
throw new StartImportError("INVALID_DELIMITER");
|
|
19450
|
+
}
|
|
19451
|
+
const bucket = args.s3Key.split("/")[0];
|
|
19452
|
+
if (bucket !== config.fileUploads?.s3Bucket) {
|
|
19453
|
+
throw new StartImportError("IMPORT_S3_KEY_OUTSIDE_BUCKET");
|
|
19454
|
+
}
|
|
19455
|
+
const keyWithoutBucket = args.s3Key.split("/").slice(1).join("/");
|
|
19456
|
+
const prefixAllowed = user.type === "api" || user.super_admin === true || !keyWithoutBucket.includes("user_") || keyWithoutBucket.includes(`user_${user.id}/`);
|
|
19457
|
+
if (!prefixAllowed) {
|
|
19458
|
+
throw new StartImportError("IMPORT_S3_KEY_NOT_ALLOWED");
|
|
19459
|
+
}
|
|
19460
|
+
const running = await db2("job_results").where({ context: args.contextId, type: "import" }).whereIn("state", ["waiting", "active"]).first();
|
|
19461
|
+
if (running) {
|
|
19462
|
+
throw new StartImportError("IMPORT_ALREADY_RUNNING");
|
|
19463
|
+
}
|
|
19464
|
+
const id = (uuid ?? import_node_crypto8.randomUUID)();
|
|
19465
|
+
const label = `Import ${args.fileName}`;
|
|
19466
|
+
const userSnapshot = {
|
|
19467
|
+
id: user.id,
|
|
19468
|
+
super_admin: user.super_admin === true,
|
|
19469
|
+
role: idOrSelf(user.role),
|
|
19470
|
+
team: idOrSelf(user.team)
|
|
19471
|
+
};
|
|
19472
|
+
await db2("job_results").insert({
|
|
19473
|
+
id,
|
|
19474
|
+
job_id: id,
|
|
19475
|
+
type: "import",
|
|
19476
|
+
context: args.contextId,
|
|
19477
|
+
label,
|
|
19478
|
+
state: "waiting",
|
|
19479
|
+
trigger: args.trigger,
|
|
19480
|
+
trigger_metadata: JSON.stringify({
|
|
19481
|
+
s3Key: args.s3Key,
|
|
19482
|
+
fileName: args.fileName,
|
|
19483
|
+
mapping: args.mapping,
|
|
19484
|
+
access,
|
|
19485
|
+
options: args.options,
|
|
19486
|
+
user: userSnapshot
|
|
19487
|
+
}),
|
|
19488
|
+
metadata: JSON.stringify({
|
|
19489
|
+
total: args.totalRows ?? 0,
|
|
19490
|
+
processed: 0,
|
|
19491
|
+
created: 0,
|
|
19492
|
+
updated: 0,
|
|
19493
|
+
failed: 0,
|
|
19494
|
+
invalid: 0
|
|
19495
|
+
})
|
|
19496
|
+
});
|
|
19497
|
+
try {
|
|
19498
|
+
await queue.add(
|
|
19499
|
+
"import",
|
|
19500
|
+
{
|
|
19501
|
+
label,
|
|
19502
|
+
type: "import",
|
|
19503
|
+
// BullMqJobData.trigger is a STATISTICS_LABELS value, which has no
|
|
19504
|
+
// "ui" member -- "api" here is just that field's required value for
|
|
19505
|
+
// this queue path, unrelated to the job_results row's own ui|api
|
|
19506
|
+
// `trigger` column above (which records real run provenance).
|
|
19507
|
+
trigger: "api",
|
|
19508
|
+
timeoutInSeconds: 6 * 3600,
|
|
19509
|
+
// Required: bullmq.validate (src/validators/bullmq.ts) throws without
|
|
19510
|
+
// an `inputs` key, even though the import branch ignores it (its
|
|
19511
|
+
// inputs live on the job_results row's trigger_metadata instead).
|
|
19512
|
+
inputs: {},
|
|
19513
|
+
jobResultId: id,
|
|
19514
|
+
context: args.contextId,
|
|
19515
|
+
user: user.id,
|
|
19516
|
+
role: idOrSelf(user.role)
|
|
19517
|
+
},
|
|
19518
|
+
{
|
|
19519
|
+
jobId: id,
|
|
19520
|
+
attempts: 1,
|
|
19521
|
+
removeOnComplete: 5e3,
|
|
19522
|
+
removeOnFail: 5e3
|
|
19523
|
+
}
|
|
19524
|
+
);
|
|
19525
|
+
} catch (error) {
|
|
19526
|
+
await db2("job_results").where({ id }).update({ state: "failed", error: JSON.stringify(serializeError(error)) });
|
|
19527
|
+
throw error;
|
|
19528
|
+
}
|
|
19529
|
+
return { jobResultId: id };
|
|
19530
|
+
}
|
|
19531
|
+
async function cancelImport(deps, jobResultId) {
|
|
19532
|
+
const { db: db2, queue, user } = deps;
|
|
19533
|
+
const row = await db2("job_results").where({ id: jobResultId }).first();
|
|
19534
|
+
if (!row) {
|
|
19535
|
+
throw new StartImportError("IMPORT_NOT_FOUND");
|
|
19536
|
+
}
|
|
19537
|
+
if (row.type !== "import") {
|
|
19538
|
+
throw new StartImportError("IMPORT_NOT_FOUND");
|
|
19539
|
+
}
|
|
19540
|
+
if (row.state !== "waiting" && row.state !== "active") {
|
|
19541
|
+
return { ok: true };
|
|
19542
|
+
}
|
|
19543
|
+
const meta = parseMetadata(row.trigger_metadata);
|
|
19544
|
+
const starterId = idOrSelf(meta.user);
|
|
19545
|
+
const isStarter = starterId != null && Number(starterId) === user.id;
|
|
19546
|
+
if (!isStarter && user.super_admin !== true) {
|
|
19547
|
+
throw new StartImportError("NOT_AUTHORIZED");
|
|
19548
|
+
}
|
|
19549
|
+
await db2("job_results").where({ id: jobResultId }).update({ metadata: mergeMetadataRaw(db2, { cancelRequested: true }) });
|
|
19550
|
+
if (row.state === "waiting") {
|
|
19551
|
+
try {
|
|
19552
|
+
const job = await queue.getJob?.(jobResultId);
|
|
19553
|
+
await job?.remove();
|
|
19554
|
+
} catch (error) {
|
|
19555
|
+
console.error("[EXULU] failed to remove queued import job after cancel", error);
|
|
19556
|
+
}
|
|
19557
|
+
await db2("job_results").where({ id: jobResultId }).whereIn("state", ["waiting"]).update({ state: "cancelled" });
|
|
19558
|
+
} else {
|
|
19559
|
+
try {
|
|
19560
|
+
const job = await queue.getJob?.(jobResultId);
|
|
19561
|
+
if (!job) {
|
|
19562
|
+
await db2("job_results").where({ id: jobResultId }).whereIn("state", ["active"]).update({ state: "cancelled" });
|
|
19563
|
+
}
|
|
19564
|
+
} catch (error) {
|
|
19565
|
+
console.error("[EXULU] failed to inspect the running import job after cancel", error);
|
|
19566
|
+
}
|
|
19567
|
+
}
|
|
19568
|
+
return { ok: true };
|
|
19569
|
+
}
|
|
19570
|
+
|
|
18963
19571
|
// src/graphql/mutations/index.ts
|
|
18964
19572
|
init_rbac_update();
|
|
18965
19573
|
|
|
@@ -19172,10 +19780,10 @@ var currentChunksDimensionality = async (contextId) => {
|
|
|
19172
19780
|
[getChunksTableName(contextId)]
|
|
19173
19781
|
);
|
|
19174
19782
|
return parseVectorDimensionality(result?.rows?.[0]?.type ?? null);
|
|
19175
|
-
} catch (
|
|
19783
|
+
} catch (err4) {
|
|
19176
19784
|
console.warn(
|
|
19177
19785
|
`[EXULU] Could not read the chunk vector dimensionality for "${contextId}":`,
|
|
19178
|
-
|
|
19786
|
+
err4.message
|
|
19179
19787
|
);
|
|
19180
19788
|
return null;
|
|
19181
19789
|
}
|
|
@@ -19295,10 +19903,10 @@ var getTranscriptsSettings = async () => {
|
|
|
19295
19903
|
const { db: db2 } = await postgresClient();
|
|
19296
19904
|
const row = await db2.from("platform_configurations").where({ config_key: TRANSCRIPTS_SETTINGS_KEY }).first();
|
|
19297
19905
|
return { ...EMPTY, ...parseStoredSettings(row) ?? {} };
|
|
19298
|
-
} catch (
|
|
19906
|
+
} catch (err4) {
|
|
19299
19907
|
console.warn(
|
|
19300
19908
|
"[EXULU] Could not read the Transcripts settings:",
|
|
19301
|
-
|
|
19909
|
+
err4.message
|
|
19302
19910
|
);
|
|
19303
19911
|
return { ...EMPTY };
|
|
19304
19912
|
}
|
|
@@ -19413,7 +20021,7 @@ var parseSettingsInput = (input) => {
|
|
|
19413
20021
|
};
|
|
19414
20022
|
|
|
19415
20023
|
// src/graphql/mutations/index.ts
|
|
19416
|
-
var
|
|
20024
|
+
var VALID_RIGHTS_MODES3 = ["private", "users", "roles", "teams", "public"];
|
|
19417
20025
|
var postprocessDeletion = async ({
|
|
19418
20026
|
table,
|
|
19419
20027
|
requestedFields,
|
|
@@ -19555,10 +20163,10 @@ var buildTranscriptsSettingsInfo = async () => {
|
|
|
19555
20163
|
const { db: db2 } = await postgresClient();
|
|
19556
20164
|
const promptRows = await db2.from("prompt_library").select("id");
|
|
19557
20165
|
livePromptIds = new Set(promptRows.map((row) => String(row.id)));
|
|
19558
|
-
} catch (
|
|
20166
|
+
} catch (err4) {
|
|
19559
20167
|
console.warn(
|
|
19560
20168
|
"[EXULU] Could not read prompt_library for the Transcripts settings page:",
|
|
19561
|
-
|
|
20169
|
+
err4.message
|
|
19562
20170
|
);
|
|
19563
20171
|
}
|
|
19564
20172
|
let liveAgentIds = null;
|
|
@@ -19566,10 +20174,10 @@ var buildTranscriptsSettingsInfo = async () => {
|
|
|
19566
20174
|
const { db: db2 } = await postgresClient();
|
|
19567
20175
|
const agentRows = await db2.from("agents").select("id");
|
|
19568
20176
|
liveAgentIds = new Set(agentRows.map((row) => String(row.id)));
|
|
19569
|
-
} catch (
|
|
20177
|
+
} catch (err4) {
|
|
19570
20178
|
console.warn(
|
|
19571
20179
|
"[EXULU] Could not read agents for the Transcripts settings page:",
|
|
19572
|
-
|
|
20180
|
+
err4.message
|
|
19573
20181
|
);
|
|
19574
20182
|
}
|
|
19575
20183
|
const { live, stale } = livePromptIds && liveAgentIds ? filterLivePresets(resolved.summaryPresets.value, livePromptIds, liveAgentIds) : { live: resolved.summaryPresets.value, stale: [] };
|
|
@@ -19782,9 +20390,9 @@ function createMutations(table, contexts, tools, config) {
|
|
|
19782
20390
|
input.id = db2.fn.uuid();
|
|
19783
20391
|
}
|
|
19784
20392
|
}
|
|
19785
|
-
if (table.RBAC && input.rights_mode != null && !
|
|
20393
|
+
if (table.RBAC && input.rights_mode != null && !VALID_RIGHTS_MODES3.includes(input.rights_mode)) {
|
|
19786
20394
|
throw new Error(
|
|
19787
|
-
`Invalid rights_mode "${input.rights_mode}" \u2014 expected one of: ${
|
|
20395
|
+
`Invalid rights_mode "${input.rights_mode}" \u2014 expected one of: ${VALID_RIGHTS_MODES3.join(", ")}`
|
|
19788
20396
|
);
|
|
19789
20397
|
}
|
|
19790
20398
|
const columns = await db2(tableNamePlural).columnInfo();
|
|
@@ -20192,6 +20800,89 @@ function createMutations(table, contexts, tools, config) {
|
|
|
20192
20800
|
items
|
|
20193
20801
|
};
|
|
20194
20802
|
};
|
|
20803
|
+
const getImportQueue = async () => {
|
|
20804
|
+
let registered;
|
|
20805
|
+
try {
|
|
20806
|
+
registered = registerImportQueue();
|
|
20807
|
+
} catch (error) {
|
|
20808
|
+
throw new Error("QUEUES_NOT_LICENSED");
|
|
20809
|
+
}
|
|
20810
|
+
let importQueue;
|
|
20811
|
+
try {
|
|
20812
|
+
importQueue = await registered.use();
|
|
20813
|
+
} catch (error) {
|
|
20814
|
+
console.error("[EXULU] import queue unavailable", error);
|
|
20815
|
+
throw error;
|
|
20816
|
+
}
|
|
20817
|
+
return {
|
|
20818
|
+
add: (name, data, opts) => importQueue.queue.add(name, data, opts),
|
|
20819
|
+
getJob: (id) => importQueue.queue.getJob(id)
|
|
20820
|
+
};
|
|
20821
|
+
};
|
|
20822
|
+
mutations[`${tableNameSingular}StartImport`] = async (_, args, context, info) => {
|
|
20823
|
+
if (!context.user) {
|
|
20824
|
+
throw new Error("NOT_AUTHORIZED");
|
|
20825
|
+
}
|
|
20826
|
+
if (!table.id) {
|
|
20827
|
+
throw new Error("CONTEXT_NOT_FOUND");
|
|
20828
|
+
}
|
|
20829
|
+
const queue = await getImportQueue();
|
|
20830
|
+
try {
|
|
20831
|
+
return await startImport(
|
|
20832
|
+
{
|
|
20833
|
+
db: context.db,
|
|
20834
|
+
config,
|
|
20835
|
+
queue,
|
|
20836
|
+
user: context.user,
|
|
20837
|
+
// Mirrors ExecuteSource's own `exists` lookup above, as a
|
|
20838
|
+
// predicate rather than a one-shot find (start-import.ts needs
|
|
20839
|
+
// it before it knows the id is even valid).
|
|
20840
|
+
contextExists: (id) => contexts.some((c) => c.id === id)
|
|
20841
|
+
},
|
|
20842
|
+
{
|
|
20843
|
+
contextId: table.id,
|
|
20844
|
+
s3Key: args.input.s3Key,
|
|
20845
|
+
fileName: args.input.fileName,
|
|
20846
|
+
mapping: args.input.mapping,
|
|
20847
|
+
access: args.input.access,
|
|
20848
|
+
options: args.input.options,
|
|
20849
|
+
// Runs-view provenance (same rule as the workflow-run resolver
|
|
20850
|
+
// at src/graphql/schemas/index.ts:1964): API-key callers get
|
|
20851
|
+
// "api", everyone else (UI session) gets "ui".
|
|
20852
|
+
trigger: context.user.type === "api" ? "api" : "ui",
|
|
20853
|
+
totalRows: args.input.totalRows
|
|
20854
|
+
}
|
|
20855
|
+
);
|
|
20856
|
+
} catch (error) {
|
|
20857
|
+
if (error instanceof StartImportError) {
|
|
20858
|
+
throw new Error(error.code);
|
|
20859
|
+
}
|
|
20860
|
+
throw error;
|
|
20861
|
+
}
|
|
20862
|
+
};
|
|
20863
|
+
mutations[`${tableNameSingular}CancelImport`] = async (_, args, context, info) => {
|
|
20864
|
+
if (!context.user) {
|
|
20865
|
+
throw new Error("NOT_AUTHORIZED");
|
|
20866
|
+
}
|
|
20867
|
+
const queue = await getImportQueue();
|
|
20868
|
+
try {
|
|
20869
|
+
return await cancelImport(
|
|
20870
|
+
{
|
|
20871
|
+
db: context.db,
|
|
20872
|
+
config,
|
|
20873
|
+
queue,
|
|
20874
|
+
user: context.user,
|
|
20875
|
+
contextExists: (id) => contexts.some((c) => c.id === id)
|
|
20876
|
+
},
|
|
20877
|
+
args.jobResultId
|
|
20878
|
+
);
|
|
20879
|
+
} catch (error) {
|
|
20880
|
+
if (error instanceof StartImportError) {
|
|
20881
|
+
throw new Error(error.code);
|
|
20882
|
+
}
|
|
20883
|
+
throw error;
|
|
20884
|
+
}
|
|
20885
|
+
};
|
|
20195
20886
|
mutations[`${tableNameSingular}GenerateChunks`] = async (_, args, context, info) => {
|
|
20196
20887
|
const { db: db2 } = await postgresClient();
|
|
20197
20888
|
const exists = contexts.find((context2) => context2.id === table.id);
|
|
@@ -20394,9 +21085,9 @@ function createMutations(table, contexts, tools, config) {
|
|
|
20394
21085
|
rebuild: result.case,
|
|
20395
21086
|
itemsQueued: result.items
|
|
20396
21087
|
};
|
|
20397
|
-
} catch (
|
|
21088
|
+
} catch (err4) {
|
|
20398
21089
|
ctx.embedder = previous;
|
|
20399
|
-
throw
|
|
21090
|
+
throw err4;
|
|
20400
21091
|
}
|
|
20401
21092
|
};
|
|
20402
21093
|
mutations[`${tableNameSingular}ExtractEntities`] = async (_, args, context) => {
|
|
@@ -20432,9 +21123,9 @@ function createMutations(table, contexts, tools, config) {
|
|
|
20432
21123
|
if (!Array.isArray(ids) || ids.length === 0) {
|
|
20433
21124
|
throw new Error("ids is required and must be a non-empty array.");
|
|
20434
21125
|
}
|
|
20435
|
-
if (!
|
|
21126
|
+
if (!VALID_RIGHTS_MODES3.includes(rights_mode)) {
|
|
20436
21127
|
throw new Error(
|
|
20437
|
-
`Invalid rights_mode "${rights_mode}" \u2014 expected one of: ${
|
|
21128
|
+
`Invalid rights_mode "${rights_mode}" \u2014 expected one of: ${VALID_RIGHTS_MODES3.join(", ")}`
|
|
20438
21129
|
);
|
|
20439
21130
|
}
|
|
20440
21131
|
for (const id of ids) {
|
|
@@ -20484,9 +21175,7 @@ function createMutations(table, contexts, tools, config) {
|
|
|
20484
21175
|
if (!inner) continue;
|
|
20485
21176
|
mutations[key] = async (parent, args, context, info) => {
|
|
20486
21177
|
if (context?.user?.super_admin !== true) {
|
|
20487
|
-
throw new Error(
|
|
20488
|
-
`${table.name.plural} rows are changed through their own API; the generic mutation is reserved for super admins.`
|
|
20489
|
-
);
|
|
21178
|
+
throw new Error(`${table.name.plural} rows may only be changed by super admins through this API.`);
|
|
20490
21179
|
}
|
|
20491
21180
|
return inner(parent, args, context, info);
|
|
20492
21181
|
};
|
|
@@ -20516,12 +21205,12 @@ var bullmq = {
|
|
|
20516
21205
|
if (!data.inputs) {
|
|
20517
21206
|
throw new Error(`Missing property "inputs" in data for job ${id}.`);
|
|
20518
21207
|
}
|
|
20519
|
-
if (data.type !== "embedder" && data.type !== "workflow" && data.type !== "processor" && data.type !== "eval_run" && data.type !== "eval_function" && data.type !== "source" && data.type !== "email_intake") {
|
|
21208
|
+
if (data.type !== "embedder" && data.type !== "workflow" && data.type !== "processor" && data.type !== "eval_run" && data.type !== "eval_function" && data.type !== "source" && data.type !== "email_intake" && data.type !== "import") {
|
|
20520
21209
|
throw new Error(
|
|
20521
|
-
`Property "type" in data for job ${id} must be of value "embedder", "workflow", "processor", "eval_run", "eval_function", "source" or "
|
|
21210
|
+
`Property "type" in data for job ${id} must be of value "embedder", "workflow", "processor", "eval_run", "eval_function", "source", "email_intake" or "import".`
|
|
20522
21211
|
);
|
|
20523
21212
|
}
|
|
20524
|
-
if (data.type !== "email_intake" && !data.workflow && !data.embedder && !data.processor && !data.eval_run_id && !data.eval_functions?.length && !data.source) {
|
|
21213
|
+
if (data.type !== "email_intake" && data.type !== "import" && !data.workflow && !data.embedder && !data.processor && !data.eval_run_id && !data.eval_functions?.length && !data.source) {
|
|
20525
21214
|
throw new Error(
|
|
20526
21215
|
`Either a workflow, embedder, processor, eval_run, eval_functions or source must be set for job ${id}.`
|
|
20527
21216
|
);
|
|
@@ -20529,37 +21218,6 @@ var bullmq = {
|
|
|
20529
21218
|
}
|
|
20530
21219
|
};
|
|
20531
21220
|
|
|
20532
|
-
// src/utils/serialize-error.ts
|
|
20533
|
-
init_cjs_shims();
|
|
20534
|
-
var MAX_CAUSE_DEPTH = 3;
|
|
20535
|
-
function serializeError(err3, depth = 0) {
|
|
20536
|
-
if (err3 instanceof Error) {
|
|
20537
|
-
const out = { name: err3.name, message: err3.message };
|
|
20538
|
-
if (err3.stack) out.stack = err3.stack;
|
|
20539
|
-
for (const [key, value] of Object.entries(err3)) {
|
|
20540
|
-
if (key !== "cause") out[key] = value;
|
|
20541
|
-
}
|
|
20542
|
-
const cause = err3.cause;
|
|
20543
|
-
if (cause !== void 0 && depth < MAX_CAUSE_DEPTH) {
|
|
20544
|
-
out.cause = serializeError(cause, depth + 1);
|
|
20545
|
-
}
|
|
20546
|
-
return out;
|
|
20547
|
-
}
|
|
20548
|
-
if (typeof err3 === "string") {
|
|
20549
|
-
return { message: err3 };
|
|
20550
|
-
}
|
|
20551
|
-
if (err3 !== null && typeof err3 === "object") {
|
|
20552
|
-
let message;
|
|
20553
|
-
try {
|
|
20554
|
-
message = JSON.stringify(err3);
|
|
20555
|
-
} catch {
|
|
20556
|
-
message = "[unserializable error object]";
|
|
20557
|
-
}
|
|
20558
|
-
return { ...err3, message };
|
|
20559
|
-
}
|
|
20560
|
-
return { message: String(err3) };
|
|
20561
|
-
}
|
|
20562
|
-
|
|
20563
21221
|
// src/exulu/turn-metadata.ts
|
|
20564
21222
|
init_cjs_shims();
|
|
20565
21223
|
function finishTurnMetadata(opts) {
|
|
@@ -20695,8 +21353,8 @@ async function resolveFreshFileUrl(url, opts) {
|
|
|
20695
21353
|
if (!location) return url;
|
|
20696
21354
|
try {
|
|
20697
21355
|
return await opts.sign(location.bucket, location.key);
|
|
20698
|
-
} catch (
|
|
20699
|
-
console.warn(`[EXULU] could not re-sign stored file URL for key "${location.key}":`,
|
|
21356
|
+
} catch (err4) {
|
|
21357
|
+
console.warn(`[EXULU] could not re-sign stored file URL for key "${location.key}":`, err4);
|
|
20700
21358
|
return url;
|
|
20701
21359
|
}
|
|
20702
21360
|
}
|
|
@@ -20747,8 +21405,8 @@ async function loadSessionFileListing(opts) {
|
|
|
20747
21405
|
lastModified: new Date(o.lastModified)
|
|
20748
21406
|
}));
|
|
20749
21407
|
return describeSessionFiles(files, { lastTurnAt: opts.lastTurnAt });
|
|
20750
|
-
} catch (
|
|
20751
|
-
console.warn(`[EXULU] could not list session files for prompt (session ${opts.sessionID}):`,
|
|
21408
|
+
} catch (err4) {
|
|
21409
|
+
console.warn(`[EXULU] could not list session files for prompt (session ${opts.sessionID}):`, err4);
|
|
20752
21410
|
return "";
|
|
20753
21411
|
}
|
|
20754
21412
|
}
|
|
@@ -21230,7 +21888,7 @@ async function recordMemoryUsage(input) {
|
|
|
21230
21888
|
}
|
|
21231
21889
|
|
|
21232
21890
|
// src/exulu/generate-stream.ts
|
|
21233
|
-
var
|
|
21891
|
+
var import_node_crypto9 = require("crypto");
|
|
21234
21892
|
var processFilePartsInMessages = async (messages, offloadCtx) => {
|
|
21235
21893
|
const processedMessages = await Promise.all(
|
|
21236
21894
|
messages.map(async (message) => {
|
|
@@ -21633,7 +22291,7 @@ When a tool execution is not approved by the user, do not retry it unless explic
|
|
|
21633
22291
|
contextId: agent.memory,
|
|
21634
22292
|
agentId: agent.id,
|
|
21635
22293
|
session: session ?? null,
|
|
21636
|
-
messageId: output.response?.id ?? (0,
|
|
22294
|
+
messageId: output.response?.id ?? (0, import_node_crypto9.randomUUID)(),
|
|
21637
22295
|
userId: user?.id ?? null
|
|
21638
22296
|
});
|
|
21639
22297
|
}
|
|
@@ -21708,7 +22366,7 @@ When a tool execution is not approved by the user, do not retry it unless explic
|
|
|
21708
22366
|
contextId: agent.memory,
|
|
21709
22367
|
agentId: agent.id,
|
|
21710
22368
|
session: session ?? null,
|
|
21711
|
-
messageId: response?.id ?? (0,
|
|
22369
|
+
messageId: response?.id ?? (0, import_node_crypto9.randomUUID)(),
|
|
21712
22370
|
userId: user?.id ?? null
|
|
21713
22371
|
});
|
|
21714
22372
|
}
|
|
@@ -22024,10 +22682,10 @@ function extractGlossaryFromAgentTools(tools) {
|
|
|
22024
22682
|
return glossary.filter(
|
|
22025
22683
|
(g) => !!g && typeof g.term === "string" && typeof g.meaning === "string" && g.term.trim().length > 0
|
|
22026
22684
|
);
|
|
22027
|
-
} catch (
|
|
22685
|
+
} catch (err4) {
|
|
22028
22686
|
console.warn(
|
|
22029
22687
|
"[EXULU] Failed to parse the agentic_context_search vocabulary config while building agent instructions.",
|
|
22030
|
-
|
|
22688
|
+
err4
|
|
22031
22689
|
);
|
|
22032
22690
|
return [];
|
|
22033
22691
|
}
|
|
@@ -22225,14 +22883,14 @@ init_singleton();
|
|
|
22225
22883
|
|
|
22226
22884
|
// src/exulu/email-inbound/intake.ts
|
|
22227
22885
|
init_cjs_shims();
|
|
22228
|
-
var
|
|
22886
|
+
var import_node_crypto12 = require("crypto");
|
|
22229
22887
|
init_client();
|
|
22230
22888
|
init_uppy();
|
|
22231
22889
|
init_singleton();
|
|
22232
22890
|
|
|
22233
22891
|
// src/exulu/email-inbound/normalize.ts
|
|
22234
22892
|
init_cjs_shims();
|
|
22235
|
-
var
|
|
22893
|
+
var import_node_crypto10 = require("crypto");
|
|
22236
22894
|
var import_mailparser = require("mailparser");
|
|
22237
22895
|
var htmlToText = (html) => html.replace(/<style[\s\S]*?<\/style>/gi, " ").replace(/<script[\s\S]*?<\/script>/gi, " ").replace(/<[^>]+>/g, " ").replace(/ /gi, " ").replace(/</gi, "<").replace(/>/gi, ">").replace(/&/gi, "&").replace(/\s+/g, " ").trim();
|
|
22238
22896
|
var headerValueToString = (value) => {
|
|
@@ -22273,7 +22931,7 @@ async function parseRawMime(raw) {
|
|
|
22273
22931
|
return {
|
|
22274
22932
|
// Message-ID is the dedup key (spec §4.4.5). A missing header gets a
|
|
22275
22933
|
// deterministic content hash so webhook/job retries still dedup.
|
|
22276
|
-
messageId: parsed.messageId ?? `generated-${(0,
|
|
22934
|
+
messageId: parsed.messageId ?? `generated-${(0, import_node_crypto10.createHash)("sha256").update(raw).digest("hex")}`,
|
|
22277
22935
|
from: {
|
|
22278
22936
|
address: fromEntry.address.toLowerCase(),
|
|
22279
22937
|
...fromEntry.name ? { name: fromEntry.name } : {}
|
|
@@ -22293,7 +22951,7 @@ async function parseRawMime(raw) {
|
|
|
22293
22951
|
|
|
22294
22952
|
// src/exulu/email-inbound/adapters.ts
|
|
22295
22953
|
init_cjs_shims();
|
|
22296
|
-
var
|
|
22954
|
+
var import_node_crypto11 = require("crypto");
|
|
22297
22955
|
var import_node_stream = require("stream");
|
|
22298
22956
|
var import_busboy = __toESM(require("busboy"), 1);
|
|
22299
22957
|
var htmlToText2 = (html) => html.replace(/<\s*(script|style)[^>]*>[\s\S]*?<\s*\/\s*\1\s*>/gi, "").replace(/<[^>]+>/g, " ").replace(/ /gi, " ").replace(/&/gi, "&").replace(/</gi, "<").replace(/>/gi, ">").replace(/\s+/g, " ").trim();
|
|
@@ -22338,7 +22996,7 @@ function extractMultipartMimePart(rawBody, contentType) {
|
|
|
22338
22996
|
if (found) resolve8(found);
|
|
22339
22997
|
else reject(new Error("No raw MIME part found (expected a body-mime, email, or message field)."));
|
|
22340
22998
|
});
|
|
22341
|
-
bb.on("error", (
|
|
22999
|
+
bb.on("error", (err4) => reject(err4 instanceof Error ? err4 : new Error(String(err4))));
|
|
22342
23000
|
import_node_stream.Readable.from(rawBody).pipe(bb);
|
|
22343
23001
|
});
|
|
22344
23002
|
}
|
|
@@ -22351,7 +23009,7 @@ function jsonToInboundEmail(raw) {
|
|
|
22351
23009
|
const subject = typeof obj.subject === "string" ? obj.subject : "";
|
|
22352
23010
|
const html = typeof obj.html === "string" ? obj.html : void 0;
|
|
22353
23011
|
const text = typeof obj.text === "string" && obj.text ? obj.text : html ? htmlToText2(html) : "";
|
|
22354
|
-
const messageId = typeof obj.message_id === "string" && obj.message_id ? obj.message_id : `<${(0,
|
|
23012
|
+
const messageId = typeof obj.message_id === "string" && obj.message_id ? obj.message_id : `<${(0, import_node_crypto11.randomUUID)()}@webhook.local>`;
|
|
22355
23013
|
const attachments = Array.isArray(obj.attachments) ? obj.attachments.map(decodeAttachment) : [];
|
|
22356
23014
|
const headers = /* @__PURE__ */ new Map([["message-id", messageId]]);
|
|
22357
23015
|
return {
|
|
@@ -22434,10 +23092,10 @@ var checkRateLimit = async (redis, key, limitPerHour, now = Date.now()) => {
|
|
|
22434
23092
|
const elapsedFraction = now % HOUR_MS / HOUR_MS;
|
|
22435
23093
|
const weighted = count + previous * (1 - elapsedFraction);
|
|
22436
23094
|
return weighted <= limitPerHour;
|
|
22437
|
-
} catch (
|
|
23095
|
+
} catch (err4) {
|
|
22438
23096
|
console.error(
|
|
22439
23097
|
"[EXULU] email-inbound rate limit: redis unavailable, allowing (best-effort)",
|
|
22440
|
-
|
|
23098
|
+
err4 instanceof Error ? err4.message : String(err4)
|
|
22441
23099
|
);
|
|
22442
23100
|
return true;
|
|
22443
23101
|
}
|
|
@@ -22589,7 +23247,7 @@ var fireRun = async (opts) => {
|
|
|
22589
23247
|
}
|
|
22590
23248
|
const fromDisplay = email.from.name ? `"${email.from.name}" <${email.from.address}>` : `<${email.from.address}>`;
|
|
22591
23249
|
const initialMessage = {
|
|
22592
|
-
id: (0,
|
|
23250
|
+
id: (0, import_node_crypto12.randomUUID)(),
|
|
22593
23251
|
role: "user",
|
|
22594
23252
|
parts: [
|
|
22595
23253
|
{
|
|
@@ -22773,6 +23431,426 @@ function computeRunCostUsd(inputTokens, outputTokens, price) {
|
|
|
22773
23431
|
return inTok / 1e6 * inPrice + outTok / 1e6 * outPrice;
|
|
22774
23432
|
}
|
|
22775
23433
|
|
|
23434
|
+
// ee/workers.ts
|
|
23435
|
+
init_uppy();
|
|
23436
|
+
|
|
23437
|
+
// src/exulu/import/run-import.ts
|
|
23438
|
+
init_cjs_shims();
|
|
23439
|
+
|
|
23440
|
+
// src/exulu/import/csv-stream.ts
|
|
23441
|
+
init_cjs_shims();
|
|
23442
|
+
var import_node_stream2 = require("stream");
|
|
23443
|
+
var import_csv_parse = require("csv-parse");
|
|
23444
|
+
var CANDIDATE_DELIMITERS = [",", ";", " ", "|"];
|
|
23445
|
+
var MAX_HEADER_BYTES = 64 * 1024;
|
|
23446
|
+
function sniffDelimiter(headerLine) {
|
|
23447
|
+
const counts = new Map(CANDIDATE_DELIMITERS.map((d) => [d, 0]));
|
|
23448
|
+
let inQuotes = false;
|
|
23449
|
+
for (const char of headerLine) {
|
|
23450
|
+
if (char === '"') {
|
|
23451
|
+
inQuotes = !inQuotes;
|
|
23452
|
+
continue;
|
|
23453
|
+
}
|
|
23454
|
+
if (inQuotes) continue;
|
|
23455
|
+
const seen = counts.get(char);
|
|
23456
|
+
if (seen !== void 0) counts.set(char, seen + 1);
|
|
23457
|
+
}
|
|
23458
|
+
let best = CANDIDATE_DELIMITERS[0];
|
|
23459
|
+
let bestCount = 0;
|
|
23460
|
+
for (const candidate of CANDIDATE_DELIMITERS) {
|
|
23461
|
+
const count = counts.get(candidate) ?? 0;
|
|
23462
|
+
if (count > bestCount) {
|
|
23463
|
+
best = candidate;
|
|
23464
|
+
bestCount = count;
|
|
23465
|
+
}
|
|
23466
|
+
}
|
|
23467
|
+
return best;
|
|
23468
|
+
}
|
|
23469
|
+
function createSniffer(onFirstLine) {
|
|
23470
|
+
const head = [];
|
|
23471
|
+
let headBytes = 0;
|
|
23472
|
+
let resolved = false;
|
|
23473
|
+
const resolve8 = (line) => {
|
|
23474
|
+
if (resolved) return;
|
|
23475
|
+
resolved = true;
|
|
23476
|
+
onFirstLine(line);
|
|
23477
|
+
};
|
|
23478
|
+
return new import_node_stream2.Transform({
|
|
23479
|
+
readableHighWaterMark: 4 * MAX_HEADER_BYTES,
|
|
23480
|
+
transform(chunk2, _encoding, callback) {
|
|
23481
|
+
if (!resolved) {
|
|
23482
|
+
const buffer = Buffer.isBuffer(chunk2) ? chunk2 : Buffer.from(String(chunk2));
|
|
23483
|
+
head.push(buffer);
|
|
23484
|
+
headBytes += buffer.length;
|
|
23485
|
+
const text = Buffer.concat(head).toString("utf-8");
|
|
23486
|
+
const eol = /\r|\n/.exec(text);
|
|
23487
|
+
if (eol) {
|
|
23488
|
+
resolve8(text.slice(0, eol.index));
|
|
23489
|
+
} else if (headBytes >= MAX_HEADER_BYTES) {
|
|
23490
|
+
resolve8(text);
|
|
23491
|
+
}
|
|
23492
|
+
}
|
|
23493
|
+
callback(null, chunk2);
|
|
23494
|
+
},
|
|
23495
|
+
flush(callback) {
|
|
23496
|
+
resolve8(Buffer.concat(head).toString("utf-8"));
|
|
23497
|
+
callback();
|
|
23498
|
+
}
|
|
23499
|
+
});
|
|
23500
|
+
}
|
|
23501
|
+
async function streamCsvRows(input, handlers, opts) {
|
|
23502
|
+
let resolveFirstLine = () => {
|
|
23503
|
+
};
|
|
23504
|
+
const firstLine = new Promise((resolve8) => {
|
|
23505
|
+
resolveFirstLine = resolve8;
|
|
23506
|
+
});
|
|
23507
|
+
const sniffer = createSniffer((line) => resolveFirstLine(line));
|
|
23508
|
+
let parser;
|
|
23509
|
+
let earlyError;
|
|
23510
|
+
input.on("error", (err4) => sniffer.destroy(err4));
|
|
23511
|
+
sniffer.on("error", (err4) => {
|
|
23512
|
+
if (parser) parser.destroy(err4);
|
|
23513
|
+
else {
|
|
23514
|
+
earlyError = err4;
|
|
23515
|
+
resolveFirstLine("");
|
|
23516
|
+
}
|
|
23517
|
+
});
|
|
23518
|
+
input.pipe(sniffer);
|
|
23519
|
+
const headerLine = await firstLine;
|
|
23520
|
+
if (earlyError) throw earlyError;
|
|
23521
|
+
const delimiter = opts?.delimiter ?? sniffDelimiter(headerLine);
|
|
23522
|
+
parser = (0, import_csv_parse.parse)({
|
|
23523
|
+
bom: true,
|
|
23524
|
+
relax_quotes: true,
|
|
23525
|
+
relax_column_count: true,
|
|
23526
|
+
skip_empty_lines: true,
|
|
23527
|
+
columns: false,
|
|
23528
|
+
delimiter,
|
|
23529
|
+
// csv-parse's auto record-delimiter discovery locks onto the first
|
|
23530
|
+
// line ending it sees (outside quotes) and never reconsiders -- a file
|
|
23531
|
+
// whose header ends in "\n" but has later rows ending in "\r\n" (or
|
|
23532
|
+
// vice versa) would then have the "\r" leak into field content instead
|
|
23533
|
+
// of being recognized as part of the delimiter. Listing all three EOL
|
|
23534
|
+
// styles up front avoids that trap for real-world, possibly
|
|
23535
|
+
// inconsistently-terminated uploads.
|
|
23536
|
+
record_delimiter: ["\r\n", "\n", "\r"]
|
|
23537
|
+
});
|
|
23538
|
+
sniffer.pipe(parser);
|
|
23539
|
+
let sawHeader = false;
|
|
23540
|
+
let index = 0;
|
|
23541
|
+
for await (const record of parser) {
|
|
23542
|
+
if (!sawHeader) {
|
|
23543
|
+
sawHeader = true;
|
|
23544
|
+
await handlers.onHeader(record.map((cell) => cell.trim()));
|
|
23545
|
+
continue;
|
|
23546
|
+
}
|
|
23547
|
+
if (record.every((cell) => cell.trim() === "")) continue;
|
|
23548
|
+
await handlers.onRow(record, index);
|
|
23549
|
+
index++;
|
|
23550
|
+
}
|
|
23551
|
+
return { rows: index };
|
|
23552
|
+
}
|
|
23553
|
+
|
|
23554
|
+
// src/exulu/import/mapping.ts
|
|
23555
|
+
init_cjs_shims();
|
|
23556
|
+
init_sanitize_name();
|
|
23557
|
+
function normalizeHeader(value) {
|
|
23558
|
+
return value.trim().toLowerCase().replace(/[\s-]+/g, "_");
|
|
23559
|
+
}
|
|
23560
|
+
function headerMatchesField(field, normalizedHeader) {
|
|
23561
|
+
if (normalizeHeader(field.name) === normalizedHeader) return true;
|
|
23562
|
+
return field.label != null && normalizeHeader(field.label) === normalizedHeader;
|
|
23563
|
+
}
|
|
23564
|
+
function autoMapColumns(headers, fields) {
|
|
23565
|
+
const used = /* @__PURE__ */ new Set();
|
|
23566
|
+
return headers.map((header2) => {
|
|
23567
|
+
const normalized = normalizeHeader(header2);
|
|
23568
|
+
const match = fields.find((f) => !used.has(f.name) && headerMatchesField(f, normalized));
|
|
23569
|
+
if (!match) return { header: header2, fieldName: null };
|
|
23570
|
+
used.add(match.name);
|
|
23571
|
+
return { header: header2, fieldName: match.name };
|
|
23572
|
+
});
|
|
23573
|
+
}
|
|
23574
|
+
var CORE_FIELDS = [
|
|
23575
|
+
{ name: "id", type: "text", core: true },
|
|
23576
|
+
{ name: "external_id", type: "text", core: true },
|
|
23577
|
+
{ name: "name", type: "shortText", required: true, core: true },
|
|
23578
|
+
{ name: "description", type: "longText", core: true },
|
|
23579
|
+
{ name: "tags", type: "text", core: true }
|
|
23580
|
+
];
|
|
23581
|
+
function importFieldsFor(fields) {
|
|
23582
|
+
const custom = fields.filter((f) => !f.calculated && !f.hidden && f.type !== "file").map((f) => ({
|
|
23583
|
+
name: sanitizeName(f.name),
|
|
23584
|
+
label: f.name,
|
|
23585
|
+
type: f.type,
|
|
23586
|
+
required: f.required === true,
|
|
23587
|
+
core: false,
|
|
23588
|
+
enumValues: f.enumValues
|
|
23589
|
+
}));
|
|
23590
|
+
return [...CORE_FIELDS, ...custom];
|
|
23591
|
+
}
|
|
23592
|
+
function resolveMapping(headers, fields, given) {
|
|
23593
|
+
if (!given) {
|
|
23594
|
+
return { byIndex: autoMapColumns(headers, fields).map((m) => m.fieldName), unknownFields: [] };
|
|
23595
|
+
}
|
|
23596
|
+
const fieldNames = new Set(fields.map((f) => f.name));
|
|
23597
|
+
const byHeader = new Map(given.map((g) => [normalizeHeader(g.header), g.fieldName]));
|
|
23598
|
+
const unknownFields = /* @__PURE__ */ new Set();
|
|
23599
|
+
const byIndex = headers.map((header2) => {
|
|
23600
|
+
const fieldName = byHeader.get(normalizeHeader(header2));
|
|
23601
|
+
if (fieldName == null) return null;
|
|
23602
|
+
if (!fieldNames.has(fieldName)) {
|
|
23603
|
+
unknownFields.add(fieldName);
|
|
23604
|
+
return null;
|
|
23605
|
+
}
|
|
23606
|
+
return fieldName;
|
|
23607
|
+
});
|
|
23608
|
+
return { byIndex, unknownFields: [...unknownFields] };
|
|
23609
|
+
}
|
|
23610
|
+
|
|
23611
|
+
// src/exulu/import/run-import.ts
|
|
23612
|
+
var ABORT_MESSAGES = {
|
|
23613
|
+
NO_MAPPABLE_COLUMNS: "No column in the file maps to a usable field (name, id, or external_id).",
|
|
23614
|
+
EMPTY_FILE: "The file has no header row."
|
|
23615
|
+
};
|
|
23616
|
+
var ImportAbort = class extends Error {
|
|
23617
|
+
constructor(code) {
|
|
23618
|
+
super(ABORT_MESSAGES[code]);
|
|
23619
|
+
this.code = code;
|
|
23620
|
+
this.name = "ImportAbort";
|
|
23621
|
+
}
|
|
23622
|
+
};
|
|
23623
|
+
var DEFAULT_CHUNK_ROWS = 500;
|
|
23624
|
+
var DEFAULT_CONCURRENCY = 8;
|
|
23625
|
+
var DEFAULT_PROGRESS_INTERVAL_MS = 1e4;
|
|
23626
|
+
var IMPORT_MAX_ERROR_LINES = 5e4;
|
|
23627
|
+
var RunCancelled = class extends Error {
|
|
23628
|
+
};
|
|
23629
|
+
function csvField(value) {
|
|
23630
|
+
return /["\n\r,]/.test(value) ? `"${value.replace(/"/g, '""')}"` : value;
|
|
23631
|
+
}
|
|
23632
|
+
function csvLine(cells) {
|
|
23633
|
+
return cells.map(csvField).join(",");
|
|
23634
|
+
}
|
|
23635
|
+
async function runPool(items, concurrency, worker) {
|
|
23636
|
+
let next = 0;
|
|
23637
|
+
const runners = Array.from({ length: Math.min(concurrency, items.length) }, async () => {
|
|
23638
|
+
while (next < items.length) {
|
|
23639
|
+
const index = next;
|
|
23640
|
+
next += 1;
|
|
23641
|
+
await worker(items[index]);
|
|
23642
|
+
}
|
|
23643
|
+
});
|
|
23644
|
+
await Promise.all(runners);
|
|
23645
|
+
}
|
|
23646
|
+
async function runImport(deps) {
|
|
23647
|
+
const now = deps.now ?? Date.now;
|
|
23648
|
+
const log7 = deps.log ?? (() => {
|
|
23649
|
+
});
|
|
23650
|
+
const chunkRows = deps.chunkRows ?? DEFAULT_CHUNK_ROWS;
|
|
23651
|
+
const concurrency = deps.concurrency ?? DEFAULT_CONCURRENCY;
|
|
23652
|
+
const progressIntervalMs = deps.progressIntervalMs ?? DEFAULT_PROGRESS_INTERVAL_MS;
|
|
23653
|
+
const maxErrorLines = deps.maxErrorLines ?? IMPORT_MAX_ERROR_LINES;
|
|
23654
|
+
const startedAt = now();
|
|
23655
|
+
const metadata = {
|
|
23656
|
+
total: deps.total ?? null,
|
|
23657
|
+
processed: 0,
|
|
23658
|
+
created: 0,
|
|
23659
|
+
updated: 0,
|
|
23660
|
+
failed: 0,
|
|
23661
|
+
invalid: 0
|
|
23662
|
+
};
|
|
23663
|
+
let cancelled = false;
|
|
23664
|
+
let headerSeen = false;
|
|
23665
|
+
let headerCells = [];
|
|
23666
|
+
let byIndex = [];
|
|
23667
|
+
const errorLines = [];
|
|
23668
|
+
let truncatedErrorCount = 0;
|
|
23669
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
23670
|
+
const seenExternalIds = /* @__PURE__ */ new Set();
|
|
23671
|
+
let buffer = [];
|
|
23672
|
+
let lastTickAt = startedAt;
|
|
23673
|
+
function pushErrorLine(cells, message) {
|
|
23674
|
+
if (errorLines.length < maxErrorLines) {
|
|
23675
|
+
errorLines.push(csvLine([...cells, message]));
|
|
23676
|
+
} else {
|
|
23677
|
+
truncatedErrorCount++;
|
|
23678
|
+
}
|
|
23679
|
+
}
|
|
23680
|
+
async function runCreate(row, cells) {
|
|
23681
|
+
try {
|
|
23682
|
+
await deps.createItem(buildCreateInput(row, deps.access));
|
|
23683
|
+
metadata.created++;
|
|
23684
|
+
} catch (e) {
|
|
23685
|
+
metadata.failed++;
|
|
23686
|
+
pushErrorLine(cells, e instanceof Error ? e.message : String(e));
|
|
23687
|
+
}
|
|
23688
|
+
}
|
|
23689
|
+
async function runUpdate(existing, row, cells) {
|
|
23690
|
+
let allowed;
|
|
23691
|
+
try {
|
|
23692
|
+
allowed = deps.canWrite(existing);
|
|
23693
|
+
} catch (e) {
|
|
23694
|
+
metadata.failed++;
|
|
23695
|
+
pushErrorLine(cells, e instanceof Error ? e.message : String(e));
|
|
23696
|
+
return;
|
|
23697
|
+
}
|
|
23698
|
+
if (!allowed) {
|
|
23699
|
+
metadata.failed++;
|
|
23700
|
+
pushErrorLine(cells, "no write access");
|
|
23701
|
+
return;
|
|
23702
|
+
}
|
|
23703
|
+
try {
|
|
23704
|
+
await deps.updateItem(existing.id, buildUpdateInput(row));
|
|
23705
|
+
metadata.updated++;
|
|
23706
|
+
} catch (e) {
|
|
23707
|
+
metadata.failed++;
|
|
23708
|
+
pushErrorLine(cells, e instanceof Error ? e.message : String(e));
|
|
23709
|
+
}
|
|
23710
|
+
}
|
|
23711
|
+
async function processChunk(chunk2) {
|
|
23712
|
+
if (chunk2.length === 0) return;
|
|
23713
|
+
const toCreate = [];
|
|
23714
|
+
const toUpdate = [];
|
|
23715
|
+
for (const { index, cells } of chunk2) {
|
|
23716
|
+
metadata.processed++;
|
|
23717
|
+
try {
|
|
23718
|
+
const row = buildRow(index, cells, byIndex, deps.fields);
|
|
23719
|
+
if (!rowIsValid(row)) {
|
|
23720
|
+
metadata.invalid++;
|
|
23721
|
+
pushErrorLine(cells, row.errors.join("; "));
|
|
23722
|
+
continue;
|
|
23723
|
+
}
|
|
23724
|
+
const action = rowAction(row);
|
|
23725
|
+
if (action.action === "create") {
|
|
23726
|
+
toCreate.push({ row, cells });
|
|
23727
|
+
continue;
|
|
23728
|
+
}
|
|
23729
|
+
const seen = action.by === "id" ? seenIds : seenExternalIds;
|
|
23730
|
+
if (seen.has(action.key)) {
|
|
23731
|
+
metadata.invalid++;
|
|
23732
|
+
pushErrorLine(cells, `duplicateKey:${action.by}`);
|
|
23733
|
+
continue;
|
|
23734
|
+
}
|
|
23735
|
+
seen.add(action.key);
|
|
23736
|
+
toUpdate.push({ row, by: action.by, key: action.key, cells });
|
|
23737
|
+
} catch (e) {
|
|
23738
|
+
metadata.failed++;
|
|
23739
|
+
pushErrorLine(cells, e instanceof Error ? e.message : String(e));
|
|
23740
|
+
}
|
|
23741
|
+
}
|
|
23742
|
+
const ids = toUpdate.filter((u) => u.by === "id").map((u) => u.key);
|
|
23743
|
+
const externalIds = toUpdate.filter((u) => u.by === "external_id").map((u) => u.key);
|
|
23744
|
+
let existingRows;
|
|
23745
|
+
try {
|
|
23746
|
+
existingRows = ids.length > 0 || externalIds.length > 0 ? await deps.lookupExisting(ids, externalIds) : [];
|
|
23747
|
+
} catch (e) {
|
|
23748
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
23749
|
+
for (const { cells } of toCreate) {
|
|
23750
|
+
metadata.failed++;
|
|
23751
|
+
pushErrorLine(cells, message);
|
|
23752
|
+
}
|
|
23753
|
+
for (const u of toUpdate) {
|
|
23754
|
+
metadata.failed++;
|
|
23755
|
+
pushErrorLine(u.cells, message);
|
|
23756
|
+
}
|
|
23757
|
+
return;
|
|
23758
|
+
}
|
|
23759
|
+
const byId = new Map(existingRows.map((r) => [r.id, r]));
|
|
23760
|
+
const byExternalId = new Map(
|
|
23761
|
+
existingRows.filter((r) => r.external_id != null).map((r) => [r.external_id, r])
|
|
23762
|
+
);
|
|
23763
|
+
const tasks = [];
|
|
23764
|
+
for (const { row, cells } of toCreate) {
|
|
23765
|
+
tasks.push(() => runCreate(row, cells));
|
|
23766
|
+
}
|
|
23767
|
+
for (const u of toUpdate) {
|
|
23768
|
+
const existing = u.by === "id" ? byId.get(u.key) : byExternalId.get(u.key);
|
|
23769
|
+
if (existing) {
|
|
23770
|
+
tasks.push(() => runUpdate(existing, u.row, u.cells));
|
|
23771
|
+
continue;
|
|
23772
|
+
}
|
|
23773
|
+
if (u.by === "id") {
|
|
23774
|
+
metadata.failed++;
|
|
23775
|
+
pushErrorLine(u.cells, "id not found");
|
|
23776
|
+
continue;
|
|
23777
|
+
}
|
|
23778
|
+
tasks.push(() => runCreate(u.row, u.cells));
|
|
23779
|
+
}
|
|
23780
|
+
await runPool(tasks, concurrency, (task) => task());
|
|
23781
|
+
}
|
|
23782
|
+
async function tick3() {
|
|
23783
|
+
lastTickAt = now();
|
|
23784
|
+
await deps.writeProgress({ ...metadata });
|
|
23785
|
+
}
|
|
23786
|
+
try {
|
|
23787
|
+
await streamCsvRows(
|
|
23788
|
+
deps.stream,
|
|
23789
|
+
{
|
|
23790
|
+
onHeader: (headers) => {
|
|
23791
|
+
headerSeen = true;
|
|
23792
|
+
headerCells = headers;
|
|
23793
|
+
const resolved = resolveMapping(headers, deps.fields, deps.mapping);
|
|
23794
|
+
byIndex = resolved.byIndex;
|
|
23795
|
+
const nameMapped = byIndex.includes("name");
|
|
23796
|
+
const keyMapped = byIndex.includes("id") || byIndex.includes("external_id");
|
|
23797
|
+
const allUnmapped = byIndex.every((f) => f === null);
|
|
23798
|
+
if (allUnmapped || !nameMapped && !keyMapped) {
|
|
23799
|
+
throw new ImportAbort("NO_MAPPABLE_COLUMNS");
|
|
23800
|
+
}
|
|
23801
|
+
},
|
|
23802
|
+
onRow: async (cells, index) => {
|
|
23803
|
+
buffer.push({ index, cells });
|
|
23804
|
+
const intervalElapsed = now() - lastTickAt >= progressIntervalMs;
|
|
23805
|
+
if (buffer.length < chunkRows && !intervalElapsed) return;
|
|
23806
|
+
const chunk2 = buffer;
|
|
23807
|
+
buffer = [];
|
|
23808
|
+
await processChunk(chunk2);
|
|
23809
|
+
await tick3();
|
|
23810
|
+
if (await deps.isCancelRequested()) {
|
|
23811
|
+
cancelled = true;
|
|
23812
|
+
log7(`import: cancelled after ${metadata.processed} rows`);
|
|
23813
|
+
throw new RunCancelled();
|
|
23814
|
+
}
|
|
23815
|
+
}
|
|
23816
|
+
},
|
|
23817
|
+
{ delimiter: deps.options.delimiter }
|
|
23818
|
+
);
|
|
23819
|
+
} catch (e) {
|
|
23820
|
+
if (!(e instanceof RunCancelled)) throw e;
|
|
23821
|
+
}
|
|
23822
|
+
if (!headerSeen) {
|
|
23823
|
+
throw new ImportAbort("EMPTY_FILE");
|
|
23824
|
+
}
|
|
23825
|
+
if (!cancelled && buffer.length > 0) {
|
|
23826
|
+
const chunk2 = buffer;
|
|
23827
|
+
buffer = [];
|
|
23828
|
+
await processChunk(chunk2);
|
|
23829
|
+
await tick3();
|
|
23830
|
+
}
|
|
23831
|
+
const errorReportTruncated = truncatedErrorCount > 0;
|
|
23832
|
+
let errorReportKey = null;
|
|
23833
|
+
if (errorLines.length > 0 || errorReportTruncated) {
|
|
23834
|
+
const lines = [csvLine([...headerCells, "import_error"]), ...errorLines];
|
|
23835
|
+
if (errorReportTruncated) {
|
|
23836
|
+
const markerPadding = Array(Math.max(headerCells.length - 1, 0)).fill("");
|
|
23837
|
+
lines.push(csvLine(["\u2026", ...markerPadding, `truncated: ${truncatedErrorCount} more rows not listed`]));
|
|
23838
|
+
}
|
|
23839
|
+
const csv = "\uFEFF" + lines.join("\n");
|
|
23840
|
+
errorReportKey = await deps.uploadErrorReport(csv);
|
|
23841
|
+
}
|
|
23842
|
+
log7(
|
|
23843
|
+
`import: completed -- processed ${metadata.processed}, created ${metadata.created}, updated ${metadata.updated}, failed ${metadata.failed}, invalid ${metadata.invalid}`
|
|
23844
|
+
);
|
|
23845
|
+
return {
|
|
23846
|
+
...metadata,
|
|
23847
|
+
durationMs: now() - startedAt,
|
|
23848
|
+
errorReportKey,
|
|
23849
|
+
cancelled,
|
|
23850
|
+
errorReportTruncated
|
|
23851
|
+
};
|
|
23852
|
+
}
|
|
23853
|
+
|
|
22776
23854
|
// ee/workers.ts
|
|
22777
23855
|
var FlowStepError = class extends Error {
|
|
22778
23856
|
stepIndex;
|
|
@@ -22883,7 +23961,7 @@ var createWorkers = async (queues2, config, contexts, evals, tools, tracer) => {
|
|
|
22883
23961
|
type: bullmqJob.data.type
|
|
22884
23962
|
});
|
|
22885
23963
|
let progressInterval;
|
|
22886
|
-
if (bullmqJob.data.type === "processor") {
|
|
23964
|
+
if (bullmqJob.data.type === "processor" || bullmqJob.data.type === "import") {
|
|
22887
23965
|
progressInterval = setInterval(async () => {
|
|
22888
23966
|
try {
|
|
22889
23967
|
await bullmqJob.updateProgress({
|
|
@@ -23537,6 +24615,97 @@ var createWorkers = async (queues2, config, contexts, evals, tools, tracer) => {
|
|
|
23537
24615
|
}
|
|
23538
24616
|
};
|
|
23539
24617
|
}
|
|
24618
|
+
if (data.type === "import") {
|
|
24619
|
+
console.log("[EXULU] running a server-side bulk import job.", bullmqJob.name);
|
|
24620
|
+
if (!data.jobResultId) {
|
|
24621
|
+
throw new Error(`No jobResultId set for import job ${bullmqJob.id}.`);
|
|
24622
|
+
}
|
|
24623
|
+
if (!data.context) {
|
|
24624
|
+
throw new Error(`No context id set for import job ${bullmqJob.id}.`);
|
|
24625
|
+
}
|
|
24626
|
+
const importData = {
|
|
24627
|
+
type: "import",
|
|
24628
|
+
jobResultId: data.jobResultId,
|
|
24629
|
+
context: data.context,
|
|
24630
|
+
user: data.user,
|
|
24631
|
+
role: data.role
|
|
24632
|
+
};
|
|
24633
|
+
const jobResultId = importData.jobResultId;
|
|
24634
|
+
const row = await db2.from("job_results").where({ id: jobResultId }).first();
|
|
24635
|
+
if (!row) {
|
|
24636
|
+
throw new Error(
|
|
24637
|
+
`job_results row ${jobResultId} not found for import job ${bullmqJob.id}.`
|
|
24638
|
+
);
|
|
24639
|
+
}
|
|
24640
|
+
const priorMetadata = parseMetadata(row.metadata);
|
|
24641
|
+
const priorProcessed = Number(priorMetadata.processed ?? 0);
|
|
24642
|
+
if (row.state === JOB_STATUS_ENUM.active || priorProcessed > 0) {
|
|
24643
|
+
throw new Error(
|
|
24644
|
+
`IMPORT_RESTARTED_AFTER_STALL: import ${jobResultId} was already running; partial rows are kept, start a new import`
|
|
24645
|
+
);
|
|
24646
|
+
}
|
|
24647
|
+
await upsertJobStart(db2, bullmqJob, row.label, "import");
|
|
24648
|
+
const context = contexts.find((c) => c.id === importData.context);
|
|
24649
|
+
if (!context) {
|
|
24650
|
+
throw new Error(`Context ${importData.context} not found in the registry.`);
|
|
24651
|
+
}
|
|
24652
|
+
const triggerMetadata = parseRunMetadata(row.trigger_metadata);
|
|
24653
|
+
if (!triggerMetadata.s3Key) {
|
|
24654
|
+
throw new Error(
|
|
24655
|
+
`No s3Key recorded on job_results row ${jobResultId} for import job.`
|
|
24656
|
+
);
|
|
24657
|
+
}
|
|
24658
|
+
if (!triggerMetadata.access) {
|
|
24659
|
+
throw new Error(
|
|
24660
|
+
`No batch access recorded on job_results row ${jobResultId} for import job.`
|
|
24661
|
+
);
|
|
24662
|
+
}
|
|
24663
|
+
const snap = triggerMetadata.user;
|
|
24664
|
+
const importUser = snap && typeof snap === "object" ? {
|
|
24665
|
+
id: Number(snap.id),
|
|
24666
|
+
super_admin: snap.super_admin === true,
|
|
24667
|
+
role: snap.role,
|
|
24668
|
+
team: snap.team
|
|
24669
|
+
} : { id: Number(snap ?? importData.user), role: importData.role };
|
|
24670
|
+
if (!importUser.id) {
|
|
24671
|
+
throw new Error(`No acting user recorded for import job ${bullmqJob.id}.`);
|
|
24672
|
+
}
|
|
24673
|
+
const bareS3Key = triggerMetadata.s3Key.slice(triggerMetadata.s3Key.indexOf("/") + 1);
|
|
24674
|
+
const stream = await getS3ObjectStream(bareS3Key, config);
|
|
24675
|
+
try {
|
|
24676
|
+
const deps = buildWorkerDeps({
|
|
24677
|
+
db: db2,
|
|
24678
|
+
config,
|
|
24679
|
+
context,
|
|
24680
|
+
contextId: importData.context,
|
|
24681
|
+
jobResultId,
|
|
24682
|
+
stream,
|
|
24683
|
+
fields: importFieldsFor(context.fields),
|
|
24684
|
+
mapping: triggerMetadata.mapping,
|
|
24685
|
+
access: triggerMetadata.access,
|
|
24686
|
+
options: triggerMetadata.options ?? {},
|
|
24687
|
+
user: importUser,
|
|
24688
|
+
log: (m) => console.log(`[EXULU] import ${jobResultId}: ${m}`),
|
|
24689
|
+
// The row count StartImport seeded into metadata.total
|
|
24690
|
+
// (from the caller's `totalRows`); buildWorkerDeps treats a
|
|
24691
|
+
// 0/absent value as "unknown" so the progress patch does
|
|
24692
|
+
// not overwrite it with null on the first tick.
|
|
24693
|
+
total: priorMetadata.total
|
|
24694
|
+
});
|
|
24695
|
+
const result = await runImport(deps);
|
|
24696
|
+
if (result.cancelled) {
|
|
24697
|
+
await finalizeCancelled(db2, row.id, result);
|
|
24698
|
+
}
|
|
24699
|
+
return { result, metadata: result };
|
|
24700
|
+
} catch (error) {
|
|
24701
|
+
if (error instanceof ImportAbort) {
|
|
24702
|
+
console.error(`[EXULU] import ${jobResultId} aborted: ${error.code}`);
|
|
24703
|
+
}
|
|
24704
|
+
throw error;
|
|
24705
|
+
} finally {
|
|
24706
|
+
stream.destroy();
|
|
24707
|
+
}
|
|
24708
|
+
}
|
|
23540
24709
|
if (data.type === "email_intake") {
|
|
23541
24710
|
console.log("[EXULU] running a routine webhook intake job.", bullmqJob.name);
|
|
23542
24711
|
if (!data.inputs?.s3Key || !data.inputs?.triggerId) {
|
|
@@ -23870,8 +25039,8 @@ var processUiMessagesFlow = async ({
|
|
|
23870
25039
|
let contextWindow;
|
|
23871
25040
|
try {
|
|
23872
25041
|
contextWindow = await resolveContextWindow({ modelId: resolved.model.id });
|
|
23873
|
-
} catch (
|
|
23874
|
-
console.warn(`[EXULU] Could not resolve the context window for routine model "${resolved.model.id}"; using the default.`,
|
|
25042
|
+
} catch (err4) {
|
|
25043
|
+
console.warn(`[EXULU] Could not resolve the context window for routine model "${resolved.model.id}"; using the default.`, err4);
|
|
23875
25044
|
}
|
|
23876
25045
|
const messagesWithoutPlaceholder = inputMessages.filter(
|
|
23877
25046
|
(message) => message.metadata?.type !== "placeholder"
|
|
@@ -23943,6 +25112,12 @@ var processUiMessagesFlow = async ({
|
|
|
23943
25112
|
const stream = result.stream.toUIMessageStream({
|
|
23944
25113
|
messageMetadata: ({ part }) => {
|
|
23945
25114
|
console.log("[EXULU] part", part.type);
|
|
25115
|
+
if (part.type === "finish-step") {
|
|
25116
|
+
return {
|
|
25117
|
+
lastStepInputTokens: part.usage.inputTokens,
|
|
25118
|
+
lastStepOutputTokens: part.usage.outputTokens
|
|
25119
|
+
};
|
|
25120
|
+
}
|
|
23946
25121
|
if (part.type === "finish") {
|
|
23947
25122
|
return finishTurnMetadata({ totalUsage: part.totalUsage, startedAt: startTime });
|
|
23948
25123
|
}
|
|
@@ -24220,10 +25395,10 @@ async function fetch_with_retry(args) {
|
|
|
24220
25395
|
url,
|
|
24221
25396
|
timeout_ms ? { ...options, signal: AbortSignal.timeout(timeout_ms) } : options
|
|
24222
25397
|
);
|
|
24223
|
-
} catch (
|
|
24224
|
-
if (!retry_on_reject || attempt === max_attempts) throw
|
|
25398
|
+
} catch (err4) {
|
|
25399
|
+
if (!retry_on_reject || attempt === max_attempts) throw err4;
|
|
24225
25400
|
console.log(
|
|
24226
|
-
`[EXULU-RECALL] fetch error from ${url} (${
|
|
25401
|
+
`[EXULU-RECALL] fetch error from ${url} (${err4.message}); retrying in ~5s (attempt ${attempt}/${max_attempts})`
|
|
24227
25402
|
);
|
|
24228
25403
|
await new Promise((resolve8) => setTimeout(resolve8, 5e3 + jitterMs()));
|
|
24229
25404
|
continue;
|
|
@@ -24560,13 +25735,13 @@ var recallService = {
|
|
|
24560
25735
|
});
|
|
24561
25736
|
const [updated] = await db2(TABLE2).where({ id: inserted.id }).update({ recall_bot_id: bot.id, updatedAt: /* @__PURE__ */ new Date() }).returning("*");
|
|
24562
25737
|
return this._row(updated);
|
|
24563
|
-
} catch (
|
|
25738
|
+
} catch (err4) {
|
|
24564
25739
|
const [failed] = await db2(TABLE2).where({ id: inserted.id }).update({
|
|
24565
25740
|
status: "failed",
|
|
24566
|
-
error:
|
|
25741
|
+
error: err4.message,
|
|
24567
25742
|
updatedAt: /* @__PURE__ */ new Date()
|
|
24568
25743
|
}).returning("*");
|
|
24569
|
-
log3(`createBot failed for job ${inserted.id}: ${
|
|
25744
|
+
log3(`createBot failed for job ${inserted.id}: ${err4.message}`);
|
|
24570
25745
|
return this._row(failed);
|
|
24571
25746
|
}
|
|
24572
25747
|
},
|
|
@@ -24637,8 +25812,8 @@ var recallService = {
|
|
|
24637
25812
|
row?.language || "auto"
|
|
24638
25813
|
);
|
|
24639
25814
|
await this._update(jobId, { recall_transcript_id: transcript.id ?? null });
|
|
24640
|
-
} catch (
|
|
24641
|
-
await this._fail(jobId, `create transcript failed: ${
|
|
25815
|
+
} catch (err4) {
|
|
25816
|
+
await this._fail(jobId, `create transcript failed: ${err4.message}`);
|
|
24642
25817
|
}
|
|
24643
25818
|
},
|
|
24644
25819
|
async _onTranscriptDone(jobId, transcriptId, recordingId) {
|
|
@@ -24674,12 +25849,12 @@ var recallService = {
|
|
|
24674
25849
|
jobId,
|
|
24675
25850
|
exuluApp.get().config
|
|
24676
25851
|
);
|
|
24677
|
-
} catch (
|
|
24678
|
-
log3(`could not store video locally for job ${jobId}: ${
|
|
25852
|
+
} catch (err4) {
|
|
25853
|
+
log3(`could not store video locally for job ${jobId}: ${err4.message}`);
|
|
24679
25854
|
}
|
|
24680
25855
|
}
|
|
24681
|
-
} catch (
|
|
24682
|
-
log3(`could not fetch recording duration for job ${jobId}: ${
|
|
25856
|
+
} catch (err4) {
|
|
25857
|
+
log3(`could not fetch recording duration for job ${jobId}: ${err4.message}`);
|
|
24683
25858
|
}
|
|
24684
25859
|
}
|
|
24685
25860
|
await this._update(jobId, {
|
|
@@ -24689,8 +25864,8 @@ var recallService = {
|
|
|
24689
25864
|
...videoS3Key ? { video_s3key: videoS3Key } : {},
|
|
24690
25865
|
status: "awaiting_review"
|
|
24691
25866
|
});
|
|
24692
|
-
} catch (
|
|
24693
|
-
await this._fail(jobId, `transcript download failed: ${
|
|
25867
|
+
} catch (err4) {
|
|
25868
|
+
await this._fail(jobId, `transcript download failed: ${err4.message}`);
|
|
24694
25869
|
return;
|
|
24695
25870
|
}
|
|
24696
25871
|
await this.runPostProcessing(jobId);
|
|
@@ -24722,9 +25897,9 @@ var recallService = {
|
|
|
24722
25897
|
if (!video) return null;
|
|
24723
25898
|
if (video.status?.code && video.status.code !== "done") return null;
|
|
24724
25899
|
return video.data?.download_url ?? null;
|
|
24725
|
-
} catch (
|
|
25900
|
+
} catch (err4) {
|
|
24726
25901
|
log3(
|
|
24727
|
-
`could not resolve video url for recording ${recordingId}: ${
|
|
25902
|
+
`could not resolve video url for recording ${recordingId}: ${err4.message}`
|
|
24728
25903
|
);
|
|
24729
25904
|
return null;
|
|
24730
25905
|
}
|
|
@@ -24861,15 +26036,15 @@ ${transcriptText}`,
|
|
|
24861
26036
|
error: null,
|
|
24862
26037
|
ran_at: ranAt
|
|
24863
26038
|
};
|
|
24864
|
-
} catch (
|
|
24865
|
-
log3(`post-processing prompt ${promptId} failed for job ${job.id}: ${
|
|
26039
|
+
} catch (err4) {
|
|
26040
|
+
log3(`post-processing prompt ${promptId} failed for job ${job.id}: ${err4.message}`);
|
|
24866
26041
|
return {
|
|
24867
26042
|
prompt_id: promptId,
|
|
24868
26043
|
agent_id: agentId,
|
|
24869
26044
|
prompt_name: promptName,
|
|
24870
26045
|
status: "failed",
|
|
24871
26046
|
output: null,
|
|
24872
|
-
error:
|
|
26047
|
+
error: err4.message,
|
|
24873
26048
|
ran_at: ranAt
|
|
24874
26049
|
};
|
|
24875
26050
|
}
|
|
@@ -24899,8 +26074,8 @@ ${transcriptText}`,
|
|
|
24899
26074
|
const job = this._row(dbRow);
|
|
24900
26075
|
try {
|
|
24901
26076
|
if (await this._reconcileStuckJob(job)) acted++;
|
|
24902
|
-
} catch (
|
|
24903
|
-
if (await this._reconcileError(job,
|
|
26077
|
+
} catch (err4) {
|
|
26078
|
+
if (await this._reconcileError(job, err4)) acted++;
|
|
24904
26079
|
}
|
|
24905
26080
|
}
|
|
24906
26081
|
for (const dbRow of redo) {
|
|
@@ -24908,9 +26083,9 @@ ${transcriptText}`,
|
|
|
24908
26083
|
log3(`reconcile: re-running lost post-processing for job ${dbRow.id}`);
|
|
24909
26084
|
const outputs = await this.runPostProcessing(dbRow.id);
|
|
24910
26085
|
if (outputs.length > 0) acted++;
|
|
24911
|
-
} catch (
|
|
26086
|
+
} catch (err4) {
|
|
24912
26087
|
log3(
|
|
24913
|
-
`post-processing redo failed for job ${dbRow.id}: ${
|
|
26088
|
+
`post-processing redo failed for job ${dbRow.id}: ${err4.message}`
|
|
24914
26089
|
);
|
|
24915
26090
|
}
|
|
24916
26091
|
}
|
|
@@ -24930,9 +26105,9 @@ ${transcriptText}`,
|
|
|
24930
26105
|
* Otherwise apply the 24h give-up (API errors must not defer it forever),
|
|
24931
26106
|
* and touch the row so it rotates to the back of the sweep window.
|
|
24932
26107
|
*/
|
|
24933
|
-
async _reconcileError(job,
|
|
24934
|
-
const message =
|
|
24935
|
-
if (
|
|
26108
|
+
async _reconcileError(job, err4) {
|
|
26109
|
+
const message = err4.message ?? String(err4);
|
|
26110
|
+
if (err4.status === 404) {
|
|
24936
26111
|
await this._fail(
|
|
24937
26112
|
job.id,
|
|
24938
26113
|
`Recall no longer knows this recording: ${message}`
|
|
@@ -25128,15 +26303,15 @@ var request2 = async (path4, init = {}) => {
|
|
|
25128
26303
|
let res;
|
|
25129
26304
|
try {
|
|
25130
26305
|
res = await fetch(url, init);
|
|
25131
|
-
} catch (
|
|
26306
|
+
} catch (err4) {
|
|
25132
26307
|
throw new TranscriptionServerUnavailable(
|
|
25133
|
-
`Unable to reach whisper server at ${url}: ${
|
|
26308
|
+
`Unable to reach whisper server at ${url}: ${err4.message}`
|
|
25134
26309
|
);
|
|
25135
26310
|
}
|
|
25136
26311
|
if (res.status === 404) {
|
|
25137
|
-
const
|
|
25138
|
-
|
|
25139
|
-
throw
|
|
26312
|
+
const err4 = new Error(`whisper server returned 404 for ${path4}`);
|
|
26313
|
+
err4.code = "JOB_NOT_FOUND";
|
|
26314
|
+
throw err4;
|
|
25140
26315
|
}
|
|
25141
26316
|
if (!res.ok) {
|
|
25142
26317
|
throw new Error(
|
|
@@ -25287,13 +26462,13 @@ var transcriptionService = {
|
|
|
25287
26462
|
updatedAt: /* @__PURE__ */ new Date()
|
|
25288
26463
|
}).returning("*");
|
|
25289
26464
|
return this._rowFromDb(updated);
|
|
25290
|
-
} catch (
|
|
26465
|
+
} catch (err4) {
|
|
25291
26466
|
const [failed] = await db2(TABLE3).where({ id: row.id }).update({
|
|
25292
26467
|
status: "failed",
|
|
25293
|
-
error:
|
|
26468
|
+
error: err4.message,
|
|
25294
26469
|
updatedAt: /* @__PURE__ */ new Date()
|
|
25295
26470
|
}).returning("*");
|
|
25296
|
-
log4(`Failed to dispatch job ${row.id}: ${
|
|
26471
|
+
log4(`Failed to dispatch job ${row.id}: ${err4.message}`);
|
|
25297
26472
|
return this._rowFromDb(failed);
|
|
25298
26473
|
}
|
|
25299
26474
|
},
|
|
@@ -25312,18 +26487,18 @@ var transcriptionService = {
|
|
|
25312
26487
|
try {
|
|
25313
26488
|
const job = await transcriptionClient.getJob(row.whisper_job_id);
|
|
25314
26489
|
await this._applyJobUpdate(row, job);
|
|
25315
|
-
} catch (
|
|
25316
|
-
const code =
|
|
26490
|
+
} catch (err4) {
|
|
26491
|
+
const code = err4.code;
|
|
25317
26492
|
if (code === "JOB_NOT_FOUND") {
|
|
25318
26493
|
await db2(TABLE3).where({ id: row.id }).update({
|
|
25319
26494
|
status: "failed",
|
|
25320
26495
|
error: "lost on server restart",
|
|
25321
26496
|
updatedAt: /* @__PURE__ */ new Date()
|
|
25322
26497
|
});
|
|
25323
|
-
} else if (
|
|
26498
|
+
} else if (err4 instanceof TranscriptionServerUnavailable) {
|
|
25324
26499
|
log4(`Whisper server unreachable while polling ${row.id}; will retry`);
|
|
25325
26500
|
} else {
|
|
25326
|
-
log4(`Error polling job ${row.id}: ${
|
|
26501
|
+
log4(`Error polling job ${row.id}: ${err4.message}`);
|
|
25327
26502
|
}
|
|
25328
26503
|
}
|
|
25329
26504
|
}
|
|
@@ -25350,8 +26525,8 @@ var transcriptionService = {
|
|
|
25350
26525
|
row.post_processing_prompts,
|
|
25351
26526
|
row.post_processing_outputs
|
|
25352
26527
|
)) {
|
|
25353
|
-
void recallService.runPostProcessing(row.id).catch((
|
|
25354
|
-
log4(`post-processing for upload ${row.id} failed: ${
|
|
26528
|
+
void recallService.runPostProcessing(row.id).catch((err4) => {
|
|
26529
|
+
log4(`post-processing for upload ${row.id} failed: ${err4.message}`);
|
|
25355
26530
|
});
|
|
25356
26531
|
}
|
|
25357
26532
|
return;
|
|
@@ -25379,10 +26554,10 @@ var transcriptionService = {
|
|
|
25379
26554
|
if (row.whisper_job_id && transcriptionClient.isConfigured()) {
|
|
25380
26555
|
try {
|
|
25381
26556
|
await transcriptionClient.cancelJob(row.whisper_job_id);
|
|
25382
|
-
} catch (
|
|
25383
|
-
const code =
|
|
26557
|
+
} catch (err4) {
|
|
26558
|
+
const code = err4.code;
|
|
25384
26559
|
if (code !== "JOB_NOT_FOUND") {
|
|
25385
|
-
log4(`Best-effort cancel of whisper job failed: ${
|
|
26560
|
+
log4(`Best-effort cancel of whisper job failed: ${err4.message}`);
|
|
25386
26561
|
}
|
|
25387
26562
|
}
|
|
25388
26563
|
}
|
|
@@ -25492,13 +26667,13 @@ var transcriptionService = {
|
|
|
25492
26667
|
// upsert when re-saving
|
|
25493
26668
|
);
|
|
25494
26669
|
item = result.item;
|
|
25495
|
-
} catch (
|
|
26670
|
+
} catch (err4) {
|
|
25496
26671
|
await db2(TABLE3).where({ id }).update({
|
|
25497
26672
|
speakers: JSON.stringify(input.speakers),
|
|
25498
|
-
error: `Failed to save: ${
|
|
26673
|
+
error: `Failed to save: ${err4.message}`,
|
|
25499
26674
|
updatedAt: /* @__PURE__ */ new Date()
|
|
25500
26675
|
});
|
|
25501
|
-
throw
|
|
26676
|
+
throw err4;
|
|
25502
26677
|
}
|
|
25503
26678
|
const itemId = item.id ?? row.saved_item_id ?? "";
|
|
25504
26679
|
const users = input.target_rbac_users ?? row.target_rbac_users ?? [];
|
|
@@ -25512,8 +26687,8 @@ var transcriptionService = {
|
|
|
25512
26687
|
{ users, roles },
|
|
25513
26688
|
[]
|
|
25514
26689
|
);
|
|
25515
|
-
} catch (
|
|
25516
|
-
log4(`RBAC update failed for item ${itemId}: ${
|
|
26690
|
+
} catch (err4) {
|
|
26691
|
+
log4(`RBAC update failed for item ${itemId}: ${err4.message}`);
|
|
25517
26692
|
}
|
|
25518
26693
|
}
|
|
25519
26694
|
const projectId = input.project_id ?? row.project_id ?? null;
|
|
@@ -25534,8 +26709,8 @@ var transcriptionService = {
|
|
|
25534
26709
|
});
|
|
25535
26710
|
}
|
|
25536
26711
|
}
|
|
25537
|
-
} catch (
|
|
25538
|
-
projectWarning =
|
|
26712
|
+
} catch (err4) {
|
|
26713
|
+
projectWarning = err4.message;
|
|
25539
26714
|
}
|
|
25540
26715
|
}
|
|
25541
26716
|
const nextCorrectedSegments = input.corrected_segments !== void 0 ? input.corrected_segments : row.corrected_segments;
|
|
@@ -25576,9 +26751,9 @@ var transcriptionService = {
|
|
|
25576
26751
|
const { db: db2 } = await postgresClient();
|
|
25577
26752
|
try {
|
|
25578
26753
|
await assertOwnsTranscriptionJob(db2, user, jobId);
|
|
25579
|
-
} catch (
|
|
25580
|
-
if (
|
|
25581
|
-
throw
|
|
26754
|
+
} catch (err4) {
|
|
26755
|
+
if (err4 instanceof TranscriptionJobAccessError) return void 0;
|
|
26756
|
+
throw err4;
|
|
25582
26757
|
}
|
|
25583
26758
|
const dbRow = await db2(TABLE3).where({ id: jobId }).first();
|
|
25584
26759
|
if (!dbRow) return void 0;
|
|
@@ -25712,8 +26887,8 @@ var liveRecordingService = {
|
|
|
25712
26887
|
);
|
|
25713
26888
|
}
|
|
25714
26889
|
log5(`live recording ${id} stopped \u2192 awaiting_review`);
|
|
25715
|
-
void recallService.runPostProcessing(id).catch((
|
|
25716
|
-
log5(`post-processing for job ${id} failed: ${
|
|
26890
|
+
void recallService.runPostProcessing(id).catch((err4) => {
|
|
26891
|
+
log5(`post-processing for job ${id} failed: ${err4.message}`);
|
|
25717
26892
|
});
|
|
25718
26893
|
return rowFromDb(updated);
|
|
25719
26894
|
}
|
|
@@ -25721,7 +26896,7 @@ var liveRecordingService = {
|
|
|
25721
26896
|
|
|
25722
26897
|
// src/exulu/email-inbound/trigger-config.ts
|
|
25723
26898
|
init_cjs_shims();
|
|
25724
|
-
var
|
|
26899
|
+
var import_node_crypto13 = require("crypto");
|
|
25725
26900
|
var import_safe_regex = __toESM(require("safe-regex"), 1);
|
|
25726
26901
|
var MAX_FILTER_PATTERN_LENGTH = 200;
|
|
25727
26902
|
var FILTER_FIELDS = [
|
|
@@ -25815,10 +26990,10 @@ function validateEmailTriggerConfig(raw) {
|
|
|
25815
26990
|
return config;
|
|
25816
26991
|
}
|
|
25817
26992
|
function generateTriggerSecret() {
|
|
25818
|
-
return (0,
|
|
26993
|
+
return (0, import_node_crypto13.randomBytes)(32).toString("base64url");
|
|
25819
26994
|
}
|
|
25820
26995
|
function generateSigningSecret() {
|
|
25821
|
-
return (0,
|
|
26996
|
+
return (0, import_node_crypto13.randomBytes)(32).toString("base64url");
|
|
25822
26997
|
}
|
|
25823
26998
|
|
|
25824
26999
|
// src/graphql/schemas/index.ts
|
|
@@ -25848,9 +27023,9 @@ async function insertTriggerWithSecretRetry(insertFn, baseRow) {
|
|
|
25848
27023
|
for (let attempt = 0; attempt < 5; attempt++) {
|
|
25849
27024
|
try {
|
|
25850
27025
|
return await insertFn({ ...baseRow, secret: generateTriggerSecret() });
|
|
25851
|
-
} catch (
|
|
25852
|
-
if (
|
|
25853
|
-
throw
|
|
27026
|
+
} catch (err4) {
|
|
27027
|
+
if (err4?.code === "23505") continue;
|
|
27028
|
+
throw err4;
|
|
25854
27029
|
}
|
|
25855
27030
|
}
|
|
25856
27031
|
throw new Error("Could not generate a unique trigger secret.");
|
|
@@ -25858,11 +27033,11 @@ async function insertTriggerWithSecretRetry(insertFn, baseRow) {
|
|
|
25858
27033
|
|
|
25859
27034
|
// src/exulu/email-inbound/webhook.ts
|
|
25860
27035
|
init_cjs_shims();
|
|
25861
|
-
var
|
|
27036
|
+
var import_node_crypto15 = require("crypto");
|
|
25862
27037
|
|
|
25863
27038
|
// src/exulu/email-inbound/verify-signature.ts
|
|
25864
27039
|
init_cjs_shims();
|
|
25865
|
-
var
|
|
27040
|
+
var import_node_crypto14 = require("crypto");
|
|
25866
27041
|
var SIGNATURE_REPLAY_WINDOW_SECONDS = 300;
|
|
25867
27042
|
var REPLAY_TTL_SECONDS = 900;
|
|
25868
27043
|
function verifyPayloadSignature(rawBody, signatureHeader, timestampHeader, secret) {
|
|
@@ -25871,11 +27046,11 @@ function verifyPayloadSignature(rawBody, signatureHeader, timestampHeader, secre
|
|
|
25871
27046
|
const provided = signatureHeader.slice("sha256=".length);
|
|
25872
27047
|
if (!/^[0-9a-f]+$/i.test(provided)) return false;
|
|
25873
27048
|
const message = timestampHeader ? Buffer.concat([Buffer.from(`${timestampHeader}.`), rawBody]) : rawBody;
|
|
25874
|
-
const expected = (0,
|
|
27049
|
+
const expected = (0, import_node_crypto14.createHmac)("sha256", secret).update(message).digest("hex");
|
|
25875
27050
|
const expectedBuf = Buffer.from(expected, "utf8");
|
|
25876
27051
|
const providedBuf = Buffer.from(provided.toLowerCase(), "utf8");
|
|
25877
27052
|
if (expectedBuf.length !== providedBuf.length) return false;
|
|
25878
|
-
return (0,
|
|
27053
|
+
return (0, import_node_crypto14.timingSafeEqual)(expectedBuf, providedBuf);
|
|
25879
27054
|
}
|
|
25880
27055
|
async function isReplay(redis, signature, timestamp) {
|
|
25881
27056
|
const ts = Number(timestamp);
|
|
@@ -25888,10 +27063,10 @@ async function isReplay(redis, signature, timestamp) {
|
|
|
25888
27063
|
EX: REPLAY_TTL_SECONDS
|
|
25889
27064
|
});
|
|
25890
27065
|
return result === null;
|
|
25891
|
-
} catch (
|
|
27066
|
+
} catch (err4) {
|
|
25892
27067
|
console.error(
|
|
25893
27068
|
"[EXULU] routine-webhook replay guard: redis unavailable, degrading to window-only",
|
|
25894
|
-
|
|
27069
|
+
err4 instanceof Error ? err4.message : String(err4)
|
|
25895
27070
|
);
|
|
25896
27071
|
return false;
|
|
25897
27072
|
}
|
|
@@ -25964,8 +27139,8 @@ var createRoutineWebhookHandler = (deps) => async (req, res) => {
|
|
|
25964
27139
|
payloadBytes = rawBody;
|
|
25965
27140
|
format = "eml";
|
|
25966
27141
|
}
|
|
25967
|
-
} catch (
|
|
25968
|
-
res.status(400).json({ detail:
|
|
27142
|
+
} catch (err4) {
|
|
27143
|
+
res.status(400).json({ detail: err4 instanceof Error ? err4.message : "bad payload" });
|
|
25969
27144
|
return;
|
|
25970
27145
|
}
|
|
25971
27146
|
void deps.stampLastFiredAt(db2, trigger.id).catch(
|
|
@@ -25973,7 +27148,7 @@ var createRoutineWebhookHandler = (deps) => async (req, res) => {
|
|
|
25973
27148
|
);
|
|
25974
27149
|
try {
|
|
25975
27150
|
const ext = format === "json" ? "json" : "eml";
|
|
25976
|
-
const s3Key = await deps.putRawPayload(`${EMAIL_INBOUND_S3_PREFIX}${(0,
|
|
27151
|
+
const s3Key = await deps.putRawPayload(`${EMAIL_INBOUND_S3_PREFIX}${(0, import_node_crypto15.randomUUID)()}.${ext}`, payloadBytes);
|
|
25977
27152
|
await deps.enqueueIntake({ s3Key, triggerId: trigger.id, format });
|
|
25978
27153
|
} catch (error) {
|
|
25979
27154
|
console.error("[EXULU-WEBHOOK] persist/enqueue failed", error);
|
|
@@ -25985,7 +27160,7 @@ var createRoutineWebhookHandler = (deps) => async (req, res) => {
|
|
|
25985
27160
|
|
|
25986
27161
|
// src/graphql/schemas/index.ts
|
|
25987
27162
|
init_uppy();
|
|
25988
|
-
var
|
|
27163
|
+
var import_node_crypto16 = require("crypto");
|
|
25989
27164
|
init_memory_base();
|
|
25990
27165
|
|
|
25991
27166
|
// src/graphql/resolvers/memory-base-stats.ts
|
|
@@ -27529,6 +28704,8 @@ function createSDL(tables, contexts, tools, config, evals) {
|
|
|
27529
28704
|
mutationDefs += `
|
|
27530
28705
|
${tableNameSingular}GenerateChunks(where: [Filter${tableNameSingularUpperCaseFirst}], limit: Int): ${tableNameSingular}GenerateChunksReturnPayload
|
|
27531
28706
|
${tableNameSingular}ExecuteSource(source: ID!, inputs: JSON!): ${tableNameSingular}ExecuteSourceReturnPayload
|
|
28707
|
+
${tableNameSingular}StartImport(input: StartImportInput!): StartImportPayload
|
|
28708
|
+
${tableNameSingular}CancelImport(jobResultId: ID!): CancelImportPayload
|
|
27532
28709
|
${tableNameSingular}DeleteChunks(where: [Filter${tableNameSingularUpperCaseFirst}], limit: Int): ${tableNameSingular}DeleteChunksReturnPayload
|
|
27533
28710
|
${tableNameSingular}BackfillEntities(onlyStale: Boolean, limit: Int): ${tableNameSingular}EntityBackfillPayload
|
|
27534
28711
|
${tableNameSingular}PurgeEntityType(type: String!): ${tableNameSingular}EntityPurgePayload
|
|
@@ -27567,6 +28744,40 @@ function createSDL(tables, contexts, tools, config, evals) {
|
|
|
27567
28744
|
items: [String!]
|
|
27568
28745
|
}
|
|
27569
28746
|
|
|
28747
|
+
input StartImportMappingInput {
|
|
28748
|
+
header: String!
|
|
28749
|
+
fieldName: String
|
|
28750
|
+
}
|
|
28751
|
+
|
|
28752
|
+
input StartImportAccessInput {
|
|
28753
|
+
rights_mode: String!
|
|
28754
|
+
users: JSON
|
|
28755
|
+
roles: JSON
|
|
28756
|
+
teams: JSON
|
|
28757
|
+
}
|
|
28758
|
+
|
|
28759
|
+
input StartImportOptionsInput {
|
|
28760
|
+
skipEmbeddings: Boolean
|
|
28761
|
+
delimiter: String
|
|
28762
|
+
}
|
|
28763
|
+
|
|
28764
|
+
input StartImportInput {
|
|
28765
|
+
s3Key: String!
|
|
28766
|
+
fileName: String!
|
|
28767
|
+
mapping: [StartImportMappingInput!]
|
|
28768
|
+
access: StartImportAccessInput!
|
|
28769
|
+
options: StartImportOptionsInput
|
|
28770
|
+
totalRows: Int
|
|
28771
|
+
}
|
|
28772
|
+
|
|
28773
|
+
type StartImportPayload {
|
|
28774
|
+
jobResultId: ID!
|
|
28775
|
+
}
|
|
28776
|
+
|
|
28777
|
+
type CancelImportPayload {
|
|
28778
|
+
ok: Boolean!
|
|
28779
|
+
}
|
|
28780
|
+
|
|
27570
28781
|
type ${tableNameSingular}ProcessItemFieldReturnPayload {
|
|
27571
28782
|
message: String!
|
|
27572
28783
|
results: [String]
|
|
@@ -28101,8 +29312,8 @@ type EmbeddingModelOption {
|
|
|
28101
29312
|
maxChunkSize: m.maxChunkSize,
|
|
28102
29313
|
maxBatchSize: m.maxBatchSize
|
|
28103
29314
|
}));
|
|
28104
|
-
} catch (
|
|
28105
|
-
console.warn("[EXULU] Could not read embedding models:",
|
|
29315
|
+
} catch (err4) {
|
|
29316
|
+
console.warn("[EXULU] Could not read embedding models:", err4.message);
|
|
28106
29317
|
return [];
|
|
28107
29318
|
}
|
|
28108
29319
|
};
|
|
@@ -28295,9 +29506,9 @@ type EmbeddingModelOption {
|
|
|
28295
29506
|
throw new Error("You don't have access to this workflow template.");
|
|
28296
29507
|
}
|
|
28297
29508
|
const hasWorkflowsWriteRole = user?.super_admin || user?.role?.workflows === "write";
|
|
28298
|
-
const
|
|
29509
|
+
const canWrite2 = hasWorkflowsWriteRole && await checkRecordAccess(workflowTemplate, "write", user);
|
|
28299
29510
|
const rows = await db2.from("workflow_triggers").where({ workflow: args.workflow }).orderBy("createdAt", "asc");
|
|
28300
|
-
return rows.map((r) => toWorkflowTriggerPayload(r, { canWrite }));
|
|
29511
|
+
return rows.map((r) => toWorkflowTriggerPayload(r, { canWrite: canWrite2 }));
|
|
28301
29512
|
};
|
|
28302
29513
|
resolvers.Mutation["upsertWorkflowEmailTrigger"] = async (_, args, context) => {
|
|
28303
29514
|
if (!args.workflow) {
|
|
@@ -28378,9 +29589,9 @@ type EmbeddingModelOption {
|
|
|
28378
29589
|
const rows = await db2.from("workflow_triggers").where({ id: args.id }).update({ secret: generateTriggerSecret(), updatedAt: (/* @__PURE__ */ new Date()).toISOString() }).returning("*");
|
|
28379
29590
|
updated = rows[0];
|
|
28380
29591
|
break;
|
|
28381
|
-
} catch (
|
|
28382
|
-
if (
|
|
28383
|
-
throw
|
|
29592
|
+
} catch (err4) {
|
|
29593
|
+
if (err4?.code === "23505") continue;
|
|
29594
|
+
throw err4;
|
|
28384
29595
|
}
|
|
28385
29596
|
}
|
|
28386
29597
|
if (!updated) throw new Error("Could not generate a unique trigger secret.");
|
|
@@ -28426,13 +29637,13 @@ type EmbeddingModelOption {
|
|
|
28426
29637
|
bytes = Buffer.from(args.payload, "latin1");
|
|
28427
29638
|
format = "eml";
|
|
28428
29639
|
}
|
|
28429
|
-
} catch (
|
|
28430
|
-
return { outcome: "error", error:
|
|
29640
|
+
} catch (err4) {
|
|
29641
|
+
return { outcome: "error", error: err4 instanceof Error ? err4.message : "bad payload" };
|
|
28431
29642
|
}
|
|
28432
29643
|
const ext = format === "json" ? "json" : "eml";
|
|
28433
29644
|
const fullKey = await uploadFile(
|
|
28434
29645
|
bytes,
|
|
28435
|
-
`${EMAIL_INBOUND_S3_PREFIX}${(0,
|
|
29646
|
+
`${EMAIL_INBOUND_S3_PREFIX}${(0, import_node_crypto16.randomUUID)()}.${ext}`,
|
|
28436
29647
|
config,
|
|
28437
29648
|
{ contentType: "application/octet-stream" },
|
|
28438
29649
|
void 0,
|
|
@@ -28617,11 +29828,11 @@ type EmbeddingModelOption {
|
|
|
28617
29828
|
user
|
|
28618
29829
|
);
|
|
28619
29830
|
return new Map(rows.map((row) => [row.id, row]));
|
|
28620
|
-
} catch (
|
|
28621
|
-
if (
|
|
29831
|
+
} catch (err4) {
|
|
29832
|
+
if (err4 instanceof Error && err4.message.startsWith("Access control error")) {
|
|
28622
29833
|
return /* @__PURE__ */ new Map();
|
|
28623
29834
|
}
|
|
28624
|
-
throw
|
|
29835
|
+
throw err4;
|
|
28625
29836
|
}
|
|
28626
29837
|
};
|
|
28627
29838
|
const loadRoutineRunForWrite = async (db2, user, id) => {
|
|
@@ -29135,8 +30346,8 @@ type EmbeddingModelOption {
|
|
|
29135
30346
|
stuck_count: num7(stuckRow?.c),
|
|
29136
30347
|
stale_count: num7(staleRow?.c)
|
|
29137
30348
|
};
|
|
29138
|
-
} catch (
|
|
29139
|
-
console.error("[EXULU] computeContextAggregates failed for", contextId,
|
|
30349
|
+
} catch (err4) {
|
|
30350
|
+
console.error("[EXULU] computeContextAggregates failed for", contextId, err4);
|
|
29140
30351
|
return empty;
|
|
29141
30352
|
}
|
|
29142
30353
|
};
|
|
@@ -29682,9 +30893,9 @@ async function extractZipToPrefix(bytes, prefix, config) {
|
|
|
29682
30893
|
let zip;
|
|
29683
30894
|
try {
|
|
29684
30895
|
zip = await import_jszip2.default.loadAsync(bytes);
|
|
29685
|
-
} catch (
|
|
30896
|
+
} catch (err4) {
|
|
29686
30897
|
throw new BundleValidationError(
|
|
29687
|
-
`Could not parse zip file: ${
|
|
30898
|
+
`Could not parse zip file: ${err4?.message ?? "unknown error"}`
|
|
29688
30899
|
);
|
|
29689
30900
|
}
|
|
29690
30901
|
const entries = [];
|
|
@@ -29788,7 +30999,7 @@ var import_body_parser = __toESM(require("body-parser"), 1);
|
|
|
29788
30999
|
var import_crypto_js7 = require("crypto-js");
|
|
29789
31000
|
var import_openai = require("openai");
|
|
29790
31001
|
var import_fs4 = __toESM(require("fs"), 1);
|
|
29791
|
-
var
|
|
31002
|
+
var import_node_crypto20 = require("crypto");
|
|
29792
31003
|
var import_api2 = require("@opentelemetry/api");
|
|
29793
31004
|
init_check_record_access();
|
|
29794
31005
|
var import_jszip4 = __toESM(require("jszip"), 1);
|
|
@@ -29796,7 +31007,7 @@ var import_jszip4 = __toESM(require("jszip"), 1);
|
|
|
29796
31007
|
// src/skills/bundled.ts
|
|
29797
31008
|
init_cjs_shims();
|
|
29798
31009
|
var import_jszip3 = __toESM(require("jszip"), 1);
|
|
29799
|
-
var
|
|
31010
|
+
var import_node_crypto17 = require("crypto");
|
|
29800
31011
|
|
|
29801
31012
|
// src/skills/bundled.generated.ts
|
|
29802
31013
|
init_cjs_shims();
|
|
@@ -29820,7 +31031,7 @@ var BUNDLED_SKILLS = [
|
|
|
29820
31031
|
init_frontmatter();
|
|
29821
31032
|
var BUNDLED_LABEL = "Bundled with the IMP";
|
|
29822
31033
|
function bundledSkillHash(skill) {
|
|
29823
|
-
const h = (0,
|
|
31034
|
+
const h = (0, import_node_crypto17.createHash)("sha256");
|
|
29824
31035
|
for (const path4 of Object.keys(skill.files).sort()) {
|
|
29825
31036
|
h.update(path4).update("\0").update(skill.files[path4]).update("\0");
|
|
29826
31037
|
}
|
|
@@ -29881,7 +31092,7 @@ async function seedBundledSkills({
|
|
|
29881
31092
|
log7(`"${skill.name}" updated to v${nextVersion}`);
|
|
29882
31093
|
continue;
|
|
29883
31094
|
}
|
|
29884
|
-
const skillId = (0,
|
|
31095
|
+
const skillId = (0, import_node_crypto17.randomUUID)();
|
|
29885
31096
|
await extractBundleToVersion({ bytes: await bundledSkillZip(skill), skillId, version: 1, config });
|
|
29886
31097
|
await db2("skills").insert({
|
|
29887
31098
|
id: skillId,
|
|
@@ -29983,7 +31194,7 @@ init_context_budget();
|
|
|
29983
31194
|
|
|
29984
31195
|
// src/exulu/compact-session.ts
|
|
29985
31196
|
init_cjs_shims();
|
|
29986
|
-
var
|
|
31197
|
+
var import_node_crypto18 = require("crypto");
|
|
29987
31198
|
var import_ai11 = require("ai");
|
|
29988
31199
|
init_truncate_tool_output();
|
|
29989
31200
|
init_context_budget();
|
|
@@ -30088,7 +31299,7 @@ Focus especially on: ${steer.trim()}` : SUMMARY_SYSTEM;
|
|
|
30088
31299
|
...steer?.trim() ? { steer: steer.trim() } : {}
|
|
30089
31300
|
};
|
|
30090
31301
|
const checkpoint = {
|
|
30091
|
-
id: `compaction_${(0,
|
|
31302
|
+
id: `compaction_${(0, import_node_crypto18.randomUUID)()}`,
|
|
30092
31303
|
role: "user",
|
|
30093
31304
|
parts: [{ type: "text", text: `[Conversation summary \u2014 earlier messages were compacted]
|
|
30094
31305
|
|
|
@@ -30103,19 +31314,19 @@ ${summary}` }],
|
|
|
30103
31314
|
init_cjs_shims();
|
|
30104
31315
|
var import_ai12 = require("ai");
|
|
30105
31316
|
init_context_budget();
|
|
30106
|
-
function describeRequestError(
|
|
30107
|
-
if (
|
|
30108
|
-
return { status: 413, body:
|
|
31317
|
+
function describeRequestError(err4) {
|
|
31318
|
+
if (err4 instanceof ContextCompactionRequiredError) {
|
|
31319
|
+
return { status: 413, body: err4.message };
|
|
30109
31320
|
}
|
|
30110
|
-
if (import_ai12.TypeValidationError.isInstance(
|
|
30111
|
-
const cause =
|
|
31321
|
+
if (import_ai12.TypeValidationError.isInstance(err4)) {
|
|
31322
|
+
const cause = err4.cause;
|
|
30112
31323
|
const detail = cause instanceof Error ? cause.message : typeof cause === "string" ? cause : "";
|
|
30113
31324
|
return {
|
|
30114
31325
|
status: 422,
|
|
30115
31326
|
body: `The stored conversation could not be loaded: ${detail.slice(0, 400) || "type validation failed"}`
|
|
30116
31327
|
};
|
|
30117
31328
|
}
|
|
30118
|
-
return { status: 500, body:
|
|
31329
|
+
return { status: 500, body: err4 instanceof Error ? err4.message : String(err4) };
|
|
30119
31330
|
}
|
|
30120
31331
|
|
|
30121
31332
|
// src/exulu/memory/recalled-metadata.ts
|
|
@@ -30570,12 +31781,12 @@ function registerLiveRecordingChunkRoute(app, deps) {
|
|
|
30570
31781
|
const db2 = await deps.getDb();
|
|
30571
31782
|
try {
|
|
30572
31783
|
await deps.assertOwns(db2, user, jobId);
|
|
30573
|
-
} catch (
|
|
30574
|
-
if (
|
|
30575
|
-
res.status(
|
|
31784
|
+
} catch (err4) {
|
|
31785
|
+
if (err4 instanceof TranscriptionJobAccessError) {
|
|
31786
|
+
res.status(err4.code).json({ detail: err4.message });
|
|
30576
31787
|
return;
|
|
30577
31788
|
}
|
|
30578
|
-
throw
|
|
31789
|
+
throw err4;
|
|
30579
31790
|
}
|
|
30580
31791
|
const row = await db2.from("transcription_jobs").select(["status", "raw_segments", "project_id"]).where({ id: jobId }).first();
|
|
30581
31792
|
if (!row) {
|
|
@@ -30630,14 +31841,14 @@ function registerLiveRecordingChunkRoute(app, deps) {
|
|
|
30630
31841
|
priorText: LIVE_PRIOR_TEXT_ENABLED ? priorTextFrom(row.raw_segments) : void 0,
|
|
30631
31842
|
tags
|
|
30632
31843
|
}));
|
|
30633
|
-
} catch (
|
|
30634
|
-
if (
|
|
30635
|
-
const code =
|
|
30636
|
-
res.status(code).json({ detail:
|
|
31844
|
+
} catch (err4) {
|
|
31845
|
+
if (err4 instanceof TranscriptionError) {
|
|
31846
|
+
const code = err4.upstreamStatus >= 500 ? 502 : err4.upstreamStatus;
|
|
31847
|
+
res.status(code).json({ detail: err4.message });
|
|
30637
31848
|
return;
|
|
30638
31849
|
}
|
|
30639
|
-
console.error(`[EXULU] ${CHUNK_ROUTE_PATH} transcription failed`,
|
|
30640
|
-
res.status(500).json({ detail:
|
|
31850
|
+
console.error(`[EXULU] ${CHUNK_ROUTE_PATH} transcription failed`, err4);
|
|
31851
|
+
res.status(500).json({ detail: err4 instanceof Error ? err4.message : "Transcription failed." });
|
|
30641
31852
|
return;
|
|
30642
31853
|
}
|
|
30643
31854
|
}
|
|
@@ -30731,7 +31942,7 @@ var formatSrtTime = (seconds) => {
|
|
|
30731
31942
|
const ms = String(totalMs % 1e3).padStart(3, "0");
|
|
30732
31943
|
return `${formatCsvTime(wholeSeconds)},${ms}`;
|
|
30733
31944
|
};
|
|
30734
|
-
var
|
|
31945
|
+
var csvField2 = (value, isTextField = false) => {
|
|
30735
31946
|
const needsQuote = /["\n\r,]/.test(value) || isTextField;
|
|
30736
31947
|
return needsQuote ? `"${value.replace(/"/g, '""')}"` : value;
|
|
30737
31948
|
};
|
|
@@ -30745,7 +31956,7 @@ function buildTranscriptCsv(item, options) {
|
|
|
30745
31956
|
const label = resolveLabel(item, segment.speaker, options.speakers);
|
|
30746
31957
|
const text = (segment.text ?? "").trim();
|
|
30747
31958
|
const cells = options.timestamps ? [formatCsvTime(segment.start), formatCsvTime(segment.end), label, text] : [label, text];
|
|
30748
|
-
return cells.map((value, i) =>
|
|
31959
|
+
return cells.map((value, i) => csvField2(value, i === cells.length - 1)).join(",");
|
|
30749
31960
|
});
|
|
30750
31961
|
return [header2, ...rows].join("\n") + "\n";
|
|
30751
31962
|
}
|
|
@@ -30805,8 +32016,8 @@ function registerTranscriptExportRoute(app, deps) {
|
|
|
30805
32016
|
`attachment; filename="${encodeURIComponent(filename)}"`
|
|
30806
32017
|
);
|
|
30807
32018
|
res.send(body);
|
|
30808
|
-
} catch (
|
|
30809
|
-
console.error("[EXULU] transcript export failed",
|
|
32019
|
+
} catch (err4) {
|
|
32020
|
+
console.error("[EXULU] transcript export failed", err4);
|
|
30810
32021
|
res.status(500).json({ detail: "Export failed." });
|
|
30811
32022
|
}
|
|
30812
32023
|
});
|
|
@@ -30856,8 +32067,8 @@ function registerTranscriptExportRoute(app, deps) {
|
|
|
30856
32067
|
`attachment; filename="${encodeURIComponent(filename)}"`
|
|
30857
32068
|
);
|
|
30858
32069
|
res.send(body);
|
|
30859
|
-
} catch (
|
|
30860
|
-
console.error("[EXULU] transcript job export failed",
|
|
32070
|
+
} catch (err4) {
|
|
32071
|
+
console.error("[EXULU] transcript job export failed", err4);
|
|
30861
32072
|
res.status(500).json({ detail: "Export failed." });
|
|
30862
32073
|
}
|
|
30863
32074
|
});
|
|
@@ -30930,7 +32141,7 @@ function pipelineConfigFor(agent) {
|
|
|
30930
32141
|
// ee/claim-check/routes.ts
|
|
30931
32142
|
var CLAIM_CHECK_PATH = "/claims/check";
|
|
30932
32143
|
var CLAIM_CHECK_SESSION_PATH = "/claims/check/:session";
|
|
30933
|
-
var
|
|
32144
|
+
var UUID_RE2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
30934
32145
|
function hasNumericUserId(user) {
|
|
30935
32146
|
return Boolean(user?.id) && Number.isFinite(Number(user?.id));
|
|
30936
32147
|
}
|
|
@@ -31091,9 +32302,9 @@ function registerClaimCheckRoutes(app, deps) {
|
|
|
31091
32302
|
}
|
|
31092
32303
|
try {
|
|
31093
32304
|
agent = await deps.getAgent(body.agent);
|
|
31094
|
-
} catch (
|
|
32305
|
+
} catch (err4) {
|
|
31095
32306
|
console.warn(
|
|
31096
|
-
`[EXULU] claim check: agent lookup for "${body.agent}" failed: ${
|
|
32307
|
+
`[EXULU] claim check: agent lookup for "${body.agent}" failed: ${err4 instanceof Error ? err4.message : String(err4)}`
|
|
31097
32308
|
);
|
|
31098
32309
|
}
|
|
31099
32310
|
if (!agent) {
|
|
@@ -31118,7 +32329,7 @@ function registerClaimCheckRoutes(app, deps) {
|
|
|
31118
32329
|
});
|
|
31119
32330
|
return;
|
|
31120
32331
|
}
|
|
31121
|
-
if (deps.findClaimCheck && body.session && body.messageId &&
|
|
32332
|
+
if (deps.findClaimCheck && body.session && body.messageId && UUID_RE2.test(body.session)) {
|
|
31122
32333
|
try {
|
|
31123
32334
|
const stored = await deps.findClaimCheck({
|
|
31124
32335
|
session: body.session,
|
|
@@ -31129,10 +32340,10 @@ function registerClaimCheckRoutes(app, deps) {
|
|
|
31129
32340
|
res.status(200).json(stored);
|
|
31130
32341
|
return;
|
|
31131
32342
|
}
|
|
31132
|
-
} catch (
|
|
32343
|
+
} catch (err4) {
|
|
31133
32344
|
console.warn(
|
|
31134
32345
|
"[EXULU claim-check] could not read the stored check for this message; running the check.",
|
|
31135
|
-
|
|
32346
|
+
err4
|
|
31136
32347
|
);
|
|
31137
32348
|
}
|
|
31138
32349
|
}
|
|
@@ -31158,10 +32369,10 @@ function registerClaimCheckRoutes(app, deps) {
|
|
|
31158
32369
|
model = resolved.languageModel;
|
|
31159
32370
|
break;
|
|
31160
32371
|
}
|
|
31161
|
-
} catch (
|
|
31162
|
-
lastError =
|
|
32372
|
+
} catch (err4) {
|
|
32373
|
+
lastError = err4;
|
|
31163
32374
|
console.warn(
|
|
31164
|
-
`[EXULU] claim check: model "${modelId}" failed to resolve: ${
|
|
32375
|
+
`[EXULU] claim check: model "${modelId}" failed to resolve: ${err4 instanceof Error ? err4.message : String(err4)}`
|
|
31165
32376
|
);
|
|
31166
32377
|
}
|
|
31167
32378
|
}
|
|
@@ -31225,21 +32436,21 @@ function registerClaimCheckRoutes(app, deps) {
|
|
|
31225
32436
|
]);
|
|
31226
32437
|
completedResult = result;
|
|
31227
32438
|
res.status(200).json(result);
|
|
31228
|
-
} catch (
|
|
31229
|
-
if (
|
|
32439
|
+
} catch (err4) {
|
|
32440
|
+
if (err4 instanceof ClaimCheckTimeoutError) {
|
|
31230
32441
|
console.warn(`[EXULU] claim check exceeded the ${timeoutMs} ms deadline.`);
|
|
31231
32442
|
res.status(504).json({
|
|
31232
32443
|
detail: `The claim check did not finish within ${timeoutMs / 1e3} seconds and was cancelled.`
|
|
31233
32444
|
});
|
|
31234
32445
|
} else {
|
|
31235
|
-
console.error("[EXULU] claim check failed.",
|
|
32446
|
+
console.error("[EXULU] claim check failed.", err4);
|
|
31236
32447
|
res.status(500).json({ detail: "The claim check failed." });
|
|
31237
32448
|
}
|
|
31238
32449
|
} finally {
|
|
31239
32450
|
if (deadline) clearTimeout(deadline);
|
|
31240
32451
|
deps.limiter.release();
|
|
31241
32452
|
}
|
|
31242
|
-
if (completedResult && body.session && body.messageId &&
|
|
32453
|
+
if (completedResult && body.session && body.messageId && UUID_RE2.test(body.session)) {
|
|
31243
32454
|
if (!deps.saveClaimCheck) {
|
|
31244
32455
|
console.error(
|
|
31245
32456
|
"[EXULU claim-check] saveClaimCheck is not wired; this check cannot survive a reload."
|
|
@@ -31252,8 +32463,8 @@ function registerClaimCheckRoutes(app, deps) {
|
|
|
31252
32463
|
userId: Number(user.id),
|
|
31253
32464
|
result: completedResult
|
|
31254
32465
|
});
|
|
31255
|
-
} catch (
|
|
31256
|
-
console.warn("[EXULU claim-check] could not store the check for this message.",
|
|
32466
|
+
} catch (err4) {
|
|
32467
|
+
console.warn("[EXULU claim-check] could not store the check for this message.", err4);
|
|
31257
32468
|
}
|
|
31258
32469
|
}
|
|
31259
32470
|
}
|
|
@@ -31264,7 +32475,7 @@ function registerClaimCheckRoutes(app, deps) {
|
|
|
31264
32475
|
return;
|
|
31265
32476
|
}
|
|
31266
32477
|
const session = req.params.session ?? "";
|
|
31267
|
-
if (!
|
|
32478
|
+
if (!UUID_RE2.test(session)) {
|
|
31268
32479
|
res.status(400).json({ detail: "session must be a uuid." });
|
|
31269
32480
|
return;
|
|
31270
32481
|
}
|
|
@@ -31281,8 +32492,8 @@ function registerClaimCheckRoutes(app, deps) {
|
|
|
31281
32492
|
try {
|
|
31282
32493
|
const checks = await deps.listClaimChecks({ session, userId: Number(auth.user.id) });
|
|
31283
32494
|
res.status(200).json({ checks });
|
|
31284
|
-
} catch (
|
|
31285
|
-
console.error("[EXULU claim-check] could not read stored checks.",
|
|
32495
|
+
} catch (err4) {
|
|
32496
|
+
console.error("[EXULU claim-check] could not read stored checks.", err4);
|
|
31286
32497
|
res.status(500).json({ detail: "Could not read stored checks." });
|
|
31287
32498
|
}
|
|
31288
32499
|
});
|
|
@@ -32628,9 +33839,9 @@ async function runClaimCheck(args) {
|
|
|
32628
33839
|
limits: { truncated: skipped.length > 0 || truncation.sources > 0, sentencesSkipped: skipped.length },
|
|
32629
33840
|
notes: state.notes
|
|
32630
33841
|
};
|
|
32631
|
-
} catch (
|
|
33842
|
+
} catch (err4) {
|
|
32632
33843
|
timings.totalMs = Date.now() - startedAt;
|
|
32633
|
-
const message =
|
|
33844
|
+
const message = err4 instanceof Error ? err4.message : String(err4);
|
|
32634
33845
|
return {
|
|
32635
33846
|
status: "partial",
|
|
32636
33847
|
score: scoreClaims([], options.thresholds),
|
|
@@ -32692,8 +33903,8 @@ function makeSecondChance(args) {
|
|
|
32692
33903
|
}))
|
|
32693
33904
|
);
|
|
32694
33905
|
return selectEvidence([claimText], index, MAX_SNIPPETS_PER_CLAIM);
|
|
32695
|
-
} catch (
|
|
32696
|
-
console.warn("[EXULU claim-check] second-chance retrieval failed:",
|
|
33906
|
+
} catch (err4) {
|
|
33907
|
+
console.warn("[EXULU claim-check] second-chance retrieval failed:", err4);
|
|
32697
33908
|
return [];
|
|
32698
33909
|
}
|
|
32699
33910
|
};
|
|
@@ -32741,8 +33952,8 @@ async function testSource(source, deps) {
|
|
|
32741
33952
|
try {
|
|
32742
33953
|
await entry.ping();
|
|
32743
33954
|
return { ok: true };
|
|
32744
|
-
} catch (
|
|
32745
|
-
return { ok: false, reason: "unreachable", message:
|
|
33955
|
+
} catch (err4) {
|
|
33956
|
+
return { ok: false, reason: "unreachable", message: err4.message };
|
|
32746
33957
|
}
|
|
32747
33958
|
}
|
|
32748
33959
|
|
|
@@ -33441,7 +34652,7 @@ init_flow();
|
|
|
33441
34652
|
|
|
33442
34653
|
// src/exulu/recall/verify.ts
|
|
33443
34654
|
init_cjs_shims();
|
|
33444
|
-
var
|
|
34655
|
+
var import_node_crypto19 = require("crypto");
|
|
33445
34656
|
var TOLERANCE_SECONDS = 5 * 60;
|
|
33446
34657
|
var header = (headers, ...names) => {
|
|
33447
34658
|
for (const name of names) {
|
|
@@ -33459,7 +34670,7 @@ var safeEqual = (a, b) => {
|
|
|
33459
34670
|
const bufA = Buffer.from(a);
|
|
33460
34671
|
const bufB = Buffer.from(b);
|
|
33461
34672
|
if (bufA.length !== bufB.length) return false;
|
|
33462
|
-
return (0,
|
|
34673
|
+
return (0, import_node_crypto19.timingSafeEqual)(bufA, bufB);
|
|
33463
34674
|
};
|
|
33464
34675
|
var verifyRecallRequest = (headers, rawBody, secret = recallVerificationSecret()) => {
|
|
33465
34676
|
if (!secret) {
|
|
@@ -33481,7 +34692,7 @@ var verifyRecallRequest = (headers, rawBody, secret = recallVerificationSecret()
|
|
|
33481
34692
|
}
|
|
33482
34693
|
const body = typeof rawBody === "string" ? rawBody : rawBody.toString("utf8");
|
|
33483
34694
|
const signedContent = `${id}.${timestamp}.${body}`;
|
|
33484
|
-
const expected = (0,
|
|
34695
|
+
const expected = (0, import_node_crypto19.createHmac)("sha256", secretKey(secret)).update(signedContent).digest("base64");
|
|
33485
34696
|
const passed = signatureHeader.split(" ").some((entry) => {
|
|
33486
34697
|
const [, sig] = entry.split(",");
|
|
33487
34698
|
return !!sig && safeEqual(sig, expected);
|
|
@@ -33846,6 +35057,7 @@ var {
|
|
|
33846
35057
|
rbacSchema: rbacSchema2,
|
|
33847
35058
|
promptLibrarySchema: promptLibrarySchema2,
|
|
33848
35059
|
contextPresetsSchema: contextPresetsSchema2,
|
|
35060
|
+
contextFoldersSchema: contextFoldersSchema2,
|
|
33849
35061
|
teamsSchema: teamsSchema2,
|
|
33850
35062
|
entityTypeSettingsSchema: entityTypeSettingsSchema2,
|
|
33851
35063
|
promptFavoritesSchema: promptFavoritesSchema2,
|
|
@@ -33908,6 +35120,12 @@ var createExpressRoutes = async (app, tools, contexts, config, evals, tracer) =>
|
|
|
33908
35120
|
jobResultsSchema2(),
|
|
33909
35121
|
promptLibrarySchema2(),
|
|
33910
35122
|
contextPresetsSchema2(),
|
|
35123
|
+
// Knowledge folders (2026-10): UI-only grouping of knowledge contexts
|
|
35124
|
+
// for the IMP's folder view. apiWrites: "super_admin" (core-schema.ts)
|
|
35125
|
+
// reserves the generic CreateOne/UpdateOne*/RemoveOne*/CopyOneById
|
|
35126
|
+
// mutations for super admins; reads stay generic for every
|
|
35127
|
+
// authenticated user, same split as sharedArtifactsSchema below.
|
|
35128
|
+
contextFoldersSchema2(),
|
|
33911
35129
|
teamsSchema2(),
|
|
33912
35130
|
entityTypeSettingsSchema2(),
|
|
33913
35131
|
promptFavoritesSchema2(),
|
|
@@ -34060,8 +35278,8 @@ var createExpressRoutes = async (app, tools, contexts, config, evals, tracer) =>
|
|
|
34060
35278
|
}
|
|
34061
35279
|
const event = req.body;
|
|
34062
35280
|
res.status(200).json({ ok: true });
|
|
34063
|
-
void recallService.handleWebhookEvent(event).catch((
|
|
34064
|
-
console.error("[EXULU-RECALL] webhook processing failed",
|
|
35281
|
+
void recallService.handleWebhookEvent(event).catch((err4) => {
|
|
35282
|
+
console.error("[EXULU-RECALL] webhook processing failed", err4);
|
|
34065
35283
|
});
|
|
34066
35284
|
});
|
|
34067
35285
|
const routineWebhookHandler = createRoutineWebhookHandler({
|
|
@@ -34092,7 +35310,7 @@ var createExpressRoutes = async (app, tools, contexts, config, evals, tracer) =>
|
|
|
34092
35310
|
inputs: payload
|
|
34093
35311
|
};
|
|
34094
35312
|
await queue.queue.add("email-intake", jobData, {
|
|
34095
|
-
jobId: (0,
|
|
35313
|
+
jobId: (0, import_node_crypto20.randomUUID)(),
|
|
34096
35314
|
attempts: 3,
|
|
34097
35315
|
removeOnComplete: 5e3,
|
|
34098
35316
|
removeOnFail: 1e4,
|
|
@@ -34288,13 +35506,13 @@ var createExpressRoutes = async (app, tools, contexts, config, evals, tracer) =>
|
|
|
34288
35506
|
user,
|
|
34289
35507
|
agent
|
|
34290
35508
|
});
|
|
34291
|
-
} catch (
|
|
34292
|
-
if (
|
|
34293
|
-
const status =
|
|
34294
|
-
res.status(status).json({ message:
|
|
35509
|
+
} catch (err4) {
|
|
35510
|
+
if (err4 instanceof ResolveModelError) {
|
|
35511
|
+
const status = err4.code === "MODEL_FORBIDDEN" ? 403 : 400;
|
|
35512
|
+
res.status(status).json({ message: err4.message, code: err4.code });
|
|
34295
35513
|
return;
|
|
34296
35514
|
}
|
|
34297
|
-
throw
|
|
35515
|
+
throw err4;
|
|
34298
35516
|
}
|
|
34299
35517
|
const resolvedLanguageModel = resolved.languageModel;
|
|
34300
35518
|
const resolvedModelId = resolved.model.id;
|
|
@@ -34345,13 +35563,13 @@ ${customInstructions}` : agent.instructions,
|
|
|
34345
35563
|
contextWindow,
|
|
34346
35564
|
disabledTools
|
|
34347
35565
|
});
|
|
34348
|
-
} catch (
|
|
35566
|
+
} catch (err4) {
|
|
34349
35567
|
if (headers.session) clearStreamActive(headers.session);
|
|
34350
35568
|
console.error(
|
|
34351
35569
|
"[EXULU] chat request failed before streaming.",
|
|
34352
|
-
|
|
35570
|
+
err4 instanceof Error ? err4.message.slice(0, 500) : err4
|
|
34353
35571
|
);
|
|
34354
|
-
const { status, body } = describeRequestError(
|
|
35572
|
+
const { status, body } = describeRequestError(err4);
|
|
34355
35573
|
res.status(status).send(body);
|
|
34356
35574
|
return;
|
|
34357
35575
|
}
|
|
@@ -34463,7 +35681,7 @@ ${customInstructions}` : agent.instructions,
|
|
|
34463
35681
|
contextId: agent.memory,
|
|
34464
35682
|
agentId: agent.id,
|
|
34465
35683
|
session: headers.session ?? null,
|
|
34466
|
-
messageId: responseMessage?.id ?? messages[messages.length - 1]?.id ?? (0,
|
|
35684
|
+
messageId: responseMessage?.id ?? messages[messages.length - 1]?.id ?? (0, import_node_crypto20.randomUUID)(),
|
|
34467
35685
|
userId: user?.id ?? null
|
|
34468
35686
|
});
|
|
34469
35687
|
}
|
|
@@ -34542,12 +35760,12 @@ ${customInstructions}` : agent.instructions,
|
|
|
34542
35760
|
onTokenUsage: async ({ inputTokens, outputTokens }) => {
|
|
34543
35761
|
}
|
|
34544
35762
|
});
|
|
34545
|
-
} catch (
|
|
35763
|
+
} catch (err4) {
|
|
34546
35764
|
console.error(
|
|
34547
35765
|
"[EXULU] run request failed.",
|
|
34548
|
-
|
|
35766
|
+
err4 instanceof Error ? err4.message.slice(0, 500) : err4
|
|
34549
35767
|
);
|
|
34550
|
-
const { status, body } = describeRequestError(
|
|
35768
|
+
const { status, body } = describeRequestError(err4);
|
|
34551
35769
|
res.status(status).send(body);
|
|
34552
35770
|
return;
|
|
34553
35771
|
}
|
|
@@ -34614,13 +35832,13 @@ ${customInstructions}` : agent.instructions,
|
|
|
34614
35832
|
let resolved;
|
|
34615
35833
|
try {
|
|
34616
35834
|
resolved = await resolveModel({ modelId, user, agent });
|
|
34617
|
-
} catch (
|
|
34618
|
-
if (
|
|
34619
|
-
const status =
|
|
34620
|
-
res.status(status).json({ message:
|
|
35835
|
+
} catch (err4) {
|
|
35836
|
+
if (err4 instanceof ResolveModelError) {
|
|
35837
|
+
const status = err4.code === "MODEL_FORBIDDEN" ? 403 : 400;
|
|
35838
|
+
res.status(status).json({ message: err4.message, code: err4.code });
|
|
34621
35839
|
return;
|
|
34622
35840
|
}
|
|
34623
|
-
throw
|
|
35841
|
+
throw err4;
|
|
34624
35842
|
}
|
|
34625
35843
|
const contextWindow = await resolveContextWindow({
|
|
34626
35844
|
modelId: resolved.model.id
|
|
@@ -34636,13 +35854,13 @@ ${customInstructions}` : agent.instructions,
|
|
|
34636
35854
|
modelId: resolved.model.id
|
|
34637
35855
|
});
|
|
34638
35856
|
res.json(result);
|
|
34639
|
-
} catch (
|
|
34640
|
-
if (
|
|
34641
|
-
res.status(422).send(
|
|
35857
|
+
} catch (err4) {
|
|
35858
|
+
if (err4 instanceof CompactionInsufficientError) {
|
|
35859
|
+
res.status(422).send(err4.message);
|
|
34642
35860
|
return;
|
|
34643
35861
|
}
|
|
34644
|
-
console.error("[EXULU] compactSession failed.",
|
|
34645
|
-
res.status(500).json({ message:
|
|
35862
|
+
console.error("[EXULU] compactSession failed.", err4);
|
|
35863
|
+
res.status(500).json({ message: err4 instanceof Error ? err4.message : "Compaction failed." });
|
|
34646
35864
|
}
|
|
34647
35865
|
});
|
|
34648
35866
|
};
|
|
@@ -34707,13 +35925,13 @@ ${customInstructions}` : agent.instructions,
|
|
|
34707
35925
|
user,
|
|
34708
35926
|
agent
|
|
34709
35927
|
});
|
|
34710
|
-
} catch (
|
|
34711
|
-
if (
|
|
34712
|
-
const status =
|
|
34713
|
-
res.status(status).json({ detail:
|
|
35928
|
+
} catch (err4) {
|
|
35929
|
+
if (err4 instanceof ResolveModelError) {
|
|
35930
|
+
const status = err4.code === "MODEL_FORBIDDEN" ? 403 : 400;
|
|
35931
|
+
res.status(status).json({ detail: err4.message, code: err4.code });
|
|
34714
35932
|
return;
|
|
34715
35933
|
}
|
|
34716
|
-
throw
|
|
35934
|
+
throw err4;
|
|
34717
35935
|
}
|
|
34718
35936
|
try {
|
|
34719
35937
|
const { suggestions, usage } = await generateSuggestions({
|
|
@@ -34753,10 +35971,10 @@ ${customInstructions}` : agent.instructions,
|
|
|
34753
35971
|
] : []
|
|
34754
35972
|
]);
|
|
34755
35973
|
res.status(200).json({ suggestions });
|
|
34756
|
-
} catch (
|
|
34757
|
-
console.error("[EXULU] suggestions generation failed",
|
|
35974
|
+
} catch (err4) {
|
|
35975
|
+
console.error("[EXULU] suggestions generation failed", err4);
|
|
34758
35976
|
res.status(500).json({
|
|
34759
|
-
detail:
|
|
35977
|
+
detail: err4 instanceof Error ? err4.message : "Failed to generate suggestions."
|
|
34760
35978
|
});
|
|
34761
35979
|
}
|
|
34762
35980
|
});
|
|
@@ -34766,14 +35984,14 @@ ${customInstructions}` : agent.instructions,
|
|
|
34766
35984
|
limits: { fileSize: MAX_TRANSCRIBE_BYTES }
|
|
34767
35985
|
});
|
|
34768
35986
|
const transcribeUploadMiddleware = (req, res, next) => {
|
|
34769
|
-
transcribeUpload.single("file")(req, res, (
|
|
34770
|
-
if (!
|
|
34771
|
-
const code =
|
|
35987
|
+
transcribeUpload.single("file")(req, res, (err4) => {
|
|
35988
|
+
if (!err4) return next();
|
|
35989
|
+
const code = err4?.code;
|
|
34772
35990
|
if (code === "LIMIT_FILE_SIZE") {
|
|
34773
35991
|
res.status(413).json({ detail: "Recording too large. Please record a shorter clip." });
|
|
34774
35992
|
return;
|
|
34775
35993
|
}
|
|
34776
|
-
res.status(400).json({ detail:
|
|
35994
|
+
res.status(400).json({ detail: err4 instanceof Error ? err4.message : "Upload failed." });
|
|
34777
35995
|
});
|
|
34778
35996
|
};
|
|
34779
35997
|
app.post(
|
|
@@ -34817,15 +36035,15 @@ ${customInstructions}` : agent.instructions,
|
|
|
34817
36035
|
try {
|
|
34818
36036
|
const { text } = await transcribeAudio({ file, language });
|
|
34819
36037
|
res.status(200).json({ text });
|
|
34820
|
-
} catch (
|
|
34821
|
-
if (
|
|
34822
|
-
const code =
|
|
34823
|
-
res.status(code).json({ detail:
|
|
36038
|
+
} catch (err4) {
|
|
36039
|
+
if (err4 instanceof TranscriptionError) {
|
|
36040
|
+
const code = err4.upstreamStatus >= 500 ? 502 : err4.upstreamStatus;
|
|
36041
|
+
res.status(code).json({ detail: err4.message });
|
|
34824
36042
|
return;
|
|
34825
36043
|
}
|
|
34826
|
-
console.error("[EXULU] /transcribe failed",
|
|
36044
|
+
console.error("[EXULU] /transcribe failed", err4);
|
|
34827
36045
|
res.status(500).json({
|
|
34828
|
-
detail:
|
|
36046
|
+
detail: err4 instanceof Error ? err4.message : "Transcription failed."
|
|
34829
36047
|
});
|
|
34830
36048
|
}
|
|
34831
36049
|
}
|
|
@@ -34904,8 +36122,8 @@ ${customInstructions}` : agent.instructions,
|
|
|
34904
36122
|
const response = await fetch(url, {
|
|
34905
36123
|
headers: { Authorization: recallApiKey(), accept: "application/json" },
|
|
34906
36124
|
signal: AbortSignal.timeout(1e4)
|
|
34907
|
-
}).catch((
|
|
34908
|
-
throw new Error(`Unable to reach the Recall API: ${
|
|
36125
|
+
}).catch((err4) => {
|
|
36126
|
+
throw new Error(`Unable to reach the Recall API: ${err4.message}`);
|
|
34909
36127
|
});
|
|
34910
36128
|
if (!response.ok) {
|
|
34911
36129
|
const body = await response.text();
|
|
@@ -34929,8 +36147,8 @@ ${customInstructions}` : agent.instructions,
|
|
|
34929
36147
|
}
|
|
34930
36148
|
});
|
|
34931
36149
|
res.status(200).json(result);
|
|
34932
|
-
} catch (
|
|
34933
|
-
res.status(400).json({ detail:
|
|
36150
|
+
} catch (err4) {
|
|
36151
|
+
res.status(400).json({ detail: err4.message });
|
|
34934
36152
|
}
|
|
34935
36153
|
});
|
|
34936
36154
|
const MAX_TTS_INPUT_CHARS = 4e3;
|
|
@@ -34978,15 +36196,15 @@ ${customInstructions}` : agent.instructions,
|
|
|
34978
36196
|
res.setHeader("Content-Length", String(audio.length));
|
|
34979
36197
|
res.setHeader("Cache-Control", "no-store");
|
|
34980
36198
|
res.send(audio);
|
|
34981
|
-
} catch (
|
|
34982
|
-
if (
|
|
34983
|
-
const code =
|
|
34984
|
-
res.status(code).json({ detail:
|
|
36199
|
+
} catch (err4) {
|
|
36200
|
+
if (err4 instanceof SpeechError) {
|
|
36201
|
+
const code = err4.upstreamStatus >= 500 ? 502 : err4.upstreamStatus;
|
|
36202
|
+
res.status(code).json({ detail: err4.message });
|
|
34985
36203
|
return;
|
|
34986
36204
|
}
|
|
34987
|
-
console.error("[EXULU] /speech failed",
|
|
36205
|
+
console.error("[EXULU] /speech failed", err4);
|
|
34988
36206
|
res.status(500).json({
|
|
34989
|
-
detail:
|
|
36207
|
+
detail: err4 instanceof Error ? err4.message : "Speech generation failed."
|
|
34990
36208
|
});
|
|
34991
36209
|
}
|
|
34992
36210
|
}
|
|
@@ -34997,10 +36215,10 @@ ${customInstructions}` : agent.instructions,
|
|
|
34997
36215
|
const configPath = process.env.LITELLM_CONFIG_PATH ?? (0, import_node_path10.resolve)(process.cwd(), "./config.litellm.yaml");
|
|
34998
36216
|
const models2 = parseImageGenerationModels(configPath);
|
|
34999
36217
|
return new Map(models2.map((m) => [m.model_name, m]));
|
|
35000
|
-
} catch (
|
|
36218
|
+
} catch (err4) {
|
|
35001
36219
|
console.error(
|
|
35002
36220
|
"[EXULU] Skipping /images/* routes due to config.litellm.yaml error:",
|
|
35003
|
-
|
|
36221
|
+
err4.message
|
|
35004
36222
|
);
|
|
35005
36223
|
return /* @__PURE__ */ new Map();
|
|
35006
36224
|
}
|
|
@@ -35112,7 +36330,7 @@ ${customInstructions}` : agent.instructions,
|
|
|
35112
36330
|
const keys = [];
|
|
35113
36331
|
const revisedPrompts = [];
|
|
35114
36332
|
for (const img of images) {
|
|
35115
|
-
const filename = `${(0,
|
|
36333
|
+
const filename = `${(0, import_node_crypto20.randomUUID)()}.${img.extension}`;
|
|
35116
36334
|
const key = `sessions/${sessionId}/images/${toolCallId}/${filename}`;
|
|
35117
36335
|
const fullKey = await uploadFile(
|
|
35118
36336
|
img.buffer,
|
|
@@ -35202,16 +36420,16 @@ ${style.markdown}` : params.prompt;
|
|
|
35202
36420
|
revisedPrompt: revisedPrompts[i]
|
|
35203
36421
|
}))
|
|
35204
36422
|
});
|
|
35205
|
-
} catch (
|
|
36423
|
+
} catch (err4) {
|
|
35206
36424
|
if (abortController.signal.aborted) return;
|
|
35207
|
-
if (
|
|
35208
|
-
const code =
|
|
35209
|
-
res.status(code).json({ detail:
|
|
36425
|
+
if (err4 instanceof ImageGenerationError) {
|
|
36426
|
+
const code = err4.upstreamStatus >= 500 ? 502 : err4.upstreamStatus;
|
|
36427
|
+
res.status(code).json({ detail: err4.message });
|
|
35210
36428
|
return;
|
|
35211
36429
|
}
|
|
35212
|
-
console.error("[EXULU] /images/generate failed",
|
|
36430
|
+
console.error("[EXULU] /images/generate failed", err4);
|
|
35213
36431
|
res.status(500).json({
|
|
35214
|
-
detail:
|
|
36432
|
+
detail: err4 instanceof Error ? err4.message : "Image generation failed."
|
|
35215
36433
|
});
|
|
35216
36434
|
}
|
|
35217
36435
|
});
|
|
@@ -35319,16 +36537,16 @@ ${style.markdown}` : params.prompt;
|
|
|
35319
36537
|
revisedPrompt: revisedPrompts[i]
|
|
35320
36538
|
}))
|
|
35321
36539
|
});
|
|
35322
|
-
} catch (
|
|
36540
|
+
} catch (err4) {
|
|
35323
36541
|
if (abortController.signal.aborted) return;
|
|
35324
|
-
if (
|
|
35325
|
-
const code =
|
|
35326
|
-
res.status(code).json({ detail:
|
|
36542
|
+
if (err4 instanceof ImageGenerationError) {
|
|
36543
|
+
const code = err4.upstreamStatus >= 500 ? 502 : err4.upstreamStatus;
|
|
36544
|
+
res.status(code).json({ detail: err4.message });
|
|
35327
36545
|
return;
|
|
35328
36546
|
}
|
|
35329
|
-
console.error("[EXULU] /images/edit failed",
|
|
36547
|
+
console.error("[EXULU] /images/edit failed", err4);
|
|
35330
36548
|
res.status(500).json({
|
|
35331
|
-
detail:
|
|
36549
|
+
detail: err4 instanceof Error ? err4.message : "Image edit failed."
|
|
35332
36550
|
});
|
|
35333
36551
|
}
|
|
35334
36552
|
});
|
|
@@ -35400,7 +36618,7 @@ ${style.markdown}` : params.prompt;
|
|
|
35400
36618
|
(d) => `- ${d.presignedUrl} (prompt: "${d.prompt}", model: ${d.model}${d.styleName ? `, style: ${d.styleName}` : ""})`
|
|
35401
36619
|
);
|
|
35402
36620
|
const messageText = "The user generated and selected the following image(s) in this chat:\n" + lines.join("\n");
|
|
35403
|
-
const messageId = (0,
|
|
36621
|
+
const messageId = (0, import_node_crypto20.randomUUID)();
|
|
35404
36622
|
const uiMessage = {
|
|
35405
36623
|
id: messageId,
|
|
35406
36624
|
role: "system",
|
|
@@ -35533,11 +36751,11 @@ ${style.markdown}` : params.prompt;
|
|
|
35533
36751
|
reader.releaseLock();
|
|
35534
36752
|
}
|
|
35535
36753
|
res.end();
|
|
35536
|
-
} catch (
|
|
35537
|
-
console.error("[EXULU] LiteLLM UI proxy failed",
|
|
36754
|
+
} catch (err4) {
|
|
36755
|
+
console.error("[EXULU] LiteLLM UI proxy failed", err4);
|
|
35538
36756
|
if (!res.headersSent) {
|
|
35539
36757
|
res.status(502).json({
|
|
35540
|
-
detail:
|
|
36758
|
+
detail: err4 instanceof Error ? err4.message : "LiteLLM UI proxy failed."
|
|
35541
36759
|
});
|
|
35542
36760
|
} else {
|
|
35543
36761
|
res.end();
|
|
@@ -35662,11 +36880,11 @@ ${style.markdown}` : params.prompt;
|
|
|
35662
36880
|
reader.releaseLock();
|
|
35663
36881
|
}
|
|
35664
36882
|
res.end();
|
|
35665
|
-
} catch (
|
|
35666
|
-
console.error("[EXULU] /litellm proxy failed",
|
|
36883
|
+
} catch (err4) {
|
|
36884
|
+
console.error("[EXULU] /litellm proxy failed", err4);
|
|
35667
36885
|
if (!res.headersSent) {
|
|
35668
36886
|
res.status(502).json({
|
|
35669
|
-
detail:
|
|
36887
|
+
detail: err4 instanceof Error ? err4.message : "LiteLLM proxy failed."
|
|
35670
36888
|
});
|
|
35671
36889
|
} else {
|
|
35672
36890
|
res.end();
|
|
@@ -35723,8 +36941,8 @@ ${style.markdown}` : params.prompt;
|
|
|
35723
36941
|
`attachment; filename="${encodeURIComponent(filename)}"`
|
|
35724
36942
|
);
|
|
35725
36943
|
res.send(bytes);
|
|
35726
|
-
} catch (
|
|
35727
|
-
console.error("[EXULU] markdown export failed",
|
|
36944
|
+
} catch (err4) {
|
|
36945
|
+
console.error("[EXULU] markdown export failed", err4);
|
|
35728
36946
|
res.status(500).json({ detail: "Export failed." });
|
|
35729
36947
|
}
|
|
35730
36948
|
});
|
|
@@ -35822,14 +37040,14 @@ ${style.markdown}` : params.prompt;
|
|
|
35822
37040
|
}
|
|
35823
37041
|
try {
|
|
35824
37042
|
res.status(200).json({ usage: await getMyUsageView(authResult.user.id, window) });
|
|
35825
|
-
} catch (
|
|
35826
|
-
if (
|
|
35827
|
-
res.status(502).json({ detail:
|
|
37043
|
+
} catch (err4) {
|
|
37044
|
+
if (err4 instanceof LiteLLMAdminError) {
|
|
37045
|
+
res.status(502).json({ detail: err4.message });
|
|
35828
37046
|
return;
|
|
35829
37047
|
}
|
|
35830
|
-
console.error("[EXULU] /me/usage failed",
|
|
37048
|
+
console.error("[EXULU] /me/usage failed", err4);
|
|
35831
37049
|
res.status(500).json({
|
|
35832
|
-
detail:
|
|
37050
|
+
detail: err4 instanceof Error ? err4.message : "Usage query failed."
|
|
35833
37051
|
});
|
|
35834
37052
|
}
|
|
35835
37053
|
});
|
|
@@ -35859,11 +37077,11 @@ ${style.markdown}` : params.prompt;
|
|
|
35859
37077
|
try {
|
|
35860
37078
|
await upsertBudget(tag, body.max_budget, body.budget_duration, body.budget_reset_at);
|
|
35861
37079
|
results.push({ entityId: String(id), ok: true });
|
|
35862
|
-
} catch (
|
|
37080
|
+
} catch (err4) {
|
|
35863
37081
|
results.push({
|
|
35864
37082
|
entityId: String(id),
|
|
35865
37083
|
ok: false,
|
|
35866
|
-
error:
|
|
37084
|
+
error: err4 instanceof Error ? err4.message : "Failed."
|
|
35867
37085
|
});
|
|
35868
37086
|
}
|
|
35869
37087
|
}
|
|
@@ -35890,9 +37108,9 @@ ${style.markdown}` : params.prompt;
|
|
|
35890
37108
|
await upsertBudget(tag, body.max_budget, body.budget_duration, body.budget_reset_at);
|
|
35891
37109
|
const info = await tagInfo([tag]);
|
|
35892
37110
|
res.status(200).json({ budget: info[tag] ?? null });
|
|
35893
|
-
} catch (
|
|
37111
|
+
} catch (err4) {
|
|
35894
37112
|
res.status(502).json({
|
|
35895
|
-
detail:
|
|
37113
|
+
detail: err4 instanceof Error ? err4.message : "Failed to save budget."
|
|
35896
37114
|
});
|
|
35897
37115
|
}
|
|
35898
37116
|
}
|
|
@@ -35912,9 +37130,9 @@ ${style.markdown}` : params.prompt;
|
|
|
35912
37130
|
await tagDelete(tag);
|
|
35913
37131
|
invalidateBudgetCaches(tag);
|
|
35914
37132
|
res.status(204).end();
|
|
35915
|
-
} catch (
|
|
37133
|
+
} catch (err4) {
|
|
35916
37134
|
res.status(502).json({
|
|
35917
|
-
detail:
|
|
37135
|
+
detail: err4 instanceof Error ? err4.message : "Failed to delete budget."
|
|
35918
37136
|
});
|
|
35919
37137
|
}
|
|
35920
37138
|
}
|
|
@@ -36285,14 +37503,14 @@ ${style.markdown}` : params.prompt;
|
|
|
36285
37503
|
echoedPrefix
|
|
36286
37504
|
);
|
|
36287
37505
|
res.status(200).json(projected);
|
|
36288
|
-
} catch (
|
|
36289
|
-
if (
|
|
36290
|
-
res.status(502).json({ detail:
|
|
37506
|
+
} catch (err4) {
|
|
37507
|
+
if (err4 instanceof LiteLLMAdminError) {
|
|
37508
|
+
res.status(502).json({ detail: err4.message });
|
|
36291
37509
|
return;
|
|
36292
37510
|
}
|
|
36293
|
-
console.error("[EXULU] /admin/litellm/tag-activity failed",
|
|
37511
|
+
console.error("[EXULU] /admin/litellm/tag-activity failed", err4);
|
|
36294
37512
|
res.status(500).json({
|
|
36295
|
-
detail:
|
|
37513
|
+
detail: err4 instanceof Error ? err4.message : "Analytics query failed."
|
|
36296
37514
|
});
|
|
36297
37515
|
}
|
|
36298
37516
|
}
|
|
@@ -36353,7 +37571,7 @@ ${style.markdown}` : params.prompt;
|
|
|
36353
37571
|
void (async () => {
|
|
36354
37572
|
const { db: db2 } = await postgresClient();
|
|
36355
37573
|
await seedBundledSkills({ db: db2, config });
|
|
36356
|
-
})().catch((
|
|
37574
|
+
})().catch((err4) => console.error("[SKILLS] seeding the bundled skills failed", err4));
|
|
36357
37575
|
app.get("/skills/agent/bootstrap", async (_req, res) => {
|
|
36358
37576
|
try {
|
|
36359
37577
|
const zip = new import_jszip4.default();
|
|
@@ -36369,8 +37587,8 @@ ${style.markdown}` : params.prompt;
|
|
|
36369
37587
|
res.setHeader("Content-Type", "application/zip");
|
|
36370
37588
|
res.setHeader("Content-Disposition", 'attachment; filename="imp-skills.zip"');
|
|
36371
37589
|
res.send(buffer);
|
|
36372
|
-
} catch (
|
|
36373
|
-
console.error("[SKILLS] Failed to build bootstrap zip",
|
|
37590
|
+
} catch (err4) {
|
|
37591
|
+
console.error("[SKILLS] Failed to build bootstrap zip", err4);
|
|
36374
37592
|
res.status(500).json({ detail: "Failed to build bootstrap skill." });
|
|
36375
37593
|
}
|
|
36376
37594
|
});
|
|
@@ -36454,17 +37672,17 @@ ${style.markdown}` : params.prompt;
|
|
|
36454
37672
|
const { db: db2 } = await postgresClient();
|
|
36455
37673
|
const existing = await resolveSkillByName(db2, name);
|
|
36456
37674
|
if (existing) {
|
|
36457
|
-
const
|
|
36458
|
-
if (
|
|
37675
|
+
const canWrite2 = await canAccessSkill(db2, existing, "write", authResult.user);
|
|
37676
|
+
if (canWrite2) {
|
|
36459
37677
|
const nextVersion = (existing.current_version ?? 1) + 1;
|
|
36460
37678
|
try {
|
|
36461
37679
|
await extractBundleToVersion({ bytes, skillId: existing.id, version: nextVersion, config });
|
|
36462
|
-
} catch (
|
|
36463
|
-
if (
|
|
36464
|
-
res.status(400).json({ detail:
|
|
37680
|
+
} catch (err4) {
|
|
37681
|
+
if (err4 instanceof BundleValidationError) {
|
|
37682
|
+
res.status(400).json({ detail: err4.message });
|
|
36465
37683
|
return;
|
|
36466
37684
|
}
|
|
36467
|
-
console.error("[SKILLS] publish (new version) failed",
|
|
37685
|
+
console.error("[SKILLS] publish (new version) failed", err4);
|
|
36468
37686
|
res.status(500).json({ detail: "Failed to publish new version." });
|
|
36469
37687
|
return;
|
|
36470
37688
|
}
|
|
@@ -36497,15 +37715,15 @@ ${style.markdown}` : params.prompt;
|
|
|
36497
37715
|
return;
|
|
36498
37716
|
}
|
|
36499
37717
|
const meta = await parseSkillFrontmatter(bytes);
|
|
36500
|
-
const skillId = (0,
|
|
37718
|
+
const skillId = (0, import_node_crypto20.randomUUID)();
|
|
36501
37719
|
try {
|
|
36502
37720
|
await extractBundleToVersion({ bytes, skillId, version: 1, config });
|
|
36503
|
-
} catch (
|
|
36504
|
-
if (
|
|
36505
|
-
res.status(400).json({ detail:
|
|
37721
|
+
} catch (err4) {
|
|
37722
|
+
if (err4 instanceof BundleValidationError) {
|
|
37723
|
+
res.status(400).json({ detail: err4.message });
|
|
36506
37724
|
return;
|
|
36507
37725
|
}
|
|
36508
|
-
console.error("[SKILLS] publish (create) failed",
|
|
37726
|
+
console.error("[SKILLS] publish (create) failed", err4);
|
|
36509
37727
|
res.status(500).json({ detail: "Failed to publish skill." });
|
|
36510
37728
|
return;
|
|
36511
37729
|
}
|
|
@@ -36525,7 +37743,7 @@ ${style.markdown}` : params.prompt;
|
|
|
36525
37743
|
rights_mode: visibility,
|
|
36526
37744
|
created_by: authResult.user.id
|
|
36527
37745
|
});
|
|
36528
|
-
} catch (
|
|
37746
|
+
} catch (err4) {
|
|
36529
37747
|
res.status(409).json({ detail: "That name is unavailable." });
|
|
36530
37748
|
return;
|
|
36531
37749
|
}
|
|
@@ -36579,8 +37797,8 @@ ${style.markdown}` : params.prompt;
|
|
|
36579
37797
|
const s3Key = `skills/${skillId}/v1/SKILL.md`;
|
|
36580
37798
|
try {
|
|
36581
37799
|
await uploadFile(Buffer.from(skillMdContent, "utf-8"), s3Key, config, { contentType: "text/markdown" }, void 0, void 0, true);
|
|
36582
|
-
} catch (
|
|
36583
|
-
console.error("[SKILLS] Failed to create SKILL.md in S3",
|
|
37800
|
+
} catch (err4) {
|
|
37801
|
+
console.error("[SKILLS] Failed to create SKILL.md in S3", err4);
|
|
36584
37802
|
res.status(500).json({ detail: "Failed to initialise skill folder in S3." });
|
|
36585
37803
|
return;
|
|
36586
37804
|
}
|
|
@@ -36617,7 +37835,7 @@ ${style.markdown}` : params.prompt;
|
|
|
36617
37835
|
res.status(404).json({ detail: "Skill not found." });
|
|
36618
37836
|
return;
|
|
36619
37837
|
}
|
|
36620
|
-
const stagingKey = `user_${authResult.user.id}/skills/_staging/${(0,
|
|
37838
|
+
const stagingKey = `user_${authResult.user.id}/skills/_staging/${(0, import_node_crypto20.randomUUID)()}${extension}`;
|
|
36621
37839
|
const fullKey = config.fileUploads?.s3prefix ? `${config.fileUploads.s3prefix.replace(/\/$/, "")}/${stagingKey}` : stagingKey;
|
|
36622
37840
|
const uploadUrl = await getS3SignedUploadUrl(fullKey, contentType, config);
|
|
36623
37841
|
res.json({ uploadUrl, stagingKey });
|
|
@@ -36657,15 +37875,15 @@ ${style.markdown}` : params.prompt;
|
|
|
36657
37875
|
let bytes;
|
|
36658
37876
|
try {
|
|
36659
37877
|
bytes = await getS3ObjectBytes(fullStagingKey, config);
|
|
36660
|
-
} catch (
|
|
36661
|
-
console.error("[SKILLS] Failed to fetch staged bundle",
|
|
37878
|
+
} catch (err4) {
|
|
37879
|
+
console.error("[SKILLS] Failed to fetch staged bundle", err4);
|
|
36662
37880
|
res.status(500).json({ detail: "Failed to fetch staged bundle from S3." });
|
|
36663
37881
|
return;
|
|
36664
37882
|
}
|
|
36665
37883
|
let result;
|
|
36666
37884
|
try {
|
|
36667
37885
|
result = await extractBundleToS3({ bytes, skillId, isZip, config });
|
|
36668
|
-
} catch (
|
|
37886
|
+
} catch (err4) {
|
|
36669
37887
|
try {
|
|
36670
37888
|
await db2("skills").where({ id: skillId }).delete();
|
|
36671
37889
|
} catch (cleanupErr) {
|
|
@@ -36682,11 +37900,11 @@ ${style.markdown}` : params.prompt;
|
|
|
36682
37900
|
cleanupErr
|
|
36683
37901
|
);
|
|
36684
37902
|
}
|
|
36685
|
-
if (
|
|
36686
|
-
res.status(400).json({ detail:
|
|
37903
|
+
if (err4 instanceof BundleValidationError) {
|
|
37904
|
+
res.status(400).json({ detail: err4.message });
|
|
36687
37905
|
return;
|
|
36688
37906
|
}
|
|
36689
|
-
console.error("[SKILLS] Failed to extract bundle",
|
|
37907
|
+
console.error("[SKILLS] Failed to extract bundle", err4);
|
|
36690
37908
|
res.status(500).json({ detail: "Failed to extract bundle." });
|
|
36691
37909
|
return;
|
|
36692
37910
|
}
|
|
@@ -36700,8 +37918,8 @@ ${style.markdown}` : params.prompt;
|
|
|
36700
37918
|
});
|
|
36701
37919
|
try {
|
|
36702
37920
|
await deleteS3Object(fullStagingKey, config);
|
|
36703
|
-
} catch (
|
|
36704
|
-
console.warn(`[SKILLS] Failed to delete staging key ${fullStagingKey}; continuing.`,
|
|
37921
|
+
} catch (err4) {
|
|
37922
|
+
console.warn(`[SKILLS] Failed to delete staging key ${fullStagingKey}; continuing.`, err4);
|
|
36705
37923
|
}
|
|
36706
37924
|
res.json({ version: 1, filesCount: result.filesCount });
|
|
36707
37925
|
});
|
|
@@ -37109,8 +38327,8 @@ ${style.markdown}` : params.prompt;
|
|
|
37109
38327
|
const skills = await getEnabledSkills(agent, []);
|
|
37110
38328
|
const outcome = await refreshSessionSkills(sessionId, skills, config);
|
|
37111
38329
|
res.json({ ...outcome, skills: skills.map((s) => ({ id: s.id, name: s.name, version: s.current_version })) });
|
|
37112
|
-
} catch (
|
|
37113
|
-
console.error("[SKILLS] reload failed",
|
|
38330
|
+
} catch (err4) {
|
|
38331
|
+
console.error("[SKILLS] reload failed", err4);
|
|
37114
38332
|
res.status(500).json({ detail: "Could not reload the skills." });
|
|
37115
38333
|
}
|
|
37116
38334
|
});
|
|
@@ -37130,8 +38348,8 @@ ${style.markdown}` : params.prompt;
|
|
|
37130
38348
|
let objects;
|
|
37131
38349
|
try {
|
|
37132
38350
|
objects = await listS3ObjectsByPrefix(userSessionPrefix, config);
|
|
37133
|
-
} catch (
|
|
37134
|
-
console.error("[SESSION-FILES] Failed to list S3 objects",
|
|
38351
|
+
} catch (err4) {
|
|
38352
|
+
console.error("[SESSION-FILES] Failed to list S3 objects", err4);
|
|
37135
38353
|
res.status(500).json({ detail: "Failed to list session files." });
|
|
37136
38354
|
return;
|
|
37137
38355
|
}
|
|
@@ -37213,8 +38431,8 @@ ${style.markdown}` : params.prompt;
|
|
|
37213
38431
|
config
|
|
37214
38432
|
});
|
|
37215
38433
|
res.json(result);
|
|
37216
|
-
} catch (
|
|
37217
|
-
console.error("[SESSION-FILES] sync-to-sandbox failed",
|
|
38434
|
+
} catch (err4) {
|
|
38435
|
+
console.error("[SESSION-FILES] sync-to-sandbox failed", err4);
|
|
37218
38436
|
res.status(500).json({ detail: "Failed to sync file into sandbox." });
|
|
37219
38437
|
}
|
|
37220
38438
|
}
|
|
@@ -37241,8 +38459,8 @@ ${style.markdown}` : params.prompt;
|
|
|
37241
38459
|
try {
|
|
37242
38460
|
await deleteS3Object(key, config);
|
|
37243
38461
|
res.json({ deleted: true });
|
|
37244
|
-
} catch (
|
|
37245
|
-
console.error("[SESSION-FILES] delete failed",
|
|
38462
|
+
} catch (err4) {
|
|
38463
|
+
console.error("[SESSION-FILES] delete failed", err4);
|
|
37246
38464
|
res.status(500).json({ detail: "Failed to delete session file." });
|
|
37247
38465
|
}
|
|
37248
38466
|
}
|
|
@@ -37283,13 +38501,13 @@ ${style.markdown}` : params.prompt;
|
|
|
37283
38501
|
res.setHeader("Content-Type", "application/pdf");
|
|
37284
38502
|
res.setHeader("Cache-Control", "private, max-age=300");
|
|
37285
38503
|
res.send(pdfBytes);
|
|
37286
|
-
} catch (
|
|
37287
|
-
if (
|
|
37288
|
-
console.error("[SESSION-FILES] preview render failed",
|
|
37289
|
-
res.status(500).json({ detail:
|
|
38504
|
+
} catch (err4) {
|
|
38505
|
+
if (err4 instanceof PreviewRenderError) {
|
|
38506
|
+
console.error("[SESSION-FILES] preview render failed", err4);
|
|
38507
|
+
res.status(500).json({ detail: err4.message });
|
|
37290
38508
|
return;
|
|
37291
38509
|
}
|
|
37292
|
-
console.error("[SESSION-FILES] preview unexpected error",
|
|
38510
|
+
console.error("[SESSION-FILES] preview unexpected error", err4);
|
|
37293
38511
|
res.status(500).json({ detail: "Failed to render preview." });
|
|
37294
38512
|
}
|
|
37295
38513
|
}
|
|
@@ -37394,8 +38612,8 @@ ${style.markdown}` : params.prompt;
|
|
|
37394
38612
|
`attachment; filename="${filename}"`
|
|
37395
38613
|
);
|
|
37396
38614
|
res.send(buffer);
|
|
37397
|
-
} catch (
|
|
37398
|
-
console.error("[GDPR] Failed to build data export",
|
|
38615
|
+
} catch (err4) {
|
|
38616
|
+
console.error("[GDPR] Failed to build data export", err4);
|
|
37399
38617
|
res.status(500).json({ detail: "Failed to build data export." });
|
|
37400
38618
|
}
|
|
37401
38619
|
});
|
|
@@ -37416,8 +38634,8 @@ ${style.markdown}` : params.prompt;
|
|
|
37416
38634
|
await trx("rbac").where({ user_id: targetUser.id }).delete();
|
|
37417
38635
|
await trx("users").where({ id: targetUser.id }).delete();
|
|
37418
38636
|
});
|
|
37419
|
-
} catch (
|
|
37420
|
-
console.error("[GDPR] Failed to delete user",
|
|
38637
|
+
} catch (err4) {
|
|
38638
|
+
console.error("[GDPR] Failed to delete user", err4);
|
|
37421
38639
|
res.status(500).json({ detail: "Failed to delete user." });
|
|
37422
38640
|
return;
|
|
37423
38641
|
}
|
|
@@ -37425,8 +38643,8 @@ ${style.markdown}` : params.prompt;
|
|
|
37425
38643
|
const prefix = `user_${targetUser.id}/`;
|
|
37426
38644
|
const files = await listS3ObjectsByPrefix(prefix, config);
|
|
37427
38645
|
await Promise.all(files.map((f) => deleteS3Object(f.key, config)));
|
|
37428
|
-
} catch (
|
|
37429
|
-
console.error("[GDPR] DB delete succeeded but S3 cleanup failed",
|
|
38646
|
+
} catch (err4) {
|
|
38647
|
+
console.error("[GDPR] DB delete succeeded but S3 cleanup failed", err4);
|
|
37430
38648
|
}
|
|
37431
38649
|
res.status(204).send();
|
|
37432
38650
|
});
|
|
@@ -37720,9 +38938,9 @@ ${style.markdown}` : params.prompt;
|
|
|
37720
38938
|
if (!agentModel) return "";
|
|
37721
38939
|
return "";
|
|
37722
38940
|
};
|
|
37723
|
-
const
|
|
38941
|
+
const UUID_RE3 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
37724
38942
|
const getGuestAgentById = async (id) => {
|
|
37725
|
-
if (!
|
|
38943
|
+
if (!UUID_RE3.test(id)) return void 0;
|
|
37726
38944
|
const { db: db2 } = await postgresClient();
|
|
37727
38945
|
return db2.from("agents").where({ id, guest_access: true, active: true }).first();
|
|
37728
38946
|
};
|
|
@@ -37866,7 +39084,7 @@ function buildUnifiedDiff(fromLines, toLines, fromLabel, toLabel) {
|
|
|
37866
39084
|
// src/mcp/index.ts
|
|
37867
39085
|
init_cjs_shims();
|
|
37868
39086
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
37869
|
-
var
|
|
39087
|
+
var import_node_crypto21 = require("crypto");
|
|
37870
39088
|
var import_streamableHttp = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
37871
39089
|
var import_types13 = require("@modelcontextprotocol/sdk/types.js");
|
|
37872
39090
|
init_sanitize_tool_name();
|
|
@@ -37967,7 +39185,7 @@ var ExuluMCP = class {
|
|
|
37967
39185
|
throw new Error("Tool not found in converted tools array.");
|
|
37968
39186
|
}
|
|
37969
39187
|
const iterator = await convertedTool.execute(inputs, {
|
|
37970
|
-
toolCallId: tool4.id + "_" + (0,
|
|
39188
|
+
toolCallId: tool4.id + "_" + (0, import_node_crypto21.randomUUID)(),
|
|
37971
39189
|
messages: []
|
|
37972
39190
|
});
|
|
37973
39191
|
let result;
|
|
@@ -38157,7 +39375,7 @@ var ExuluMCP = class {
|
|
|
38157
39375
|
transport = this.transports[sessionId];
|
|
38158
39376
|
} else if (!sessionId && (0, import_types13.isInitializeRequest)(req.body)) {
|
|
38159
39377
|
transport = new import_streamableHttp.StreamableHTTPServerTransport({
|
|
38160
|
-
sessionIdGenerator: () => (0,
|
|
39378
|
+
sessionIdGenerator: () => (0, import_node_crypto21.randomUUID)(),
|
|
38161
39379
|
onsessioninitialized: (sessionId2) => {
|
|
38162
39380
|
this.transports[sessionId2] = transport;
|
|
38163
39381
|
}
|
|
@@ -38763,7 +39981,7 @@ var import_zod31 = __toESM(require("zod"), 1);
|
|
|
38763
39981
|
init_tool();
|
|
38764
39982
|
init_check_record_access();
|
|
38765
39983
|
init_client();
|
|
38766
|
-
var
|
|
39984
|
+
var import_node_crypto22 = require("crypto");
|
|
38767
39985
|
var AnswerOptionSchema = import_zod31.default.object({
|
|
38768
39986
|
id: import_zod31.default.string().describe("Unique identifier for the answer option"),
|
|
38769
39987
|
text: import_zod31.default.string().describe("The text of the answer option")
|
|
@@ -38817,15 +40035,15 @@ var QuestionAskTool = new ExuluTool({
|
|
|
38817
40035
|
throw new Error("You don't have access to this session " + session.id + ".");
|
|
38818
40036
|
}
|
|
38819
40037
|
const answerOptionsWithIds = answerOptions.map((text) => ({
|
|
38820
|
-
id: (0,
|
|
40038
|
+
id: (0, import_node_crypto22.randomUUID)(),
|
|
38821
40039
|
text
|
|
38822
40040
|
}));
|
|
38823
40041
|
answerOptionsWithIds.push({
|
|
38824
|
-
id: (0,
|
|
40042
|
+
id: (0, import_node_crypto22.randomUUID)(),
|
|
38825
40043
|
text: "None of the above..."
|
|
38826
40044
|
});
|
|
38827
40045
|
const newQuestion = {
|
|
38828
|
-
id: (0,
|
|
40046
|
+
id: (0, import_node_crypto22.randomUUID)(),
|
|
38829
40047
|
question,
|
|
38830
40048
|
answerOptions: answerOptionsWithIds,
|
|
38831
40049
|
status: "pending"
|
|
@@ -39186,8 +40404,8 @@ var tick = async () => {
|
|
|
39186
40404
|
if (stopped) return;
|
|
39187
40405
|
try {
|
|
39188
40406
|
await transcriptionService.pollOnce(MAX_PER_TICK);
|
|
39189
|
-
} catch (
|
|
39190
|
-
console.error(`[EXULU-TRANSCRIPTION] polling tick failed: ${
|
|
40407
|
+
} catch (err4) {
|
|
40408
|
+
console.error(`[EXULU-TRANSCRIPTION] polling tick failed: ${err4.message}`);
|
|
39191
40409
|
} finally {
|
|
39192
40410
|
if (!stopped) {
|
|
39193
40411
|
timer = setTimeout(tick, POLL_INTERVAL_MS);
|
|
@@ -39221,9 +40439,9 @@ var tick2 = async () => {
|
|
|
39221
40439
|
if (acted > 0) {
|
|
39222
40440
|
console.log(`[EXULU-RECALL] reconcile tick recovered ${acted} job(s)`);
|
|
39223
40441
|
}
|
|
39224
|
-
} catch (
|
|
40442
|
+
} catch (err4) {
|
|
39225
40443
|
console.error(
|
|
39226
|
-
`[EXULU-RECALL] reconcile tick failed: ${
|
|
40444
|
+
`[EXULU-RECALL] reconcile tick failed: ${err4.message}`
|
|
39227
40445
|
);
|
|
39228
40446
|
} finally {
|
|
39229
40447
|
if (!stopped2) {
|
|
@@ -39423,6 +40641,7 @@ var ExuluApp = class {
|
|
|
39423
40641
|
5,
|
|
39424
40642
|
300
|
|
39425
40643
|
);
|
|
40644
|
+
registerImportQueue();
|
|
39426
40645
|
if (queues2?.length) {
|
|
39427
40646
|
for (const queue of queues2) {
|
|
39428
40647
|
queueSet.add(await queue);
|
|
@@ -39471,10 +40690,10 @@ var ExuluApp = class {
|
|
|
39471
40690
|
setLiteLLMPackageRoot(packageRoot);
|
|
39472
40691
|
try {
|
|
39473
40692
|
await startLiteLLMSupervisor();
|
|
39474
|
-
} catch (
|
|
40693
|
+
} catch (err4) {
|
|
39475
40694
|
console.error(
|
|
39476
40695
|
"[EXULU] LiteLLM supervisor failed to start:",
|
|
39477
|
-
|
|
40696
|
+
err4.message
|
|
39478
40697
|
);
|
|
39479
40698
|
}
|
|
39480
40699
|
}
|
|
@@ -39485,9 +40704,9 @@ var ExuluApp = class {
|
|
|
39485
40704
|
console.log(
|
|
39486
40705
|
`[EXULU] Transcription: enabled (server=${process.env.TRANSCRIPTION_SERVER}, device=${health.device}, GPU=${health.gpu.available ? "enabled" : "disabled"}, diarization=${health.diarization ? "enabled" : "disabled"})`
|
|
39487
40706
|
);
|
|
39488
|
-
} catch (
|
|
40707
|
+
} catch (err4) {
|
|
39489
40708
|
console.warn(
|
|
39490
|
-
`[EXULU] TRANSCRIPTION_SERVER set but not reachable yet: ${
|
|
40709
|
+
`[EXULU] TRANSCRIPTION_SERVER set but not reachable yet: ${err4.message}. Polling loop is running; jobs will reconcile once the server is up.`
|
|
39491
40710
|
);
|
|
39492
40711
|
}
|
|
39493
40712
|
} else {
|
|
@@ -40585,6 +41804,7 @@ var {
|
|
|
40585
41804
|
jobResultsSchema: jobResultsSchema3,
|
|
40586
41805
|
promptLibrarySchema: promptLibrarySchema3,
|
|
40587
41806
|
contextPresetsSchema: contextPresetsSchema3,
|
|
41807
|
+
contextFoldersSchema: contextFoldersSchema3,
|
|
40588
41808
|
contextProjectionsSchema: contextProjectionsSchema2,
|
|
40589
41809
|
contextMapTopicsSchema: contextMapTopicsSchema2,
|
|
40590
41810
|
entityTypeSettingsSchema: entityTypeSettingsSchema3,
|
|
@@ -40648,6 +41868,7 @@ var up = async function(knex) {
|
|
|
40648
41868
|
jobResultsSchema3(),
|
|
40649
41869
|
promptLibrarySchema3(),
|
|
40650
41870
|
contextPresetsSchema3(),
|
|
41871
|
+
contextFoldersSchema3(),
|
|
40651
41872
|
contextProjectionsSchema2(),
|
|
40652
41873
|
contextMapTopicsSchema2(),
|
|
40653
41874
|
entityTypeSettingsSchema3(),
|
|
@@ -41054,12 +42275,12 @@ var initLiteLLMDatabase = async (packageRoot) => {
|
|
|
41054
42275
|
await probe.connect();
|
|
41055
42276
|
await probe.end();
|
|
41056
42277
|
return true;
|
|
41057
|
-
} catch (
|
|
41058
|
-
const code =
|
|
42278
|
+
} catch (err4) {
|
|
42279
|
+
const code = err4?.code;
|
|
41059
42280
|
if (code !== "3D000") {
|
|
41060
42281
|
warn2([
|
|
41061
42282
|
`Could not connect to LiteLLM's target database:`,
|
|
41062
|
-
` ${
|
|
42283
|
+
` ${err4 instanceof Error ? err4.message : String(err4)}`,
|
|
41063
42284
|
``,
|
|
41064
42285
|
`Skipping LiteLLM database setup. LiteLLM features that depend on`,
|
|
41065
42286
|
`the database will fail at runtime until this is resolved.`
|
|
@@ -41123,11 +42344,11 @@ var initLiteLLMDatabase = async (packageRoot) => {
|
|
|
41123
42344
|
ORDER BY table_name;`
|
|
41124
42345
|
);
|
|
41125
42346
|
foreignTables = res.rows.map((r) => r.table_name);
|
|
41126
|
-
} catch (
|
|
42347
|
+
} catch (err4) {
|
|
41127
42348
|
warn2([
|
|
41128
42349
|
`Could not query LiteLLM's target database to verify it is safe`,
|
|
41129
42350
|
`to push into:`,
|
|
41130
|
-
` ${
|
|
42351
|
+
` ${err4 instanceof Error ? err4.message : String(err4)}`,
|
|
41131
42352
|
``,
|
|
41132
42353
|
`Skipping LiteLLM database setup. LiteLLM features that depend on the`,
|
|
41133
42354
|
`database will fail at runtime until this is resolved.`
|
|
@@ -41941,10 +43162,10 @@ async function resolveOcr(input) {
|
|
|
41941
43162
|
}
|
|
41942
43163
|
try {
|
|
41943
43164
|
await waitForLiteLLMReady();
|
|
41944
|
-
} catch (
|
|
43165
|
+
} catch (err4) {
|
|
41945
43166
|
throw new ResolveOcrError(
|
|
41946
43167
|
"LITELLM_NOT_READY",
|
|
41947
|
-
`LiteLLM is not ready: ${
|
|
43168
|
+
`LiteLLM is not ready: ${err4.message}`
|
|
41948
43169
|
);
|
|
41949
43170
|
}
|
|
41950
43171
|
const { baseUrl, authHeaders } = resolveLiteLLMTarget();
|
|
@@ -42462,9 +43683,9 @@ async function processPdf(buffer, paths, config, verbose = false) {
|
|
|
42462
43683
|
let pdfChunks;
|
|
42463
43684
|
try {
|
|
42464
43685
|
pdfChunks = JSON.parse(splitResult.stdout);
|
|
42465
|
-
} catch (
|
|
43686
|
+
} catch (err4) {
|
|
42466
43687
|
throw new Error(
|
|
42467
|
-
`[EXULU] split_pdf.py returned invalid JSON on stdout: ${
|
|
43688
|
+
`[EXULU] split_pdf.py returned invalid JSON on stdout: ${err4.message}
|
|
42468
43689
|
stdout: ${splitResult.stdout.slice(0, 500)}
|
|
42469
43690
|
stderr: ${splitResult.stderr.slice(-1e3)}`
|
|
42470
43691
|
);
|