diff --git a/preview/check-v025.mjs b/preview/check-v025.mjs new file mode 100644 index 0000000..8eacd50 --- /dev/null +++ b/preview/check-v025.mjs @@ -0,0 +1,42 @@ +import { spawn } from 'node:child_process' +import { mkdtemp, writeFile } from 'node:fs/promises' +import { tmpdir } from 'node:os' +import { join, dirname } from 'node:path' +import { fileURLToPath } from 'node:url' +const url = process.argv[2] +const EDGE = 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe' +const dir = dirname(fileURLToPath(import.meta.url)) +const profile = await mkdtemp(join(tmpdir(), 'ss-v025-')) +const out = {} +const sleep = ms => new Promise(r => setTimeout(r, ms)) +let browser, ws +try { + browser = spawn(EDGE, ['--headless=new','--disable-gpu','--no-first-run','--no-default-browser-check','--remote-debugging-port=0','--user-data-dir=' + profile, 'about:blank'], { stdio: ['ignore','ignore','pipe'] }) + const endpoint = await new Promise((resolve, reject) => { let log=''; const t=setTimeout(()=>reject(Error('timeout')),20000); browser.stderr.on('data', b=>{ log+=b; const m=log.match(/DevTools listening on (.+)/); if(m){clearTimeout(t);resolve(m[1].trim())} }); browser.on('error',reject) }) + ws = new WebSocket(endpoint); await new Promise((r,j)=>{ws.onopen=r;ws.onerror=j}) + let n=0; const pend=new Map() + ws.onmessage = e => { const m=JSON.parse(e.data); if(m.id){const p=pend.get(m.id);pend.delete(m.id);m.error?p.reject(Error(JSON.stringify(m.error))):p.resolve(m.result)} } + const cdp=(method,params={},sid)=>new Promise((res,rej)=>{const id=++n;pend.set(id,{resolve:res,reject:rej});ws.send(JSON.stringify({id,method,params,...(sid?{sessionId:sid}:{})}))}) + const { targetId } = await cdp('Target.createTarget', { url: 'about:blank' }) + const { sessionId } = await cdp('Target.attachToTarget', { targetId, flatten: true }) + const call=(m,p={})=>cdp(m,p,sessionId) + await call('Page.enable'); await call('Runtime.enable') + const ev = async x => { const r=await call('Runtime.evaluate',{expression:x,returnByValue:true,awaitPromise:true}); if(r.exceptionDetails) throw Error(r.exceptionDetails.exception?.description||r.exceptionDetails.text); return r.result.value } + const waitFor = async (x,t=45000)=>{ const end=Date.now()+t; while(Date.now() { const r=await call('Page.captureScreenshot',{format:'png',captureBeyondViewport:false}); await writeFile(join(dir,name),Buffer.from(r.data,'base64')) } + await call('Emulation.setDeviceMetricsOverride',{width:1440,height:900,deviceScaleFactor:1,mobile:false}) + await call('Page.navigate',{url}) + await waitFor("document.readyState === 'complete'",30000) + try { await ev("(() => { const b=[...document.querySelectorAll('button')].find(x=>(x.innerText||'').trim()==='继续'); if(b)b.click(); return !!b })()") } catch {} + await waitFor("!!document.querySelector('.ssw-nav-hit')",60000) + out.api = { skipped: true } + await ev("document.querySelector('.ssw-nav-hit').click(); true") + await waitFor("!!document.querySelector('.ssw-root')",20000) + await sleep(2200) + out.ui = await ev("(() => ({ hasBulkEnable: (document.body.innerText||'').includes('启用此项目的十席'), detailButton: document.querySelector('.ssw-detail-actions button')?.innerText ?? null }))()") + out.configOpened = await ev("(() => { const b=document.querySelector('.ssw-config-toggle'); if(!b) return false; b.click(); return true })()") + await sleep(600) + out.configLabel = await ev("(() => { const labels=[...document.querySelectorAll('.ssw-config .ssw-label')].map(e=>e.innerText.trim()); const note=document.querySelector('.ssw-config .ssw-scope-note')?.innerText ?? null; return { labels, note } })()") + await shot('v025-config.png') +} catch(e) { out.fatal = String(e?.stack ?? e) } finally { try{ws?.close()}catch{}; try{browser?.kill()}catch{} } +console.log(JSON.stringify(out, null, 2)) \ No newline at end of file diff --git a/preview/check-v025b.mjs b/preview/check-v025b.mjs new file mode 100644 index 0000000..b76768b --- /dev/null +++ b/preview/check-v025b.mjs @@ -0,0 +1,43 @@ +import { spawn } from 'node:child_process' +import { mkdtemp, writeFile } from 'node:fs/promises' +import { tmpdir } from 'node:os' +import { join, dirname } from 'node:path' +import { fileURLToPath } from 'node:url' +const url = process.argv[2] +const EDGE = 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe' +const dir = dirname(fileURLToPath(import.meta.url)) +const profile = await mkdtemp(join(tmpdir(), 'ss-v025b-')) +const out = {} +const sleep = ms => new Promise(r => setTimeout(r, ms)) +let browser, ws +try { + browser = spawn(EDGE, ['--headless=new','--disable-gpu','--no-first-run','--no-default-browser-check','--remote-debugging-port=0','--user-data-dir=' + profile, 'about:blank'], { stdio: ['ignore','ignore','pipe'] }) + const endpoint = await new Promise((resolve, reject) => { let log=''; const t=setTimeout(()=>reject(Error('timeout')),20000); browser.stderr.on('data', b=>{ log+=b; const m=log.match(/DevTools listening on (.+)/); if(m){clearTimeout(t);resolve(m[1].trim())} }); browser.on('error',reject) }) + ws = new WebSocket(endpoint); await new Promise((r,j)=>{ws.onopen=r;ws.onerror=j}) + let n=0; const pend=new Map() + ws.onmessage = e => { const m=JSON.parse(e.data); if(m.id){const p=pend.get(m.id);pend.delete(m.id);m.error?p.reject(Error(JSON.stringify(m.error))):p.resolve(m.result)} } + const cdp=(method,params={},sid)=>new Promise((res,rej)=>{const id=++n;pend.set(id,{resolve:res,reject:rej});ws.send(JSON.stringify({id,method,params,...(sid?{sessionId:sid}:{})}))}) + const { targetId } = await cdp('Target.createTarget', { url: 'about:blank' }) + const { sessionId } = await cdp('Target.attachToTarget', { targetId, flatten: true }) + const call=(m,p={})=>cdp(m,p,sessionId) + await call('Page.enable'); await call('Runtime.enable') + const ev = async x => { const r=await call('Runtime.evaluate',{expression:x,returnByValue:true,awaitPromise:true}); if(r.exceptionDetails) throw Error(r.exceptionDetails.exception?.description||r.exceptionDetails.text); return r.result.value } + const waitFor = async (x,t=60000)=>{ const end=Date.now()+t; while(Date.now() { const r=await call('Page.captureScreenshot',{format:'png',captureBeyondViewport:false}); await writeFile(join(dir,name),Buffer.from(r.data,'base64')) } + await call('Emulation.setDeviceMetricsOverride',{width:1440,height:900,deviceScaleFactor:1,mobile:false}) + await call('Page.navigate',{url}) + await waitFor("document.readyState === 'complete'",30000) + try { await ev("(() => { const b=[...document.querySelectorAll('button')].find(x=>(x.innerText||'').trim()==='继续'); if(b)b.click(); return !!b })()") } catch {} + await waitFor("!!document.querySelector('.ssw-nav-hit')",60000) + await ev("document.querySelector('.ssw-nav-hit').click(); true") + await waitFor("!!document.querySelector('.ssw-root')",20000) + await sleep(2200) + out.before = await ev("(() => ({ button: document.querySelector('.ssw-detail-actions button')?.innerText ?? null, count: document.querySelector('.ssw-count')?.innerText ?? null, bulk: (document.body.innerText||'').includes('启用此项目的十席') }))()") + await shot('v025-unbound.png') + await ev("(() => { const b=document.querySelector('.ssw-detail-actions button'); if(b) b.click(); return !!b })()") + await waitFor("(() => { const b=document.querySelector('.ssw-detail-actions button'); return b && b.innerText.includes('开始对话') })()", 90000) + await sleep(1500) + out.after = await ev("(() => ({ button: document.querySelector('.ssw-detail-actions button')?.innerText ?? null, count: document.querySelector('.ssw-count')?.innerText ?? null, bound: document.querySelectorAll('.ssw-dot[data-status=bound]').length }))()") + await shot('v025-one-seat.png') +} catch(e) { out.fatal = String(e?.stack ?? e) } finally { try{ws?.close()}catch{}; try{browser?.kill()}catch{} } +console.log(JSON.stringify(out, null, 2)) \ No newline at end of file diff --git a/preview/v025-config.png b/preview/v025-config.png new file mode 100644 index 0000000..9ad2a82 Binary files /dev/null and b/preview/v025-config.png differ diff --git a/preview/v025-one-seat.png b/preview/v025-one-seat.png new file mode 100644 index 0000000..adef9d3 Binary files /dev/null and b/preview/v025-one-seat.png differ diff --git a/preview/v025-unbound.png b/preview/v025-unbound.png new file mode 100644 index 0000000..d08c527 Binary files /dev/null and b/preview/v025-unbound.png differ diff --git a/sansheng/client.js b/sansheng/client.js index 773a919..3450020 100644 --- a/sansheng/client.js +++ b/sansheng/client.js @@ -1327,7 +1327,7 @@ function apply(ctx) { setConfigOpen(false); } const seat = seatById[id]; - if (wb.ready && seat && seat.status === "bound") { + if (seat && seat.status === "bound") { const rec = seatRecordOf(view, id); if (rec && rec.sessionId) { navigateToSession(rec.sessionId); @@ -1335,7 +1335,7 @@ function apply(ctx) { return; } } - if (wb.ready && seat && seat.status !== "bound") setNotice("该席尚未绑定会话,先启用或重试启用"); + if (seat && seat.status !== "bound" && seat.status !== "creating") setNotice("「" + seat.name + "」还没开启,点下面的按钮开启这个部门"); } function setModelValue(value) { setDraft((prev) => updateDraft(prev, selectedSeatId, { modelValue: value })); @@ -1343,6 +1343,24 @@ function apply(ctx) { function setInstructions(value) { setDraft((prev) => updateDraft(prev, selectedSeatId, { instructions: value })); } + async function enableSelectedSeat() { + const projectId = view && view.project ? view.project.id : null; + if (!projectId) return; + const seatId = wb.selected.id; + setBusy(true); + setError(null); + setNotice("正在开启「" + wb.selected.name + "」…"); + try { + const next = await request("enableSeat", { projectId, seatId }); + if (!alive.current) return; + setView(next); + setNotice("已开启「" + wb.selected.name + "」的独立会话"); + } catch (enableError) { + if (alive.current) setError(enableError && enableError.message ? enableError.message : "开启失败"); + } finally { + if (alive.current) setBusy(false); + } + } async function enableSeats() { const projectId = view && view.project ? view.project.id : null; if (!projectId) return; @@ -1523,10 +1541,11 @@ function apply(ctx) { (0, import_react.createElement)("span", { className: "ssw-count" }, wb.project.seatCount + " 个角色 · " + wb.project.sessionCount + " 个会话") ) ); + const selectedStatus = wb.selected.status; const detailActions = (0, import_react.createElement)( "div", { className: "ssw-detail-actions" }, - wb.ready ? (0, import_react.createElement)("button", { + selectedStatus === "bound" ? (0, import_react.createElement)("button", { type: "button", className: "ssw-primary", disabled: busy, @@ -1534,9 +1553,9 @@ function apply(ctx) { }, "开始对话") : (0, import_react.createElement)("button", { type: "button", className: "ssw-primary", - disabled: busy, - onClick: enableSeats - }, busy ? "正在启用…" : "启用此项目的十席") + disabled: busy || selectedStatus === "creating", + onClick: enableSelectedSeat + }, selectedStatus === "creating" ? "正在开启…" : "开启「" + wb.selected.name + "」") ); const optionEls = wb.selected.modelOptions.map((option) => (0, import_react.createElement)("option", { key: option.value, value: option.value }, option.label)); if (wb.selected.modelValue && !wb.selected.modelOptions.some((option) => option.value === wb.selected.modelValue)) { @@ -1560,7 +1579,7 @@ function apply(ctx) { configOpen ? (0, import_react.createElement)( "div", { className: "ssw-config-body" }, - (0, import_react.createElement)("label", { className: "ssw-label" }, "会话模型"), + (0, import_react.createElement)("label", { className: "ssw-label" }, "默认模型(开启该部门时应用)"), (0, import_react.createElement)( "select", { @@ -1581,7 +1600,7 @@ function apply(ctx) { placeholder: "补充该角色在当前项目中的工作要求", onChange: (event) => setInstructions(event.target.value) }), - (0, import_react.createElement)("p", { className: "ssw-scope-note" }, "每个角色是独立会话;模型与说明只影响当前项目当前角色,不改变宿主默认模型。"), + (0, import_react.createElement)("p", { className: "ssw-scope-note" }, "这里预配置的模型会在开启该部门或按需派工时应用;丞相派工不选择模型。只影响当前项目当前角色。"), (0, import_react.createElement)( "div", { className: "ssw-save-row" }, diff --git a/sansheng/package.json b/sansheng/package.json index 747de4b..2123a37 100644 --- a/sansheng/package.json +++ b/sansheng/package.json @@ -1,6 +1,6 @@ { "name": "dsh-sansheng-liubu", - "version": "0.2.4", + "version": "0.3.0", "description": "三省六部:每个项目固定十席角色与独立会话的 DSH 插件(第一版)。", "keywords": [ "dsh-plugin", diff --git a/sansheng/src/client/index.js b/sansheng/src/client/index.js index 8e21d53..1313e8f 100644 --- a/sansheng/src/client/index.js +++ b/sansheng/src/client/index.js @@ -397,7 +397,7 @@ export function apply(ctx) { setConfigOpen(false) } const seat = seatById[id] - if (wb.ready && seat && seat.status === 'bound') { + if (seat && seat.status === 'bound') { const rec = seatRecordOf(view, id) if (rec && rec.sessionId) { navigateToSession(rec.sessionId) @@ -405,7 +405,7 @@ export function apply(ctx) { return } } - if (wb.ready && seat && seat.status !== 'bound') setNotice('该席尚未绑定会话,先启用或重试启用') + if (seat && seat.status !== 'bound' && seat.status !== 'creating') setNotice('「' + seat.name + '」还没开启,点下面的按钮开启这个部门') } function setModelValue(value) { @@ -415,6 +415,23 @@ export function apply(ctx) { setDraft(prev => updateDraft(prev, selectedSeatId, { instructions: value })) } + async function enableSelectedSeat() { + const projectId = view && view.project ? view.project.id : null + if (!projectId) return + const seatId = wb.selected.id + setBusy(true); setError(null); setNotice('正在开启「' + wb.selected.name + '」…') + try { + const next = await request('enableSeat', { projectId, seatId }) + if (!alive.current) return + setView(next) + setNotice('已开启「' + wb.selected.name + '」的独立会话') + } catch (enableError) { + if (alive.current) setError(enableError && enableError.message ? enableError.message : '开启失败') + } finally { + if (alive.current) setBusy(false) + } + } + async function enableSeats() { const projectId = view && view.project ? view.project.id : null if (!projectId) return @@ -569,15 +586,17 @@ export function apply(ctx) { ), ) + const selectedStatus = wb.selected.status const detailActions = h('div', { className: 'ssw-detail-actions' }, - wb.ready + selectedStatus === 'bound' ? h('button', { type: 'button', className: 'ssw-primary', disabled: busy, onClick: () => pickSeat(wb.selected.id), }, '开始对话') : h('button', { - type: 'button', className: 'ssw-primary', disabled: busy, onClick: enableSeats, - }, busy ? '正在启用…' : '启用此项目的十席'), + type: 'button', className: 'ssw-primary', disabled: busy || selectedStatus === 'creating', + onClick: enableSelectedSeat, + }, selectedStatus === 'creating' ? '正在开启…' : '开启「' + wb.selected.name + '」'), ) const optionEls = wb.selected.modelOptions.map(option => h('option', { key: option.value, value: option.value }, option.label)) @@ -595,7 +614,7 @@ export function apply(ctx) { ), configOpen ? h('div', { className: 'ssw-config-body' }, - h('label', { className: 'ssw-label' }, '会话模型'), + h('label', { className: 'ssw-label' }, '默认模型(开启该部门时应用)'), h('select', { className: 'ssw-field', value: wb.selected.modelValue, disabled: busy, onChange: event => setModelValue(event.target.value), @@ -609,7 +628,7 @@ export function apply(ctx) { placeholder: '补充该角色在当前项目中的工作要求', onChange: event => setInstructions(event.target.value), }), - h('p', { className: 'ssw-scope-note' }, '每个角色是独立会话;模型与说明只影响当前项目当前角色,不改变宿主默认模型。'), + h('p', { className: 'ssw-scope-note' }, '这里预配置的模型会在开启该部门或按需派工时应用;丞相派工不选择模型。只影响当前项目当前角色。'), h('div', { className: 'ssw-save-row' }, h('button', { type: 'button', className: 'ssw-primary', disabled: busy, onClick: saveConfig }, busy ? '保存中…' : '保存配置'), wb.selected.dirty ? h('span', { className: 'ssw-save-status' }, '有未保存修改') : null, diff --git a/sansheng/src/host/api.js b/sansheng/src/host/api.js index 884f31e..8fe9b82 100644 --- a/sansheng/src/host/api.js +++ b/sansheng/src/host/api.js @@ -29,6 +29,11 @@ export function createApiHandler(service) { return { ok: true, value: await service.open(payload ?? {}) } case 'enable': return { ok: true, value: await service.enable(requireProjectId(payload)) } + case 'enableSeat': { + const seatId = payload?.seatId + if (!SEAT_IDS.includes(seatId)) throw bad(`未知席 ${String(seatId)}`) + return { ok: true, value: await service.enableSeat(requireProjectId(payload), seatId) } + } case 'configure': { const projectId = requireProjectId(payload) const seatId = payload?.seatId diff --git a/sansheng/src/host/provision.js b/sansheng/src/host/provision.js index ed26207..afa1164 100644 --- a/sansheng/src/host/provision.js +++ b/sansheng/src/host/provision.js @@ -2,6 +2,7 @@ // ID 不一致立即停止后续创建并保留记录;失败保留已完成绑定,重试只补未完成项。 import { randomUUID } from 'node:crypto' import { SEAT_IDS, SEATS } from '../shared/roles.js' +import { applyModel } from './model.js' export class ProvisionError extends Error { constructor(code, message) { super(message); this.name = 'ProvisionError'; this.code = code } @@ -54,6 +55,15 @@ export function createProvisioner({ store, host, now = () => Date.now() }) { }) } + // 建好会话后立即应用该席预先配置的模型;没有配置就保持原样(绝不在这里替角色挑模型)。 + async function applyPreconfiguredModel(projectId, seatId) { + const seat = store.get(projectId)?.seats?.[seatId] + if (!seat || !seat.sessionId || !seat.model) return + try { await applyModel(host, seat.sessionId, seat.model) } catch (error) { + console.warn('[sansheng] 应用预配置模型失败:', error && error.message ? error.message : error) + } + } + async function ensureSeat(projectId, seatId) { await store.ensureLoaded() const seat = store.get(projectId).seats[seatId] @@ -79,6 +89,7 @@ export function createProvisioner({ store, host, now = () => Date.now() }) { } if (resolved && !('error' in resolved) && resolved.agent) { await markBound(projectId, seatId, planned) + await applyPreconfiguredModel(projectId, seatId) return { ok: true, recovered: true } } if (resolved && 'error' in resolved && resolved.error && !isNotFound(resolved.error)) { @@ -99,9 +110,35 @@ export function createProvisioner({ store, host, now = () => Date.now() }) { return { ok: false, fatal: true } } await markBound(projectId, seatId, planned) + await applyPreconfiguredModel(projectId, seatId) return { ok: true } } + // 只开启一个部门(用户手动点,或派工按需触发)。 + async function enableSeat(projectId, seatId) { + return withLock(projectId, async () => { + await store.ensureLoaded() + const project = store.get(projectId) + if (!project) throw new ProvisionError('sansheng/not-found', `项目 ${projectId} 不存在`) + if (!SEAT_IDS.includes(seatId)) throw new ProvisionError('sansheng/invalid', `未知席 ${String(seatId)}`) + const result = await ensureSeat(projectId, seatId) + if (result.ok && typeof host.sessionController.rename === 'function') { + const seat = store.get(projectId)?.seats?.[seatId] + if (seat?.sessionId) { + try { await host.sessionController.rename({ sessionId: seat.sessionId, title: `${SEATS[seatId].label}会话` }) } catch { /* 标题失败不影响绑定 */ } + } + } + await store.mutate(s => { + const p = s.projects[projectId] + const allBound = SEAT_IDS.every(id => p.seats[id]?.status === 'bound') + p.status = allBound ? 'ready' : (p.status === 'error' ? 'pending' : p.status) + p.updatedAt = now() + p.revision = (p.revision ?? 0) + 1 + }) + return { projectId, seatId, ...result } + }) + } + async function enable(projectId) { return withLock(projectId, async () => { await store.ensureLoaded() @@ -150,5 +187,5 @@ export function createProvisioner({ store, host, now = () => Date.now() }) { }) } - return { enable, ensureSeat } + return { enable, enableSeat, ensureSeat } } diff --git a/sansheng/src/host/service.js b/sansheng/src/host/service.js index 8bd9af7..09f9d55 100644 --- a/sansheng/src/host/service.js +++ b/sansheng/src/host/service.js @@ -124,6 +124,14 @@ export class SanshengService { return this.project(projectId) } + async enableSeat(projectId, seatId) { + await this.store.ensureLoaded() + if (!this.store.get(projectId)) throw new ServiceError('sansheng/not-found', `项目 ${projectId} 不存在`) + if (!SEAT_IDS.includes(seatId)) throw new ServiceError('sansheng/invalid', `未知席 ${String(seatId)}`) + await this.provisioner.enableSeat(projectId, seatId) + return this.project(projectId) + } + async configure(projectId, seatId, { model, instructions } = {}) { await this.store.ensureLoaded() if (!SEAT_IDS.includes(seatId)) throw new ServiceError('sansheng/invalid', `未知席 ${seatId}`) @@ -192,9 +200,14 @@ export class SanshengService { const task = (project.tasks ?? []).find(item => item.id === taskId) if (!task) throw new ServiceError('sansheng/not-found', `任务 ${taskId} 不存在`) if (task.status === 'done' || task.status === 'cancelled') throw new ServiceError('sansheng/invalid', '已完成或已取消的任务不能再次派工') - const seat = project.seats[task.ownerSeatId] + let seat = project.seats[task.ownerSeatId] if (!seat || seat.status !== 'bound' || !seat.sessionId) { - throw new ServiceError('sansheng/seat-unbound', `请先为「${SEATS[task.ownerSeatId]?.label ?? task.ownerSeatId}」接通会话再派工`) + // 按需开启:丞相派工时只给出主责部门,由系统用该部门预配置的模型开启会话;丞相不选模型。 + await this.provisioner.enableSeat(projectId, task.ownerSeatId) + seat = this.store.get(projectId)?.seats?.[task.ownerSeatId] + if (!seat || seat.status !== 'bound' || !seat.sessionId) { + throw new ServiceError('sansheng/seat-unbound', `「${SEATS[task.ownerSeatId]?.label ?? task.ownerSeatId}」的会话还没开启成功,请稍后重试`) + } } const text = `【任务】${task.title}${task.goal ? '\n' + task.goal : ''}` let delivered = false diff --git a/sansheng/test/tasks.test.js b/sansheng/test/tasks.test.js index 03660eb..33a9a22 100644 --- a/sansheng/test/tasks.test.js +++ b/sansheng/test/tasks.test.js @@ -30,13 +30,32 @@ test('任务:新建草稿、派工记录、取消,按项目保存', async () await assert.rejects(() => service.taskDispatch(projectId, created.task.id), err => err.code === 'sansheng/invalid') }) -test('任务:缺标题、未知主责席被拒绝;未接通会话不能派工', async () => { +test('任务:缺标题、未知主责席被拒绝;派工按需开启该部门会话', async () => { const ctx = await setupService() const opened = await ctx.service.open({ path: '/tasks2', name: '未启用项目' }) await assert.rejects(() => ctx.service.taskCreate(opened.project.id, { title: '', ownerSeatId: 'lead' }), err => err.code === 'sansheng/invalid') await assert.rejects(() => ctx.service.taskCreate(opened.project.id, { title: 'x', ownerSeatId: 'nope' }), err => err.code === 'sansheng/invalid') const created = await ctx.service.taskCreate(opened.project.id, { title: '待派工', ownerSeatId: 'lead' }) - await assert.rejects(() => ctx.service.taskDispatch(opened.project.id, created.task.id), err => err.code === 'sansheng/seat-unbound') + const dispatched = await ctx.service.taskDispatch(opened.project.id, created.task.id) + // 派工时按需开启主责部门,不要求先手动启用十席 + assert.equal(dispatched.task.status, 'prepared') + assert.ok(dispatched.task.sessionId) + const view = await ctx.service.project(opened.project.id) + assert.equal(view.project.seats.find(s => s.id === 'lead').status, 'bound') +}) + +test('单席开启:应用预先配置的模型,且不要求开启十席', async () => { + const ctx = await setupService() + const opened = await ctx.service.open({ path: '/seat-model', name: '按需开启' }) + await ctx.service.configure(opened.project.id, 'gongbu', { model: { provider: 'deepseek', model: 'deepseek-reasoner', reasoningEffort: 'high' } }) + const view = await ctx.service.enableSeat(opened.project.id, 'gongbu') + const seat = view.project.seats.find(s => s.id === 'gongbu') + assert.equal(seat.status, 'bound') + // 其它席保持未开启 + assert.equal(view.project.seats.filter(s => s.status === 'bound').length, 1) + const applied = ctx.fake.calls.agentSelect.find(item => item.sessionId === seat.sessionId) + assert.ok(applied, '建会话后应把预配置模型应用到这个会话') + assert.deepEqual(applied.selection, { provider: 'deepseek', model: 'deepseek-reasoner', reasoningEffort: 'high' }) }) test('成果:登记、列表、关联任务校验', async () => {