Files
deepseek-harness/packages/client/modules/src/client/index.ts
T
imccyu bd1d6dcd0c Merge pull request #8504 from deepseek-harness/feat/client-config-live-update
feat(client): sync volatile plugin config to the browser
2026-11-17 16:08:14 +08:00

75 lines
3.5 KiB
TypeScript

/**
* Browser half (the standard `./client` export): the module-system class and
* wire contract, plus the enrollment plugin face. The module system itself is
* built by the shell kernel BEFORE cordis exists (the bootstrap exception —
* the mechanism that loads plugins cannot arrive through itself). The host
* parser-preloads this ordinary client bundle into the pending registration
* queue. The HTML-installed loader facade materializes this bundle and calls
* its bootstrap export, which constructs the system and retains the same
* exports for this package's graph row. The plugin face enrolls the module
* system attached to its own Loader as `ctx.modules`.
* @module @deepseek-ai/dsh-client-modules/client
*/
import type { Context } from '@deepseek-ai/cordis'
import type { Loader } from '@deepseek-ai/cordis-plugin-loader'
import { ClientModuleSystem } from './system.ts'
import { parseBootManifest } from './manifest.ts'
import type { SyncedConfig, SyncedConfigService } from '@deepseek-ai/dsh-client-config/types'
import type {
ClientBootstrapModule, ClientModuleCreateOptions, ClientModuleLoader, ClientModuleLoaderTarget,
} from './manifest.ts'
export { ClientModuleSystem }
export { tearDownEntryFiber } from './entry-lifecycle.ts'
export type { ClientReleaseChange } from './release-change.ts'
export type { ClientEntries, ClientEntryState } from './entries.ts'
export { exactPackageSpecifier, parseBootManifest, parseDshClient, stripClientSuffix } from './manifest.ts'
export type {
BootManifest, BootModuleRow, BootPluginRow, ClientBootstrapModule, ClientBundleRegistration,
ClientModuleCreateOptions, ClientModuleLoader, ClientModuleLoaderTarget, ClientModuleRecord,
ClientModuleSystemOptions, DshWindow,
WebBootEntry, WebBootGraph, WebBootRelease,
} from './manifest.ts'
/**
* Build the live module system from the HTML facade's materialized modules bundle.
* @param target - Stable registration facade whose pending queue becomes the live sink.
* @param bootstrapModule - This bundle's id and already-materialized exports.
* @param options - Raw boot graph, delivered manifests, and optional bundle transport.
* @returns The created module system.
*/
export function createClientModuleSystem(
target: ClientModuleLoaderTarget,
bootstrapModule: ClientBootstrapModule,
options: ClientModuleCreateOptions,
): ClientModuleSystem {
return new ClientModuleSystem({
manifest: parseBootManifest(options.boot),
staticModules: options.staticModules,
registrationTarget: target,
bootstrapModule,
...(options.loadBundle === undefined ? {} : { loadBundle: options.loadBundle }),
...(options.resolveAsset === undefined ? {} : { resolveAsset: options.resolveAsset }),
})
}
/** Required service: the Loader whose internal module system and synced configuration this plugin publishes. */
export const inject = ['loader']
/**
* Enroll the kernel-built module system as `ctx.modules` and its synced configuration lookup as `ctx.config`.
* @param ctx - client root context.
*/
export function apply(ctx: Context): void {
const loader: Loader = ctx.loader
const modules = loader.internal as unknown as ClientModuleLoader | undefined
if (modules?.version !== 'client') {
throw new Error('client-modules: the Loader has no client module system')
}
ctx.reflect.provide('modules', modules)
const config: SyncedConfigService = {
resolveConfigByPackage: <C>(packageName: string) => modules.entries.resolveConfigByPackage(packageName) as SyncedConfig<C> | undefined,
}
ctx.reflect.provide('config', config)
}