@instruments/materialgraph 1.4.0 → 2.1.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.
Files changed (44) hide show
  1. package/catalog-client.d.ts +1 -6
  2. package/catalog-client.js +0 -15
  3. package/catalog-types.d.ts +0 -43
  4. package/client-response-schema.js +0 -1
  5. package/client.d.ts +1 -11
  6. package/client.js +1 -12
  7. package/colors-client.d.ts +1 -1
  8. package/colors-client.js +6 -2
  9. package/find-sampled-together-types.d.ts +0 -2
  10. package/get-variant-types.d.ts +1 -1
  11. package/http-transport.d.ts +0 -16
  12. package/http-transport.js +0 -73
  13. package/identifiers.d.ts +1 -6
  14. package/identifiers.js +1 -1
  15. package/index.d.ts +5 -5
  16. package/index.js +1 -1
  17. package/nearest-paints-types.d.ts +2 -0
  18. package/operation-responses.d.ts +2 -7
  19. package/operations.generated.d.ts +1 -1
  20. package/operations.generated.js +0 -30
  21. package/package.json +2 -6
  22. package/resolve-color-types.d.ts +0 -6
  23. package/response-schemas.generated.d.ts +1 -1
  24. package/response-schemas.generated.js +36 -43
  25. package/response-schemas.js +1 -2
  26. package/scheme-bundle-types.d.ts +20 -0
  27. package/scheme-bundle-types.js +10 -0
  28. package/search-catalog-subset-types.d.ts +1 -1
  29. package/source-material-types.d.ts +59 -0
  30. package/source-material.d.ts +8 -0
  31. package/source-material.js +92 -0
  32. package/webmcp.generated.js +4 -4
  33. package/run-types.d.ts +0 -161
  34. package/run-types.js +0 -6
  35. package/runs.d.ts +0 -36
  36. package/runs.js +0 -198
  37. package/samplize-catalog-types.d.ts +0 -98
  38. package/samplize-colorvec.d.ts +0 -70
  39. package/samplize-colorvec.js +0 -222
  40. package/sse.d.ts +0 -36
  41. package/sse.js +0 -167
  42. package/workflows-client.d.ts +0 -54
  43. package/workflows-client.js +0 -41
  44. /package/{samplize-catalog-types.js → source-material-types.js} +0 -0
