@instruments/materialgraph 0.35.0 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ import type { FindVariantsByVectorItem } from "./find-variants-by-vector-types.js";
1
2
  /**
2
3
  * @module search-variants-types
3
4
  * @description Hand-maintained mirror of `search_variants`'s (MG-2223) input
@@ -9,6 +10,16 @@
9
10
  */
10
11
  import type { ColorRangeCondition, FilterGroups, ListVariantsInclude, ListVariantsOutput, OptionalFilterGroups } from "./list-variants-types.js";
11
12
  import type { SearchCatalogueSubset } from "./search-catalogue-subset-types.js";
13
+ /** Found by meaning, because fewer than half the query's words were understood. Follows `items`; not filtered by its words. */
14
+ export type SearchVariantsMeaning = {
15
+ /** Why no meaning results came back. */
16
+ error?: "timed_out" | "unavailable";
17
+ items: FindVariantsByVectorItem[];
18
+ /** How many of the query's content words were understood. */
19
+ understoodWords: number;
20
+ /** How many content words the query has. */
21
+ words: number;
22
+ };
12
23
  /** Switches one of a previous answer's `choices`: its `handle`, and the `group` and `id` of the alternative to read it as. */
13
24
  export type SearchVariantsSelection = {
14
25
  group: string;
@@ -72,6 +83,8 @@ export type SearchVariantsOutput = ListVariantsOutput & {
72
83
  correction: string;
73
84
  word: string;
74
85
  }[];
86
+ /** Results found by meaning, present only when most words were not understood. */
87
+ meaning?: SearchVariantsMeaning;
75
88
  /** The `listVariants()` filters that ran: send them, with `optionalFilters` and `name`, to `listVariants()` to narrow or widen this search. */
76
89
  filters?: FilterGroups;
77
90
  /** The paint name looked up, as `listVariants()` takes it. */
package/types.d.ts CHANGED
@@ -102,7 +102,7 @@ export type CospecPairing = {
102
102
  * How this companion relates to the seed — the distinction raw order evidence
103
103
  * does not carry, and the one that decides what you may claim.
104
104
  *
105
- * - `companion` — a DIFFERENT BRAND entirely. This is the cross-brand claim
105
+ * - `other_brand` — a DIFFERENT BRAND entirely. This is the cross-brand claim
106
106
  * the rail exists to make.
107
107
  * - `brand_sibling` — the seed's own brand, a different product.
108
108
  * - `colorway` — the seed's own product, restyled.
@@ -113,7 +113,7 @@ export type CospecPairing = {
113
113
  * Optional because responses captured before the field existed are genuinely
114
114
  * in the wild; absent means "from an older version", never "unrelated".
115
115
  */
116
- relation?: "companion" | "brand_sibling" | "colorway";
116
+ relation?: "other_brand" | "brand_sibling" | "colorway";
117
117
  category: string | null;
118
118
  projectCount: number;
119
119
  customerCount: number;
package/ndjson.d.ts DELETED
@@ -1,46 +0,0 @@
1
- /**
2
- * A minimal, dependency-free NDJSON (newline-delimited JSON) line reader — the
3
- * primitive for line-oriented JSON streams. Hand-rolled so the
4
- * SDK stays zero-runtime-dep and works unchanged inside Node route handlers,
5
- * where `fetch` yields a byte `ReadableStream`.
6
- *
7
- * Deliberately a SIBLING of `sse.ts`, not a reuse of it. NDJSON and SSE agree on
8
- * nothing but "text arrives in chunks": SSE frames are `field: value` lines
9
- * terminated by a BLANK line, with comment lines and multi-line `data:`
10
- * accumulation, whereas an NDJSON frame is exactly one line of JSON. Feeding
11
- * NDJSON through the SSE tokenizer would read `{"type":"step",…}` as a field
12
- * named `{"type"` and silently discard every frame. The two also want OPPOSITE
13
- * end-of-stream policies: SSE dispatches a trailing partial frame as valid,
14
- * while a truncated NDJSON line must surface as an error (enforced by the
15
- * caller, which parses whatever `flush` returns rather than dropping it).
16
- *
17
- * Line endings: the reader splits on `\n` only, per the NDJSON contract. A `\r`
18
- * left by a CRLF-normalising proxy stays as trailing whitespace on the line,
19
- * which `JSON.parse` ignores.
20
- */
21
- /**
22
- * A push-based NDJSON line assembler. Feed it decoded text with {@link push};
23
- * it returns the lines that text COMPLETED, terminators removed. Any partial
24
- * trailing line is held in an internal buffer until a later chunk terminates it,
25
- * or until {@link flush} surrenders it at end of stream.
26
- */
27
- export declare class NdjsonDecoder {
28
- #private;
29
- /** Absorb one decoded chunk and return the lines it completed, in order. */
30
- push(text: string): string[];
31
- /**
32
- * Surrender the unterminated remainder at end of stream — a well-formed
33
- * NDJSON stream's final line need not carry a trailing newline. The remainder
34
- * is RETURNED, never dropped: a truncated frame is the caller's error to
35
- * raise, not this decoder's fragment to discard.
36
- */
37
- flush(): string[];
38
- }
39
- /**
40
- * Iterate the NDJSON lines of a byte stream. Only lines with non-whitespace
41
- * content are yielded — a blank separator line carries no frame and must never
42
- * reach `JSON.parse`, where it would become an empty object. Stops cleanly when
43
- * the stream ends or `signal` aborts (mid-read abort rejections are swallowed
44
- * once the signal is set).
45
- */
46
- export declare function readNdjsonLines(body: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<string, void, unknown>;
package/ndjson.js DELETED
@@ -1,111 +0,0 @@
1
- /**
2
- * A minimal, dependency-free NDJSON (newline-delimited JSON) line reader — the
3
- * primitive for line-oriented JSON streams. Hand-rolled so the
4
- * SDK stays zero-runtime-dep and works unchanged inside Node route handlers,
5
- * where `fetch` yields a byte `ReadableStream`.
6
- *
7
- * Deliberately a SIBLING of `sse.ts`, not a reuse of it. NDJSON and SSE agree on
8
- * nothing but "text arrives in chunks": SSE frames are `field: value` lines
9
- * terminated by a BLANK line, with comment lines and multi-line `data:`
10
- * accumulation, whereas an NDJSON frame is exactly one line of JSON. Feeding
11
- * NDJSON through the SSE tokenizer would read `{"type":"step",…}` as a field
12
- * named `{"type"` and silently discard every frame. The two also want OPPOSITE
13
- * end-of-stream policies: SSE dispatches a trailing partial frame as valid,
14
- * while a truncated NDJSON line must surface as an error (enforced by the
15
- * caller, which parses whatever `flush` returns rather than dropping it).
16
- *
17
- * Line endings: the reader splits on `\n` only, per the NDJSON contract. A `\r`
18
- * left by a CRLF-normalising proxy stays as trailing whitespace on the line,
19
- * which `JSON.parse` ignores.
20
- */
21
- /**
22
- * A push-based NDJSON line assembler. Feed it decoded text with {@link push};
23
- * it returns the lines that text COMPLETED, terminators removed. Any partial
24
- * trailing line is held in an internal buffer until a later chunk terminates it,
25
- * or until {@link flush} surrenders it at end of stream.
26
- */
27
- export class NdjsonDecoder {
28
- #buffer = "";
29
- /** Absorb one decoded chunk and return the lines it completed, in order. */
30
- push(text) {
31
- this.#buffer += text;
32
- const lines = [];
33
- for (;;) {
34
- const index = this.#buffer.indexOf("\n");
35
- if (index === -1) {
36
- break;
37
- }
38
- lines.push(this.#buffer.slice(0, index));
39
- this.#buffer = this.#buffer.slice(index + 1);
40
- }
41
- return lines;
42
- }
43
- /**
44
- * Surrender the unterminated remainder at end of stream — a well-formed
45
- * NDJSON stream's final line need not carry a trailing newline. The remainder
46
- * is RETURNED, never dropped: a truncated frame is the caller's error to
47
- * raise, not this decoder's fragment to discard.
48
- */
49
- flush() {
50
- if (this.#buffer.length === 0) {
51
- return [];
52
- }
53
- const remainder = this.#buffer;
54
- this.#buffer = "";
55
- return [remainder];
56
- }
57
- }
58
- /**
59
- * Iterate the NDJSON lines of a byte stream. Only lines with non-whitespace
60
- * content are yielded — a blank separator line carries no frame and must never
61
- * reach `JSON.parse`, where it would become an empty object. Stops cleanly when
62
- * the stream ends or `signal` aborts (mid-read abort rejections are swallowed
63
- * once the signal is set).
64
- */
65
- export async function* readNdjsonLines(body, signal) {
66
- const reader = body.getReader();
67
- const decoder = new TextDecoder();
68
- const ndjson = new NdjsonDecoder();
69
- try {
70
- for (;;) {
71
- if (signal?.aborted) {
72
- return;
73
- }
74
- let result;
75
- try {
76
- result = await reader.read();
77
- }
78
- catch (error) {
79
- if (signal?.aborted) {
80
- return;
81
- }
82
- throw error;
83
- }
84
- if (result.done) {
85
- // `decode()` with no argument flushes any dangling multi-byte sequence.
86
- for (const line of ndjson.push(decoder.decode())) {
87
- if (line.trim().length > 0) {
88
- yield line;
89
- }
90
- }
91
- for (const line of ndjson.flush()) {
92
- if (line.trim().length > 0) {
93
- yield line;
94
- }
95
- }
96
- return;
97
- }
98
- for (const line of ndjson.push(decoder.decode(result.value, { stream: true }))) {
99
- if (signal?.aborted) {
100
- return;
101
- }
102
- if (line.trim().length > 0) {
103
- yield line;
104
- }
105
- }
106
- }
107
- }
108
- finally {
109
- reader.releaseLock();
110
- }
111
- }