Files
deepseek-harness/packages/api/remote-access/src/client/index.ts
T
imccyu 09899f3a0f feat(remote-access): 插件注册跟随访问状态(whenAccess),index 按 Peer 注入访问快照
- remote-access 新增 whenAccess / whenResourceAccess,ui-session、ui-workspace 各自提供 whenAccess
- schedule、plugin-manager、settings-general、settings-account、directory-picker-native 的入口包进 global whenAccess;消息反馈按钮按会话 useAccess 渲染
- webserver/index-inject 带 Peer,renderIndex / collectIndexInjections 需要 Peer,remote-access 注入 snapshotFor(peer.principal)
- client-test-runtime 新增 StaticRemoteAccess、staticAccessPlugin 与 TestClientOptions.access
- implemented Agent Note 2026-10-21-when-access 与升级指南 webserver-index-peer

Refs #2940
2026-10-21 17:57:51 +08:00

37 lines
1.8 KiB
TypeScript

/**
* Client face: starts from the access snapshot the index injected, follows
* the calling Peer's snapshot stream, provides the `remoteAccess` Client
* service whose `source(kind, id, action)` answers for any declared-kind
* resource and whose `whenAccess(action, callback)` keeps effects installed
* while the global resource allows an action, and publishes
* `useRemoteAccess(action)` on the global resource. Domain UI adapters
* publish their own resource Hooks over `source()` and their own
* `whenAccess` over `whenResourceAccess()`. Every
* answer is a boolean: true for the owner, false without a snapshot or after
* a non-owner stream fails; the Host enforces every call regardless.
* @module @deepseek-ai/dsh-api-remote-access/client
*/
import type { Context } from '@deepseek-ai/cordis'
import remoteAccessRemote from '@deepseek-ai/dsh-api-remote-access/remote'
import { REMOTE_ACCESS_SNAPSHOT_KEY } from '../snapshot.ts'
import { mountAccess } from './mount.ts'
import { parseInjectedBaseline } from './state.ts'
export type {
RemoteAccessAction, RemoteAccessEndpoint, RemoteAccessFrame, RemoteAccessGrant, RemoteAccessResource, TypertResourceKind,
} from '../types.ts'
export type { AccessEffect, ClientRemoteAccess, RemoteEndpoint } from './mount.ts'
/** Required Client services: the Remote mount face and the Slot registry. */
export const inject = ['remote', 'slots']
/**
* Mount the generated `remoteAccess` namespace and publish the access Hooks.
* @param ctx - Client root Context.
* @returns disposer that withdraws the namespace after the stream stops.
*/
export function apply(ctx: Context): Promise<() => Promise<void>> {
return mountAccess(ctx, remoteAccessRemote, parseInjectedBaseline(Reflect.get(globalThis, REMOTE_ACCESS_SNAPSHOT_KEY)))
}