@instruments/materialgraph 0.29.0 → 0.31.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 (89) hide show
  1. package/brands-client.d.ts +1 -1
  2. package/by-colour-types.d.ts +4 -4
  3. package/catalogue-client.d.ts +3 -3
  4. package/catalogue-client.js +3 -3
  5. package/catalogue-types.d.ts +1 -1
  6. package/client-vocabulary.d.ts +3 -5
  7. package/client-vocabulary.js +9 -6
  8. package/client.d.ts +85 -174
  9. package/client.js +98 -211
  10. package/colour-region-types.d.ts +18 -0
  11. package/colours-client.d.ts +10 -83
  12. package/colours-client.js +1 -85
  13. package/errors.d.ts +1 -1
  14. package/errors.js +1 -0
  15. package/find-companions-types.d.ts +70 -0
  16. package/find-companions-types.js +12 -0
  17. package/find-variants-by-colour-types.d.ts +197 -0
  18. package/find-variants-by-vector-types.d.ts +67 -0
  19. package/find-variants-by-vector-types.js +5 -0
  20. package/get-variant-types.d.ts +50 -0
  21. package/get-variant-types.js +10 -0
  22. package/http-transport.d.ts +1 -1
  23. package/identifiers.d.ts +1 -1
  24. package/identifiers.js +1 -1
  25. package/image-reference-types.d.ts +18 -0
  26. package/index.d.ts +9 -7
  27. package/index.js +1 -1
  28. package/list-enum-values-types.d.ts +58 -0
  29. package/list-variants-types.d.ts +6 -2
  30. package/material-asset-types.d.ts +2 -2
  31. package/material-types.d.ts +13 -151
  32. package/operations.d.ts +1 -1
  33. package/operations.js +27 -88
  34. package/package.json +1 -1
  35. package/palette-search-types.d.ts +3 -49
  36. package/resolve-colour-types.d.ts +5 -5
  37. package/resolve-variant-types.d.ts +75 -0
  38. package/{identify-types.js → resolve-variant-types.js} +2 -2
  39. package/response-schemas.generated.d.ts +1 -1
  40. package/response-schemas.generated.js +46 -84
  41. package/run-types.d.ts +23 -216
  42. package/runs.d.ts +10 -58
  43. package/runs.js +19 -106
  44. package/schema-resource-types.d.ts +2 -139
  45. package/schema-resource-types.js +0 -8
  46. package/search-card-types.d.ts +1 -1
  47. package/search-index-plan-types.d.ts +6 -2
  48. package/search-request-types.d.ts +10 -2
  49. package/spec-types.d.ts +4 -4
  50. package/spec-types.js +2 -2
  51. package/specifications.d.ts +1 -9
  52. package/specifications.js +0 -12
  53. package/sse.d.ts +2 -2
  54. package/sse.js +2 -2
  55. package/types.d.ts +4 -38
  56. package/validation.d.ts +0 -74
  57. package/validation.js +2 -116
  58. package/webmcp.generated.js +9 -9
  59. package/workflows-client.d.ts +54 -0
  60. package/workflows-client.js +41 -0
  61. package/client-source-material-comments.d.ts +0 -51
  62. package/client-source-material-comments.js +0 -6
  63. package/codes-client.d.ts +0 -118
  64. package/codes-client.js +0 -99
  65. package/codes-types.d.ts +0 -325
  66. package/colour-aggregate-types.d.ts +0 -163
  67. package/coordinate-client.d.ts +0 -23
  68. package/coordinate-client.js +0 -13
  69. package/demand-batch-types.d.ts +0 -118
  70. package/demand-types.d.ts +0 -154
  71. package/identify-types.d.ts +0 -82
  72. package/material-composition-client.d.ts +0 -21
  73. package/material-composition-client.js +0 -13
  74. package/material-composition-types.d.ts +0 -403
  75. package/material-composition-types.js +0 -1
  76. package/source-material-validation.d.ts +0 -7
  77. package/source-material-validation.js +0 -214
  78. package/spec-facet-types.d.ts +0 -48
  79. package/spec-facet-types.js +0 -7
  80. package/substitute-types.d.ts +0 -102
  81. package/substitute-types.js +0 -1
  82. package/suggest-types.d.ts +0 -67
  83. package/suggest-types.js +0 -28
  84. package/taxonomy-coverage-types.d.ts +0 -34
  85. package/taxonomy-coverage-types.js +0 -1
  86. /package/{codes-types.js → colour-region-types.js} +0 -0
  87. /package/{colour-aggregate-types.js → find-variants-by-colour-types.js} +0 -0
  88. /package/{demand-batch-types.js → image-reference-types.js} +0 -0
  89. /package/{demand-types.js → list-enum-values-types.js} +0 -0
