@swarmclawai/swarmclaw 1.2.4 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/bin/daemon-cmd.js +169 -0
- package/bin/server-cmd.js +3 -0
- package/bin/swarmclaw.js +11 -0
- package/package.json +17 -16
- package/src/app/api/agents/[id]/clone/route.ts +3 -32
- package/src/app/api/agents/[id]/route.ts +6 -158
- package/src/app/api/agents/[id]/status/route.ts +2 -3
- package/src/app/api/agents/[id]/thread/route.ts +4 -17
- package/src/app/api/agents/bulk/route.ts +5 -47
- package/src/app/api/agents/route.ts +5 -119
- package/src/app/api/agents/trash/route.ts +13 -24
- package/src/app/api/auth/route.ts +3 -9
- package/src/app/api/autonomy/estop/route.ts +5 -5
- package/src/app/api/chatrooms/[id]/chat/route.ts +11 -5
- package/src/app/api/chatrooms/[id]/route.ts +23 -2
- package/src/app/api/chatrooms/route.ts +13 -2
- package/src/app/api/chats/[id]/clear/route.ts +2 -13
- package/src/app/api/chats/[id]/deploy/route.ts +2 -3
- package/src/app/api/chats/[id]/edit-resend/route.ts +7 -13
- package/src/app/api/chats/[id]/mailbox/route.ts +6 -8
- package/src/app/api/chats/[id]/queue/route.ts +17 -64
- package/src/app/api/chats/[id]/retry/route.ts +4 -22
- package/src/app/api/chats/[id]/route.ts +10 -138
- package/src/app/api/chats/heartbeat/route.ts +2 -1
- package/src/app/api/chats/migrate-messages/route.ts +7 -0
- package/src/app/api/chats/route.ts +13 -134
- package/src/app/api/connectors/[id]/access/route.ts +12 -229
- package/src/app/api/connectors/[id]/doctor/route.ts +1 -1
- package/src/app/api/connectors/[id]/health/route.ts +12 -39
- package/src/app/api/connectors/[id]/route.ts +14 -122
- package/src/app/api/connectors/[id]/webhook/route.ts +1 -1
- package/src/app/api/connectors/doctor/route.ts +1 -1
- package/src/app/api/connectors/route.ts +12 -70
- package/src/app/api/credentials/[id]/route.ts +2 -4
- package/src/app/api/credentials/route.ts +10 -19
- package/src/app/api/daemon/health-check/route.ts +3 -4
- package/src/app/api/daemon/route.ts +10 -8
- package/src/app/api/documents/route.ts +11 -10
- package/src/app/api/external-agents/route.ts +3 -3
- package/src/app/api/gateways/[id]/health/route.ts +2 -3
- package/src/app/api/gateways/[id]/route.ts +7 -122
- package/src/app/api/gateways/route.ts +3 -103
- package/src/app/api/mcp-servers/[id]/tools/route.ts +5 -5
- package/src/app/api/openclaw/dashboard-url/route.ts +8 -16
- package/src/app/api/openclaw/directory/route.ts +2 -2
- package/src/app/api/openclaw/history/route.ts +3 -5
- package/src/app/api/providers/[id]/route.test.ts +49 -0
- package/src/app/api/providers/ollama/route.ts +6 -5
- package/src/app/api/schedules/[id]/route.ts +14 -108
- package/src/app/api/schedules/[id]/run/route.ts +6 -67
- package/src/app/api/schedules/route.ts +9 -51
- package/src/app/api/settings/route.ts +4 -3
- package/src/app/api/setup/check-provider/route.ts +15 -1
- package/src/app/api/setup/openclaw-device/route.ts +2 -2
- package/src/app/api/system/status/route.ts +2 -2
- package/src/app/api/tasks/[id]/route.ts +16 -202
- package/src/app/api/tasks/bulk/route.ts +5 -86
- package/src/app/api/tasks/metrics/route.ts +2 -1
- package/src/app/api/tasks/route.ts +11 -171
- package/src/app/api/upload/route.ts +1 -1
- package/src/app/api/uploads/[filename]/route.ts +1 -1
- package/src/app/api/uploads/route.ts +1 -1
- package/src/app/api/webhooks/[id]/history/route.ts +2 -2
- package/src/app/layout.tsx +9 -6
- package/src/app/protocols/page.tsx +71 -89
- package/src/app/tasks/page.tsx +32 -32
- package/src/cli/index.js +1 -0
- package/src/cli/spec.js +1 -0
- package/src/components/agents/agent-sheet.tsx +5 -5
- package/src/components/auth/setup-wizard/index.tsx +4 -4
- package/src/components/auth/setup-wizard/step-agents.tsx +1 -1
- package/src/components/auth/setup-wizard/step-connect.tsx +1 -1
- package/src/components/auth/setup-wizard/utils.ts +1 -1
- package/src/components/chatrooms/chatroom-sheet.tsx +16 -276
- package/src/components/connectors/connector-list.tsx +26 -40
- package/src/components/connectors/connector-sheet.tsx +95 -149
- package/src/components/gateways/gateway-sheet.tsx +61 -110
- package/src/components/layout/live-query-sync.tsx +121 -0
- package/src/components/protocols/structured-session-launcher.tsx +24 -45
- package/src/components/providers/app-query-provider.tsx +17 -0
- package/src/components/providers/provider-list.tsx +60 -61
- package/src/components/providers/provider-sheet.tsx +74 -56
- package/src/components/skills/skill-list.tsx +5 -18
- package/src/components/skills/skill-sheet.tsx +21 -20
- package/src/components/skills/skills-workspace.tsx +48 -87
- package/src/components/tasks/task-card.tsx +20 -13
- package/src/components/tasks/task-column.tsx +22 -7
- package/src/components/tasks/task-list.tsx +8 -11
- package/src/components/tasks/task-sheet.tsx +111 -103
- package/src/features/agents/queries.ts +20 -0
- package/src/features/chatrooms/queries.ts +20 -0
- package/src/features/chats/queries.ts +27 -0
- package/src/features/connectors/queries.ts +145 -0
- package/src/features/credentials/queries.ts +37 -0
- package/src/features/extensions/queries.ts +26 -0
- package/src/features/external-agents/queries.ts +36 -0
- package/src/features/gateways/queries.ts +274 -0
- package/src/features/missions/queries.ts +23 -0
- package/src/features/projects/queries.ts +20 -0
- package/src/features/protocols/queries.ts +149 -0
- package/src/features/providers/queries.ts +142 -0
- package/src/features/settings/queries.ts +20 -0
- package/src/features/skills/queries.ts +182 -0
- package/src/features/tasks/queries.ts +189 -0
- package/src/hooks/use-ws.ts +3 -2
- package/src/lib/app/api-client.ts +2 -2
- package/src/lib/query/client.ts +17 -0
- package/src/lib/server/agents/agent-runtime-config.ts +1 -1
- package/src/lib/server/agents/agent-service.ts +429 -0
- package/src/lib/server/agents/agent-thread-session.ts +6 -5
- package/src/lib/server/agents/autonomy-contract.ts +1 -4
- package/src/lib/server/agents/delegation-advisory.test.ts +206 -0
- package/src/lib/server/agents/delegation-advisory.ts +251 -0
- package/src/lib/server/agents/main-agent-loop.ts +98 -40
- package/src/lib/server/agents/subagent-runtime.ts +12 -0
- package/src/lib/server/autonomy/supervisor-reflection.test.ts +20 -1
- package/src/lib/server/autonomy/supervisor-reflection.ts +39 -19
- package/src/lib/server/build-llm.ts +7 -15
- package/src/lib/server/capability-router.test.ts +70 -1
- package/src/lib/server/capability-router.ts +24 -99
- package/src/lib/server/chat-execution/chat-execution-utils.ts +0 -15
- package/src/lib/server/chat-execution/chat-streaming-utils.ts +2 -4
- package/src/lib/server/chat-execution/chat-turn-finalization.ts +77 -12
- package/src/lib/server/chat-execution/chat-turn-partial-persistence.ts +4 -4
- package/src/lib/server/chat-execution/chat-turn-preflight.ts +2 -2
- package/src/lib/server/chat-execution/chat-turn-preparation.ts +41 -17
- package/src/lib/server/chat-execution/chat-turn-stream-execution.ts +4 -2
- package/src/lib/server/chat-execution/chat-turn-tool-routing.test.ts +45 -0
- package/src/lib/server/chat-execution/chat-turn-tool-routing.ts +48 -17
- package/src/lib/server/chat-execution/continuation-evaluator.ts +4 -1
- package/src/lib/server/chat-execution/direct-memory-intent.test.ts +9 -0
- package/src/lib/server/chat-execution/direct-memory-intent.ts +12 -2
- package/src/lib/server/chat-execution/message-classifier.test.ts +35 -23
- package/src/lib/server/chat-execution/message-classifier.ts +74 -32
- package/src/lib/server/chat-execution/prompt-builder.test.ts +29 -0
- package/src/lib/server/chat-execution/prompt-builder.ts +37 -2
- package/src/lib/server/chat-execution/prompt-sections.test.ts +56 -0
- package/src/lib/server/chat-execution/prompt-sections.ts +193 -0
- package/src/lib/server/chat-execution/stream-agent-chat.ts +63 -7
- package/src/lib/server/chat-execution/stream-continuation.test.ts +36 -0
- package/src/lib/server/chat-execution/stream-continuation.ts +28 -13
- package/src/lib/server/chatrooms/chatroom-agent-signals.ts +26 -18
- package/src/lib/server/chatrooms/chatroom-helpers.ts +19 -18
- package/src/lib/server/chatrooms/chatroom-repository.ts +16 -0
- package/src/lib/server/chatrooms/chatroom-routing.test.ts +96 -0
- package/src/lib/server/chatrooms/chatroom-routing.ts +207 -53
- package/src/lib/server/chatrooms/mailbox-utils.ts +4 -2
- package/src/lib/server/chatrooms/session-mailbox.ts +50 -40
- package/src/lib/server/chats/chat-session-service.ts +410 -0
- package/src/lib/server/connectors/access.ts +1 -1
- package/src/lib/server/connectors/commands.ts +7 -6
- package/src/lib/server/connectors/connector-inbound.ts +14 -7
- package/src/lib/server/connectors/connector-outbound.ts +16 -11
- package/src/lib/server/connectors/connector-service.ts +453 -0
- package/src/lib/server/connectors/delivery.ts +17 -12
- package/src/lib/server/connectors/inbound-audio-transcription.ts +5 -14
- package/src/lib/server/connectors/media.ts +1 -1
- package/src/lib/server/connectors/response-media.ts +1 -1
- package/src/lib/server/connectors/session-consolidation.ts +11 -7
- package/src/lib/server/connectors/session.ts +9 -7
- package/src/lib/server/connectors/voice-note.ts +2 -1
- package/src/lib/server/context-manager.ts +20 -1
- package/src/lib/server/cost.ts +2 -3
- package/src/lib/server/credentials/credential-repository.ts +43 -4
- package/src/lib/server/credentials/credential-service.ts +112 -0
- package/src/lib/server/daemon/admin-metadata.ts +64 -0
- package/src/lib/server/daemon/controller.ts +577 -0
- package/src/lib/server/daemon/daemon-runtime.ts +352 -0
- package/src/lib/server/daemon/daemon-status-repository.ts +63 -0
- package/src/lib/server/daemon/types.ts +101 -0
- package/src/lib/server/embeddings.ts +3 -9
- package/src/lib/server/eval/agent-regression.ts +3 -2
- package/src/lib/server/eval/runner.ts +2 -2
- package/src/lib/server/execution-brief.test.ts +167 -0
- package/src/lib/server/execution-brief.ts +295 -0
- package/src/lib/server/execution-engine/chat-turn.ts +9 -0
- package/src/lib/server/execution-engine/import-boundary.test.ts +44 -0
- package/src/lib/server/execution-engine/index.ts +35 -0
- package/src/lib/server/execution-engine/task-attempt.ts +303 -0
- package/src/lib/server/execution-engine/types.ts +33 -0
- package/src/lib/server/gateways/gateway-profile-repository.ts +47 -3
- package/src/lib/server/gateways/gateway-profile-service.ts +200 -0
- package/src/lib/server/memory/session-archive-memory.ts +12 -10
- package/src/lib/server/messages/message-repository.ts +330 -0
- package/src/lib/server/missions/mission-service/core.ts +8 -6
- package/src/lib/server/openclaw/agent-resolver.ts +2 -3
- package/src/lib/server/openclaw/doctor.ts +1 -1
- package/src/lib/server/openclaw/gateway.test.ts +10 -1
- package/src/lib/server/openclaw/gateway.ts +5 -14
- package/src/lib/server/openclaw/health.ts +3 -11
- package/src/lib/server/openclaw/sync.ts +8 -6
- package/src/lib/server/persistence/storage-context.ts +3 -0
- package/src/lib/server/protocols/protocol-agent-turn.ts +25 -17
- package/src/lib/server/protocols/protocol-normalization.ts +1 -1
- package/src/lib/server/protocols/protocol-queries.ts +13 -7
- package/src/lib/server/protocols/protocol-run-lifecycle.ts +16 -20
- package/src/lib/server/protocols/protocol-run-repository.ts +81 -0
- package/src/lib/server/protocols/protocol-step-processors.ts +23 -31
- package/src/lib/server/protocols/protocol-swarm.ts +8 -8
- package/src/lib/server/protocols/protocol-template-repository.ts +42 -0
- package/src/lib/server/protocols/protocol-templates.ts +4 -2
- package/src/lib/server/protocols/protocol-types.ts +10 -7
- package/src/lib/server/provider-endpoint.ts +7 -12
- package/src/lib/server/provider-model-discovery.ts +2 -11
- package/src/lib/server/query-expansion.ts +5 -6
- package/src/lib/server/run-context.test.ts +365 -0
- package/src/lib/server/run-context.ts +367 -0
- package/src/lib/server/runtime/heartbeat-service.ts +7 -5
- package/src/lib/server/runtime/queue/core.ts +61 -190
- package/src/lib/server/runtime/run-ledger.ts +8 -0
- package/src/lib/server/runtime/session-run-manager/drain.ts +2 -2
- package/src/lib/server/runtime/session-run-manager/enqueue.ts +6 -0
- package/src/lib/server/runtime/session-run-manager/state.ts +4 -0
- package/src/lib/server/schedules/schedule-route-service.ts +230 -0
- package/src/lib/server/service-result.ts +16 -0
- package/src/lib/server/session-note.ts +2 -3
- package/src/lib/server/session-reset-policy.ts +4 -3
- package/src/lib/server/session-tools/connector.ts +9 -6
- package/src/lib/server/session-tools/context-mgmt.ts +58 -9
- package/src/lib/server/session-tools/crud.ts +162 -10
- package/src/lib/server/session-tools/delegate.ts +1 -1
- package/src/lib/server/session-tools/manage-tasks.test.ts +152 -0
- package/src/lib/server/session-tools/memory.ts +6 -4
- package/src/lib/server/session-tools/session-info.test.ts +56 -0
- package/src/lib/server/session-tools/session-info.ts +119 -12
- package/src/lib/server/session-tools/skill-runtime.ts +3 -1
- package/src/lib/server/session-tools/skills.ts +15 -15
- package/src/lib/server/session-tools/subagent.test.ts +115 -1
- package/src/lib/server/session-tools/subagent.ts +125 -7
- package/src/lib/server/session-tools/team-context.ts +4 -3
- package/src/lib/server/session-tools/wallet.ts +0 -58
- package/src/lib/server/sessions/session-lineage.ts +55 -0
- package/src/lib/server/sessions/session-repository.ts +2 -2
- package/src/lib/server/skills/learned-skills.ts +24 -23
- package/src/lib/server/skills/runtime-skill-resolver.ts +2 -1
- package/src/lib/server/skills/skill-repository.ts +136 -13
- package/src/lib/server/skills/skill-suggestions.ts +25 -28
- package/src/lib/server/storage-normalization.test.ts +44 -267
- package/src/lib/server/storage-normalization.ts +75 -0
- package/src/lib/server/storage.ts +19 -0
- package/src/lib/server/structured-extract.ts +3 -14
- package/src/lib/server/tasks/task-followups.ts +16 -11
- package/src/lib/server/tasks/task-result.test.ts +25 -29
- package/src/lib/server/tasks/task-result.ts +5 -9
- package/src/lib/server/tasks/task-route-service.ts +449 -0
- package/src/lib/server/text-normalization.ts +41 -0
- package/src/lib/server/tool-planning.ts +6 -42
- package/src/lib/server/upload-path.ts +5 -0
- package/src/lib/server/working-state/extraction.ts +614 -0
- package/src/lib/server/working-state/normalization.ts +866 -0
- package/src/lib/server/working-state/prompt.ts +60 -0
- package/src/lib/server/working-state/repository.ts +38 -0
- package/src/lib/server/working-state/service.test.ts +253 -0
- package/src/lib/server/working-state/service.ts +293 -0
- package/src/lib/validation/schemas.ts +1 -0
- package/src/lib/ws-client.ts +3 -3
- package/src/stores/slices/task-slice.ts +1 -4
- package/src/stores/use-chatroom-store.ts +2 -2
- package/src/types/index.ts +277 -12
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { useEffect, useState } from 'react'
|
|
3
|
+
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
4
4
|
import { useRouter } from 'next/navigation'
|
|
5
5
|
import ReactMarkdown from 'react-markdown'
|
|
6
6
|
import remarkGfm from 'remark-gfm'
|
|
7
7
|
import { useAppStore } from '@/stores/use-app-store'
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { useAgentsQuery } from '@/features/agents/queries'
|
|
9
|
+
import {
|
|
10
|
+
useAppendTaskCommentMutation,
|
|
11
|
+
useCreateTaskMutation,
|
|
12
|
+
useTasksQuery,
|
|
13
|
+
useUpdateTaskMutation,
|
|
14
|
+
} from '@/features/tasks/queries'
|
|
15
|
+
import { useProjectsQuery } from '@/features/projects/queries'
|
|
16
|
+
import { useAppSettingsQuery } from '@/features/settings/queries'
|
|
17
|
+
import { useProtocolRunsQuery } from '@/features/protocols/queries'
|
|
10
18
|
import { getMissionPath } from '@/lib/app/navigation'
|
|
11
19
|
import { BottomSheet } from '@/components/shared/bottom-sheet'
|
|
12
20
|
import { AgentPickerList } from '@/components/shared/agent-picker-list'
|
|
@@ -43,20 +51,17 @@ export function TaskSheet() {
|
|
|
43
51
|
const setOpen = useAppStore((s) => s.setTaskSheetOpen)
|
|
44
52
|
const editingId = useAppStore((s) => s.editingTaskId)
|
|
45
53
|
const setEditingId = useAppStore((s) => s.setEditingTaskId)
|
|
46
|
-
const tasks = useAppStore((s) => s.tasks)
|
|
47
|
-
const loadTasks = useAppStore((s) => s.loadTasks)
|
|
48
|
-
const agents = useAppStore((s) => s.agents)
|
|
49
|
-
const loadAgents = useAppStore((s) => s.loadAgents)
|
|
50
|
-
|
|
51
|
-
const projects = useAppStore((s) => s.projects)
|
|
52
|
-
const loadProjects = useAppStore((s) => s.loadProjects)
|
|
53
54
|
const activeProjectFilter = useAppStore((s) => s.activeProjectFilter)
|
|
54
55
|
|
|
55
56
|
const viewOnly = useAppStore((s) => s.taskSheetViewOnly)
|
|
56
57
|
const setViewOnly = useAppStore((s) => s.setTaskSheetViewOnly)
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
const
|
|
58
|
+
const { data: tasks = {}, isLoading: tasksLoading } = useTasksQuery({ includeArchived: true, enabled: open })
|
|
59
|
+
const { data: agents = {}, isLoading: agentsLoading } = useAgentsQuery({ enabled: open })
|
|
60
|
+
const { data: projects = {}, isLoading: projectsLoading } = useProjectsQuery({ enabled: open })
|
|
61
|
+
const { data: appSettings = {}, isLoading: settingsLoading } = useAppSettingsQuery({ enabled: open })
|
|
62
|
+
const createTaskMutation = useCreateTaskMutation()
|
|
63
|
+
const updateTaskMutation = useUpdateTaskMutation()
|
|
64
|
+
const appendCommentMutation = useAppendTaskCommentMutation()
|
|
60
65
|
|
|
61
66
|
const [title, setTitle] = useState('')
|
|
62
67
|
const [description, setDescription] = useState('')
|
|
@@ -82,69 +87,96 @@ export function TaskSheet() {
|
|
|
82
87
|
const [qualityGateRequireArtifact, setQualityGateRequireArtifact] = useState(false)
|
|
83
88
|
const [qualityGateRequireReport, setQualityGateRequireReport] = useState(false)
|
|
84
89
|
const [structuredSessionOpen, setStructuredSessionOpen] = useState(false)
|
|
85
|
-
const
|
|
90
|
+
const formInitRef = useRef<string | null>(null)
|
|
86
91
|
|
|
87
92
|
const editing = editingId ? tasks[editingId] : null
|
|
88
|
-
const agentList =
|
|
93
|
+
const agentList = useMemo(
|
|
94
|
+
() => Object.values(agents).sort((a, b) => a.name.localeCompare(b.name)),
|
|
95
|
+
[agents],
|
|
96
|
+
)
|
|
97
|
+
const { data: linkedProtocolRuns = [] } = useProtocolRunsQuery({
|
|
98
|
+
taskId: editing?.id || null,
|
|
99
|
+
limit: 6,
|
|
100
|
+
enabled: open && !!editing?.id,
|
|
101
|
+
})
|
|
102
|
+
const activeStructuredRunId =
|
|
103
|
+
linkedProtocolRuns.find((run) => !['completed', 'failed', 'cancelled', 'archived'].includes(run.status))?.id || null
|
|
89
104
|
|
|
90
105
|
useEffect(() => {
|
|
91
|
-
if (open)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
setFile(null)
|
|
131
|
-
setTags([])
|
|
132
|
-
setBlockedBy([])
|
|
133
|
-
setDepSearch('')
|
|
134
|
-
setDepError(null)
|
|
135
|
-
setDueAt('')
|
|
136
|
-
setCustomFields({})
|
|
137
|
-
setPriority('')
|
|
138
|
-
setQualityGateEnabled(defaultGateEnabled)
|
|
139
|
-
setQualityGateMinResultChars(defaultGateMinResult)
|
|
140
|
-
setQualityGateMinEvidenceItems(defaultGateMinEvidence)
|
|
141
|
-
setQualityGateRequireVerification(defaultGateRequireVerification)
|
|
142
|
-
setQualityGateRequireArtifact(defaultGateRequireArtifact)
|
|
143
|
-
setQualityGateRequireReport(defaultGateRequireReport)
|
|
144
|
-
}
|
|
106
|
+
if (!open) return
|
|
107
|
+
if (tasksLoading || agentsLoading || projectsLoading || settingsLoading) return
|
|
108
|
+
|
|
109
|
+
const initKey = editingId ?? '__new__'
|
|
110
|
+
if (formInitRef.current === initKey) return
|
|
111
|
+
|
|
112
|
+
const defaultGateEnabled = appSettings.taskQualityGateEnabled ?? true
|
|
113
|
+
const defaultGateMinResult = normalizeGateNumber(appSettings.taskQualityGateMinResultChars, 80, 10, 2000)
|
|
114
|
+
const defaultGateMinEvidence = normalizeGateNumber(appSettings.taskQualityGateMinEvidenceItems, 2, 0, 8)
|
|
115
|
+
const defaultGateRequireVerification = appSettings.taskQualityGateRequireVerification ?? false
|
|
116
|
+
const defaultGateRequireArtifact = appSettings.taskQualityGateRequireArtifact ?? false
|
|
117
|
+
const defaultGateRequireReport = appSettings.taskQualityGateRequireReport ?? false
|
|
118
|
+
|
|
119
|
+
if (editingId && !editing) return
|
|
120
|
+
|
|
121
|
+
if (editing) {
|
|
122
|
+
setTitle(editing.title)
|
|
123
|
+
setDescription(editing.description)
|
|
124
|
+
setAgentId(editing.agentId)
|
|
125
|
+
setProjectId(editing.projectId || '')
|
|
126
|
+
setImages(editing.images || [])
|
|
127
|
+
setCwd(editing.cwd || '')
|
|
128
|
+
setFile(editing.file || null)
|
|
129
|
+
setTags(editing.tags || [])
|
|
130
|
+
setBlockedBy(editing.blockedBy || [])
|
|
131
|
+
setDepSearch('')
|
|
132
|
+
setDepError(null)
|
|
133
|
+
setDueAt(editing.dueAt ? new Date(editing.dueAt).toISOString().slice(0, 10) : '')
|
|
134
|
+
setCustomFields(editing.customFields || {})
|
|
135
|
+
setPriority(editing.priority || '')
|
|
136
|
+
const gate = (editing.qualityGate || null) as TaskQualityGateConfig | null
|
|
137
|
+
setQualityGateEnabled(gate?.enabled ?? defaultGateEnabled)
|
|
138
|
+
setQualityGateMinResultChars(normalizeGateNumber(gate?.minResultChars, defaultGateMinResult, 10, 2000))
|
|
139
|
+
setQualityGateMinEvidenceItems(normalizeGateNumber(gate?.minEvidenceItems, defaultGateMinEvidence, 0, 8))
|
|
140
|
+
setQualityGateRequireVerification(gate?.requireVerification ?? defaultGateRequireVerification)
|
|
141
|
+
setQualityGateRequireArtifact(gate?.requireArtifact ?? defaultGateRequireArtifact)
|
|
142
|
+
setQualityGateRequireReport(gate?.requireReport ?? defaultGateRequireReport)
|
|
143
|
+
formInitRef.current = initKey
|
|
144
|
+
return
|
|
145
145
|
}
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
|
|
147
|
+
setTitle('')
|
|
148
|
+
setDescription('')
|
|
149
|
+
setAgentId(agentList[0]?.id || '')
|
|
150
|
+
setProjectId(activeProjectFilter || '')
|
|
151
|
+
setImages([])
|
|
152
|
+
setCwd('')
|
|
153
|
+
setFile(null)
|
|
154
|
+
setTags([])
|
|
155
|
+
setBlockedBy([])
|
|
156
|
+
setDepSearch('')
|
|
157
|
+
setDepError(null)
|
|
158
|
+
setDueAt('')
|
|
159
|
+
setCustomFields({})
|
|
160
|
+
setPriority('')
|
|
161
|
+
setQualityGateEnabled(defaultGateEnabled)
|
|
162
|
+
setQualityGateMinResultChars(defaultGateMinResult)
|
|
163
|
+
setQualityGateMinEvidenceItems(defaultGateMinEvidence)
|
|
164
|
+
setQualityGateRequireVerification(defaultGateRequireVerification)
|
|
165
|
+
setQualityGateRequireArtifact(defaultGateRequireArtifact)
|
|
166
|
+
setQualityGateRequireReport(defaultGateRequireReport)
|
|
167
|
+
formInitRef.current = initKey
|
|
168
|
+
}, [
|
|
169
|
+
activeProjectFilter,
|
|
170
|
+
agentList,
|
|
171
|
+
agentsLoading,
|
|
172
|
+
appSettings,
|
|
173
|
+
editing,
|
|
174
|
+
editingId,
|
|
175
|
+
open,
|
|
176
|
+
projectsLoading,
|
|
177
|
+
settingsLoading,
|
|
178
|
+
tasksLoading,
|
|
179
|
+
])
|
|
148
180
|
|
|
149
181
|
// Update default agent when agents load (only if no agent selected yet)
|
|
150
182
|
useEffect(() => {
|
|
@@ -153,27 +185,8 @@ export function TaskSheet() {
|
|
|
153
185
|
}
|
|
154
186
|
}, [open, editing, agentId, agentList])
|
|
155
187
|
|
|
156
|
-
useEffect(() => {
|
|
157
|
-
if (!editing?.id || !open) {
|
|
158
|
-
setActiveStructuredRunId(null)
|
|
159
|
-
return
|
|
160
|
-
}
|
|
161
|
-
let cancelled = false
|
|
162
|
-
void api<Array<{ id: string; status: string }>>('GET', `/protocols/runs?taskId=${encodeURIComponent(editing.id)}&limit=6`)
|
|
163
|
-
.then((runs) => {
|
|
164
|
-
if (cancelled) return
|
|
165
|
-
const active = (Array.isArray(runs) ? runs : []).find((run) => !['completed', 'failed', 'cancelled', 'archived'].includes(run.status))
|
|
166
|
-
setActiveStructuredRunId(active?.id || null)
|
|
167
|
-
})
|
|
168
|
-
.catch(() => {
|
|
169
|
-
if (!cancelled) setActiveStructuredRunId(null)
|
|
170
|
-
})
|
|
171
|
-
return () => {
|
|
172
|
-
cancelled = true
|
|
173
|
-
}
|
|
174
|
-
}, [editing?.id, open])
|
|
175
|
-
|
|
176
188
|
const onClose = () => {
|
|
189
|
+
formInitRef.current = null
|
|
177
190
|
setOpen(false)
|
|
178
191
|
setEditingId(null)
|
|
179
192
|
}
|
|
@@ -202,13 +215,13 @@ export function TaskSheet() {
|
|
|
202
215
|
} as Partial<BoardTask> & { title: string; description: string; agentId: string }
|
|
203
216
|
try {
|
|
204
217
|
if (editing) {
|
|
205
|
-
const res = await
|
|
218
|
+
const res = await updateTaskMutation.mutateAsync({ id: editing.id, patch: payload })
|
|
206
219
|
if (res && typeof res === 'object' && 'error' in res) {
|
|
207
220
|
setDepError(String((res as unknown as Record<string, unknown>).error))
|
|
208
221
|
return
|
|
209
222
|
}
|
|
210
223
|
} else {
|
|
211
|
-
const res = await
|
|
224
|
+
const res = await createTaskMutation.mutateAsync(payload)
|
|
212
225
|
if (res && typeof res === 'object' && 'error' in res) {
|
|
213
226
|
setDepError(String((res as unknown as Record<string, unknown>).error))
|
|
214
227
|
return
|
|
@@ -219,7 +232,6 @@ export function TaskSheet() {
|
|
|
219
232
|
return
|
|
220
233
|
}
|
|
221
234
|
setDepError(null)
|
|
222
|
-
await loadTasks()
|
|
223
235
|
onClose()
|
|
224
236
|
}
|
|
225
237
|
|
|
@@ -244,24 +256,21 @@ export function TaskSheet() {
|
|
|
244
256
|
|
|
245
257
|
const handleArchive = async () => {
|
|
246
258
|
if (editing) {
|
|
247
|
-
await
|
|
248
|
-
await loadTasks()
|
|
259
|
+
await updateTaskMutation.mutateAsync({ id: editing.id, patch: { status: 'archived' } })
|
|
249
260
|
onClose()
|
|
250
261
|
}
|
|
251
262
|
}
|
|
252
263
|
|
|
253
264
|
const handleUnarchive = async () => {
|
|
254
265
|
if (editing) {
|
|
255
|
-
await
|
|
256
|
-
await loadTasks()
|
|
266
|
+
await updateTaskMutation.mutateAsync({ id: editing.id, patch: { status: 'backlog' } })
|
|
257
267
|
onClose()
|
|
258
268
|
}
|
|
259
269
|
}
|
|
260
270
|
|
|
261
271
|
const handleQueue = async () => {
|
|
262
272
|
if (editing && editing.status === 'backlog') {
|
|
263
|
-
await
|
|
264
|
-
await loadTasks()
|
|
273
|
+
await updateTaskMutation.mutateAsync({ id: editing.id, patch: { status: 'queued' } })
|
|
265
274
|
onClose()
|
|
266
275
|
}
|
|
267
276
|
}
|
|
@@ -269,14 +278,13 @@ export function TaskSheet() {
|
|
|
269
278
|
const handleAddComment = async () => {
|
|
270
279
|
if (!editing || !commentText.trim()) return
|
|
271
280
|
const c: TaskComment = {
|
|
272
|
-
id:
|
|
281
|
+
id: Math.random().toString(36).slice(2, 10),
|
|
273
282
|
author: 'You',
|
|
274
283
|
text: commentText.trim(),
|
|
275
284
|
createdAt: Date.now(),
|
|
276
285
|
}
|
|
277
286
|
// Use atomic append to avoid race conditions with queue-added comments
|
|
278
|
-
await
|
|
279
|
-
await loadTasks()
|
|
287
|
+
await appendCommentMutation.mutateAsync({ id: editing.id, comment: c })
|
|
280
288
|
setCommentText('')
|
|
281
289
|
}
|
|
282
290
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query'
|
|
2
|
+
import { fetchAgents } from '@/lib/agents'
|
|
3
|
+
import type { Agent } from '@/types'
|
|
4
|
+
|
|
5
|
+
type QueryOptions = {
|
|
6
|
+
enabled?: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const agentQueryKeys = {
|
|
10
|
+
all: ['agents'] as const,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function useAgentsQuery(options: QueryOptions = {}) {
|
|
14
|
+
return useQuery<Record<string, Agent>>({
|
|
15
|
+
queryKey: agentQueryKeys.all,
|
|
16
|
+
queryFn: fetchAgents,
|
|
17
|
+
enabled: options.enabled,
|
|
18
|
+
staleTime: 60_000,
|
|
19
|
+
})
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query'
|
|
2
|
+
import { api } from '@/lib/app/api-client'
|
|
3
|
+
import type { Chatroom } from '@/types'
|
|
4
|
+
|
|
5
|
+
type QueryOptions = {
|
|
6
|
+
enabled?: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const chatroomQueryKeys = {
|
|
10
|
+
all: ['chatrooms'] as const,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function useChatroomsQuery(options: QueryOptions = {}) {
|
|
14
|
+
return useQuery<Record<string, Chatroom>>({
|
|
15
|
+
queryKey: chatroomQueryKeys.all,
|
|
16
|
+
queryFn: () => api<Record<string, Chatroom>>('GET', '/chatrooms'),
|
|
17
|
+
enabled: options.enabled,
|
|
18
|
+
staleTime: 30_000,
|
|
19
|
+
})
|
|
20
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query'
|
|
2
|
+
import { api } from '@/lib/app/api-client'
|
|
3
|
+
import type { Message, Session } from '@/types'
|
|
4
|
+
|
|
5
|
+
export const chatQueryKeys = {
|
|
6
|
+
all: ['chats'] as const,
|
|
7
|
+
lists: () => ['chats', 'list'] as const,
|
|
8
|
+
detail: (id: string) => ['chats', id] as const,
|
|
9
|
+
messages: (sessionId: string) => ['chats', sessionId, 'messages'] as const,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function useChatListQuery() {
|
|
13
|
+
return useQuery<Session[]>({
|
|
14
|
+
queryKey: chatQueryKeys.lists(),
|
|
15
|
+
queryFn: () => api<Session[]>('GET', '/chats'),
|
|
16
|
+
staleTime: 10_000,
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function useMessagesQuery(sessionId: string) {
|
|
21
|
+
return useQuery<Message[]>({
|
|
22
|
+
queryKey: chatQueryKeys.messages(sessionId),
|
|
23
|
+
queryFn: () => api<Message[]>('GET', `/chats/${sessionId}/messages`),
|
|
24
|
+
enabled: !!sessionId,
|
|
25
|
+
staleTime: 5_000,
|
|
26
|
+
})
|
|
27
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { api } from '@/lib/app/api-client'
|
|
3
|
+
import type {
|
|
4
|
+
Connector,
|
|
5
|
+
ConnectorAccessMutationAction,
|
|
6
|
+
ConnectorAccessMutationResponse,
|
|
7
|
+
ConnectorAccessSnapshot,
|
|
8
|
+
} from '@/types'
|
|
9
|
+
|
|
10
|
+
type QueryOptions = {
|
|
11
|
+
enabled?: boolean
|
|
12
|
+
refetchInterval?: number | false
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface SaveConnectorInput {
|
|
16
|
+
id?: string | null
|
|
17
|
+
payload: Record<string, unknown>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function invalidateConnectorQueries(queryClient: ReturnType<typeof useQueryClient>) {
|
|
21
|
+
await queryClient.invalidateQueries({ queryKey: connectorQueryKeys.all })
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const connectorQueryKeys = {
|
|
25
|
+
all: ['connectors'] as const,
|
|
26
|
+
list: () => ['connectors', 'list'] as const,
|
|
27
|
+
detail: (id: string) => ['connectors', 'detail', id] as const,
|
|
28
|
+
access: (id: string) => ['connectors', 'access', id] as const,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function useConnectorsQuery(options: QueryOptions = {}) {
|
|
32
|
+
return useQuery<Record<string, Connector>>({
|
|
33
|
+
queryKey: connectorQueryKeys.list(),
|
|
34
|
+
queryFn: () => api<Record<string, Connector>>('GET', '/connectors'),
|
|
35
|
+
enabled: options.enabled,
|
|
36
|
+
staleTime: 10_000,
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function useConnectorQuery(id: string | null | undefined, options: QueryOptions = {}) {
|
|
41
|
+
return useQuery<Connector>({
|
|
42
|
+
queryKey: connectorQueryKeys.detail(id || 'unknown'),
|
|
43
|
+
queryFn: () => api<Connector>('GET', `/connectors/${id}`),
|
|
44
|
+
enabled: Boolean(id) && options.enabled !== false,
|
|
45
|
+
staleTime: 2_000,
|
|
46
|
+
refetchInterval: options.refetchInterval,
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function useConnectorAccessQuery(id: string | null | undefined, options: QueryOptions = {}) {
|
|
51
|
+
return useQuery<ConnectorAccessSnapshot>({
|
|
52
|
+
queryKey: connectorQueryKeys.access(id || 'unknown'),
|
|
53
|
+
queryFn: () => api<ConnectorAccessSnapshot>('GET', `/connectors/${id}/access`),
|
|
54
|
+
enabled: Boolean(id) && options.enabled !== false,
|
|
55
|
+
staleTime: 5_000,
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function useConnectorDoctorMutation() {
|
|
60
|
+
return useMutation({
|
|
61
|
+
mutationFn: (payload: Record<string, unknown>) =>
|
|
62
|
+
api<{
|
|
63
|
+
warnings?: string[]
|
|
64
|
+
policy?: Record<string, unknown> | null
|
|
65
|
+
}>('POST', '/connectors/doctor', payload),
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function useSaveConnectorMutation() {
|
|
70
|
+
const queryClient = useQueryClient()
|
|
71
|
+
return useMutation({
|
|
72
|
+
mutationFn: ({ id, payload }: SaveConnectorInput) =>
|
|
73
|
+
id ? api('PUT', `/connectors/${id}`, payload) : api('POST', '/connectors', payload),
|
|
74
|
+
onSuccess: async (_data, variables) => {
|
|
75
|
+
await Promise.all([
|
|
76
|
+
invalidateConnectorQueries(queryClient),
|
|
77
|
+
variables.id
|
|
78
|
+
? queryClient.invalidateQueries({ queryKey: connectorQueryKeys.detail(variables.id) })
|
|
79
|
+
: Promise.resolve(),
|
|
80
|
+
])
|
|
81
|
+
},
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function useConnectorActionMutation() {
|
|
86
|
+
const queryClient = useQueryClient()
|
|
87
|
+
return useMutation({
|
|
88
|
+
mutationFn: ({ id, action }: { id: string; action: string }) =>
|
|
89
|
+
api('PUT', `/connectors/${id}`, { action }),
|
|
90
|
+
onSuccess: async (_data, variables) => {
|
|
91
|
+
await Promise.all([
|
|
92
|
+
invalidateConnectorQueries(queryClient),
|
|
93
|
+
queryClient.invalidateQueries({ queryKey: connectorQueryKeys.detail(variables.id) }),
|
|
94
|
+
])
|
|
95
|
+
},
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function useDeleteConnectorMutation() {
|
|
100
|
+
const queryClient = useQueryClient()
|
|
101
|
+
return useMutation({
|
|
102
|
+
mutationFn: (id: string) => api('DELETE', `/connectors/${id}`),
|
|
103
|
+
onSuccess: async (_data, id) => {
|
|
104
|
+
await Promise.all([
|
|
105
|
+
invalidateConnectorQueries(queryClient),
|
|
106
|
+
queryClient.removeQueries({ queryKey: connectorQueryKeys.detail(id) }),
|
|
107
|
+
queryClient.removeQueries({ queryKey: connectorQueryKeys.access(id) }),
|
|
108
|
+
])
|
|
109
|
+
},
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function useConnectorAccessMutation(id: string | null | undefined) {
|
|
114
|
+
const queryClient = useQueryClient()
|
|
115
|
+
return useMutation({
|
|
116
|
+
mutationFn: ({
|
|
117
|
+
action,
|
|
118
|
+
senderId,
|
|
119
|
+
senderIdAlt,
|
|
120
|
+
code,
|
|
121
|
+
dmAddressingMode,
|
|
122
|
+
}: {
|
|
123
|
+
action: ConnectorAccessMutationAction
|
|
124
|
+
senderId?: string | null
|
|
125
|
+
senderIdAlt?: string | null
|
|
126
|
+
code?: string | null
|
|
127
|
+
dmAddressingMode?: 'open' | 'addressed' | null
|
|
128
|
+
}) => api<ConnectorAccessMutationResponse>('PUT', `/connectors/${id}/access`, {
|
|
129
|
+
action,
|
|
130
|
+
senderId: senderId || null,
|
|
131
|
+
senderIdAlt: senderIdAlt || null,
|
|
132
|
+
code: code || null,
|
|
133
|
+
dmAddressingMode: dmAddressingMode || null,
|
|
134
|
+
}),
|
|
135
|
+
onSuccess: async (result) => {
|
|
136
|
+
if (id) {
|
|
137
|
+
queryClient.setQueryData(connectorQueryKeys.access(id), result.snapshot)
|
|
138
|
+
await Promise.all([
|
|
139
|
+
queryClient.invalidateQueries({ queryKey: connectorQueryKeys.detail(id) }),
|
|
140
|
+
invalidateConnectorQueries(queryClient),
|
|
141
|
+
])
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
})
|
|
145
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { createCredential, fetchCredentials } from '@/lib/chat/chats'
|
|
3
|
+
import type { Credentials } from '@/types'
|
|
4
|
+
|
|
5
|
+
type QueryOptions = {
|
|
6
|
+
enabled?: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface CreateCredentialInput {
|
|
10
|
+
provider: string
|
|
11
|
+
name: string
|
|
12
|
+
apiKey: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const credentialQueryKeys = {
|
|
16
|
+
all: ['credentials'] as const,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function useCredentialsQuery(options: QueryOptions = {}) {
|
|
20
|
+
return useQuery<Credentials>({
|
|
21
|
+
queryKey: credentialQueryKeys.all,
|
|
22
|
+
queryFn: fetchCredentials,
|
|
23
|
+
enabled: options.enabled,
|
|
24
|
+
staleTime: 30_000,
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function useCreateCredentialMutation() {
|
|
29
|
+
const queryClient = useQueryClient()
|
|
30
|
+
return useMutation({
|
|
31
|
+
mutationFn: ({ provider, name, apiKey }: CreateCredentialInput) =>
|
|
32
|
+
createCredential(provider, name, apiKey),
|
|
33
|
+
onSuccess: async () => {
|
|
34
|
+
await queryClient.invalidateQueries({ queryKey: credentialQueryKeys.all })
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query'
|
|
2
|
+
import { api } from '@/lib/app/api-client'
|
|
3
|
+
|
|
4
|
+
type QueryOptions = {
|
|
5
|
+
enabled?: boolean
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ConnectorExtensionOption {
|
|
9
|
+
id: string
|
|
10
|
+
name: string
|
|
11
|
+
description?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const extensionQueryKeys = {
|
|
15
|
+
all: ['extensions'] as const,
|
|
16
|
+
connectorUi: () => ['extensions', 'connector-ui'] as const,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function useConnectorExtensionOptionsQuery(options: QueryOptions = {}) {
|
|
20
|
+
return useQuery<ConnectorExtensionOption[]>({
|
|
21
|
+
queryKey: extensionQueryKeys.connectorUi(),
|
|
22
|
+
queryFn: () => api<ConnectorExtensionOption[]>('GET', '/extensions/ui?type=connectors'),
|
|
23
|
+
enabled: options.enabled,
|
|
24
|
+
staleTime: 60_000,
|
|
25
|
+
})
|
|
26
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { api } from '@/lib/app/api-client'
|
|
3
|
+
import type { ExternalAgentRuntime } from '@/types'
|
|
4
|
+
|
|
5
|
+
type QueryOptions = {
|
|
6
|
+
enabled?: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const externalAgentQueryKeys = {
|
|
10
|
+
all: ['external-agents'] as const,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function useExternalAgentsQuery(options: QueryOptions = {}) {
|
|
14
|
+
return useQuery<ExternalAgentRuntime[]>({
|
|
15
|
+
queryKey: externalAgentQueryKeys.all,
|
|
16
|
+
queryFn: () => api<ExternalAgentRuntime[]>('GET', '/external-agents'),
|
|
17
|
+
enabled: options.enabled,
|
|
18
|
+
staleTime: 20_000,
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function useExternalAgentRuntimeMutation() {
|
|
23
|
+
const queryClient = useQueryClient()
|
|
24
|
+
return useMutation({
|
|
25
|
+
mutationFn: ({
|
|
26
|
+
runtimeId,
|
|
27
|
+
action,
|
|
28
|
+
}: {
|
|
29
|
+
runtimeId: string
|
|
30
|
+
action: 'activate' | 'drain' | 'cordon' | 'restart'
|
|
31
|
+
}) => api('PUT', `/external-agents/${runtimeId}`, { action }),
|
|
32
|
+
onSuccess: async () => {
|
|
33
|
+
await queryClient.invalidateQueries({ queryKey: externalAgentQueryKeys.all })
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
}
|