openloops 0.10.3 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +11 -17
- package/dist/clients/llm/llm-client.d.ts +2 -2
- package/dist/clients/llm/llm-client.js +17 -18
- package/dist/clients/llm/llm-client.mjs +12 -13
- package/dist/clients/llm/llm-types.d.ts +2 -2
- package/dist/clients/llm/model-resolution.js +4 -5
- package/dist/clients/llm/model-resolution.mjs +1 -2
- package/dist/clients/serper/serper-client.js +3 -4
- package/dist/clients/serper/serper-client.mjs +1 -2
- package/dist/clients/slack/slack-client.js +2 -2
- package/dist/clients/slack/slack-client.mjs +1 -1
- package/dist/common/utils/number-setting.js +2 -2
- package/dist/common/utils/number-setting.mjs +1 -1
- package/dist/db/indexes/index.js +1 -5
- package/dist/db/indexes/index.mjs +1 -5
- package/dist/guardrails/guard.d.ts +4 -4
- package/dist/harness/actor-profile.d.ts +2 -0
- package/dist/{common/error/error-reporter.js → harness/actor-profile.js} +10 -13
- package/dist/harness/actor-profile.mjs +9 -0
- package/dist/harness/agent-loop.d.ts +4 -5
- package/dist/harness/agent.d.ts +7 -7
- package/dist/harness/agent.js +46 -46
- package/dist/harness/agent.mjs +44 -44
- package/dist/harness/default-model.d.ts +20 -0
- package/dist/harness/default-model.js +72 -0
- package/dist/harness/default-model.mjs +46 -0
- package/dist/harness/index.d.ts +2 -0
- package/dist/harness/index.js +8 -1
- package/dist/harness/index.mjs +5 -1
- package/dist/harness/tool-pipeline.d.ts +1 -1
- package/dist/harness/tool-pipeline.js +3 -3
- package/dist/harness/tool-pipeline.mjs +1 -1
- package/dist/harness/usage-limit.d.ts +2 -2
- package/dist/harness/usage-limit.js +5 -3
- package/dist/harness/usage-limit.mjs +5 -3
- package/dist/harness/workspace.d.ts +3 -3
- package/dist/harness/workspace.js +8 -8
- package/dist/harness/workspace.mjs +8 -8
- package/dist/services/automations/entities/automation-run.entity.d.ts +1 -1
- package/dist/services/automations/entities/automation-run.entity.js +4 -4
- package/dist/services/automations/entities/automation-run.entity.mjs +1 -1
- package/dist/services/automations/entities/automation.entity.d.ts +1 -1
- package/dist/services/automations/entities/automation.entity.js +3 -3
- package/dist/services/automations/entities/automation.entity.mjs +1 -1
- package/dist/services/automations/repositories/automation-run.repository.d.ts +1 -1
- package/dist/services/automations/repositories/automation-run.repository.js +5 -6
- package/dist/services/automations/repositories/automation-run.repository.mjs +2 -3
- package/dist/services/automations/repositories/automation.repository.d.ts +1 -1
- package/dist/services/automations/repositories/automation.repository.js +5 -6
- package/dist/services/automations/repositories/automation.repository.mjs +2 -3
- package/dist/services/automations/runner/automation-runner.d.ts +4 -4
- package/dist/services/automations/runner/automation-runner.js +16 -15
- package/dist/services/automations/runner/automation-runner.mjs +11 -10
- package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.js +2 -2
- package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.mjs +1 -1
- package/dist/services/automations/use-cases/claim-due-automations.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/claim-due-automations.use-case.js +3 -4
- package/dist/services/automations/use-cases/claim-due-automations.use-case.mjs +1 -2
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.js +2 -2
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.mjs +1 -1
- package/dist/services/automations/use-cases/create-automation.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/create-automation.use-case.js +8 -8
- package/dist/services/automations/use-cases/create-automation.use-case.mjs +5 -5
- package/dist/services/automations/use-cases/delete-automation.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/delete-automation.use-case.js +8 -8
- package/dist/services/automations/use-cases/delete-automation.use-case.mjs +5 -5
- package/dist/services/automations/use-cases/finish-automation-run.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/finish-automation-run.use-case.js +2 -2
- package/dist/services/automations/use-cases/finish-automation-run.use-case.mjs +1 -1
- package/dist/services/automations/use-cases/get-automation-by-id.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/get-automation-by-id.use-case.js +7 -7
- package/dist/services/automations/use-cases/get-automation-by-id.use-case.mjs +4 -4
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.js +7 -7
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.mjs +4 -4
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.d.ts +2 -2
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.js +7 -7
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.mjs +4 -4
- package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.d.ts +2 -2
- package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.js +9 -9
- package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.mjs +6 -6
- package/dist/services/automations/use-cases/list-automations-by-user.use-case.d.ts +2 -2
- package/dist/services/automations/use-cases/list-automations-by-user.use-case.js +9 -9
- package/dist/services/automations/use-cases/list-automations-by-user.use-case.mjs +6 -6
- package/dist/services/automations/use-cases/preview-automation-runs.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/preview-automation-runs.use-case.js +2 -2
- package/dist/services/automations/use-cases/preview-automation-runs.use-case.mjs +1 -1
- package/dist/services/automations/use-cases/receive-automation-event.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/receive-automation-event.use-case.js +3 -3
- package/dist/services/automations/use-cases/receive-automation-event.use-case.mjs +2 -2
- package/dist/services/automations/use-cases/renew-automation-lease.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/renew-automation-lease.use-case.js +2 -2
- package/dist/services/automations/use-cases/renew-automation-lease.use-case.mjs +1 -1
- package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.js +10 -11
- package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.mjs +7 -8
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.js +7 -7
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.mjs +4 -4
- package/dist/services/automations/use-cases/start-automation-run.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/start-automation-run.use-case.js +5 -5
- package/dist/services/automations/use-cases/start-automation-run.use-case.mjs +4 -4
- package/dist/services/automations/use-cases/sync-automation-run.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/sync-automation-run.use-case.js +2 -2
- package/dist/services/automations/use-cases/sync-automation-run.use-case.mjs +1 -1
- package/dist/services/automations/use-cases/sync-automation-runs.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/sync-automation-runs.use-case.js +2 -2
- package/dist/services/automations/use-cases/sync-automation-runs.use-case.mjs +1 -1
- package/dist/services/automations/use-cases/update-automation.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/update-automation.use-case.js +8 -9
- package/dist/services/automations/use-cases/update-automation.use-case.mjs +4 -5
- package/dist/services/automations/utils/event-token.d.ts +1 -0
- package/dist/services/automations/utils/event-token.js +9 -6
- package/dist/services/automations/utils/event-token.mjs +3 -1
- package/dist/services/automations/utils/open-run.d.ts +1 -1
- package/dist/services/automations/utils/runner-scope.d.ts +1 -1
- package/dist/services/automations/utils/runner-scope.js +3 -3
- package/dist/services/automations/utils/runner-scope.mjs +1 -1
- package/dist/services/chats/entities/chat-message.entity.d.ts +1 -1
- package/dist/services/chats/entities/chat-message.entity.js +3 -3
- package/dist/services/chats/entities/chat-message.entity.mjs +1 -1
- package/dist/services/chats/entities/chat.entity.d.ts +1 -1
- package/dist/services/chats/entities/chat.entity.js +4 -4
- package/dist/services/chats/entities/chat.entity.mjs +1 -1
- package/dist/services/chats/repositories/chat.repository.d.ts +1 -1
- package/dist/services/chats/repositories/chat.repository.js +5 -6
- package/dist/services/chats/repositories/chat.repository.mjs +2 -3
- package/dist/services/chats/use-cases/create-chat.use-case.d.ts +1 -1
- package/dist/services/chats/use-cases/create-chat.use-case.js +7 -7
- package/dist/services/chats/use-cases/create-chat.use-case.mjs +4 -4
- package/dist/services/chats/use-cases/delete-chat.use-case.d.ts +1 -1
- package/dist/services/chats/use-cases/delete-chat.use-case.js +8 -8
- package/dist/services/chats/use-cases/delete-chat.use-case.mjs +5 -5
- package/dist/services/chats/use-cases/get-chat-by-id.use-case.d.ts +2 -2
- package/dist/services/chats/use-cases/get-chat-by-id.use-case.js +7 -7
- package/dist/services/chats/use-cases/get-chat-by-id.use-case.mjs +4 -4
- package/dist/services/chats/use-cases/interrupt-execution.use-case.d.ts +1 -1
- package/dist/services/chats/use-cases/interrupt-execution.use-case.js +7 -7
- package/dist/services/chats/use-cases/interrupt-execution.use-case.mjs +4 -4
- package/dist/services/chats/use-cases/list-chats-by-props.use-case.d.ts +2 -2
- package/dist/services/chats/use-cases/list-chats-by-props.use-case.js +7 -7
- package/dist/services/chats/use-cases/list-chats-by-props.use-case.mjs +4 -4
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.d.ts +2 -2
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.js +8 -8
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.mjs +5 -5
- package/dist/services/chats/use-cases/update-chat.use-case.d.ts +1 -1
- package/dist/services/chats/use-cases/update-chat.use-case.js +7 -7
- package/dist/services/chats/use-cases/update-chat.use-case.mjs +4 -4
- package/dist/services/llmcalls/entities/llmcall.entity.d.ts +1 -1
- package/dist/services/llmcalls/entities/llmcall.entity.js +4 -4
- package/dist/services/llmcalls/entities/llmcall.entity.mjs +1 -1
- package/dist/services/llmcalls/repositories/llmcall.repository.d.ts +1 -1
- package/dist/services/llmcalls/repositories/llmcall.repository.js +5 -6
- package/dist/services/llmcalls/repositories/llmcall.repository.mjs +2 -3
- package/dist/services/llmcalls/use-cases/create-llmcall.use-case.d.ts +1 -1
- package/dist/services/llmcalls/use-cases/create-llmcall.use-case.js +7 -7
- package/dist/services/llmcalls/use-cases/create-llmcall.use-case.mjs +4 -4
- package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.d.ts +1 -1
- package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.js +8 -8
- package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.mjs +5 -5
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.d.ts +1 -1
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.js +9 -9
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.mjs +6 -6
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.d.ts +1 -1
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.js +9 -9
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.mjs +6 -6
- package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.d.ts +2 -2
- package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.js +12 -10
- package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.mjs +9 -7
- package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.d.ts +1 -1
- package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.js +7 -7
- package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.mjs +4 -4
- package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.d.ts +2 -2
- package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.js +5 -5
- package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.mjs +4 -4
- package/dist/services/llmcalls/use-cases/update-llmcall.use-case.d.ts +1 -1
- package/dist/services/llmcalls/use-cases/update-llmcall.use-case.js +7 -7
- package/dist/services/llmcalls/use-cases/update-llmcall.use-case.mjs +4 -4
- package/dist/services/mcp-servers/admin/admin-params.d.ts +5 -0
- package/dist/{common/logger/index.js → services/mcp-servers/admin/admin-params.js} +2 -8
- package/dist/services/mcp-servers/admin/admin-params.mjs +0 -0
- package/dist/services/mcp-servers/admin/use-cases/create-internal-mcp.use-case.d.ts +3 -2
- package/dist/services/mcp-servers/admin/use-cases/create-internal-mcp.use-case.js +7 -7
- package/dist/services/mcp-servers/admin/use-cases/create-internal-mcp.use-case.mjs +4 -4
- package/dist/services/mcp-servers/admin/use-cases/delete-internal-mcp.use-case.d.ts +3 -2
- package/dist/services/mcp-servers/admin/use-cases/delete-internal-mcp.use-case.js +7 -7
- package/dist/services/mcp-servers/admin/use-cases/delete-internal-mcp.use-case.mjs +4 -4
- package/dist/services/mcp-servers/admin/use-cases/get-internal-mcp-by-id.use-case.d.ts +3 -2
- package/dist/services/mcp-servers/admin/use-cases/get-internal-mcp-by-id.use-case.js +7 -7
- package/dist/services/mcp-servers/admin/use-cases/get-internal-mcp-by-id.use-case.mjs +4 -4
- package/dist/services/mcp-servers/admin/use-cases/list-internal-mcps.use-case.d.ts +4 -3
- package/dist/services/mcp-servers/admin/use-cases/list-internal-mcps.use-case.js +7 -7
- package/dist/services/mcp-servers/admin/use-cases/list-internal-mcps.use-case.mjs +4 -4
- package/dist/services/mcp-servers/admin/use-cases/update-internal-mcp.use-case.d.ts +3 -2
- package/dist/services/mcp-servers/admin/use-cases/update-internal-mcp.use-case.js +8 -9
- package/dist/services/mcp-servers/admin/use-cases/update-internal-mcp.use-case.mjs +4 -5
- package/dist/services/mcp-servers/entities/mcpserver.entity.d.ts +1 -1
- package/dist/services/mcp-servers/entities/mcpserver.entity.js +2 -2
- package/dist/services/mcp-servers/entities/mcpserver.entity.mjs +1 -1
- package/dist/services/mcp-servers/repositories/mcpserver.repository.d.ts +1 -1
- package/dist/services/mcp-servers/repositories/mcpserver.repository.js +6 -7
- package/dist/services/mcp-servers/repositories/mcpserver.repository.mjs +2 -3
- package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.d.ts +1 -1
- package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.js +8 -8
- package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.mjs +5 -5
- package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.d.ts +1 -1
- package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.js +7 -7
- package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.mjs +4 -4
- package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.d.ts +1 -1
- package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.js +8 -8
- package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.mjs +5 -5
- package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.d.ts +1 -1
- package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.js +7 -7
- package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.mjs +4 -4
- package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.d.ts +1 -1
- package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.js +8 -8
- package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.mjs +5 -5
- package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.d.ts +2 -2
- package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.js +8 -8
- package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.mjs +5 -5
- package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.d.ts +1 -1
- package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.js +9 -10
- package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.mjs +5 -6
- package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.d.ts +1 -1
- package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.js +9 -10
- package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.mjs +4 -5
- package/dist/services/tasks/entities/agent-action.entity.d.ts +1 -1
- package/dist/services/tasks/entities/agent-action.entity.js +6 -7
- package/dist/services/tasks/entities/agent-action.entity.mjs +1 -2
- package/dist/services/tasks/entities/agent-task.entity.d.ts +1 -1
- package/dist/services/tasks/entities/agent-task.entity.js +4 -4
- package/dist/services/tasks/entities/agent-task.entity.mjs +1 -1
- package/dist/services/tasks/repositories/agent-action.repository.d.ts +1 -1
- package/dist/services/tasks/repositories/agent-action.repository.js +5 -6
- package/dist/services/tasks/repositories/agent-action.repository.mjs +2 -3
- package/dist/services/tasks/repositories/agent-task.repository.d.ts +1 -1
- package/dist/services/tasks/repositories/agent-task.repository.js +5 -6
- package/dist/services/tasks/repositories/agent-task.repository.mjs +2 -3
- package/dist/services/tasks/use-cases/create-agent-action.use-case.d.ts +1 -1
- package/dist/services/tasks/use-cases/create-agent-action.use-case.js +7 -7
- package/dist/services/tasks/use-cases/create-agent-action.use-case.mjs +4 -4
- package/dist/services/tasks/use-cases/create-agent-task.use-case.d.ts +1 -1
- package/dist/services/tasks/use-cases/create-agent-task.use-case.js +7 -7
- package/dist/services/tasks/use-cases/create-agent-task.use-case.mjs +4 -4
- package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.d.ts +1 -1
- package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.js +7 -7
- package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.mjs +4 -4
- package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.d.ts +2 -2
- package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.js +9 -10
- package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.mjs +6 -7
- package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.d.ts +2 -2
- package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.js +9 -10
- package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.mjs +6 -7
- package/dist/services/tasks/use-cases/update-agent-action.use-case.d.ts +1 -1
- package/dist/services/tasks/use-cases/update-agent-action.use-case.js +7 -7
- package/dist/services/tasks/use-cases/update-agent-action.use-case.mjs +4 -4
- package/dist/services/tasks/use-cases/update-agent-task.use-case.d.ts +1 -1
- package/dist/services/tasks/use-cases/update-agent-task.use-case.js +7 -7
- package/dist/services/tasks/use-cases/update-agent-task.use-case.mjs +4 -4
- package/dist/services/traces/entities/agent-trace-entry.entity.d.ts +1 -1
- package/dist/services/traces/entities/agent-trace-entry.entity.js +6 -6
- package/dist/services/traces/entities/agent-trace-entry.entity.mjs +1 -1
- package/dist/services/traces/repositories/agent-trace.repository.d.ts +1 -1
- package/dist/services/traces/repositories/agent-trace.repository.js +4 -4
- package/dist/services/traces/repositories/agent-trace.repository.mjs +2 -2
- package/dist/services/traces/use-cases/create-agent-traces.use-case.d.ts +1 -1
- package/dist/services/traces/use-cases/create-agent-traces.use-case.js +7 -7
- package/dist/services/traces/use-cases/create-agent-traces.use-case.mjs +4 -4
- package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.d.ts +2 -2
- package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.js +12 -13
- package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.mjs +6 -7
- package/dist/services/workspaces/entities/workspace-item.entity.d.ts +1 -1
- package/dist/services/workspaces/entities/workspace-item.entity.js +5 -5
- package/dist/services/workspaces/entities/workspace-item.entity.mjs +1 -1
- package/dist/services/workspaces/repositories/workspace-item.repository.d.ts +1 -1
- package/dist/services/workspaces/repositories/workspace-item.repository.js +5 -6
- package/dist/services/workspaces/repositories/workspace-item.repository.mjs +2 -3
- package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.d.ts +1 -1
- package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.js +11 -12
- package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.mjs +6 -7
- package/dist/services/workspaces/use-cases/get-workspace-item.use-case.d.ts +1 -1
- package/dist/services/workspaces/use-cases/get-workspace-item.use-case.js +11 -12
- package/dist/services/workspaces/use-cases/get-workspace-item.use-case.mjs +6 -7
- package/dist/services/workspaces/use-cases/list-workspace-items.use-case.d.ts +2 -2
- package/dist/services/workspaces/use-cases/list-workspace-items.use-case.js +11 -12
- package/dist/services/workspaces/use-cases/list-workspace-items.use-case.mjs +6 -7
- package/dist/services/workspaces/use-cases/save-workspace-item.use-case.d.ts +1 -1
- package/dist/services/workspaces/use-cases/save-workspace-item.use-case.js +10 -11
- package/dist/services/workspaces/use-cases/save-workspace-item.use-case.mjs +6 -7
- package/dist/services/workspaces/use-cases/search-workspace-items.use-case.d.ts +2 -2
- package/dist/services/workspaces/use-cases/search-workspace-items.use-case.js +11 -12
- package/dist/services/workspaces/use-cases/search-workspace-items.use-case.mjs +6 -7
- package/dist/skills/runtime-context.d.ts +3 -3
- package/dist/skills/runtime-context.js +24 -21
- package/dist/skills/runtime-context.mjs +24 -21
- package/dist/skills/skill.d.ts +3 -3
- package/dist/skills/skill.js +5 -5
- package/dist/skills/skill.mjs +4 -4
- package/dist/tools/core/call-ai/call-ai.tool.js +2 -2
- package/dist/tools/core/call-ai/call-ai.tool.mjs +2 -2
- 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/dist/tools/tool.d.ts +2 -2
- package/dist/tools/tool.js +1 -1
- package/dist/tools/tool.mjs +1 -1
- package/docs/README.md +1 -1
- package/docs/agent.md +10 -10
- package/docs/authentication.md +15 -114
- package/docs/authorization.md +18 -18
- package/docs/automations.md +28 -28
- package/docs/chats.md +14 -14
- package/docs/configuration.md +14 -15
- package/docs/error-reporting.md +6 -6
- package/docs/guardrails.md +1 -1
- package/docs/integration-guide.md +12 -12
- package/docs/loops.md +2 -2
- package/docs/mcp-servers.md +15 -15
- package/docs/skills.md +1 -1
- package/docs/tools.md +2 -2
- package/docs/usage.md +5 -5
- package/docs/users.md +18 -91
- package/examples/automations/create-automation.ts +4 -4
- package/examples/automations/create-event-automation.ts +5 -5
- package/examples/automations/list-automation-runs.ts +7 -7
- package/examples/automations/list-automations.ts +4 -4
- package/examples/automations/preview-automation-runs.ts +1 -1
- package/examples/automations/receive-automation-event.ts +1 -1
- package/examples/automations/revoke-automation-event-token.ts +6 -6
- package/examples/automations/run-automation-now.ts +4 -4
- package/examples/automations/run-automation-worker.ts +1 -1
- package/examples/automations/update-automation.ts +6 -6
- package/examples/chats/delete-chat.ts +6 -6
- package/examples/chats/get-chat-by-id.ts +6 -6
- package/examples/chats/list-autonomous-chats.ts +4 -4
- package/examples/chats/list-chats.ts +4 -4
- package/examples/chats/search-chats.ts +5 -5
- package/examples/errors/error-reporting.ts +6 -6
- package/examples/loops/custom-loop.ts +5 -5
- package/examples/mcps/create-mcp.ts +4 -4
- package/examples/mcps/decide-mcp.ts +7 -7
- package/examples/mcps/delete-mcp.ts +6 -6
- package/examples/mcps/get-mcp-by-id.ts +4 -4
- package/examples/mcps/internal-mcp-admin.ts +8 -8
- package/examples/mcps/internal-mcp.ts +5 -5
- package/examples/mcps/list-all-mcps.ts +4 -4
- package/examples/mcps/list-user-mcps.ts +4 -4
- package/examples/mcps/update-mcp.ts +4 -4
- package/examples/mcps/verify-mcp.ts +4 -4
- package/examples/run-agent/interrupt-agent.ts +5 -5
- package/examples/run-agent/run-agent-autonomous.ts +5 -5
- package/examples/run-agent/run-agent-multi-tenant.ts +10 -11
- package/examples/run-agent/run-agent-strict-mode.ts +5 -5
- package/examples/run-agent/run-agent-with-confirmation.ts +6 -6
- package/examples/run-agent/run-agent-with-fallback-model.ts +5 -5
- package/examples/run-agent/run-agent-with-fetch-url.ts +5 -5
- package/examples/run-agent/run-agent-with-guards.ts +5 -5
- package/examples/run-agent/run-agent-with-hooks.ts +5 -5
- package/examples/run-agent/run-agent-with-identity.ts +5 -5
- package/examples/run-agent/run-agent-with-model.ts +5 -5
- package/examples/run-agent/run-agent-with-slack.ts +5 -5
- package/examples/run-agent/run-agent-with-tools.ts +5 -5
- package/examples/run-agent/run-agent-with-usage-limit-stop.ts +5 -5
- package/examples/run-agent/run-agent-with-usage-limit.ts +5 -5
- package/examples/tools/basic-tool.ts +1 -1
- package/examples/tools/web-search-tool.ts +1 -1
- package/examples/usage/get-chat-usage.ts +4 -4
- package/examples/usage/get-message-usage.ts +4 -4
- package/examples/usage/get-usage-stats-by-range.ts +4 -4
- package/examples/usage/get-usage-stats.ts +4 -4
- package/examples/users/set-default-model.ts +12 -21
- package/package.json +5 -20
- package/dist/common/base/base.app.d.ts +0 -12
- package/dist/common/base/base.app.js +0 -57
- package/dist/common/base/base.app.mjs +0 -33
- package/dist/common/base/base.entity.d.ts +0 -38
- package/dist/common/base/base.entity.js +0 -100
- package/dist/common/base/base.entity.mjs +0 -76
- package/dist/common/base/base.use-case.d.ts +0 -11
- package/dist/common/base/base.use-case.js +0 -30
- package/dist/common/base/base.use-case.mjs +0 -6
- package/dist/common/base/current-session.d.ts +0 -129
- package/dist/common/base/current-session.js +0 -123
- package/dist/common/base/current-session.mjs +0 -98
- package/dist/common/base/current-user.d.ts +0 -16
- package/dist/common/base/current-user.js +0 -85
- package/dist/common/base/current-user.mjs +0 -61
- package/dist/common/base/index.d.ts +0 -3
- package/dist/common/base/index.js +0 -26
- package/dist/common/base/index.mjs +0 -3
- package/dist/common/base/share.d.ts +0 -12
- package/dist/common/base/share.js +0 -45
- package/dist/common/base/share.mjs +0 -20
- package/dist/common/base/utils/index.d.ts +0 -2
- package/dist/common/base/utils/index.js +0 -24
- package/dist/common/base/utils/index.mjs +0 -2
- package/dist/common/base/utils/is-plain-object.d.ts +0 -1
- package/dist/common/base/utils/is-plain-object.js +0 -32
- package/dist/common/base/utils/is-plain-object.mjs +0 -8
- package/dist/common/base/utils/to-patch.d.ts +0 -9
- package/dist/common/base/utils/to-patch.js +0 -46
- package/dist/common/base/utils/to-patch.mjs +0 -21
- package/dist/common/error/error-reporter.d.ts +0 -11
- package/dist/common/error/error-reporter.mjs +0 -11
- package/dist/common/error/http-error.d.ts +0 -11
- package/dist/common/error/http-error.js +0 -37
- package/dist/common/error/http-error.mjs +0 -13
- package/dist/common/error/index.d.ts +0 -3
- package/dist/common/error/index.js +0 -26
- package/dist/common/error/index.mjs +0 -3
- package/dist/common/error/reportError.d.ts +0 -2
- package/dist/common/error/reportError.js +0 -61
- package/dist/common/error/reportError.mjs +0 -37
- package/dist/common/error/sentry-client.d.ts +0 -10
- package/dist/common/error/sentry-client.js +0 -82
- package/dist/common/error/sentry-client.mjs +0 -57
- package/dist/common/index.d.ts +0 -6
- package/dist/common/index.js +0 -37
- package/dist/common/index.mjs +0 -9
- package/dist/common/logger/index.d.ts +0 -1
- package/dist/common/logger/index.mjs +0 -1
- package/dist/common/logger/pino.d.ts +0 -12
- package/dist/common/logger/pino.js +0 -79
- package/dist/common/logger/pino.mjs +0 -44
- package/dist/common/repositories/index.d.ts +0 -3
- package/dist/common/repositories/index.js +0 -26
- package/dist/common/repositories/index.mjs +0 -3
- package/dist/common/repositories/mongo-db.client.d.ts +0 -11
- package/dist/common/repositories/mongo-db.client.js +0 -83
- package/dist/common/repositories/mongo-db.client.mjs +0 -60
- package/dist/common/repositories/mongo-db.repository.d.ts +0 -130
- package/dist/common/repositories/mongo-db.repository.js +0 -357
- package/dist/common/repositories/mongo-db.repository.mjs +0 -332
- package/dist/common/repositories/scope.d.ts +0 -19
- package/dist/common/repositories/scope.js +0 -63
- package/dist/common/repositories/scope.mjs +0 -39
- package/dist/common/utils/config-context.d.ts +0 -3
- package/dist/common/utils/config-context.js +0 -33
- package/dist/common/utils/config-context.mjs +0 -8
- package/dist/common/utils/database-name.d.ts +0 -2
- package/dist/common/utils/database-name.js +0 -32
- package/dist/common/utils/database-name.mjs +0 -7
- package/dist/common/utils/secret-manager.d.ts +0 -17
- package/dist/common/utils/secret-manager.js +0 -124
- package/dist/common/utils/secret-manager.mjs +0 -89
- package/dist/db/indexes/refresh-tokens.d.ts +0 -2
- package/dist/db/indexes/refresh-tokens.js +0 -33
- package/dist/db/indexes/refresh-tokens.mjs +0 -9
- package/dist/db/indexes/revoked-tokens.d.ts +0 -2
- package/dist/db/indexes/revoked-tokens.js +0 -31
- package/dist/db/indexes/revoked-tokens.mjs +0 -7
- package/dist/services/authentication/entities/index.d.ts +0 -2
- package/dist/services/authentication/entities/index.js +0 -24
- package/dist/services/authentication/entities/index.mjs +0 -2
- package/dist/services/authentication/entities/refresh-token.entity.d.ts +0 -25
- package/dist/services/authentication/entities/refresh-token.entity.js +0 -75
- package/dist/services/authentication/entities/refresh-token.entity.mjs +0 -51
- package/dist/services/authentication/entities/revoked-token.entity.d.ts +0 -17
- package/dist/services/authentication/entities/revoked-token.entity.js +0 -67
- package/dist/services/authentication/entities/revoked-token.entity.mjs +0 -43
- package/dist/services/authentication/helpers/auth-config.d.ts +0 -9
- package/dist/services/authentication/helpers/auth-config.js +0 -36
- package/dist/services/authentication/helpers/auth-config.mjs +0 -12
- package/dist/services/authentication/helpers/session-tokens.d.ts +0 -16
- package/dist/services/authentication/helpers/session-tokens.js +0 -60
- package/dist/services/authentication/helpers/session-tokens.mjs +0 -35
- package/dist/services/authentication/helpers/tokens.d.ts +0 -43
- package/dist/services/authentication/helpers/tokens.js +0 -113
- package/dist/services/authentication/helpers/tokens.mjs +0 -71
- package/dist/services/authentication/index.d.ts +0 -5
- package/dist/services/authentication/index.js +0 -47
- package/dist/services/authentication/index.mjs +0 -13
- package/dist/services/authentication/module.d.ts +0 -16
- package/dist/services/authentication/module.js +0 -81
- package/dist/services/authentication/module.mjs +0 -50
- package/dist/services/authentication/repositories/index.d.ts +0 -2
- package/dist/services/authentication/repositories/index.js +0 -24
- package/dist/services/authentication/repositories/index.mjs +0 -2
- package/dist/services/authentication/repositories/refresh-token.repository.d.ts +0 -10
- package/dist/services/authentication/repositories/refresh-token.repository.js +0 -60
- package/dist/services/authentication/repositories/refresh-token.repository.mjs +0 -36
- package/dist/services/authentication/repositories/revoked-token.repository.d.ts +0 -7
- package/dist/services/authentication/repositories/revoked-token.repository.js +0 -44
- package/dist/services/authentication/repositories/revoked-token.repository.mjs +0 -20
- package/dist/services/authentication/use-cases/claim-refresh-token.use-case.d.ts +0 -12
- package/dist/services/authentication/use-cases/claim-refresh-token.use-case.js +0 -40
- package/dist/services/authentication/use-cases/claim-refresh-token.use-case.mjs +0 -16
- package/dist/services/authentication/use-cases/create-refresh-token.use-case.d.ts +0 -11
- package/dist/services/authentication/use-cases/create-refresh-token.use-case.js +0 -43
- package/dist/services/authentication/use-cases/create-refresh-token.use-case.mjs +0 -19
- package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.d.ts +0 -11
- package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.js +0 -40
- package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.mjs +0 -16
- package/dist/services/authentication/use-cases/is-token-revoked.use-case.d.ts +0 -13
- package/dist/services/authentication/use-cases/is-token-revoked.use-case.js +0 -42
- package/dist/services/authentication/use-cases/is-token-revoked.use-case.mjs +0 -18
- package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.d.ts +0 -18
- package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.js +0 -49
- package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.mjs +0 -25
- package/dist/services/authentication/use-cases/issue-session.use-case.d.ts +0 -13
- package/dist/services/authentication/use-cases/issue-session.use-case.js +0 -48
- package/dist/services/authentication/use-cases/issue-session.use-case.mjs +0 -24
- package/dist/services/authentication/use-cases/login.use-case.d.ts +0 -20
- package/dist/services/authentication/use-cases/login.use-case.js +0 -54
- package/dist/services/authentication/use-cases/login.use-case.mjs +0 -30
- package/dist/services/authentication/use-cases/logout.use-case.d.ts +0 -14
- package/dist/services/authentication/use-cases/logout.use-case.js +0 -48
- package/dist/services/authentication/use-cases/logout.use-case.mjs +0 -24
- package/dist/services/authentication/use-cases/refresh.use-case.d.ts +0 -23
- package/dist/services/authentication/use-cases/refresh.use-case.js +0 -84
- package/dist/services/authentication/use-cases/refresh.use-case.mjs +0 -60
- package/dist/services/authentication/use-cases/reset-password.use-case.d.ts +0 -15
- package/dist/services/authentication/use-cases/reset-password.use-case.js +0 -61
- package/dist/services/authentication/use-cases/reset-password.use-case.mjs +0 -37
- package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.d.ts +0 -11
- package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.js +0 -40
- package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.mjs +0 -16
- package/dist/services/authentication/use-cases/revoke-token.use-case.d.ts +0 -12
- package/dist/services/authentication/use-cases/revoke-token.use-case.js +0 -52
- package/dist/services/authentication/use-cases/revoke-token.use-case.mjs +0 -28
- package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.d.ts +0 -13
- package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.js +0 -40
- package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.mjs +0 -16
- package/dist/services/users/entities/index.d.ts +0 -1
- package/dist/services/users/entities/index.js +0 -22
- package/dist/services/users/entities/index.mjs +0 -1
- package/dist/services/users/entities/user-acquisition.d.ts +0 -12
- package/dist/services/users/entities/user-acquisition.js +0 -42
- package/dist/services/users/entities/user-acquisition.mjs +0 -18
- package/dist/services/users/entities/user-country.d.ts +0 -11
- package/dist/services/users/entities/user-country.js +0 -44
- package/dist/services/users/entities/user-country.mjs +0 -20
- package/dist/services/users/entities/user-currency.d.ts +0 -13
- package/dist/services/users/entities/user-currency.js +0 -44
- package/dist/services/users/entities/user-currency.mjs +0 -20
- package/dist/services/users/entities/user-default-model.d.ts +0 -11
- package/dist/services/users/entities/user-default-model.js +0 -42
- package/dist/services/users/entities/user-default-model.mjs +0 -18
- package/dist/services/users/entities/user-email.value-object.d.ts +0 -6
- package/dist/services/users/entities/user-email.value-object.js +0 -43
- package/dist/services/users/entities/user-email.value-object.mjs +0 -19
- package/dist/services/users/entities/user-language.d.ts +0 -11
- package/dist/services/users/entities/user-language.js +0 -44
- package/dist/services/users/entities/user-language.mjs +0 -20
- package/dist/services/users/entities/user-marketing.d.ts +0 -9
- package/dist/services/users/entities/user-marketing.js +0 -40
- package/dist/services/users/entities/user-marketing.mjs +0 -16
- package/dist/services/users/entities/user-notification-preferences.d.ts +0 -11
- package/dist/services/users/entities/user-notification-preferences.js +0 -41
- package/dist/services/users/entities/user-notification-preferences.mjs +0 -17
- package/dist/services/users/entities/user-password.value-object.d.ts +0 -8
- package/dist/services/users/entities/user-password.value-object.js +0 -69
- package/dist/services/users/entities/user-password.value-object.mjs +0 -35
- package/dist/services/users/entities/user-permissions.d.ts +0 -21
- package/dist/services/users/entities/user-permissions.js +0 -59
- package/dist/services/users/entities/user-permissions.mjs +0 -35
- package/dist/services/users/entities/user-preferences.d.ts +0 -28
- package/dist/services/users/entities/user-preferences.js +0 -74
- package/dist/services/users/entities/user-preferences.mjs +0 -50
- package/dist/services/users/entities/user-report-preferences.d.ts +0 -16
- package/dist/services/users/entities/user-report-preferences.js +0 -56
- package/dist/services/users/entities/user-report-preferences.mjs +0 -32
- package/dist/services/users/entities/user-report-schedule.d.ts +0 -11
- package/dist/services/users/entities/user-report-schedule.js +0 -41
- package/dist/services/users/entities/user-report-schedule.mjs +0 -17
- package/dist/services/users/entities/user-timezone.d.ts +0 -11
- package/dist/services/users/entities/user-timezone.js +0 -44
- package/dist/services/users/entities/user-timezone.mjs +0 -20
- package/dist/services/users/entities/user.entity.d.ts +0 -42
- package/dist/services/users/entities/user.entity.js +0 -117
- package/dist/services/users/entities/user.entity.mjs +0 -92
- package/dist/services/users/index.d.ts +0 -3
- package/dist/services/users/index.js +0 -26
- package/dist/services/users/index.mjs +0 -3
- package/dist/services/users/module.d.ts +0 -12
- package/dist/services/users/module.js +0 -67
- package/dist/services/users/module.mjs +0 -38
- package/dist/services/users/repositories/index.d.ts +0 -1
- package/dist/services/users/repositories/index.js +0 -22
- package/dist/services/users/repositories/index.mjs +0 -1
- package/dist/services/users/repositories/user.repository.d.ts +0 -18
- package/dist/services/users/repositories/user.repository.js +0 -88
- package/dist/services/users/repositories/user.repository.mjs +0 -64
- package/dist/services/users/use-cases/change-password.use-case.d.ts +0 -15
- package/dist/services/users/use-cases/change-password.use-case.js +0 -52
- package/dist/services/users/use-cases/change-password.use-case.mjs +0 -28
- package/dist/services/users/use-cases/create-user.use-case.d.ts +0 -12
- package/dist/services/users/use-cases/create-user.use-case.js +0 -49
- package/dist/services/users/use-cases/create-user.use-case.mjs +0 -25
- package/dist/services/users/use-cases/delete-user.use-case.d.ts +0 -16
- package/dist/services/users/use-cases/delete-user.use-case.js +0 -48
- package/dist/services/users/use-cases/delete-user.use-case.mjs +0 -24
- package/dist/services/users/use-cases/get-user-by-id.use-case.d.ts +0 -12
- package/dist/services/users/use-cases/get-user-by-id.use-case.js +0 -43
- package/dist/services/users/use-cases/get-user-by-id.use-case.mjs +0 -19
- package/dist/services/users/use-cases/list-users-by-props.use-case.d.ts +0 -17
- package/dist/services/users/use-cases/list-users-by-props.use-case.js +0 -42
- package/dist/services/users/use-cases/list-users-by-props.use-case.mjs +0 -18
- package/dist/services/users/use-cases/update-user.use-case.d.ts +0 -13
- package/dist/services/users/use-cases/update-user.use-case.js +0 -53
- package/dist/services/users/use-cases/update-user.use-case.mjs +0 -29
- package/dist/services/users/utils/default-model.d.ts +0 -6
- package/dist/services/users/utils/default-model.js +0 -38
- package/dist/services/users/utils/default-model.mjs +0 -14
- package/examples/authentication/login.ts +0 -22
- package/examples/users/create-user.ts +0 -25
- package/examples/users/delete-user.ts +0 -42
- package/examples/users/get-user-by-id.ts +0 -21
- package/examples/users/list-users.ts +0 -22
- package/examples/users/update-user.ts +0 -25
|
@@ -1,36 +1,39 @@
|
|
|
1
|
+
import { localeOf } from "nanosaas/common";
|
|
2
|
+
import { buildUserContext } from "nanosaas/users";
|
|
1
3
|
function buildRuntimeContext(params) {
|
|
2
|
-
const {
|
|
3
|
-
const currentCountryCode = currentSession?.location?.country;
|
|
4
|
-
const currentCurrencyCode = currentSession?.currencyCode;
|
|
4
|
+
const { actor, requestContext, chat } = params;
|
|
5
5
|
const now = /* @__PURE__ */ new Date();
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const profile = actor?.profile;
|
|
7
|
+
const context = buildUserContext(profile?.preferences, requestContext, now);
|
|
8
|
+
const here = localeOf(requestContext);
|
|
8
9
|
return {
|
|
9
|
-
now_utc: now.
|
|
10
|
-
now_local:
|
|
11
|
-
timezone,
|
|
10
|
+
now_utc: context.now.utcNow,
|
|
11
|
+
now_local: context.now.localTime,
|
|
12
|
+
timezone: context.now.timezone,
|
|
12
13
|
day_of_week: now.toLocaleDateString("en-US", { weekday: "long" }),
|
|
13
14
|
...chat?.state?.language ? { detected_language: chat.state.language } : {},
|
|
14
|
-
...
|
|
15
|
+
...actor ? {
|
|
15
16
|
user_details: {
|
|
16
|
-
first_name:
|
|
17
|
-
last_name:
|
|
18
|
-
preferred_language:
|
|
19
|
-
residence_country_code:
|
|
20
|
-
|
|
17
|
+
first_name: profile?.firstName,
|
|
18
|
+
last_name: profile?.lastName,
|
|
19
|
+
preferred_language: context.home.language,
|
|
20
|
+
residence_country_code: context.home.country,
|
|
21
|
+
residence_timezone: context.home.timezone,
|
|
22
|
+
preferred_currency_code: context.home.currency
|
|
21
23
|
}
|
|
22
24
|
} : {},
|
|
23
|
-
...
|
|
25
|
+
...requestContext ? {
|
|
24
26
|
session_details: {
|
|
25
27
|
current_location: {
|
|
26
|
-
country_code:
|
|
27
|
-
currency_code:
|
|
28
|
-
timezone_offset:
|
|
28
|
+
country_code: context.now.country,
|
|
29
|
+
currency_code: here.currency?.isoCode,
|
|
30
|
+
timezone_offset: requestContext.timezoneOffset,
|
|
31
|
+
away_from_home: context.away
|
|
29
32
|
},
|
|
30
33
|
client_info: {
|
|
31
|
-
platform:
|
|
32
|
-
brand:
|
|
33
|
-
model:
|
|
34
|
+
platform: requestContext.client.device?.os,
|
|
35
|
+
brand: requestContext.client.device?.brand,
|
|
36
|
+
model: requestContext.client.device?.model
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
} : {}
|
package/dist/skills/skill.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LLMMessage, LLMToolDefinition, ThinkingEffort } from '../clients/llm/llm-types.js';
|
|
2
|
-
import {
|
|
2
|
+
import { ActorLike, RequestContext } from 'nanosaas/common';
|
|
3
3
|
import type { Chat } from '../services/chats/entities/chat.entity.js';
|
|
4
4
|
import { SkillMode } from './call-modes';
|
|
5
5
|
export { SkillMode, DEFAULT_SKILL_MODE } from './call-modes';
|
|
@@ -23,8 +23,8 @@ export interface SkillRunOptions<TInput = Record<string, any>> {
|
|
|
23
23
|
sessionId: string;
|
|
24
24
|
answerId: string;
|
|
25
25
|
userMessage?: string;
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
actor?: ActorLike;
|
|
27
|
+
requestContext?: RequestContext;
|
|
28
28
|
contextInjection?: Record<string, any>;
|
|
29
29
|
input?: TInput;
|
|
30
30
|
chat?: Chat;
|
package/dist/skills/skill.js
CHANGED
|
@@ -25,7 +25,7 @@ __export(skill_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(skill_exports);
|
|
26
26
|
var import_helpers = require("../common/helpers/index.js");
|
|
27
27
|
var import_llm_client = require("../clients/llm/llm-client.js");
|
|
28
|
-
var
|
|
28
|
+
var import_common = require("nanosaas/common");
|
|
29
29
|
var import_runtime_context = require("./runtime-context");
|
|
30
30
|
var import_call_modes = require("./call-modes");
|
|
31
31
|
var import_call_modes2 = require("./call-modes");
|
|
@@ -52,14 +52,14 @@ class Skill {
|
|
|
52
52
|
this.mode = props.mode ?? import_call_modes.DEFAULT_SKILL_MODE;
|
|
53
53
|
}
|
|
54
54
|
async run(options) {
|
|
55
|
-
const { provider, modelName, sessionId, answerId, userMessage,
|
|
55
|
+
const { provider, modelName, sessionId, answerId, userMessage, actor, requestContext, contextInjection = {}, input = {}, chat, history = [], chatHistory = [], tools, mode = this.mode, thinking = this.thinking } = options;
|
|
56
56
|
const misplaced = RESERVED_CONTEXT_KEYS.filter((key) => key in contextInjection);
|
|
57
57
|
if (misplaced.length) throw new Error(`[SKILL:${this.name}] ${misplaced.join(", ")} must be passed as run options, not inside contextInjection`);
|
|
58
58
|
if (history.length && chatHistory.length) throw new Error(`[SKILL:${this.name}] history and chatHistory cannot be used together`);
|
|
59
59
|
try {
|
|
60
60
|
const llmClient = new import_llm_client.LLMClient();
|
|
61
61
|
const context = {
|
|
62
|
-
...(0, import_runtime_context.buildRuntimeContext)({
|
|
62
|
+
...(0, import_runtime_context.buildRuntimeContext)({ actor, requestContext, chat }),
|
|
63
63
|
...contextInjection
|
|
64
64
|
};
|
|
65
65
|
const inputPayload = {
|
|
@@ -76,7 +76,7 @@ class Skill {
|
|
|
76
76
|
sessionId,
|
|
77
77
|
answerId,
|
|
78
78
|
origin: this.name,
|
|
79
|
-
|
|
79
|
+
actor,
|
|
80
80
|
messages: call.messages,
|
|
81
81
|
tools: call.tools,
|
|
82
82
|
toolChoice: call.toolChoice,
|
|
@@ -86,7 +86,7 @@ class Skill {
|
|
|
86
86
|
const reading = (0, import_call_modes.readModeResponse)(mode, this.name, response, { expectActions: Boolean(tools?.length) });
|
|
87
87
|
if (reading.blocks > 1) {
|
|
88
88
|
const note = `The model sent ${reading.blocks} text blocks; block ${reading.chosen + 1} was used and the rest were discarded`;
|
|
89
|
-
new
|
|
89
|
+
new import_common.Logger().warn({ skill: this.name, model: response.model, blocks: reading.blocks, chosen: reading.chosen }, `[SKILL:${this.name}] ${note}`);
|
|
90
90
|
chat?.addTrace({ node: this.name, reasoning: note });
|
|
91
91
|
}
|
|
92
92
|
const parsed = this.parseJsonResponse(reading.text);
|
package/dist/skills/skill.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { extractJSON } from "../common/helpers/index.js";
|
|
2
2
|
import { LLMClient } from "../clients/llm/llm-client.js";
|
|
3
|
-
import { Logger } from "
|
|
3
|
+
import { Logger } from "nanosaas/common";
|
|
4
4
|
import { buildRuntimeContext } from "./runtime-context";
|
|
5
5
|
import { DEFAULT_SKILL_MODE, buildModeCall, readModeResponse } from "./call-modes";
|
|
6
6
|
import { SkillMode as SkillMode2, DEFAULT_SKILL_MODE as DEFAULT_SKILL_MODE2 } from "./call-modes";
|
|
@@ -27,14 +27,14 @@ class Skill {
|
|
|
27
27
|
this.mode = props.mode ?? DEFAULT_SKILL_MODE;
|
|
28
28
|
}
|
|
29
29
|
async run(options) {
|
|
30
|
-
const { provider, modelName, sessionId, answerId, userMessage,
|
|
30
|
+
const { provider, modelName, sessionId, answerId, userMessage, actor, requestContext, contextInjection = {}, input = {}, chat, history = [], chatHistory = [], tools, mode = this.mode, thinking = this.thinking } = options;
|
|
31
31
|
const misplaced = RESERVED_CONTEXT_KEYS.filter((key) => key in contextInjection);
|
|
32
32
|
if (misplaced.length) throw new Error(`[SKILL:${this.name}] ${misplaced.join(", ")} must be passed as run options, not inside contextInjection`);
|
|
33
33
|
if (history.length && chatHistory.length) throw new Error(`[SKILL:${this.name}] history and chatHistory cannot be used together`);
|
|
34
34
|
try {
|
|
35
35
|
const llmClient = new LLMClient();
|
|
36
36
|
const context = {
|
|
37
|
-
...buildRuntimeContext({
|
|
37
|
+
...buildRuntimeContext({ actor, requestContext, chat }),
|
|
38
38
|
...contextInjection
|
|
39
39
|
};
|
|
40
40
|
const inputPayload = {
|
|
@@ -51,7 +51,7 @@ class Skill {
|
|
|
51
51
|
sessionId,
|
|
52
52
|
answerId,
|
|
53
53
|
origin: this.name,
|
|
54
|
-
|
|
54
|
+
actor,
|
|
55
55
|
messages: call.messages,
|
|
56
56
|
tools: call.tools,
|
|
57
57
|
toolChoice: call.toolChoice,
|
|
@@ -46,7 +46,7 @@ const callAiTool = new import_tool.Tool({
|
|
|
46
46
|
required: ["instructions", "input_data"]
|
|
47
47
|
},
|
|
48
48
|
handler: async (params) => {
|
|
49
|
-
const { payload,
|
|
49
|
+
const { payload, actor, sessionId, answerId } = params;
|
|
50
50
|
const { instructions, input_data } = payload;
|
|
51
51
|
if (!instructions) throw new Error("[call_ai_tool] Param instructions is required");
|
|
52
52
|
if (!input_data) throw new Error("[call_ai_tool] Param input_data is required");
|
|
@@ -57,7 +57,7 @@ const callAiTool = new import_tool.Tool({
|
|
|
57
57
|
contextInjection: {
|
|
58
58
|
systemPrompt: instructions
|
|
59
59
|
},
|
|
60
|
-
|
|
60
|
+
actor
|
|
61
61
|
});
|
|
62
62
|
return { data: result };
|
|
63
63
|
}
|
|
@@ -23,7 +23,7 @@ const callAiTool = new Tool({
|
|
|
23
23
|
required: ["instructions", "input_data"]
|
|
24
24
|
},
|
|
25
25
|
handler: async (params) => {
|
|
26
|
-
const { payload,
|
|
26
|
+
const { payload, actor, sessionId, answerId } = params;
|
|
27
27
|
const { instructions, input_data } = payload;
|
|
28
28
|
if (!instructions) throw new Error("[call_ai_tool] Param instructions is required");
|
|
29
29
|
if (!input_data) throw new Error("[call_ai_tool] Param input_data is required");
|
|
@@ -34,7 +34,7 @@ const callAiTool = new Tool({
|
|
|
34
34
|
contextInjection: {
|
|
35
35
|
systemPrompt: instructions
|
|
36
36
|
},
|
|
37
|
-
|
|
37
|
+
actor
|
|
38
38
|
});
|
|
39
39
|
return { data: result };
|
|
40
40
|
}
|
|
@@ -41,7 +41,7 @@ const webSearchTool = new import_tool.Tool({
|
|
|
41
41
|
},
|
|
42
42
|
handler: async (params) => {
|
|
43
43
|
if (!params) throw new Error("[web_search] params is required");
|
|
44
|
-
const {
|
|
44
|
+
const { actor, sessionId, answerId, ...rest } = params;
|
|
45
45
|
const serperClient = new import_serper_client.SerperClient();
|
|
46
46
|
const results = await serperClient.searchOnGoogle(rest);
|
|
47
47
|
return { data: results };
|
|
@@ -20,7 +20,7 @@ const webSearchTool = new Tool({
|
|
|
20
20
|
},
|
|
21
21
|
handler: async (params) => {
|
|
22
22
|
if (!params) throw new Error("[web_search] params is required");
|
|
23
|
-
const {
|
|
23
|
+
const { actor, sessionId, answerId, ...rest } = params;
|
|
24
24
|
const serperClient = new SerperClient();
|
|
25
25
|
const results = await serperClient.searchOnGoogle(rest);
|
|
26
26
|
return { data: results };
|
package/dist/tools/tool.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
2
|
import type { Tool as McpTool } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
-
import {
|
|
3
|
+
import { ActorLike } from 'nanosaas/common';
|
|
4
4
|
interface InputSchema {
|
|
5
5
|
type: 'object';
|
|
6
6
|
properties: Record<string, {
|
|
@@ -20,7 +20,7 @@ interface Output {
|
|
|
20
20
|
data: any;
|
|
21
21
|
}
|
|
22
22
|
export interface BaseParams {
|
|
23
|
-
|
|
23
|
+
actor: ActorLike;
|
|
24
24
|
sessionId: string;
|
|
25
25
|
answerId: string;
|
|
26
26
|
}
|
package/dist/tools/tool.js
CHANGED
|
@@ -124,7 +124,7 @@ class Tool {
|
|
|
124
124
|
server: opts.namespace,
|
|
125
125
|
notice: opts.internal ? void 0 : externalToolNotice(opts.namespace),
|
|
126
126
|
handler: async (params = {}) => {
|
|
127
|
-
const {
|
|
127
|
+
const { actor, sessionId, answerId, ...args } = params;
|
|
128
128
|
const timeoutMs = (0, import_number_setting.numberSetting)("MCP_TOOL_TIMEOUT_MS", DEFAULT_MCP_TOOL_TIMEOUT_MS);
|
|
129
129
|
let result;
|
|
130
130
|
try {
|
package/dist/tools/tool.mjs
CHANGED
|
@@ -100,7 +100,7 @@ class Tool {
|
|
|
100
100
|
server: opts.namespace,
|
|
101
101
|
notice: opts.internal ? void 0 : externalToolNotice(opts.namespace),
|
|
102
102
|
handler: async (params = {}) => {
|
|
103
|
-
const {
|
|
103
|
+
const { actor, sessionId, answerId, ...args } = params;
|
|
104
104
|
const timeoutMs = numberSetting("MCP_TOOL_TIMEOUT_MS", DEFAULT_MCP_TOOL_TIMEOUT_MS);
|
|
105
105
|
let result;
|
|
106
106
|
try {
|
package/docs/README.md
CHANGED
|
@@ -39,7 +39,7 @@ Start with the [README](../README.md) for what `openloops` is and how to run it.
|
|
|
39
39
|
|
|
40
40
|
| Page | What it covers |
|
|
41
41
|
| --- | --- |
|
|
42
|
-
| [User management](users.md) | `
|
|
42
|
+
| [User management](users.md) | `Actor`, creating, listing, updating and deleting users. |
|
|
43
43
|
| [Authentication](authentication.md) | Login and tokens. |
|
|
44
44
|
| [LLM usage tracking](usage.md) | Tokens and cost per chat or answer, per-user statistics, and how to limit the spend of a user. |
|
|
45
45
|
|
package/docs/agent.md
CHANGED
|
@@ -54,8 +54,8 @@ const result = await agent.run({
|
|
|
54
54
|
modelProvider: 'anthropic',
|
|
55
55
|
modelName: 'claude-haiku-5-5',
|
|
56
56
|
},
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
actor,
|
|
58
|
+
requestContext,
|
|
59
59
|
})
|
|
60
60
|
```
|
|
61
61
|
|
|
@@ -72,7 +72,7 @@ Omit `chatId` to start a brand-new chat. Pass an existing `chatId` to continue a
|
|
|
72
72
|
| `notifyOnCompletion` | Exposed as `agent.notifyOnCompletion` so a post execution hook can notify the user. |
|
|
73
73
|
| `isPrivateSession` | Stored in the chat settings for your application to use. |
|
|
74
74
|
|
|
75
|
-
`
|
|
75
|
+
`requestContext` is optional. It carries device, location and locale, which skills use to answer in the right time zone and language.
|
|
76
76
|
|
|
77
77
|
`mcpTokens` is optional. It gives the token of the user to each [internal MCP server](mcp-servers.md#internal-mcp-servers), by name. It is never saved. In an [autonomous run](#autonomous-mode) with no token for a server, the `autonomousToken` of that server is used, see [automations](automations.md#internal-mcp-servers-in-an-automation).
|
|
78
78
|
|
|
@@ -83,7 +83,7 @@ Pass `usageLimit` in the run to cap what a user can spend, in US dollars, in a p
|
|
|
83
83
|
```typescript
|
|
84
84
|
const result = await agent.run({
|
|
85
85
|
input: { message: 'hi' },
|
|
86
|
-
|
|
86
|
+
actor,
|
|
87
87
|
usageLimit: { maxCostUsd: 1, period: 'month' },
|
|
88
88
|
})
|
|
89
89
|
```
|
|
@@ -113,7 +113,7 @@ const limits = {
|
|
|
113
113
|
|
|
114
114
|
const result = await agent.run({
|
|
115
115
|
input,
|
|
116
|
-
|
|
116
|
+
actor,
|
|
117
117
|
usageLimit: limits[userPays ? 'paid' : 'free'],
|
|
118
118
|
})
|
|
119
119
|
|
|
@@ -132,11 +132,11 @@ An autonomous run is one where nobody is in the chat while the agent works, for
|
|
|
132
132
|
await agent.run({
|
|
133
133
|
input: { message: 'Every morning, summarize my open tickets' },
|
|
134
134
|
options: { executionMode: 'autonomous' },
|
|
135
|
-
|
|
135
|
+
actor,
|
|
136
136
|
})
|
|
137
137
|
```
|
|
138
138
|
|
|
139
|
-
`
|
|
139
|
+
`actor` is still required: it owns the chat and the MCP servers. What changes while a run is autonomous:
|
|
140
140
|
|
|
141
141
|
- The model is told that nobody is present, so it plans the whole task and writes a complete final answer.
|
|
142
142
|
- Questions the model sends with `ask_user` are answered by an automatic evaluator, a skill that only knows the context of the task. The model receives the answer marked as automatic and is told to use its judgment. The evaluator never grants permissions and says it cannot decide when the context does not settle the question. At most 3 questions per task are answered this way.
|
|
@@ -157,7 +157,7 @@ To run an agent on a schedule, see [automations](automations.md).
|
|
|
157
157
|
`agent.run` does not throw for failures inside the run. It returns:
|
|
158
158
|
|
|
159
159
|
```typescript
|
|
160
|
-
const { data, error } = await agent.run({ input,
|
|
160
|
+
const { data, error } = await agent.run({ input, actor })
|
|
161
161
|
|
|
162
162
|
data?.lastAnswer
|
|
163
163
|
data?.messages
|
|
@@ -263,7 +263,7 @@ const stop = agent.onActivity(activity => {
|
|
|
263
263
|
stream.write(`event: activity\ndata: ${JSON.stringify({ activity })}\n\n`)
|
|
264
264
|
})
|
|
265
265
|
|
|
266
|
-
await agent.run({ input: { chatId, message },
|
|
266
|
+
await agent.run({ input: { chatId, message }, actor })
|
|
267
267
|
|
|
268
268
|
stop()
|
|
269
269
|
```
|
|
@@ -279,7 +279,7 @@ The listener receives every change of the activity of the run while it is in pro
|
|
|
279
279
|
## Stopping a running turn
|
|
280
280
|
|
|
281
281
|
```typescript
|
|
282
|
-
await Agent.interruptExecution(chatId,
|
|
282
|
+
await Agent.interruptExecution(chatId, actor)
|
|
283
283
|
```
|
|
284
284
|
|
|
285
285
|
Call it from a separate request while `agent.run()` is still executing, for example when the user presses stop. The running loop checks for the request before every node and stops cleanly. The next message in that chat starts again from the initial node of the loop.
|
package/docs/authentication.md
CHANGED
|
@@ -1,136 +1,37 @@
|
|
|
1
1
|
# Authentication
|
|
2
2
|
|
|
3
|
-
`openloops`
|
|
3
|
+
`openloops` does not log users in. Users, sessions, password reset and the tokens come from [`nanosaas`](https://www.npmjs.com/package/nanosaas), the package that `openloops` has as a peer dependency. Use its `authentication` module for `register`, `login`, `refreshSession`, `logout`, `recoverPassword` and `resetPassword`, and read its documentation for the rate limit, the sessions and the key rotation.
|
|
4
|
+
|
|
5
|
+
What `openloops` asks from your backend is an `actor` on every call. It reads the access token and builds it, without reading the database:
|
|
4
6
|
|
|
5
7
|
```typescript
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
```
|
|
8
|
+
import { verifySessionToken } from 'nanosaas/authentication'
|
|
9
|
+
import { Actor } from 'nanosaas/common'
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
const claims = verifySessionToken(token)
|
|
12
|
+
const actor = Actor.fromClaims({ userId: claims.sub, sessionId: claims.sid })
|
|
13
|
+
```
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
`verifySessionToken` throws a `TokenError` whose `reason` is `invalid` or `expired`. It refuses a token of another audience, so a reset token or an event token cannot be used as a session. See [users](users.md) for what the agent does with the `actor`.
|
|
13
16
|
|
|
14
17
|
## The tokens
|
|
15
18
|
|
|
16
|
-
Every token is a JWT signed with `HS256` and `JWT_SECRET
|
|
19
|
+
Every token is a JWT signed with `HS256` and `JWT_SECRET` (`JWT_SECRET_V<n>` to rotate it), and carries the same claims. The issuer is the one you set with `configure({ appName })` (or `tokenIssuer`), so every product that uses the same name accepts the same tokens.
|
|
17
20
|
|
|
18
21
|
| Claim | Value |
|
|
19
22
|
| --- | --- |
|
|
20
|
-
| `iss` |
|
|
23
|
+
| `iss` | The issuer of your solution. A token without it, or with another one, is refused. |
|
|
21
24
|
| `aud` | What the token is for: `session`, `password-reset` or `automation-event`. A token is only valid for its own audience. |
|
|
22
25
|
| `sub` | The id of the user, or the id of the automation for an event token. |
|
|
23
26
|
| `jti` | A unique id, only in the tokens that can be revoked one by one: reset and event tokens. |
|
|
24
27
|
| `exp` | When it stops working. |
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
| --- | --- | --- | --- |
|
|
28
|
-
| Access of a session | `session` | 1 hour | `email`, `firstName`, `lastName`, `sid` (the id of the session) |
|
|
29
|
-
| Reset of the password | `password-reset` | 15 minutes | `jti` |
|
|
30
|
-
| Event of an automation | `automation-event` | The one you choose, or none | `jti`, `v` |
|
|
31
|
-
|
|
32
|
-
The refresh token is not a JWT: it is a random string, and only its hash is stored.
|
|
33
|
-
|
|
34
|
-
## Logging in
|
|
35
|
-
|
|
36
|
-
```typescript
|
|
37
|
-
const result = await login({
|
|
38
|
-
payload: {
|
|
39
|
-
emailOrUsername: 'jose@endeavourai.co',
|
|
40
|
-
password: 'a-real-password',
|
|
41
|
-
},
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
result.accessToken
|
|
45
|
-
result.refreshToken
|
|
46
|
-
result.expiresIn
|
|
47
|
-
result.refreshExpiresAt
|
|
48
|
-
result.user
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
- `accessToken` lasts 1 hour. `refreshToken` lasts 30 days for a user and 7 days for an admin, and a session cannot be extended beyond 90 days (7 for an admin), no matter how often it is refreshed.
|
|
52
|
-
- `user` is the user record without the password.
|
|
53
|
-
- A missing field fails with 400. An unknown user and a wrong password fail with the same 401, so the answer does not tell which accounts exist.
|
|
29
|
+
The access token of a session carries no personal data. If your client needs the name or the email, ask your backend for the profile of the user.
|
|
54
30
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
```typescript
|
|
58
|
-
const next = await refreshSession({ refreshToken })
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
- It gives a new access token and a new refresh token, and the old refresh token cannot be used again. All of them belong to one session.
|
|
62
|
-
- A refresh token that was used is accepted again for 10 seconds, to survive a retry of the client. Later than that, it is taken as stolen: the whole session is closed and the next refresh fails with 401.
|
|
63
|
-
- It fails with 401 for an unknown, expired or revoked token, and when the user no longer exists.
|
|
64
|
-
- Two refreshes at the same time with the same token do not create two sessions.
|
|
65
|
-
|
|
66
|
-
```typescript
|
|
67
|
-
await logout({ refreshToken })
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
Closes the session of that refresh token. An unknown or missing token is ignored.
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
await revokeUserSessions({ userId, now: new Date(), exceptFamilyId })
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
Closes every session of the user, except the one you name. `changePassword` and `resetPassword` do it for you.
|
|
77
|
-
|
|
78
|
-
## From a token to a `CurrentUser`
|
|
79
|
-
|
|
80
|
-
Your backend reads the access token, and builds the `CurrentUser` that every other call needs:
|
|
81
|
-
|
|
82
|
-
```typescript
|
|
83
|
-
import { verifySessionToken } from 'openloops/authentication'
|
|
84
|
-
import { CurrentUser } from 'openloops/base'
|
|
85
|
-
|
|
86
|
-
const claims = verifySessionToken(token)
|
|
87
|
-
const currentUser = await CurrentUser.asyncFromDB(claims.userId)
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
`verifySessionToken` throws a `TokenError` whose `reason` is `invalid` or `expired`. It refuses a token of another audience, so a reset token or an event token cannot be used as a session. See [users](users.md).
|
|
91
|
-
|
|
92
|
-
## Resetting a password
|
|
93
|
-
|
|
94
|
-
`openloops` does not send emails. It issues the token, and your backend sends the link:
|
|
95
|
-
|
|
96
|
-
```typescript
|
|
97
|
-
const issued = await issuePasswordResetToken({ payload: { emailOrUsername } })
|
|
98
|
-
|
|
99
|
-
if (issued) await sendEmail(issued.user.email, `https://example.com/reset?token=${issued.token}`)
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
- It answers `null` when the user does not exist. Answer the same to the client in both cases, so nobody can learn which accounts exist.
|
|
103
|
-
- The token lasts 15 minutes and works once.
|
|
104
|
-
|
|
105
|
-
```typescript
|
|
106
|
-
await resetPassword({ token, password })
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
- It fails with 401 for a token that is invalid, expired, already used, or that is not a reset token, and with 400 if there is no password.
|
|
110
|
-
- It changes the password and closes every session of the user.
|
|
111
|
-
|
|
112
|
-
```typescript
|
|
113
|
-
await changePassword({ id, password, sessionId, currentUser })
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
For a user that changes their own password while logged in. It closes the other sessions and keeps the one in `sessionId` (the `sessionId` that `verifySessionToken` gives). `updateUser` refuses a `password`: this is the only way to change it.
|
|
31
|
+
The tokens of [event automations](automations.md#the-token) are issued and revoked by `openloops` with the functions of `nanosaas/authentication`, with the audience `automation-event`.
|
|
117
32
|
|
|
118
33
|
## Revoked tokens
|
|
119
34
|
|
|
120
|
-
A signed token cannot be taken back, so
|
|
121
|
-
|
|
122
|
-
```typescript
|
|
123
|
-
const isFirstTime = await revokeToken({ payload: { jti, audience: 'automation-event', subject: automationId, expiresAt } })
|
|
124
|
-
|
|
125
|
-
const data = await isTokenRevoked({ jti })
|
|
126
|
-
|
|
127
|
-
data.revoked
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
- Revoking the same `jti` twice does nothing and answers `false`. `expiresAt` is optional: when it is set, the entry is deleted by itself on that date, which is when the token would have stopped working anyway.
|
|
131
|
-
- Reset tokens use it so they work once, and event tokens use it through `revokeAutomationEventToken`.
|
|
132
|
-
- The access token of a session has no `jti`: to cut a session, close it with `logout` or `revokeUserSessions`. The access token still works until it expires, at most one hour.
|
|
133
|
-
|
|
134
|
-
## Collections
|
|
35
|
+
A signed token cannot be taken back, so a list keeps the ids (`jti`) of the tokens that must stop working, in the collection `revoked_tokens` of `nanosaas`. Event tokens use it through `revokeAutomationEventToken`, and reset tokens use it so they work once. The access token of a session has no `jti`: to cut a session, close it with `logout` or `revokeUserSessions`.
|
|
135
36
|
|
|
136
|
-
`refresh_tokens` and `revoked_tokens` are
|
|
37
|
+
The indexes of `refresh_tokens` and `revoked_tokens` are `AUTH_INDEXES` of `nanosaas/authentication`. Apply them with the indexes of `openloops` (see [configuration](configuration.md#indexes)).
|
package/docs/authorization.md
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
# Authorization
|
|
2
2
|
|
|
3
|
-
> **Breaking change.** Since this version every call that creates, reads or writes a record needs the `
|
|
3
|
+
> **Breaking change.** Since this version every call that creates, reads or writes a record needs the `actor`, or a `scope` you build yourself. The calls that worked without one, or that created a record for the user in the payload, now fail with 401. Read [what changes when you create records](#creating-records) and the [migration steps](#migrating-from-05).
|
|
4
4
|
|
|
5
5
|
Every use case that reads or writes a record of a user checks who owns it. The check is not in a controller, it is in the repository, inside the same query that reads or writes the record, so it does not cost an extra read and cannot be forgotten.
|
|
6
6
|
|
|
7
7
|
## The scope
|
|
8
8
|
|
|
9
|
-
A `Scope` tells the repository on whose behalf it works. Use cases build one from the `
|
|
9
|
+
A `Scope` tells the repository on whose behalf it works. Use cases build one from the `actor` you pass:
|
|
10
10
|
|
|
11
11
|
| Scope | Used for | Reaches |
|
|
12
12
|
| --- | --- | --- |
|
|
13
|
-
| `Scope.canView(
|
|
14
|
-
| `Scope.canEdit(
|
|
15
|
-
| `Scope.canManage(
|
|
16
|
-
| `Scope.asAdmin(
|
|
13
|
+
| `Scope.canView(actor)` | Reading. | The records of the user. |
|
|
14
|
+
| `Scope.canEdit(actor)` | Creating and updating. | The records of the user. |
|
|
15
|
+
| `Scope.canManage(actor)` | Deleting, issuing and revoking tokens. | The records of the user. |
|
|
16
|
+
| `Scope.asAdmin(actor)` | Actions of an administrator. | Every record. It fails with 403 if the user is not an admin. |
|
|
17
17
|
| `Scope.system('reason')` | Workers, webhooks and flows without a user. | Every record. The reason is required. |
|
|
18
18
|
|
|
19
|
-
An admin does not get more access by being an admin. A use case called with an admin as `
|
|
19
|
+
An admin does not get more access by being an admin. A use case called with an admin as `actor` still works on the records of that admin. To work on any record, build the scope yourself and pass it:
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
|
-
import { Scope } from '
|
|
22
|
+
import { Scope } from 'nanosaas/db'
|
|
23
23
|
|
|
24
|
-
await deleteChat({ id,
|
|
24
|
+
await deleteChat({ id, actor, scope: Scope.asAdmin(actor) })
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
Every use case accepts `scope`. Use it only from code you wrote, never from a value that comes from a request.
|
|
@@ -30,23 +30,23 @@ Every use case accepts `scope`. Use it only from code you wrote, never from a va
|
|
|
30
30
|
|
|
31
31
|
Every `create...` use case (`createChat`, `createMcpServer`, `createAutomation`, `createUser`, `createLLMCall`, `createAgentTask`, `createAgentAction`, `createAgentTraces`, `saveWorkspaceItem`) now takes the owner and the author from the scope, not from the payload:
|
|
32
32
|
|
|
33
|
-
- With a user scope, the new record belongs to the `
|
|
34
|
-
- To create a record for someone else, or without a user (a sign up, a webhook, a worker), pass a trusted scope: `Scope.system('reason')` or `Scope.asAdmin(
|
|
35
|
-
- Without `
|
|
33
|
+
- With a user scope, the new record belongs to the `actor`. `ownerId`, `createdBy`, `createdAt` and the other fields of control are set by the repository, and the ones you put in the payload are discarded. You cannot create a record for another user by sending his `ownerId`.
|
|
34
|
+
- To create a record for someone else, or without a user (a sign up, a webhook, a worker), pass a trusted scope: `Scope.system('reason')` or `Scope.asAdmin(actor)`. The payload is kept as you send it, and `ownerId` is the one you send. With `system` there is no `createdBy`, unless you send it.
|
|
35
|
+
- Without `actor` and without `scope` the call fails with 401. Before, `createChat` and the others created the record without an owner.
|
|
36
36
|
- The record that returns has its `_id`, `ownerId`, `createdAt` and `createdBy`.
|
|
37
37
|
|
|
38
38
|
```typescript
|
|
39
|
-
await createChat({ payload,
|
|
39
|
+
await createChat({ payload, actor })
|
|
40
40
|
|
|
41
41
|
await createUser({ payload, scope: Scope.system('sign up') })
|
|
42
42
|
|
|
43
|
-
await createAutomation({ payload: { ...payload, ownerId: otherUserId }, scope: Scope.asAdmin(
|
|
43
|
+
await createAutomation({ payload: { ...payload, ownerId: otherUserId }, scope: Scope.asAdmin(actor) })
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
## What changes in your endpoints
|
|
47
47
|
|
|
48
48
|
- A record that is not the user's is answered as if it did not exist. The functions that update or delete throw a 404 `HttpError` with the message `{{resource_not_found}}`, and the getters return `null` or throw the same 404. Nobody can learn that an id exists by getting a 403.
|
|
49
|
-
- A call without `
|
|
49
|
+
- A call without `actor` and without `scope` fails with 401, it does not read everything.
|
|
50
50
|
- You do not need to load the record to check `ownerId` before calling a function that takes an id.
|
|
51
51
|
|
|
52
52
|
## What the repository does with the fields of control
|
|
@@ -65,11 +65,11 @@ await createUser({ payload, scope: Scope.system('sign up') })
|
|
|
65
65
|
|
|
66
66
|
## Migrating from 0.5
|
|
67
67
|
|
|
68
|
-
- Pass `
|
|
68
|
+
- Pass `actor`, or a `scope`, to every function that reads or writes the records of a user: the ones that take an id (`getChatById`, `updateChat`, `deleteChat`, `getMcpServerById`, `updateMcpServer`, `deleteMcpServer`, `decideMcpServerTrust`, `verifyMcpServerConnection`, `getUserById`, `updateUser`, `deleteUser`, `updateAutomation`, `deleteAutomation`), the ones that create (see [creating records](#creating-records)), the ones that list and the usage reports (`getLLMUsageByChat`, `getLLMUsageByMessage` and `getLLMUsageStats`). Many of them accepted a call without a user before and did not check the owner. `getAutomationById`, `listAutomationRunsByAutomation`, `startAutomationRun` and `runner.runNow` did not read the user at all.
|
|
69
69
|
- You do not need to pass anything to `login`, `revokeToken`, `isTokenRevoked`, `previewAutomationRuns` and `receiveAutomationEvent`, which do not belong to a user, nor to the functions of the runner (`claimDueAutomations`, `claimQueuedAutomationRuns`, `finishAutomationRun`, `syncAutomationRun`, `syncAutomationRuns`, `attachAutomationRunChat` and `renewAutomationLease`), which use their own system scope.
|
|
70
|
-
- Pass `
|
|
70
|
+
- Pass `actor` to `getAutomationById`, `listAutomationRunsByAutomation`, `startAutomationRun` and `runner.runNow`. They did not need it before.
|
|
71
71
|
- Replace `sanitize: false` in `createUser` with a `scope`, as shown above.
|
|
72
|
-
- Where an admin used to act on the record of another user, pass `scope: Scope.asAdmin(
|
|
72
|
+
- Where an admin used to act on the record of another user, pass `scope: Scope.asAdmin(actor)`.
|
|
73
73
|
- `issueAutomationEventToken`, `revokeAutomationEventToken` and `rotateAutomationEventTokens` are for the owner. They used to accept an admin.
|
|
74
74
|
- Expect a 404 where you got a 403 for the records of other users, and remove the ownership checks you wrote before calling a function with an id.
|
|
75
75
|
- Hard delete is for `Scope.asAdmin` or `Scope.system` only.
|