@withpica/mcp-sdk 3.5.0 → 3.7.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.
package/dist/index.js CHANGED
@@ -203,6 +203,37 @@ class BaseResource {
203
203
  }
204
204
  return (data.data || data);
205
205
  }
206
+ /**
207
+ * Like `request`, but returns the FULL parsed envelope instead of
208
+ * narrowing to `.data`. Needed by the two spreadsheet-moment auto-twin
209
+ * routes (`POST /admin/works`, `POST /admin/recordings`), whose response
210
+ * carries `twin`/`twin_error` as siblings of `data` — `request()`'s
211
+ * `return data.data || data` would otherwise silently drop them before
212
+ * the MCP tool ever sees a twin was created.
213
+ */
214
+ async requestWithEnvelope(method, path, body) {
215
+ const url = `${this.baseUrl}${path}`;
216
+ const timeoutMs = getTimeoutForPath(path);
217
+ if (this.debug) {
218
+ console.error(`[PICA SDK] ${method} ${url} (timeout: ${timeoutMs}ms)`);
219
+ }
220
+ const response = await this.fetchWithRetry(url, {
221
+ method,
222
+ headers: {
223
+ Authorization: `Bearer ${this.apiKey}`,
224
+ "Content-Type": "application/json",
225
+ ...this.getBypassHeaders(),
226
+ },
227
+ body: body ? JSON.stringify(body) : undefined,
228
+ }, timeoutMs);
229
+ const json = await response.json();
230
+ // Same success:false guard as `request()` — see its comment above.
231
+ if (json && typeof json === "object" && json.success === false) {
232
+ const msg = typeof json.error === "string" ? json.error : "unspecified error";
233
+ throw new ApiError(`API returned success:false: ${msg}`, response.status, false);
234
+ }
235
+ return json;
236
+ }
206
237
  /**
207
238
  * Make a request whose SUCCESS body is raw text, not a JSON envelope —
208
239
  * for routes that stream a generated file (e.g. `text/csv`) rather than
@@ -353,7 +384,19 @@ class WorksResource extends BaseResource {
353
384
  return this.request("GET", `/admin/works/${id}`);
354
385
  }
355
386
  async create(data) {
356
- return this.request("POST", "/admin/works", data);
387
+ // Spreadsheet-moment auto-twin — the route response carries `twin` /
388
+ // `twin_error` as siblings of `data`, which the plain `request()`
389
+ // helper would drop (it narrows to `.data`). Fetch the full envelope
390
+ // and merge the twin fields onto the returned Work so callers (and the
391
+ // MCP tool executor) can see them.
392
+ const envelope = await this.requestWithEnvelope("POST", "/admin/works", data);
393
+ return {
394
+ ...envelope.data,
395
+ twin: envelope.twin ?? null,
396
+ ...(envelope.twin_error !== undefined && {
397
+ twin_error: envelope.twin_error,
398
+ }),
399
+ };
357
400
  }
358
401
  async update(id, updates) {
359
402
  return this.request("PATCH", `/admin/works/${id}`, updates);
@@ -392,6 +435,18 @@ class WorksResource extends BaseResource {
392
435
  const result = await this.request("GET", `/admin/works/${workId}/releases`);
393
436
  return result?.data || [];
394
437
  }
438
+ /**
439
+ * Assemble the full song dossier for one work — everything PICA holds about
440
+ * a song in one call (work, recordings, releases, composition credits,
441
+ * people, provenance, AI disclosure, consent). Backs the `dossier` section
442
+ * of pica_works_inspect. JSON format only here; the PDF export lives on the
443
+ * web UI (`GET /admin/works/[id]/dossier?format=pdf`).
444
+ *
445
+ * `request()` unwraps the `{ success, data }` envelope to the dossier itself.
446
+ */
447
+ async dossier(workId) {
448
+ return this.request("GET", `/admin/works/${workId}/dossier?format=json`);
449
+ }
395
450
  /**
396
451
  * Stamp a human-creation provenance attestation. Complement to the
397
452
  * AI-disclosure side — captures who signed, when, the attestation
@@ -704,6 +759,37 @@ class PicaScoreResource extends BaseResource {
704
759
  return this.request("GET", "/admin/pica-score");
705
760
  }
706
761
  }
762
+ class IntegrityResource extends BaseResource {
763
+ /**
764
+ * GET /admin/integrity/assess?entity_type=&entity_id= -> single-entity assessment.
765
+ * NOTE: for entity_type "release" this is a documented v1 no-op — no
766
+ * release-grain gap code exists yet, so `gaps` is always empty by design
767
+ * (see assessEntity's release branch in lib/services/integrity-floor.ts).
768
+ */
769
+ async assessEntity(entityType, entityId) {
770
+ const qp = new URLSearchParams({
771
+ entity_type: entityType,
772
+ entity_id: entityId,
773
+ });
774
+ return this.request("GET", `/admin/integrity/assess?${qp.toString()}`);
775
+ }
776
+ /** GET /admin/integrity/assess (no params) -> org-grain summary. */
777
+ async assessOrg() {
778
+ return this.request("GET", "/admin/integrity/assess");
779
+ }
780
+ /**
781
+ * POST /admin/integrity/waivers. Duplicate-active-waiver is a 409
782
+ * (`ConflictError` on the app side) — surfaces here as a non-retryable
783
+ * `ApiError` with `status === 409` (see `BaseResource.request`).
784
+ */
785
+ async waive(input) {
786
+ return this.request("POST", "/admin/integrity/waivers", input);
787
+ }
788
+ /** PATCH /admin/integrity/waivers { waiver_id, revoke: true }. No un-revoke path. */
789
+ async revokeWaiver(waiverId) {
790
+ await this.request("PATCH", "/admin/integrity/waivers", { waiver_id: waiverId, revoke: true });
791
+ }
792
+ }
707
793
  class AudioFilesResource extends BaseResource {
708
794
  async list(params) {
709
795
  const queryParams = new URLSearchParams();
@@ -1119,7 +1205,18 @@ class RecordingsResource extends BaseResource {
1119
1205
  return this.request("GET", `/admin/recordings/${id}`);
1120
1206
  }
1121
1207
  async create(data) {
1122
- return this.request("POST", "/admin/recordings", data);
1208
+ // Spreadsheet-moment auto-twin — mirrors WorksResource.create above:
1209
+ // fetch the full envelope so `twin`/`twin_error` survive onto the
1210
+ // returned Recording instead of being dropped by `request()`'s
1211
+ // `.data`-only narrowing.
1212
+ const envelope = await this.requestWithEnvelope("POST", "/admin/recordings", data);
1213
+ return {
1214
+ ...envelope.data,
1215
+ twin: envelope.twin ?? null,
1216
+ ...(envelope.twin_error !== undefined && {
1217
+ twin_error: envelope.twin_error,
1218
+ }),
1219
+ };
1123
1220
  }
1124
1221
  async update(id, updates) {
1125
1222
  return this.request("PATCH", `/admin/recordings/${id}`, updates);
@@ -3623,6 +3720,8 @@ export class PicaClient {
3623
3720
  shareSend;
3624
3721
  accessSimulate;
3625
3722
  approvals;
3723
+ // Registration Integrity Floor (spec 2026-07-09, Task 8).
3724
+ integrity;
3626
3725
  async catalogStats(params) {
3627
3726
  const baseUrl = this.works["baseUrl"];
3628
3727
  const apiKey = this.works["apiKey"];
@@ -3731,6 +3830,7 @@ export class PicaClient {
3731
3830
  this.shareSend = new ShareSendResource(baseUrl, config.apiKey, debug);
3732
3831
  this.accessSimulate = new AccessSimulateResource(baseUrl, config.apiKey, debug);
3733
3832
  this.approvals = new ApprovalsResource(baseUrl, config.apiKey, debug);
3833
+ this.integrity = new IntegrityResource(baseUrl, config.apiKey, debug);
3734
3834
  }
3735
3835
  }
3736
3836
  //# sourceMappingURL=index.js.map