openloops 0.1.38 → 0.2.1
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/README.md +60 -5
- package/dist/clients/index.d.ts +2 -2
- package/dist/clients/index.js +4 -4
- package/dist/clients/index.mjs +2 -2
- package/dist/clients/llm/index.d.ts +1 -0
- package/dist/{loops/plan-execute → clients/llm}/index.js +4 -4
- package/dist/clients/llm/index.mjs +1 -0
- package/dist/clients/{llm-client.d.ts → llm/llm-client.d.ts} +3 -14
- package/dist/clients/{llm-client.js → llm/llm-client.js} +14 -37
- package/dist/clients/{llm-client.mjs → llm/llm-client.mjs} +15 -38
- package/dist/clients/{llm-error.mjs → llm/llm-error.mjs} +1 -1
- package/dist/clients/{llm-types.d.ts → llm/llm-types.d.ts} +1 -1
- package/dist/clients/llm/model-resolution.d.ts +20 -0
- package/dist/clients/llm/model-resolution.js +83 -0
- package/dist/clients/llm/model-resolution.mjs +46 -0
- package/dist/clients/{pi-ai-adapter.mjs → llm/pi-ai-adapter.mjs} +1 -1
- package/dist/clients/serper/index.d.ts +1 -0
- package/dist/clients/serper/index.js +22 -0
- package/dist/clients/serper/index.mjs +1 -0
- package/dist/clients/{serper-client.js → serper/serper-client.js} +2 -2
- package/dist/clients/{serper-client.mjs → serper/serper-client.mjs} +3 -3
- package/dist/harness/agent-loop.d.ts +0 -1
- package/dist/harness/agent.d.ts +6 -1
- package/dist/harness/agent.js +21 -13
- package/dist/harness/agent.mjs +21 -13
- package/dist/harness/native-tools.d.ts +1 -1
- package/dist/{loops/shared → harness}/skills/approval-request.d.ts +1 -1
- package/dist/{loops/shared → harness}/skills/approval-request.js +1 -1
- package/dist/{loops/shared → harness}/skills/approval-request.mjs +2 -2
- package/dist/{loops/shared → harness}/skills/autonomous-answer.d.ts +1 -1
- package/dist/{loops/shared → harness}/skills/autonomous-answer.js +1 -1
- package/dist/{loops/shared → harness}/skills/autonomous-answer.mjs +2 -2
- package/dist/{loops/shared → harness}/skills/confirmation-gate.d.ts +1 -1
- package/dist/{loops/shared → harness}/skills/confirmation-gate.js +1 -1
- package/dist/{loops/shared → harness}/skills/confirmation-gate.mjs +2 -2
- package/dist/harness/skills/index.d.ts +4 -0
- package/dist/{loops/plan-execute → harness}/skills/index.js +8 -8
- package/dist/harness/skills/index.mjs +4 -0
- package/dist/{loops/shared → harness}/skills/mcp-change-review.d.ts +1 -1
- package/dist/{loops/shared → harness}/skills/mcp-change-review.js +1 -1
- package/dist/{loops/shared → harness}/skills/mcp-change-review.mjs +2 -2
- package/dist/harness/tool-catalog.d.ts +1 -1
- package/dist/loops/index.d.ts +0 -1
- package/dist/loops/index.js +0 -2
- package/dist/loops/index.mjs +0 -1
- package/dist/loops/shared/skills/index.d.ts +0 -4
- package/dist/loops/shared/skills/index.js +1 -9
- package/dist/loops/shared/skills/index.mjs +0 -4
- package/dist/services/agentic-jobs/entities/agentic-job-run.entity.d.ts +42 -0
- package/dist/services/agentic-jobs/entities/agentic-job-run.entity.js +103 -0
- package/dist/services/agentic-jobs/entities/agentic-job-run.entity.mjs +80 -0
- package/dist/services/agentic-jobs/entities/agentic-job.entity.d.ts +39 -0
- package/dist/services/agentic-jobs/entities/agentic-job.entity.js +113 -0
- package/dist/services/agentic-jobs/entities/agentic-job.entity.mjs +90 -0
- package/dist/services/agentic-jobs/entities/index.d.ts +3 -0
- package/dist/services/agentic-jobs/entities/index.js +26 -0
- package/dist/services/agentic-jobs/entities/index.mjs +3 -0
- package/dist/services/agentic-jobs/entities/recurrence.d.ts +18 -0
- package/dist/services/agentic-jobs/entities/recurrence.js +84 -0
- package/dist/services/agentic-jobs/entities/recurrence.mjs +59 -0
- package/dist/services/agentic-jobs/index.d.ts +4 -0
- package/dist/services/agentic-jobs/index.js +28 -0
- package/dist/services/agentic-jobs/index.mjs +4 -0
- package/dist/services/agentic-jobs/module.d.ts +31 -0
- package/dist/services/agentic-jobs/module.js +132 -0
- package/dist/services/agentic-jobs/module.mjs +95 -0
- package/dist/services/agentic-jobs/repositories/agentic-job-run.repository.d.ts +11 -0
- package/dist/services/agentic-jobs/repositories/agentic-job-run.repository.js +71 -0
- package/dist/services/agentic-jobs/repositories/agentic-job-run.repository.mjs +42 -0
- package/dist/services/agentic-jobs/repositories/agentic-job.repository.d.ts +27 -0
- package/dist/services/agentic-jobs/repositories/agentic-job.repository.js +127 -0
- package/dist/services/agentic-jobs/repositories/agentic-job.repository.mjs +98 -0
- package/dist/services/agentic-jobs/repositories/index.d.ts +2 -0
- package/dist/services/agentic-jobs/repositories/index.js +24 -0
- package/dist/services/agentic-jobs/repositories/index.mjs +2 -0
- package/dist/services/agentic-jobs/runner/agentic-job-runner.d.ts +48 -0
- package/dist/services/agentic-jobs/runner/agentic-job-runner.js +181 -0
- package/dist/services/agentic-jobs/runner/agentic-job-runner.mjs +157 -0
- package/dist/services/agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.d.ts +15 -0
- package/dist/services/agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.js +58 -0
- package/dist/services/agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.mjs +29 -0
- package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.d.ts +29 -0
- package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.js +110 -0
- package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.mjs +81 -0
- package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.d.ts +14 -0
- package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.js +73 -0
- package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.mjs +44 -0
- package/dist/services/agentic-jobs/use-cases/delete-agentic-job.use-case.d.ts +15 -0
- package/dist/services/agentic-jobs/use-cases/delete-agentic-job.use-case.js +65 -0
- package/dist/services/agentic-jobs/use-cases/delete-agentic-job.use-case.mjs +36 -0
- package/dist/services/agentic-jobs/use-cases/finish-agentic-job-run.use-case.d.ts +19 -0
- package/dist/services/agentic-jobs/use-cases/finish-agentic-job-run.use-case.js +75 -0
- package/dist/services/agentic-jobs/use-cases/finish-agentic-job-run.use-case.mjs +46 -0
- package/dist/services/agentic-jobs/use-cases/get-agentic-job-by-id.use-case.d.ts +14 -0
- package/dist/services/agentic-jobs/use-cases/get-agentic-job-by-id.use-case.js +55 -0
- package/dist/services/agentic-jobs/use-cases/get-agentic-job-by-id.use-case.mjs +26 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.d.ts +16 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.js +57 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.mjs +28 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.d.ts +16 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.js +57 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.mjs +28 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.d.ts +15 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.js +57 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.mjs +28 -0
- package/dist/services/agentic-jobs/use-cases/preview-agentic-job-runs.use-case.d.ts +15 -0
- package/dist/services/agentic-jobs/use-cases/preview-agentic-job-runs.use-case.js +52 -0
- package/dist/services/agentic-jobs/use-cases/preview-agentic-job-runs.use-case.mjs +23 -0
- package/dist/services/agentic-jobs/use-cases/renew-agentic-job-lease.use-case.d.ts +18 -0
- package/dist/services/agentic-jobs/use-cases/renew-agentic-job-lease.use-case.js +58 -0
- package/dist/services/agentic-jobs/use-cases/renew-agentic-job-lease.use-case.mjs +29 -0
- package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.d.ts +21 -0
- package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.js +67 -0
- package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.mjs +38 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-run.use-case.d.ts +20 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-run.use-case.js +86 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-run.use-case.mjs +56 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-runs.use-case.d.ts +19 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-runs.use-case.js +68 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-runs.use-case.mjs +39 -0
- package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.d.ts +15 -0
- package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.js +83 -0
- package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.mjs +54 -0
- package/dist/services/agentic-jobs/utils/job-fields.d.ts +14 -0
- package/dist/services/agentic-jobs/utils/job-fields.js +61 -0
- package/dist/services/agentic-jobs/utils/job-fields.mjs +37 -0
- package/dist/services/agentic-jobs/utils/next-run.d.ts +4 -0
- package/dist/services/agentic-jobs/utils/next-run.js +62 -0
- package/dist/services/agentic-jobs/utils/next-run.mjs +37 -0
- package/dist/services/agentic-jobs/utils/open-run.d.ts +12 -0
- package/dist/services/agentic-jobs/utils/open-run.js +47 -0
- package/dist/services/agentic-jobs/utils/open-run.mjs +24 -0
- package/dist/services/agentic-jobs/utils/settings.d.ts +2 -0
- package/dist/services/agentic-jobs/utils/settings.js +34 -0
- package/dist/services/agentic-jobs/utils/settings.mjs +10 -0
- package/dist/services/chats/entities/chat.entity.d.ts +0 -5
- package/dist/services/chats/entities/chat.entity.js +0 -10
- package/dist/services/chats/entities/chat.entity.mjs +0 -10
- package/dist/services/llmcalls/module.d.ts +4 -2
- package/dist/services/llmcalls/module.js +13 -6
- package/dist/services/llmcalls/module.mjs +11 -5
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.d.ts +14 -0
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.js +62 -0
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.mjs +33 -0
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.d.ts +14 -0
- package/dist/services/llmcalls/use-cases/{get-llm-usage.use-case.js → get-llm-usage-by-message.use-case.js} +18 -37
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.mjs +33 -0
- package/dist/services/llmcalls/utils/usage-totals.d.ts +20 -0
- package/dist/services/llmcalls/utils/usage-totals.js +31 -0
- package/dist/services/llmcalls/utils/usage-totals.mjs +29 -0
- package/dist/services/tasks/entities/agent-task.entity.d.ts +2 -24
- package/dist/services/tasks/entities/agent-task.entity.js +2 -75
- package/dist/services/tasks/entities/agent-task.entity.mjs +2 -75
- package/dist/services/users/entities/user-default-model.d.ts +11 -0
- package/dist/services/users/entities/user-default-model.js +42 -0
- package/dist/services/users/entities/user-default-model.mjs +19 -0
- package/dist/services/users/entities/user-preferences.d.ts +4 -1
- package/dist/services/users/entities/user-preferences.js +8 -3
- package/dist/services/users/entities/user-preferences.mjs +8 -3
- package/dist/services/users/use-cases/create-user.use-case.js +3 -1
- package/dist/services/users/use-cases/create-user.use-case.mjs +3 -1
- package/dist/services/users/use-cases/update-user.use-case.js +4 -1
- package/dist/services/users/use-cases/update-user.use-case.mjs +4 -1
- package/dist/services/users/utils/default-model.d.ts +6 -0
- package/dist/services/users/utils/default-model.js +38 -0
- package/dist/services/users/utils/default-model.mjs +15 -0
- package/dist/skills/call-modes.d.ts +1 -1
- package/dist/skills/skill.d.ts +1 -1
- package/dist/skills/skill.js +1 -1
- package/dist/skills/skill.mjs +1 -1
- package/dist/tools/core/web-search/web-search.tool.js +1 -1
- package/dist/tools/core/web-search/web-search.tool.mjs +1 -1
- package/docs/README.md +46 -0
- package/docs/agent.md +202 -0
- package/docs/agentic-jobs.md +207 -0
- package/docs/assets/harness-car.svg +79 -0
- package/docs/authentication.md +40 -0
- package/docs/chats.md +88 -0
- package/docs/configuration.md +83 -0
- package/docs/guardrails.md +71 -0
- package/docs/harness.md +92 -0
- package/docs/integration-guide.md +138 -0
- package/docs/llms.txt +35 -0
- package/docs/loops.md +136 -0
- package/docs/mcp-servers.md +148 -0
- package/docs/skills.md +104 -0
- package/docs/tools.md +90 -0
- package/docs/usage.md +91 -0
- package/docs/users.md +108 -0
- package/examples/agentic-jobs/create-agentic-job.ts +24 -0
- package/examples/agentic-jobs/list-agentic-job-runs.ts +28 -0
- package/examples/agentic-jobs/list-agentic-jobs.ts +25 -0
- package/examples/agentic-jobs/preview-agentic-job-runs.ts +16 -0
- package/examples/agentic-jobs/run-agentic-job-now.ts +19 -0
- package/examples/agentic-jobs/run-agentic-job-worker.ts +29 -0
- package/examples/agentic-jobs/update-agentic-job.ts +36 -0
- package/examples/authentication/login.ts +17 -0
- package/examples/chats/delete-chat.ts +32 -0
- package/examples/chats/get-chat-by-id.ts +32 -0
- package/examples/chats/list-autonomous-chats.ts +23 -0
- package/examples/chats/list-chats.ts +20 -0
- package/examples/guardrails/custom-guard.ts +11 -0
- package/examples/loops/custom-loop.ts +50 -0
- package/examples/mcps/create-mcp.ts +24 -0
- package/examples/mcps/decide-mcp.ts +40 -0
- package/examples/mcps/delete-mcp.ts +32 -0
- package/examples/mcps/get-mcp-by-id.ts +17 -0
- package/examples/mcps/list-all-mcps.ts +14 -0
- package/examples/mcps/list-user-mcps.ts +23 -0
- package/examples/mcps/update-mcp.ts +23 -0
- package/examples/mcps/verify-mcp.ts +17 -0
- package/examples/run-agent/interrupt-agent.ts +16 -0
- package/examples/run-agent/run-agent-autonomous.ts +34 -0
- package/examples/run-agent/run-agent-strict-mode.ts +30 -0
- package/examples/run-agent/run-agent-with-confirmation.ts +49 -0
- package/examples/run-agent/run-agent-with-fallback-model.ts +25 -0
- package/examples/run-agent/run-agent-with-guards.ts +33 -0
- package/examples/run-agent/run-agent-with-hooks.ts +55 -0
- package/examples/run-agent/run-agent-with-identity.ts +36 -0
- package/examples/run-agent/run-agent-with-model.ts +33 -0
- package/examples/run-agent/run-agent-with-tools.ts +31 -0
- package/examples/tools/basic-tool.ts +35 -0
- package/examples/tools/destructive-tool.ts +34 -0
- package/examples/tools/web-search-tool.ts +37 -0
- package/examples/usage/get-chat-usage.ts +20 -0
- package/examples/usage/get-message-usage.ts +20 -0
- package/examples/usage/get-usage-stats-by-range.ts +23 -0
- package/examples/usage/get-usage-stats.ts +18 -0
- package/examples/users/create-user.ts +19 -0
- package/examples/users/delete-user.ts +36 -0
- package/examples/users/get-user-by-id.ts +18 -0
- package/examples/users/list-users.ts +18 -0
- package/examples/users/set-default-model.ts +36 -0
- package/examples/users/update-user.ts +22 -0
- package/package.json +9 -5
- package/dist/loops/plan-execute/index.d.ts +0 -1
- package/dist/loops/plan-execute/index.mjs +0 -1
- package/dist/loops/plan-execute/loop.d.ts +0 -26
- package/dist/loops/plan-execute/loop.js +0 -267
- package/dist/loops/plan-execute/loop.mjs +0 -249
- package/dist/loops/plan-execute/skills/action-planner.d.ts +0 -35
- package/dist/loops/plan-execute/skills/action-planner.js +0 -71
- package/dist/loops/plan-execute/skills/action-planner.mjs +0 -48
- package/dist/loops/plan-execute/skills/final-responder.d.ts +0 -7
- package/dist/loops/plan-execute/skills/final-responder.js +0 -58
- package/dist/loops/plan-execute/skills/final-responder.mjs +0 -35
- package/dist/loops/plan-execute/skills/index.d.ts +0 -4
- package/dist/loops/plan-execute/skills/index.mjs +0 -4
- package/dist/loops/plan-execute/skills/state-observer.d.ts +0 -10
- package/dist/loops/plan-execute/skills/state-observer.js +0 -61
- package/dist/loops/plan-execute/skills/state-observer.mjs +0 -38
- package/dist/loops/plan-execute/skills/strategy-engine.d.ts +0 -11
- package/dist/loops/plan-execute/skills/strategy-engine.js +0 -61
- package/dist/loops/plan-execute/skills/strategy-engine.mjs +0 -38
- package/dist/services/llmcalls/use-cases/get-llm-usage.use-case.d.ts +0 -24
- package/dist/services/llmcalls/use-cases/get-llm-usage.use-case.mjs +0 -51
- package/dist/skills/skill-runner.d.ts +0 -30
- package/dist/skills/skill-runner.js +0 -121
- package/dist/skills/skill-runner.mjs +0 -92
- /package/dist/clients/{llm-error.d.ts → llm/llm-error.d.ts} +0 -0
- /package/dist/clients/{llm-error.js → llm/llm-error.js} +0 -0
- /package/dist/clients/{llm-types.js → llm/llm-types.js} +0 -0
- /package/dist/clients/{llm-types.mjs → llm/llm-types.mjs} +0 -0
- /package/dist/clients/{pi-ai-adapter.d.ts → llm/pi-ai-adapter.d.ts} +0 -0
- /package/dist/clients/{pi-ai-adapter.js → llm/pi-ai-adapter.js} +0 -0
- /package/dist/clients/{serper-client.d.ts → serper/serper-client.d.ts} +0 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# MCP servers
|
|
2
|
+
|
|
3
|
+
Each user can register their own [MCP](https://modelcontextprotocol.io) servers. `openloops` connects to them when the agent needs them and converts their tools into regular `Tool` instances. Your loop never needs to know MCP exists.
|
|
4
|
+
|
|
5
|
+
MCP servers are third parties and can change their tools at any time, so every server goes through a trust flow before the agent is allowed to run any of its tools. Trust is per user: a server that one user approves is not approved for anyone else.
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import {
|
|
9
|
+
createMcpServer,
|
|
10
|
+
getMcpServerById,
|
|
11
|
+
listMcpServersByUser,
|
|
12
|
+
listAllMcpServersByUser,
|
|
13
|
+
updateMcpServer,
|
|
14
|
+
deleteMcpServer,
|
|
15
|
+
verifyMcpServerConnection,
|
|
16
|
+
decideMcpServerTrust,
|
|
17
|
+
} from 'openloops/mcps'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Registering a server
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
const result = await createMcpServer({
|
|
24
|
+
payload: {
|
|
25
|
+
name: 'my-mcp',
|
|
26
|
+
type: 'http',
|
|
27
|
+
url: 'https://example.dev/api/mcp',
|
|
28
|
+
headers: {
|
|
29
|
+
Authorization: 'Bearer ...',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
currentUser,
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Only `type: 'http'` is supported. `stdio` (which would mean running an arbitrary local process on your server) is intentionally not allowed.
|
|
37
|
+
|
|
38
|
+
`headers` is a plain key-value map, so you're not limited to `Authorization`.
|
|
39
|
+
|
|
40
|
+
Creating a server connects to it once to read its manifest (tools and instructions) and returns the result of that check. The new server starts as `locked`: nothing runs until the user approves it.
|
|
41
|
+
|
|
42
|
+
## The server record
|
|
43
|
+
|
|
44
|
+
| Field | Meaning |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| `name`, `url`, `type`, `headers` | What you registered. |
|
|
47
|
+
| `trust` | `locked` (never approved, also the value of old records without one), `approved` or `blocked`. |
|
|
48
|
+
| `approvedHash` | Hash of the manifest the user approved. |
|
|
49
|
+
| `history` | The last 5 manifests the server has shown, newest first. The approved one is never dropped. |
|
|
50
|
+
| `status` | `ok`, `error` or `unknown`, from the last connection check. Use it for a green or red dot. |
|
|
51
|
+
| `lastError` | Sanitized message of the last failed check, without header values or the url. |
|
|
52
|
+
|
|
53
|
+
The latest manifest is `history[0]`. The approved manifest is the entry of `history` whose hash equals `approvedHash`. What changed between them is computed when it is needed and is never stored.
|
|
54
|
+
|
|
55
|
+
`headers` and `history` are returned as they are stored. If your API exposes these records to a client, mask the header values and leave out `history` in your controller.
|
|
56
|
+
|
|
57
|
+
## Listing a user's servers
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
const page = await listMcpServersByUser({
|
|
61
|
+
options: { page: 1, limit: 10 },
|
|
62
|
+
currentUser,
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const all = await listAllMcpServersByUser({ currentUser })
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`listMcpServersByUser` is paginated (page 1, 10 per page by default) and sorted by last update, newest first. Use it for a management screen.
|
|
69
|
+
|
|
70
|
+
`listAllMcpServersByUser` returns every server of the user, oldest first. This is what the agent uses, so a user can have any number of servers.
|
|
71
|
+
|
|
72
|
+
## Getting one by id
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
const result = await getMcpServerById({ id: mcpServerId, currentUser })
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Updating a server
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const result = await updateMcpServer({
|
|
82
|
+
id: mcpServerId,
|
|
83
|
+
payload: {
|
|
84
|
+
name: 'my-mcp-updated',
|
|
85
|
+
headers: { Authorization: 'Bearer <new-token>' },
|
|
86
|
+
__v: current.__v,
|
|
87
|
+
},
|
|
88
|
+
currentUser,
|
|
89
|
+
})
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
- `trust`, `approvedHash`, `status`, `lastError` and `history` in the payload are ignored. They only change through the trust decision and the connection check, so you can send a whole record back without overwriting an approval.
|
|
93
|
+
- Changing `url` or `type` locks the server again (`trust` is `locked` and `approvedHash` is cleared) and checks the connection. The history is kept for traceability.
|
|
94
|
+
- Changing `headers` checks the connection again and keeps the approval. If the server answers with a different manifest, the agent treats it as a change and asks.
|
|
95
|
+
- If you send `__v` and the record was modified in the meantime, the update fails with a `VersionConflictError` (code `VERSION_CONFLICT`, status 409). Reload and try again.
|
|
96
|
+
|
|
97
|
+
## Deleting a server
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
await deleteMcpServer({ id: mcpServerId, currentUser })
|
|
101
|
+
|
|
102
|
+
await deleteMcpServer({ id: mcpServerId, hardDelete: true, currentUser })
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The first one is a soft delete. A hard delete is for admins only.
|
|
106
|
+
|
|
107
|
+
## Checking the connection
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
const result = await verifyMcpServerConnection({ id: mcpServerId, currentUser })
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Connects, reads the manifest and stores it in `history` if it is new, or stores a sanitized error and `status: 'error'`. The agent calls it by itself when it sees that a server changed. You can call it from a "test connection" button.
|
|
114
|
+
|
|
115
|
+
## Approving or blocking a server
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
await decideMcpServerTrust({
|
|
119
|
+
id: mcpServerId,
|
|
120
|
+
decision: 'approve',
|
|
121
|
+
manifestHash: result.data.history[0].hash,
|
|
122
|
+
currentUser,
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
await decideMcpServerTrust({ id: mcpServerId, decision: 'block', currentUser })
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
- Approving requires the hash of the manifest the user reviewed, and it must be the latest one in `history`. If the server changed since the user looked at it, the call fails and the user has to review again.
|
|
129
|
+
- A blocked server can be approved again the same way, which unblocks it.
|
|
130
|
+
- The agent makes the same call when the user answers yes or no in the chat, so a screen in your app and the chat are two ways of reaching the same decision.
|
|
131
|
+
|
|
132
|
+
## How the agent uses the servers
|
|
133
|
+
|
|
134
|
+
1. At the start of a turn the model sees an index of the user's servers: `name`, an optional `description` (the server's instructions, truncated) and a `state`: `approved`, `not_approved` or `blocked`. Nothing is connected yet.
|
|
135
|
+
2. When the model needs a capability, it lists the tools of a server with `search_tools` (with the `server` argument) or searches across all of them. Listing needs no approval. A blocked server cannot be listed.
|
|
136
|
+
3. The agent connects to a server the first time it is needed in a run. It compares the manifest the server shows now with the approved one and stores it if it is new.
|
|
137
|
+
4. Approval is asked when a tool is about to run, never before:
|
|
138
|
+
- First use of a server: always asks.
|
|
139
|
+
- The server changed after being approved: asks if a tool was added, a parameter or annotation changed, or the instructions changed. A review skill decides the harmless cases (a description rewritten, a tool removed) and approves them on behalf of the user. With `strictMode: true` it always asks.
|
|
140
|
+
5. The question is written from what changed, not from the whole server. A yes approves the manifest the user was shown, once per server and version, not once per tool. A no blocks the server.
|
|
141
|
+
|
|
142
|
+
A server that cannot be reached after a few retries is reported as unavailable for that run and the others keep working. A tool that does not answer within `MCP_TOOL_TIMEOUT_MS` (60 seconds by default, restarted by progress notifications) fails without being repeated, and the model is told that the result is unknown. See [configuration](configuration.md#timeouts).
|
|
143
|
+
|
|
144
|
+
Connections are closed at the end of every turn, including when the turn fails.
|
|
145
|
+
|
|
146
|
+
## Tools of MCP servers
|
|
147
|
+
|
|
148
|
+
Their names are prefixed with the server name, and they are marked as external so the model treats their descriptions as data. A tool is destructive when the server marks it with `destructiveHint`. A tool without that annotation is not treated as destructive, so rely on the server's approval and on your own review of what the server exposes.
|
package/docs/skills.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Skills
|
|
2
|
+
|
|
3
|
+
A `Skill` is a typed, structured call to an LLM: the way a node inside your `AgentLoop` reasons about something. Where a `Tool` *does* something in the world, a `Skill` *decides* something.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { Skill } from 'openloops/skills'
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Defining a skill
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
export type ResponseSchema = {
|
|
13
|
+
can_answer: boolean
|
|
14
|
+
answer: string
|
|
15
|
+
reasoning: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const myResponder = new Skill<ResponseSchema>({
|
|
19
|
+
name: 'my_responder',
|
|
20
|
+
version: '1.0.0',
|
|
21
|
+
description: 'Decides whether the request can be answered directly.',
|
|
22
|
+
temperature: 0.3,
|
|
23
|
+
systemInstructions: {
|
|
24
|
+
instruction_set: {
|
|
25
|
+
goal: 'Decide if the user message can be answered without any tools.',
|
|
26
|
+
role: 'You are the first filter of an assistant.',
|
|
27
|
+
logic_rules: [
|
|
28
|
+
'OUTPUT_FORMAT: Every response is a single JSON object matching response_schema. Nothing outside that JSON.',
|
|
29
|
+
],
|
|
30
|
+
response_schema: {
|
|
31
|
+
can_answer: 'boolean',
|
|
32
|
+
answer: 'string',
|
|
33
|
+
reasoning: 'string',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
| Prop | Required | What it does |
|
|
41
|
+
| --- | --- | --- |
|
|
42
|
+
| `name` | yes | Identifies the skill in traces and usage records. |
|
|
43
|
+
| `systemInstructions` | yes | A plain object the model follows. The bundled skills use `instruction_set` with `goal`, `role`, `logic_rules` and `response_schema`, which is a good shape to copy. |
|
|
44
|
+
| `version` | no | Recorded in the metadata of every call. Bump it whenever the prompt changes. |
|
|
45
|
+
| `description` | no | What the skill is for. |
|
|
46
|
+
| `temperature` | no | Sampling temperature. Defaults to `0.7`. |
|
|
47
|
+
| `systemRole` | no | Default `true`: the instructions travel as a system message. |
|
|
48
|
+
| `mode` | no | How the model is called when tools are given. Defaults to `plain_chat`. |
|
|
49
|
+
|
|
50
|
+
## Running a skill
|
|
51
|
+
|
|
52
|
+
Inside a loop node:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const result = await myResponder.run({
|
|
56
|
+
...ctx.skillParams,
|
|
57
|
+
contextInjection: {
|
|
58
|
+
goal: ctx.task?.goal,
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
if (result.can_answer) {
|
|
63
|
+
harness.reply(result.answer)
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`ctx.skillParams` already carries the provider and model chosen for the chat, `sessionId`, `answerId`, the user's message, `currentUser`, `currentSession` and the current chat. You normally only add `contextInjection`.
|
|
68
|
+
|
|
69
|
+
| Run option | What it does |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `contextInjection` | Extra keys placed under `CONTEXT`. |
|
|
72
|
+
| `input` | Extra keys placed under `INPUT`, next to `user_message`. |
|
|
73
|
+
| `history` | The conversation of a reasoning cycle, as messages. Used by loops that keep a state between cycles. |
|
|
74
|
+
| `chatHistory` | Previous user and assistant turns. Cannot be combined with `history`. |
|
|
75
|
+
| `tools` | Tool definitions to show the model. |
|
|
76
|
+
| `mode` | Overrides the mode of the skill for this call. |
|
|
77
|
+
|
|
78
|
+
`tools`, `mode`, `history` and `chatHistory` are run options. Putting them inside `contextInjection` throws.
|
|
79
|
+
|
|
80
|
+
## What the model always receives
|
|
81
|
+
|
|
82
|
+
Besides your `contextInjection`, every call gets the current UTC and local time, time zone, day of the week, the user's name and language, the session's device and location, and the conversation language (`detected_language`) when an earlier node has already detected it. Skills do not need to detect it again.
|
|
83
|
+
|
|
84
|
+
## The result
|
|
85
|
+
|
|
86
|
+
The parsed JSON object comes back with a few extras:
|
|
87
|
+
|
|
88
|
+
| Field | Meaning |
|
|
89
|
+
| --- | --- |
|
|
90
|
+
| `costInUsd` | Cost of the call. |
|
|
91
|
+
| `responseId` | Provider response id. |
|
|
92
|
+
| `opening` | The first message of the call, which loops store to keep the opening stable between cycles. |
|
|
93
|
+
| `callInfo` | `skill`, `skillVersion`, `mode`, `model`, `provider`, number of `blocks` and, when the model did not return JSON, `rawText`. |
|
|
94
|
+
|
|
95
|
+
Every call is traced, including failures. When a model sends several text blocks in one answer, the first complete one is used and the rest are discarded, which is noted in the trace.
|
|
96
|
+
|
|
97
|
+
## Call modes
|
|
98
|
+
|
|
99
|
+
| Mode | When to use it |
|
|
100
|
+
| --- | --- |
|
|
101
|
+
| `plain_chat` | Default. The tool list travels as text and the model answers with the JSON as text. It was the best or tied for best in the evals and works with any provider. |
|
|
102
|
+
| `function_calling` | One forced call per cycle with the whole response as arguments. Needs a provider with forced tool choice. |
|
|
103
|
+
| `function_calling_split` | Native function calling for each action. Experimental. |
|
|
104
|
+
| `legacy_tools_off` | Do not use. It scored 0 to 30% in the evals. |
|
package/docs/tools.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Tools
|
|
2
|
+
|
|
3
|
+
A `Tool` is a single capability your agent can call, such as searching the web, creating a record, or sending a message. Loops never care whether a tool is native to your code or came from a connected MCP server; both are the same `Tool` class by the time a loop sees them.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { Tool, BaseParams } from 'openloops/tools'
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Writing a custom tool
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
interface Params extends BaseParams {
|
|
13
|
+
firstName: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface Output {
|
|
17
|
+
data: { greeting: string }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const greetUserTool = new Tool({
|
|
21
|
+
name: 'greet_user',
|
|
22
|
+
description: 'Greet the user',
|
|
23
|
+
destructive: false,
|
|
24
|
+
parameters: {
|
|
25
|
+
type: 'object',
|
|
26
|
+
properties: {
|
|
27
|
+
firstName: { type: 'string', description: 'First name of the user' },
|
|
28
|
+
},
|
|
29
|
+
required: ['firstName'],
|
|
30
|
+
},
|
|
31
|
+
handler: async (params: Params): Promise<Output> => {
|
|
32
|
+
const { currentUser, sessionId, answerId, firstName } = params
|
|
33
|
+
return { data: { greeting: `Hi ${firstName}` } }
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
| Prop | What it does |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| `name` | Letters, numbers, `_` and `-`, up to 64 characters. This is the name the model writes in an action. |
|
|
41
|
+
| `description` | What the tool does. Write it for the model. |
|
|
42
|
+
| `parameters` | JSON schema of the arguments. |
|
|
43
|
+
| `destructive` | `true` makes the agent ask the user to confirm before it runs. Defaults to `false`, so set it explicitly for anything that changes or deletes data. |
|
|
44
|
+
| `handler` | Receives the arguments plus `BaseParams` and returns `{ data }`. |
|
|
45
|
+
|
|
46
|
+
`BaseParams` (`currentUser`, `sessionId`, `answerId`) is always merged into the arguments your handler receives. Destructure and ignore the ones you don't need.
|
|
47
|
+
|
|
48
|
+
A `Tool` instance is shared. Never write to `this` inside a handler. Everything that varies between calls comes in through `params`.
|
|
49
|
+
|
|
50
|
+
## Argument validation
|
|
51
|
+
|
|
52
|
+
Arguments are validated against `parameters` before the handler runs: required arguments, types and `enum` values. An invalid call comes back to the model as a failed action with a message it can use to correct itself. Tools from MCP servers are validated strictly, so an argument that is not in the schema is rejected.
|
|
53
|
+
|
|
54
|
+
## Registering a tool
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { Agent } from 'openloops/core'
|
|
58
|
+
import { AgiLoop } from 'openloops/loops'
|
|
59
|
+
|
|
60
|
+
const agent = new Agent({ loop: new AgiLoop() })
|
|
61
|
+
agent.addTool(greetUserTool)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
When your agent has more than 15 local tools, the model no longer receives the whole catalog. It sees a summary per source and finds the tools it needs with the native `search_tools`. See [harness](harness.md#tool-discovery).
|
|
65
|
+
|
|
66
|
+
## Built-in tools
|
|
67
|
+
|
|
68
|
+
### `webSearchTool`
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { webSearchTool } from 'openloops/tools'
|
|
72
|
+
|
|
73
|
+
agent.addTool(webSearchTool)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Requires a [Serper](https://serper.dev) API key. Set `SERPER_API_KEY` in your `.env`.
|
|
77
|
+
|
|
78
|
+
### `callAiTool`
|
|
79
|
+
|
|
80
|
+
An LLM-backed tool for ad-hoc analysis, summarization, extraction or transformation. It is useful as a fallback when no other tool fits a step.
|
|
81
|
+
|
|
82
|
+
## MCP tools
|
|
83
|
+
|
|
84
|
+
Tools exposed by a connected MCP server are converted to `Tool` instances by `openloops`. See [MCP servers](mcp-servers.md). Their names are prefixed with the server's name (for example `my-server__search`) so two servers never collide.
|
|
85
|
+
|
|
86
|
+
An MCP tool differs from a local one in three ways:
|
|
87
|
+
|
|
88
|
+
- `origin` is `mcp`, `server` is the server's name and `notice` is set. The notice tells the model that the description was written by a third party and is not an instruction from the user.
|
|
89
|
+
- `destructive` comes from the server's `destructiveHint` annotation and is `false` when the annotation is missing.
|
|
90
|
+
- It cannot run until the user has approved its server.
|
package/docs/usage.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# LLM usage tracking
|
|
2
|
+
|
|
3
|
+
Every LLM call `openloops` makes, including every skill run and every reasoning step, is recorded automatically with the raw response of the provider. Tokens, cache usage, reasoning tokens and cost are all read from that stored response, so nothing has to be instrumented.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { getLLMUsageByMessage, getLLMUsageByChat, getLLMUsageStats } from 'openloops/llmcalls'
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
There are three functions:
|
|
10
|
+
|
|
11
|
+
- `getLLMUsageByMessage` answers how much one answer of the agent used.
|
|
12
|
+
- `getLLMUsageByChat` answers how much a whole chat used.
|
|
13
|
+
- `getLLMUsageStats` answers how much a user used in a period, by model and over time.
|
|
14
|
+
|
|
15
|
+
## Usage of one answer and of one chat
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
const answer = await getLLMUsageByMessage({
|
|
19
|
+
messageId: assistantMessageId,
|
|
20
|
+
currentUser,
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const chat = await getLLMUsageByChat({
|
|
24
|
+
chatId,
|
|
25
|
+
currentUser,
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`messageId` is the `answerId` of the assistant message, and everything the agent spent to produce that answer is added together. Both functions only count the calls of `currentUser`, and both return the same shape:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
result.data.summary
|
|
33
|
+
// { calls, input, output, cacheRead, cacheWrite, reasoning, totalTokens, totalCost }
|
|
34
|
+
|
|
35
|
+
result.data.models
|
|
36
|
+
// [{ provider, model, calls, input, output, cacheRead, cacheWrite, reasoning, totalTokens, totalCost }]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`summary` is the total, and `models` has one entry for every provider and model that was used, with the same fields. A chat can use several models, because the user can change it between runs, so the detail by model tells how much each one cost. The answer of one message will usually have a single model. `summary` is always the sum of `models`, and `models` is sorted by tokens, highest first.
|
|
40
|
+
|
|
41
|
+
| Field | Meaning |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| `calls` | Number of calls to the model. |
|
|
44
|
+
| `input`, `output` | Tokens sent and generated. |
|
|
45
|
+
| `cacheRead`, `cacheWrite` | Tokens read from and written to the provider's prompt cache. |
|
|
46
|
+
| `reasoning` | Reasoning tokens, when the provider reports them. They are already inside `output`, so do not add them again. |
|
|
47
|
+
| `totalTokens` | Total tokens as the provider counts them. |
|
|
48
|
+
| `totalCost` | Cost in USD. |
|
|
49
|
+
|
|
50
|
+
When there are no matching calls, `summary` has every field in `0` and `models` is empty. A call that was stored without provider or model appears as `unknown`. `messageId` and `chatId` are required, and the call fails if they are missing or are not valid ids.
|
|
51
|
+
|
|
52
|
+
## Usage statistics of a user
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const result = await getLLMUsageStats({
|
|
56
|
+
filters: {
|
|
57
|
+
fromDate: '2026-09-01',
|
|
58
|
+
toDate: '2026-09-30',
|
|
59
|
+
groupBy: 'day',
|
|
60
|
+
provider: 'anthropic',
|
|
61
|
+
model: 'claude-haiku-5-5',
|
|
62
|
+
},
|
|
63
|
+
currentUser,
|
|
64
|
+
})
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
All filters are optional. The statistics are always those of `currentUser`.
|
|
68
|
+
|
|
69
|
+
| Filter | Default | Meaning |
|
|
70
|
+
| --- | --- | --- |
|
|
71
|
+
| `fromDate`, `toDate` | First and last day of the current month | Local days in the format `YYYY-MM-DD`, both included. |
|
|
72
|
+
| `groupBy` | `day` | Size of each period of the series: `day` or `month`. |
|
|
73
|
+
| `provider`, `model` | none | Only calls of that provider or model. |
|
|
74
|
+
|
|
75
|
+
Days and periods are calculated in the time zone of the user (UTC when the user has none), and daylight saving time is respected. A range can have at most 366 periods.
|
|
76
|
+
|
|
77
|
+
### The result
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
result.data.summary
|
|
81
|
+
// { calls, totalTokens, totalCost }
|
|
82
|
+
|
|
83
|
+
result.data.models
|
|
84
|
+
// [{ provider, model, calls, totalTokens, totalCost, tokensPercentage, costPercentage }]
|
|
85
|
+
|
|
86
|
+
result.data.series
|
|
87
|
+
// [{ period, input, output, cacheRead, cacheWrite, reasoning, totalTokens, totalCost }]
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
- `models` is sorted by tokens, highest first. The two percentages are the share of that model in the total tokens and in the total cost, and each one adds up to 100.
|
|
91
|
+
- `series` has one entry for every period of the range, in order, including the periods without calls, which come with zeros. `period` is `2026-09-15` for `day` and `2026-09` for `month`.
|
package/docs/users.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# User management
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { createUser, getUserById, updateUser, deleteUser, ListUsersByProps } from 'openloops/users'
|
|
7
|
+
import { CurrentUser } from 'openloops/base'
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## `CurrentUser`
|
|
11
|
+
|
|
12
|
+
Every call into `openloops`, whether running an agent, managing MCP servers or checking usage, needs a `CurrentUser`. Build one from a stored user id:
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
const currentUser = await CurrentUser.asyncFromDB(userId)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
It returns `undefined` when the user does not exist. A `CurrentUser` knows its role, so `currentUser.isAdmin()` decides what the use cases let it do: only admins can hard delete, and fields such as the version, owner and audit dates are only editable by them.
|
|
19
|
+
|
|
20
|
+
To log a user in and get a token, see [authentication](authentication.md).
|
|
21
|
+
|
|
22
|
+
## Creating a user
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
const result = await createUser({
|
|
26
|
+
payload: {
|
|
27
|
+
firstName: 'Jose',
|
|
28
|
+
lastName: 'Barcos',
|
|
29
|
+
email: 'jose@openloops.xyz',
|
|
30
|
+
password: 'a-real-password',
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`email` and `password` are required. Passwords are hashed before being stored and are never returned.
|
|
36
|
+
|
|
37
|
+
## Getting a user
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
const result = await getUserById({ id: userId, currentUser })
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The returned user never includes the password field.
|
|
44
|
+
|
|
45
|
+
## Listing users
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
const result = await ListUsersByProps({
|
|
49
|
+
where: { firstName: 'Jose' },
|
|
50
|
+
options: { page: 1, limit: 10 },
|
|
51
|
+
currentUser,
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Updating a user
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
const result = await updateUser({
|
|
59
|
+
id: userId,
|
|
60
|
+
payload: {
|
|
61
|
+
firstName: 'Jose',
|
|
62
|
+
lastName: 'Developer',
|
|
63
|
+
},
|
|
64
|
+
currentUser,
|
|
65
|
+
})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Default model
|
|
69
|
+
|
|
70
|
+
A user can have a preferred model, which is used for the chats they start when no model is chosen in the run.
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
await updateUser({
|
|
74
|
+
id: userId,
|
|
75
|
+
payload: {
|
|
76
|
+
preferences: {
|
|
77
|
+
defaultModel: { provider: 'anthropic', model: 'claude-haiku-5-5' },
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
currentUser,
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
await updateUser({ id: userId, payload: { preferences: { defaultModel: null } }, currentUser })
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
- The provider and the model are required together, and the model must exist in the catalog of providers. Otherwise the call fails with an error that says why.
|
|
87
|
+
- It does not change the other preferences of the user.
|
|
88
|
+
- Sending `null` removes it.
|
|
89
|
+
- It only applies to chats that start afterwards, because every chat saves the model it uses. See [configuration](configuration.md#which-model-a-chat-uses).
|
|
90
|
+
|
|
91
|
+
## Deleting a user
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
await deleteUser({
|
|
95
|
+
id: userId,
|
|
96
|
+
accountDeletionReason: 'User requested account closure',
|
|
97
|
+
currentUser,
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
await deleteUser({
|
|
101
|
+
id: userId,
|
|
102
|
+
accountDeletionReason: 'GDPR request',
|
|
103
|
+
hardDelete: true,
|
|
104
|
+
currentUser,
|
|
105
|
+
})
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The first one is a soft delete, `accountDeletionReason` is optional. A hard delete permanently removes the record and is for admins only.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Logger } from 'openloops/common'
|
|
2
|
+
import { CurrentUser } from 'openloops/base'
|
|
3
|
+
import { createAgenticJob } from 'openloops/agentic-jobs'
|
|
4
|
+
|
|
5
|
+
async function createJob () {
|
|
6
|
+
const logger = new Logger()
|
|
7
|
+
const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
|
|
8
|
+
|
|
9
|
+
const result = await createAgenticJob({
|
|
10
|
+
payload: {
|
|
11
|
+
name: 'Morning report',
|
|
12
|
+
instructions: 'Summarize the news about the bitcoin price and keep the summary short',
|
|
13
|
+
recurrence: { type: 'weekly', days: [1, 2, 3, 4, 5], time: '08:00' },
|
|
14
|
+
timezone: 'America/Lima',
|
|
15
|
+
modelProvider: 'anthropic',
|
|
16
|
+
modelName: 'claude-haiku-5-5',
|
|
17
|
+
},
|
|
18
|
+
currentUser,
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
logger.info({ id: result.data._id, nextRunAt: result.data.nextRunAt }, '[Demo] Created agentic job')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
createJob()
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Logger } from 'openloops/common'
|
|
2
|
+
import { CurrentUser } from 'openloops/base'
|
|
3
|
+
import { listAgenticJobRunsByJob, listAgenticJobRunsByUser } from 'openloops/agentic-jobs'
|
|
4
|
+
|
|
5
|
+
async function listRunsOfAJob () {
|
|
6
|
+
const logger = new Logger()
|
|
7
|
+
|
|
8
|
+
const result = await listAgenticJobRunsByJob({
|
|
9
|
+
jobId: '6ad0c9a6d3ea4199c9b7ba10',
|
|
10
|
+
options: { page: 1, limit: 20 },
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
logger.info(result.data.map(run => ({ status: run.status, startedAt: run.startedAt, chatId: run.chatId, error: run.error })), '[Demo] Runs of the job')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function listRunsThatNeedAttention () {
|
|
17
|
+
const logger = new Logger()
|
|
18
|
+
const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
|
|
19
|
+
|
|
20
|
+
const paused = await listAgenticJobRunsByUser({ status: 'paused', currentUser })
|
|
21
|
+
const failed = await listAgenticJobRunsByUser({ status: 'failed', currentUser })
|
|
22
|
+
|
|
23
|
+
logger.info({ paused: paused.data.length, failed: failed.data.length }, '[Demo] Runs that need attention')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
listRunsOfAJob()
|
|
27
|
+
|
|
28
|
+
// listRunsThatNeedAttention()
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Logger } from 'openloops/common'
|
|
2
|
+
import { CurrentUser } from 'openloops/base'
|
|
3
|
+
import { listAgenticJobsByUser } from 'openloops/agentic-jobs'
|
|
4
|
+
|
|
5
|
+
async function listJobs () {
|
|
6
|
+
const logger = new Logger()
|
|
7
|
+
const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
|
|
8
|
+
|
|
9
|
+
const result = await listAgenticJobsByUser({
|
|
10
|
+
options: {
|
|
11
|
+
page: 1,
|
|
12
|
+
limit: 20,
|
|
13
|
+
},
|
|
14
|
+
currentUser,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
logger.info(result.data.map(job => ({
|
|
18
|
+
name: job.name,
|
|
19
|
+
enabled: job.enabled,
|
|
20
|
+
nextRunAt: job.nextRunAt,
|
|
21
|
+
lastRunStatus: job.lastRunStatus,
|
|
22
|
+
})), '[Demo] Agentic jobs')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
listJobs()
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Logger } from 'openloops/common'
|
|
2
|
+
import { previewAgenticJobRuns } from 'openloops/agentic-jobs'
|
|
3
|
+
|
|
4
|
+
async function previewRuns () {
|
|
5
|
+
const logger = new Logger()
|
|
6
|
+
|
|
7
|
+
const result = await previewAgenticJobRuns({
|
|
8
|
+
recurrence: { type: 'monthly', day: 'last', time: '18:00' },
|
|
9
|
+
timezone: 'America/Lima',
|
|
10
|
+
count: 5,
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
logger.info(result.data.runs, '[Demo] Next runs')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
previewRuns()
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Logger } from 'openloops/common'
|
|
2
|
+
import { createAgenticJobRunner } from 'openloops/agentic-jobs'
|
|
3
|
+
import { webSearchTool } from 'openloops/tools'
|
|
4
|
+
|
|
5
|
+
async function runNow () {
|
|
6
|
+
const logger = new Logger()
|
|
7
|
+
|
|
8
|
+
const runner = createAgenticJobRunner({
|
|
9
|
+
agent: { tools: [webSearchTool] },
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
const { run } = await runner.runNow({ jobId: '6ad0c9a6d3ea4199c9b7ba10' })
|
|
13
|
+
|
|
14
|
+
logger.info({ runId: run._id, status: run.status }, '[Demo] The run started in the background')
|
|
15
|
+
|
|
16
|
+
await runner.stop()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
runNow()
|