package/sse.js DELETED
@@ -1,167 +0,0 @@
1
- /**
2
- * A minimal, dependency-free Server-Sent Events reader — the primitive behind
3
- * {@link WorkflowsClient.streamRunEvents}. Hand-rolled (no `eventsource`,
4
- * no `undici`) so the SDK stays zero-runtime-dep and works unchanged inside
5
- * Node route handlers, where `fetch` yields a byte `ReadableStream`.
6
- *
7
- * The parser follows the WHATWG event-stream tokenizer closely enough for the
8
- * `/api/v1/workflows/{workflowId}/runs/{runId}/events` contract: `\n`, `\r\n`, and `\r` line endings,
9
- * multi-line `data:` accumulation, comment (`:`-prefixed) lines, and a single
10
- * optional leading space after the field colon. Frames split across network
11
- * chunks are held in an internal buffer until their terminating blank line.
12
- */
13
- /**
14
- * A push-based SSE line assembler. Feed it decoded text with {@link push}; it
15
- * returns any frames completed by that text. Call {@link flush} once the stream
16
- * ends to dispatch a final frame that had data but no terminating blank line.
17
- */
18
- export class SseDecoder {
19
- #buffer = "";
20
- #dataLines = [];
21
- #id;
22
- #event;
23
- #hasFields = false;
24
- push(text) {
25
- this.#buffer += text;
26
- const frames = [];
27
- for (;;) {
28
- const lineEnd = this.#nextLineEnd();
29
- if (lineEnd === null) {
30
- break;
31
- }
32
- const line = this.#buffer.slice(0, lineEnd.index);
33
- this.#buffer = this.#buffer.slice(lineEnd.nextIndex);
34
- const frame = this.#consumeLine(line);
35
- if (frame) {
36
- frames.push(frame);
37
- }
38
- }
39
- return frames;
40
- }
41
- /** Dispatch a trailing frame that had fields but no closing blank line. */
42
- flush() {
43
- if (this.#buffer.length > 0) {
44
- // At end of stream a deferred trailing CR is a real terminator, not data.
45
- const line = this.#buffer.endsWith("\r")
46
- ? this.#buffer.slice(0, -1)
47
- : this.#buffer;
48
- this.#buffer = "";
49
- const frame = this.#consumeLine(line);
50
- if (frame) {
51
- return [frame];
52
- }
53
- }
54
- const frame = this.#dispatch();
55
- return frame ? [frame] : [];
56
- }
57
- /** Locate the next line terminator, deferring a lone trailing `\r` (may be `\r\n`). */
58
- #nextLineEnd() {
59
- for (let i = 0; i < this.#buffer.length; i += 1) {
60
- const char = this.#buffer[i];
61
- if (char === "\n") {
62
- return { index: i, nextIndex: i + 1 };
63
- }
64
- if (char === "\r") {
65
- if (i === this.#buffer.length - 1) {
66
- return null;
67
- }
68
- return this.#buffer[i + 1] === "\n"
69
- ? { index: i, nextIndex: i + 2 }
70
- : { index: i, nextIndex: i + 1 };
71
- }
72
- }
73
- return null;
74
- }
75
- #consumeLine(line) {
76
- if (line.length === 0) {
77
- return this.#dispatch();
78
- }
79
- if (line.startsWith(":")) {
80
- return undefined;
81
- }
82
- const colon = line.indexOf(":");
83
- const field = colon === -1 ? line : line.slice(0, colon);
84
- let value = colon === -1 ? "" : line.slice(colon + 1);
85
- if (value.startsWith(" ")) {
86
- value = value.slice(1);
87
- }
88
- if (field === "data") {
89
- this.#dataLines.push(value);
90
- this.#hasFields = true;
91
- }
92
- else if (field === "event") {
93
- this.#event = value;
94
- this.#hasFields = true;
95
- }
96
- else if (field === "id") {
97
- this.#id = value;
98
- this.#hasFields = true;
99
- }
100
- return undefined;
101
- }
102
- #dispatch() {
103
- if (!this.#hasFields) {
104
- return undefined;
105
- }
106
- const frame = { data: this.#dataLines.join("\n") };
107
- if (this.#event !== undefined) {
108
- frame.event = this.#event;
109
- }
110
- if (this.#id !== undefined) {
111
- frame.id = this.#id;
112
- }
113
- this.#dataLines = [];
114
- this.#event = undefined;
115
- this.#id = undefined;
116
- this.#hasFields = false;
117
- return frame;
118
- }
119
- }
120
- /**
121
- * Iterate the SSE frames of a byte stream. Stops cleanly when the stream ends
122
- * or `signal` aborts (mid-read abort rejections are swallowed once the signal
123
- * is set). Frames with no `data` field (comments, bare `id:`) are not yielded.
124
- * @yields {SseFrame} Each completed frame containing fields.
125
- */
126
- export const readSseFrames = async function* readSseFrames(body, signal) {
127
- const isAborted = () => signal?.aborted === true;
128
- const reader = body.getReader();
129
- const decoder = new TextDecoder();
130
- const sse = new SseDecoder();
131
- try {
132
- for (;;) {
133
- if (isAborted()) {
134
- return;
135
- }
136
- let result;
137
- try {
138
- result = await reader.read();
139
- }
140
- catch (error) {
141
- if (isAborted()) {
142
- return;
143
- }
144
- throw error;
145
- }
146
- if (result.done) {
147
- for (const frame of sse.push(decoder.decode())) {
148
- yield frame;
149
- }
150
- for (const frame of sse.flush()) {
151
- yield frame;
152
- }
153
- return;
154
- }
155
- const text = decoder.decode(result.value, { stream: true });
156
- for (const frame of sse.push(text)) {
157
- if (isAborted()) {
158
- return;
159
- }
160
- yield frame;
161
- }
162
- }
163
- }
164
- finally {
165
- reader.releaseLock();
166
- }
167
- };
@@ -1,54 +0,0 @@
1
- import type { HttpTransport } from "./http-transport.js";
2
- /**
3
- * The workflow Run surface, namespaced as `mg.workflows`. A Run is the start of
4
- * one registered Mastra workflow and nothing else: you name the workflow, hand
5
- * it its input, and follow the Run it returns. Replaces the flat `createRun()`,
6
- * `run()`, `streamRunEvents()` and `drainRunEvents()` methods, retired with no
7
- * shim when `/api/v1/runs` moved under `/api/v1/workflows/{workflowId}/runs`.
8
- *
9
- * THE QUESTION: "do a whole job for me" — the ASYNC lens. Everything else on
10
- * the client answers in one round trip; a Run may suspend for human input and
11
- * finish minutes later. `start()` acknowledges without executing, `run()` polls
12
- * the ledger, and `streamRunEvents()` follows it live.
13
- *
14
- * `workflowId` is the registered workflow's id, such as `edit-collection`. A
15
- * Run is read under the workflow that started it: asking for it under another
16
- * workflow's id is a 404.
17
- *
18
- * Starting a Run needs the `mg:compose` or `mg:write` scope, plus whatever
19
- * scope the workflow itself declares.
20
- */
21
- import type { RunId } from "./identifiers.js";
22
- import type { CreatePublicRunRequest, CreatePublicRunResponse, DrainRunEventsOptions, PublicRunResponse, RunEvent, StreamRunEventsOptions } from "./run-types.js";
23
- export declare class WorkflowsClient {
24
- #private;
25
- constructor(options: {
26
- transport: HttpTransport;
27
- });
28
- /**
29
- * Start an asynchronous Run of `workflowId` (POST
30
- * `/api/v1/workflows/{workflowId}/runs`). Pass `idempotencyKey` so a retry
31
- * replays rather than duplicates. Follow with {@link streamRunEvents} (live)
32
- * or {@link run} (poll).
33
- */
34
- start(workflowId: string, body: CreatePublicRunRequest, signal?: AbortSignal): Promise<CreatePublicRunResponse>;
35
- /**
36
- * THE QUESTION: "where has this Run got to?" — the caller-owned, redacted
37
- * ledger record. Polling; prefer {@link streamRunEvents} when a human is
38
- * waiting.
39
- */
40
- run(workflowId: string, runId: RunId, signal?: AbortSignal): Promise<PublicRunResponse>;
41
- /**
42
- * Stream ordered Run events as an async iterator (GET
43
- * `/api/v1/workflows/{workflowId}/runs/{runId}/events`, SSE). Iterates until
44
- * the stream ends or the signal aborts; pass `after` to resume from the last
45
- * observed sequence.
46
- */
47
- streamRunEvents(workflowId: string, runId: RunId, options?: StreamRunEventsOptions): AsyncGenerator<RunEvent>;
48
- /**
49
- * Collect Run events until a terminal event, the deadline, or the stream
50
- * ends — the bounded events-log pattern (a single pass over
51
- * {@link streamRunEvents}).
52
- */
53
- drainRunEvents(workflowId: string, runId: RunId, options: DrainRunEventsOptions): Promise<RunEvent[]>;
54
- }
@@ -1,41 +0,0 @@
1
- import { drainRunEvents, getWorkflowRun, startWorkflowRun, streamRunEvents, } from "./runs.js";
2
- export class WorkflowsClient {
3
- #transport;
4
- constructor(options) {
5
- this.#transport = options.transport;
6
- }
7
- /**
8
- * Start an asynchronous Run of `workflowId` (POST
9
- * `/api/v1/workflows/{workflowId}/runs`). Pass `idempotencyKey` so a retry
10
- * replays rather than duplicates. Follow with {@link streamRunEvents} (live)
11
- * or {@link run} (poll).
12
- */
13
- async start(workflowId, body, signal) {
14
- return await startWorkflowRun(this.#transport, workflowId, body, signal);
15
- }
16
- /**
17
- * THE QUESTION: "where has this Run got to?" — the caller-owned, redacted
18
- * ledger record. Polling; prefer {@link streamRunEvents} when a human is
19
- * waiting.
20
- */
21
- async run(workflowId, runId, signal) {
22
- return await getWorkflowRun(this.#transport, workflowId, runId, signal);
23
- }
24
- /**
25
- * Stream ordered Run events as an async iterator (GET
26
- * `/api/v1/workflows/{workflowId}/runs/{runId}/events`, SSE). Iterates until
27
- * the stream ends or the signal aborts; pass `after` to resume from the last
28
- * observed sequence.
29
- */
30
- streamRunEvents(workflowId, runId, options) {
31
- return streamRunEvents(this.#transport, workflowId, runId, options);
32
- }
33
- /**
34
- * Collect Run events until a terminal event, the deadline, or the stream
35
- * ends — the bounded events-log pattern (a single pass over
36
- * {@link streamRunEvents}).
37
- */
38
- async drainRunEvents(workflowId, runId, options) {
39
- return await drainRunEvents(this.#transport, workflowId, runId, options);
40
- }
41
- }