@exulu/backend 5.5.1 → 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 +1765 -550
- package/dist/index.js +1468 -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 +173 -2
- package/package.json +1 -1
|
@@ -1723,7 +1723,7 @@ var ExuluTool = class _ExuluTool {
|
|
|
1723
1723
|
if (!agent) {
|
|
1724
1724
|
throw new Error("Agent not found.");
|
|
1725
1725
|
}
|
|
1726
|
-
const { convertExuluToolsToAiSdkTools: convertExuluToolsToAiSdkTools2 } = await import("./convert-exulu-tools-to-ai-sdk-tools-
|
|
1726
|
+
const { convertExuluToolsToAiSdkTools: convertExuluToolsToAiSdkTools2 } = await import("./convert-exulu-tools-to-ai-sdk-tools-7TYZVHEQ.js");
|
|
1727
1727
|
const tools = await convertExuluToolsToAiSdkTools2(
|
|
1728
1728
|
[this],
|
|
1729
1729
|
[],
|
|
@@ -5104,6 +5104,19 @@ var getS3ObjectContent = async (key, config) => {
|
|
|
5104
5104
|
}
|
|
5105
5105
|
return response.Body.transformToString("utf-8");
|
|
5106
5106
|
};
|
|
5107
|
+
var getS3ObjectStream = async (key, config) => {
|
|
5108
|
+
if (!config.fileUploads) {
|
|
5109
|
+
throw new Error("File uploads are not configured");
|
|
5110
|
+
}
|
|
5111
|
+
const client = getS3Client(config);
|
|
5112
|
+
const bucket = config.fileUploads.s3Bucket;
|
|
5113
|
+
const command = new GetObjectCommand({ Bucket: bucket, Key: key });
|
|
5114
|
+
const response = await client.send(command);
|
|
5115
|
+
if (!response.Body) {
|
|
5116
|
+
throw new Error(`Empty body for S3 key: ${key}`);
|
|
5117
|
+
}
|
|
5118
|
+
return response.Body;
|
|
5119
|
+
};
|
|
5107
5120
|
var getS3ObjectEtag = async (key, config) => {
|
|
5108
5121
|
if (!config.fileUploads) {
|
|
5109
5122
|
throw new Error("File uploads are not configured");
|
|
@@ -8723,6 +8736,7 @@ var TERMINAL_JOB_STATES = ["completed", "failed", "filtered", "cancelled"];
|
|
|
8723
8736
|
// ee/queues/prune-job-results.ts
|
|
8724
8737
|
var MAX_TERMINAL = 1e4;
|
|
8725
8738
|
var PRUNE_EVERY = 100;
|
|
8739
|
+
var MAX_IMPORT_PER_CONTEXT = 200;
|
|
8726
8740
|
var sinceLastPrune = 0;
|
|
8727
8741
|
var pruning = false;
|
|
8728
8742
|
async function maybePruneJobResults(db2) {
|
|
@@ -8731,9 +8745,26 @@ async function maybePruneJobResults(db2) {
|
|
|
8731
8745
|
sinceLastPrune = 0;
|
|
8732
8746
|
pruning = true;
|
|
8733
8747
|
try {
|
|
8734
|
-
|
|
8748
|
+
await pruneGenericJobResults(db2);
|
|
8749
|
+
await pruneImportJobResults(db2);
|
|
8750
|
+
} finally {
|
|
8751
|
+
pruning = false;
|
|
8752
|
+
}
|
|
8753
|
+
}
|
|
8754
|
+
function excludeImportType(builder) {
|
|
8755
|
+
return builder.where(function() {
|
|
8756
|
+
this.whereNot({ type: "import" }).orWhereNull("type");
|
|
8757
|
+
});
|
|
8758
|
+
}
|
|
8759
|
+
async function pruneGenericJobResults(db2) {
|
|
8760
|
+
try {
|
|
8761
|
+
const boundary = await excludeImportType(
|
|
8762
|
+
db2("job_results").whereIn("state", TERMINAL_JOB_STATES)
|
|
8763
|
+
).orderBy("createdAt", "desc").offset(MAX_TERMINAL).limit(1).first();
|
|
8735
8764
|
if (boundary?.createdAt) {
|
|
8736
|
-
const deleted = await
|
|
8765
|
+
const deleted = await excludeImportType(
|
|
8766
|
+
db2("job_results").whereIn("state", TERMINAL_JOB_STATES)
|
|
8767
|
+
).where("createdAt", "<=", boundary.createdAt).del();
|
|
8737
8768
|
if (deleted) {
|
|
8738
8769
|
console.log(
|
|
8739
8770
|
`[EXULU] pruned ${deleted} terminal job_results rows (cap ${MAX_TERMINAL}).`
|
|
@@ -8742,8 +8773,30 @@ async function maybePruneJobResults(db2) {
|
|
|
8742
8773
|
}
|
|
8743
8774
|
} catch (err3) {
|
|
8744
8775
|
console.error("[EXULU] job_results prune failed", err3);
|
|
8745
|
-
}
|
|
8746
|
-
|
|
8776
|
+
}
|
|
8777
|
+
}
|
|
8778
|
+
async function pruneImportJobResults(db2) {
|
|
8779
|
+
if (db2.client?.config?.client !== "pg") return;
|
|
8780
|
+
try {
|
|
8781
|
+
const statePlaceholders = TERMINAL_JOB_STATES.map(() => "?").join(", ");
|
|
8782
|
+
const deleted = await db2("job_results").where({ type: "import" }).whereRaw(
|
|
8783
|
+
`id in (
|
|
8784
|
+
select id from (
|
|
8785
|
+
select id, row_number() over (partition by context order by "createdAt" desc) as rn
|
|
8786
|
+
from job_results
|
|
8787
|
+
where type = 'import' and state in (${statePlaceholders})
|
|
8788
|
+
) ranked
|
|
8789
|
+
where rn > ?
|
|
8790
|
+
)`,
|
|
8791
|
+
[...TERMINAL_JOB_STATES, MAX_IMPORT_PER_CONTEXT]
|
|
8792
|
+
).del();
|
|
8793
|
+
if (deleted) {
|
|
8794
|
+
console.log(
|
|
8795
|
+
`[EXULU] pruned ${deleted} terminal import job_results rows (cap ${MAX_IMPORT_PER_CONTEXT}/context).`
|
|
8796
|
+
);
|
|
8797
|
+
}
|
|
8798
|
+
} catch (err3) {
|
|
8799
|
+
console.error("[EXULU] import job_results prune failed", err3);
|
|
8747
8800
|
}
|
|
8748
8801
|
}
|
|
8749
8802
|
|
|
@@ -11116,6 +11169,58 @@ var contextPresetsSchema = {
|
|
|
11116
11169
|
}
|
|
11117
11170
|
]
|
|
11118
11171
|
};
|
|
11172
|
+
var contextFoldersSchema = {
|
|
11173
|
+
type: "context_folders",
|
|
11174
|
+
name: {
|
|
11175
|
+
plural: "context_folders",
|
|
11176
|
+
singular: "context_folder"
|
|
11177
|
+
},
|
|
11178
|
+
RBAC: false,
|
|
11179
|
+
apiWrites: "super_admin",
|
|
11180
|
+
fields: [
|
|
11181
|
+
{
|
|
11182
|
+
// `index: true` is advisory here, not a DB index: init-exulu-db.ts's
|
|
11183
|
+
// mapType call for core tables only forwards `unique`, never `index`,
|
|
11184
|
+
// to knex. Kept on the field because it documents intent (and other,
|
|
11185
|
+
// non-core-table callers of mapType do read it) and the schema test
|
|
11186
|
+
// asserts it, but creating this table does not add a Postgres index.
|
|
11187
|
+
name: "name",
|
|
11188
|
+
type: "text",
|
|
11189
|
+
required: true,
|
|
11190
|
+
index: true
|
|
11191
|
+
},
|
|
11192
|
+
{
|
|
11193
|
+
name: "description",
|
|
11194
|
+
type: "text"
|
|
11195
|
+
},
|
|
11196
|
+
{
|
|
11197
|
+
name: "icon",
|
|
11198
|
+
type: "text"
|
|
11199
|
+
},
|
|
11200
|
+
{
|
|
11201
|
+
// `default: 0` is advisory here, not a DB default: map-types.ts's
|
|
11202
|
+
// json/number branches only call `.defaultTo(defaultValue)` when
|
|
11203
|
+
// defaultValue is truthy, and 0 is falsy, so no column default is ever
|
|
11204
|
+
// emitted for this field. New rows rely on the GraphQL input/resolver
|
|
11205
|
+
// defaulting sort_order, not a Postgres-level default.
|
|
11206
|
+
name: "sort_order",
|
|
11207
|
+
type: "number",
|
|
11208
|
+
default: 0
|
|
11209
|
+
},
|
|
11210
|
+
{
|
|
11211
|
+
// Unlike sort_order's `0`, "[]" is a truthy string, so map-types.ts's
|
|
11212
|
+
// json branch does emit `.defaultTo("[]")`: a CreateOne that omits
|
|
11213
|
+
// context_ids stores an empty array instead of NULL. That matters
|
|
11214
|
+
// because the generated GraphQL output type is JSON! (non-null) —
|
|
11215
|
+
// without this default a bare NULL would break context_foldersPagination
|
|
11216
|
+
// for every reader, not just the row that omitted the field.
|
|
11217
|
+
name: "context_ids",
|
|
11218
|
+
type: "json",
|
|
11219
|
+
required: true,
|
|
11220
|
+
default: "[]"
|
|
11221
|
+
}
|
|
11222
|
+
]
|
|
11223
|
+
};
|
|
11119
11224
|
var addCoreFields = (schema) => {
|
|
11120
11225
|
schema.fields.forEach((field) => {
|
|
11121
11226
|
if (field.type === "file") {
|
|
@@ -11200,6 +11305,7 @@ var coreSchemas = {
|
|
|
11200
11305
|
contextProjectionsSchema: () => addCoreFields(contextProjectionsSchema),
|
|
11201
11306
|
contextMapTopicsSchema: () => addCoreFields(contextMapTopicsSchema),
|
|
11202
11307
|
contextPresetsSchema: () => addCoreFields(contextPresetsSchema),
|
|
11308
|
+
contextFoldersSchema: () => addCoreFields(contextFoldersSchema),
|
|
11203
11309
|
sharedArtifactsSchema: () => addCoreFields(sharedArtifactsSchema),
|
|
11204
11310
|
transcriptionJobsSchema: () => addCoreFields(transcriptionJobsSchema),
|
|
11205
11311
|
imageGenerationsSchema: () => addCoreFields(imageGenerationsSchema),
|
|
@@ -15693,6 +15799,7 @@ export {
|
|
|
15693
15799
|
listS3ObjectsByPrefix,
|
|
15694
15800
|
copyS3Object,
|
|
15695
15801
|
getS3ObjectContent,
|
|
15802
|
+
getS3ObjectStream,
|
|
15696
15803
|
getS3ObjectEtag,
|
|
15697
15804
|
getS3ObjectBytes,
|
|
15698
15805
|
deleteS3Object,
|