mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
The remaining P1 from the #939 review, plus the P2 it shares a mechanism with. Nothing carried a version, so two tabs editing one namespace silently overwrote each other — reproduced as tab B's `reasoning` lost to tab A's older draft. The seam's per-namespace write queue orders writes; it cannot tell a fresh writer from one replaying a snapshot a predecessor superseded. Each namespace now carries a monotonic `revision` over its RAW section. A write may send `expectedRevision`, checked at the FRONT of the queue (not at call time, which would race the very predecessor it guards against); a mismatch rejects with `SettingsConflictError` → `settings-conflict` on the wire, carrying both revisions. The editor captures the revision it opened at and, on conflict, asks the user to reopen rather than replaying its snapshot. The same counter fixes the missing broadcast. `settings/updated` is gated on the resolved value — correct for consumers, wrong for configuration surfaces: storing an override equal to the composition base leaves the resolved value alone while changing what the document says (the field is now overridden, not inherited) and moving every open editor's revision. `settings/document-updated (ns, revision)` fires on any raw-section change, in-process or external, and `host/settings-changed` now rides it. That event also closes the stale model picker: editing a provider's `models` changes no route, so `llm/adapters-updated` never fired and an open picker kept serving the old catalog. A change to an exposed provider namespace now emits `host/models-changed` too — that namespace holds the catalog. Docs: both sides of the five touched README pairs, a type-equiv block for `SettingsPathOp`, and an Agent Note recording what the plane exposes and who may overwrite what. The deferred wire-redaction gaps (secrets behind union/intersection/transform, `.default(...)` in the served envelope, schema text in rejection messages, `new Function` rehydration, pi-ai's `headers`) are recorded as TODO(settings-wire-redaction) and in Known Limitations rather than half-fixed.
73 lines
3.1 KiB
TypeScript
73 lines
3.1 KiB
TypeScript
/**
|
|
* settings domain zod schemas (names derived from map keys: settingsDescribeRequestSchema /
|
|
* settingsDescribeValueSchema / settingsUpdate* / settingsReplace*).
|
|
*/
|
|
|
|
import { z } from 'zod'
|
|
import type { RequestPayload, ResponseValue } from './rpc-map.ts'
|
|
import type { Wire } from './rpc.schema.ts'
|
|
import type { SettingsNamespaceView, SettingsPathOpView, SettingsSecretView } from './settings.ts'
|
|
|
|
/** One redacted secret slot. */
|
|
export const settingsSecretViewSchema = z.object({
|
|
path: z.array(z.string()),
|
|
set: z.boolean(),
|
|
}) satisfies z.ZodType<Wire<SettingsSecretView>>
|
|
|
|
/** SettingsNamespaceView row of settings.describe and the write responses. */
|
|
export const settingsNamespaceViewSchema = z.object({
|
|
ns: z.string().min(1),
|
|
schema: z.unknown(),
|
|
value: z.unknown(),
|
|
base: z.unknown().optional(),
|
|
user: z.unknown().optional(),
|
|
applies: z.union([z.literal('live'), z.literal('restart')]),
|
|
secrets: z.array(settingsSecretViewSchema),
|
|
revision: z.number(),
|
|
}) satisfies z.ZodType<Wire<SettingsNamespaceView>>
|
|
|
|
/** settings.describe request payload. */
|
|
export const settingsDescribeRequestSchema = z.object({}) satisfies z.ZodType<Wire<RequestPayload<'settings.describe'>>>
|
|
|
|
/** settings.describe response value. */
|
|
export const settingsDescribeValueSchema = z.object({
|
|
writable: z.boolean(),
|
|
namespaces: z.array(settingsNamespaceViewSchema),
|
|
}) satisfies z.ZodType<Wire<ResponseValue<'settings.describe'>>>
|
|
|
|
/** settings.update request payload. */
|
|
export const settingsUpdateRequestSchema = z.object({
|
|
ns: z.string().min(1),
|
|
patch: z.record(z.string(), z.unknown()),
|
|
expectedRevision: z.number().optional(),
|
|
}) satisfies z.ZodType<Wire<RequestPayload<'settings.update'>>>
|
|
|
|
/** settings.update response value: the namespace's new redacted view. */
|
|
export const settingsUpdateValueSchema = settingsNamespaceViewSchema satisfies z.ZodType<Wire<ResponseValue<'settings.update'>>>
|
|
|
|
/** settings.replace request payload. */
|
|
export const settingsReplaceRequestSchema = z.object({
|
|
ns: z.string().min(1),
|
|
section: z.record(z.string(), z.unknown()),
|
|
expectedRevision: z.number().optional(),
|
|
}) satisfies z.ZodType<Wire<RequestPayload<'settings.replace'>>>
|
|
|
|
/** One path-addressed edit of settings.mutate. */
|
|
export const settingsPathOpSchema = z.discriminatedUnion('op', [
|
|
z.object({ op: z.literal('set'), path: z.array(z.string()), value: z.unknown() }),
|
|
z.object({ op: z.literal('unset'), path: z.array(z.string()) }),
|
|
]) as unknown as z.ZodType<Wire<SettingsPathOpView>>
|
|
|
|
/** settings.mutate request payload. */
|
|
export const settingsMutateRequestSchema = z.object({
|
|
ns: z.string().min(1),
|
|
ops: z.array(settingsPathOpSchema),
|
|
expectedRevision: z.number().optional(),
|
|
}) satisfies z.ZodType<Wire<RequestPayload<'settings.mutate'>>>
|
|
|
|
/** settings.mutate response value: the namespace's new redacted view. */
|
|
export const settingsMutateValueSchema = settingsNamespaceViewSchema satisfies z.ZodType<Wire<ResponseValue<'settings.mutate'>>>
|
|
|
|
/** settings.replace response value. */
|
|
export const settingsReplaceValueSchema = settingsNamespaceViewSchema satisfies z.ZodType<Wire<ResponseValue<'settings.replace'>>>
|