@exulu/backend 5.24.0 → 5.25.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/index.cjs CHANGED
@@ -27922,6 +27922,49 @@ var markSessionSeenForViewer = async ({
27922
27922
  // src/graphql/mutations/index.ts
27923
27923
  init_skill_access();
27924
27924
  init_write_grant();
27925
+
27926
+ // src/graphql/utilities/user-self-service.ts
27927
+ init_cjs_shims();
27928
+ var USER_SELF_SERVICE_FIELDS = [
27929
+ "favourite_agents",
27930
+ "favourite_projects",
27931
+ "favourite_contexts",
27932
+ "favourite_items",
27933
+ "favourite_artifacts",
27934
+ "recently_viewed_items",
27935
+ "personal_system_prompt"
27936
+ ];
27937
+ var sameId = (a, b) => a !== void 0 && a !== null && b !== void 0 && b !== null && String(a) === String(b);
27938
+ var pinsOwnId = (where, userId) => {
27939
+ const filters = Array.isArray(where) ? where : [where];
27940
+ if (filters.length !== 1) return false;
27941
+ const filter = filters[0];
27942
+ if (!filter || typeof filter !== "object") return false;
27943
+ const columns = Object.keys(filter);
27944
+ if (columns.length !== 1 || columns[0] !== "id") return false;
27945
+ const operators = filter.id;
27946
+ if (!operators || typeof operators !== "object") return false;
27947
+ const names = Object.keys(operators);
27948
+ if (names.length !== 1 || names[0] !== "eq") return false;
27949
+ return sameId(operators.eq, userId);
27950
+ };
27951
+ var isOwnUserSelfServiceWrite = ({
27952
+ tableNamePlural,
27953
+ user,
27954
+ rowId,
27955
+ inputKeys,
27956
+ where
27957
+ }) => {
27958
+ if (tableNamePlural !== "users") return false;
27959
+ if (!user || user.type === "api" || user.via_companion === true) return false;
27960
+ if (!sameId(rowId, user.id)) return false;
27961
+ if (where !== void 0 && !pinsOwnId(where, user.id)) return false;
27962
+ if (!Array.isArray(inputKeys) || inputKeys.length === 0) return false;
27963
+ const allowed = USER_SELF_SERVICE_FIELDS;
27964
+ return inputKeys.every((key) => allowed.includes(key));
27965
+ };
27966
+
27967
+ // src/graphql/mutations/index.ts
27925
27968
  var VALID_RIGHTS_MODES3 = ["private", "users", "roles", "teams", "public"];
27926
27969
  var postprocessDeletion = async ({
27927
27970
  table,
@@ -28104,7 +28147,7 @@ var buildTranscriptsSettingsInfo = async () => {
28104
28147
  function createMutations(table, contexts, tools, config) {
28105
28148
  const tableNamePlural = table.name.plural.toLowerCase();
28106
28149
  const tableNameSingular = table.name.singular.toLowerCase();
28107
- const validateWriteAccess = async (id, context) => {
28150
+ const validateWriteAccess = async (id, context, selfService) => {
28108
28151
  try {
28109
28152
  const { db: db2, user } = context;
28110
28153
  if (user.via_companion === true) {
@@ -28116,7 +28159,13 @@ function createMutations(table, contexts, tools, config) {
28116
28159
  if (user.super_admin === true) {
28117
28160
  return true;
28118
28161
  }
28119
- if (!user.super_admin && (table.name.plural === "agents" || table.name.plural === "workflow_templates" || table.name.plural === "variables" || table.name.plural === "users" || table.name.plural === "test_cases" || table.name.plural === "eval_sets" || table.name.plural === "eval_runs") && (!user.role || !(table.name.plural === "agents" && user.role.agents === "write") && !(table.name.plural === "workflow_templates" && user.role.workflows === "write") && !(table.name.plural === "variables" && user.role.variables === "write") && !(table.name.plural === "users" && user.role.users === "write") && !((table.name.plural === "test_cases" || table.name.plural === "eval_sets" || table.name.plural === "eval_runs") && user.role.evals === "write"))) {
28162
+ const ownSelfServiceWrite = !!selfService && isOwnUserSelfServiceWrite({
28163
+ tableNamePlural: table.name.plural,
28164
+ user,
28165
+ rowId: id,
28166
+ ...selfService
28167
+ });
28168
+ if (!user.super_admin && !ownSelfServiceWrite && (table.name.plural === "agents" || table.name.plural === "workflow_templates" || table.name.plural === "variables" || table.name.plural === "users" || table.name.plural === "test_cases" || table.name.plural === "eval_sets" || table.name.plural === "eval_runs") && (!user.role || !(table.name.plural === "agents" && user.role.agents === "write") && !(table.name.plural === "workflow_templates" && user.role.workflows === "write") && !(table.name.plural === "variables" && user.role.variables === "write") && !(table.name.plural === "users" && user.role.users === "write") && !((table.name.plural === "test_cases" || table.name.plural === "eval_sets" || table.name.plural === "eval_runs") && user.role.evals === "write"))) {
28120
28169
  console.error(
28121
28170
  "Access control error: no role found for current user or no access to entity type."
28122
28171
  );
@@ -28366,6 +28415,7 @@ function createMutations(table, contexts, tools, config) {
28366
28415
  [`${tableNamePlural}UpdateOne`]: async (_, args, context, info) => {
28367
28416
  const { db: db2, req } = context;
28368
28417
  let { where, input } = args;
28418
+ const inputKeys = Object.keys(input ?? {});
28369
28419
  await validateCreateOrRemoveSuperAdminPermission(tableNamePlural, input, req);
28370
28420
  const rbacData = input.RBAC;
28371
28421
  delete input.RBAC;
@@ -28390,7 +28440,7 @@ function createMutations(table, contexts, tools, config) {
28390
28440
  if (!item) {
28391
28441
  throw new Error("Record not found");
28392
28442
  }
28393
- await validateWriteAccess(item.id, context);
28443
+ await validateWriteAccess(item.id, context, { inputKeys, where: where ?? null });
28394
28444
  if (table.type === "items") {
28395
28445
  await assertItemFileKeysReadable({
28396
28446
  input,
@@ -28472,7 +28522,7 @@ function createMutations(table, contexts, tools, config) {
28472
28522
  throw new Error("Embedding generation cannot be requested through the companion server.");
28473
28523
  }
28474
28524
  await validateCreateOrRemoveSuperAdminPermission(tableNamePlural, input, req);
28475
- await validateWriteAccess(id, context);
28525
+ await validateWriteAccess(id, context, { inputKeys: Object.keys(input ?? {}) });
28476
28526
  if (table.type === "items") {
28477
28527
  await assertItemFileKeysReadable({
28478
28528
  input,
@@ -34691,6 +34741,20 @@ var mapRoutineRunRow = (row, routineById) => {
34691
34741
  };
34692
34742
  };
34693
34743
 
34744
+ // src/exulu/routines/run-for-session.ts
34745
+ init_cjs_shims();
34746
+ async function routineRunForSession(db2, sessionId, routineById) {
34747
+ const readableIds = [...routineById.keys()];
34748
+ if (!sessionId || readableIds.length === 0) return null;
34749
+ const row = await db2("job_results").where({ session: sessionId, type: "workflow" }).whereIn("workflow", readableIds).orderBy("createdAt", "desc").first();
34750
+ if (!row) return null;
34751
+ const routine = await loadRoutineWorkStatusConfig(db2, row.workflow);
34752
+ return {
34753
+ run: mapRoutineRunRow(row, routineById),
34754
+ work_statuses: routine?.config ?? { statuses: [], default: null }
34755
+ };
34756
+ }
34757
+
34694
34758
  // src/graphql/schemas/index.ts
34695
34759
  init_schemas();
34696
34760
  init_entitlements();
@@ -38393,6 +38457,7 @@ type PageInfo {
38393
38457
  typeDefs += `
38394
38458
  routineRuns(page: Int, limit: Int, workflow: ID, states: [String!], triggers: [String!], from: Date, to: Date, search: String, needsAttention: Boolean, workStatuses: [String!], workStatusOpen: Boolean): RoutineRunPage
38395
38459
  routineRunsNeedingAttentionCount: Float!
38460
+ routineRunForSession(session: ID!): RoutineRunForSession
38396
38461
  `;
38397
38462
  typeDefs += `
38398
38463
  queue(queue: QueueEnum!): QueueResult
@@ -38682,6 +38747,11 @@ type RoutineRunPage {
38682
38747
  items: [RoutineRun!]!
38683
38748
  total: Float!
38684
38749
  }
38750
+
38751
+ type RoutineRunForSession {
38752
+ run: RoutineRun!
38753
+ work_statuses: JSON!
38754
+ }
38685
38755
  `;
38686
38756
  modelDefs += `
38687
38757
  type LiteLLMModel {
@@ -39310,6 +39380,10 @@ type EmbeddingModelOption {
39310
39380
  total
39311
39381
  };
39312
39382
  };
39383
+ resolvers2.Query["routineRunForSession"] = async (_, args, context) => {
39384
+ const { db: db2 } = await postgresClient();
39385
+ return routineRunForSession(db2, args.session, await readableRoutines(db2, context.user));
39386
+ };
39313
39387
  resolvers2.Query["routineRunsNeedingAttentionCount"] = async (_, args, context) => {
39314
39388
  const user = context.user;
39315
39389
  const { db: db2 } = await postgresClient();
package/dist/index.js CHANGED
@@ -4246,6 +4246,46 @@ var markSessionSeenForViewer = async ({
4246
4246
  return true;
4247
4247
  };
4248
4248
 
4249
+ // src/graphql/utilities/user-self-service.ts
4250
+ var USER_SELF_SERVICE_FIELDS = [
4251
+ "favourite_agents",
4252
+ "favourite_projects",
4253
+ "favourite_contexts",
4254
+ "favourite_items",
4255
+ "favourite_artifacts",
4256
+ "recently_viewed_items",
4257
+ "personal_system_prompt"
4258
+ ];
4259
+ var sameId = (a, b) => a !== void 0 && a !== null && b !== void 0 && b !== null && String(a) === String(b);
4260
+ var pinsOwnId = (where, userId) => {
4261
+ const filters = Array.isArray(where) ? where : [where];
4262
+ if (filters.length !== 1) return false;
4263
+ const filter = filters[0];
4264
+ if (!filter || typeof filter !== "object") return false;
4265
+ const columns = Object.keys(filter);
4266
+ if (columns.length !== 1 || columns[0] !== "id") return false;
4267
+ const operators = filter.id;
4268
+ if (!operators || typeof operators !== "object") return false;
4269
+ const names = Object.keys(operators);
4270
+ if (names.length !== 1 || names[0] !== "eq") return false;
4271
+ return sameId(operators.eq, userId);
4272
+ };
4273
+ var isOwnUserSelfServiceWrite = ({
4274
+ tableNamePlural,
4275
+ user,
4276
+ rowId,
4277
+ inputKeys,
4278
+ where
4279
+ }) => {
4280
+ if (tableNamePlural !== "users") return false;
4281
+ if (!user || user.type === "api" || user.via_companion === true) return false;
4282
+ if (!sameId(rowId, user.id)) return false;
4283
+ if (where !== void 0 && !pinsOwnId(where, user.id)) return false;
4284
+ if (!Array.isArray(inputKeys) || inputKeys.length === 0) return false;
4285
+ const allowed = USER_SELF_SERVICE_FIELDS;
4286
+ return inputKeys.every((key) => allowed.includes(key));
4287
+ };
4288
+
4249
4289
  // src/graphql/mutations/index.ts
4250
4290
  var VALID_RIGHTS_MODES3 = ["private", "users", "roles", "teams", "public"];
4251
4291
  var postprocessDeletion = async ({
@@ -4429,7 +4469,7 @@ var buildTranscriptsSettingsInfo = async () => {
4429
4469
  function createMutations(table, contexts, tools, config) {
4430
4470
  const tableNamePlural = table.name.plural.toLowerCase();
4431
4471
  const tableNameSingular = table.name.singular.toLowerCase();
4432
- const validateWriteAccess = async (id, context) => {
4472
+ const validateWriteAccess = async (id, context, selfService) => {
4433
4473
  try {
4434
4474
  const { db, user } = context;
4435
4475
  if (user.via_companion === true) {
@@ -4441,7 +4481,13 @@ function createMutations(table, contexts, tools, config) {
4441
4481
  if (user.super_admin === true) {
4442
4482
  return true;
4443
4483
  }
4444
- if (!user.super_admin && (table.name.plural === "agents" || table.name.plural === "workflow_templates" || table.name.plural === "variables" || table.name.plural === "users" || table.name.plural === "test_cases" || table.name.plural === "eval_sets" || table.name.plural === "eval_runs") && (!user.role || !(table.name.plural === "agents" && user.role.agents === "write") && !(table.name.plural === "workflow_templates" && user.role.workflows === "write") && !(table.name.plural === "variables" && user.role.variables === "write") && !(table.name.plural === "users" && user.role.users === "write") && !((table.name.plural === "test_cases" || table.name.plural === "eval_sets" || table.name.plural === "eval_runs") && user.role.evals === "write"))) {
4484
+ const ownSelfServiceWrite = !!selfService && isOwnUserSelfServiceWrite({
4485
+ tableNamePlural: table.name.plural,
4486
+ user,
4487
+ rowId: id,
4488
+ ...selfService
4489
+ });
4490
+ if (!user.super_admin && !ownSelfServiceWrite && (table.name.plural === "agents" || table.name.plural === "workflow_templates" || table.name.plural === "variables" || table.name.plural === "users" || table.name.plural === "test_cases" || table.name.plural === "eval_sets" || table.name.plural === "eval_runs") && (!user.role || !(table.name.plural === "agents" && user.role.agents === "write") && !(table.name.plural === "workflow_templates" && user.role.workflows === "write") && !(table.name.plural === "variables" && user.role.variables === "write") && !(table.name.plural === "users" && user.role.users === "write") && !((table.name.plural === "test_cases" || table.name.plural === "eval_sets" || table.name.plural === "eval_runs") && user.role.evals === "write"))) {
4445
4491
  console.error(
4446
4492
  "Access control error: no role found for current user or no access to entity type."
4447
4493
  );
@@ -4691,6 +4737,7 @@ function createMutations(table, contexts, tools, config) {
4691
4737
  [`${tableNamePlural}UpdateOne`]: async (_, args, context, info) => {
4692
4738
  const { db, req } = context;
4693
4739
  let { where, input } = args;
4740
+ const inputKeys = Object.keys(input ?? {});
4694
4741
  await validateCreateOrRemoveSuperAdminPermission(tableNamePlural, input, req);
4695
4742
  const rbacData = input.RBAC;
4696
4743
  delete input.RBAC;
@@ -4715,7 +4762,7 @@ function createMutations(table, contexts, tools, config) {
4715
4762
  if (!item) {
4716
4763
  throw new Error("Record not found");
4717
4764
  }
4718
- await validateWriteAccess(item.id, context);
4765
+ await validateWriteAccess(item.id, context, { inputKeys, where: where ?? null });
4719
4766
  if (table.type === "items") {
4720
4767
  await assertItemFileKeysReadable({
4721
4768
  input,
@@ -4797,7 +4844,7 @@ function createMutations(table, contexts, tools, config) {
4797
4844
  throw new Error("Embedding generation cannot be requested through the companion server.");
4798
4845
  }
4799
4846
  await validateCreateOrRemoveSuperAdminPermission(tableNamePlural, input, req);
4800
- await validateWriteAccess(id, context);
4847
+ await validateWriteAccess(id, context, { inputKeys: Object.keys(input ?? {}) });
4801
4848
  if (table.type === "items") {
4802
4849
  await assertItemFileKeysReadable({
4803
4850
  input,
@@ -10852,6 +10899,19 @@ var mapRoutineRunRow = (row, routineById) => {
10852
10899
  };
10853
10900
  };
10854
10901
 
10902
+ // src/exulu/routines/run-for-session.ts
10903
+ async function routineRunForSession(db, sessionId, routineById) {
10904
+ const readableIds = [...routineById.keys()];
10905
+ if (!sessionId || readableIds.length === 0) return null;
10906
+ const row = await db("job_results").where({ session: sessionId, type: "workflow" }).whereIn("workflow", readableIds).orderBy("createdAt", "desc").first();
10907
+ if (!row) return null;
10908
+ const routine = await loadRoutineWorkStatusConfig(db, row.workflow);
10909
+ return {
10910
+ run: mapRoutineRunRow(row, routineById),
10911
+ work_statuses: routine?.config ?? { statuses: [], default: null }
10912
+ };
10913
+ }
10914
+
10855
10915
  // src/graphql/schemas/index.ts
10856
10916
  import "fs";
10857
10917
 
@@ -14471,6 +14531,7 @@ type PageInfo {
14471
14531
  typeDefs += `
14472
14532
  routineRuns(page: Int, limit: Int, workflow: ID, states: [String!], triggers: [String!], from: Date, to: Date, search: String, needsAttention: Boolean, workStatuses: [String!], workStatusOpen: Boolean): RoutineRunPage
14473
14533
  routineRunsNeedingAttentionCount: Float!
14534
+ routineRunForSession(session: ID!): RoutineRunForSession
14474
14535
  `;
14475
14536
  typeDefs += `
14476
14537
  queue(queue: QueueEnum!): QueueResult
@@ -14760,6 +14821,11 @@ type RoutineRunPage {
14760
14821
  items: [RoutineRun!]!
14761
14822
  total: Float!
14762
14823
  }
14824
+
14825
+ type RoutineRunForSession {
14826
+ run: RoutineRun!
14827
+ work_statuses: JSON!
14828
+ }
14763
14829
  `;
14764
14830
  modelDefs += `
14765
14831
  type LiteLLMModel {
@@ -15388,6 +15454,10 @@ type EmbeddingModelOption {
15388
15454
  total
15389
15455
  };
15390
15456
  };
15457
+ resolvers.Query["routineRunForSession"] = async (_, args, context) => {
15458
+ const { db } = await postgresClient();
15459
+ return routineRunForSession(db, args.session, await readableRoutines(db, context.user));
15460
+ };
15391
15461
  resolvers.Query["routineRunsNeedingAttentionCount"] = async (_, args, context) => {
15392
15462
  const user = context.user;
15393
15463
  const { db } = await postgresClient();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@exulu/backend",
3
3
  "author": "Qventu B.V.",
4
- "version": "5.24.0",
4
+ "version": "5.25.0",
5
5
  "main": "./dist/index.js",
6
6
  "private": false,
7
7
  "publishConfig": {