mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
The definitive slot model for the web client, replacing the first-generation
define/register two-step, ScopedSlots whitelist faces, and binding handles:
- 'root' is the only a-priori slot (SlotsService built-in); the shell renders
exactly ctx.slots.renderSlot('root', {}).
- register is the single API: children = slot declaration + render
authorization + runtime spec in one options object; misconfiguration fails
loud at load (duplicate declaration, undeclared contribution, one store
handle under two scopes).
- Component props arrive in four auto-derived shares: PropsRuntime<K>
(owner params + session/global standard kits via declare-merge),
PropsRenderSlots<S>, PropsStore<H>, and the inject business face.
sessionId is framework-supplied; hooks are framework-made only.
- Framework store seat: defineStore factories declare schema/actions/persist;
read = useStore, write = baked actions only; store scope derives from the
mounting entry; per-session persist keys and clearPersisted lifecycle.
- inject factories read the apply closure's own ctx (binding handles retired;
root-ctx back door closed); SessionProvider is self-wired render-prop.
- Rendering sits behind the SlotRenderer install seam; runtime stays
React-free; ownership ledger keyed to the single entry axis closes the
stale-authority window (StaleAuthorizationError probes).
Docs: the slot type-chain note is refreshed in place as the slot system
standard RFC (bilingual pair re-recorded); the web client architecture RFC
defers its slot sections there; packages/client/AGENTS.md gains the slot and
props discipline; gui-testing/web-styling notes drop missions/ references.
Tests: suites rewritten to the standard (props fed directly, real store
engines via createXXXStore().create(), no render machinery); load-time
negative samples for declaration/authorization/store conflicts; verified by
real-host playwright run (three columns, empty state, collapse, keyed session
remount, cross-slot selection sharing).
docs(ui-sidebar): point contract reference at the committed slot standard RFC
missions/ is workspace-local and never committed; the README must not cite it.
68 lines
2.6 KiB
TypeScript
68 lines
2.6 KiB
TypeScript
/**
|
|
* Runtime plugin browser-half apply: slots + sessions mounting over the
|
|
* connection handle, stream-loop sink wiring into the object layer, and the
|
|
* fiber-scoped loop teardown.
|
|
*/
|
|
import { Context } from 'cordis'
|
|
import { describe, expect, it } from 'vitest'
|
|
import type { ConnectionHandle } from '@deepseek-ai/dsh-client-connection/client'
|
|
import type { ConnectionSinks } from '@deepseek-ai/dsh-client-connection/client'
|
|
import * as RuntimeClient from '../src/client/index.ts'
|
|
import { FakeApiClient } from './fake-api.ts'
|
|
|
|
interface Bench {
|
|
ctx: Context
|
|
api: FakeApiClient
|
|
sinks: ConnectionSinks | undefined
|
|
stopped: number
|
|
}
|
|
|
|
async function mount(): Promise<Bench> {
|
|
const ctx = new Context()
|
|
const api = new FakeApiClient()
|
|
const bench: Bench = { ctx, api, sinks: undefined, stopped: 0 }
|
|
const handle: ConnectionHandle = {
|
|
api,
|
|
start: (sinks) => {
|
|
bench.sinks = sinks
|
|
return { stop: () => { bench.stopped += 1 } }
|
|
},
|
|
}
|
|
ctx.reflect.provide('connection', handle)
|
|
await ctx.plugin(RuntimeClient).await()
|
|
return bench
|
|
}
|
|
|
|
describe('runtime client apply', () => {
|
|
it('mounts ctx.slots + ctx.sessions and wires the stream sinks into the manager', async () => {
|
|
const bench = await mount()
|
|
expect(bench.ctx.get('slots') !== undefined).toBe(true)
|
|
// The built-in 'root' declaration ships with this package's SlotsService
|
|
// (the SlotMap 'root' merge lives here since the slot-parity rework).
|
|
expect(bench.ctx.slots.spec('root')).toEqual({ kind: 'single', scope: 'root' })
|
|
const sessions = bench.ctx.get('sessions')
|
|
expect(sessions !== undefined).toBe(true)
|
|
expect(bench.sinks).toBeDefined()
|
|
|
|
// Frame sinks reach the object layer: a host session-added lands in the list store.
|
|
bench.sinks?.onHostEnvelope?.({
|
|
rpcId: 'r1' as never,
|
|
payload: { type: 'host/session-added', sessionId: 's-new' } as never,
|
|
})
|
|
await Promise.resolve()
|
|
expect((sessions as { list: { getSnapshot(): { ids: string[] } } }).list.getSnapshot().ids).toContain('s-new')
|
|
// Mux sink and onConnected route without throwing (manager semantics own the behavior).
|
|
bench.sinks?.onMuxEnvelope?.({ rpcId: 'r2' as never, payload: { type: 'stream/error', message: 'x' } as never })
|
|
bench.sinks?.onConnected?.()
|
|
})
|
|
|
|
it('stops the stream loop when the plugin fiber unloads', async () => {
|
|
const bench = await mount()
|
|
const fiber = [...bench.ctx.registry.values()].find(f => f.name?.includes('client'))
|
|
// Dispose the whole tree: the ctx.effect teardown must call loop.stop exactly once.
|
|
await bench.ctx.fiber.dispose()
|
|
expect(bench.stopped).toBe(1)
|
|
void fiber
|
|
})
|
|
})
|