Files
deepseek-harness/packages/util/values
imccyu 64ac8d1a5b fix(client): realm-independent JSON and shallowEqual checks, and owner-held cross-package styles (#9181)
* fix(typert): accept plain JSON values from any realm

An isolated Client plugin builds its values in an iframe, so they inherit
that realm's Array.prototype and Object.prototype, and the identity checks
in the Remote JSON validation and the Gateway's record checks rejected them.

dsh-util-values exports hasPlainPrototype, which matches this realm's
intrinsics by identity and another realm's through their native
constructors. isRemoteJsonValue and the Gateway's event-frame and
event-request record checks use it. Objects and arrays that inherit any
other prototype stay rejected, so an inherited toJSON cannot rewrite a
validated value.

* fix(client-store): compare Maps and Sets from any realm in shallowEqual

shallowEqual delegated to zustand/shallow, which recognizes collections with
instanceof Map and instanceof Set. A selector in a script-isolated plugin
returns collections built by its iframe realm, so both checks failed and two
Maps fell through to an Object.keys comparison, where any two Maps are equal.
ui-workflow-run selects its running members as a Map, so under isolation its
"Open ..." member buttons never appeared.

shallowEqual now recognizes Maps and Sets by their Object.prototype.toString
tag and otherwise keeps the one-level semantics: Object.is for scalars and
values, Set membership, and own enumerable string keys for other objects
and arrays. A Map comparison also requires each key to exist in the other
Map, so new Map([["a", undefined]]) no longer equals
new Map([["b", undefined]]). zustand remains a development dependency for
createStore and subscribeWithSelector.

* fix(ui-sidebar): ease the sidebar width from its layout owner props

ui-sidebar eased its width under `[data-animating]:not([data-dragging])`,
attributes of ui-layout's frame. With ui-sidebar's styles isolated that
ancestor lies outside its scope, so collapse and expand lost the easing.

ui-layout now passes the same state through `SidebarOwnerProps.animating`,
true while the frame eases its tracks and false during a resize drag or a
viewport change. The sidebar marks its own root `data-sidebar-animating`
and keeps the width transition there, after the quiet-scrollbar transition
it replaces, and reduced motion still turns it off.

* fix(ui-chat): style only Chat's own DOM inside the Conversation scrollport

ui-chat laid out its frame, scroller, aside layer, back-to-bottom control,
and turn rail under `:global([data-conversation-scroll]) .x`, and set
`overscroll-behavior-y` and `overflow-anchor` on ui-conversation's
scrollport through `[data-conversation-scroll]:has(.root)`. With ui-chat's
styles isolated, neither form matched, so Chat scrolled itself inside the
shared scrollport and lost its anchoring, back-to-bottom position, and
floating controls.

Chat's rules now test the scrollport in `:is()` on its own compounds,
`.frame:is(:global([data-conversation-scroll]) *)`, with unchanged
specificity. The scrollport rules move to their owner: ui-conversation
reads `data-conversation-overscroll="none"` and
`data-conversation-scroll-anchor="none"` from an element a View marks
inside the scrollport, and Chat marks its root with them, the second only
while it follows the tail.

* fix(ui-sidebar-documentpreview): hide the body a filling navigator covers

ui-sidebar-files hid the body of any row marked
`data-files-navigator-row` while its navigator Factory filled the row.
The document preview's content row is documentpreview's DOM, so with
ui-sidebar-files' styles isolated the covered preview stayed visible and
reachable by Tab.

The preview's own stylesheet now holds those rules on its `.content` row,
reading the navigator's `data-files-navigator-mode` through the row's
`:has()`, so the preview hides its body itself in both modes. The files
page row never had a covered sibling, so ui-sidebar-files drops the rules
and the `data-files-navigator-row` mark, and its README and Factory
documentation state that the host hides the covered content.

* chore(workflow-ptc): regenerate the workflow guest for the util-values prototype checks

The guest bundles packages/util/values; its same-realm Object.prototype and Array.prototype fast paths changed the generated source.
2026-11-25 21:33:04 +08:00
..
2026-11-22 15:27:28 +08:00

description, kind
description kind
Lossless JSON validation, detached snapshots, deep freezing, structural equality, and exhaustive-union helpers for runtime packages. package-library

@deepseek-ai/dsh-util-values

English | 中文

Summary

Callers can validate lossless JSON, read streamed arguments, detach a JSON snapshot, freeze a published value, compare JSON-compatible data, or terminate an unreachable branch without importing a capability package. Each streamed call uses its own PartialArguments reader; PartialArguments.EMPTY is a shared sealed view with no fields.

Table of Contents


Use this package

Validate or snapshot JSON data

Use isJsonValue() for a predicate and snapshotJsonValue() when the caller also needs a detached copy. Both accept only lossless JSON roots: null, booleans, finite numbers other than negative zero, strings, dense intrinsic arrays, and plain or null-prototype records with enumerable string keys. Cycles, sparse arrays, symbol or non-enumerable own properties, functions, and class instances are rejected.

import { isJsonValue, snapshotJsonValue, type JsonValue } from '@deepseek-ai/dsh-util-values'

declare const input: unknown

if (!isJsonValue(input)) throw new TypeError('expected lossless JSON')
const snapshot = snapshotJsonValue(input) as JsonValue

Use hasPlainPrototype(value) when a caller checks only the container and reads its fields itself. It accepts an array that inherits a realm's intrinsic Array.prototype and Object.prototype, or a non-array object whose prototype is null or a realm's intrinsic Object.prototype; elements and property values are not inspected. All three functions accept values built in another JavaScript realm, such as an iframe, and reject an object or array that inherits any other prototype, because that prototype could supply toJSON.

Read streamed arguments

PartialArguments reads a JSON object's top-level fields lazily. append() retains separate fragments without scanning or concatenating them. Readers index new key/value ranges, skipping unrequested contents; only requested strings are decoded or counted, and only requested complete non-string values are parsed. complete() reports a closing delimiter, not validated contents; invalid reports errors already discovered by indexing or content reads. It is not a substitute for tool-input validation.

refresh() reports changes to previously observed answers at publication time; intervening reads do not acknowledge pending changes. It evaluates content before comparing completion, so decoding errors cannot suppress a completion update. String readers provide decoded text, bounded prefixes, and exact UTF-16 length, with optional step and offset for change detection. settle(finalText) compares fragments directly against the complete text: equal input seals the same view and retains its caches; missing or conflicting deltas produce a new sealed view. fromText() and fromObject() also create sealed views that reject appends. isSealed reads that append restriction without scanning or observing content; closed() also covers a closed outer object or failed indexing. See the readers for return distinctions.

Publish, compare, or retain keyed values

deepFreeze(value) freezes an object graph in place and returns the same value. It walks enumerable string-keyed children and deliberately leaves live AbortSignal objects mutable. deepEqualJson(a, b) compares JSON-compatible arrays and records structurally; callers must validate hostile or unconstrained values before comparison.

WeakMapWithValues<Key, Value> combines weak object-key lookup with a strongly retained, insertion-ordered values set. Each value belongs to one key. The owner must call delete(key) or clear() at the corresponding lifecycle boundary; the collection does not perform automatic cleanup.

Close a discriminated union

Use assertNever(value, context?) in the default branch of a closed discriminated union. A newly added variant then fails TypeScript compilation at every exhaustive switch, while a runtime value that escaped its declared type throws with the optional context label.


Understand the implementation

Implementation internals — click to expand

The JSON validator keeps one cursor per active container, reads one child at a time, and tracks only the active ancestor chain, so deeply nested values do not consume the JavaScript call stack and repeated non-cyclic references remain valid. Containers that inherit this realm's intrinsics are recognized by identity; those of another JavaScript realm are recognized by native constructor representations from the running engine. Snapshot writes use own data properties, including for names such as __proto__. Value operations derive their result only from their arguments; WeakMapWithValues stores only instance-owned associations.

Source map

File Role
src/index.ts JSON value type, plain-prototype recognition, validation and snapshot traversal, structural equality, deep freezing, weak-key/strong-value associations, and exhaustive-union failure
src/partial-json.ts Lazy top-level argument scanning and observed-answer change detection

Further Exploration


Known Limitations and Deferred Work

  • deepEqualJson assumes JSON-compatible inputs — it is not a general object comparator and does not define semantics for prototypes, symbols, accessors, cycles, maps, or sets.
  • deepFreeze follows enumerable string-keyed children — it does not turn arbitrary host objects into immutable data, and it intentionally skips live AbortSignal instances.
  • WeakMapWithValues requires explicit cleanup and unique values — values remain strongly held until their owning key is deleted or the collection is cleared, and one value must not be shared by several keys.

Dev Note

Working context for maintainers — click to expand

None.