openloops 0.7.2 → 0.7.5

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.
Files changed (101) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/dist/common/base/current-user.js +1 -1
  3. package/dist/common/base/current-user.mjs +1 -1
  4. package/dist/loops/agi/loop.js +1 -1
  5. package/dist/loops/agi/loop.mjs +1 -1
  6. package/dist/services/mcp-servers/admin/use-cases/create-internal-mcp.use-case.d.ts +1 -1
  7. package/dist/services/mcp-servers/admin/use-cases/create-internal-mcp.use-case.js +2 -2
  8. package/dist/services/mcp-servers/admin/use-cases/create-internal-mcp.use-case.mjs +2 -2
  9. package/dist/services/mcp-servers/admin/use-cases/update-internal-mcp.use-case.d.ts +1 -1
  10. package/dist/services/mcp-servers/admin/use-cases/update-internal-mcp.use-case.js +2 -2
  11. package/dist/services/mcp-servers/admin/use-cases/update-internal-mcp.use-case.mjs +2 -2
  12. package/dist/services/mcp-servers/entities/mcpserver.entity.d.ts +1 -3
  13. package/dist/services/mcp-servers/entities/mcpserver.entity.js +3 -8
  14. package/dist/services/mcp-servers/entities/mcpserver.entity.mjs +3 -8
  15. package/dist/services/mcp-servers/internal.d.ts +0 -1
  16. package/dist/services/mcp-servers/internal.js +1 -1
  17. package/dist/services/mcp-servers/internal.mjs +1 -1
  18. package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.js +1 -1
  19. package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.mjs +1 -1
  20. package/dist/services/tasks/entities/agent-action.entity.d.ts +3 -1
  21. package/dist/services/tasks/entities/agent-action.entity.js +8 -3
  22. package/dist/services/tasks/entities/agent-action.entity.mjs +8 -3
  23. package/dist/services/tasks/entities/agent-task.entity.js +1 -1
  24. package/dist/services/tasks/entities/agent-task.entity.mjs +1 -1
  25. package/dist/services/users/repositories/user.repository.js +1 -1
  26. package/dist/services/users/repositories/user.repository.mjs +1 -1
  27. package/dist/tools/core/fetch-url/fetch-url.tool.d.ts +2 -0
  28. package/dist/tools/core/fetch-url/fetch-url.tool.js +184 -0
  29. package/dist/tools/core/fetch-url/fetch-url.tool.mjs +150 -0
  30. package/dist/tools/core/fetch-url/html-to-text.d.ts +1 -0
  31. package/dist/tools/core/fetch-url/html-to-text.js +137 -0
  32. package/dist/tools/core/fetch-url/html-to-text.mjs +113 -0
  33. package/dist/tools/core/fetch-url/index.d.ts +1 -0
  34. package/dist/tools/core/fetch-url/index.js +22 -0
  35. package/dist/tools/core/fetch-url/index.mjs +1 -0
  36. package/dist/tools/core/fetch-url/network-guard.d.ts +1 -0
  37. package/dist/tools/core/fetch-url/network-guard.js +62 -0
  38. package/dist/tools/core/fetch-url/network-guard.mjs +38 -0
  39. package/dist/tools/core/index.d.ts +1 -0
  40. package/dist/tools/core/index.js +2 -0
  41. package/dist/tools/core/index.mjs +1 -0
  42. package/dist/tools/core/web-search/web-search.tool.js +3 -1
  43. package/dist/tools/core/web-search/web-search.tool.mjs +3 -1
  44. package/dist/tools/tool.js +1 -1
  45. package/dist/tools/tool.mjs +1 -1
  46. package/docs/automations.md +1 -0
  47. package/docs/mcp-servers.md +3 -4
  48. package/docs/tools.md +34 -1
  49. package/examples/authentication/login.ts +5 -0
  50. package/examples/automations/create-automation.ts +5 -0
  51. package/examples/automations/create-event-automation.ts +5 -0
  52. package/examples/automations/list-automation-runs.ts +6 -0
  53. package/examples/automations/list-automations.ts +3 -0
  54. package/examples/automations/preview-automation-runs.ts +3 -0
  55. package/examples/automations/receive-automation-event.ts +5 -0
  56. package/examples/automations/revoke-automation-event-token.ts +6 -0
  57. package/examples/automations/run-automation-now.ts +3 -0
  58. package/examples/automations/run-automation-worker.ts +7 -0
  59. package/examples/automations/update-automation.ts +6 -0
  60. package/examples/chats/delete-chat.ts +6 -0
  61. package/examples/chats/get-chat-by-id.ts +6 -0
  62. package/examples/chats/list-autonomous-chats.ts +3 -0
  63. package/examples/chats/list-chats.ts +3 -0
  64. package/examples/guardrails/custom-guard.ts +5 -0
  65. package/examples/loops/custom-loop.ts +8 -0
  66. package/examples/mcps/create-mcp.ts +5 -0
  67. package/examples/mcps/decide-mcp.ts +6 -0
  68. package/examples/mcps/delete-mcp.ts +6 -0
  69. package/examples/mcps/get-mcp-by-id.ts +3 -0
  70. package/examples/mcps/internal-mcp-admin.ts +24 -1
  71. package/examples/mcps/internal-mcp.ts +14 -0
  72. package/examples/mcps/list-all-mcps.ts +3 -0
  73. package/examples/mcps/list-user-mcps.ts +3 -0
  74. package/examples/mcps/update-mcp.ts +5 -0
  75. package/examples/mcps/verify-mcp.ts +3 -0
  76. package/examples/run-agent/interrupt-agent.ts +3 -0
  77. package/examples/run-agent/run-agent-autonomous.ts +3 -0
  78. package/examples/run-agent/run-agent-strict-mode.ts +3 -0
  79. package/examples/run-agent/run-agent-with-confirmation.ts +6 -0
  80. package/examples/run-agent/run-agent-with-fallback-model.ts +3 -0
  81. package/examples/run-agent/run-agent-with-fetch-url.ts +34 -0
  82. package/examples/run-agent/run-agent-with-guards.ts +3 -0
  83. package/examples/run-agent/run-agent-with-hooks.ts +6 -0
  84. package/examples/run-agent/run-agent-with-identity.ts +3 -0
  85. package/examples/run-agent/run-agent-with-model.ts +3 -0
  86. package/examples/run-agent/run-agent-with-slack.ts +3 -0
  87. package/examples/run-agent/run-agent-with-tools.ts +3 -0
  88. package/examples/tools/basic-tool.ts +3 -0
  89. package/examples/tools/destructive-tool.ts +3 -0
  90. package/examples/tools/web-search-tool.ts +3 -0
  91. package/examples/usage/get-chat-usage.ts +3 -0
  92. package/examples/usage/get-message-usage.ts +3 -0
  93. package/examples/usage/get-usage-stats-by-range.ts +3 -0
  94. package/examples/usage/get-usage-stats.ts +3 -0
  95. package/examples/users/create-user.ts +3 -0
  96. package/examples/users/delete-user.ts +6 -0
  97. package/examples/users/get-user-by-id.ts +3 -0
  98. package/examples/users/list-users.ts +3 -0
  99. package/examples/users/set-default-model.ts +6 -0
  100. package/examples/users/update-user.ts +3 -0
  101. package/package.json +1 -1
