openloops 0.9.0 → 0.10.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +2 -0
  3. package/dist/clients/llm/llm-client.d.ts +1 -0
  4. package/dist/clients/llm/llm-client.js +6 -3
  5. package/dist/clients/llm/llm-client.mjs +6 -3
  6. package/dist/common/base/current-user.js +2 -1
  7. package/dist/common/base/current-user.mjs +2 -1
  8. package/dist/common/index.d.ts +3 -0
  9. package/dist/common/index.js +6 -0
  10. package/dist/common/index.mjs +4 -0
  11. package/dist/common/repositories/mongo-db.client.d.ts +1 -1
  12. package/dist/common/repositories/mongo-db.client.js +7 -6
  13. package/dist/common/repositories/mongo-db.client.mjs +7 -6
  14. package/dist/common/repositories/mongo-db.repository.d.ts +3 -2
  15. package/dist/common/repositories/mongo-db.repository.js +20 -16
  16. package/dist/common/repositories/mongo-db.repository.mjs +20 -16
  17. package/dist/common/utils/config-context.d.ts +3 -0
  18. package/dist/common/utils/config-context.js +33 -0
  19. package/dist/common/utils/config-context.mjs +8 -0
  20. package/dist/common/utils/secret-manager.d.ts +7 -5
  21. package/dist/common/utils/secret-manager.js +41 -28
  22. package/dist/common/utils/secret-manager.mjs +41 -28
  23. package/dist/harness/agent-state.d.ts +1 -1
  24. package/dist/harness/agent.d.ts +1 -0
  25. package/dist/harness/agent.js +17 -1
  26. package/dist/harness/agent.mjs +17 -1
  27. package/dist/services/authentication/repositories/refresh-token.repository.js +1 -1
  28. package/dist/services/authentication/repositories/refresh-token.repository.mjs +1 -1
  29. package/dist/services/authentication/repositories/revoked-token.repository.js +1 -1
  30. package/dist/services/authentication/repositories/revoked-token.repository.mjs +1 -1
  31. package/dist/services/automations/repositories/automation-run.repository.js +1 -1
  32. package/dist/services/automations/repositories/automation-run.repository.mjs +1 -1
  33. package/dist/services/automations/repositories/automation.repository.js +1 -1
  34. package/dist/services/automations/repositories/automation.repository.mjs +1 -1
  35. package/dist/services/chats/repositories/chat.repository.js +1 -1
  36. package/dist/services/chats/repositories/chat.repository.mjs +1 -1
  37. package/dist/services/llmcalls/repositories/llmcall.repository.js +1 -1
  38. package/dist/services/llmcalls/repositories/llmcall.repository.mjs +1 -1
  39. package/dist/services/mcp-servers/repositories/mcpserver.repository.js +1 -1
  40. package/dist/services/mcp-servers/repositories/mcpserver.repository.mjs +1 -1
  41. package/dist/services/tasks/repositories/agent-action.repository.js +1 -1
  42. package/dist/services/tasks/repositories/agent-action.repository.mjs +1 -1
  43. package/dist/services/tasks/repositories/agent-task.repository.js +1 -1
  44. package/dist/services/tasks/repositories/agent-task.repository.mjs +1 -1
  45. package/dist/services/traces/repositories/agent-trace.repository.js +1 -1
  46. package/dist/services/traces/repositories/agent-trace.repository.mjs +1 -1
  47. package/dist/services/users/repositories/user.repository.js +1 -1
  48. package/dist/services/users/repositories/user.repository.mjs +1 -1
  49. package/dist/services/workspaces/repositories/workspace-item.repository.js +1 -1
  50. package/dist/services/workspaces/repositories/workspace-item.repository.mjs +1 -1
  51. package/docs/README.md +1 -1
  52. package/docs/agent.md +3 -2
  53. package/docs/configuration.md +30 -1
  54. package/docs/integration-guide.md +1 -1
  55. package/docs/llms.txt +1 -1
  56. package/examples/run-agent/run-agent-multi-tenant.ts +52 -0
  57. package/examples/run-agent/run-agent-with-usage-limit.ts +5 -4
  58. package/package.json +1 -1
package/docs/llms.txt CHANGED
@@ -13,7 +13,7 @@ Start with the integration guide, then read only the pages you need. All pages a
13
13
  ## Run an agent
14
14
 
15
15
  - [The Agent](agent.md): options, running a turn, statuses, confirmations, autonomous mode
16
- - [Configuration](configuration.md): environment variables, default model, timeouts
16
+ - [Configuration](configuration.md): environment variables, encrypted values, several agents in one process, default model, timeouts
17
17
  - [Reporting errors](error-reporting.md): `setErrorReporter`, what it receives, what is reported, serverless and moving from `SENTRY_DSN`