package/run-types.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Hand-mirrored wire types for the MaterialGraph public Run + source-material
3
- * surface (spec 0.7.0). Like {@link ./types.ts}, these interfaces carry NO
4
- * runtime dependency on any `@materialgraph/*` package — they mirror the shapes
5
- * in `apps/web/public/openapi.yaml` (`create_public_run`, `get_public_run`,
2
+ * Hand-mirrored wire types for the MaterialGraph workflow Run + source-material
3
+ * surface. Like {@link ./types.ts}, these interfaces carry NO runtime
4
+ * dependency on any `@materialgraph/*` package — they mirror the shapes in
5
+ * `apps/web/public/openapi.yaml` (`create_public_run`, `get_public_run`,
6
6
  * `list_public_run_events`, `upload_source_material`).
7
7
  *
8
8
  * TOLERANT-PARSING CONTRACT: response enums are widened with {@link OpenEnum}
@@ -10,7 +10,7 @@
10
10
  * unknown keys pass through untouched.
11
11
  */
12
12
  import type { BatchId, RunId, SourceFileId } from "./identifiers.js";
13
- import type { JsonValue, OpenEnum } from "./types.js";
13
+ import type { OpenEnum } from "./types.js";
14
14
  /**
15
15
  * A file to upload. Two forms so the SDK is ergonomic on BOTH Node route
16
16
  * handlers and modern runtimes: pass a platform `Blob`/`File` directly, or the
@@ -26,30 +26,14 @@ export type FileInput = Blob | {
26
26
  contentType?: string;
27
27
  };
28
28
  /**
29
- * A heterogeneous pile of source files (multipart field `files`, repeatable):
30
- * any mix of PDF, plain-text/markdown, and images (≥1, ≤16). The server
31
- * classifies each file and assigns its receipt {@link SourceMaterialReceiptFile.role};
32
- * the caller no longer pre-sorts a brief from its references.
29
+ * Input for {@link MaterialGraphClient.uploadSourceMaterial}: a heterogeneous
30
+ * pile of source files (multipart field `files`, repeatable), any mix of PDF,
31
+ * plain-text/markdown, and images (≥1, ≤16). The server classifies each file
32
+ * and assigns its receipt {@link SourceMaterialReceiptFile.role}.
33
33
  */
34
- export type UploadSourceMaterialFilesInput = {
34
+ export type UploadSourceMaterialInput = {
35
35
  files: FileInput[];
36
36
  };
37
- /**
38
- * The legacy pre-classified shape — a single PDF `brief` plus optional image
39
- * `references` (multipart fields `brief` + `references`). Still accepted by the
40
- * server, folded into the pile. Prefer {@link UploadSourceMaterialFilesInput}.
41
- */
42
- export type UploadSourceMaterialLegacyInput = {
43
- /** The single PDF brief for the batch (multipart field `brief`). */
44
- brief: FileInput;
45
- /** Up to 12 reference images (multipart field `references`, repeatable). */
46
- references?: FileInput[];
47
- };
48
- /**
49
- * Input for {@link MaterialGraphClient.uploadSourceMaterial} — either the
50
- * pile-of-files shape or the legacy brief+references shape.
51
- */
52
- export type UploadSourceMaterialInput = UploadSourceMaterialFilesInput | UploadSourceMaterialLegacyInput;
53
37
  /** One stored file in an upload receipt. */
54
38
  export type SourceMaterialReceiptFile = {
55
39
  /** The stored file id (`smf_…`). Opaque — the prefix is a reading aid, not a contract. */
@@ -74,185 +58,6 @@ export type SourceMaterialBatchReceipt = {
74
58
  batchId: BatchId;
75
59
  sources: SourceMaterialReceiptFile[];
76
60
  };
77
- /**
78
- * One analysis computed over an uploaded image's bytes.
79
- *
80
- * Analyses are CONTENT-ADDRESSED: keyed by the file's SHA-256, not by the
81
- * upload or the uploading key. Re-uploading an image someone has already
82
- * analysed therefore returns that analysis immediately, with no work. That
83
- * sharing is by design and discloses nothing — you only ever see analyses of
84
- * images you hold yourself.
85
- */
86
- export type SourceImageAnalysis = {
87
- /** The kind of read. {@link OpenEnum} keeps a newer server value type-checking. */
88
- kind: OpenEnum<"scene_match">;
89
- /** The model version that produced {@link SourceImageAnalysis.result}. */
90
- model: string;
91
- /**
92
- * `failed` analyses are RETURNED, not hidden — so "we looked and it did not
93
- * work" is distinguishable from "nobody has looked yet", which is an empty
94
- * {@link SourceMaterialBatchFile.analyses}.
95
- */
96
- status: OpenEnum<"ok" | "failed">;
97
- /**
98
- * The payload verbatim, or the failure record when `status` is `failed`. For
99
- * `scene_match`: the detected regions with their candidate variant ids and
100
- * scores. The interior shape belongs to the producing model and may gain
101
- * fields, so it is typed as JSON rather than pinned here.
102
- */
103
- result: Record<string, JsonValue>;
104
- /** ISO-8601 timestamp of the most recent analysis. */
105
- analysedAt: string;
106
- };
107
- /** Who a comment is from, as you SUBMIT it. Not the API principal posting it. */
108
- export type SourceMaterialCommentAuthorInput = {
109
- /** Trimmed, 1–160 characters. Longer or blank is refused by the server. */
110
- name: string;
111
- /**
112
- * Their practice or team; `null` for a note carrying no organisation.
113
- * Trimmed, 1–160 characters when present. Nullable, not optional.
114
- */
115
- organisation: string | null;
116
- };
117
- /**
118
- * Who a comment is from, as you READ IT BACK.
119
- *
120
- * `attribution` is the honesty field: nothing verified this name. Render it as
121
- * "recorded as from X", never as a statement X signed — the identity that IS
122
- * verified is {@link SourceMaterialCommentReply.recordedBy}.
123
- */
124
- export type SourceMaterialCommentAuthor = {
125
- /**
126
- * How the name got here. `reported` means a caller typed it. {@link OpenEnum}
127
- * keeps a newer server value type-checking; treat anything unfamiliar as
128
- * unverified.
129
- */
130
- attribution: OpenEnum<"reported">;
131
- } & SourceMaterialCommentAuthorInput;
132
- /** The authenticated principal that recorded a comment. */
133
- export type SourceMaterialCommentRecorder = {
134
- /**
135
- * The principal that wrote the row. Comments can only be posted against a
136
- * batch the poster owns, so on every comment you can read this is your own.
137
- */
138
- principalId: string;
139
- };
140
- /**
141
- * One reply on a source-material file. A reply carries no replies of its own:
142
- * threads are one level deep because the database makes a reply-to-reply
143
- * unstorable, and this type says so rather than implying a tree.
144
- */
145
- export type SourceMaterialCommentReply = {
146
- /** The stored comment id (`smc_…`). Opaque. */
147
- commentId: string;
148
- author: SourceMaterialCommentAuthor;
149
- /** Who recorded it — the audit answer behind the reported name. */
150
- recordedBy: SourceMaterialCommentRecorder;
151
- body: string;
152
- /** ISO-8601 timestamp of the posting. */
153
- createdAt: string;
154
- };
155
- /** One root remark with the replies that answer it. */
156
- export type SourceMaterialComment = {
157
- /** ALWAYS an array. `[]` means nobody answered — never a missing field. */
158
- replies: SourceMaterialCommentReply[];
159
- } & SourceMaterialCommentReply;
160
- /** The `200` body of `GET …/sources/{sourceId}/comments`. */
161
- export type SourceMaterialCommentThread = {
162
- /** The file the thread hangs off (`smf_…`). Opaque. */
163
- sourceId: string;
164
- /**
165
- * The thread, oldest root first. ALWAYS an array; `[]` means the file is
166
- * yours and nobody has commented on it.
167
- */
168
- comments: SourceMaterialComment[];
169
- /**
170
- * `true` when the file holds more comment rows than one read inlines (500),
171
- * so `comments` is the oldest of them rather than all of them.
172
- */
173
- truncated: boolean;
174
- };
175
- /** The body of `POST …/sources/{sourceId}/comments`. */
176
- export type PostSourceMaterialCommentInput = {
177
- author: SourceMaterialCommentAuthorInput;
178
- /** Trimmed, 1–4000 characters. */
179
- body: string;
180
- /**
181
- * The root comment being answered, or absent for a new remark. Must be a ROOT
182
- * comment on the same file: replying to a reply is a 400.
183
- */
184
- parentCommentId?: string | null;
185
- /**
186
- * Your own token for this one intended remark, 1–200 characters. Send it and
187
- * a retry after a network timeout returns the comment you already posted
188
- * rather than a permanent duplicate. Scoped to the file.
189
- */
190
- idempotencyKey?: string | null;
191
- };
192
- /** A comment the server just stored, as a root. */
193
- export type StoredSourceMaterialRootComment = {
194
- kind: "root";
195
- } & SourceMaterialComment;
196
- /** A comment the server just stored, as a reply to a root. */
197
- export type StoredSourceMaterialReplyComment = {
198
- kind: "reply";
199
- /** The root this answers. Present because a reply always has one. */
200
- parentCommentId: string;
201
- } & SourceMaterialCommentReply;
202
- /**
203
- * What a POST returns, discriminated on `kind`. Switch on it: a `root` carries
204
- * an empty `replies`, a `reply` carries `parentCommentId` and no `replies` at
205
- * all, because it can never have any.
206
- */
207
- export type StoredSourceMaterialComment = StoredSourceMaterialRootComment | StoredSourceMaterialReplyComment;
208
- /** The `201` body of `POST …/sources/{sourceId}/comments`. */
209
- export type PostSourceMaterialCommentResult = {
210
- /** The file the comment hangs off (`smf_…`). Opaque. */
211
- sourceId: string;
212
- comment: StoredSourceMaterialComment;
213
- };
214
- /** One file as `GET /api/v1/source-material/{batchId}` returns it. */
215
- export type SourceMaterialBatchFile = {
216
- /** Fetchable URL for the stored bytes. */
217
- url: string;
218
- /**
219
- * ALWAYS an array. `[]` means nothing has been computed yet — never a missing
220
- * field. Preprocessing is triggered manually today; when it becomes automatic
221
- * only the trigger changes and this contract does not.
222
- */
223
- analyses: SourceImageAnalysis[];
224
- /**
225
- * The argument about this file, oldest root first. ALWAYS an array; `[]` means
226
- * nobody has commented, which is a state to draw rather than an absence to
227
- * guess at.
228
- */
229
- comments: SourceMaterialComment[];
230
- /**
231
- * `true` when this file holds more comment rows than one read inlines (500),
232
- * so `comments` is the oldest of them. `false` on a file whose whole thread
233
- * you have, including one nobody has commented on.
234
- */
235
- commentsTruncated: boolean;
236
- } & SourceMaterialReceiptFile;
237
- /**
238
- * The `200` body of `GET /api/v1/source-material/{batchId}` — the batch, every
239
- * file it holds, and the analyses computed over each file's bytes.
240
- */
241
- export type SourceMaterialBatchDetail = {
242
- /** The stored batch id (`smb_…`). Opaque. */
243
- batchId: BatchId;
244
- /** ISO-8601 timestamp of the upload. */
245
- createdAt: string;
246
- sources: SourceMaterialBatchFile[];
247
- };
248
- /**
249
- * Still carried on {@link PublicRun.capabilityKind}, so a Run created before
250
- * MG-2252 reads back as `"agent"`. The rest of the public capability manifest
251
- * shape retired with `GET /api/v1/capabilities`.
252
- */
253
- export type CapabilityKind = OpenEnum<"agent" | "tool" | "workflow">;
254
- /** What `POST /api/v1/runs` admits: never an agent since MG-2252. */
255
- export type CreatableCapabilityKind = "tool" | "workflow";
256
61
  export type PublicRunStatus = OpenEnum<"queued" | "claimed" | "running" | "suspended" | "succeeded" | "failed" | "canceled">;
257
62
  export type PublicRunFailure = {
258
63
  code: string;
@@ -272,8 +77,8 @@ export type PublicRunArtifactRef = {
272
77
  export type PublicRun = {
273
78
  /** Opaque — round-trip verbatim into every other Run call. */
274
79
  id: RunId;
275
- capabilityKind: CapabilityKind;
276
- capabilityId: string;
80
+ /** The workflow this Run belongs to, e.g. `curate-collection`: the id its path names. */
81
+ workflowId: string;
277
82
  clientReference: string | null;
278
83
  /** `suspended` is a QUESTION, not a failure — see `suspensionStepId`. */
279
84
  status: PublicRunStatus;
@@ -300,12 +105,14 @@ export type PublicRun = {
300
105
  createdAt: string;
301
106
  updatedAt: string;
302
107
  };
303
- /** Body for `POST /api/v1/runs` ({@link MaterialGraphClient.createRun}). */
108
+ /**
109
+ * Body for `POST /api/v1/workflows/{workflowId}/runs`
110
+ * ({@link WorkflowsClient.start}). The workflow is named by the path, never the
111
+ * body.
112
+ */
304
113
  export type CreatePublicRunRequest = {
305
- capabilityKind: CreatableCapabilityKind;
306
- capabilityId: string;
307
- /** The capability input, validated server-side against its live input schema. */
308
- inputJson: unknown;
114
+ /** The workflow input, validated server-side against its live input schema. */
115
+ inputJson: Record<string, unknown>;
309
116
  /**
310
117
  * Stable caller key making Run creation idempotent across retries. Supply it:
311
118
  * without one, a retried POST starts a SECOND Run rather than replaying the
@@ -315,14 +122,14 @@ export type CreatePublicRunRequest = {
315
122
  /** Free-form caller correlation reference, echoed back on the Run. */
316
123
  clientReference?: string;
317
124
  };
318
- /** The `POST /api/v1/runs` response (`200` replay or `202` accepted). */
125
+ /** The start response (`200` replay or `202` accepted). */
319
126
  export type CreatePublicRunResponse = {
320
127
  accepted: boolean;
321
128
  replayed: boolean;
322
129
  workflowRunId: string;
323
130
  run: PublicRun;
324
131
  };
325
- /** The `GET /api/v1/runs/{runId}` response envelope. */
132
+ /** The `GET /api/v1/workflows/{workflowId}/runs/{runId}` response envelope. */
326
133
  export type PublicRunResponse = {
327
134
  run: PublicRun;
328
135
  };
@@ -338,14 +145,14 @@ export type RunEvent = {
338
145
  };
339
146
  /** Run event types that close the stream — a terminal event ends a drain. */
340
147
  export declare const TERMINAL_RUN_EVENT_TYPES: ReadonlySet<string>;
341
- /** Options for {@link MaterialGraphClient.streamRunEvents}. */
148
+ /** Options for {@link WorkflowsClient.streamRunEvents}. */
342
149
  export type StreamRunEventsOptions = {
343
150
  /** Resume the stream after this sequence (exclusive). Omitted starts at 0. */
344
151
  after?: number;
345
152
  /** Abort the stream; iteration stops cleanly. */
346
153
  signal?: AbortSignal;
347
154
  };
348
- /** Options for {@link MaterialGraphClient.drainRunEvents}. */
155
+ /** Options for {@link WorkflowsClient.drainRunEvents}. */
349
156
  export type DrainRunEventsOptions = {
350
157
  /** Resume after this sequence (exclusive). */
351
158
  after?: number;
package/runs.d.ts CHANGED
@@ -1,70 +1,22 @@
1
1
  import type { HttpTransport } from "./http-transport.js";
2
- import type { CreatePublicRunRequest, CreatePublicRunResponse, DrainRunEventsOptions, PostSourceMaterialCommentInput, PostSourceMaterialCommentResult, PublicRunResponse, RunEvent, SourceMaterialBatchDetail, SourceMaterialBatchReceipt, SourceMaterialCommentThread, StreamRunEventsOptions, UploadSourceMaterialInput } from "./run-types.js";
2
+ import type { CreatePublicRunRequest, CreatePublicRunResponse, DrainRunEventsOptions, PublicRunResponse, RunEvent, SourceMaterialBatchReceipt, StreamRunEventsOptions, UploadSourceMaterialInput } from "./run-types.js";
3
3
  /**
4
4
  * Upload one atomic source-material batch (`POST /api/v1/source-material`).
5
- * Accepts the pile-of-files shape (`{ files }` → repeatable `files` field) or
6
- * the legacy `{ brief, references }` shape (→ `brief` + repeatable `references`
7
- * fields). Both wire to multipart the server accepts.
5
+ * Each entry of `{ files }` becomes one part of the repeatable multipart
6
+ * `files` field.
8
7
  */
9
8
  export declare const uploadSourceMaterial: (transport: HttpTransport, input: UploadSourceMaterialInput, signal?: AbortSignal) => Promise<SourceMaterialBatchReceipt>;
10
- /**
11
- * Read back one uploaded batch (`GET /api/v1/source-material/{batchId}`): every
12
- * file with a fetchable `url`, and every analysis computed over its bytes
13
- * inlined as `analyses` — always an array, `[]` when nothing has been computed.
14
- *
15
- * A batch you do not own is indistinguishable from one that does not exist:
16
- * both raise a 404, never a 403, so batch ids cannot be probed for existence.
17
- *
18
- * The body is VALIDATED, not trusted: `checkSourceMaterialBatchDetail` mirrors
19
- * the server's Zod contract so a malformed response fails here with a path into
20
- * the payload rather than as an undefined three frames away in caller code.
21
- */
22
- export declare const getSourceMaterialBatch: (transport: HttpTransport, batchId: string, signal?: AbortSignal) => Promise<SourceMaterialBatchDetail>;
23
- /**
24
- * Read one file's comment thread
25
- * (`GET /api/v1/source-material/{batchId}/sources/{sourceId}/comments`).
26
- *
27
- * The remarks people left on one uploaded file, oldest root first, each root
28
- * carrying the replies that answer it. `comments` is always an array — `[]`
29
- * means the file is yours and nobody has said anything about it.
30
- *
31
- * Author names are REPORTED, never verified: each carries
32
- * `author.attribution: "reported"` plus the principal that recorded it in
33
- * `recordedBy`. Render "recorded as from X", not "X said".
34
- *
35
- * `truncated` is `true` when the file holds more rows than one read inlines.
36
- *
37
- * A file that is not in that batch, or a batch you do not own, raises the same
38
- * 404 as a file that never existed.
39
- */
40
- export declare const listSourceMaterialComments: (transport: HttpTransport, batchId: string, sourceId: string, signal?: AbortSignal) => Promise<SourceMaterialCommentThread>;
41
- /**
42
- * Add one remark to a file's thread
43
- * (`POST /api/v1/source-material/{batchId}/sources/{sourceId}/comments`).
44
- *
45
- * `author` is who the comment is FROM — usually the client or a colleague, not
46
- * the key posting it — so it is stored and read back as reported attribution.
47
- * Pass `parentCommentId` to answer a ROOT comment on the same file; anything
48
- * deeper is a 400, because threads are one level deep.
49
- *
50
- * Pass `idempotencyKey` and a retry after a network timeout returns the comment
51
- * you already posted rather than a permanent duplicate.
52
- *
53
- * The result is discriminated on `kind`: switch on it rather than reaching for
54
- * `replies`, which a `reply` does not have.
55
- */
56
- export declare const postSourceMaterialComment: (transport: HttpTransport, batchId: string, sourceId: string, input: PostSourceMaterialCommentInput, signal?: AbortSignal) => Promise<PostSourceMaterialCommentResult>;
57
- /** Start an asynchronous capability Run (`POST /api/v1/runs`). */
58
- export declare const createRun: (transport: HttpTransport, body: CreatePublicRunRequest, signal?: AbortSignal) => Promise<CreatePublicRunResponse>;
59
- /** Get a Run's current state (`GET /api/v1/runs/{runId}`). */
60
- export declare const getRun: (transport: HttpTransport, runId: string, signal?: AbortSignal) => Promise<PublicRunResponse>;
9
+ /** Start an asynchronous Run of one workflow (`POST /api/v1/workflows/{workflowId}/runs`). */
10
+ export declare const startWorkflowRun: (transport: HttpTransport, workflowId: string, body: CreatePublicRunRequest, signal?: AbortSignal) => Promise<CreatePublicRunResponse>;
11
+ /** Get a Run's current state (`GET /api/v1/workflows/{workflowId}/runs/{runId}`). */
12
+ export declare const getWorkflowRun: (transport: HttpTransport, workflowId: string, runId: string, signal?: AbortSignal) => Promise<PublicRunResponse>;
61
13
  /**
62
14
  * Stream ordered Run events as an async iterator (`GET
63
- * /api/v1/runs/{runId}/events`, SSE). Iterates until the stream ends or
15
+ * /api/v1/workflows/{workflowId}/runs/{runId}/events`, SSE). Iterates until the stream ends or
64
16
  * `signal` aborts. One connection is bounded server-side (~25s or a terminal
65
17
  * event); pass `after` to resume from the last observed sequence.
66
18
  */
67
- export declare function streamRunEvents(transport: HttpTransport, runId: string, options?: StreamRunEventsOptions): AsyncGenerator<RunEvent, void, unknown>;
19
+ export declare function streamRunEvents(transport: HttpTransport, workflowId: string, runId: string, options?: StreamRunEventsOptions): AsyncGenerator<RunEvent, void, unknown>;
68
20
  /**
69
21
  * Collect Run events until a terminal event, the deadline, or the stream ends —
70
22
  * the bounded events-log pattern the console uses. A single pass over
@@ -80,4 +32,4 @@ export declare function streamRunEvents(transport: HttpTransport, runId: string,
80
32
  * failure (a real 4xx/5xx or transport error) still propagates, keeping the
81
33
  * fail-fast surface for genuine upstream problems.
82
34
  */
83
- export declare const drainRunEvents: (transport: HttpTransport, runId: string, options: DrainRunEventsOptions) => Promise<RunEvent[]>;
35
+ export declare const drainRunEvents: (transport: HttpTransport, workflowId: string, runId: string, options: DrainRunEventsOptions) => Promise<RunEvent[]>;
package/runs.js CHANGED
@@ -1,13 +1,13 @@
1
1
  /**
2
- * The Run + source-material namespace — the agentic half of the SDK. These
2
+ * The workflow Run + source-material calls — the agentic half of the SDK. These
3
3
  * functions take the shared {@link HttpTransport} and speak the hosted Run
4
- * lifecycle: upload source material, create/read Runs, and stream (or drain)
5
- * their events. Box's proxy routes are thin wrappers over exactly these calls.
4
+ * lifecycle: upload source material, start and read a workflow's Runs, and
5
+ * stream (or drain) their events. `mg.workflows` and `uploadSourceMaterial`
6
+ * are thin wrappers over exactly these calls.
6
7
  */
7
8
  import { MaterialGraphError } from "./errors.js";
8
9
  import { findSdkOperation, operationPath } from "./operations.js";
9
10
  import { TERMINAL_RUN_EVENT_TYPES } from "./run-types.js";
10
- import { checkPostSourceMaterialCommentResult, checkSourceMaterialBatchDetail, checkSourceMaterialCommentThread, } from "./source-material-validation.js";
11
11
  import { readSseFrames } from "./sse.js";
12
12
  const runOperation = (operationId) => {
13
13
  const match = findSdkOperation(operationId);
@@ -43,22 +43,13 @@ const appendFile = (form, field, input) => {
43
43
  };
44
44
  /**
45
45
  * Upload one atomic source-material batch (`POST /api/v1/source-material`).
46
- * Accepts the pile-of-files shape (`{ files }` → repeatable `files` field) or
47
- * the legacy `{ brief, references }` shape (→ `brief` + repeatable `references`
48
- * fields). Both wire to multipart the server accepts.
46
+ * Each entry of `{ files }` becomes one part of the repeatable multipart
47
+ * `files` field.
49
48
  */
50
49
  export const uploadSourceMaterial = async (transport, input, signal) => {
51
50
  const form = new FormData();
52
- if ("files" in input) {
53
- for (const file of input.files) {
54
- appendFile(form, "files", file);
55
- }
56
- }
57
- else {
58
- appendFile(form, "brief", input.brief);
59
- for (const reference of input.references ?? []) {
60
- appendFile(form, "references", reference);
61
- }
51
+ for (const file of input.files) {
52
+ appendFile(form, "files", file);
62
53
  }
63
54
  const url = transport.buildUrl(operationPath(runOperation("upload_source_material")));
64
55
  // No Content-Type header: fetch sets multipart/form-data with the boundary.
@@ -71,93 +62,15 @@ export const uploadSourceMaterial = async (transport, input, signal) => {
71
62
  });
72
63
  return parsed;
73
64
  };
74
- /**
75
- * Read back one uploaded batch (`GET /api/v1/source-material/{batchId}`): every
76
- * file with a fetchable `url`, and every analysis computed over its bytes
77
- * inlined as `analyses` — always an array, `[]` when nothing has been computed.
78
- *
79
- * A batch you do not own is indistinguishable from one that does not exist:
80
- * both raise a 404, never a 403, so batch ids cannot be probed for existence.
81
- *
82
- * The body is VALIDATED, not trusted: `checkSourceMaterialBatchDetail` mirrors
83
- * the server's Zod contract so a malformed response fails here with a path into
84
- * the payload rather than as an undefined three frames away in caller code.
85
- */
86
- export const getSourceMaterialBatch = async (transport, batchId, signal) => {
87
- const body = await transport.requestJson(runOperation("get_source_material_batch"), {
88
- pathParams: { batchId },
89
- signal,
90
- });
91
- return checkSourceMaterialBatchDetail(body, batchId);
92
- };
93
- /**
94
- * Read one file's comment thread
95
- * (`GET /api/v1/source-material/{batchId}/sources/{sourceId}/comments`).
96
- *
97
- * The remarks people left on one uploaded file, oldest root first, each root
98
- * carrying the replies that answer it. `comments` is always an array — `[]`
99
- * means the file is yours and nobody has said anything about it.
100
- *
101
- * Author names are REPORTED, never verified: each carries
102
- * `author.attribution: "reported"` plus the principal that recorded it in
103
- * `recordedBy`. Render "recorded as from X", not "X said".
104
- *
105
- * `truncated` is `true` when the file holds more rows than one read inlines.
106
- *
107
- * A file that is not in that batch, or a batch you do not own, raises the same
108
- * 404 as a file that never existed.
109
- */
110
- export const listSourceMaterialComments = async (transport, batchId, sourceId, signal) => {
111
- const body = await transport.requestJson(runOperation("list_source_material_comments"), {
112
- pathParams: { batchId, sourceId },
113
- signal,
114
- });
115
- return checkSourceMaterialCommentThread(body, sourceId);
116
- };
117
- /**
118
- * Add one remark to a file's thread
119
- * (`POST /api/v1/source-material/{batchId}/sources/{sourceId}/comments`).
120
- *
121
- * `author` is who the comment is FROM — usually the client or a colleague, not
122
- * the key posting it — so it is stored and read back as reported attribution.
123
- * Pass `parentCommentId` to answer a ROOT comment on the same file; anything
124
- * deeper is a 400, because threads are one level deep.
125
- *
126
- * Pass `idempotencyKey` and a retry after a network timeout returns the comment
127
- * you already posted rather than a permanent duplicate.
128
- *
129
- * The result is discriminated on `kind`: switch on it rather than reaching for
130
- * `replies`, which a `reply` does not have.
131
- */
132
- export const postSourceMaterialComment = async (transport, batchId, sourceId, input, signal) => {
133
- const body = await transport.requestJson(runOperation("post_source_material_comment"), {
134
- // Built key by key rather than spread: `parentCommentId` and
135
- // `idempotencyKey` are forwarded only when PRESENT, so a caller that
136
- // omits them sends a body byte-identical to one that never knew about
137
- // them.
138
- body: {
139
- author: input.author,
140
- body: input.body,
141
- ...(input.parentCommentId === undefined
142
- ? {}
143
- : { parentCommentId: input.parentCommentId }),
144
- ...(input.idempotencyKey === undefined
145
- ? {}
146
- : { idempotencyKey: input.idempotencyKey }),
147
- },
148
- pathParams: { batchId, sourceId },
149
- signal,
150
- });
151
- return checkPostSourceMaterialCommentResult(body, sourceId);
152
- };
153
- /** Start an asynchronous capability Run (`POST /api/v1/runs`). */
154
- export const createRun = async (transport, body, signal) => await transport.requestJson(runOperation("create_public_run"), {
65
+ /** Start an asynchronous Run of one workflow (`POST /api/v1/workflows/{workflowId}/runs`). */
66
+ export const startWorkflowRun = async (transport, workflowId, body, signal) => await transport.requestJson(runOperation("create_public_run"), {
155
67
  body,
68
+ pathParams: { workflowId },
156
69
  signal,
157
70
  });
158
- /** Get a Run's current state (`GET /api/v1/runs/{runId}`). */
159
- export const getRun = async (transport, runId, signal) => await transport.requestJson(runOperation("get_public_run"), {
160
- pathParams: { runId },
71
+ /** Get a Run's current state (`GET /api/v1/workflows/{workflowId}/runs/{runId}`). */
72
+ export const getWorkflowRun = async (transport, workflowId, runId, signal) => await transport.requestJson(runOperation("get_public_run"), {
73
+ pathParams: { runId, workflowId },
161
74
  signal,
162
75
  });
163
76
  /** Decode one SSE `data:` frame into a {@link RunEvent}, or `null` when unusable. */
@@ -183,13 +96,13 @@ const decodeRunEvent = (data) => {
183
96
  };
184
97
  /**
185
98
  * Stream ordered Run events as an async iterator (`GET
186
- * /api/v1/runs/{runId}/events`, SSE). Iterates until the stream ends or
99
+ * /api/v1/workflows/{workflowId}/runs/{runId}/events`, SSE). Iterates until the stream ends or
187
100
  * `signal` aborts. One connection is bounded server-side (~25s or a terminal
188
101
  * event); pass `after` to resume from the last observed sequence.
189
102
  */
190
- export async function* streamRunEvents(transport, runId, options = {}) {
103
+ export async function* streamRunEvents(transport, workflowId, runId, options = {}) {
191
104
  const body = await transport.openStream(runOperation("list_public_run_events"), {
192
- pathParams: { runId },
105
+ pathParams: { runId, workflowId },
193
106
  ...(options.after === undefined
194
107
  ? {}
195
108
  : { query: { after: options.after } }),
@@ -219,14 +132,14 @@ export async function* streamRunEvents(transport, runId, options = {}) {
219
132
  * failure (a real 4xx/5xx or transport error) still propagates, keeping the
220
133
  * fail-fast surface for genuine upstream problems.
221
134
  */
222
- export const drainRunEvents = async (transport, runId, options) => {
135
+ export const drainRunEvents = async (transport, workflowId, runId, options) => {
223
136
  const collected = [];
224
137
  const controller = new AbortController();
225
138
  const timer = setTimeout(() => {
226
139
  controller.abort();
227
140
  }, options.deadlineMs);
228
141
  try {
229
- for await (const event of streamRunEvents(transport, runId, {
142
+ for await (const event of streamRunEvents(transport, workflowId, runId, {
230
143
  after: options.after,
231
144
  signal: controller.signal,
232
145
  })) {