@nocobase/app-plugin-agents 0.1.0-beta.8 → 1.0.0-beta.15
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 +304 -0
- package/README.md +94 -51
- package/dist/client/api/client.d.ts +25 -19
- package/dist/client/api/client.d.ts.map +1 -1
- package/dist/client/api/client.js +23 -24
- package/dist/client/api/client.js.map +1 -1
- package/dist/client/api/keys.d.ts +4 -1
- package/dist/client/api/keys.d.ts.map +1 -1
- package/dist/client/api/keys.js +4 -1
- package/dist/client/api/keys.js.map +1 -1
- package/dist/client/api/runners.d.ts +8 -4
- package/dist/client/api/runners.d.ts.map +1 -1
- package/dist/client/api/runners.js +9 -0
- package/dist/client/api/runners.js.map +1 -1
- package/dist/client/chat/ai-form.d.ts +13 -0
- package/dist/client/chat/ai-form.d.ts.map +1 -0
- package/dist/client/chat/ai-form.js +57 -0
- package/dist/client/chat/ai-form.js.map +1 -0
- package/dist/client/chat/api.d.ts +16 -14
- package/dist/client/chat/api.d.ts.map +1 -1
- package/dist/client/chat/api.js +85 -18
- package/dist/client/chat/api.js.map +1 -1
- package/dist/client/chat/client-id.d.ts +3 -0
- package/dist/client/chat/client-id.d.ts.map +1 -0
- package/dist/client/chat/client-id.js +17 -0
- package/dist/client/chat/client-id.js.map +1 -0
- package/dist/client/chat/consultation-identity.d.ts +7 -0
- package/dist/client/chat/consultation-identity.d.ts.map +1 -0
- package/dist/client/chat/consultation-identity.js +39 -0
- package/dist/client/chat/consultation-identity.js.map +1 -0
- package/dist/client/chat/context-model.d.ts +21 -3
- package/dist/client/chat/context-model.d.ts.map +1 -1
- package/dist/client/chat/context-model.js +33 -4
- package/dist/client/chat/context-model.js.map +1 -1
- package/dist/client/chat/controller.d.ts +83 -0
- package/dist/client/chat/controller.d.ts.map +1 -0
- package/dist/client/chat/controller.js +767 -0
- package/dist/client/chat/controller.js.map +1 -0
- package/dist/client/chat/extensions.d.ts +8 -3
- package/dist/client/chat/extensions.d.ts.map +1 -1
- package/dist/client/chat/extensions.js.map +1 -1
- package/dist/client/chat/feedback.d.ts +18 -0
- package/dist/client/chat/feedback.d.ts.map +1 -0
- package/dist/client/chat/feedback.js +38 -0
- package/dist/client/chat/feedback.js.map +1 -0
- package/dist/client/chat/form-registry.d.ts +95 -0
- package/dist/client/chat/form-registry.d.ts.map +1 -0
- package/dist/client/chat/form-registry.js +384 -0
- package/dist/client/chat/form-registry.js.map +1 -0
- package/dist/client/chat/keys.d.ts +1 -0
- package/dist/client/chat/keys.d.ts.map +1 -1
- package/dist/client/chat/keys.js +3 -1
- package/dist/client/chat/keys.js.map +1 -1
- package/dist/client/chat/message-model.d.ts +38 -44
- package/dist/client/chat/message-model.d.ts.map +1 -1
- package/dist/client/chat/message-model.js +138 -56
- package/dist/client/chat/message-model.js.map +1 -1
- package/dist/client/chat/provider.d.ts +12 -2
- package/dist/client/chat/provider.d.ts.map +1 -1
- package/dist/client/chat/provider.js +130 -4
- package/dist/client/chat/provider.js.map +1 -1
- package/dist/client/chat/submissions.d.ts +67 -0
- package/dist/client/chat/submissions.d.ts.map +1 -0
- package/dist/client/chat/submissions.js +241 -0
- package/dist/client/chat/submissions.js.map +1 -0
- package/dist/client/chat/tool-renderer.d.ts +39 -0
- package/dist/client/chat/tool-renderer.d.ts.map +1 -0
- package/dist/client/chat/tool-renderer.js +27 -0
- package/dist/client/chat/tool-renderer.js.map +1 -0
- package/dist/client/chat/use-chat-scroll.d.ts +4 -0
- package/dist/client/chat/use-chat-scroll.d.ts.map +1 -0
- package/dist/client/chat/use-chat-scroll.js +73 -0
- package/dist/client/chat/use-chat-scroll.js.map +1 -0
- package/dist/client/chat/use-chat.d.ts +13 -24
- package/dist/client/chat/use-chat.d.ts.map +1 -1
- package/dist/client/chat/use-chat.js +250 -235
- package/dist/client/chat/use-chat.js.map +1 -1
- package/dist/client/chat.d.ts +20 -8
- package/dist/client/chat.d.ts.map +1 -1
- package/dist/client/chat.js +16 -4
- package/dist/client/chat.js.map +1 -1
- package/dist/client/components/agent-picker.d.ts +6 -23
- package/dist/client/components/agent-picker.d.ts.map +1 -1
- package/dist/client/components/agent-picker.js +20 -39
- package/dist/client/components/agent-picker.js.map +1 -1
- package/dist/client/components/quota-status.d.ts +16 -0
- package/dist/client/components/quota-status.d.ts.map +1 -0
- package/dist/client/components/quota-status.js +39 -0
- package/dist/client/components/quota-status.js.map +1 -0
- package/dist/client/components/runners-refresh.d.ts.map +1 -1
- package/dist/client/components/runners-refresh.js +1 -0
- package/dist/client/components/runners-refresh.js.map +1 -1
- package/dist/client/components/variables/variable-dialogs.d.ts.map +1 -1
- package/dist/client/components/variables/variable-dialogs.js +7 -7
- package/dist/client/components/variables/variable-dialogs.js.map +1 -1
- package/dist/client/config.d.ts +2 -0
- package/dist/client/config.d.ts.map +1 -1
- package/dist/client/config.js +2 -0
- package/dist/client/config.js.map +1 -1
- package/dist/client/hooks/use-agent-picker-labels.d.ts.map +1 -1
- package/dist/client/hooks/use-agent-picker-labels.js +4 -12
- package/dist/client/hooks/use-agent-picker-labels.js.map +1 -1
- package/dist/client/hooks/use-quota-expiry.d.ts +7 -0
- package/dist/client/hooks/use-quota-expiry.d.ts.map +1 -0
- package/dist/client/hooks/use-quota-expiry.js +92 -0
- package/dist/client/hooks/use-quota-expiry.js.map +1 -0
- package/dist/client/hooks/use-realtime-topic.d.ts +1 -4
- package/dist/client/hooks/use-realtime-topic.d.ts.map +1 -1
- package/dist/client/hooks/use-realtime-topic.js +7 -11
- package/dist/client/hooks/use-realtime-topic.js.map +1 -1
- package/dist/client/kit.d.ts +14 -12
- package/dist/client/kit.d.ts.map +1 -1
- package/dist/client/kit.js +37 -14
- package/dist/client/kit.js.map +1 -1
- package/dist/client/lib/agents.d.ts +5 -18
- package/dist/client/lib/agents.d.ts.map +1 -1
- package/dist/client/lib/agents.js +18 -55
- package/dist/client/lib/agents.js.map +1 -1
- package/dist/client/lib/format.d.ts +3 -1
- package/dist/client/lib/format.d.ts.map +1 -1
- package/dist/client/lib/format.js +25 -0
- package/dist/client/lib/format.js.map +1 -1
- package/dist/client/lib/skill-settings-context.d.ts +9 -0
- package/dist/client/lib/skill-settings-context.d.ts.map +1 -0
- package/dist/client/lib/skill-settings-context.js +4 -0
- package/dist/client/lib/skill-settings-context.js.map +1 -0
- package/dist/client/lib/skill-settings.d.ts +12 -0
- package/dist/client/lib/skill-settings.d.ts.map +1 -0
- package/dist/client/lib/skill-settings.js +37 -0
- package/dist/client/lib/skill-settings.js.map +1 -0
- package/dist/client/locales/chat.en-US.d.ts +8 -27
- package/dist/client/locales/chat.en-US.d.ts.map +1 -1
- package/dist/client/locales/chat.en-US.js +12 -30
- package/dist/client/locales/chat.en-US.js.map +1 -1
- package/dist/client/locales/chat.zh-CN.d.ts.map +1 -1
- package/dist/client/locales/chat.zh-CN.js +9 -27
- package/dist/client/locales/chat.zh-CN.js.map +1 -1
- package/dist/client/locales/en-US.d.ts +87 -217
- package/dist/client/locales/en-US.d.ts.map +1 -1
- package/dist/client/locales/en-US.js +92 -218
- package/dist/client/locales/en-US.js.map +1 -1
- package/dist/client/locales/runWait.en-US.d.ts +7 -0
- package/dist/client/locales/runWait.en-US.d.ts.map +1 -1
- package/dist/client/locales/runWait.en-US.js +10 -3
- package/dist/client/locales/runWait.en-US.js.map +1 -1
- package/dist/client/locales/runWait.zh-CN.d.ts +1 -1
- package/dist/client/locales/runWait.zh-CN.d.ts.map +1 -1
- package/dist/client/locales/runWait.zh-CN.js +11 -4
- package/dist/client/locales/runWait.zh-CN.js.map +1 -1
- package/dist/client/locales/runtimes.en-US.d.ts +83 -0
- package/dist/client/locales/runtimes.en-US.d.ts.map +1 -1
- package/dist/client/locales/runtimes.en-US.js +84 -1
- package/dist/client/locales/runtimes.en-US.js.map +1 -1
- package/dist/client/locales/runtimes.zh-CN.d.ts.map +1 -1
- package/dist/client/locales/runtimes.zh-CN.js +83 -0
- package/dist/client/locales/runtimes.zh-CN.js.map +1 -1
- package/dist/client/locales/skills.en-US.d.ts +7 -0
- package/dist/client/locales/skills.en-US.d.ts.map +1 -1
- package/dist/client/locales/skills.en-US.js +8 -1
- package/dist/client/locales/skills.en-US.js.map +1 -1
- package/dist/client/locales/skills.zh-CN.d.ts.map +1 -1
- package/dist/client/locales/skills.zh-CN.js +8 -1
- package/dist/client/locales/skills.zh-CN.js.map +1 -1
- package/dist/client/locales/zh-CN.d.ts.map +1 -1
- package/dist/client/locales/zh-CN.js +94 -220
- package/dist/client/locales/zh-CN.js.map +1 -1
- package/dist/client/online/services.d.ts.map +1 -1
- package/dist/client/online/services.js +5 -6
- package/dist/client/online/services.js.map +1 -1
- package/dist/client/pages/agents/agent-dialog.d.ts +9 -0
- package/dist/client/pages/agents/agent-dialog.d.ts.map +1 -0
- package/dist/client/pages/agents/agent-dialog.js +106 -0
- package/dist/client/pages/agents/agent-dialog.js.map +1 -0
- package/dist/client/pages/agents/agent-state.d.ts +11 -0
- package/dist/client/pages/agents/agent-state.d.ts.map +1 -0
- package/dist/client/pages/agents/agent-state.js +28 -0
- package/dist/client/pages/agents/agent-state.js.map +1 -0
- package/dist/client/pages/agents/index.d.ts +1 -1
- package/dist/client/pages/agents/index.d.ts.map +1 -1
- package/dist/client/pages/agents/index.js +7 -101
- package/dist/client/pages/agents/index.js.map +1 -1
- package/dist/client/pages/agents/runner-agents.d.ts +3 -0
- package/dist/client/pages/agents/runner-agents.d.ts.map +1 -0
- package/dist/client/pages/agents/runner-agents.js +185 -0
- package/dist/client/pages/agents/runner-agents.js.map +1 -0
- package/dist/client/pages/runtimes/connect.js.map +1 -1
- package/dist/client/pages/runtimes/index.d.ts.map +1 -1
- package/dist/client/pages/runtimes/index.js +1 -1
- package/dist/client/pages/runtimes/index.js.map +1 -1
- package/dist/client/pages/runtimes/quota-targets.d.ts +4 -0
- package/dist/client/pages/runtimes/quota-targets.d.ts.map +1 -0
- package/dist/client/pages/runtimes/quota-targets.js +18 -0
- package/dist/client/pages/runtimes/quota-targets.js.map +1 -0
- package/dist/client/pages/runtimes/quota.d.ts +17 -0
- package/dist/client/pages/runtimes/quota.d.ts.map +1 -0
- package/dist/client/pages/runtimes/quota.js +50 -0
- package/dist/client/pages/runtimes/quota.js.map +1 -0
- package/dist/client/pages/runtimes/runner-cells.d.ts +11 -4
- package/dist/client/pages/runtimes/runner-cells.d.ts.map +1 -1
- package/dist/client/pages/runtimes/runner-cells.js +6 -3
- package/dist/client/pages/runtimes/runner-cells.js.map +1 -1
- package/dist/client/pages/runtimes/runner-overview.d.ts +9 -0
- package/dist/client/pages/runtimes/runner-overview.d.ts.map +1 -0
- package/dist/client/pages/runtimes/runner-overview.js +109 -0
- package/dist/client/pages/runtimes/runner-overview.js.map +1 -0
- package/dist/client/pages/runtimes/runner-runs.d.ts +5 -0
- package/dist/client/pages/runtimes/runner-runs.d.ts.map +1 -0
- package/dist/client/pages/runtimes/runner-runs.js +35 -0
- package/dist/client/pages/runtimes/runner-runs.js.map +1 -0
- package/dist/client/pages/runtimes/runner-sheet.d.ts +2 -3
- package/dist/client/pages/runtimes/runner-sheet.d.ts.map +1 -1
- package/dist/client/pages/runtimes/runner-sheet.js +43 -171
- package/dist/client/pages/runtimes/runner-sheet.js.map +1 -1
- package/dist/client/pages/runtimes/runner-tools.d.ts +17 -0
- package/dist/client/pages/runtimes/runner-tools.d.ts.map +1 -0
- package/dist/client/pages/runtimes/runner-tools.js +75 -0
- package/dist/client/pages/runtimes/runner-tools.js.map +1 -0
- package/dist/client/pages/runtimes/runner-workspaces.d.ts +6 -0
- package/dist/client/pages/runtimes/runner-workspaces.d.ts.map +1 -0
- package/dist/client/pages/runtimes/runner-workspaces.js +37 -0
- package/dist/client/pages/runtimes/runner-workspaces.js.map +1 -0
- package/dist/client/pages/runtimes/tool-slots-fields.js +1 -1
- package/dist/client/pages/runtimes/tool-slots-fields.js.map +1 -1
- package/dist/client/pages/runtimes/workspace-diagnostics.d.ts +6 -4
- package/dist/client/pages/runtimes/workspace-diagnostics.d.ts.map +1 -1
- package/dist/client/pages/runtimes/workspace-diagnostics.js +67 -33
- package/dist/client/pages/runtimes/workspace-diagnostics.js.map +1 -1
- package/dist/client/pages/skills/detail/index.d.ts.map +1 -1
- package/dist/client/pages/skills/detail/index.js +11 -15
- package/dist/client/pages/skills/detail/index.js.map +1 -1
- package/dist/client/pages/skills/index.d.ts.map +1 -1
- package/dist/client/pages/skills/index.js +2 -2
- package/dist/client/pages/skills/index.js.map +1 -1
- package/dist/client/pages/usage/index.js +2 -2
- package/dist/client/pages/usage/index.js.map +1 -1
- package/dist/client/profile/default-agent.d.ts.map +1 -1
- package/dist/client/profile/default-agent.js +2 -4
- package/dist/client/profile/default-agent.js.map +1 -1
- package/dist/client/routes.d.ts +1 -1
- package/dist/client/routes.d.ts.map +1 -1
- package/dist/client/routes.js +1 -13
- package/dist/client/routes.js.map +1 -1
- package/dist/client/runs/format-wait.d.ts.map +1 -1
- package/dist/client/runs/format-wait.js +15 -1
- package/dist/client/runs/format-wait.js.map +1 -1
- package/dist/client/runs/subject-runs.d.ts +5 -0
- package/dist/client/runs/subject-runs.d.ts.map +1 -1
- package/dist/client/runs/subject-runs.js +24 -9
- package/dist/client/runs/subject-runs.js.map +1 -1
- package/dist/client/runs/use-run-events.d.ts +1 -1
- package/dist/client/runs/use-run-events.d.ts.map +1 -1
- package/dist/client/runs/use-run-events.js +5 -2
- package/dist/client/runs/use-run-events.js.map +1 -1
- package/dist/client/runs.d.ts +1 -1
- package/dist/client/runs.d.ts.map +1 -1
- package/dist/client/runs.js +1 -1
- package/dist/client/runs.js.map +1 -1
- package/dist/database/migrations/.manifest.json +42 -2
- package/dist/database/migrations/202610020003_ag_create_runs.d.ts.map +1 -1
- package/dist/database/migrations/202610020003_ag_create_runs.js +0 -1
- package/dist/database/migrations/202610020003_ag_create_runs.js.map +1 -1
- package/dist/database/migrations/202610120001_ag_index_run_retries.d.ts +4 -0
- package/dist/database/migrations/202610120001_ag_index_run_retries.d.ts.map +1 -0
- package/dist/database/migrations/202610120001_ag_index_run_retries.js +17 -0
- package/dist/database/migrations/202610120001_ag_index_run_retries.js.map +1 -0
- package/dist/database/migrations/202610120002_ag_add_queue_entered_at.d.ts +4 -0
- package/dist/database/migrations/202610120002_ag_add_queue_entered_at.d.ts.map +1 -0
- package/dist/database/migrations/202610120002_ag_add_queue_entered_at.js +50 -0
- package/dist/database/migrations/202610120002_ag_add_queue_entered_at.js.map +1 -0
- package/dist/database/migrations/202610170001_ag_runner_quota.d.ts +4 -0
- package/dist/database/migrations/202610170001_ag_runner_quota.d.ts.map +1 -0
- package/dist/database/migrations/202610170001_ag_runner_quota.js +19 -0
- package/dist/database/migrations/202610170001_ag_runner_quota.js.map +1 -0
- package/dist/database/migrations/202610240020_ag_runner_agents.d.ts +4 -0
- package/dist/database/migrations/202610240020_ag_runner_agents.d.ts.map +1 -0
- package/dist/database/migrations/202610240020_ag_runner_agents.js +115 -0
- package/dist/database/migrations/202610240020_ag_runner_agents.js.map +1 -0
- package/dist/database/migrations/202610240040_ag_discovery_preferences.d.ts +4 -0
- package/dist/database/migrations/202610240040_ag_discovery_preferences.d.ts.map +1 -0
- package/dist/database/migrations/202610240040_ag_discovery_preferences.js +18 -0
- package/dist/database/migrations/202610240040_ag_discovery_preferences.js.map +1 -0
- package/dist/database/migrations/202610250001_ag_comment_runner_consent.d.ts +4 -0
- package/dist/database/migrations/202610250001_ag_comment_runner_consent.d.ts.map +1 -0
- package/dist/database/migrations/202610250001_ag_comment_runner_consent.js +41 -0
- package/dist/database/migrations/202610250001_ag_comment_runner_consent.js.map +1 -0
- package/dist/database/migrations/202610260001_ag_drop_directory_index.d.ts +4 -0
- package/dist/database/migrations/202610260001_ag_drop_directory_index.d.ts.map +1 -0
- package/dist/database/migrations/202610260001_ag_drop_directory_index.js +24 -0
- package/dist/database/migrations/202610260001_ag_drop_directory_index.js.map +1 -0
- package/dist/database/migrations/202610260001_ag_run_revision.d.ts +4 -0
- package/dist/database/migrations/202610260001_ag_run_revision.d.ts.map +1 -0
- package/dist/database/migrations/202610260001_ag_run_revision.js +19 -0
- package/dist/database/migrations/202610260001_ag_run_revision.js.map +1 -0
- package/dist/database/migrations/202610270001_ag_online_agent.d.ts +4 -0
- package/dist/database/migrations/202610270001_ag_online_agent.d.ts.map +1 -0
- package/dist/database/migrations/202610270001_ag_online_agent.js +43 -0
- package/dist/database/migrations/202610270001_ag_online_agent.js.map +1 -0
- package/dist/database/migrations/202610270002_ag_chat_list_visibility.d.ts +4 -0
- package/dist/database/migrations/202610270002_ag_chat_list_visibility.d.ts.map +1 -0
- package/dist/database/migrations/202610270002_ag_chat_list_visibility.js +17 -0
- package/dist/database/migrations/202610270002_ag_chat_list_visibility.js.map +1 -0
- package/dist/package.json +34 -12
- package/dist/server/cli/run-credential.js +1 -1
- package/dist/server/cli/surface.d.ts.map +1 -1
- package/dist/server/cli/surface.js +4 -1
- package/dist/server/cli/surface.js.map +1 -1
- package/dist/server/composition.d.ts +36 -35
- package/dist/server/composition.d.ts.map +1 -1
- package/dist/server/composition.js +99 -66
- package/dist/server/composition.js.map +1 -1
- package/dist/server/core/agents/agent.service.d.ts +51 -43
- package/dist/server/core/agents/agent.service.d.ts.map +1 -1
- package/dist/server/core/agents/agent.service.js +347 -321
- package/dist/server/core/agents/agent.service.js.map +1 -1
- package/dist/server/core/agents/agent.store.d.ts +26 -12
- package/dist/server/core/agents/agent.store.d.ts.map +1 -1
- package/dist/server/core/agents/agent.store.js +74 -66
- package/dist/server/core/agents/agent.store.js.map +1 -1
- package/dist/server/core/agents/agent.views.d.ts +29 -0
- package/dist/server/core/agents/agent.views.d.ts.map +1 -0
- package/dist/server/core/agents/agent.views.js +88 -0
- package/dist/server/core/agents/agent.views.js.map +1 -0
- package/dist/server/core/agents/discovery.d.ts +12 -0
- package/dist/server/core/agents/discovery.d.ts.map +1 -0
- package/dist/server/core/agents/discovery.js +39 -0
- package/dist/server/core/agents/discovery.js.map +1 -0
- package/dist/server/core/agents/index.d.ts +3 -2
- package/dist/server/core/agents/index.d.ts.map +1 -1
- package/dist/server/core/agents/index.js +3 -2
- package/dist/server/core/agents/index.js.map +1 -1
- package/dist/server/core/brief/brief.js +3 -3
- package/dist/server/core/brief/brief.js.map +1 -1
- package/dist/server/core/callers/index.d.ts +10 -1
- package/dist/server/core/callers/index.d.ts.map +1 -1
- package/dist/server/core/callers/index.js +15 -0
- package/dist/server/core/callers/index.js.map +1 -1
- package/dist/server/core/conversations/attachments.d.ts.map +1 -1
- package/dist/server/core/conversations/attachments.js +6 -1
- package/dist/server/core/conversations/attachments.js.map +1 -1
- package/dist/server/core/conversations/availability.d.ts +6 -11
- package/dist/server/core/conversations/availability.d.ts.map +1 -1
- package/dist/server/core/conversations/availability.js +11 -15
- package/dist/server/core/conversations/availability.js.map +1 -1
- package/dist/server/core/conversations/chat-settings.d.ts +2 -2
- package/dist/server/core/conversations/chat-settings.d.ts.map +1 -1
- package/dist/server/core/conversations/chat-settings.js +17 -22
- package/dist/server/core/conversations/chat-settings.js.map +1 -1
- package/dist/server/core/conversations/conversation.service.d.ts +13 -8
- package/dist/server/core/conversations/conversation.service.d.ts.map +1 -1
- package/dist/server/core/conversations/conversation.service.js +397 -383
- package/dist/server/core/conversations/conversation.service.js.map +1 -1
- package/dist/server/core/conversations/conversation.store.d.ts +3 -0
- package/dist/server/core/conversations/conversation.store.d.ts.map +1 -1
- package/dist/server/core/conversations/conversation.store.js +2 -1
- package/dist/server/core/conversations/conversation.store.js.map +1 -1
- package/dist/server/core/conversations/page-context.d.ts +8 -2
- package/dist/server/core/conversations/page-context.d.ts.map +1 -1
- package/dist/server/core/conversations/page-context.js +61 -2
- package/dist/server/core/conversations/page-context.js.map +1 -1
- package/dist/server/core/conversations/ports.d.ts +18 -20
- package/dist/server/core/conversations/ports.d.ts.map +1 -1
- package/dist/server/core/reports/model-usage.d.ts.map +1 -1
- package/dist/server/core/reports/model-usage.js +42 -44
- package/dist/server/core/reports/model-usage.js.map +1 -1
- package/dist/server/core/reports/prices.d.ts.map +1 -1
- package/dist/server/core/reports/prices.js +29 -5
- package/dist/server/core/reports/prices.js.map +1 -1
- package/dist/server/core/reports/report.service.d.ts +4 -2
- package/dist/server/core/reports/report.service.d.ts.map +1 -1
- package/dist/server/core/reports/report.service.js +148 -66
- package/dist/server/core/reports/report.service.js.map +1 -1
- package/dist/server/core/runs/access.d.ts +5 -0
- package/dist/server/core/runs/access.d.ts.map +1 -0
- package/dist/server/core/runs/access.js +10 -0
- package/dist/server/core/runs/access.js.map +1 -0
- package/dist/server/core/runs/availability.d.ts +18 -6
- package/dist/server/core/runs/availability.d.ts.map +1 -1
- package/dist/server/core/runs/availability.js +40 -34
- package/dist/server/core/runs/availability.js.map +1 -1
- package/dist/server/core/runs/claim.d.ts +30 -106
- package/dist/server/core/runs/claim.d.ts.map +1 -1
- package/dist/server/core/runs/claim.js +630 -323
- package/dist/server/core/runs/claim.js.map +1 -1
- package/dist/server/core/runs/comment-consent.d.ts +24 -0
- package/dist/server/core/runs/comment-consent.d.ts.map +1 -0
- package/dist/server/core/runs/comment-consent.js +116 -0
- package/dist/server/core/runs/comment-consent.js.map +1 -0
- package/dist/server/core/runs/eligibility.d.ts +13 -1
- package/dist/server/core/runs/eligibility.d.ts.map +1 -1
- package/dist/server/core/runs/eligibility.js +41 -10
- package/dist/server/core/runs/eligibility.js.map +1 -1
- package/dist/server/core/runs/execution-view.d.ts +8 -0
- package/dist/server/core/runs/execution-view.d.ts.map +1 -1
- package/dist/server/core/runs/execution-view.js +9 -0
- package/dist/server/core/runs/execution-view.js.map +1 -1
- package/dist/server/core/runs/execution.d.ts +1 -1
- package/dist/server/core/runs/execution.d.ts.map +1 -1
- package/dist/server/core/runs/execution.js +8 -2
- package/dist/server/core/runs/execution.js.map +1 -1
- package/dist/server/core/runs/identity.d.ts +9 -0
- package/dist/server/core/runs/identity.d.ts.map +1 -0
- package/dist/server/core/runs/identity.js +75 -0
- package/dist/server/core/runs/identity.js.map +1 -0
- package/dist/server/core/runs/index.d.ts +6 -6
- package/dist/server/core/runs/index.d.ts.map +1 -1
- package/dist/server/core/runs/index.js +6 -6
- package/dist/server/core/runs/index.js.map +1 -1
- package/dist/server/core/runs/input-gate.d.ts +1 -1
- package/dist/server/core/runs/input-gate.d.ts.map +1 -1
- package/dist/server/core/runs/input-gate.js +4 -2
- package/dist/server/core/runs/input-gate.js.map +1 -1
- package/dist/server/core/runs/lifecycle.d.ts +16 -18
- package/dist/server/core/runs/lifecycle.d.ts.map +1 -1
- package/dist/server/core/runs/lifecycle.js +146 -60
- package/dist/server/core/runs/lifecycle.js.map +1 -1
- package/dist/server/core/runs/policy.d.ts +9 -2
- package/dist/server/core/runs/policy.d.ts.map +1 -1
- package/dist/server/core/runs/policy.js +17 -8
- package/dist/server/core/runs/policy.js.map +1 -1
- package/dist/server/core/runs/ports.d.ts +41 -31
- package/dist/server/core/runs/ports.d.ts.map +1 -1
- package/dist/server/core/runs/ports.js +2 -13
- package/dist/server/core/runs/ports.js.map +1 -1
- package/dist/server/core/runs/preview.d.ts.map +1 -1
- package/dist/server/core/runs/preview.js +1 -3
- package/dist/server/core/runs/preview.js.map +1 -1
- package/dist/server/core/runs/run-data-purge.d.ts +15 -0
- package/dist/server/core/runs/run-data-purge.d.ts.map +1 -0
- package/dist/server/core/runs/run-data-purge.js +82 -0
- package/dist/server/core/runs/run-data-purge.js.map +1 -0
- package/dist/server/core/runs/run-requests.d.ts +25 -0
- package/dist/server/core/runs/run-requests.d.ts.map +1 -1
- package/dist/server/core/runs/run-requests.js +131 -64
- package/dist/server/core/runs/run-requests.js.map +1 -1
- package/dist/server/core/runs/run.service.d.ts +39 -3
- package/dist/server/core/runs/run.service.d.ts.map +1 -1
- package/dist/server/core/runs/run.service.js +729 -102
- package/dist/server/core/runs/run.service.js.map +1 -1
- package/dist/server/core/runs/run.store.d.ts +11 -0
- package/dist/server/core/runs/run.store.d.ts.map +1 -1
- package/dist/server/core/runs/run.store.js +39 -11
- package/dist/server/core/runs/run.store.js.map +1 -1
- package/dist/server/core/runs/runner-view.d.ts +12 -2
- package/dist/server/core/runs/runner-view.d.ts.map +1 -1
- package/dist/server/core/runs/runner-view.js +55 -13
- package/dist/server/core/runs/runner-view.js.map +1 -1
- package/dist/server/core/runs/selection.d.ts +13 -0
- package/dist/server/core/runs/selection.d.ts.map +1 -0
- package/dist/server/core/runs/selection.js +21 -0
- package/dist/server/core/runs/selection.js.map +1 -0
- package/dist/server/core/runs/sweeper.d.ts +1 -0
- package/dist/server/core/runs/sweeper.d.ts.map +1 -1
- package/dist/server/core/runs/sweeper.js +66 -17
- package/dist/server/core/runs/sweeper.js.map +1 -1
- package/dist/server/core/runs/transitions.d.ts +6 -2
- package/dist/server/core/runs/transitions.d.ts.map +1 -1
- package/dist/server/core/runs/transitions.js +73 -19
- package/dist/server/core/runs/transitions.js.map +1 -1
- package/dist/server/core/runs/workload.d.ts +17 -5
- package/dist/server/core/runs/workload.d.ts.map +1 -1
- package/dist/server/core/runs/workload.js +203 -68
- package/dist/server/core/runs/workload.js.map +1 -1
- package/dist/server/core/skills/skill.service.d.ts +6 -2
- package/dist/server/core/skills/skill.service.d.ts.map +1 -1
- package/dist/server/core/skills/skill.service.js +87 -66
- package/dist/server/core/skills/skill.service.js.map +1 -1
- package/dist/server/core/skills/skill.store.d.ts +14 -0
- package/dist/server/core/skills/skill.store.d.ts.map +1 -1
- package/dist/server/core/skills/skill.store.js +30 -0
- package/dist/server/core/skills/skill.store.js.map +1 -1
- package/dist/server/core/transaction-read.d.ts +4 -0
- package/dist/server/core/transaction-read.d.ts.map +1 -0
- package/dist/server/core/transaction-read.js +30 -0
- package/dist/server/core/transaction-read.js.map +1 -0
- package/dist/server/core/variables/index.d.ts +1 -1
- package/dist/server/core/variables/index.d.ts.map +1 -1
- package/dist/server/core/variables/index.js.map +1 -1
- package/dist/server/core/variables/variable.service.d.ts +18 -0
- package/dist/server/core/variables/variable.service.d.ts.map +1 -1
- package/dist/server/core/variables/variable.service.js +95 -20
- package/dist/server/core/variables/variable.service.js.map +1 -1
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +3 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/jobs/job.service.d.ts +1 -1
- package/dist/server/jobs/job.service.d.ts.map +1 -1
- package/dist/server/jobs/job.service.js +8 -2
- package/dist/server/jobs/job.service.js.map +1 -1
- package/dist/server/kernel/events.d.ts +12 -3
- package/dist/server/kernel/events.d.ts.map +1 -1
- package/dist/server/kernel/events.js.map +1 -1
- package/dist/server/kernel/scopes.d.ts +6 -0
- package/dist/server/kernel/scopes.d.ts.map +1 -1
- package/dist/server/kernel/scopes.js +3 -1
- package/dist/server/kernel/scopes.js.map +1 -1
- package/dist/server/online/agent/configuration.d.ts +26 -0
- package/dist/server/online/agent/configuration.d.ts.map +1 -0
- package/dist/server/online/agent/configuration.js +261 -0
- package/dist/server/online/agent/configuration.js.map +1 -0
- package/dist/server/online/agent/contracts.d.ts +87 -0
- package/dist/server/online/agent/contracts.d.ts.map +1 -0
- package/dist/server/online/agent/contracts.js +2 -0
- package/dist/server/online/agent/contracts.js.map +1 -0
- package/dist/server/online/agent/errors.d.ts +11 -0
- package/dist/server/online/agent/errors.d.ts.map +1 -0
- package/dist/server/online/agent/errors.js +21 -0
- package/dist/server/online/agent/errors.js.map +1 -0
- package/dist/server/online/agent/index.d.ts +11 -0
- package/dist/server/online/agent/index.d.ts.map +1 -0
- package/dist/server/online/agent/index.js +9 -0
- package/dist/server/online/agent/index.js.map +1 -0
- package/dist/server/online/agent/messages/json.d.ts +5 -0
- package/dist/server/online/agent/messages/json.d.ts.map +1 -0
- package/dist/server/online/agent/messages/json.js +88 -0
- package/dist/server/online/agent/messages/json.js.map +1 -0
- package/dist/server/online/agent/messages/projection.d.ts +20 -0
- package/dist/server/online/agent/messages/projection.d.ts.map +1 -0
- package/dist/server/online/agent/messages/projection.js +495 -0
- package/dist/server/online/agent/messages/projection.js.map +1 -0
- package/dist/server/online/agent/messages/validation.d.ts +7 -0
- package/dist/server/online/agent/messages/validation.d.ts.map +1 -0
- package/dist/server/online/agent/messages/validation.js +159 -0
- package/dist/server/online/agent/messages/validation.js.map +1 -0
- package/dist/server/online/agent/native/backend.d.ts +60 -0
- package/dist/server/online/agent/native/backend.d.ts.map +1 -0
- package/dist/server/online/agent/native/backend.js +411 -0
- package/dist/server/online/agent/native/backend.js.map +1 -0
- package/dist/server/online/agent/native/execution.d.ts +41 -0
- package/dist/server/online/agent/native/execution.d.ts.map +1 -0
- package/dist/server/online/agent/native/execution.js +430 -0
- package/dist/server/online/agent/native/execution.js.map +1 -0
- package/dist/server/online/agent/native/session.d.ts +40 -0
- package/dist/server/online/agent/native/session.d.ts.map +1 -0
- package/dist/server/online/agent/native/session.js +104 -0
- package/dist/server/online/agent/native/session.js.map +1 -0
- package/dist/server/online/agent/native/types.d.ts +32 -0
- package/dist/server/online/agent/native/types.d.ts.map +1 -0
- package/dist/server/online/agent/native/types.js +2 -0
- package/dist/server/online/agent/native/types.js.map +1 -0
- package/dist/server/online/agent/persistence/manager.d.ts +16 -0
- package/dist/server/online/agent/persistence/manager.d.ts.map +1 -0
- package/dist/server/online/agent/persistence/manager.js +209 -0
- package/dist/server/online/agent/persistence/manager.js.map +1 -0
- package/dist/server/online/agent/persistence/state.d.ts +11 -0
- package/dist/server/online/agent/persistence/state.d.ts.map +1 -0
- package/dist/server/online/agent/persistence/state.js +45 -0
- package/dist/server/online/agent/persistence/state.js.map +1 -0
- package/dist/server/online/agent/persistence/store.d.ts +58 -0
- package/dist/server/online/agent/persistence/store.d.ts.map +1 -0
- package/dist/server/online/agent/persistence/store.js +634 -0
- package/dist/server/online/agent/persistence/store.js.map +1 -0
- package/dist/server/online/agent/persistence/types.d.ts +44 -0
- package/dist/server/online/agent/persistence/types.d.ts.map +1 -0
- package/dist/server/online/agent/persistence/types.js +2 -0
- package/dist/server/online/agent/persistence/types.js.map +1 -0
- package/dist/server/online/agent/runner/backend.d.ts +57 -0
- package/dist/server/online/agent/runner/backend.d.ts.map +1 -0
- package/dist/server/online/agent/runner/backend.js +501 -0
- package/dist/server/online/agent/runner/backend.js.map +1 -0
- package/dist/server/online/agent/runner/projection.d.ts +10 -0
- package/dist/server/online/agent/runner/projection.d.ts.map +1 -0
- package/dist/server/online/agent/runner/projection.js +171 -0
- package/dist/server/online/agent/runner/projection.js.map +1 -0
- package/dist/server/online/agent/runner/types.d.ts +44 -0
- package/dist/server/online/agent/runner/types.d.ts.map +1 -0
- package/dist/server/online/agent/runner/types.js +2 -0
- package/dist/server/online/agent/runner/types.js.map +1 -0
- package/dist/server/online/agent/service.d.ts +47 -0
- package/dist/server/online/agent/service.d.ts.map +1 -0
- package/dist/server/online/agent/service.js +111 -0
- package/dist/server/online/agent/service.js.map +1 -0
- package/dist/server/online/agent/transport/streams.d.ts +54 -0
- package/dist/server/online/agent/transport/streams.d.ts.map +1 -0
- package/dist/server/online/agent/transport/streams.js +440 -0
- package/dist/server/online/agent/transport/streams.js.map +1 -0
- package/dist/server/online/agent/types.d.ts +155 -0
- package/dist/server/online/agent/types.d.ts.map +1 -0
- package/dist/server/online/agent/types.js +2 -0
- package/dist/server/online/agent/types.js.map +1 -0
- package/dist/server/online/index.d.ts +0 -5
- package/dist/server/online/index.d.ts.map +1 -1
- package/dist/server/online/index.js +0 -5
- package/dist/server/online/index.js.map +1 -1
- package/dist/server/online/providers.d.ts.map +1 -1
- package/dist/server/online/providers.js +26 -2
- package/dist/server/online/providers.js.map +1 -1
- package/dist/server/online/routes.d.ts.map +1 -1
- package/dist/server/online/routes.js +6 -35
- package/dist/server/online/routes.js.map +1 -1
- package/dist/server/online/services.d.ts.map +1 -1
- package/dist/server/online/services.js +101 -24
- package/dist/server/online/services.js.map +1 -1
- package/dist/server/providers/agents.d.ts +18 -25
- package/dist/server/providers/agents.d.ts.map +1 -1
- package/dist/server/providers/agents.js +79 -100
- package/dist/server/providers/agents.js.map +1 -1
- package/dist/server/providers/runners.d.ts +3 -1
- package/dist/server/providers/runners.d.ts.map +1 -1
- package/dist/server/providers/runners.js +38 -9
- package/dist/server/providers/runners.js.map +1 -1
- package/dist/server/routes/admin.d.ts +4 -0
- package/dist/server/routes/admin.d.ts.map +1 -1
- package/dist/server/routes/admin.js +139 -212
- package/dist/server/routes/admin.js.map +1 -1
- package/dist/server/routes/chat.d.ts.map +1 -1
- package/dist/server/routes/chat.js +313 -164
- package/dist/server/routes/chat.js.map +1 -1
- package/dist/server/routes/index.d.ts.map +1 -1
- package/dist/server/routes/index.js +8 -0
- package/dist/server/routes/index.js.map +1 -1
- package/dist/server/routes/roster.d.ts.map +1 -1
- package/dist/server/routes/roster.js +6 -22
- package/dist/server/routes/roster.js.map +1 -1
- package/dist/server/routes/run-requests.js +3 -3
- package/dist/server/routes/run-requests.js.map +1 -1
- package/dist/server/routes/runners/admin.d.ts.map +1 -1
- package/dist/server/routes/runners/admin.js +219 -25
- package/dist/server/routes/runners/admin.js.map +1 -1
- package/dist/server/routes/runners/install.d.ts.map +1 -1
- package/dist/server/routes/runners/install.js +7 -2
- package/dist/server/routes/runners/install.js.map +1 -1
- package/dist/server/routes/runners/runner.d.ts.map +1 -1
- package/dist/server/routes/runners/runner.js +2 -0
- package/dist/server/routes/runners/runner.js.map +1 -1
- package/dist/server/routes/schemas.d.ts +18 -10
- package/dist/server/routes/schemas.d.ts.map +1 -1
- package/dist/server/routes/schemas.js +498 -153
- package/dist/server/routes/schemas.js.map +1 -1
- package/dist/server/runners/runner.service.d.ts +47 -4
- package/dist/server/runners/runner.service.d.ts.map +1 -1
- package/dist/server/runners/runner.service.js +423 -79
- package/dist/server/runners/runner.service.js.map +1 -1
- package/dist/server/runners/runner.store.d.ts +8 -3
- package/dist/server/runners/runner.store.d.ts.map +1 -1
- package/dist/server/runners/runner.store.js +63 -6
- package/dist/server/runners/runner.store.js.map +1 -1
- package/dist/server/runners/slots.d.ts +5 -2
- package/dist/server/runners/slots.d.ts.map +1 -1
- package/dist/server/runners/slots.js +3 -4
- package/dist/server/runners/slots.js.map +1 -1
- package/dist/server/runners/workspaces.d.ts.map +1 -1
- package/dist/server/runners/workspaces.js +18 -2
- package/dist/server/runners/workspaces.js.map +1 -1
- package/dist/server/testing.d.ts +0 -2
- package/dist/server/testing.d.ts.map +1 -1
- package/dist/server/testing.js +1 -4
- package/dist/server/testing.js.map +1 -1
- package/dist/server/tokens.d.ts +8 -7
- package/dist/server/tokens.d.ts.map +1 -1
- package/dist/server/tokens.js +4 -2
- package/dist/server/tokens.js.map +1 -1
- package/dist/shared/access.d.ts +2 -6
- package/dist/shared/access.d.ts.map +1 -1
- package/dist/shared/access.js +2 -6
- package/dist/shared/access.js.map +1 -1
- package/dist/shared/agents.d.ts +131 -169
- package/dist/shared/agents.d.ts.map +1 -1
- package/dist/shared/agents.js +36 -102
- package/dist/shared/agents.js.map +1 -1
- package/dist/shared/conversations.d.ts +93 -170
- package/dist/shared/conversations.d.ts.map +1 -1
- package/dist/shared/conversations.js +8 -30
- package/dist/shared/conversations.js.map +1 -1
- package/dist/shared/model-catalog.d.ts +53 -0
- package/dist/shared/model-catalog.d.ts.map +1 -0
- package/dist/shared/model-catalog.js +182 -0
- package/dist/shared/model-catalog.js.map +1 -0
- package/dist/shared/online-agent.d.ts +3 -0
- package/dist/shared/online-agent.d.ts.map +1 -0
- package/dist/shared/online-agent.js +3 -0
- package/dist/shared/online-agent.js.map +1 -0
- package/dist/shared/page-ui-context.d.ts +26 -0
- package/dist/shared/page-ui-context.d.ts.map +1 -0
- package/dist/shared/page-ui-context.js +129 -0
- package/dist/shared/page-ui-context.js.map +1 -0
- package/dist/shared/quota.d.ts +15 -0
- package/dist/shared/quota.d.ts.map +1 -0
- package/dist/shared/quota.js +2 -0
- package/dist/shared/quota.js.map +1 -0
- package/dist/shared/runners.d.ts +132 -14
- package/dist/shared/runners.d.ts.map +1 -1
- package/dist/shared/runners.js +171 -11
- package/dist/shared/runners.js.map +1 -1
- package/dist/shared/runs.d.ts +59 -1
- package/dist/shared/runs.d.ts.map +1 -1
- package/dist/shared/runs.js +28 -0
- package/dist/shared/runs.js.map +1 -1
- package/dist/shared/skills.d.ts +11 -5
- package/dist/shared/skills.d.ts.map +1 -1
- package/dist/shared/skills.js +7 -2
- package/dist/shared/skills.js.map +1 -1
- package/dist/shared/ui-message.d.ts +80 -0
- package/dist/shared/ui-message.d.ts.map +1 -0
- package/dist/shared/ui-message.js +153 -0
- package/dist/shared/ui-message.js.map +1 -0
- package/dist/shared/variables.js +1 -1
- package/dist/shared/variables.js.map +1 -1
- package/docs/ai-forms.md +346 -0
- package/docs/execution-history.md +19 -0
- package/docs/mysql-installation-upgrade.md +7 -0
- package/docs/runner-agents.md +27 -0
- package/docs/ui-message-clients.md +80 -0
- package/docs/ui-messages.md +209 -0
- package/docs/workspace-cleanup.md +13 -0
- package/package.json +39 -25
- package/skills/nocobase-app-plugin-agents/SKILL.md +16 -13
- package/skills/nocobase-app-plugin-agents/references/agents.md +30 -0
- package/skills/nocobase-app-plugin-agents/references/extension-points.md +21 -21
- package/skills/nocobase-app-plugin-agents/references/model-services.md +17 -0
- package/skills/nocobase-app-plugin-agents/references/online-agent.md +216 -0
- package/skills/nocobase-app-plugin-agents/references/runners.md +12 -0
- package/skills/nocobase-app-plugin-agents/references/setup-and-config.md +6 -7
- package/skills/nocobase-app-plugin-agents/references/variables-skills-usage.md +6 -4
- package/skills/nocobase-app-plugin-agents/references/verification-and-troubleshooting.md +29 -32
- package/dist/client/chat/settings-section.d.ts +0 -5
- package/dist/client/chat/settings-section.d.ts.map +0 -1
- package/dist/client/chat/settings-section.js +0 -86
- package/dist/client/chat/settings-section.js.map +0 -1
- package/dist/client/components/agent-fields.d.ts +0 -45
- package/dist/client/components/agent-fields.d.ts.map +0 -1
- package/dist/client/components/agent-fields.js +0 -83
- package/dist/client/components/agent-fields.js.map +0 -1
- package/dist/client/components/agent-type.d.ts +0 -32
- package/dist/client/components/agent-type.d.ts.map +0 -1
- package/dist/client/components/agent-type.js +0 -80
- package/dist/client/components/agent-type.js.map +0 -1
- package/dist/client/components/model-entries.d.ts +0 -44
- package/dist/client/components/model-entries.d.ts.map +0 -1
- package/dist/client/components/model-entries.js +0 -104
- package/dist/client/components/model-entries.js.map +0 -1
- package/dist/client/hooks/use-agent-save.d.ts +0 -9
- package/dist/client/hooks/use-agent-save.d.ts.map +0 -1
- package/dist/client/hooks/use-agent-save.js +0 -40
- package/dist/client/hooks/use-agent-save.js.map +0 -1
- package/dist/client/hooks/use-model-catalog.d.ts +0 -9
- package/dist/client/hooks/use-model-catalog.d.ts.map +0 -1
- package/dist/client/hooks/use-model-catalog.js +0 -27
- package/dist/client/hooks/use-model-catalog.js.map +0 -1
- package/dist/client/lib/model-suggestions.d.ts +0 -28
- package/dist/client/lib/model-suggestions.d.ts.map +0 -1
- package/dist/client/lib/model-suggestions.js +0 -44
- package/dist/client/lib/model-suggestions.js.map +0 -1
- package/dist/client/lib/tool-policy.d.ts +0 -3
- package/dist/client/lib/tool-policy.d.ts.map +0 -1
- package/dist/client/lib/tool-policy.js +0 -5
- package/dist/client/lib/tool-policy.js.map +0 -1
- package/dist/client/online/default-model.d.ts +0 -5
- package/dist/client/online/default-model.d.ts.map +0 -1
- package/dist/client/online/default-model.js +0 -65
- package/dist/client/online/default-model.js.map +0 -1
- package/dist/client/pages/agents/agent-model.d.ts +0 -69
- package/dist/client/pages/agents/agent-model.d.ts.map +0 -1
- package/dist/client/pages/agents/agent-model.js +0 -153
- package/dist/client/pages/agents/agent-model.js.map +0 -1
- package/dist/client/pages/agents/detail/brief-preview.d.ts +0 -7
- package/dist/client/pages/agents/detail/brief-preview.d.ts.map +0 -1
- package/dist/client/pages/agents/detail/brief-preview.js +0 -43
- package/dist/client/pages/agents/detail/brief-preview.js.map +0 -1
- package/dist/client/pages/agents/detail/history.d.ts +0 -11
- package/dist/client/pages/agents/detail/history.d.ts.map +0 -1
- package/dist/client/pages/agents/detail/history.js +0 -149
- package/dist/client/pages/agents/detail/history.js.map +0 -1
- package/dist/client/pages/agents/detail/index.d.ts +0 -3
- package/dist/client/pages/agents/detail/index.d.ts.map +0 -1
- package/dist/client/pages/agents/detail/index.js +0 -241
- package/dist/client/pages/agents/detail/index.js.map +0 -1
- package/dist/client/pages/agents/detail/sections.d.ts +0 -21
- package/dist/client/pages/agents/detail/sections.d.ts.map +0 -1
- package/dist/client/pages/agents/detail/sections.js +0 -280
- package/dist/client/pages/agents/detail/sections.js.map +0 -1
- package/dist/client/pages/agents/detail/tab-draft.d.ts +0 -43
- package/dist/client/pages/agents/detail/tab-draft.d.ts.map +0 -1
- package/dist/client/pages/agents/detail/tab-draft.js +0 -115
- package/dist/client/pages/agents/detail/tab-draft.js.map +0 -1
- package/dist/client/pages/agents/detail/unsaved-bar.d.ts +0 -13
- package/dist/client/pages/agents/detail/unsaved-bar.d.ts.map +0 -1
- package/dist/client/pages/agents/detail/unsaved-bar.js +0 -21
- package/dist/client/pages/agents/detail/unsaved-bar.js.map +0 -1
- package/dist/client/pages/agents/new.d.ts +0 -3
- package/dist/client/pages/agents/new.d.ts.map +0 -1
- package/dist/client/pages/agents/new.js +0 -149
- package/dist/client/pages/agents/new.js.map +0 -1
- package/dist/client/pages/agents/preset-picker.d.ts +0 -8
- package/dist/client/pages/agents/preset-picker.d.ts.map +0 -1
- package/dist/client/pages/agents/preset-picker.js +0 -41
- package/dist/client/pages/agents/preset-picker.js.map +0 -1
- package/dist/server/core/consultations/consultation.service.d.ts +0 -59
- package/dist/server/core/consultations/consultation.service.d.ts.map +0 -1
- package/dist/server/core/consultations/consultation.service.js +0 -198
- package/dist/server/core/consultations/consultation.service.js.map +0 -1
- package/dist/server/core/consultations/index.d.ts +0 -3
- package/dist/server/core/consultations/index.d.ts.map +0 -1
- package/dist/server/core/consultations/index.js +0 -3
- package/dist/server/core/consultations/index.js.map +0 -1
- package/dist/server/core/consultations/prompt.d.ts +0 -41
- package/dist/server/core/consultations/prompt.d.ts.map +0 -1
- package/dist/server/core/consultations/prompt.js +0 -64
- package/dist/server/core/consultations/prompt.js.map +0 -1
- package/dist/server/core/presets/index.d.ts +0 -19
- package/dist/server/core/presets/index.d.ts.map +0 -1
- package/dist/server/core/presets/index.js +0 -28
- package/dist/server/core/presets/index.js.map +0 -1
- package/dist/server/online/cli-command.d.ts +0 -20
- package/dist/server/online/cli-command.d.ts.map +0 -1
- package/dist/server/online/cli-command.js +0 -345
- package/dist/server/online/cli-command.js.map +0 -1
- package/dist/server/online/consult-tool.d.ts +0 -54
- package/dist/server/online/consult-tool.d.ts.map +0 -1
- package/dist/server/online/consult-tool.js +0 -177
- package/dist/server/online/consult-tool.js.map +0 -1
- package/dist/server/online/executor.d.ts +0 -83
- package/dist/server/online/executor.d.ts.map +0 -1
- package/dist/server/online/executor.js +0 -714
- package/dist/server/online/executor.js.map +0 -1
- package/dist/server/online/sandbox.d.ts +0 -32
- package/dist/server/online/sandbox.d.ts.map +0 -1
- package/dist/server/online/sandbox.js +0 -246
- package/dist/server/online/sandbox.js.map +0 -1
- package/dist/server/online/scripted.d.ts +0 -12
- package/dist/server/online/scripted.d.ts.map +0 -1
- package/dist/server/online/scripted.js +0 -176
- package/dist/server/online/scripted.js.map +0 -1
- package/dist/server/online/tools.d.ts +0 -17
- package/dist/server/online/tools.d.ts.map +0 -1
- package/dist/server/online/tools.js +0 -31
- package/dist/server/online/tools.js.map +0 -1
- package/dist/server/vendor/THIRD_PARTY_LICENSES.txt +0 -782
- package/dist/server/vendor/just-bash.d.ts +0 -83
- package/dist/server/vendor/just-bash.js +0 -2102
- package/dist/shared/presets.d.ts +0 -30
- package/dist/shared/presets.d.ts.map +0 -1
- package/dist/shared/presets.js +0 -2
- package/dist/shared/presets.js.map +0 -1
- package/skills/nocobase-app-plugin-agents/references/online-agents.md +0 -31
|
@@ -9,16 +9,17 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { ProtocolError, TERMINAL_RUN_STATUSES, } from '@nocobase/agent-protocol';
|
|
11
11
|
import { conflict, forbidden, invalid, notFound, precondition, } from '../../kernel/errors.js';
|
|
12
|
-
import { asJson, cleanList, jsonObject } from '../../kernel/values.js';
|
|
12
|
+
import { asJson, cleanList, jsonObject, stringArray, } from '../../kernel/values.js';
|
|
13
13
|
import { findAgent, lockAgentForClaim } from '../agents/index.js';
|
|
14
|
+
import { agentNamesOf } from '../agents/agent.store.js';
|
|
14
15
|
import { createRunRequestService, insertRunRequest, } from './run-requests.js';
|
|
15
16
|
import { authenticateRunToken } from './run-tokens.js';
|
|
16
|
-
import { ACTIVE, eventsRepo, findRunRecord, inputsOnSince, inputsRepo, isActive, isTerminal, lastSummary, openRunsOn, pendingInputs, reposRepo, runsOfKey, runsRepo, toInput, toInputView, toRepo, toRun, usageRepo, } from './run.store.js';
|
|
17
|
-
import {
|
|
18
|
-
import { readWorkload } from './workload.js';
|
|
17
|
+
import { ACTIVE, eventsRepo, findRunRecord, inputsOnSince, inputsRepo, isActive, isTerminal, lastSummary, openRunsOn, openRunsOnEach, pendingInputs, reposRepo, runsOfKey, runsRepo, toInput, toInputView, toRepo, toRun, usageRepo, } from './run.store.js';
|
|
18
|
+
import { readQueueWait, readWorkload, } from './workload.js';
|
|
19
19
|
import { finishRun } from './transitions.js';
|
|
20
20
|
import { gateInputs, gatePending } from './input-gate.js';
|
|
21
21
|
import { findBrief, requestReset } from './workspace.store.js';
|
|
22
|
+
import { findCommentRoot, currentCommentOwner, commentConsent, commentFromOwner, } from './comment-consent.js';
|
|
22
23
|
export const DEFAULT_THREAD = 'main';
|
|
23
24
|
/**
|
|
24
25
|
* The run work went into, for a caller that names no responsible (a conversation, a consultation): such work is never
|
|
@@ -31,7 +32,9 @@ export function queuedRun(result) {
|
|
|
31
32
|
}
|
|
32
33
|
/** Who a chain of work a run belongs to started with: who confirmed it, else who it was requested by. */
|
|
33
34
|
function chainSourceOf(run) {
|
|
34
|
-
return run.
|
|
35
|
+
return run.commentRootRunId
|
|
36
|
+
? (run.requestedByUserId ?? run.actorUserId)
|
|
37
|
+
: (run.confirmedByUserId ?? run.requestedByUserId ?? run.actorUserId);
|
|
35
38
|
}
|
|
36
39
|
/** A delay as the moment a run may be claimed, or null for now (and for any moment already past). */
|
|
37
40
|
function fireAtOf(value, now) {
|
|
@@ -42,8 +45,20 @@ function fireAtOf(value, now) {
|
|
|
42
45
|
throw invalid('fireAt is not a date.');
|
|
43
46
|
return at.getTime() > now.getTime() ? at.toISOString() : null;
|
|
44
47
|
}
|
|
48
|
+
const COMMENT_CANCEL_DETAIL = 'The personal runner request was declined or switched to the commenter.';
|
|
45
49
|
export function createRunService(deps) {
|
|
46
50
|
const { tx, ids, clock } = deps;
|
|
51
|
+
/** Ends one unfinished run of a declined chain; a run that moved since it was read rolls the decision back. */
|
|
52
|
+
async function endCommentRun(unit, run, byUserId) {
|
|
53
|
+
const ended = await finishRun(unit, deps, run, {
|
|
54
|
+
status: 'cancelled',
|
|
55
|
+
reason: null,
|
|
56
|
+
detail: COMMENT_CANCEL_DETAIL,
|
|
57
|
+
cancelledById: byUserId,
|
|
58
|
+
});
|
|
59
|
+
if (!ended)
|
|
60
|
+
throw conflict('The comment work changed; read it again.');
|
|
61
|
+
}
|
|
47
62
|
const require = async (conn, id) => {
|
|
48
63
|
const run = await findRunRecord(conn, id);
|
|
49
64
|
if (!run)
|
|
@@ -79,22 +94,20 @@ export function createRunService(deps) {
|
|
|
79
94
|
const agent = await findAgent(unit.conn, agentId);
|
|
80
95
|
if (!agent)
|
|
81
96
|
throw notFound('Agent');
|
|
82
|
-
if (agent.
|
|
83
|
-
throw precondition('
|
|
97
|
+
if (agent.status !== 'enabled')
|
|
98
|
+
throw precondition('AGENT_NOT_ENABLED', 'The agent is not enabled.');
|
|
84
99
|
if (!deps.agents.mayInvoke(agent, userId))
|
|
85
100
|
throw forbidden('You may not wake this agent.');
|
|
86
101
|
return agent;
|
|
87
102
|
}
|
|
88
103
|
async function createRun(unit, agent, values) {
|
|
89
|
-
if (!takesType(deps.subjects.get(values.subject.kind), agent.type))
|
|
90
|
-
throw invalid(`A ${agent.type} agent cannot work on a ${values.subject.kind}.`, { reason: 'AGENT_TYPE_NOT_ALLOWED', agentType: agent.type });
|
|
91
104
|
const now = clock.now().toISOString();
|
|
92
105
|
const id = ids.next();
|
|
93
106
|
await runsRepo(unit.conn).createOne({
|
|
94
107
|
values: {
|
|
95
108
|
id,
|
|
96
109
|
agentId: agent.id,
|
|
97
|
-
agentType:
|
|
110
|
+
agentType: 'runner',
|
|
98
111
|
runnerId: null,
|
|
99
112
|
status: 'queued',
|
|
100
113
|
priority: values.priority,
|
|
@@ -106,6 +119,11 @@ export function createRunService(deps) {
|
|
|
106
119
|
subjectKind: values.subject.kind,
|
|
107
120
|
subjectId: values.subject.id,
|
|
108
121
|
threadScope: values.threadScope,
|
|
122
|
+
commentRootRunId: values.commentRootRunId === ''
|
|
123
|
+
? id
|
|
124
|
+
: (values.commentRootRunId ?? null),
|
|
125
|
+
commentExecution: values.commentExecution ?? null,
|
|
126
|
+
commentOwnerKey: values.commentOwnerKey ?? null,
|
|
109
127
|
actorUserId: values.actorUserId,
|
|
110
128
|
requestedByUserId: values.requestedByUserId,
|
|
111
129
|
confirmedByUserId: values.confirmedByUserId,
|
|
@@ -113,6 +131,7 @@ export function createRunService(deps) {
|
|
|
113
131
|
requires: cleanList([...values.requires]),
|
|
114
132
|
acceptsInput: false,
|
|
115
133
|
availableAt: values.availableAt ?? null,
|
|
134
|
+
queueEnteredAt: now,
|
|
116
135
|
leaseExpiresAt: null,
|
|
117
136
|
dispatchedAt: null,
|
|
118
137
|
startedAt: null,
|
|
@@ -208,13 +227,93 @@ export function createRunService(deps) {
|
|
|
208
227
|
actualModels: models.get(run.id) ?? [],
|
|
209
228
|
});
|
|
210
229
|
}
|
|
230
|
+
/** Cross-root appends require both sources to retain the same owner's authorization. */
|
|
231
|
+
async function equivalentCommentAuthority(unit, run, work) {
|
|
232
|
+
if (run.ownerUserId !== work.ownerUserId ||
|
|
233
|
+
(run.commentOwnerKey ?? null) !== (work.commentOwnerKey ?? null) ||
|
|
234
|
+
(run.commentExecution ?? 'owner') !== (work.commentExecution ?? 'owner'))
|
|
235
|
+
return false;
|
|
236
|
+
if ((run.commentRootRunId ?? null) === (work.commentRootRunId ?? null)) {
|
|
237
|
+
if (!run.commentRootRunId)
|
|
238
|
+
return true;
|
|
239
|
+
const root = await findCommentRoot(unit.conn, run.commentRootRunId);
|
|
240
|
+
// Requester execution keeps its own identity; it does not borrow the owner's consent.
|
|
241
|
+
if (root.commentExecution === 'requester')
|
|
242
|
+
return (root.actorUserId === work.actorUserId &&
|
|
243
|
+
(await currentCommentOwner(unit.conn, deps.subjects, root)));
|
|
244
|
+
return await authorizedRoot(root);
|
|
245
|
+
}
|
|
246
|
+
if (work.commentExecution === 'requester' ||
|
|
247
|
+
run.commentExecution === 'requester' ||
|
|
248
|
+
!work.sourceRunId)
|
|
249
|
+
return false;
|
|
250
|
+
const source = await findRunRecord(unit.conn, work.sourceRunId);
|
|
251
|
+
if (!source ||
|
|
252
|
+
source.subjectKind !== run.subjectKind ||
|
|
253
|
+
source.subjectId !== run.subjectId ||
|
|
254
|
+
source.ownerUserId !== run.ownerUserId ||
|
|
255
|
+
source.actorUserId !== run.actorUserId)
|
|
256
|
+
return false;
|
|
257
|
+
const sourceRoot = source.commentRootRunId
|
|
258
|
+
? await findCommentRoot(unit.conn, source.commentRootRunId)
|
|
259
|
+
: source;
|
|
260
|
+
const targetRoot = run.commentRootRunId
|
|
261
|
+
? await findCommentRoot(unit.conn, run.commentRootRunId)
|
|
262
|
+
: run;
|
|
263
|
+
return ((await authorizedRoot(sourceRoot)) && (await authorizedRoot(targetRoot)));
|
|
264
|
+
async function authorizedRoot(root) {
|
|
265
|
+
if (!(await currentCommentOwner(unit.conn, deps.subjects, root)))
|
|
266
|
+
return false;
|
|
267
|
+
if (!root.commentRootRunId)
|
|
268
|
+
return chainSourceOf(root) === root.ownerUserId;
|
|
269
|
+
const { decision } = await commentConsent(unit.conn, root);
|
|
270
|
+
if (decision === 'pending' || decision === 'rejected')
|
|
271
|
+
return false;
|
|
272
|
+
return (decision === 'confirmed' || (await commentFromOwner(unit.conn, root)));
|
|
273
|
+
}
|
|
274
|
+
}
|
|
211
275
|
/**
|
|
212
276
|
* Queues `work` for `agent`: it joins the run working on its key while that run can still be told, else the run
|
|
213
277
|
* waiting for it, else starts a new run.
|
|
214
278
|
*/
|
|
215
279
|
async function queue(unit, agent, work) {
|
|
280
|
+
if (work.commentRootRunId) {
|
|
281
|
+
// A plain read: the root's subject never changes, and the agent lock below serializes the chain's enqueues.
|
|
282
|
+
const root = await findCommentRoot(unit.conn, work.commentRootRunId);
|
|
283
|
+
if (root.subjectKind !== work.subject.kind ||
|
|
284
|
+
root.subjectId !== work.subject.id)
|
|
285
|
+
throw invalid('A comment authorization cannot cross subjects.');
|
|
286
|
+
}
|
|
216
287
|
// Serializes enqueues and claims for this agent, so a key never gets two waiting runs.
|
|
217
288
|
await lockAgentForClaim(unit.conn, agent.id, clock.now().toISOString());
|
|
289
|
+
if (work.preferActive) {
|
|
290
|
+
const commentId = jsonObject(work.input.payload).commentId;
|
|
291
|
+
if (typeof commentId === 'string') {
|
|
292
|
+
const prior = await inputsRepo(unit.conn).findOne({
|
|
293
|
+
filter: (f) => f.and([
|
|
294
|
+
f.string('type').eq('comment'),
|
|
295
|
+
f.json('payload').path(['commentId']).eq(commentId),
|
|
296
|
+
f
|
|
297
|
+
.relation('run')
|
|
298
|
+
.some((r) => r.and([
|
|
299
|
+
r.string('agentId').eq(agent.id),
|
|
300
|
+
r.string('subjectKind').eq(work.subject.kind),
|
|
301
|
+
r.string('subjectId').eq(work.subject.id),
|
|
302
|
+
])),
|
|
303
|
+
]),
|
|
304
|
+
});
|
|
305
|
+
if (prior) {
|
|
306
|
+
const run = (await findRunRecord(unit.conn, prior.runId));
|
|
307
|
+
return {
|
|
308
|
+
runId: run.id,
|
|
309
|
+
inputId: prior.id,
|
|
310
|
+
outcome: 'appended',
|
|
311
|
+
status: run.status,
|
|
312
|
+
duplicate: true,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
218
317
|
const key = {
|
|
219
318
|
agentId: agent.id,
|
|
220
319
|
subjectKind: work.subject.kind,
|
|
@@ -223,24 +322,87 @@ export function createRunService(deps) {
|
|
|
223
322
|
};
|
|
224
323
|
// Only into work done as the same person: merged into another's run, it would borrow their identity, or wait
|
|
225
324
|
// for a runner that never takes it.
|
|
226
|
-
const
|
|
227
|
-
const
|
|
228
|
-
(run.
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
325
|
+
const unfiltered = await runsOfKey(unit.conn, key, ['queued', ...ACTIVE], work.actorUserId);
|
|
326
|
+
const open = unfiltered.filter((run) => (run.commentRootRunId ?? null) === (work.commentRootRunId ?? null) &&
|
|
327
|
+
(run.commentExecution ?? null) === (work.commentExecution ?? null));
|
|
328
|
+
let working;
|
|
329
|
+
for (let candidate of work.preferActive ? unfiltered : open) {
|
|
330
|
+
if (work.freshSession ||
|
|
331
|
+
candidate.cancelRequestedAt ||
|
|
332
|
+
!(candidate.status === 'dispatched' ||
|
|
333
|
+
(candidate.status === 'running' && Boolean(candidate.acceptsInput))))
|
|
334
|
+
continue;
|
|
335
|
+
if (work.preferActive) {
|
|
336
|
+
if (!candidate.runnerId ||
|
|
337
|
+
!['claude', 'codex', 'pi', 'opencode'].includes(candidate.tool ?? ''))
|
|
338
|
+
continue;
|
|
339
|
+
const runner = await deps.runners.find(unit.conn, candidate.runnerId);
|
|
340
|
+
if (!runner?.features.includes('steer'))
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
for (let attempt = 0; attempt < 4; attempt += 1) {
|
|
344
|
+
if (work.preferActive &&
|
|
345
|
+
!(await equivalentCommentAuthority(unit, candidate, work)))
|
|
346
|
+
break;
|
|
347
|
+
const input = {
|
|
235
348
|
id: '',
|
|
236
349
|
at: clock.now().toISOString(),
|
|
237
350
|
...work.input,
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
351
|
+
...(candidate.commentRootRunId
|
|
352
|
+
? {
|
|
353
|
+
payload: {
|
|
354
|
+
...jsonObject(work.input.payload),
|
|
355
|
+
commentRootRunId: candidate.commentRootRunId,
|
|
356
|
+
},
|
|
357
|
+
}
|
|
358
|
+
: {}),
|
|
359
|
+
};
|
|
360
|
+
if ((await gateInputs(unit.conn, deps, candidate, agent, [input]))
|
|
361
|
+
.length === 0)
|
|
362
|
+
break;
|
|
363
|
+
const touched = await runsRepo(unit.conn).updateMany({
|
|
364
|
+
filter: (f) => f.and([
|
|
365
|
+
f.string('id').eq(candidate.id),
|
|
366
|
+
f.string('status').eq(candidate.status),
|
|
367
|
+
f.number('revision').eq(candidate.revision),
|
|
368
|
+
f.date('cancelRequestedAt').empty(),
|
|
369
|
+
]),
|
|
370
|
+
values: { updatedAt: clock.now().toISOString() },
|
|
371
|
+
});
|
|
372
|
+
if (touched.updatedCount === 1) {
|
|
373
|
+
working = candidate;
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
const current = await findRunRecord(unit.conn, candidate.id);
|
|
377
|
+
if (!current ||
|
|
378
|
+
current.cancelRequestedAt ||
|
|
379
|
+
!(current.status === 'dispatched' ||
|
|
380
|
+
(current.status === 'running' && current.acceptsInput)))
|
|
381
|
+
break;
|
|
382
|
+
// A claim/start may change the holder or tool; re-evaluate those on a subsequent dispatch.
|
|
383
|
+
if (current.actorUserId !== work.actorUserId ||
|
|
384
|
+
current.threadScope !== work.threadScope ||
|
|
385
|
+
current.runnerId !== candidate.runnerId ||
|
|
386
|
+
current.tool !== candidate.tool)
|
|
387
|
+
break;
|
|
388
|
+
candidate = current;
|
|
389
|
+
if (attempt === 3)
|
|
390
|
+
throw conflict('The run revision changed during append; retry the dispatch.');
|
|
391
|
+
}
|
|
392
|
+
if (working)
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
242
395
|
const waiting = open.find((run) => run.status === 'queued');
|
|
243
396
|
const target = working ?? waiting;
|
|
397
|
+
const commentInput = (rootId) => rootId
|
|
398
|
+
? {
|
|
399
|
+
...work.input,
|
|
400
|
+
payload: {
|
|
401
|
+
...jsonObject(work.input.payload),
|
|
402
|
+
commentRootRunId: rootId,
|
|
403
|
+
},
|
|
404
|
+
}
|
|
405
|
+
: work.input;
|
|
244
406
|
if (!working && waiting)
|
|
245
407
|
await hurry(unit, waiting, work.priority, work.fireAt);
|
|
246
408
|
if (target) {
|
|
@@ -249,7 +411,7 @@ export function createRunService(deps) {
|
|
|
249
411
|
filter: { id: target.id, status: 'queued' },
|
|
250
412
|
values: { freshSession: true, updatedAt: clock.now().toISOString() },
|
|
251
413
|
});
|
|
252
|
-
const inputId = await insertInput(unit, target.id,
|
|
414
|
+
const inputId = await insertInput(unit, target.id, commentInput(target.commentRootRunId));
|
|
253
415
|
return {
|
|
254
416
|
runId: target.id,
|
|
255
417
|
outcome: working ? 'appended' : 'merged',
|
|
@@ -258,6 +420,9 @@ export function createRunService(deps) {
|
|
|
258
420
|
};
|
|
259
421
|
}
|
|
260
422
|
const runId = await createRun(unit, agent, {
|
|
423
|
+
commentRootRunId: work.commentRootRunId,
|
|
424
|
+
commentExecution: work.commentExecution,
|
|
425
|
+
commentOwnerKey: work.commentOwnerKey,
|
|
261
426
|
freshSession: work.freshSession,
|
|
262
427
|
subject: work.subject,
|
|
263
428
|
threadScope: work.threadScope,
|
|
@@ -272,16 +437,23 @@ export function createRunService(deps) {
|
|
|
272
437
|
...(work.parentRunId ? { parentRunId: work.parentRunId } : {}),
|
|
273
438
|
...(work.maxAttempts ? { maxAttempts: work.maxAttempts } : {}),
|
|
274
439
|
});
|
|
275
|
-
const inputId = await insertInput(unit, runId, work.
|
|
440
|
+
const inputId = await insertInput(unit, runId, commentInput(work.commentRootRunId === '' ? runId : work.commentRootRunId));
|
|
276
441
|
return { runId, outcome: 'created', status: 'queued', inputId };
|
|
277
442
|
}
|
|
278
443
|
/** The source of the chain of work a request belongs to (`EnqueueRequest.requestedByUserId`). */
|
|
279
444
|
async function sourceOf(unit, request) {
|
|
445
|
+
if (request.comment &&
|
|
446
|
+
request.input.actor.kind === 'user' &&
|
|
447
|
+
jsonObject(request.input.payload).byAgent !== true &&
|
|
448
|
+
(request.requestedByUserId ?? request.actorUserId))
|
|
449
|
+
return (request.requestedByUserId ?? request.actorUserId);
|
|
280
450
|
if (request.causedByRunId) {
|
|
281
451
|
const cause = await findRunRecord(unit.conn, request.causedByRunId);
|
|
282
452
|
if (!cause)
|
|
283
453
|
throw invalid('causedByRunId names no run.');
|
|
284
|
-
return
|
|
454
|
+
return request.comment
|
|
455
|
+
? (cause.requestedByUserId ?? cause.actorUserId)
|
|
456
|
+
: chainSourceOf(cause);
|
|
285
457
|
}
|
|
286
458
|
const source = request.requestedByUserId ??
|
|
287
459
|
request.actorUserId ??
|
|
@@ -290,10 +462,23 @@ export function createRunService(deps) {
|
|
|
290
462
|
throw invalid('Name who woke the agent: actorUserId, requestedByUserId or responsibleUserId.');
|
|
291
463
|
return source;
|
|
292
464
|
}
|
|
465
|
+
async function selectedIdentity(unit, request, commentExecution) {
|
|
466
|
+
const identity = await deps.subjects
|
|
467
|
+
.get(request.subject.kind)
|
|
468
|
+
?.actsAs?.(unit.conn, {
|
|
469
|
+
subjectId: request.subject.id,
|
|
470
|
+
agentId: request.agentId,
|
|
471
|
+
causedByRunId: request.causedByRunId,
|
|
472
|
+
commentExecution,
|
|
473
|
+
actorUserId: request.actorUserId,
|
|
474
|
+
inputs: [request.input],
|
|
475
|
+
});
|
|
476
|
+
if (identity && !identity.actorUserId)
|
|
477
|
+
throw new ProtocolError('FORBIDDEN', 'The subject has no valid execution identity.', { identityReason: identity.reason ?? 'noOwner' });
|
|
478
|
+
return identity;
|
|
479
|
+
}
|
|
293
480
|
/** Refuses work run as `userId` when no runner they may use can run the agent now: it would only wait. */
|
|
294
481
|
async function requireRunnerFor(unit, agent, userId, requires) {
|
|
295
|
-
if (agent.type !== 'runner')
|
|
296
|
-
return;
|
|
297
482
|
// By the claim's own rules, the agent's variables included; the subject's are the claim's to check.
|
|
298
483
|
if (!(await deps.eligibility.canClaim(unit.conn, agent, {
|
|
299
484
|
actorUserId: userId,
|
|
@@ -312,26 +497,225 @@ export function createRunService(deps) {
|
|
|
312
497
|
mayInvoke: (agent, userId) => deps.agents.mayInvoke(agent, userId),
|
|
313
498
|
requireInvocable,
|
|
314
499
|
requireRunnerFor,
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
500
|
+
prepareCommentActor: async (record, byUserId) => {
|
|
501
|
+
const mayRead = deps.subjects.get(record.subjectKind)?.commentActorMayRead;
|
|
502
|
+
if (mayRead && !(await mayRead(record.subjectId, byUserId)))
|
|
503
|
+
throw forbidden('The acting user may no longer read this issue.');
|
|
504
|
+
},
|
|
505
|
+
checkCommentRequest: async (unit, record) => {
|
|
506
|
+
const root = await findCommentRoot(unit.conn, record.commentRootRunId);
|
|
507
|
+
if (!(await currentCommentOwner(unit.conn, deps.subjects, root)) ||
|
|
508
|
+
root.commentExecution !== 'owner' ||
|
|
509
|
+
root.ownerUserId !== record.responsibleUserId ||
|
|
510
|
+
(root.commentOwnerKey ?? null) !== (record.commentOwnerKey ?? null))
|
|
511
|
+
throw precondition('RUN_REQUEST_SETTLED', 'This comment request belongs to an earlier owner assignment.');
|
|
512
|
+
},
|
|
513
|
+
releaseCommentRequest: async (unit, record, byUserId) => {
|
|
514
|
+
const run = await findRunRecord(unit.conn, record.commentRunId);
|
|
515
|
+
if (!run ||
|
|
516
|
+
run.status !== 'queued' ||
|
|
517
|
+
run.commentRootRunId !== record.commentRootRunId)
|
|
518
|
+
throw precondition('RUN_REQUEST_SETTLED', 'The requested work is no longer waiting.');
|
|
519
|
+
const inputs = await pendingInputs(unit.conn, run.id);
|
|
520
|
+
const now = clock.now().toISOString();
|
|
521
|
+
// Guarded on the requested run itself: a claim that took it first wins, and this confirmation rolls back.
|
|
522
|
+
const released = await runsRepo(unit.conn).updateMany({
|
|
523
|
+
filter: { id: run.id, status: 'queued' },
|
|
524
|
+
values: { confirmedByUserId: byUserId, updatedAt: now },
|
|
525
|
+
});
|
|
526
|
+
if (released.updatedCount !== 1)
|
|
527
|
+
throw precondition('RUN_REQUEST_SETTLED', 'The requested work is no longer waiting.');
|
|
528
|
+
await runsRepo(unit.conn).updateMany({
|
|
529
|
+
filter: {
|
|
530
|
+
commentRootRunId: record.commentRootRunId,
|
|
531
|
+
status: 'queued',
|
|
532
|
+
actorUserId: record.responsibleUserId,
|
|
533
|
+
},
|
|
534
|
+
values: { confirmedByUserId: byUserId, updatedAt: now },
|
|
535
|
+
});
|
|
536
|
+
unit.emit({ type: 'run.changed', runId: run.id, status: 'queued' });
|
|
537
|
+
return {
|
|
538
|
+
runId: run.id,
|
|
539
|
+
outcome: 'merged',
|
|
540
|
+
status: 'queued',
|
|
541
|
+
inputId: inputs[0].id,
|
|
542
|
+
};
|
|
543
|
+
},
|
|
544
|
+
cancelCommentRequest: async (unit, record, byUserId) => {
|
|
545
|
+
for (const run of await runsRepo(unit.conn).findMany({
|
|
546
|
+
filter: { commentRootRunId: record.commentRootRunId },
|
|
547
|
+
}))
|
|
548
|
+
if (!isTerminal(run.status))
|
|
549
|
+
await endCommentRun(unit, run, byUserId);
|
|
550
|
+
},
|
|
551
|
+
runCommentAsRequester: async (unit, record, byUserId) => {
|
|
552
|
+
// Queuing the replacements takes their agents' rows, as claims do before they take a run. Taking every agent of
|
|
553
|
+
// the chain first, in one order, keeps this from holding a run a claim waits on while it waits for that claim.
|
|
554
|
+
const agentIds = new Set((await runsRepo(unit.conn).findMany({
|
|
555
|
+
filter: { commentRootRunId: record.commentRootRunId },
|
|
556
|
+
})).map((run) => run.agentId));
|
|
557
|
+
for (const agentId of [...agentIds].sort())
|
|
558
|
+
await lockAgentForClaim(unit.conn, agentId, clock.now().toISOString());
|
|
559
|
+
const chain = await runsRepo(unit.conn).findMany({
|
|
560
|
+
filter: { commentRootRunId: record.commentRootRunId },
|
|
561
|
+
sort: (sort) => [sort.field('createdAt').asc(), sort.field('id').asc()],
|
|
562
|
+
});
|
|
563
|
+
const targets = [];
|
|
564
|
+
for (const old of chain) {
|
|
565
|
+
// Rejection ends the queued chain, but leaves its inputs unhandled. Do not revive independently ended work.
|
|
566
|
+
const declined = record.status === 'rejected' &&
|
|
567
|
+
old.status === 'cancelled' &&
|
|
568
|
+
old.cancelledById === record.responsibleUserId &&
|
|
569
|
+
old.failureDetail === COMMENT_CANCEL_DETAIL;
|
|
570
|
+
if (isTerminal(old.status) && !declined)
|
|
571
|
+
continue;
|
|
572
|
+
const inputs = await pendingInputs(unit.conn, old.id);
|
|
573
|
+
if (inputs.length === 0)
|
|
574
|
+
continue;
|
|
575
|
+
await selectedIdentity(unit, {
|
|
576
|
+
agentId: old.agentId,
|
|
577
|
+
subject: { kind: old.subjectKind, id: old.subjectId },
|
|
578
|
+
input: toInput(inputs[0]),
|
|
579
|
+
actorUserId: byUserId,
|
|
580
|
+
}, 'requester');
|
|
581
|
+
const agent = await requireInvocable(unit, old.agentId, byUserId);
|
|
582
|
+
const requires = stringArray(old.requires);
|
|
583
|
+
await requireRunnerFor(unit, agent, byUserId, requires);
|
|
584
|
+
targets.push({ old, inputs, agent, requires });
|
|
585
|
+
}
|
|
586
|
+
if (!targets.length)
|
|
587
|
+
throw precondition('RUN_REQUEST_SETTLED', 'No comment work is still waiting.');
|
|
588
|
+
// Validate all targets before stopping any of them. Each stop is guarded on the status read, so a run a claim took
|
|
589
|
+
// meanwhile rolls this back rather than being replaced twice; the settled request covers repeat clicks.
|
|
590
|
+
for (const old of chain)
|
|
591
|
+
if (!isTerminal(old.status))
|
|
592
|
+
await endCommentRun(unit, old, byUserId);
|
|
593
|
+
const replacements = new Map();
|
|
594
|
+
let rootId;
|
|
595
|
+
for (const { old, inputs, agent, requires } of targets) {
|
|
596
|
+
const first = inputs[0];
|
|
597
|
+
const next = await queue(unit, agent, {
|
|
598
|
+
commentRootRunId: rootId ?? '',
|
|
599
|
+
commentExecution: 'requester',
|
|
600
|
+
commentOwnerKey: record.commentOwnerKey ?? null,
|
|
601
|
+
freshSession: Boolean(old.freshSession),
|
|
602
|
+
subject: { kind: old.subjectKind, id: old.subjectId },
|
|
603
|
+
threadScope: old.threadScope,
|
|
604
|
+
actorUserId: byUserId,
|
|
605
|
+
requestedByUserId: byUserId,
|
|
606
|
+
confirmedByUserId: null,
|
|
607
|
+
ownerUserId: old.ownerUserId,
|
|
608
|
+
priority: Number(old.priority),
|
|
609
|
+
fireAt: fireAtOf(old.availableAt ?? undefined, clock.now()),
|
|
610
|
+
requires,
|
|
611
|
+
maxAttempts: Number(old.maxAttempts),
|
|
612
|
+
input: toInput(first),
|
|
613
|
+
});
|
|
614
|
+
rootId ??= next.runId;
|
|
615
|
+
replacements.set(old.id, next);
|
|
616
|
+
for (const input of inputs.slice(1))
|
|
617
|
+
await insertInput(unit, next.runId, {
|
|
618
|
+
...toInput(input),
|
|
619
|
+
payload: { ...jsonObject(input.payload), commentRootRunId: rootId },
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
// Remap causal references only for replaced work; completed ancestors remain the original historical runs.
|
|
623
|
+
for (const { old } of targets) {
|
|
624
|
+
const next = replacements.get(old.id);
|
|
625
|
+
if (old.parentRunId)
|
|
626
|
+
await runsRepo(unit.conn).updateMany({
|
|
627
|
+
filter: { id: next.runId },
|
|
628
|
+
values: {
|
|
629
|
+
parentRunId: replacements.get(old.parentRunId)?.runId ?? old.parentRunId,
|
|
630
|
+
},
|
|
631
|
+
});
|
|
632
|
+
for (const input of await pendingInputs(unit.conn, next.runId)) {
|
|
633
|
+
const payload = jsonObject(input.payload);
|
|
634
|
+
const cause = typeof payload.causedByRunId === 'string'
|
|
635
|
+
? replacements.get(payload.causedByRunId)
|
|
636
|
+
: undefined;
|
|
637
|
+
if (cause)
|
|
638
|
+
await inputsRepo(unit.conn).updateMany({
|
|
639
|
+
filter: { id: input.id },
|
|
640
|
+
values: {
|
|
641
|
+
payload: asJson({ ...payload, causedByRunId: cause.runId }),
|
|
642
|
+
},
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
const rootInputs = await pendingInputs(unit.conn, rootId);
|
|
647
|
+
if (!rootInputs.some((input) => input.type === record.inputType &&
|
|
648
|
+
input.text === record.inputText &&
|
|
649
|
+
jsonObject(input.payload).commentId ===
|
|
650
|
+
jsonObject(record.inputPayload).commentId)) {
|
|
651
|
+
const sourceId = await insertInput(unit, rootId, {
|
|
652
|
+
type: record.inputType,
|
|
653
|
+
actor: {
|
|
654
|
+
kind: record.inputActorKind,
|
|
655
|
+
id: record.inputActorId,
|
|
656
|
+
name: record.inputActorName,
|
|
657
|
+
},
|
|
658
|
+
text: record.inputText,
|
|
659
|
+
payload: {
|
|
660
|
+
...jsonObject(record.inputPayload),
|
|
661
|
+
commentSourceSnapshot: true,
|
|
662
|
+
commentRootRunId: rootId,
|
|
663
|
+
},
|
|
664
|
+
});
|
|
665
|
+
await inputsRepo(unit.conn).updateMany({
|
|
666
|
+
filter: { id: sourceId },
|
|
667
|
+
values: { handledAt: clock.now().toISOString() },
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
return (replacements.get(record.commentRunId) ??
|
|
671
|
+
replacements.values().next().value);
|
|
672
|
+
},
|
|
673
|
+
direct: async (unit, run) => {
|
|
674
|
+
const identity = await selectedIdentity(unit, {
|
|
675
|
+
agentId: run.agent.id,
|
|
676
|
+
subject: run.subject,
|
|
677
|
+
input: run.input,
|
|
678
|
+
actorUserId: run.actorUserId,
|
|
679
|
+
});
|
|
680
|
+
const actorUserId = identity?.actorUserId ?? run.actorUserId;
|
|
681
|
+
const agent = await requireInvocable(unit, run.agent.id, actorUserId);
|
|
682
|
+
return queue(unit, agent, {
|
|
683
|
+
freshSession: run.freshSession,
|
|
684
|
+
subject: run.subject,
|
|
685
|
+
threadScope: run.threadScope,
|
|
686
|
+
actorUserId,
|
|
687
|
+
requestedByUserId: run.requestedByUserId,
|
|
688
|
+
confirmedByUserId: run.confirmedByUserId,
|
|
689
|
+
ownerUserId: identity ? actorUserId : run.ownerUserId,
|
|
690
|
+
priority: run.priority,
|
|
691
|
+
fireAt: fireAtOf(run.fireAt ?? undefined, clock.now()),
|
|
692
|
+
requires: run.requires,
|
|
693
|
+
...(run.maxAttempts === null ? {} : { maxAttempts: run.maxAttempts }),
|
|
694
|
+
input: run.input,
|
|
695
|
+
});
|
|
696
|
+
},
|
|
330
697
|
});
|
|
331
698
|
return {
|
|
332
699
|
enqueue: (request, outer) => tx.run(async (unit) => {
|
|
333
700
|
const source = await sourceOf(unit, request);
|
|
334
|
-
const
|
|
701
|
+
const cause = request.causedByRunId
|
|
702
|
+
? await findRunRecord(unit.conn, request.causedByRunId)
|
|
703
|
+
: null;
|
|
704
|
+
const inherited = !request.comment &&
|
|
705
|
+
cause?.commentRootRunId &&
|
|
706
|
+
cause.subjectKind === request.subject.kind &&
|
|
707
|
+
cause.subjectId === request.subject.id
|
|
708
|
+
? cause
|
|
709
|
+
: null;
|
|
710
|
+
const commentRootRunId = request.comment?.rootRunId ??
|
|
711
|
+
inherited?.commentRootRunId ??
|
|
712
|
+
(request.comment ? '' : null);
|
|
713
|
+
const commentExecution = inherited?.commentExecution ?? (request.comment ? 'owner' : null);
|
|
714
|
+
const commentOwnerKey = request.comment?.ownerKey ?? inherited?.commentOwnerKey ?? null;
|
|
715
|
+
const identity = await selectedIdentity(unit, request, commentExecution);
|
|
716
|
+
const responsible = identity
|
|
717
|
+
? null
|
|
718
|
+
: (request.responsibleUserId ?? null);
|
|
335
719
|
const threadScope = request.threadScope ?? DEFAULT_THREAD;
|
|
336
720
|
const foreign = responsible !== null && source !== responsible;
|
|
337
721
|
if (foreign && (request.execution ?? 'auto') === 'auto') {
|
|
@@ -342,8 +726,6 @@ export function createRunService(deps) {
|
|
|
342
726
|
const agent = await requireInvocable(unit, request.agentId, source);
|
|
343
727
|
if (!deps.agents.mayInvoke(agent, responsible))
|
|
344
728
|
throw forbidden('The person who answers for this may not wake this agent.');
|
|
345
|
-
if (!takesType(deps.subjects.get(request.subject.kind), agent.type))
|
|
346
|
-
throw invalid(`A ${agent.type} agent cannot work on a ${request.subject.kind}.`, { reason: 'AGENT_TYPE_NOT_ALLOWED', agentType: agent.type });
|
|
347
729
|
const created = await insertRunRequest(unit, { ids, clock }, {
|
|
348
730
|
agentId: agent.id,
|
|
349
731
|
freshSession: request.freshSession,
|
|
@@ -368,20 +750,30 @@ export function createRunService(deps) {
|
|
|
368
750
|
}
|
|
369
751
|
// As the responsible when they caused it; as the source when they run it as themselves (`mine`); as whoever
|
|
370
752
|
// woke the agent when nobody answers for the subject.
|
|
371
|
-
const actorUserId =
|
|
372
|
-
?
|
|
373
|
-
:
|
|
753
|
+
const actorUserId = (commentExecution === 'requester'
|
|
754
|
+
? inherited?.actorUserId
|
|
755
|
+
: identity?.actorUserId) ??
|
|
756
|
+
(foreign ? source : (responsible ?? request.actorUserId ?? source));
|
|
374
757
|
const agent = await requireInvocable(unit, request.agentId, actorUserId);
|
|
375
758
|
if (foreign)
|
|
376
759
|
await requireRunnerFor(unit, agent, actorUserId, request.requires ?? []);
|
|
377
|
-
|
|
760
|
+
const result = await queue(unit, agent, {
|
|
761
|
+
preferActive: request.preferActive,
|
|
762
|
+
sourceRunId: request.causedByRunId,
|
|
763
|
+
commentRootRunId,
|
|
764
|
+
commentExecution,
|
|
765
|
+
commentOwnerKey,
|
|
378
766
|
freshSession: request.freshSession,
|
|
379
767
|
subject: request.subject,
|
|
380
768
|
threadScope,
|
|
381
769
|
actorUserId,
|
|
382
770
|
requestedByUserId: source,
|
|
383
|
-
confirmedByUserId: null,
|
|
384
|
-
ownerUserId:
|
|
771
|
+
confirmedByUserId: inherited?.confirmedByUserId ?? null,
|
|
772
|
+
ownerUserId: commentExecution === 'requester'
|
|
773
|
+
? (inherited?.ownerUserId ?? request.ownerUserId ?? null)
|
|
774
|
+
: identity
|
|
775
|
+
? actorUserId
|
|
776
|
+
: (request.ownerUserId ?? null),
|
|
385
777
|
priority: request.priority ?? 0,
|
|
386
778
|
fireAt: fireAtOf(request.fireAt, clock.now()),
|
|
387
779
|
requires: request.requires ?? [],
|
|
@@ -389,12 +781,45 @@ export function createRunService(deps) {
|
|
|
389
781
|
...(request.maxAttempts ? { maxAttempts: request.maxAttempts } : {}),
|
|
390
782
|
input: request.input,
|
|
391
783
|
});
|
|
784
|
+
if (commentRootRunId !== null)
|
|
785
|
+
await deps.reconcileCommentConsent?.(unit, result.runId);
|
|
786
|
+
return result;
|
|
392
787
|
}, outer),
|
|
393
788
|
requests,
|
|
789
|
+
identityInputs: async (conn, runId) => {
|
|
790
|
+
const run = await findRunRecord(conn, runId);
|
|
791
|
+
if (!run)
|
|
792
|
+
return null;
|
|
793
|
+
const inputs = await inputsRepo(conn).findMany({ filter: { runId } });
|
|
794
|
+
return { run: toRun(run), inputs: inputs.map(toInput) };
|
|
795
|
+
},
|
|
394
796
|
addInput: (runId, input, outer) => tx.run(async (unit) => {
|
|
395
797
|
const run = await require(unit.conn, runId);
|
|
798
|
+
if (run.commentRootRunId &&
|
|
799
|
+
input.type === 'comment' &&
|
|
800
|
+
jsonObject(input.payload).commentRootRunId !== run.commentRootRunId)
|
|
801
|
+
throw forbidden('A comment must be queued in its own authorized run chain.');
|
|
396
802
|
if (isTerminal(run.status))
|
|
397
803
|
throw new ProtocolError('RUN_NOT_ACTIVE', `The run is ${run.status}.`);
|
|
804
|
+
if (isActive(run.status)) {
|
|
805
|
+
let current = run;
|
|
806
|
+
for (let attempt = 0; attempt < 4; attempt += 1) {
|
|
807
|
+
const updated = await runsRepo(unit.conn).updateMany({
|
|
808
|
+
filter: {
|
|
809
|
+
id: current.id,
|
|
810
|
+
status: current.status,
|
|
811
|
+
revision: current.revision,
|
|
812
|
+
},
|
|
813
|
+
values: { updatedAt: clock.now().toISOString() },
|
|
814
|
+
});
|
|
815
|
+
if (updated.updatedCount === 1)
|
|
816
|
+
return insertInput(unit, current.id, input);
|
|
817
|
+
current = await require(unit.conn, run.id);
|
|
818
|
+
if (!isActive(current.status))
|
|
819
|
+
throw conflict('The run moved on before input was appended.');
|
|
820
|
+
}
|
|
821
|
+
throw conflict('The run revision changed during append; retry the input.');
|
|
822
|
+
}
|
|
398
823
|
return insertInput(unit, run.id, input);
|
|
399
824
|
}, outer),
|
|
400
825
|
cancel: (runId, byUserId, outer) => tx.run(async (unit) => {
|
|
@@ -459,47 +884,192 @@ export function createRunService(deps) {
|
|
|
459
884
|
}
|
|
460
885
|
return ended;
|
|
461
886
|
}, outer),
|
|
462
|
-
retry: (runId, byUserId
|
|
463
|
-
const
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
887
|
+
retry: async (runId, byUserId, source = 'api') => {
|
|
888
|
+
const target = await require(tx.read(), runId);
|
|
889
|
+
// Resolve collection metadata outside the transaction too. The lock must
|
|
890
|
+
// precede consistent reads so repeatable-read databases see a concurrent
|
|
891
|
+
// retry that committed while this request waited for the lock.
|
|
892
|
+
await findAgent(tx.read(), target.agentId);
|
|
893
|
+
return tx.run(async (unit) => {
|
|
894
|
+
await lockAgentForClaim(unit.conn, target.agentId, clock.now().toISOString());
|
|
895
|
+
const run = await require(unit.conn, runId);
|
|
896
|
+
if (run.status !== 'failed' && run.status !== 'cancelled')
|
|
897
|
+
throw precondition('RUN_NOT_RETRYABLE', 'Only a failed or cancelled run can be retried.');
|
|
898
|
+
if (run.parentRunId)
|
|
899
|
+
throw precondition('RUN_NOT_RETRYABLE', 'A consultation is not retried: the agent that asked asks again.');
|
|
900
|
+
// The agent lock serializes retry and enqueue across server instances. Check
|
|
901
|
+
// the relationship even after the replacement has already ended.
|
|
902
|
+
const retried = await runsRepo(unit.conn).findOne({
|
|
903
|
+
filter: { retryOfRunId: run.id },
|
|
904
|
+
sort: (sort) => [
|
|
905
|
+
sort.field('createdAt').asc(),
|
|
906
|
+
sort.field('id').asc(),
|
|
907
|
+
],
|
|
474
908
|
});
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
909
|
+
if (retried)
|
|
910
|
+
throw precondition('RUN_ALREADY_RETRIED', 'This run has already been retried.', {
|
|
911
|
+
runId: retried.id,
|
|
912
|
+
});
|
|
913
|
+
const previousInputs = await inputsRepo(unit.conn).findMany({
|
|
914
|
+
filter: { runId: run.id },
|
|
915
|
+
});
|
|
916
|
+
if (!run.commentRootRunId &&
|
|
917
|
+
deps.subjects.get(run.subjectKind)?.commentOwnerKey &&
|
|
918
|
+
previousInputs.some((input) => input.type === 'comment' &&
|
|
919
|
+
!(input.actorKind === 'user' &&
|
|
920
|
+
input.actorId === run.ownerUserId &&
|
|
921
|
+
jsonObject(input.payload).byAgent !== true)))
|
|
922
|
+
throw precondition('RUN_NOT_RETRYABLE', 'Post the comment again to start a new authorized comment chain.');
|
|
923
|
+
const oldRoot = run.commentRootRunId
|
|
924
|
+
? await findRunRecord(unit.conn, run.commentRootRunId)
|
|
925
|
+
: null;
|
|
926
|
+
const renewComment = oldRoot
|
|
927
|
+
? !(await currentCommentOwner(unit.conn, deps.subjects, oldRoot))
|
|
928
|
+
: false;
|
|
929
|
+
const commentExecution = renewComment &&
|
|
930
|
+
run.commentExecution === 'requester' &&
|
|
931
|
+
byUserId !== run.actorUserId
|
|
932
|
+
? 'owner'
|
|
933
|
+
: run.commentExecution;
|
|
934
|
+
const identity = await deps.subjects
|
|
935
|
+
.get(run.subjectKind)
|
|
936
|
+
?.actsAs?.(unit.conn, {
|
|
937
|
+
subjectId: run.subjectId,
|
|
938
|
+
agentId: run.agentId,
|
|
939
|
+
inputs: previousInputs.map(toInput),
|
|
940
|
+
causedByRunId: run.retryOfRunId ?? undefined,
|
|
941
|
+
commentExecution,
|
|
942
|
+
actorUserId: run.actorUserId,
|
|
943
|
+
});
|
|
944
|
+
if (identity && !identity.actorUserId)
|
|
945
|
+
throw forbidden(identity.reason ?? 'noOwner');
|
|
946
|
+
const actorUserId = commentExecution === 'requester'
|
|
947
|
+
? run.actorUserId
|
|
948
|
+
: (identity?.actorUserId ?? byUserId);
|
|
949
|
+
const agent = await requireInvocable(unit, run.agentId, actorUserId);
|
|
950
|
+
const open = await runsOfKey(unit.conn, run, ['queued', ...ACTIVE], actorUserId);
|
|
951
|
+
const sameChain = run.commentRootRunId
|
|
952
|
+
? open.filter((candidate) => candidate.commentRootRunId === run.commentRootRunId)
|
|
953
|
+
: open;
|
|
954
|
+
if (sameChain.length > 0)
|
|
955
|
+
throw precondition('AGENT_BUSY', 'The agent is already working on this.', {
|
|
956
|
+
runId: sameChain[0].id,
|
|
957
|
+
});
|
|
958
|
+
const newId = await createRun(unit, agent, {
|
|
959
|
+
subject: { kind: run.subjectKind, id: run.subjectId },
|
|
960
|
+
threadScope: run.threadScope,
|
|
961
|
+
actorUserId,
|
|
962
|
+
commentRootRunId: renewComment ? '' : run.commentRootRunId,
|
|
963
|
+
commentExecution,
|
|
964
|
+
commentOwnerKey: renewComment
|
|
965
|
+
? ((await deps.subjects
|
|
966
|
+
.get(run.subjectKind)
|
|
967
|
+
?.commentOwnerKey?.(unit.conn, run.subjectId)) ?? null)
|
|
968
|
+
: run.commentOwnerKey,
|
|
969
|
+
requestedByUserId: run.commentRootRunId
|
|
970
|
+
? (run.requestedByUserId ?? run.actorUserId)
|
|
971
|
+
: byUserId,
|
|
972
|
+
confirmedByUserId: null,
|
|
973
|
+
ownerUserId: run.commentRootRunId
|
|
974
|
+
? ((await deps.subjects
|
|
975
|
+
.get(run.subjectKind)
|
|
976
|
+
?.responsibleUserId?.(unit.conn, run.subjectId)) ?? null)
|
|
977
|
+
: identity
|
|
978
|
+
? actorUserId
|
|
979
|
+
: run.ownerUserId,
|
|
980
|
+
priority: Number(run.priority),
|
|
981
|
+
requires: toRun(run).requires,
|
|
982
|
+
retryOfRunId: run.id,
|
|
983
|
+
freshSession: run.freshSession,
|
|
984
|
+
});
|
|
985
|
+
if (renewComment && oldRoot) {
|
|
986
|
+
const origins = await inputsRepo(unit.conn).findMany({
|
|
987
|
+
filter: { runId: oldRoot.id },
|
|
988
|
+
sort: (s) => [s.field('createdAt').asc(), s.field('id').asc()],
|
|
989
|
+
});
|
|
990
|
+
const origin = origins.find((input) => input.type === 'comment' &&
|
|
991
|
+
jsonObject(input.payload).commentSourceSnapshot === true) ?? origins.find((input) => input.type === 'comment');
|
|
992
|
+
if (origin) {
|
|
993
|
+
const snapshotId = await insertInput(unit, newId, {
|
|
994
|
+
type: 'comment',
|
|
995
|
+
actor: toInput(origin).actor,
|
|
996
|
+
text: origin.text,
|
|
997
|
+
payload: {
|
|
998
|
+
...jsonObject(origin.payload),
|
|
999
|
+
commentRootRunId: newId,
|
|
1000
|
+
commentSourceSnapshot: true,
|
|
1001
|
+
},
|
|
1002
|
+
});
|
|
1003
|
+
await inputsRepo(unit.conn).updateMany({
|
|
1004
|
+
filter: { id: snapshotId },
|
|
1005
|
+
values: { handledAt: clock.now().toISOString() },
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
for (const input of await pendingInputs(unit.conn, run.id))
|
|
1010
|
+
await insertInput(unit, newId, {
|
|
1011
|
+
type: input.type,
|
|
1012
|
+
actor: toInput(input).actor,
|
|
1013
|
+
text: input.text,
|
|
1014
|
+
...(input.payload === null
|
|
1015
|
+
? {}
|
|
1016
|
+
: {
|
|
1017
|
+
payload: {
|
|
1018
|
+
...jsonObject(input.payload),
|
|
1019
|
+
...(renewComment ? { commentRootRunId: newId } : {}),
|
|
1020
|
+
},
|
|
1021
|
+
}),
|
|
1022
|
+
});
|
|
488
1023
|
await insertInput(unit, newId, {
|
|
489
|
-
type:
|
|
490
|
-
actor:
|
|
491
|
-
|
|
492
|
-
|
|
1024
|
+
type: 'retry',
|
|
1025
|
+
actor: {
|
|
1026
|
+
kind: 'user',
|
|
1027
|
+
id: byUserId,
|
|
1028
|
+
name: (await deps.people.names(unit.conn, [byUserId])).get(byUserId) ??
|
|
1029
|
+
byUserId,
|
|
1030
|
+
},
|
|
1031
|
+
text: 'Retry the work of the previous run.',
|
|
1032
|
+
payload: {
|
|
1033
|
+
retryOfRunId: run.id,
|
|
1034
|
+
failureReason: run.failureReason,
|
|
1035
|
+
source,
|
|
1036
|
+
},
|
|
493
1037
|
});
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
1038
|
+
unit.emit({
|
|
1039
|
+
type: 'run.retried',
|
|
1040
|
+
runId: newId,
|
|
1041
|
+
retryOfRunId: run.id,
|
|
1042
|
+
previousStatus: run.status,
|
|
1043
|
+
});
|
|
1044
|
+
if (run.commentRootRunId)
|
|
1045
|
+
await deps.reconcileCommentConsent?.(unit, newId);
|
|
1046
|
+
return toRun(await require(unit.conn, newId));
|
|
499
1047
|
});
|
|
500
|
-
|
|
501
|
-
}),
|
|
1048
|
+
},
|
|
502
1049
|
get: async (runId) => (await readRuns([await require(tx.read(), runId)]))[0],
|
|
1050
|
+
async retryInfo(runId) {
|
|
1051
|
+
const conn = tx.read();
|
|
1052
|
+
const next = await runsRepo(conn).findOne({
|
|
1053
|
+
filter: { retryOfRunId: runId },
|
|
1054
|
+
sort: (sort) => [sort.field('createdAt').asc(), sort.field('id').asc()],
|
|
1055
|
+
});
|
|
1056
|
+
if (!next)
|
|
1057
|
+
return null;
|
|
1058
|
+
const input = await inputsRepo(conn).findOne({
|
|
1059
|
+
filter: { runId: next.id, type: 'retry' },
|
|
1060
|
+
sort: (sort) => [
|
|
1061
|
+
sort.field('createdAt').desc(),
|
|
1062
|
+
sort.field('id').desc(),
|
|
1063
|
+
],
|
|
1064
|
+
});
|
|
1065
|
+
const source = input?.payload?.source;
|
|
1066
|
+
return {
|
|
1067
|
+
runId: next.id,
|
|
1068
|
+
actorUserId: next.actorUserId,
|
|
1069
|
+
actorName: input ? toInputView(input).actor.name : next.actorUserId,
|
|
1070
|
+
source: typeof source === 'string' ? source : 'unknown',
|
|
1071
|
+
};
|
|
1072
|
+
},
|
|
503
1073
|
async detail(runId) {
|
|
504
1074
|
const conn = tx.read();
|
|
505
1075
|
const run = await require(conn, runId);
|
|
@@ -508,17 +1078,39 @@ export function createRunService(deps) {
|
|
|
508
1078
|
sort: (sort) => [sort.field('createdAt').asc(), sort.field('id').asc()],
|
|
509
1079
|
});
|
|
510
1080
|
const repos = await reposRepo(conn).findMany({ filter: { runId } });
|
|
1081
|
+
const retried = await runsRepo(conn).findOne({
|
|
1082
|
+
filter: { retryOfRunId: runId },
|
|
1083
|
+
sort: (sort) => [sort.field('createdAt').asc(), sort.field('id').asc()],
|
|
1084
|
+
});
|
|
511
1085
|
const children = await runsRepo(conn).findMany({
|
|
512
1086
|
filter: { parentRunId: runId },
|
|
513
1087
|
sort: (sort) => [sort.field('createdAt').asc(), sort.field('id').asc()],
|
|
514
1088
|
});
|
|
515
|
-
const names =
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
1089
|
+
const names = await agentNamesOf(conn, [
|
|
1090
|
+
...children.map((child) => child.agentId),
|
|
1091
|
+
...inputs.flatMap((input) => input.actorKind === 'agent' && input.actorId ? [input.actorId] : []),
|
|
1092
|
+
]);
|
|
519
1093
|
return {
|
|
520
1094
|
...(await readRuns([run]))[0],
|
|
521
|
-
|
|
1095
|
+
actorName: (await deps.people.names(conn, [run.actorUserId])).get(run.actorUserId) ?? run.actorUserId,
|
|
1096
|
+
confirmedByName: run.confirmedByUserId
|
|
1097
|
+
? ((await deps.people.names(conn, [run.confirmedByUserId])).get(run.confirmedByUserId) ?? run.confirmedByUserId)
|
|
1098
|
+
: undefined,
|
|
1099
|
+
requestedByName: (await deps.people.names(conn, [
|
|
1100
|
+
run.requestedByUserId ?? run.actorUserId,
|
|
1101
|
+
])).get(run.requestedByUserId ?? run.actorUserId) ??
|
|
1102
|
+
run.requestedByUserId ??
|
|
1103
|
+
run.actorUserId,
|
|
1104
|
+
retriedRunId: retried?.id ?? null,
|
|
1105
|
+
inputs: inputs.map((input) => {
|
|
1106
|
+
const view = toInputView(input);
|
|
1107
|
+
const name = view.actor.kind === 'agent' && view.actor.id
|
|
1108
|
+
? names.get(view.actor.id)
|
|
1109
|
+
: undefined;
|
|
1110
|
+
return name === undefined
|
|
1111
|
+
? view
|
|
1112
|
+
: { ...view, actor: { ...view.actor, name } };
|
|
1113
|
+
}),
|
|
522
1114
|
repos: repos.map(toRepo),
|
|
523
1115
|
usage: await usageOf(conn, runId),
|
|
524
1116
|
children: children.map((child) => ({
|
|
@@ -533,6 +1125,33 @@ export function createRunService(deps) {
|
|
|
533
1125
|
})),
|
|
534
1126
|
};
|
|
535
1127
|
},
|
|
1128
|
+
async inputTriggers(runIds) {
|
|
1129
|
+
const result = new Map();
|
|
1130
|
+
if (!runIds.length)
|
|
1131
|
+
return result;
|
|
1132
|
+
const rows = await tx
|
|
1133
|
+
.read()
|
|
1134
|
+
.query.selectFrom('agRunInputs as input')
|
|
1135
|
+
.select(['input.runId', 'input.type', 'input.payload'])
|
|
1136
|
+
.where('input.runId', 'in', [...runIds])
|
|
1137
|
+
.where((eb) => eb('input.id', '=', eb
|
|
1138
|
+
.selectFrom('agRunInputs as first')
|
|
1139
|
+
.select('first.id')
|
|
1140
|
+
.whereRef('first.runId', '=', 'input.runId')
|
|
1141
|
+
.orderBy('first.createdAt', 'asc')
|
|
1142
|
+
.orderBy('first.id', 'asc')
|
|
1143
|
+
.limit(1)))
|
|
1144
|
+
.execute();
|
|
1145
|
+
for (const row of rows) {
|
|
1146
|
+
const inputs = result.get(String(row.runId)) ?? [];
|
|
1147
|
+
inputs.push({
|
|
1148
|
+
type: String(row.type),
|
|
1149
|
+
payload: jsonObject(row.payload),
|
|
1150
|
+
});
|
|
1151
|
+
result.set(String(row.runId), inputs);
|
|
1152
|
+
}
|
|
1153
|
+
return result;
|
|
1154
|
+
},
|
|
536
1155
|
async list(filter) {
|
|
537
1156
|
const records = await runsRepo(tx.read()).findMany({
|
|
538
1157
|
filter: (f) => f.and([
|
|
@@ -609,6 +1228,9 @@ export function createRunService(deps) {
|
|
|
609
1228
|
workload(query) {
|
|
610
1229
|
return readWorkload(tx.read(), clock, deps.runners, query);
|
|
611
1230
|
},
|
|
1231
|
+
queueWait(runId) {
|
|
1232
|
+
return readQueueWait(tx.read(), clock, deps.runners, runId, deps.diagnose);
|
|
1233
|
+
},
|
|
612
1234
|
async events(runId, afterSeq, limit, types) {
|
|
613
1235
|
const conn = tx.read();
|
|
614
1236
|
await require(conn, runId);
|
|
@@ -643,7 +1265,16 @@ export function createRunService(deps) {
|
|
|
643
1265
|
lastSeq: events.length > 0 ? events[events.length - 1].seq : afterSeq,
|
|
644
1266
|
};
|
|
645
1267
|
},
|
|
646
|
-
authenticateToken: (value) =>
|
|
1268
|
+
authenticateToken: async (value) => {
|
|
1269
|
+
const conn = tx.read();
|
|
1270
|
+
const identity = await authenticateRunToken(conn, clock, value);
|
|
1271
|
+
if (identity.run.commentRootRunId) {
|
|
1272
|
+
const root = await findRunRecord(conn, identity.run.commentRootRunId);
|
|
1273
|
+
if (!root || !(await currentCommentOwner(conn, deps.subjects, root)))
|
|
1274
|
+
throw precondition('RUN_TOKEN_INVALID', 'The comment authorization belongs to an earlier owner assignment.');
|
|
1275
|
+
}
|
|
1276
|
+
return identity;
|
|
1277
|
+
},
|
|
647
1278
|
async self({ run }) {
|
|
648
1279
|
const conn = tx.read();
|
|
649
1280
|
const agent = await findAgent(conn, run.agentId);
|
|
@@ -672,14 +1303,10 @@ export function createRunService(deps) {
|
|
|
672
1303
|
const conn = tx.read();
|
|
673
1304
|
const binding = deps.subjects.get(run.subjectKind);
|
|
674
1305
|
const agent = await findAgent(conn, run.agentId);
|
|
675
|
-
|
|
676
|
-
const runner = run.runnerId && agent?.type === 'runner'
|
|
1306
|
+
const runner = run.runnerId
|
|
677
1307
|
? await deps.runners.find(conn, run.runnerId)
|
|
678
1308
|
: null;
|
|
679
|
-
if (!binding ||
|
|
680
|
-
!agent ||
|
|
681
|
-
(agent.type === 'runner' && !runner) ||
|
|
682
|
-
!isActive(run.status))
|
|
1309
|
+
if (!binding || !agent || !runner || !isActive(run.status))
|
|
683
1310
|
throw notFound('Run context');
|
|
684
1311
|
const assembly = await binding.context.assemble(conn, {
|
|
685
1312
|
run: toRun(run),
|
|
@@ -688,11 +1315,11 @@ export function createRunService(deps) {
|
|
|
688
1315
|
inputs: (await pendingInputs(conn, run.id)).map(toInput),
|
|
689
1316
|
cli: deps.cliName,
|
|
690
1317
|
appName: deps.appName,
|
|
691
|
-
|
|
692
|
-
});
|
|
1318
|
+
}, await binding.context.prepare?.(toRun(run)));
|
|
693
1319
|
return assembly.data;
|
|
694
1320
|
},
|
|
695
1321
|
openOn: openRunsOn,
|
|
1322
|
+
openOnEach: openRunsOnEach,
|
|
696
1323
|
pendingInputs: async (conn, runId) => (await pendingInputs(conn, runId)).map(toInput),
|
|
697
1324
|
inputsSince: inputsOnSince,
|
|
698
1325
|
lastSummary,
|