18
18
  - [Chats](chats.md): the chat record, its title, message source, listing, searching and deleting, and the migration to 0.8.0
19
19
 
@@ -0,0 +1,52 @@
1
+ import { Agent } from 'openloops/core'
2
+ import { Logger, runWithConfigs, SecretManager } from 'openloops/common'
3
+ import { CurrentUser } from 'openloops/base'
4
+ import { AgiLoop } from 'openloops/loops'
5
+
6
+ /**
7
+ * Serves two agents from the same process. Each one has its own database, its own JWT secret and its own model key, and the
8
+ * values are stored encrypted. Everything inside `runWithConfigs` reads that configuration and never the environment.
9
+ */
10
+ const agents: Record<string, Record<string, string>> = {
11
+ acme: {
12
+ OPENLOOPS_DB_URI: 'mongodb://localhost:27017',
13
+ OPENLOOPS_DB_NAME: 'agent_acme',
14
+ JWT_SECRET: SecretManager.encrypt('acme-jwt-secret', 1),
15
+ ANTHROPIC_API_KEY: SecretManager.encrypt(process.env.ACME_ANTHROPIC_API_KEY as string, 1),
16
+ },
17
+ globex: {
18
+ OPENLOOPS_DB_URI: 'mongodb://localhost:27017',
19
+ OPENLOOPS_DB_NAME: 'agent_globex',
20
+ JWT_SECRET: SecretManager.encrypt('globex-jwt-secret', 1),
21
+ ANTHROPIC_API_KEY: SecretManager.encrypt(process.env.GLOBEX_ANTHROPIC_API_KEY as string, 1),
22
+ },
23
+ }
24
+
25
+ async function handleRequest (agentName: string, userId: string, message: string) {
26
+ return runWithConfigs(agents[agentName], async () => {
27
+ const currentUser = await CurrentUser.asyncFromDB(userId)
28
+
29
+ if (!currentUser) throw new Error('[Demo] current user is not defined')
30
+
31
+ const agent = new Agent({ loop: new AgiLoop() })
32
+
33
+ return agent.run({ input: { message }, currentUser })
34
+ })
35
+ }
36
+
37
+ async function runMultiTenant () {
38
+ const logger = new Logger()
39
+
40
+ try {
41
+ const [acme, globex] = await Promise.all([
42
+ handleRequest('acme', '6ab56894eb20887d1ef7942c', 'hi from acme'),
43
+ handleRequest('globex', '6ab56894eb20887d1ef7942d', 'hi from globex'),
44
+ ])
45
+
46
+ logger.info({ acme, globex }, '[Demo] Result')
47
+ } catch (error: any) {
48
+ logger.error(error, '[Demo] Error')
49
+ }
50
+ }
51
+
52
+ runMultiTenant()
@@ -25,8 +25,9 @@ async function runAgentWithUsageLimit () {
25
25
  * 2. PASS IT IN THE RUN.
26
26
  *
27
27
  * Before the run starts, `openloops` adds the cost of every model call of the user in the period, from any chat. If the total
28
- * is equal to or greater than `maxCostUsd`, the run does not start and nothing is saved. A run that starts under the limit
29
- * finishes, even if it goes over it.
28
+ * is equal to or greater than `maxCostUsd`, the run does not start: nothing calls the model. When the run continues a chat
29
+ * (`chatId`), the message is saved in it with no answer, so the user can say `continue` when the limit is lifted. A run that
30
+ * starts under the limit finishes, even if it goes over it.
30
31
  */
31
32
  const result = await agent.run({
32
33
  input: { message: 'hi, how are you?' },
@@ -37,8 +38,8 @@ async function runAgentWithUsageLimit () {
37
38
  /**
38
39
  * 3. HANDLE THE REJECTION.
39
40
  *
40
- * `agent.run` does not throw. A blocked run comes back with `errorCode: 'USAGE_LIMIT_REACHED'`, no `data` and the amounts in
41
- * `usageLimit`. Answer your client with the status that fits, for example 429, and let the app show its own message. This
41
+ * `agent.run` does not throw. A blocked run comes back with `errorCode: 'USAGE_LIMIT_REACHED'`, the amounts in `usageLimit`
42
+ * and, when it continued a chat, the chat in `data` with the saved message. Answer your client with the status that fits, for example 429, and let the app show its own message. This
42
43
  * rejection is expected, so it is not sent to the error reporter.
43
44
  */
44
45
  if (result.errorCode === 'USAGE_LIMIT_REACHED') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openloops",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Open source harness for building multitenant AI agents for your SaaS: a TypeScript runtime with persistence, tools, MCP trust, approvals and autonomous automations",
5
5
  "author": {
6
6
  "name": "Jose Barcos",