feat: optional worker selection when creating workflow (API + frontend dropdown)
This commit is contained in:
@@ -45,10 +45,10 @@ export const api = {
|
||||
listWorkflows: (projectId: string) =>
|
||||
request<Workflow[]>(`/projects/${projectId}/workflows`),
|
||||
|
||||
createWorkflow: (projectId: string, requirement: string, templateId?: string) =>
|
||||
createWorkflow: (projectId: string, requirement: string, templateId?: string, worker?: string) =>
|
||||
request<Workflow>(`/projects/${projectId}/workflows`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ requirement, template_id: templateId || undefined }),
|
||||
body: JSON.stringify({ requirement, template_id: templateId || undefined, worker: worker || undefined }),
|
||||
}),
|
||||
|
||||
listTemplates: () =>
|
||||
@@ -93,6 +93,9 @@ export const api = {
|
||||
deleteTimer: (timerId: string) =>
|
||||
request<void>(`/timers/${timerId}`, { method: 'DELETE' }),
|
||||
|
||||
listWorkers: () =>
|
||||
request<{ name: string; cpu: string; memory: string; gpu: string }[]>('/workers'),
|
||||
|
||||
getKb: () => request<{ content: string }>('/kb'),
|
||||
|
||||
listArticles: () => request<KbArticleSummary[]>('/kb/articles'),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import { ref, watch, onMounted } from 'vue'
|
||||
import { api } from '../api'
|
||||
|
||||
const props = defineProps<{
|
||||
requirement: string
|
||||
@@ -7,13 +8,20 @@ const props = defineProps<{
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
submit: [text: string]
|
||||
submit: [text: string, worker?: string]
|
||||
}>()
|
||||
|
||||
const input = ref('')
|
||||
const editing = ref(!props.requirement)
|
||||
const workers = ref<{ name: string }[]>([])
|
||||
const selectedWorker = ref('')
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
workers.value = await api.listWorkers()
|
||||
} catch { /* ignore */ }
|
||||
})
|
||||
|
||||
// 当 requirement 从外部更新(如 loadData 完成),自动退出编辑模式
|
||||
watch(() => props.requirement, (val) => {
|
||||
if (val && editing.value && !input.value.trim()) {
|
||||
editing.value = false
|
||||
@@ -23,7 +31,7 @@ watch(() => props.requirement, (val) => {
|
||||
function submit() {
|
||||
const text = input.value.trim()
|
||||
if (!text) return
|
||||
emit('submit', text)
|
||||
emit('submit', text, selectedWorker.value || undefined)
|
||||
editing.value = false
|
||||
}
|
||||
</script>
|
||||
@@ -47,7 +55,13 @@ function submit() {
|
||||
rows="8"
|
||||
@keydown.ctrl.enter="submit"
|
||||
/>
|
||||
<button class="btn-submit" @click="submit">提交需求</button>
|
||||
<div class="submit-row">
|
||||
<select v-if="workers.length" v-model="selectedWorker" class="worker-select">
|
||||
<option value="">自动选择 Worker</option>
|
||||
<option v-for="w in workers" :key="w.name" :value="w.name">{{ w.name }}</option>
|
||||
</select>
|
||||
<button class="btn-submit" @click="submit">提交需求</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -148,8 +162,23 @@ function submit() {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.submit-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.worker-select {
|
||||
padding: 6px 10px;
|
||||
font-size: 12px;
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.btn-submit {
|
||||
align-self: flex-end;
|
||||
background: var(--accent);
|
||||
color: var(--bg-primary);
|
||||
font-weight: 600;
|
||||
|
||||
@@ -147,9 +147,9 @@ watch(() => props.projectId, () => {
|
||||
setupWs()
|
||||
})
|
||||
|
||||
async function onSubmitRequirement(text: string) {
|
||||
async function onSubmitRequirement(text: string, worker?: string) {
|
||||
try {
|
||||
const wf = await api.createWorkflow(props.projectId, text)
|
||||
const wf = await api.createWorkflow(props.projectId, text, undefined, worker)
|
||||
workflow.value = wf
|
||||
logEntries.value = []
|
||||
planSteps.value = []
|
||||
|
||||
Reference in New Issue
Block a user