* feat(preset): declare Agent compositions in profile YAML * fix(preset): share scope binding cleanup and refresh module graph * fix(preset): use host syntax colors in the YAML editor * fix(preset): write new profile declarations as block YAML * fix(preset): align eager activation with browser and worker surfaces * fix(ui-agent-preset): retain the existing preset card layout * fix(preset): keep rows waiting for a Host service mounted and re-audit after settlement A preset row whose Host provider was still activating at declaration time was reported as waiting for a missing service, and the registry recorded the definition as broken for the rest of the process. Split the mount audit into failed and pending rows: failures and root-realm leaks still reject the mount, while pending rows stay mounted and every read and binding re-audits them after the Host Loader tree settles. Remove the accidental self-dependency of @deepseek-ai/dsh-web-app and its lockfile self-link. Archive the copy-only preset authoring note, which the declarative-preset note fully supersedes, and update the ralph note's restore recipe to the profile-patch mechanism. * chore(lint): re-key and prune the unknown-cast baseline after the master merge * refactor(web-app): ship each Agent preset as its own bundle patch file `dsh.bundle.patch` accepts an ordered file list, so the four shipped preset declarations move out of the 1000-line web patch into `presets/<id>.patch.yml`, one insert per file, applied after the host patch. The host patch keeps the preset registry row. Gates and test scaffolds that read the web layer resolve every patch file through `bundlePatchPaths` instead of one hardcoded path. * refactor(preset): drop the save notice injected into live Agents The notice duplicated the save result the Web editor already shows, and after the producer-owned message sources it would have needed its own persisted source kind. Saving now only persists and reports the activation diagnostic; the persistence catalog is unchanged from master. * docs: regenerate the module graph after dropping the registry's llm dependency * test(ui-agent-preset): cover the guide dialog's keyboard handling on the declarative section * fix(preset): address the remaining review comments Apply the lowercase id rule only when creating a declaration, so presets declared with other ids stay editable. Export `isBuiltInPreset` from the display fold and key the client card groups on it. Remove the dead `error` and `retry` locale keys, the JSDoc orphaned by the `trust` removal, the `trust` fields in the plugin-inventory test fixtures, and the stale `dsh-agent-presets` package name in comments and READMEs. * refactor(preset): make the Web preset page view-and-select only Remove the child-plugin YAML editor, the `agent_preset` tool and the registry's read/save Remote methods. Presets are declared and changed only by bundle patches; the settings page keeps the roster, the new-task default and the mode help, and its question icon explains that and offers to start a Creator-mode task. The `editing-cordis-compositions` skill and the Creator persona describe the bundle-based path, and the authored skill-load Session and Web snapshots are refreshed for it. * docs(skill): make the composition skill self-sufficient for preset authoring State where the shipped declarations live, list every declaration field, inline a complete minimal bundle and an override example, and name the verification calls, so Creator mode no longer reads DSH package sources to infer the format. Refresh the authored skill-load Session for the new text. * test(tools): drop the removed agent_preset tool from the catalog expectation
169 lines
6.2 KiB
TypeScript
169 lines
6.2 KiB
TypeScript
/** Host BFF entry and Loader shell for the Remote contribution assembly. */
|
|
|
|
import { homedir } from 'node:os'
|
|
import type { Context } from '@deepseek-ai/cordis'
|
|
import type { Agent } from '@deepseek-ai/dsh-agent'
|
|
import type {
|
|
TypertRemoteEventDispatch,
|
|
TypertRemoteEventInvocation,
|
|
TypertRemoteEventOutcome,
|
|
TypertRemoteEventSource,
|
|
} from '@deepseek-ai/dsh-api-gateway'
|
|
import { Deque } from '@deepseek-ai/dsh-deque'
|
|
import { carrierKeyOf } from '@deepseek-ai/dsh-scope'
|
|
import { isJsonValue, type JsonValue } from '@deepseek-ai/dsh-util-values'
|
|
import { API_REMOTE_FORWARDED_EVENTS } from './remote-events.ts'
|
|
|
|
// The owner packages' client-safe `./types` exports carry the cordis `Events`
|
|
// declarations for every allowlisted event. Pulling them into this face is what
|
|
// makes the shape assertion below judge real signatures rather than an empty
|
|
// event vocabulary.
|
|
import type {} from '@deepseek-ai/dsh-commands/types'
|
|
import type {} from '@deepseek-ai/dsh-cordis-host-runner/types'
|
|
import type {} from '@deepseek-ai/dsh-credentials/types'
|
|
import type {} from '@deepseek-ai/dsh-goal/types'
|
|
import type {} from '@deepseek-ai/dsh-llm/types'
|
|
import type {} from '@deepseek-ai/dsh-agent-preset-registry/types'
|
|
import type {} from '@deepseek-ai/dsh-permission-presets/types'
|
|
import type {} from '@deepseek-ai/dsh-settings/types'
|
|
import type {} from '@deepseek-ai/dsh-user-approval'
|
|
import type {} from '@deepseek-ai/dsh-user-questions'
|
|
export type {} from '@deepseek-ai/dsh-api-session-controller/types'
|
|
|
|
export { API_REMOTE_FORWARDED_EVENTS } from './remote-events.ts'
|
|
export type { ApiRemoteForwardedEvent } from './types.ts'
|
|
|
|
/** Required Host service: the Gateway owns the physical Remote stream mux. */
|
|
export const inject = ['typertGateway']
|
|
|
|
/** Host plugin body registering this application's selected Cordis event source. */
|
|
export function apply(ctx: Context): void {
|
|
ctx.effect(
|
|
() => ctx.typertGateway.registerRemoteEvents(remoteEventSource(ctx), { home: homedir() }),
|
|
'api-remotes: forwarded Cordis event source',
|
|
)
|
|
}
|
|
|
|
/** Create the sole queue and listener set consumed by the registered Gateway. */
|
|
function remoteEventSource(ctx: Context): TypertRemoteEventSource {
|
|
return (signal) => {
|
|
const queue = new RemoteEventQueue()
|
|
const disposers = API_REMOTE_FORWARDED_EVENTS.map(({ event, mode }) => {
|
|
if (mode === 'emit') {
|
|
return ctx.on(event as never, ((...args: unknown[]) => {
|
|
queue.push({ event, args: assertJsonArgs(event, args) })
|
|
}) as never)
|
|
}
|
|
return ctx.on(event as never, (function (
|
|
this: unknown,
|
|
request: object,
|
|
next: () => unknown,
|
|
) {
|
|
const carrierAgent = carrierKeyOf(this)
|
|
if (carrierAgent === undefined) return next()
|
|
const agent = (request as { readonly agent?: Agent }).agent
|
|
if (agent === undefined || agent !== carrierAgent) {
|
|
throw new TypeError(`forwarded scoped event ${JSON.stringify(event)} must carry its Agent directly`)
|
|
}
|
|
return forwardWaterfall(
|
|
queue,
|
|
event,
|
|
request,
|
|
{ value: agent.ctx, subject: agent, agentId: agent.id },
|
|
next,
|
|
)
|
|
}) as never)
|
|
})
|
|
return queue.iterate(signal, () => {
|
|
for (const dispose of disposers) dispose()
|
|
})
|
|
}
|
|
}
|
|
|
|
/** One pull-driven queue bridging synchronous Cordis listeners to an AsyncIterable. */
|
|
class RemoteEventQueue {
|
|
private readonly buffer = new Deque<TypertRemoteEventDispatch>()
|
|
private waiter: (() => void) | undefined
|
|
private done = false
|
|
|
|
push(frame: TypertRemoteEventDispatch): boolean {
|
|
if (this.done) return false
|
|
this.buffer.pushBack(frame)
|
|
this.waiter?.()
|
|
return true
|
|
}
|
|
|
|
private end(reason: unknown): void {
|
|
if (this.done) return
|
|
this.done = true
|
|
while (this.buffer.size > 0) {
|
|
const dispatch = this.buffer.popFront() as TypertRemoteEventDispatch
|
|
if ('context' in dispatch) dispatch.reject(reason)
|
|
}
|
|
this.waiter?.()
|
|
}
|
|
|
|
async *iterate(signal: AbortSignal, cleanup: () => void): AsyncGenerator<TypertRemoteEventDispatch> {
|
|
const abort = (): void => { this.end(remoteEventSourceEndReason(signal)) }
|
|
signal.addEventListener('abort', abort, { once: true })
|
|
try {
|
|
while (true) {
|
|
if (this.done || signal.aborted) return
|
|
while (this.buffer.size > 0) yield this.buffer.popFront() as TypertRemoteEventDispatch
|
|
await new Promise<void>((resolve) => { this.waiter = resolve })
|
|
this.waiter = undefined
|
|
}
|
|
} finally {
|
|
signal.removeEventListener('abort', abort)
|
|
this.end(remoteEventSourceEndReason(signal))
|
|
cleanup()
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Normalize an event-source shutdown for pending Host waterfalls.
|
|
* @param signal - source lifetime whose reason wins after cancellation.
|
|
* @returns the cancellation reason or an unexpected-end failure.
|
|
*/
|
|
function remoteEventSourceEndReason(signal: AbortSignal): unknown {
|
|
if (signal.aborted) return signal.reason
|
|
return new Error('api-remotes: forwarded Remote event source ended')
|
|
}
|
|
|
|
/** Bridge one Cordis waterfall listener through the Gateway-owned pending event. */
|
|
function forwardWaterfall(
|
|
queue: RemoteEventQueue,
|
|
event: string,
|
|
request: object,
|
|
context: TypertRemoteEventInvocation['context'],
|
|
next: () => unknown,
|
|
): Promise<unknown> {
|
|
const settled = Promise.withResolvers<unknown>()
|
|
const dispatch: TypertRemoteEventInvocation = {
|
|
event,
|
|
request,
|
|
context,
|
|
resolve: (outcome: TypertRemoteEventOutcome) => {
|
|
if (outcome.kind === 'result') {
|
|
settled.resolve(outcome.value)
|
|
return
|
|
}
|
|
void Promise.resolve().then(next).then(settled.resolve, settled.reject)
|
|
},
|
|
reject: settled.reject,
|
|
}
|
|
if (!queue.push(dispatch)) void Promise.resolve().then(next).then(settled.resolve, settled.reject)
|
|
return settled.promise
|
|
}
|
|
|
|
/** Reject an allowlisted event whose runtime arguments are not lossless JSON data. */
|
|
function assertJsonArgs(event: string, args: readonly unknown[]): JsonValue[] {
|
|
for (const [index, arg] of args.entries()) {
|
|
if (!isJsonValue(arg)) {
|
|
throw new Error(`forwarded host event "${event}" argument ${String(index)} is not lossless JSON data`)
|
|
}
|
|
}
|
|
return args as JsonValue[]
|
|
}
|