@nocobase/app-plugin-agents 0.1.0-beta.1 → 0.1.0-beta.11
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 +398 -0
- package/README.md +129 -67
- package/dist/client/api/client.d.ts +25 -17
- package/dist/client/api/client.d.ts.map +1 -1
- package/dist/client/api/client.js +29 -27
- package/dist/client/api/client.js.map +1 -1
- package/dist/client/api/keys.d.ts +1 -1
- package/dist/client/api/keys.d.ts.map +1 -1
- package/dist/client/api/keys.js +1 -1
- package/dist/client/api/keys.js.map +1 -1
- package/dist/client/chat/api.d.ts +2 -7
- package/dist/client/chat/api.d.ts.map +1 -1
- package/dist/client/chat/api.js +0 -7
- package/dist/client/chat/api.js.map +1 -1
- 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/message-model.d.ts +4 -2
- package/dist/client/chat/message-model.d.ts.map +1 -1
- package/dist/client/chat/message-model.js +28 -3
- package/dist/client/chat/message-model.js.map +1 -1
- package/dist/client/chat/use-chat.d.ts +2 -10
- package/dist/client/chat/use-chat.d.ts.map +1 -1
- package/dist/client/chat/use-chat.js +3 -10
- package/dist/client/chat/use-chat.js.map +1 -1
- package/dist/client/chat.d.ts +4 -1
- package/dist/client/chat.d.ts.map +1 -1
- package/dist/client/chat.js +3 -0
- 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 +19 -39
- package/dist/client/components/agent-picker.js.map +1 -1
- package/dist/client/components/variables/variable-dialogs.d.ts +6 -1
- package/dist/client/components/variables/variable-dialogs.d.ts.map +1 -1
- package/dist/client/components/variables/variable-dialogs.js +27 -11
- package/dist/client/components/variables/variable-dialogs.js.map +1 -1
- package/dist/client/components/variables/variables-panel.d.ts.map +1 -1
- package/dist/client/components/variables/variables-panel.js +9 -2
- package/dist/client/components/variables/variables-panel.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 +3 -12
- package/dist/client/hooks/use-agent-picker-labels.js.map +1 -1
- package/dist/client/kit.d.ts +9 -12
- package/dist/client/kit.d.ts.map +1 -1
- package/dist/client/kit.js +12 -14
- package/dist/client/kit.js.map +1 -1
- package/dist/client/lib/agents.d.ts +5 -13
- package/dist/client/lib/agents.d.ts.map +1 -1
- package/dist/client/lib/agents.js +17 -32
- package/dist/client/lib/agents.js.map +1 -1
- package/dist/client/lib/install.js +1 -1
- package/dist/client/locales/chat.en-US.d.ts +9 -22
- package/dist/client/locales/chat.en-US.d.ts.map +1 -1
- package/dist/client/locales/chat.en-US.js +13 -25
- 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 +10 -22
- package/dist/client/locales/chat.zh-CN.js.map +1 -1
- package/dist/client/locales/en-US.d.ts +101 -219
- package/dist/client/locales/en-US.d.ts.map +1 -1
- package/dist/client/locales/en-US.js +106 -219
- package/dist/client/locales/en-US.js.map +1 -1
- package/dist/client/locales/runWait.en-US.d.ts +38 -0
- package/dist/client/locales/runWait.en-US.d.ts.map +1 -0
- package/dist/client/locales/runWait.en-US.js +37 -0
- package/dist/client/locales/runWait.en-US.js.map +1 -0
- package/dist/client/locales/runWait.zh-CN.d.ts +5 -0
- package/dist/client/locales/runWait.zh-CN.d.ts.map +1 -0
- package/dist/client/locales/runWait.zh-CN.js +32 -0
- package/dist/client/locales/runWait.zh-CN.js.map +1 -0
- package/dist/client/locales/runtimes.en-US.d.ts +54 -0
- package/dist/client/locales/runtimes.en-US.d.ts.map +1 -1
- package/dist/client/locales/runtimes.en-US.js +57 -3
- 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 +57 -3
- package/dist/client/locales/runtimes.zh-CN.js.map +1 -1
- package/dist/client/locales/skills.en-US.d.ts +1 -0
- package/dist/client/locales/skills.en-US.d.ts.map +1 -1
- package/dist/client/locales/skills.en-US.js +2 -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 +2 -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 +108 -221
- 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 +6 -100
- 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 +172 -0
- package/dist/client/pages/agents/runner-agents.js.map +1 -0
- package/dist/client/pages/runtimes/connect.js +1 -1
- 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 +3 -2
- package/dist/client/pages/runtimes/index.js.map +1 -1
- package/dist/client/pages/runtimes/runner-cells.d.ts +1 -1
- package/dist/client/pages/runtimes/runner-cells.d.ts.map +1 -1
- package/dist/client/pages/runtimes/runner-cells.js +4 -1
- package/dist/client/pages/runtimes/runner-cells.js.map +1 -1
- package/dist/client/pages/runtimes/runner-sheet.d.ts.map +1 -1
- package/dist/client/pages/runtimes/runner-sheet.js +12 -3
- package/dist/client/pages/runtimes/runner-sheet.js.map +1 -1
- package/dist/client/pages/runtimes/workspace-diagnostics.d.ts +9 -0
- package/dist/client/pages/runtimes/workspace-diagnostics.d.ts.map +1 -0
- package/dist/client/pages/runtimes/workspace-diagnostics.js +68 -0
- package/dist/client/pages/runtimes/workspace-diagnostics.js.map +1 -0
- package/dist/client/pages/skills/detail/index.d.ts.map +1 -1
- package/dist/client/pages/skills/detail/index.js +7 -10
- 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 +21 -0
- package/dist/client/runs/format-wait.d.ts.map +1 -0
- package/dist/client/runs/format-wait.js +90 -0
- package/dist/client/runs/format-wait.js.map +1 -0
- 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 +13 -7
- package/dist/client/runs/subject-runs.js.map +1 -1
- package/dist/client/runs.d.ts +3 -1
- package/dist/client/runs.d.ts.map +1 -1
- package/dist/client/runs.js +3 -1
- package/dist/client/runs.js.map +1 -1
- package/dist/database/migrations/.manifest.json +62 -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/202610090001_ag_add_team_runner_variables.d.ts +9 -0
- package/dist/database/migrations/202610090001_ag_add_team_runner_variables.d.ts.map +1 -0
- package/dist/database/migrations/202610090001_ag_add_team_runner_variables.js +28 -0
- package/dist/database/migrations/202610090001_ag_add_team_runner_variables.js.map +1 -0
- package/dist/database/migrations/202610090002_ag_create_run_requests.d.ts +10 -0
- package/dist/database/migrations/202610090002_ag_create_run_requests.d.ts.map +1 -0
- package/dist/database/migrations/202610090002_ag_create_run_requests.js +105 -0
- package/dist/database/migrations/202610090002_ag_create_run_requests.js.map +1 -0
- package/dist/database/migrations/202610090003_ag_add_execution_history.d.ts +4 -0
- package/dist/database/migrations/202610090003_ag_add_execution_history.d.ts.map +1 -0
- package/dist/database/migrations/202610090003_ag_add_execution_history.js +17 -0
- package/dist/database/migrations/202610090003_ag_add_execution_history.js.map +1 -0
- package/dist/database/migrations/202610090004_ag_add_runner_workspace_usage.d.ts +9 -0
- package/dist/database/migrations/202610090004_ag_add_runner_workspace_usage.d.ts.map +1 -0
- package/dist/database/migrations/202610090004_ag_add_runner_workspace_usage.js +22 -0
- package/dist/database/migrations/202610090004_ag_add_runner_workspace_usage.js.map +1 -0
- package/dist/database/migrations/202610090005_ag_add_runner_variables.d.ts +10 -0
- package/dist/database/migrations/202610090005_ag_add_runner_variables.d.ts.map +1 -0
- package/dist/database/migrations/202610090005_ag_add_runner_variables.js +36 -0
- package/dist/database/migrations/202610090005_ag_add_runner_variables.js.map +1 -0
- package/dist/database/migrations/202610100001_ag_index_run_event_types.d.ts +4 -0
- package/dist/database/migrations/202610100001_ag_index_run_event_types.d.ts.map +1 -0
- package/dist/database/migrations/202610100001_ag_index_run_event_types.js +17 -0
- package/dist/database/migrations/202610100001_ag_index_run_event_types.js.map +1 -0
- package/dist/database/migrations/202610100002_ag_add_run_git_credentials.d.ts +9 -0
- package/dist/database/migrations/202610100002_ag_add_run_git_credentials.d.ts.map +1 -0
- package/dist/database/migrations/202610100002_ag_add_run_git_credentials.js +30 -0
- package/dist/database/migrations/202610100002_ag_add_run_git_credentials.js.map +1 -0
- package/dist/database/migrations/202610110001_ag_add_fresh_sessions.d.ts +4 -0
- package/dist/database/migrations/202610110001_ag_add_fresh_sessions.d.ts.map +1 -0
- package/dist/database/migrations/202610110001_ag_add_fresh_sessions.js +23 -0
- package/dist/database/migrations/202610110001_ag_add_fresh_sessions.js.map +1 -0
- 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/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/package.json +8 -10
- package/dist/server/cli/run-credential.js +1 -1
- package/dist/server/composition.d.ts +41 -37
- package/dist/server/composition.d.ts.map +1 -1
- package/dist/server/composition.js +66 -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 +342 -317
- package/dist/server/core/agents/agent.service.js.map +1 -1
- package/dist/server/core/agents/agent.store.d.ts +24 -12
- package/dist/server/core/agents/agent.store.d.ts.map +1 -1
- package/dist/server/core/agents/agent.store.js +64 -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 +86 -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 +2 -1
- package/dist/server/core/agents/index.d.ts.map +1 -1
- package/dist/server/core/agents/index.js +2 -1
- package/dist/server/core/agents/index.js.map +1 -1
- package/dist/server/core/brief/brief.js +1 -1
- package/dist/server/core/brief/brief.js.map +1 -1
- package/dist/server/core/callers/index.d.ts +1 -1
- package/dist/server/core/conversations/availability.d.ts +11 -10
- package/dist/server/core/conversations/availability.d.ts.map +1 -1
- package/dist/server/core/conversations/availability.js +14 -32
- package/dist/server/core/conversations/availability.js.map +1 -1
- package/dist/server/core/conversations/chat-settings.d.ts.map +1 -1
- package/dist/server/core/conversations/chat-settings.js +5 -3
- package/dist/server/core/conversations/chat-settings.js.map +1 -1
- package/dist/server/core/conversations/conversation.service.d.ts +3 -5
- package/dist/server/core/conversations/conversation.service.d.ts.map +1 -1
- package/dist/server/core/conversations/conversation.service.js +161 -221
- package/dist/server/core/conversations/conversation.service.js.map +1 -1
- package/dist/server/core/conversations/ports.d.ts +3 -17
- package/dist/server/core/conversations/ports.d.ts.map +1 -1
- package/dist/server/core/reports/report.service.d.ts.map +1 -1
- package/dist/server/core/reports/report.service.js +5 -2
- package/dist/server/core/reports/report.service.js.map +1 -1
- package/dist/server/core/runs/availability.d.ts +18 -7
- package/dist/server/core/runs/availability.d.ts.map +1 -1
- package/dist/server/core/runs/availability.js +35 -24
- package/dist/server/core/runs/availability.js.map +1 -1
- package/dist/server/core/runs/claim.d.ts +47 -67
- package/dist/server/core/runs/claim.d.ts.map +1 -1
- package/dist/server/core/runs/claim.js +805 -313
- 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 +51 -0
- package/dist/server/core/runs/eligibility.d.ts.map +1 -0
- package/dist/server/core/runs/eligibility.js +44 -0
- package/dist/server/core/runs/eligibility.js.map +1 -0
- package/dist/server/core/runs/execution-view.d.ts +10 -0
- package/dist/server/core/runs/execution-view.d.ts.map +1 -0
- package/dist/server/core/runs/execution-view.js +25 -0
- package/dist/server/core/runs/execution-view.js.map +1 -0
- package/dist/server/core/runs/execution.d.ts +13 -0
- package/dist/server/core/runs/execution.d.ts.map +1 -0
- package/dist/server/core/runs/execution.js +85 -0
- package/dist/server/core/runs/execution.js.map +1 -0
- package/dist/server/core/runs/extensions.d.ts +59 -4
- package/dist/server/core/runs/extensions.d.ts.map +1 -1
- package/dist/server/core/runs/extensions.js +45 -9
- package/dist/server/core/runs/extensions.js.map +1 -1
- package/dist/server/core/runs/git-credentials.d.ts +43 -0
- package/dist/server/core/runs/git-credentials.d.ts.map +1 -0
- package/dist/server/core/runs/git-credentials.js +129 -0
- package/dist/server/core/runs/git-credentials.js.map +1 -0
- 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 +9 -5
- package/dist/server/core/runs/index.d.ts.map +1 -1
- package/dist/server/core/runs/index.js +9 -5
- package/dist/server/core/runs/index.js.map +1 -1
- package/dist/server/core/runs/input-gate.d.ts +34 -0
- package/dist/server/core/runs/input-gate.d.ts.map +1 -0
- package/dist/server/core/runs/input-gate.js +58 -0
- package/dist/server/core/runs/input-gate.js.map +1 -0
- package/dist/server/core/runs/lifecycle.d.ts +9 -19
- package/dist/server/core/runs/lifecycle.d.ts.map +1 -1
- package/dist/server/core/runs/lifecycle.js +98 -50
- package/dist/server/core/runs/lifecycle.js.map +1 -1
- package/dist/server/core/runs/policy.d.ts +8 -0
- package/dist/server/core/runs/policy.d.ts.map +1 -1
- package/dist/server/core/runs/policy.js +10 -0
- package/dist/server/core/runs/policy.js.map +1 -1
- package/dist/server/core/runs/ports.d.ts +91 -28
- 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 +3 -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 +245 -0
- package/dist/server/core/runs/run-requests.d.ts.map +1 -0
- package/dist/server/core/runs/run-requests.js +543 -0
- package/dist/server/core/runs/run-requests.js.map +1 -0
- package/dist/server/core/runs/run.service.d.ts +96 -11
- package/dist/server/core/runs/run.service.d.ts.map +1 -1
- package/dist/server/core/runs/run.service.js +921 -96
- package/dist/server/core/runs/run.service.js.map +1 -1
- package/dist/server/core/runs/run.store.d.ts +25 -3
- package/dist/server/core/runs/run.store.d.ts.map +1 -1
- package/dist/server/core/runs/run.store.js +52 -2
- package/dist/server/core/runs/run.store.js.map +1 -1
- package/dist/server/core/runs/runner-view.d.ts +6 -4
- package/dist/server/core/runs/runner-view.d.ts.map +1 -1
- package/dist/server/core/runs/runner-view.js +13 -11
- 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 +55 -10
- package/dist/server/core/runs/sweeper.js.map +1 -1
- package/dist/server/core/runs/transitions.d.ts +2 -2
- package/dist/server/core/runs/transitions.d.ts.map +1 -1
- package/dist/server/core/runs/transitions.js +80 -8
- package/dist/server/core/runs/transitions.js.map +1 -1
- package/dist/server/core/runs/workload.d.ts +3 -3
- package/dist/server/core/runs/workload.d.ts.map +1 -1
- package/dist/server/core/runs/workload.js +154 -45
- 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 +43 -58
- 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/variables/index.d.ts +1 -1
- package/dist/server/core/variables/index.d.ts.map +1 -1
- package/dist/server/core/variables/index.js +1 -1
- package/dist/server/core/variables/index.js.map +1 -1
- package/dist/server/core/variables/variable.service.d.ts +38 -6
- package/dist/server/core/variables/variable.service.d.ts.map +1 -1
- package/dist/server/core/variables/variable.service.js +201 -30
- package/dist/server/core/variables/variable.service.js.map +1 -1
- package/dist/server/distribution/dist.service.d.ts +27 -5
- package/dist/server/distribution/dist.service.d.ts.map +1 -1
- package/dist/server/distribution/dist.service.js +41 -5
- package/dist/server/distribution/dist.service.js.map +1 -1
- package/dist/server/distribution/download-tokens.d.ts +1 -1
- package/dist/server/distribution/download-tokens.d.ts.map +1 -1
- package/dist/server/distribution/download-tokens.js +7 -4
- package/dist/server/distribution/download-tokens.js.map +1 -1
- package/dist/server/distribution/index.d.ts +11 -3
- package/dist/server/distribution/index.d.ts.map +1 -1
- package/dist/server/distribution/index.js +31 -8
- package/dist/server/distribution/index.js.map +1 -1
- package/dist/server/jobs/index.d.ts +1 -1
- package/dist/server/jobs/index.d.ts.map +1 -1
- package/dist/server/jobs/index.js +1 -1
- package/dist/server/jobs/index.js.map +1 -1
- package/dist/server/jobs/job.service.d.ts +3 -1
- package/dist/server/jobs/job.service.d.ts.map +1 -1
- package/dist/server/jobs/job.service.js +11 -3
- package/dist/server/jobs/job.service.js.map +1 -1
- package/dist/server/jobs/spec.d.ts +4 -0
- package/dist/server/jobs/spec.d.ts.map +1 -1
- package/dist/server/jobs/spec.js +6 -0
- package/dist/server/jobs/spec.js.map +1 -1
- package/dist/server/kernel/errors.d.ts +1 -1
- package/dist/server/kernel/errors.d.ts.map +1 -1
- package/dist/server/kernel/errors.js +1 -0
- package/dist/server/kernel/errors.js.map +1 -1
- package/dist/server/kernel/events.d.ts +34 -9
- package/dist/server/kernel/events.d.ts.map +1 -1
- package/dist/server/kernel/events.js.map +1 -1
- package/dist/server/kernel/redaction.d.ts +2 -0
- package/dist/server/kernel/redaction.d.ts.map +1 -1
- package/dist/server/kernel/redaction.js +17 -0
- package/dist/server/kernel/redaction.js.map +1 -1
- 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/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/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/providers/agents.d.ts +8 -25
- package/dist/server/providers/agents.d.ts.map +1 -1
- package/dist/server/providers/agents.js +11 -75
- package/dist/server/providers/agents.js.map +1 -1
- package/dist/server/providers/runners.d.ts.map +1 -1
- package/dist/server/providers/runners.js +23 -0
- package/dist/server/providers/runners.js.map +1 -1
- package/dist/server/routes/admin.d.ts.map +1 -1
- package/dist/server/routes/admin.js +158 -209
- 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 +12 -70
- 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 +11 -1
- 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 -21
- package/dist/server/routes/roster.js.map +1 -1
- package/dist/server/routes/run-requests.d.ts +6 -0
- package/dist/server/routes/run-requests.d.ts.map +1 -0
- package/dist/server/routes/run-requests.js +216 -0
- package/dist/server/routes/run-requests.js.map +1 -0
- package/dist/server/routes/runners/admin.d.ts +9 -1
- package/dist/server/routes/runners/admin.d.ts.map +1 -1
- package/dist/server/routes/runners/admin.js +62 -24
- package/dist/server/routes/runners/admin.js.map +1 -1
- package/dist/server/routes/runners/dist.d.ts +5 -1
- package/dist/server/routes/runners/dist.d.ts.map +1 -1
- package/dist/server/routes/runners/dist.js +36 -9
- package/dist/server/routes/runners/dist.js.map +1 -1
- package/dist/server/routes/runners/install.d.ts.map +1 -1
- package/dist/server/routes/runners/install.js +98 -15
- 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 +27 -7
- package/dist/server/routes/runners/runner.js.map +1 -1
- package/dist/server/routes/runners/runs.d.ts +1 -1
- package/dist/server/routes/runners/runs.d.ts.map +1 -1
- package/dist/server/routes/runners/runs.js +23 -3
- package/dist/server/routes/runners/runs.js.map +1 -1
- package/dist/server/routes/schemas.d.ts +37 -8
- package/dist/server/routes/schemas.d.ts.map +1 -1
- package/dist/server/routes/schemas.js +381 -84
- package/dist/server/routes/schemas.js.map +1 -1
- package/dist/server/runners/index.d.ts +1 -0
- package/dist/server/runners/index.d.ts.map +1 -1
- package/dist/server/runners/index.js +1 -0
- package/dist/server/runners/index.js.map +1 -1
- package/dist/server/runners/runner.service.d.ts +32 -8
- package/dist/server/runners/runner.service.d.ts.map +1 -1
- package/dist/server/runners/runner.service.js +130 -14
- package/dist/server/runners/runner.service.js.map +1 -1
- package/dist/server/runners/runner.store.d.ts +10 -1
- package/dist/server/runners/runner.store.d.ts.map +1 -1
- package/dist/server/runners/runner.store.js +117 -4
- package/dist/server/runners/runner.store.js.map +1 -1
- package/dist/server/runners/sweeper.d.ts +5 -0
- package/dist/server/runners/sweeper.d.ts.map +1 -1
- package/dist/server/runners/sweeper.js +4 -2
- package/dist/server/runners/sweeper.js.map +1 -1
- package/dist/server/runners/workspaces.d.ts +33 -0
- package/dist/server/runners/workspaces.d.ts.map +1 -0
- package/dist/server/runners/workspaces.js +248 -0
- package/dist/server/runners/workspaces.js.map +1 -0
- 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 +13 -9
- package/dist/server/tokens.d.ts.map +1 -1
- package/dist/server/tokens.js +7 -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 +128 -167
- package/dist/shared/agents.d.ts.map +1 -1
- package/dist/shared/agents.js +46 -97
- package/dist/shared/agents.js.map +1 -1
- package/dist/shared/conversations.d.ts +43 -89
- package/dist/shared/conversations.d.ts.map +1 -1
- package/dist/shared/conversations.js +5 -24
- package/dist/shared/conversations.js.map +1 -1
- package/dist/shared/model-catalog.d.ts +48 -0
- package/dist/shared/model-catalog.d.ts.map +1 -0
- package/dist/shared/model-catalog.js +148 -0
- package/dist/shared/model-catalog.js.map +1 -0
- package/dist/shared/models.js +1 -1
- package/dist/shared/models.js.map +1 -1
- package/dist/shared/runners.d.ts +107 -17
- package/dist/shared/runners.d.ts.map +1 -1
- package/dist/shared/runners.js +49 -7
- package/dist/shared/runners.js.map +1 -1
- package/dist/shared/runs.d.ts +213 -1
- package/dist/shared/runs.d.ts.map +1 -1
- package/dist/shared/runs.js +24 -0
- package/dist/shared/runs.js.map +1 -1
- package/dist/shared/skills.d.ts +8 -4
- 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/variables.d.ts +22 -0
- package/dist/shared/variables.d.ts.map +1 -1
- package/dist/shared/variables.js +10 -2
- package/dist/shared/variables.js.map +1 -1
- package/package.json +24 -26
- package/skills/nocobase-app-plugin-agents/SKILL.md +8 -7
- package/skills/nocobase-app-plugin-agents/references/agents.md +30 -0
- package/skills/nocobase-app-plugin-agents/references/distribution.md +21 -4
- package/skills/nocobase-app-plugin-agents/references/extension-points.md +30 -20
- package/skills/nocobase-app-plugin-agents/references/model-services.md +17 -0
- package/skills/nocobase-app-plugin-agents/references/runners.md +15 -1
- package/skills/nocobase-app-plugin-agents/references/setup-and-config.md +4 -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 +33 -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 -76
- 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 -35
- package/dist/client/components/model-entries.d.ts.map +0 -1
- package/dist/client/components/model-entries.js +0 -82
- 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/tool-policy.d.ts +0 -5
- package/dist/client/lib/tool-policy.d.ts.map +0 -1
- package/dist/client/lib/tool-policy.js +0 -10
- 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 -73
- package/dist/client/pages/agents/agent-model.d.ts.map +0 -1
- package/dist/client/pages/agents/agent-model.js +0 -172
- 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 -22
- package/dist/client/pages/agents/detail/sections.d.ts.map +0 -1
- package/dist/client/pages/agents/detail/sections.js +0 -311
- 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 -195
- 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
|
@@ -1,714 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The server executor: each application instance runs online agents' runs itself, as an in-process runner. It takes
|
|
3
|
-
* online runs through the claim (`claims.claimServer`, the same guarded update runners are given work through, so two
|
|
4
|
-
* instances never take one run), and reports through the same `RunnerReports` a runner's requests reach: start, events,
|
|
5
|
-
* lease, complete, fail and cancel-ack. So conversations, transcripts, the inbox's failed-run cards, retries and the
|
|
6
|
-
* sweeper work for online runs as they do for runner runs.
|
|
7
|
-
*
|
|
8
|
-
* A run works with the entry of its agent's list the claim settled, at its reasoning effort (`ServerClaim.model`: a conversation's choice, else
|
|
9
|
-
* the agent's first), and only that one: a failing model fails the run, it never falls back to another entry.
|
|
10
|
-
*
|
|
11
|
-
* A run is the AI SDK's agent loop (`ToolLoopAgent`) over the entry's language model (`ModelGateway.languageModel`):
|
|
12
|
-
* each step streams text, which a conversation shows as a draft growing in place (`conversations.streamDraft`), and
|
|
13
|
-
* ends with what it used (recorded at once, `reports.onlineUsage`); the SDK calls the step's tools and the model again
|
|
14
|
-
* with their results. The run has two tools (`sandbox.ts`): `bash`, a sandboxed shell whose CLI command runs the
|
|
15
|
-
* application's commands as the run's identity (`cli-command.ts`, from the application's command manifest), and
|
|
16
|
-
* `skill`, which reads the run's skills, mounted read-only in that shell. The loop ends when the model answers without
|
|
17
|
-
* a tool call, or after `maxSteps` steps (`stepLimit`). Input that arrives while it works (a message sent meanwhile) is
|
|
18
|
-
* read once it answers, and answered in the same run by another turn of the loop.
|
|
19
|
-
*
|
|
20
|
-
* - **Holder**: `server:<instance>`, a run's `runnerId` while this instance holds it. The lease is renewed every
|
|
21
|
-
* `TIMINGS.leaseRenewMs`; an instance that stops renewing (it crashed) loses its runs to the sweeper (`leaseExpired`),
|
|
22
|
-
* which puts them back in the queue for any instance.
|
|
23
|
-
* - **Cancelling**: the run is read every `cancelPollMs`; a cancel request aborts the model call and acknowledges.
|
|
24
|
-
* - **Failing**: the gateway's error codes map to the protocol's failure reasons (`failureOf`); rate limits and network
|
|
25
|
-
* errors go back to the queue while attempts remain, the rest fail the run, which the subject's domain reports.
|
|
26
|
-
* - **Stopping**: on shutdown every run is aborted and handed back as `runnerOffline`, which retries at once elsewhere.
|
|
27
|
-
* - No limits: no slots and no per-agent concurrency, as the owner decided; a model service's own limits surface as
|
|
28
|
-
* `toolRateLimit`.
|
|
29
|
-
* - **Consulting**: a run whose claim lists agents it may consult (`ServerClaim.consultable`) also has `ask_agent`
|
|
30
|
-
* (`consult-tool.ts`): the consulted agent's run is taken here at once (`claims.claimChild`) and run within the tool
|
|
31
|
-
* call, its draft answer streamed back as preliminary results, which the asking conversation shows on a card
|
|
32
|
-
* (`conversations.consultation`). It ends within `consult.timeoutMs` and `consult.tokenBudget`, and is aborted with
|
|
33
|
-
* the run that asked.
|
|
34
|
-
*/
|
|
35
|
-
import { createHash, randomBytes } from 'node:crypto';
|
|
36
|
-
import { jsonSchema, stepCountIs, tool, ToolLoopAgent, } from 'ai';
|
|
37
|
-
import { ProtocolError, TIMINGS, } from '@nocobase/agent-protocol';
|
|
38
|
-
import { CHAT_IMAGE_TO_MODEL_MAX, } from '../../shared/conversations.js';
|
|
39
|
-
import { firstTurn } from '../core/brief/index.js';
|
|
40
|
-
import { classify, ModelError, reasoningOf, usageOf, } from './gateway.js';
|
|
41
|
-
import { ASK_AGENT_TOOL, consultText, consultTool, } from './consult-tool.js';
|
|
42
|
-
import { cliCommand } from './cli-command.js';
|
|
43
|
-
import { onlineTools } from './sandbox.js';
|
|
44
|
-
import { errorOutput } from './tools.js';
|
|
45
|
-
/**
|
|
46
|
-
* The session id a run's model calls send in the session header an OpenCode base URL requires
|
|
47
|
-
* (`x-opencode-session`): the same for every run of one conversation — its subject and thread — so the provider
|
|
48
|
-
* routes and caches it as one, and a hash, so it names neither.
|
|
49
|
-
*/
|
|
50
|
-
export function sessionOf(run) {
|
|
51
|
-
const hex = createHash('sha256')
|
|
52
|
-
.update([run.subject.kind, run.subject.id, run.threadScope].join('\n'))
|
|
53
|
-
.digest('hex');
|
|
54
|
-
return [
|
|
55
|
-
hex.slice(0, 8),
|
|
56
|
-
hex.slice(8, 12),
|
|
57
|
-
hex.slice(12, 16),
|
|
58
|
-
hex.slice(16, 20),
|
|
59
|
-
hex.slice(20, 32),
|
|
60
|
-
].join('-');
|
|
61
|
-
}
|
|
62
|
-
/** Model calls a run may make before it fails `stepLimit`. */
|
|
63
|
-
export const DEFAULT_MAX_STEPS = 16;
|
|
64
|
-
/** How often a running online run is checked for a cancel request. */
|
|
65
|
-
const CANCEL_POLL_MS = 1_000;
|
|
66
|
-
/** How often a draft reply is written while it streams. */
|
|
67
|
-
const DRAFT_INTERVAL_MS = 300;
|
|
68
|
-
/** Online runs taken per claim. */
|
|
69
|
-
const CLAIM_BATCH = 20;
|
|
70
|
-
/** How long the executor waits for work when nobody signals it (work queued on another instance). */
|
|
71
|
-
const IDLE_POLL_MS = 2_000;
|
|
72
|
-
/** How long a consultation may take, by default. */
|
|
73
|
-
export const DEFAULT_CONSULT_TIMEOUT_MS = 120_000;
|
|
74
|
-
/** The tokens a consultation may use (input and output, of every model call), by default. */
|
|
75
|
-
export const DEFAULT_CONSULT_TOKEN_BUDGET = 200_000;
|
|
76
|
-
/** How often a consultation card is rewritten while its answer is written. */
|
|
77
|
-
const CARD_INTERVAL_MS = 1_000;
|
|
78
|
-
/** The failure reason of a model error code. */
|
|
79
|
-
export function failureOf(code) {
|
|
80
|
-
switch (code) {
|
|
81
|
-
case 'config':
|
|
82
|
-
return 'modelUnavailable';
|
|
83
|
-
case 'auth':
|
|
84
|
-
return 'toolAuth';
|
|
85
|
-
case 'quota':
|
|
86
|
-
return 'toolQuota';
|
|
87
|
-
case 'rateLimit':
|
|
88
|
-
return 'toolRateLimit';
|
|
89
|
-
case 'network':
|
|
90
|
-
return 'toolNetwork';
|
|
91
|
-
case 'contextOverflow':
|
|
92
|
-
return 'contextOverflow';
|
|
93
|
-
case 'aborted':
|
|
94
|
-
return 'cancelled';
|
|
95
|
-
default:
|
|
96
|
-
return 'unknown';
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/** Why the run's work stopped before it ended on its own; `timeout` and `budget` end a consultation. */
|
|
100
|
-
class Stop extends Error {
|
|
101
|
-
kind;
|
|
102
|
-
constructor(kind) {
|
|
103
|
-
super(kind);
|
|
104
|
-
this.kind = kind;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/** A duration in whole seconds, as a failure says it. */
|
|
108
|
-
function seconds(ms) {
|
|
109
|
-
const count = Math.max(1, Math.ceil(ms / 1000));
|
|
110
|
-
return `${count} second${count === 1 ? '' : 's'}`;
|
|
111
|
-
}
|
|
112
|
-
/** A plan a `bash` call created (`plan create`), from its JSON output. */
|
|
113
|
-
function planOf(output) {
|
|
114
|
-
if (!output.startsWith('exit code 0\n'))
|
|
115
|
-
return null;
|
|
116
|
-
try {
|
|
117
|
-
const envelope = JSON.parse(output.slice(output.indexOf('\n') + 1));
|
|
118
|
-
const data = envelope.result?.data;
|
|
119
|
-
if (envelope.ok !== true ||
|
|
120
|
-
envelope.command !== 'plan create' ||
|
|
121
|
-
typeof data?.id !== 'string')
|
|
122
|
-
return null;
|
|
123
|
-
return {
|
|
124
|
-
id: data.id,
|
|
125
|
-
title: typeof data.title === 'string' ? data.title : '',
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
catch {
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
/** A failure the model port or the loop decided. */
|
|
133
|
-
class RunFailure extends Error {
|
|
134
|
-
reason;
|
|
135
|
-
constructor(reason, message) {
|
|
136
|
-
super(message);
|
|
137
|
-
this.reason = reason;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
/** A model failure as the run's failure. */
|
|
141
|
-
function modelFailure(error) {
|
|
142
|
-
const failure = classify(error);
|
|
143
|
-
return new RunFailure(failureOf(failure.code), failure.message);
|
|
144
|
-
}
|
|
145
|
-
/** A tool's result as the run's transcript and the model read it. */
|
|
146
|
-
function resultOf(output) {
|
|
147
|
-
if (output &&
|
|
148
|
-
typeof output === 'object' &&
|
|
149
|
-
typeof output.output === 'string') {
|
|
150
|
-
const result = output;
|
|
151
|
-
return { ok: result.ok !== false, output: result.output };
|
|
152
|
-
}
|
|
153
|
-
return { ok: true, output: JSON.stringify(output ?? null) };
|
|
154
|
-
}
|
|
155
|
-
/** The run's tools as the SDK runs them: each answers `{ ok, output }`, and the model reads `output`. */
|
|
156
|
-
export function toolSetOf(tools) {
|
|
157
|
-
return Object.fromEntries(tools.map((entry) => [
|
|
158
|
-
entry.spec.name,
|
|
159
|
-
tool({
|
|
160
|
-
description: entry.spec.description,
|
|
161
|
-
inputSchema: jsonSchema(entry.spec.inputSchema),
|
|
162
|
-
execute: (args) => entry.invoke(args),
|
|
163
|
-
toModelOutput: ({ output }) => ({
|
|
164
|
-
type: 'text',
|
|
165
|
-
value: resultOf(output).output,
|
|
166
|
-
}),
|
|
167
|
-
}),
|
|
168
|
-
]));
|
|
169
|
-
}
|
|
170
|
-
/** One model call's usage, as the run records it. */
|
|
171
|
-
function usageRecord(modelService, model, usage) {
|
|
172
|
-
return {
|
|
173
|
-
modelService,
|
|
174
|
-
model,
|
|
175
|
-
inputTokens: usage.inputTokens,
|
|
176
|
-
outputTokens: usage.outputTokens,
|
|
177
|
-
...(usage.cacheReadTokens === undefined
|
|
178
|
-
? {}
|
|
179
|
-
: { cacheReadTokens: usage.cacheReadTokens }),
|
|
180
|
-
...(usage.cacheWriteTokens === undefined
|
|
181
|
-
? {}
|
|
182
|
-
: { cacheWriteTokens: usage.cacheWriteTokens }),
|
|
183
|
-
...(usage.reasoningTokens === undefined
|
|
184
|
-
? {}
|
|
185
|
-
: { reasoningTokens: usage.reasoningTokens }),
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
export function createServerExecutor(deps, options = {}) {
|
|
189
|
-
/** The model's user turn: the inputs as text, and the images sent with a conversation's messages among them. */
|
|
190
|
-
async function userTurn(turn, inputs) {
|
|
191
|
-
const text = firstTurn(turn, inputs);
|
|
192
|
-
const images = [];
|
|
193
|
-
if (deps.images)
|
|
194
|
-
for (const input of inputs) {
|
|
195
|
-
const payload = input.payload;
|
|
196
|
-
if (typeof payload?.conversationId !== 'string' ||
|
|
197
|
-
!Array.isArray(payload.attachmentIds))
|
|
198
|
-
continue;
|
|
199
|
-
const ids = payload.attachmentIds.filter((id) => typeof id === 'string');
|
|
200
|
-
try {
|
|
201
|
-
images.push(...(await deps.images(payload.conversationId, ids, CHAT_IMAGE_TO_MODEL_MAX)));
|
|
202
|
-
}
|
|
203
|
-
catch (error) {
|
|
204
|
-
// The files stay listed by name; the turn goes on without the pictures.
|
|
205
|
-
deps.onError?.('Agents could not read the images of a message.', error);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
if (images.length === 0)
|
|
209
|
-
return { role: 'user', content: text };
|
|
210
|
-
return {
|
|
211
|
-
role: 'user',
|
|
212
|
-
content: [
|
|
213
|
-
{ type: 'text', text },
|
|
214
|
-
...images.map((image) => ({
|
|
215
|
-
type: 'file',
|
|
216
|
-
data: image.data,
|
|
217
|
-
mediaType: image.mediaType,
|
|
218
|
-
})),
|
|
219
|
-
],
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
const id = options.holderId ?? `server:${randomBytes(12).toString('hex')}`;
|
|
223
|
-
const holder = { id };
|
|
224
|
-
const maxSteps = options.maxSteps ?? DEFAULT_MAX_STEPS;
|
|
225
|
-
const maxRetries = options.maxRetries ?? 2;
|
|
226
|
-
const consultTimeoutMs = options.consult?.timeoutMs ?? DEFAULT_CONSULT_TIMEOUT_MS;
|
|
227
|
-
const consultTokenBudget = options.consult?.tokenBudget ?? DEFAULT_CONSULT_TOKEN_BUDGET;
|
|
228
|
-
const idlePollMs = options.idlePollMs ?? IDLE_POLL_MS;
|
|
229
|
-
const running = new Map();
|
|
230
|
-
const report = (message, error) => deps.onError?.(message, error);
|
|
231
|
-
let loop;
|
|
232
|
-
let stopping;
|
|
233
|
-
async function execute(claim, abort, child) {
|
|
234
|
-
const { runId, agent, run, model } = claim;
|
|
235
|
-
const used = { inputTokens: 0, outputTokens: 0 };
|
|
236
|
-
const plans = [];
|
|
237
|
-
let summary = '';
|
|
238
|
-
const outcome = (status, error = null) => ({
|
|
239
|
-
status,
|
|
240
|
-
answer: summary,
|
|
241
|
-
error,
|
|
242
|
-
usage: { ...used },
|
|
243
|
-
plans: [...plans],
|
|
244
|
-
});
|
|
245
|
-
let seq = claim.firstSeq;
|
|
246
|
-
const seen = new Set(claim.inputs.map((input) => input.id));
|
|
247
|
-
const fresh = [];
|
|
248
|
-
const now = () => deps.clock.now().toISOString();
|
|
249
|
-
const events = async (list) => {
|
|
250
|
-
if (list.length === 0)
|
|
251
|
-
return;
|
|
252
|
-
const at = now();
|
|
253
|
-
await deps.reports.events(holder, runId, {
|
|
254
|
-
events: list.map((event) => ({ ...event, seq: seq++, at })),
|
|
255
|
-
});
|
|
256
|
-
};
|
|
257
|
-
const absorb = (inputs) => {
|
|
258
|
-
for (const input of inputs)
|
|
259
|
-
if (!seen.has(input.id)) {
|
|
260
|
-
seen.add(input.id);
|
|
261
|
-
fresh.push(input);
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
// Lease renewal and cancel requests, beside the loop.
|
|
265
|
-
let lastLease = Date.now();
|
|
266
|
-
const watcher = setInterval(() => {
|
|
267
|
-
void (async () => {
|
|
268
|
-
try {
|
|
269
|
-
if (Date.now() - lastLease >= TIMINGS.leaseRenewMs) {
|
|
270
|
-
lastLease = Date.now();
|
|
271
|
-
const lease = await deps.reports.lease(holder, runId);
|
|
272
|
-
absorb(lease.inputs);
|
|
273
|
-
if (lease.cancelRequested)
|
|
274
|
-
abort.abort(new Stop('cancelled'));
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
const current = await deps.runs.get(runId);
|
|
278
|
-
if (current.cancelRequestedAt)
|
|
279
|
-
abort.abort(new Stop('cancelled'));
|
|
280
|
-
else if (current.runnerId !== id)
|
|
281
|
-
abort.abort(new Stop('lost'));
|
|
282
|
-
}
|
|
283
|
-
catch (error) {
|
|
284
|
-
if (error instanceof ProtocolError)
|
|
285
|
-
abort.abort(new Stop('lost'));
|
|
286
|
-
}
|
|
287
|
-
})();
|
|
288
|
-
}, CANCEL_POLL_MS);
|
|
289
|
-
watcher.unref?.();
|
|
290
|
-
const deadline = child
|
|
291
|
-
? setTimeout(() => abort.abort(new Stop('timeout')), child.timeoutMs)
|
|
292
|
-
: undefined;
|
|
293
|
-
deadline?.unref?.();
|
|
294
|
-
const stopReason = () => {
|
|
295
|
-
const reason = abort.signal.reason;
|
|
296
|
-
return abort.signal.aborted && reason instanceof Stop ? reason : null;
|
|
297
|
-
};
|
|
298
|
-
const check = () => {
|
|
299
|
-
const stop = stopReason();
|
|
300
|
-
if (stop)
|
|
301
|
-
throw stop;
|
|
302
|
-
};
|
|
303
|
-
try {
|
|
304
|
-
const started = await deps.reports.start(holder, runId, {
|
|
305
|
-
workDir: '',
|
|
306
|
-
acceptsInput: !child,
|
|
307
|
-
});
|
|
308
|
-
absorb(started.inputs);
|
|
309
|
-
if (started.cancelRequested)
|
|
310
|
-
throw new Stop('cancelled');
|
|
311
|
-
if (!model)
|
|
312
|
-
throw new RunFailure('modelUnavailable', 'The agent lists no model, and no model service offers a default chat model.');
|
|
313
|
-
const identity = {
|
|
314
|
-
kind: 'run',
|
|
315
|
-
userId: run.actorUserId,
|
|
316
|
-
displayName: agent.name,
|
|
317
|
-
run: await deps.runs.authenticateToken(claim.token),
|
|
318
|
-
agent,
|
|
319
|
-
};
|
|
320
|
-
const surface = await deps.commands(identity, claim.token);
|
|
321
|
-
const skills = [];
|
|
322
|
-
for (const skill of claim.skills)
|
|
323
|
-
try {
|
|
324
|
-
skills.push(await deps.skill(skill));
|
|
325
|
-
}
|
|
326
|
-
catch (error) {
|
|
327
|
-
report(`Agents could not read skill ${skill.slug} for run ${runId}.`, error);
|
|
328
|
-
}
|
|
329
|
-
for (const skill of deps.builtInSkills?.() ?? [])
|
|
330
|
-
if (!skills.some((own) => own.slug === skill.slug))
|
|
331
|
-
skills.push(skill);
|
|
332
|
-
const tools = onlineTools(skills, surface ? [cliCommand(surface)] : []);
|
|
333
|
-
let languageModel;
|
|
334
|
-
try {
|
|
335
|
-
languageModel = await deps.gateway.languageModel({ modelService: model.modelService, model: model.model }, { session: sessionOf(run) });
|
|
336
|
-
}
|
|
337
|
-
catch (error) {
|
|
338
|
-
throw modelFailure(error);
|
|
339
|
-
}
|
|
340
|
-
const handled = new Set(claim.inputs.map((input) => input.id));
|
|
341
|
-
const messages = [await userTurn(claim.turn, claim.inputs)];
|
|
342
|
-
// What arrived before the run started and was not in the claim (a message sent while it was being taken).
|
|
343
|
-
const early = fresh.splice(0).filter((input) => !handled.has(input.id));
|
|
344
|
-
if (early.length > 0) {
|
|
345
|
-
for (const input of early)
|
|
346
|
-
handled.add(input.id);
|
|
347
|
-
messages.push(await userTurn('', early));
|
|
348
|
-
}
|
|
349
|
-
const toolSet = toolSetOf(tools);
|
|
350
|
-
const consultations = deps.consultations;
|
|
351
|
-
if (consultations && claim.consultable.length > 0)
|
|
352
|
-
toolSet[ASK_AGENT_TOOL] = consultTool({
|
|
353
|
-
parent: claim,
|
|
354
|
-
holder,
|
|
355
|
-
consultations,
|
|
356
|
-
claims: deps.claims,
|
|
357
|
-
run: (childClaim, signal, onDraft) => consult(childClaim, signal, onDraft),
|
|
358
|
-
});
|
|
359
|
-
const settings = {
|
|
360
|
-
model: languageModel,
|
|
361
|
-
// The brief is the same for every model call of the run: the provider may cache it.
|
|
362
|
-
instructions: {
|
|
363
|
-
role: 'system',
|
|
364
|
-
content: claim.system,
|
|
365
|
-
providerOptions: {
|
|
366
|
-
anthropic: { cacheControl: { type: 'ephemeral' } },
|
|
367
|
-
},
|
|
368
|
-
},
|
|
369
|
-
tools: toolSet,
|
|
370
|
-
toolOrder: Object.keys(toolSet),
|
|
371
|
-
reasoning: reasoningOf(model.effort),
|
|
372
|
-
maxRetries,
|
|
373
|
-
};
|
|
374
|
-
let steps = 0;
|
|
375
|
-
// Consultation cards, written in order, the answer as it streams at most every `CARD_INTERVAL_MS`.
|
|
376
|
-
let cards = Promise.resolve();
|
|
377
|
-
const cardWritten = new Map();
|
|
378
|
-
const writeCard = (card, final) => {
|
|
379
|
-
const last = cardWritten.get(card.callId);
|
|
380
|
-
if (!final &&
|
|
381
|
-
last !== undefined &&
|
|
382
|
-
Date.now() - last < CARD_INTERVAL_MS)
|
|
383
|
-
return;
|
|
384
|
-
cardWritten.set(card.callId, Date.now());
|
|
385
|
-
cards = cards
|
|
386
|
-
.then(() => deps.conversations.consultation(run, card))
|
|
387
|
-
.catch((error) => report(`Agents could not show a consultation of run ${runId}.`, error));
|
|
388
|
-
};
|
|
389
|
-
for (;;) {
|
|
390
|
-
check();
|
|
391
|
-
if (steps >= maxSteps)
|
|
392
|
-
throw new RunFailure('stepLimit', `The agent called tools ${maxSteps} times without answering.`);
|
|
393
|
-
const agentLoop = new ToolLoopAgent({
|
|
394
|
-
...settings,
|
|
395
|
-
stopWhen: stepCountIs(maxSteps - steps),
|
|
396
|
-
});
|
|
397
|
-
let pending = Promise.resolve();
|
|
398
|
-
let text = '';
|
|
399
|
-
let reasoning = '';
|
|
400
|
-
let settled = false;
|
|
401
|
-
let flushed = 0;
|
|
402
|
-
let lastReason;
|
|
403
|
-
let turnSteps = 0;
|
|
404
|
-
const flush = () => {
|
|
405
|
-
const snapshot = text;
|
|
406
|
-
pending = pending
|
|
407
|
-
.then(() => child
|
|
408
|
-
? child.onDraft(snapshot)
|
|
409
|
-
: deps.conversations.streamDraft(run, snapshot))
|
|
410
|
-
.catch((error) => report(`Agents could not show the draft of run ${runId}.`, error));
|
|
411
|
-
};
|
|
412
|
-
// A step's text and thinking are written once, before its tool calls; its text becomes the final message
|
|
413
|
-
// before the next step drafts again.
|
|
414
|
-
const settle = async () => {
|
|
415
|
-
if (settled)
|
|
416
|
-
return;
|
|
417
|
-
settled = true;
|
|
418
|
-
await pending;
|
|
419
|
-
await events([
|
|
420
|
-
...(reasoning.trim()
|
|
421
|
-
? [{ type: 'thinking', content: reasoning }]
|
|
422
|
-
: []),
|
|
423
|
-
...(text.trim() ? [{ type: 'text', content: text }] : []),
|
|
424
|
-
]);
|
|
425
|
-
if (text.trim()) {
|
|
426
|
-
summary = text;
|
|
427
|
-
await deps.conversations.syncRun(runId);
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
let response;
|
|
431
|
-
try {
|
|
432
|
-
const result = await agentLoop.stream({
|
|
433
|
-
messages,
|
|
434
|
-
abortSignal: abort.signal,
|
|
435
|
-
});
|
|
436
|
-
for await (const part of result.fullStream)
|
|
437
|
-
switch (part.type) {
|
|
438
|
-
case 'start-step':
|
|
439
|
-
text = '';
|
|
440
|
-
reasoning = '';
|
|
441
|
-
settled = false;
|
|
442
|
-
flushed = 0;
|
|
443
|
-
break;
|
|
444
|
-
case 'text-delta':
|
|
445
|
-
text += part.text;
|
|
446
|
-
if (Date.now() - flushed >= DRAFT_INTERVAL_MS) {
|
|
447
|
-
flushed = Date.now();
|
|
448
|
-
flush();
|
|
449
|
-
}
|
|
450
|
-
break;
|
|
451
|
-
case 'reasoning-delta':
|
|
452
|
-
reasoning += part.text;
|
|
453
|
-
break;
|
|
454
|
-
case 'tool-call':
|
|
455
|
-
await settle();
|
|
456
|
-
await events([
|
|
457
|
-
{ type: 'toolUse', tool: part.toolName, input: part.input },
|
|
458
|
-
]);
|
|
459
|
-
break;
|
|
460
|
-
case 'tool-result': {
|
|
461
|
-
if (part.toolName === ASK_AGENT_TOOL) {
|
|
462
|
-
const consulted = part.output;
|
|
463
|
-
writeCard(consulted.card, !part.preliminary);
|
|
464
|
-
if (part.preliminary)
|
|
465
|
-
break;
|
|
466
|
-
await cards;
|
|
467
|
-
await events([
|
|
468
|
-
{
|
|
469
|
-
type: 'toolResult',
|
|
470
|
-
tool: part.toolName,
|
|
471
|
-
output: consultText(consulted),
|
|
472
|
-
meta: {
|
|
473
|
-
ok: consulted.card.state === 'completed',
|
|
474
|
-
...(consulted.card.runId
|
|
475
|
-
? { runId: consulted.card.runId }
|
|
476
|
-
: {}),
|
|
477
|
-
},
|
|
478
|
-
},
|
|
479
|
-
]);
|
|
480
|
-
break;
|
|
481
|
-
}
|
|
482
|
-
const result = resultOf(part.output);
|
|
483
|
-
const plan = part.toolName === 'bash' ? planOf(result.output) : null;
|
|
484
|
-
if (plan)
|
|
485
|
-
plans.push(plan);
|
|
486
|
-
await events([
|
|
487
|
-
{
|
|
488
|
-
type: 'toolResult',
|
|
489
|
-
tool: part.toolName,
|
|
490
|
-
output: result.output,
|
|
491
|
-
meta: { ok: result.ok },
|
|
492
|
-
},
|
|
493
|
-
]);
|
|
494
|
-
break;
|
|
495
|
-
}
|
|
496
|
-
case 'tool-error':
|
|
497
|
-
await events([
|
|
498
|
-
{
|
|
499
|
-
type: 'toolResult',
|
|
500
|
-
tool: part.toolName,
|
|
501
|
-
output: errorOutput(new ProtocolError('COMMAND_UNKNOWN', part.error instanceof Error
|
|
502
|
-
? part.error.message
|
|
503
|
-
: String(part.error))),
|
|
504
|
-
meta: { ok: false },
|
|
505
|
-
},
|
|
506
|
-
]);
|
|
507
|
-
break;
|
|
508
|
-
case 'finish-step': {
|
|
509
|
-
await settle();
|
|
510
|
-
turnSteps += 1;
|
|
511
|
-
lastReason = part.finishReason;
|
|
512
|
-
const usage = usageOf(part.usage);
|
|
513
|
-
await deps.reports.onlineUsage(holder, runId, usageRecord(model.modelService, part.response.modelId || model.model, usage));
|
|
514
|
-
used.inputTokens +=
|
|
515
|
-
usage.inputTokens +
|
|
516
|
-
(usage.cacheReadTokens ?? 0) +
|
|
517
|
-
(usage.cacheWriteTokens ?? 0);
|
|
518
|
-
used.outputTokens += usage.outputTokens;
|
|
519
|
-
if (child &&
|
|
520
|
-
used.inputTokens + used.outputTokens > child.tokenBudget) {
|
|
521
|
-
abort.abort(new Stop('budget'));
|
|
522
|
-
check();
|
|
523
|
-
}
|
|
524
|
-
break;
|
|
525
|
-
}
|
|
526
|
-
case 'error':
|
|
527
|
-
throw modelFailure(part.error);
|
|
528
|
-
case 'abort':
|
|
529
|
-
throw modelFailure(new ModelError('aborted', 'The call was stopped.'));
|
|
530
|
-
default:
|
|
531
|
-
break;
|
|
532
|
-
}
|
|
533
|
-
response = await result.response;
|
|
534
|
-
}
|
|
535
|
-
catch (error) {
|
|
536
|
-
check();
|
|
537
|
-
if (error instanceof RunFailure)
|
|
538
|
-
throw error;
|
|
539
|
-
throw modelFailure(error);
|
|
540
|
-
}
|
|
541
|
-
finally {
|
|
542
|
-
await pending;
|
|
543
|
-
await cards;
|
|
544
|
-
}
|
|
545
|
-
check();
|
|
546
|
-
steps += turnSteps;
|
|
547
|
-
messages.push(...response.messages);
|
|
548
|
-
// The loop stopped at the step limit while the model still called tools.
|
|
549
|
-
if (lastReason === 'tool-calls')
|
|
550
|
-
throw new RunFailure('stepLimit', `The agent called tools ${maxSteps} times without answering.`);
|
|
551
|
-
// Answered. Input that arrived meanwhile is answered in the same run.
|
|
552
|
-
absorb((await deps.reports.lease(holder, runId)).inputs);
|
|
553
|
-
lastLease = Date.now();
|
|
554
|
-
const later = fresh.splice(0).filter((input) => !handled.has(input.id));
|
|
555
|
-
if (later.length > 0) {
|
|
556
|
-
for (const input of later)
|
|
557
|
-
handled.add(input.id);
|
|
558
|
-
await events([
|
|
559
|
-
{
|
|
560
|
-
type: 'input',
|
|
561
|
-
meta: { inputIds: later.map((input) => input.id) },
|
|
562
|
-
},
|
|
563
|
-
]);
|
|
564
|
-
messages.push(await userTurn('', later));
|
|
565
|
-
continue;
|
|
566
|
-
}
|
|
567
|
-
if (!text.trim() && steps === 1 && !summary)
|
|
568
|
-
throw new RunFailure('unknown', 'The model answered nothing.');
|
|
569
|
-
await deps.reports.complete(holder, runId, {
|
|
570
|
-
summary: summary.slice(0, 10_000),
|
|
571
|
-
handledInputIds: [...handled],
|
|
572
|
-
});
|
|
573
|
-
return outcome('completed');
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
catch (error) {
|
|
577
|
-
return await end(runId, error);
|
|
578
|
-
}
|
|
579
|
-
finally {
|
|
580
|
-
clearInterval(watcher);
|
|
581
|
-
if (deadline)
|
|
582
|
-
clearTimeout(deadline);
|
|
583
|
-
}
|
|
584
|
-
async function end(runIdEnded, error) {
|
|
585
|
-
try {
|
|
586
|
-
if (error instanceof Stop) {
|
|
587
|
-
if (error.kind === 'lost')
|
|
588
|
-
return outcome('failed', 'The run was taken over elsewhere.');
|
|
589
|
-
if (error.kind === 'cancelled') {
|
|
590
|
-
await deps.reports.cancelAck(holder, runIdEnded, {});
|
|
591
|
-
return outcome('cancelled', 'It was stopped.');
|
|
592
|
-
}
|
|
593
|
-
if (error.kind === 'timeout' || error.kind === 'budget') {
|
|
594
|
-
const detail = error.kind === 'timeout'
|
|
595
|
-
? `The consultation took longer than ${seconds(child?.timeoutMs ?? 0)}.`
|
|
596
|
-
: `The consultation used more than ${child?.tokenBudget ?? 0} tokens.`;
|
|
597
|
-
await deps.reports.fail(holder, runIdEnded, {
|
|
598
|
-
reason: 'unknown',
|
|
599
|
-
detail,
|
|
600
|
-
});
|
|
601
|
-
return outcome('failed', detail);
|
|
602
|
-
}
|
|
603
|
-
await deps.reports.fail(holder, runIdEnded, {
|
|
604
|
-
reason: 'runnerOffline',
|
|
605
|
-
detail: 'The application stopped while the agent worked.',
|
|
606
|
-
});
|
|
607
|
-
return outcome('failed', 'The application stopped.');
|
|
608
|
-
}
|
|
609
|
-
const failure = error instanceof RunFailure
|
|
610
|
-
? error
|
|
611
|
-
: new RunFailure('unknown', error instanceof Error ? error.message : String(error));
|
|
612
|
-
if (!(error instanceof RunFailure))
|
|
613
|
-
report(`Agents' online run ${runIdEnded} failed.`, error);
|
|
614
|
-
await deps.reports.fail(holder, runIdEnded, {
|
|
615
|
-
reason: failure.reason,
|
|
616
|
-
detail: failure.message.slice(0, 2_000),
|
|
617
|
-
});
|
|
618
|
-
return outcome('failed', failure.message.slice(0, 2_000));
|
|
619
|
-
}
|
|
620
|
-
catch (reportError) {
|
|
621
|
-
// The run moved on (the sweeper took it, or it was cancelled meanwhile): nothing left to report.
|
|
622
|
-
if (!(reportError instanceof ProtocolError))
|
|
623
|
-
report(`Agents could not end online run ${runIdEnded}.`, reportError);
|
|
624
|
-
return outcome('failed', error instanceof Error ? error.message : String(error));
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
/**
|
|
629
|
-
* Runs a consultation `ask_agent` started, within the asking tool call: aborted with the run that asked (cancelled with
|
|
630
|
-
* it, or handed back when the instance stops), and within the consultation's time and token budget.
|
|
631
|
-
*/
|
|
632
|
-
async function consult(claim, signal, onDraft) {
|
|
633
|
-
const abort = new AbortController();
|
|
634
|
-
const follow = () => {
|
|
635
|
-
const reason = signal?.reason;
|
|
636
|
-
abort.abort(new Stop(reason instanceof Stop && reason.kind === 'cancelled'
|
|
637
|
-
? 'cancelled'
|
|
638
|
-
: 'shutdown'));
|
|
639
|
-
};
|
|
640
|
-
if (signal?.aborted)
|
|
641
|
-
follow();
|
|
642
|
-
else
|
|
643
|
-
signal?.addEventListener('abort', follow, { once: true });
|
|
644
|
-
try {
|
|
645
|
-
return await execute(claim, abort, {
|
|
646
|
-
onDraft,
|
|
647
|
-
timeoutMs: consultTimeoutMs,
|
|
648
|
-
tokenBudget: consultTokenBudget,
|
|
649
|
-
});
|
|
650
|
-
}
|
|
651
|
-
finally {
|
|
652
|
-
signal?.removeEventListener('abort', follow);
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
function launch(claim) {
|
|
656
|
-
const abort = new AbortController();
|
|
657
|
-
const done = execute(claim, abort)
|
|
658
|
-
.then(() => undefined)
|
|
659
|
-
.catch((error) => report(`Agents' online run ${claim.runId} failed.`, error))
|
|
660
|
-
.finally(() => running.delete(claim.runId));
|
|
661
|
-
running.set(claim.runId, { abort, done });
|
|
662
|
-
}
|
|
663
|
-
async function take() {
|
|
664
|
-
try {
|
|
665
|
-
return await deps.claims.claimServer(holder, CLAIM_BATCH);
|
|
666
|
-
}
|
|
667
|
-
catch (error) {
|
|
668
|
-
report('Agents could not take online runs.', error);
|
|
669
|
-
return [];
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
return {
|
|
673
|
-
id,
|
|
674
|
-
start() {
|
|
675
|
-
if (loop)
|
|
676
|
-
return;
|
|
677
|
-
stopping = new AbortController();
|
|
678
|
-
const signal = stopping.signal;
|
|
679
|
-
loop = (async () => {
|
|
680
|
-
while (!signal.aborted) {
|
|
681
|
-
const claimed = await take();
|
|
682
|
-
for (const claim of claimed)
|
|
683
|
-
launch(claim);
|
|
684
|
-
if (claimed.length === 0)
|
|
685
|
-
await deps.signal.wait(idlePollMs, signal);
|
|
686
|
-
}
|
|
687
|
-
})();
|
|
688
|
-
},
|
|
689
|
-
async stop() {
|
|
690
|
-
stopping?.abort();
|
|
691
|
-
await loop;
|
|
692
|
-
loop = undefined;
|
|
693
|
-
for (const { abort } of running.values())
|
|
694
|
-
abort.abort(new Stop('shutdown'));
|
|
695
|
-
await Promise.all([...running.values()].map((entry) => entry.done));
|
|
696
|
-
},
|
|
697
|
-
async drain() {
|
|
698
|
-
let total = 0;
|
|
699
|
-
for (;;) {
|
|
700
|
-
const claimed = await take();
|
|
701
|
-
if (claimed.length === 0)
|
|
702
|
-
break;
|
|
703
|
-
total += claimed.length;
|
|
704
|
-
for (const claim of claimed)
|
|
705
|
-
launch(claim);
|
|
706
|
-
await Promise.all([...running.values()].map((entry) => entry.done));
|
|
707
|
-
}
|
|
708
|
-
await Promise.all([...running.values()].map((entry) => entry.done));
|
|
709
|
-
return total;
|
|
710
|
-
},
|
|
711
|
-
active: () => running.size,
|
|
712
|
-
};
|
|
713
|
-
}
|
|
714
|
-
//# sourceMappingURL=executor.js.map
|