@@ -2,25 +2,39 @@ import { Logger } from 'openloops/common'
2
2
  import { CurrentUser } from 'openloops/base'
3
3
  import { createInternalMcp, updateInternalMcp, listInternalMcps, deleteInternalMcp } from 'openloops/mcps/admin'
4
4
 
5
+ /**
6
+ * Back office of the internal MCP servers. It needs an admin, anyone else gets 403.
7
+ *
8
+ * These servers are stored in the database, trusted (no manifest review) and loaded by the agent in every run. The users never see them.
9
+ */
5
10
  async function manageInternalMcps () {
6
11
  const logger = new Logger()
7
12
  const admin = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
8
13
 
9
14
  if (!admin) throw new Error('[Demo] admin is not defined')
10
15
 
16
+ /**
17
+ * An MCP with a template. `{{token}}` is replaced in each run with the token of the user, passed in `mcpTokens`, so the server acts on behalf of that user.
18
+ *
19
+ * If a run brings no token for it, the server is unavailable for that run and the agent continues without it. In an automation there is no token of the user, so it is unavailable there too.
20
+ */
11
21
  const crm = await createInternalMcp({
12
22
  payload: {
13
23
  name: 'crm',
14
24
  url: 'https://crm.example.com/mcp',
15
25
  environment: 'production',
16
26
  headers: { Authorization: 'Bearer {{token}}' },
17
- autonomousToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjcm0uZXhhbXBsZS5jb20iLCJzdWIiOiJzdmMtb3Blbmxvb3BzLWNybSIsImF1ZCI6ImNybS1tY3AiLCJzY29wZSI6ImNybTpyZWFkIGNybTp3cml0ZSIsImlhdCI6MTc2MjIxNDQwMCwiZXhwIjoxNzkzNzUwNDAwfQ.YCtd8mv7RZpaZb3Z1aSl25MGP2QRWHc8RtA82MJOH7U',
18
27
  },
19
28
  currentUser: admin,
20
29
  })
21
30
 
22
31
  logger.info(crm, '[Demo] Created internal mcp:')
23
32
 
33
+ /**
34
+ * An MCP with a fixed token. The header has the token written in it, so it is sent as it is in every run, for every user and also in automations.
35
+ *
36
+ * Use it only for a service account that does not depend on the user. The token is stored as written, so do not return it to a client.
37
+ */
24
38
  const catalog = await createInternalMcp({
25
39
  payload: {
26
40
  name: 'catalog',
@@ -31,12 +45,21 @@ async function manageInternalMcps () {
31
45
  currentUser: admin,
32
46
  })
33
47
 
48
+ /**
49
+ * Disables the server without deleting it. A disabled server is not loaded by the agent.
50
+ */
34
51
  await updateInternalMcp({ id: String(catalog._id), payload: { enabled: false }, currentUser: admin })
35
52
 
53
+ /**
54
+ * Lists the internal servers in pages.
55
+ */
36
56
  const page = await listInternalMcps({ options: { page: 1, limit: 10 }, currentUser: admin })
37
57
 
38
58
  logger.info({ names: page.items.map(item => item.name) }, '[Demo] Internal mcps:')
39
59
 
60
+ /**
61
+ * Deletes the server for good.
62
+ */
40
63
  await deleteInternalMcp({ id: String(catalog._id), currentUser: admin })
41
64
  }
42
65
 
@@ -3,6 +3,11 @@ import { Logger } from 'openloops/common'
3
3
  import { CurrentUser } from 'openloops/base'
4
4
  import { AgiLoop } from 'openloops/loops'
5
5
 
6
+ /**
7
+ * Declares internal MCP servers in code. They belong to your solution, not to the user, and they are trusted: no approval, no manifest review, no notice of third party. A destructive tool still asks the user.
8
+ *
9
+ * `mcpTokens` gives the token of the user to the servers that use `{{token}}`, by name. It is never saved.
10
+ */
6
11
  async function runAgentWithInternalMcp (sessionToken: string) {
7
12
  const logger = new Logger()
8
13
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -12,17 +17,26 @@ async function runAgentWithInternalMcp (sessionToken: string) {
12
17
  const agent = new Agent({
13
18
  loop: new AgiLoop(),
14
19
  internalMcps: [
20
+ /**
21
+ * An MCP with a template: it uses the token of the user from `mcpTokens`. In an automation there is no token, so it is unavailable there.
22
+ */
15
23
  {
16
24
  name: 'budget',
17
25
  url: 'https://budget.example.com/mcp',
18
26
  headers: { Authorization: 'Bearer {{token}}' },
19
27
  },
28
+ /**
29
+ * An MCP with a template and a token for automations: in a chat it uses the token of the user. In an autonomous run, such as an automation, that brings no token for it, it uses `autonomousToken`, the token of a service account, and the agent sends the id of the owner in `X-User-Id`. A chat never uses `autonomousToken`.
30
+ */
20
31
  {
21
32
  name: 'crm',
22
33
  url: 'https://crm.example.com/mcp',
23
34
  headers: { Authorization: 'Bearer {{token}}' },
24
35
  autonomousToken: process.env.CRM_SERVICE_TOKEN,
25
36
  },
37
+ /**
38
+ * An MCP with a fixed token: always the service account, in chats and in automations, for every user. Use it only for data that does not depend on the user.
39
+ */
26
40
  {
27
41
  name: 'catalog',
28
42
  url: 'https://catalog.example.com/mcp',
@@ -2,6 +2,9 @@ import { Logger } from 'openloops/common'
2
2
  import { CurrentUser } from 'openloops/base'
3
3
  import { listAllMcpServersByUser } from 'openloops/mcps'
4
4
 
5
+ /**
6
+ * Lists every MCP server of the user, oldest first, without pages. It is what the agent uses. The internal servers never appear here.
7
+ */
5
8
  async function listAllMcps () {
6
9
  const logger = new Logger()
7
10
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -2,6 +2,9 @@ import { Logger } from 'openloops/common'
2
2
  import { CurrentUser } from 'openloops/base'
3
3
  import { listMcpServersByUser } from 'openloops/mcps'
4
4
 
5
+ /**
6
+ * Lists the MCP servers of the user in pages, for a management screen. The internal servers never appear here.
7
+ */
5
8
  async function getMcpById () {
6
9
  const logger = new Logger()
7
10
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -2,6 +2,11 @@ import { Logger } from 'openloops/common'
2
2
  import { CurrentUser } from 'openloops/base'
3
3
  import { updateMcpServer } from 'openloops/mcps'
4
4
 
5
+ /**
6
+ * Updates a server of the user. Here the header carries a fixed token: the user wrote it, and it is sent as it is.
7
+ *
8
+ * Changing the headers checks the connection again and keeps the approval. Changing the `url` locks the server again.
9
+ */
5
10
  async function updateMcp () {
6
11
  const logger = new Logger()
7
12
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -2,6 +2,9 @@ import { Logger } from 'openloops/common'
2
2
  import { CurrentUser } from 'openloops/base'
3
3
  import { verifyMcpServerConnection } from 'openloops/mcps'
4
4
 
5
+ /**
6
+ * Checks the connection of a server: it reads the manifest and saves the status (`ok` or `error`). Use it in a "test connection" button, it also feeds a green or red dot.
7
+ */
5
8
  async function verifyMcp () {
6
9
  const logger = new Logger()
7
10
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -2,6 +2,9 @@ import { Agent } from 'openloops/core'
2
2
  import { Logger } from 'openloops/common'
3
3
  import { CurrentUser } from 'openloops/base'
4
4
 
5
+ /**
6
+ * Asks a running chat to stop. The loop stops before its next node, so a node that is already running finishes first.
7
+ */
5
8
  async function interruptAgent () {
6
9
  const logger = new Logger()
7
10
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -3,6 +3,9 @@ import { Logger } from 'openloops/common'
3
3
  import { CurrentUser } from 'openloops/base'
4
4
  import { AgiLoop } from 'openloops/loops'
5
5
 
6
+ /**
7
+ * Runs the agent with nobody in the chat. It does not ask questions: it decides by itself or pauses when something needs a human. When it pauses, the chat is waiting and the user answers in it.
8
+ */
6
9
  async function runAgentAutonomous () {
7
10
  const logger = new Logger()
8
11
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -3,6 +3,9 @@ import { Logger } from 'openloops/common'
3
3
  import { CurrentUser } from 'openloops/base'
4
4
  import { AgiLoop } from 'openloops/loops'
5
5
 
6
+ /**
7
+ * Strict mode: when an approved MCP server changed, the agent always asks the user, even if the change looks harmless.
8
+ */
6
9
  async function runAgentInStrictMode () {
7
10
  const logger = new Logger()
8
11
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -4,6 +4,9 @@ import { CurrentUser } from 'openloops/base'
4
4
  import { AgiLoop } from 'openloops/loops'
5
5
  import { Tool } from 'openloops/tools'
6
6
 
7
+ /**
8
+ * A destructive tool. Before it runs, the agent asks the user to confirm.
9
+ */
7
10
  const deleteNoteTool = new Tool({
8
11
  name: 'delete_note',
9
12
  description: 'Permanently delete a note by its id',
@@ -18,6 +21,9 @@ const deleteNoteTool = new Tool({
18
21
  handler: async ({ noteId }: { noteId: string }) => ({ data: { deleted: noteId } }),
19
22
  })
20
23
 
24
+ /**
25
+ * Two runs of the same chat: the first one ends with a question for the user, the second one carries the answer and the tool runs.
26
+ */
21
27
  async function runAgentWithConfirmation () {
22
28
  const logger = new Logger()
23
29
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -3,6 +3,9 @@ import { Logger } from 'openloops/common'
3
3
  import { CurrentUser } from 'openloops/base'
4
4
  import { AgiLoop } from 'openloops/loops'
5
5
 
6
+ /**
7
+ * Sets the model that is used when neither the run, the user nor the chat choose one.
8
+ */
6
9
  async function runAgentWithFallbackModel () {
7
10
  const logger = new Logger()
8
11
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -0,0 +1,34 @@
1
+ import { Agent } from 'openloops/core'
2
+ import { Logger } from 'openloops/common'
3
+ import { CurrentUser } from 'openloops/base'
4
+ import { AgiLoop } from 'openloops/loops'
5
+ import { fetchUrlTool } from 'openloops/tools'
6
+
7
+ /**
8
+ * Adds the tool that reads web pages as text. It needs no key, but it does not run JavaScript, so pages that load their content in the browser come back empty.
9
+ */
10
+ async function runAgentWithFetchUrl () {
11
+ const logger = new Logger()
12
+ const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
13
+
14
+ if (!currentUser) throw new Error('[Demo] current user is not defined')
15
+
16
+ const loop = new AgiLoop()
17
+ const agent = new Agent({ loop })
18
+ agent.addTool(fetchUrlTool)
19
+
20
+ try {
21
+ const result = await agent.run({
22
+ input: {
23
+ message: 'read https://example.com and tell me what the page says',
24
+ },
25
+ currentUser,
26
+ })
27
+
28
+ logger.debug(result, '[Demo] Result')
29
+ } catch (error: any) {
30
+ logger.error(error, '[Demo] Error')
31
+ }
32
+ }
33
+
34
+ runAgentWithFetchUrl()
@@ -4,6 +4,9 @@ import { CurrentUser } from 'openloops/base'
4
4
  import { AgiLoop } from 'openloops/loops'
5
5
  import { inputGuards } from 'openloops/guardrails'
6
6
 
7
+ /**
8
+ * Adds input guards, in the options and with `addGuard`. A blocked message gets the reply of the guard and never reaches the model.
9
+ */
7
10
  async function runAgentWithGuards () {
8
11
  const logger = new Logger()
9
12
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -3,6 +3,9 @@ import { Logger } from 'openloops/common'
3
3
  import { CurrentUser } from 'openloops/base'
4
4
  import { AgiLoop } from 'openloops/loops'
5
5
 
6
+ /**
7
+ * Hooks that run before and after the execution, for example to send a notification when the run finishes and the user asked for it.
8
+ */
6
9
  async function runAgentWithHooks () {
7
10
  const logger = new Logger()
8
11
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -47,6 +50,9 @@ async function runAgentWithHooks () {
47
50
  }
48
51
  }
49
52
 
53
+ /**
54
+ * Stands for the service of notifications of your app.
55
+ */
50
56
  async function sendNotificationMock (params: any) {
51
57
  const logger = new Logger()
52
58
  logger.info(params, '[Notification Service] Sending notification to user...')
@@ -3,6 +3,9 @@ import { Logger } from 'openloops/common'
3
3
  import { CurrentUser } from 'openloops/base'
4
4
  import { AgiLoop } from 'openloops/loops'
5
5
 
6
+ /**
7
+ * Gives the agent a name, a gender and a role, so it answers as that persona.
8
+ */
6
9
  async function runAgentWithIdentity () {
7
10
  const logger = new Logger()
8
11
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -3,6 +3,9 @@ import { Logger } from 'openloops/common'
3
3
  import { CurrentUser } from 'openloops/base'
4
4
  import { AgiLoop } from 'openloops/loops'
5
5
 
6
+ /**
7
+ * Chooses the model of this run. The chat saves the model that it used.
8
+ */
6
9
  async function runAgentWithModel () {
7
10
  const logger = new Logger()
8
11
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -4,6 +4,9 @@ import { CurrentUser } from 'openloops/base'
4
4
  import { AgiLoop } from 'openloops/loops'
5
5
  import { webSearchTool, sendSlackMessageTool } from 'openloops/tools'
6
6
 
7
+ /**
8
+ * Adds two tools: a web search and a message to Slack. The agent decides by itself when to use each one.
9
+ */
7
10
  async function runAgentWithSlack () {
8
11
  const logger = new Logger()
9
12
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -4,6 +4,9 @@ import { CurrentUser } from 'openloops/base'
4
4
  import { AgiLoop } from 'openloops/loops'
5
5
  import { webSearchTool } from 'openloops/tools'
6
6
 
7
+ /**
8
+ * Adds a tool to the agent. The model decides when to call it, and you can add more with `addTool` or in the options.
9
+ */
7
10
  async function runAgentWithTools () {
8
11
  const logger = new Logger()
9
12
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -10,6 +10,9 @@ interface Output {
10
10
  }
11
11
  }
12
12
 
13
+ /**
14
+ * A basic tool. The model reads `name`, `description` and `parameters` to decide when to call it, and the handler returns `{ data }`. It is not destructive, so it runs without asking.
15
+ */
13
16
  export const greetUserTool = new Tool({
14
17
  name: 'greet_user',
15
18
  description: 'Greet the user',
@@ -10,6 +10,9 @@ interface Output {
10
10
  }
11
11
  }
12
12
 
13
+ /**
14
+ * A destructive tool: `destructive: true` makes the agent ask the user to confirm before it runs.
15
+ */
13
16
  export const deleteNoteTool = new Tool({
14
17
  name: 'delete_note',
15
18
  description: 'Permanently delete a note by its id',
@@ -11,6 +11,9 @@ interface Output {
11
11
  data: SerperSearchResponse | undefined
12
12
  }
13
13
 
14
+ /**
15
+ * A tool that calls an external service. It needs `SERPER_API_KEY` in the environment.
16
+ */
14
17
  export const webSearchTool = new Tool({
15
18
  name: 'web_search',
16
19
  description: 'Search on web',
@@ -2,6 +2,9 @@ import { Logger } from 'openloops/common'
2
2
  import { CurrentUser } from 'openloops/base'
3
3
  import { getLLMUsageByChat } from 'openloops/llmcalls'
4
4
 
5
+ /**
6
+ * Tokens and cost of a whole chat, with the breakdown by model.
7
+ */
5
8
  async function getChatUsage () {
6
9
  const logger = new Logger()
7
10
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -2,6 +2,9 @@ import { Logger } from 'openloops/common'
2
2
  import { CurrentUser } from 'openloops/base'
3
3
  import { getLLMUsageByMessage } from 'openloops/llmcalls'
4
4
 
5
+ /**
6
+ * Tokens and cost of the answer to one message.
7
+ */
5
8
  async function getMessageUsage () {
6
9
  const logger = new Logger()
7
10
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -2,6 +2,9 @@ import { Logger } from 'openloops/common'
2
2
  import { CurrentUser } from 'openloops/base'
3
3
  import { getLLMUsageStats } from 'openloops/llmcalls'
4
4
 
5
+ /**
6
+ * Usage between two dates, grouped by month and filtered by provider and model.
7
+ */
5
8
  async function getRangeStats () {
6
9
  const logger = new Logger()
7
10
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -2,6 +2,9 @@ import { Logger } from 'openloops/common'
2
2
  import { CurrentUser } from 'openloops/base'
3
3
  import { getLLMUsageStats } from 'openloops/llmcalls'
4
4
 
5
+ /**
6
+ * Usage of the user in the current month, with the total, the breakdown by model and the series by day.
7
+ */
5
8
  async function getCurrentMonthStats () {
6
9
  const logger = new Logger()
7
10
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -2,6 +2,9 @@ import { createUser, UserRole } from 'openloops/users'
2
2
  import { Scope } from 'openloops/base'
3
3
  import { Logger } from 'openloops/common'
4
4
 
5
+ /**
6
+ * Creates a user. There is no session yet, so the call uses a system scope with a reason.
7
+ */
5
8
  async function createUserExample () {
6
9
  const logger = new Logger()
7
10
 
@@ -2,6 +2,9 @@ import { Logger } from 'openloops/common'
2
2
  import { deleteUser } from 'openloops/users'
3
3
  import { CurrentUser } from 'openloops/base'
4
4
 
5
+ /**
6
+ * Deletes the account of a user without removing it from the database. The reason is optional.
7
+ */
5
8
  async function softDeleteUser () {
6
9
  const logger = new Logger()
7
10
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -16,6 +19,9 @@ async function softDeleteUser () {
16
19
  logger.info(result, '[Demo] Deleted user')
17
20
  }
18
21
 
22
+ /**
23
+ * Removes the user from the database for good. Only an admin can do it.
24
+ */
19
25
  async function hardDeleteUser () {
20
26
  const logger = new Logger()
21
27
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -3,6 +3,9 @@ import { getUserById } from 'openloops/users'
3
3
  import { CurrentUser } from 'openloops/base'
4
4
 
5
5
  // Note: return the user without the password field
6
+ /**
7
+ * Gets a user by id. The password is never returned.
8
+ */
6
9
  async function getUserByIdExample () {
7
10
  const logger = new Logger()
8
11
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -2,6 +2,9 @@ import { Logger } from 'openloops/common'
2
2
  import { ListUsersByProps } from 'openloops/users'
3
3
  import { CurrentUser } from 'openloops/base'
4
4
 
5
+ /**
6
+ * Lists users by their properties, in pages. Only an admin can list other people.
7
+ */
5
8
  async function listUsers () {
6
9
  const logger = new Logger()
7
10
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -2,6 +2,9 @@ import { Logger } from 'openloops/common'
2
2
  import { updateUser } from 'openloops/users'
3
3
  import { CurrentUser } from 'openloops/base'
4
4
 
5
+ /**
6
+ * Sets the default model of the user, used when a run or a chat does not choose one.
7
+ */
5
8
  async function setDefaultModel () {
6
9
  const logger = new Logger()
7
10
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
@@ -19,6 +22,9 @@ async function setDefaultModel () {
19
22
  logger.info(result.preferences?.defaultModel, '[Demo] Default model:')
20
23
  }
21
24
 
25
+ /**
26
+ * Removes the default model of the user.
27
+ */
22
28
  async function removeDefaultModel () {
23
29
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
24
30
 
@@ -2,6 +2,9 @@ import { Logger } from 'openloops/common'
2
2
  import { updateUser } from 'openloops/users'
3
3
  import { CurrentUser } from 'openloops/base'
4
4
 
5
+ /**
6
+ * Updates the profile of the user. To change the password use `changePassword`.
7
+ */
5
8
  async function updateUserExample () {
6
9
  const logger = new Logger()
7
10
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openloops",
3
- "version": "0.7.2",
3
+ "version": "0.7.5",
4
4
  "description": "Open source harness for AI agents: a TypeScript runtime with persistence, tools, MCP trust, approvals and autonomous automations, where the loop is pluggable",
5
5
  "author": {
6
6
  "name": "Jose Barcos",