Merge origin/master into refactor/subagent

This commit is contained in:
Dudu-0223 committed 2026-09-21 15:07:47 +08:00
commit 55cbf441d0
558 files changed
+16303 -4339

No files matched your search

@@ -10,7 +10,6 @@ import type {
SessionProjectionHints,
SessionRenameValue,
SessionSummary,
SessionJob as JobView,
} from '../../types.ts'
import { mergeOrderedBaseline } from '../ordered-baseline.ts'
import { isRemoteFailure } from '@deepseek-ai/dsh-api-gateway/client'
@@ -56,8 +55,7 @@ export interface SessionListSnapshot {
phase: SessionListPhase
error: RemoteFailure | null
projectionsBySession: Readonly<Record<SessionId, SessionProjectionSnapshot>>
/** Background jobs per session; an absent key is an empty set. */
jobsBySession: Readonly<Record<SessionId, readonly JobView[]>>
}
/** Shared projection values and the lifecycle of their explicit baseline read. */
@@ -112,12 +110,7 @@ export class SessionManager {
private readonly addresses = new Map<SessionId, SubagentAddress>()
private readonly projectionLoads = new Map<SessionId, ProjectionLoad>()
private readonly projectionInflight = new Map<SessionId, ProjectionInflight>()
/**
* Background jobs per session, last-wins from Session Controller's control
* stream. An empty set is stored as an absent key, so absence and `[]` are
* one representation.
*/
private readonly jobsBySession = new Map<SessionId, readonly JobView[]>()
private listSnapshotCache: SessionListSnapshot
/** Entry-identity cache (reference stability): list rebuilds reuse the previous entry
@@ -628,21 +621,11 @@ export class SessionManager {
this.replaceControlBaseline(frame.value)
return
}
if (frame.type === 'projection') {
this.projectionStore(frame.sessionId).apply(frame.key, frame.value, SessionSeq(frame.seq))
this.notifier.markDirty()
return
}
if (frame.jobs.length === 0) this.jobsBySession.delete(frame.sessionId)
else this.jobsBySession.set(frame.sessionId, frame.jobs)
this.projectionStore(frame.sessionId).apply(frame.key, frame.value, SessionSeq(frame.seq))
this.notifier.markDirty()
}
private replaceControlBaseline(baseline: SessionControlBaseline): void {
this.jobsBySession.clear()
for (const [sessionId, jobs] of Object.entries(baseline.jobs)) {
if (jobs.length > 0) this.jobsBySession.set(sessionId as SessionId, jobs)
}
for (const [sessionId, block] of Object.entries(baseline.projections)) {
const store = this.projectionStore(sessionId as SessionId)
@@ -699,7 +682,6 @@ export class SessionManager {
: { kind: 'remove', sessionId })
if (durableSubagent) this.sessions.get(sessionId)?.handleRunning(false)
else this.sessions.get(sessionId)?.handleRemoved()
this.jobsBySession.delete(sessionId)
const catalog = this.projectionStores.get(sessionId)?.values().subagentCatalog
if (!durableSubagent && (catalog === undefined || catalog.length === 0)) {
this.projectionStores.delete(sessionId)
@@ -812,7 +794,6 @@ export class SessionManager {
sessionId,
{ values: store.values(), state: 'idle', error: null, ...this.projectionLoads.get(sessionId) },
])),
jobsBySession: Object.fromEntries(this.jobsBySession),
}
}
}
@@ -5,7 +5,6 @@ import { SessionSeq, type SessionId } from '@deepseek-ai/dsh-session/types'
import { workspaceTitleOf } from '@deepseek-ai/dsh-util-workspace-path'
import type { WorkspaceId } from '@deepseek-ai/dsh-workspace/types'
import { SESSION_SEARCH_RESULT_LIMIT } from '../../types.ts'
import type { SessionJob as JobView } from '../../types.ts'
import type { SessionProjectionMap } from '@deepseek-ai/dsh-session-projection/types'
import {
createSnapshotStore, notifySubscribers, type ObservableSnapshot, type SnapshotStore,
@@ -61,12 +60,6 @@ export interface SessionListState {
phase: SessionListPhase
/** Shared projection values and explicit-read state, including unopened Sessions. */
projectionsBySession: Readonly<Record<SessionId, SessionProjectionSnapshot>>
/**
* Background jobs each session can see, mirrored last-wins from Session
* Controller's control baseline and `jobs` frames. A missing key is an empty
* set, so consumers read absence rather than a sentinel.
*/
jobsBySession: Readonly<Record<SessionId, readonly JobView[]>>
}
/** Structured session-create failure. */
@@ -263,7 +256,7 @@ export class ClientSessions implements ISessions {
) {
this.manager = new SessionManager(remote)
this.list = createSnapshotStore<SessionListState>({
ids: [], byId: {}, phase: 'pending', projectionsBySession: {}, jobsBySession: {},
ids: [], byId: {}, phase: 'pending', projectionsBySession: {},
})
const disposeManagerProjection = this.manager.subscribe(() => { this.projectList() })
rootCtx.effect(() => async () => {
@@ -614,7 +607,7 @@ export class ClientSessions implements ISessions {
private projectList(): void {
const previousById = this.list.getSnapshot().byId
const {
items, phase, projectionsBySession, jobsBySession,
items, phase, projectionsBySession,
} = this.manager.getListSnapshot()
const ids: SessionId[] = []
const byId: Record<SessionId, SessionSummary> = {}
@@ -682,7 +675,7 @@ export class ClientSessions implements ISessions {
...(title === undefined ? {} : { title, displayTitle: title }),
}
}
this.list.set({ ids, byId, phase, projectionsBySession, jobsBySession })
this.list.set({ ids, byId, phase, projectionsBySession })
}
private startScopeDrop(
+2 -49
View File
@@ -1,9 +1,7 @@
/** Live Session jobs and projection state with reconnect baselines. */
/** Live Session projection state with reconnect baselines. */
import type { Context } from '@deepseek-ai/cordis'
import type { Agent } from '@deepseek-ai/dsh-agent'
import { Deque } from '@deepseek-ai/dsh-deque'
import type { JobSnapshot } from '@deepseek-ai/dsh-jobs'
import type {
Session, SessionId,
} from '@deepseek-ai/dsh-session'
@@ -11,7 +9,6 @@ import type { JsonValue } from '@deepseek-ai/dsh-util-values'
import type {
SessionControlBaseline,
SessionControlFrame,
SessionJob,
SessionProjectionBaseline,
SessionProjectionValues,
} from './types.ts'
@@ -20,7 +17,7 @@ import type {
export class SessionControlController {
private readonly streams = new Set<ControlQueue>()
/** @param ctx - Host context carrying live Agent, projection, and jobs services. */
/** @param ctx - Host context carrying live Agent and projection services. */
constructor(private readonly ctx: Context) {
ctx.sessionProjections.onChanged((session, key, value, seq) => {
this.broadcast({
@@ -31,13 +28,6 @@ export class SessionControlController {
seq,
})
})
ctx.inject(['jobs'], (jobsCtx) => {
jobsCtx.jobs.onJobsChanged((owner) => { this.onJobsChanged(owner) })
})
ctx.on('session/created', (session) => {
const jobs = this.jobsFor(this.ctx.agents.get(session.id))
if (jobs.length > 0) this.broadcast({ type: 'jobs', sessionId: session.id, jobs })
})
ctx.effect(() => () => {
for (const stream of this.streams) stream.end()
this.streams.clear()
@@ -64,13 +54,7 @@ export class SessionControlController {
private baseline(): SessionControlBaseline {
const sessions = this.ctx.sessions.list()
const jobs = Object.create(null) as Record<SessionId, readonly SessionJob[]>
for (const session of sessions) {
const agent = this.ctx.agents.get(session.id)
jobs[session.id] = this.jobsFor(agent)
}
return {
jobs,
projections: this.projectionBaseline(sessions),
}
}
@@ -90,25 +74,6 @@ export class SessionControlController {
return blocks
}
private onJobsChanged(owner: Agent | undefined): void {
if (owner !== undefined) {
this.broadcast({ type: 'jobs', sessionId: owner.id, jobs: this.jobsFor(owner) })
return
}
for (const session of this.ctx.sessions.list()) {
this.broadcast({
type: 'jobs',
sessionId: session.id,
jobs: this.jobsFor(this.ctx.agents.get(session.id)),
})
}
}
private jobsFor(agent: Agent | undefined): SessionJob[] {
const jobs = this.ctx.get('jobs')
return jobs === undefined ? [] : jobs.list(agent).map(jobView)
}
private broadcast(frame: SessionControlFrame): void {
for (const stream of this.streams) stream.push(frame)
}
@@ -154,15 +119,3 @@ class ControlQueue {
}
}
}
function jobView(job: JobSnapshot): SessionJob {
return {
id: job.id,
kind: job.kind,
label: job.label,
status: job.status,
...(job.detail === undefined ? {} : { detail: job.detail }),
startedAt: job.startedAt,
...(job.finishedAt === undefined ? {} : { finishedAt: job.finishedAt }),
}
}
@@ -498,6 +498,7 @@ export class SessionController extends TypertRemoteService {
return this.controlState.control(signal)
}
}
export { buildModelCatalog }
@@ -9,7 +9,6 @@ import type { LlmAttemptId, MessageId } from '@deepseek-ai/dsh-llm/brand'
import type { TextBlock } from '@deepseek-ai/dsh-llm'
import type { SessionId, SessionSeqCursor } from '@deepseek-ai/dsh-session/types'
import type { SessionProjectionMap } from '@deepseek-ai/dsh-session-projection/types'
import type { JobId } from '@deepseek-ai/dsh-jobs/brand'
import type { JsonValue } from '@deepseek-ai/dsh-util-values'
import type { WorkspaceId } from '@deepseek-ai/dsh-workspace/types'
@@ -555,20 +554,8 @@ export type SessionFollowFrame =
| SessionEventEntry
| { readonly type: 'assistant-stream'; readonly frame: SessionAssistantStreamFrame }
/** Browser-safe background-job row. */
export interface SessionJob {
readonly id: JobId
readonly kind: string
readonly label: string
readonly status: 'running' | 'stopping' | 'completed' | 'killed' | 'failed'
readonly detail?: string
readonly startedAt: number
readonly finishedAt?: number
}
/** Complete live control baseline emitted once per control stream generation. */
export interface SessionControlBaseline {
readonly jobs: Readonly<Record<SessionId, readonly SessionJob[]>>
readonly projections: Readonly<Record<SessionId, SessionProjectionBaseline>>
}
@@ -583,7 +570,6 @@ export interface SessionProjectionUpdate {
/** Host-wide live state stream. Each generation starts with exactly one baseline. */
export type SessionControlFrame =
| { readonly type: 'baseline'; readonly value: SessionControlBaseline }
| { readonly type: 'jobs'; readonly sessionId: SessionId; readonly jobs: readonly SessionJob[] }
| ({ readonly type: 'projection' } & SessionProjectionUpdate)
declare module '@deepseek-ai/cordis' {