openloops 0.3.0 → 0.3.3

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.
@@ -44,7 +44,7 @@ export declare class BaseEntity {
44
44
  setDefaults(): void;
45
45
  setId(id: string | ObjectId): void;
46
46
  setOwner(currentUser?: CurrentUser): void;
47
- setCreatedBy(currentUser?: CurrentUser): void;
47
+ setCreatedBy(currentUser?: CurrentUser, sanitize?: boolean): void;
48
48
  setUpdatedBy(currentUser?: CurrentUser): void;
49
49
  setDeletedBy(currentUser?: CurrentUser): void;
50
50
  setArchivedBy(currentUser?: CurrentUser): void;
@@ -111,11 +111,10 @@ const _BaseEntity = class _BaseEntity {
111
111
  if (!currentUser) return;
112
112
  this.ownerId = _BaseEntity.toObjectId(currentUser.userId);
113
113
  }
114
- setCreatedBy(currentUser) {
115
- if (!currentUser) return;
116
- this.sanitize(currentUser);
114
+ setCreatedBy(currentUser, sanitize = true) {
115
+ if (sanitize) this.sanitize(currentUser);
117
116
  this.createdAt = /* @__PURE__ */ new Date();
118
- this.createdBy = _BaseEntity.toObjectId(currentUser.userId);
117
+ this.createdBy = _BaseEntity.toObjectId(currentUser?.userId);
119
118
  this.setDefaults();
120
119
  }
121
120
  setUpdatedBy(currentUser) {
@@ -83,11 +83,10 @@ const _BaseEntity = class _BaseEntity {
83
83
  if (!currentUser) return;
84
84
  this.ownerId = _BaseEntity.toObjectId(currentUser.userId);
85
85
  }
86
- setCreatedBy(currentUser) {
87
- if (!currentUser) return;
88
- this.sanitize(currentUser);
86
+ setCreatedBy(currentUser, sanitize = true) {
87
+ if (sanitize) this.sanitize(currentUser);
89
88
  this.createdAt = /* @__PURE__ */ new Date();
90
- this.createdBy = _BaseEntity.toObjectId(currentUser.userId);
89
+ this.createdBy = _BaseEntity.toObjectId(currentUser?.userId);
91
90
  this.setDefaults();
92
91
  }
93
92
  setUpdatedBy(currentUser) {
@@ -50,7 +50,7 @@ class AgiLoop extends import_harness.AgentLoop {
50
50
  return "agi";
51
51
  }
52
52
  get version() {
53
- return "1.8.0";
53
+ return "1.8.1";
54
54
  }
55
55
  get author() {
56
56
  return {
@@ -129,7 +129,6 @@ class AgiLoop extends import_harness.AgentLoop {
129
129
  const { rawText, ...callInfo } = result.callInfo;
130
130
  const activity = (0, import_activity.cleanActivity)(result.activity);
131
131
  if (activity) ctx.chat.state?.setCurrentActivity(activity, "model");
132
- else if (ctx.chat.state?.hasModelActivity) ctx.chat.state?.setCurrentActivity("Thinking...");
133
132
  task.addTurn({ ...result, activity }, {
134
133
  author: "reasoning_engine",
135
134
  declaredTools: catalog.tools.map((tool) => tool.name),
@@ -28,7 +28,7 @@ class AgiLoop extends AgentLoop {
28
28
  return "agi";
29
29
  }
30
30
  get version() {
31
- return "1.8.0";
31
+ return "1.8.1";
32
32
  }
33
33
  get author() {
34
34
  return {
@@ -107,7 +107,6 @@ class AgiLoop extends AgentLoop {
107
107
  const { rawText, ...callInfo } = result.callInfo;
108
108
  const activity = cleanActivity(result.activity);
109
109
  if (activity) ctx.chat.state?.setCurrentActivity(activity, "model");
110
- else if (ctx.chat.state?.hasModelActivity) ctx.chat.state?.setCurrentActivity("Thinking...");
111
110
  task.addTurn({ ...result, activity }, {
112
111
  author: "reasoning_engine",
113
112
  declaredTools: catalog.tools.map((tool) => tool.name),
@@ -3,6 +3,7 @@ import { UserRepository } from '../repositories';
3
3
  import { UserProps } from '../entities';
4
4
  export interface Params extends BaseUseCaseParams {
5
5
  payload?: UserProps;
6
+ sanitize?: boolean;
6
7
  }
7
8
  export interface Output extends BaseUseCaseOutput {
8
9
  data: UserProps;
@@ -42,12 +42,12 @@ let CreateUserUseCase = class extends import_base.BaseUseCase {
42
42
  }
43
43
  userRepository;
44
44
  async execute(params) {
45
- const { payload, currentUser } = params;
45
+ const { payload, currentUser, sanitize } = params;
46
46
  if (!payload?.email) throw new Error("[Create User] email param is required");
47
47
  if (!payload?.password) throw new Error("[Create User] password param is required");
48
48
  const model = payload.preferences ? await (0, import_default_model.readDefaultModel)(payload.preferences) : void 0;
49
49
  const user = await import_entities.User.create({ ...payload, ...payload.preferences ? { preferences: model.preferences } : {} });
50
- user.setCreatedBy(currentUser);
50
+ user.setCreatedBy(currentUser, sanitize);
51
51
  await this.userRepository?.create(user);
52
52
  const { password, ...rest } = user.toJSON();
53
53
  return { data: rest };
@@ -14,12 +14,12 @@ let CreateUserUseCase = class extends BaseUseCase {
14
14
  }
15
15
  userRepository;
16
16
  async execute(params) {
17
- const { payload, currentUser } = params;
17
+ const { payload, currentUser, sanitize } = params;
18
18
  if (!payload?.email) throw new Error("[Create User] email param is required");
19
19
  if (!payload?.password) throw new Error("[Create User] password param is required");
20
20
  const model = payload.preferences ? await readDefaultModel(payload.preferences) : void 0;
21
21
  const user = await User.create({ ...payload, ...payload.preferences ? { preferences: model.preferences } : {} });
22
- user.setCreatedBy(currentUser);
22
+ user.setCreatedBy(currentUser, sanitize);
23
23
  await this.userRepository?.create(user);
24
24
  const { password, ...rest } = user.toJSON();
25
25
  return { data: rest };
package/docs/loops.md CHANGED
@@ -17,7 +17,7 @@ import { AgiLoop } from 'openloops/loops'
17
17
  | `reasoning_engine` | Reads the situation or the results of the last actions, rewrites its working state, decides the next actions, reports the language of the conversation and says in one sentence what is happening until its next answer. |
18
18
  | `action_engine` | Runs the actions the reasoning engine asked for, asks the user for confirmation when needed, delivers the final answer. |
19
19
 
20
- The sentences of both nodes are what [`agent.onActivity`](agent.md#activity-updates) tells, written in the language of the conversation, so a client can show what the agent is doing instead of a generic `Thinking...`. They are optional: when a node leaves it out or writes something unusable (not a text, empty, `running`, `stopped`), the loop shows the generic activity of that moment. The text is cleaned of markup and line breaks and cut at 80 characters, and each one is kept in the turn that produced it (`turns[].activity`) to audit what the user saw.
20
+ The sentences of both nodes are what [`agent.onActivity`](agent.md#activity-updates) tells, written in the language of the conversation, so a client can show what the agent is doing instead of a generic `Thinking...`. They are optional: when a node leaves it out or writes something unusable (not a text, empty, `running`, `stopped`), the loop keeps the last one the model gave, also when the answer of a turn is not valid and the model has to try again, and it shows the generic activity of that moment (`Thinking...`, `Running search...`) only while there is none. The text is cleaned of markup and line breaks and cut at 80 characters, and each one is kept in the turn that produced it (`turns[].activity`) to audit what the user saw.
21
21
 
22
22
  The loop works within a budget per task (20 reasoning turns and 40 tool calls) and stops with an honest answer when the model repeats itself, keeps only reading notes, or runs out of budget. It also rejects final answers that cite identifiers that never appeared in a result or in the user's words.
23
23
 
package/docs/users.md CHANGED
@@ -3,7 +3,7 @@
3
3
  `openloops` includes its own user management, so you don't need to build a parallel system just to have an identity to hand the `Agent`.
4
4
 
5
5
  ```typescript
6
- import { createUser, getUserById, updateUser, deleteUser, ListUsersByProps } from 'openloops/users'
6
+ import { createUser, getUserById, updateUser, deleteUser, ListUsersByProps, UserRole } from 'openloops/users'
7
7
  import { CurrentUser } from 'openloops/base'
8
8
  ```
9
9
 
@@ -28,12 +28,20 @@ const result = await createUser({
28
28
  lastName: 'Barcos',
29
29
  email: 'jose@openloops.xyz',
30
30
  password: 'a-real-password',
31
+ role: UserRole.USER,
31
32
  },
33
+ sanitize: false,
32
34
  })
33
35
  ```
34
36
 
35
37
  `email` and `password` are required. Passwords are hashed before being stored and are never returned.
36
38
 
39
+ ### `sanitize`
40
+
41
+ By default `createUser` removes the fields only admins can set, such as `role`, unless the `currentUser` is an admin. This is what protects you from someone escalating privileges through the payload.
42
+
43
+ If you send `role`, pass `sanitize: false`, otherwise it is discarded. Do it only when your code builds the payload itself, with the fields you choose. Never pass the raw body of a request from an API.
44
+
37
45
  ## Getting a user
38
46
 
39
47
  ```typescript
@@ -1,4 +1,4 @@
1
- import { createUser } from 'openloops/users'
1
+ import { createUser, UserRole } from 'openloops/users'
2
2
  import { Logger } from 'openloops/common'
3
3
 
4
4
  async function createUserExample () {
@@ -9,8 +9,10 @@ async function createUserExample () {
9
9
  firstName: 'Jose',
10
10
  lastName: 'Barcos',
11
11
  email: 'jose@openloops.xyz',
12
- password: 'openloops!'
13
- }
12
+ password: 'openloops!',
13
+ role: UserRole.USER
14
+ },
15
+ sanitize: false
14
16
  })
15
17
 
16
18
  logger.info(result, '[Demo] Created user:')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openloops",
3
- "version": "0.3.0",
3
+ "version": "0.3.3",
4
4
  "description": "Open source harness for AI agents: a TypeScript runtime with persistence, tools, MCP trust, approvals and autonomous jobs, where the loop is pluggable",
5
5
  "author": {
6
6
  "name": "Jose Barcos",