@andpipes/cli 0.1.4 → 0.1.5

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/bin.cjs CHANGED
@@ -467,6 +467,26 @@ var ConfirmationRequiredError = class extends Error {
467
467
  }
468
468
  };
469
469
 
470
+ // src/lib/publication-review-profile.ts
471
+ var CLI_PUBLICATION_REVIEW_PROFILE = 2;
472
+ var PUBLICATION_ERROR_REASON_CODES = Object.freeze({
473
+ publication_plan_stale: "AP_CONFLICT",
474
+ publication_review_profile_invalid: "AP_INPUT_INVALID",
475
+ publication_schema_review_too_large: "AP_INPUT_INVALID",
476
+ schema_review_receipt_mismatch: "AP_CONFLICT"
477
+ });
478
+ function isPublicationErrorReasonFor(code, reason) {
479
+ return typeof reason === "string" && Object.hasOwn(PUBLICATION_ERROR_REASON_CODES, reason) && PUBLICATION_ERROR_REASON_CODES[reason] === code;
480
+ }
481
+ function parsePublicationErrorReason(status, code, details) {
482
+ if (status < 400 || status > 499) return void 0;
483
+ if (details === null || typeof details !== "object" || Array.isArray(details)) return void 0;
484
+ const record = details;
485
+ const keys = Object.keys(record);
486
+ if (keys.length !== 1 || keys[0] !== "reason") return void 0;
487
+ return isPublicationErrorReasonFor(code, record.reason) ? record.reason : void 0;
488
+ }
489
+
470
490
  // src/lib/backend.ts
471
491
  var ADMIN_API_ORIGIN = "https://api.andpipe.com";
472
492
  var ADMIN_API_TIMEOUT_MS = 1e4;
@@ -496,6 +516,7 @@ var AdminApiClientError = class extends Error {
496
516
  detailsAbsent;
497
517
  scopeRegistrationReason;
498
518
  publishGateToolNames;
519
+ publicationReason;
499
520
  constructor(code, message, status, confirmationRequired, openApiAuthModeMismatch, safeDetails = {}) {
500
521
  super(message);
501
522
  this.name = "AdminApiClientError";
@@ -506,6 +527,7 @@ var AdminApiClientError = class extends Error {
506
527
  this.detailsAbsent = safeDetails.detailsAbsent === true;
507
528
  this.scopeRegistrationReason = safeDetails.scopeRegistrationReason;
508
529
  this.publishGateToolNames = safeDetails.publishGateToolNames === void 0 ? void 0 : Object.freeze([...safeDetails.publishGateToolNames]);
530
+ this.publicationReason = safeDetails.publicationReason;
509
531
  }
510
532
  };
511
533
  function clientError(code, message, status) {
@@ -720,7 +742,8 @@ function withKnownResponseStatus(error, responseStatus) {
720
742
  {
721
743
  detailsAbsent: error.detailsAbsent,
722
744
  ...error.scopeRegistrationReason === void 0 ? {} : { scopeRegistrationReason: error.scopeRegistrationReason },
723
- ...error.publishGateToolNames === void 0 ? {} : { publishGateToolNames: error.publishGateToolNames }
745
+ ...error.publishGateToolNames === void 0 ? {} : { publishGateToolNames: error.publishGateToolNames },
746
+ ...error.publicationReason === void 0 ? {} : { publicationReason: error.publicationReason }
724
747
  }
725
748
  );
726
749
  }
@@ -789,6 +812,7 @@ function safeApiError(status, value) {
789
812
  const code = typeof candidate === "string" && SAFE_AP_CODE_RE.test(candidate) ? candidate : "AP_HTTP_ERROR";
790
813
  const confirmationRequired = code === "AP_CONFIRMATION_REQUIRED" && status === 409 ? parsePublicationConfirmationRequiredDetails(errorRecord?.details) : void 0;
791
814
  const openApiAuthModeMismatch = code === "AP_CONFLICT" && status === 409 ? parseOpenApiImportAuthModeMismatch(errorRecord?.details) : void 0;
815
+ const publicationReason = parsePublicationErrorReason(status, code, errorRecord?.details);
792
816
  return new AdminApiClientError(
793
817
  code,
794
818
  `Admin API request failed (${code}; HTTP ${status})`,
@@ -798,7 +822,8 @@ function safeApiError(status, value) {
798
822
  {
799
823
  // AP error envelopeを受け取れた場合だけ「detailsなし」を判定できる。
800
824
  detailsAbsent: errorRecord !== void 0 && (errorRecord.details === null || errorRecord.details === void 0),
801
- ...parseScopeRegistrationErrorDetails(status, errorRecord?.details)
825
+ ...parseScopeRegistrationErrorDetails(status, errorRecord?.details),
826
+ ...publicationReason === void 0 ? {} : { publicationReason }
802
827
  }
803
828
  );
804
829
  }
@@ -932,6 +957,13 @@ function publicationPlanBody(input) {
932
957
  ...input.templateProvenance === void 0 ? {} : { templateProvenance: input.templateProvenance }
933
958
  };
934
959
  }
960
+ function publicationReviewProfileOption(options) {
961
+ if (options === void 0) return void 0;
962
+ if (options === null || typeof options !== "object" || Object.keys(options).join(",") !== "reviewProfile" || options.reviewProfile !== 2) {
963
+ throw clientError("AP_INPUT_INVALID", "tool publication review profile option is invalid");
964
+ }
965
+ return options.reviewProfile;
966
+ }
935
967
  function publicationApplyBody(input) {
936
968
  const common = publicationPlanBody(input);
937
969
  if (!import_tool_contract.PUBLICATION_SHA256_COMMITMENT_RE.test(input.planCommitment)) {
@@ -1287,6 +1319,10 @@ var AdminApiClient = class {
1287
1319
  this.#sleep = options.sleep ?? ((milliseconds) => new Promise((resolve7) => setTimeout(resolve7, milliseconds)));
1288
1320
  }
1289
1321
  async #request(path, options = {}) {
1322
+ return (await this.#requestWithHeaders(path, options)).value;
1323
+ }
1324
+ /** 2xx bodyと、そのresponse headerを返す。headerはcommand層が必要な値だけを読む。 */
1325
+ async #requestWithHeaders(path, options = {}) {
1290
1326
  const url = buildUrl(path);
1291
1327
  const method = options.method ?? "GET";
1292
1328
  const attempts = method === "GET" ? ADMIN_API_MAX_GET_ATTEMPTS : 1;
@@ -1308,6 +1344,9 @@ var AdminApiClient = class {
1308
1344
  if (options.authenticated !== false) headers.set("Authorization", `Bearer ${this.#token}`);
1309
1345
  if (body !== void 0) headers.set("Content-Type", "application/json");
1310
1346
  if (options.idempotencyKey) headers.set("Idempotency-Key", options.idempotencyKey);
1347
+ if (options.reviewProfile !== void 0) {
1348
+ headers.set(import_tool_contract.PUBLICATION_REVIEW_PROFILE_HEADER, String(options.reviewProfile));
1349
+ }
1311
1350
  response = await this.#fetch(url, {
1312
1351
  method,
1313
1352
  headers,
@@ -1364,8 +1403,8 @@ var AdminApiClient = class {
1364
1403
  }
1365
1404
  throw safeApiError(response.status, errorBody);
1366
1405
  }
1367
- if (options.responseType === "text") return text;
1368
- return parseJson(text);
1406
+ if (options.responseType === "text") return { value: text, headers: response.headers };
1407
+ return { value: parseJson(text), headers: response.headers };
1369
1408
  }
1370
1409
  throw clientError("AP_NETWORK_ERROR", "Admin API request failed");
1371
1410
  }
@@ -1511,24 +1550,41 @@ var AdminApiClient = class {
1511
1550
  status: connector.status
1512
1551
  };
1513
1552
  }
1514
- async planPublication(projectId, body) {
1515
- return this.#request(`/v1/projects/${assertProjectId(projectId)}/tool-publications:plan`, {
1516
- method: "POST",
1517
- body: publicationPlanBody(body),
1518
- maxRequestBytes: ADMIN_API_PUBLICATION_REQUEST_MAX_BYTES,
1519
- maxResponseBytes: ADMIN_API_PUBLICATION_RESPONSE_MAX_BYTES
1520
- });
1553
+ async planPublication(projectId, body, options) {
1554
+ const reviewProfile = publicationReviewProfileOption(options);
1555
+ const response = await this.#requestWithHeaders(
1556
+ `/v1/projects/${assertProjectId(projectId)}/tool-publications:plan`,
1557
+ {
1558
+ method: "POST",
1559
+ body: publicationPlanBody(body),
1560
+ maxRequestBytes: ADMIN_API_PUBLICATION_REQUEST_MAX_BYTES,
1561
+ maxResponseBytes: ADMIN_API_PUBLICATION_RESPONSE_MAX_BYTES,
1562
+ ...reviewProfile === void 0 ? {} : { reviewProfile }
1563
+ }
1564
+ );
1565
+ if (reviewProfile === void 0) return response.value;
1566
+ const planResponse = {
1567
+ body: response.value,
1568
+ reviewProfileHeader: response.headers.get(import_tool_contract.PUBLICATION_REVIEW_PROFILE_HEADER)
1569
+ };
1570
+ return planResponse;
1521
1571
  }
1522
- async applyPublication(projectId, idempotencyKey, body) {
1572
+ /**
1573
+ * 初回apply(confirmation=null)と承認済みapply。options付き (#730) だけreview profile headerを送る。
1574
+ * request bodyとIdempotency-Keyはheaderの有無で変えない。
1575
+ */
1576
+ async applyPublication(projectId, idempotencyKey, body, options) {
1523
1577
  if (!/^[A-Za-z0-9._:-]{22,200}$/u.test(idempotencyKey)) {
1524
1578
  throw clientError("AP_INPUT_INVALID", "tool publication Idempotency-Key is invalid");
1525
1579
  }
1580
+ const reviewProfile = publicationReviewProfileOption(options);
1526
1581
  return this.#request(`/v1/projects/${assertProjectId(projectId)}/tool-publications`, {
1527
1582
  method: "POST",
1528
1583
  body: publicationApplyBody(body),
1529
1584
  idempotencyKey,
1530
1585
  maxRequestBytes: ADMIN_API_PUBLICATION_REQUEST_MAX_BYTES,
1531
- maxResponseBytes: ADMIN_API_PUBLICATION_RESPONSE_MAX_BYTES
1586
+ maxResponseBytes: ADMIN_API_PUBLICATION_RESPONSE_MAX_BYTES,
1587
+ ...reviewProfile === void 0 ? {} : { reviewProfile }
1532
1588
  });
1533
1589
  }
1534
1590
  async planOpenApiImport(projectId, input) {
@@ -8362,6 +8418,10 @@ var PUBLICATION_RESPONSE_MAX_BYTES = 96 * 1024;
8362
8418
  var INITIAL_APPLY_MAX_ATTEMPTS = 3;
8363
8419
  var DEFAULT_PUBLISH_MESSAGES = import_localization9.CLI_MESSAGES.ja.publish;
8364
8420
  var DEFAULT_SCOPE_REGISTRATION_MESSAGES2 = import_localization9.OAUTH_SCOPE_REGISTRATION_MESSAGES.ja.cli;
8421
+ var DEFAULT_SCHEMA_REVIEW_MESSAGES = import_localization9.PUBLICATION_SCHEMA_REVIEW_CLI_MESSAGES.ja;
8422
+ var REVIEW_PROFILE_REQUEST = Object.freeze({
8423
+ reviewProfile: CLI_PUBLICATION_REVIEW_PROFILE
8424
+ });
8365
8425
  var PLAN_KEYS = [
8366
8426
  "requestId",
8367
8427
  "environment",
@@ -8521,10 +8581,41 @@ function parseWarnings(value, messages) {
8521
8581
  throw responseInvalid("publication_warnings_invalid", messages);
8522
8582
  }
8523
8583
  }
8524
- function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, messages) {
8584
+ function schemaReviewFailure(code, reason, text, status) {
8585
+ return new PublishCommandError(code, reason, `${text} (${reason})`, status);
8586
+ }
8587
+ function negotiateReviewProfile(response, messages, schemaReviewMessages) {
8588
+ const envelope = asRecord4(response);
8589
+ if (!envelope || !hasExactKeys3(envelope, ["body", "reviewProfileHeader"]) || envelope.reviewProfileHeader !== null && typeof envelope.reviewProfileHeader !== "string") {
8590
+ throw responseInvalid("publication_plan_invalid", messages);
8591
+ }
8592
+ const header = envelope.reviewProfileHeader;
8593
+ if (header !== null && header !== "1" && header !== "2") {
8594
+ throw schemaReviewFailure(
8595
+ "AP_RESPONSE_INVALID",
8596
+ "publication_review_profile_header_invalid",
8597
+ schemaReviewMessages.reviewProfileHeaderInvalid
8598
+ );
8599
+ }
8600
+ const body = asRecord4(envelope.body);
8601
+ const bodyDeclaresProfile = body !== null && Object.hasOwn(body, "reviewProfile");
8602
+ const profile = header === "2" ? 2 : 1;
8603
+ if (profile === 2 ? !bodyDeclaresProfile || body?.reviewProfile !== 2 : bodyDeclaresProfile) {
8604
+ throw schemaReviewFailure(
8605
+ "AP_CONFLICT",
8606
+ "publication_review_profile_mismatch",
8607
+ schemaReviewMessages.reviewProfileMismatch
8608
+ );
8609
+ }
8610
+ return {
8611
+ session: header === null ? { kind: "legacy", profile: 1 } : { kind: "negotiated", profile },
8612
+ body: envelope.body
8613
+ };
8614
+ }
8615
+ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, profile, messages) {
8525
8616
  assertCanonicalResponseSize(value, "publication_plan_too_large", messages);
8526
8617
  const plan = asRecord4(value);
8527
- if (!plan || !hasExactKeys3(plan, PLAN_KEYS) || !isCanonicalUuid(plan.requestId) || plan.environment !== "production" || plan.connectorId !== connectorId || !isCanonicalTimestamp(plan.connectorRevision) || !isCommitment(plan.connectorCommitment) || !isCommitment(plan.policyCommitment) || plan.candidateCommitment !== candidateCommitment || !isCommitment(plan.candidateCommitment) || !isCommitment(plan.baseCommitment) || !isCommitment(plan.planCommitment) || !Array.isArray(plan.tools) || typeof plan.applyAllowed !== "boolean" || !Array.isArray(plan.blockedReasons) || !plan.blockedReasons.every(
8618
+ if (!plan || !hasExactKeys3(plan, profile === 2 ? [...PLAN_KEYS, "reviewProfile"] : PLAN_KEYS) || profile === 2 && plan.reviewProfile !== 2 || !isCanonicalUuid(plan.requestId) || plan.environment !== "production" || plan.connectorId !== connectorId || !isCanonicalTimestamp(plan.connectorRevision) || !isCommitment(plan.connectorCommitment) || !isCommitment(plan.policyCommitment) || plan.candidateCommitment !== candidateCommitment || !isCommitment(plan.candidateCommitment) || !isCommitment(plan.baseCommitment) || !isCommitment(plan.planCommitment) || !Array.isArray(plan.tools) || typeof plan.applyAllowed !== "boolean" || !Array.isArray(plan.blockedReasons) || !plan.blockedReasons.every(
8528
8619
  (reason) => typeof reason === "string" && BLOCKED_REASONS.has(reason)
8529
8620
  ) || !isStrictlySorted(plan.blockedReasons) || plan.applyAllowed !== (plan.blockedReasons.length === 0)) {
8530
8621
  throw responseInvalid("publication_plan_invalid", messages);
@@ -8533,6 +8624,7 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
8533
8624
  let safeDiff;
8534
8625
  try {
8535
8626
  safeDiff = (0, import_tool_contract9.parsePublicationSafeDiffDto)({
8627
+ ...profile === 2 ? { reviewProfile: 2 } : {},
8536
8628
  tools: plan.tools,
8537
8629
  retainedTools: plan.retainedTools,
8538
8630
  warnings: plan.warnings
@@ -8540,13 +8632,16 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
8540
8632
  } catch {
8541
8633
  throw responseInvalid("publication_safe_diff_invalid", messages);
8542
8634
  }
8635
+ if (safeDiff.reviewProfile === 2 !== (profile === 2)) {
8636
+ throw responseInvalid("publication_safe_diff_invalid", messages);
8637
+ }
8543
8638
  const tools = safeDiff.tools;
8544
8639
  const toolNames = tools.map((tool) => tool.toolName);
8545
8640
  if (!isStrictlySorted(toolNames) || JSON.stringify(toolNames) !== JSON.stringify(expectedToolNames)) {
8546
8641
  throw responseInvalid("publication_plan_tools_order_invalid", messages);
8547
8642
  }
8548
8643
  const warnings = safeDiff.warnings;
8549
- const expectedPlanCommitment = (0, import_tool_contract9.publicationCommitment)("plan", {
8644
+ const expectedPlanCommitment = (0, import_tool_contract9.publicationCommitment)(profile === 2 ? "planV2" : "plan", {
8550
8645
  candidateCommitment,
8551
8646
  baseCommitment: plan.baseCommitment,
8552
8647
  connectorId,
@@ -8574,6 +8669,7 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
8574
8669
  throw responseInvalid("publication_plan_gate_inconsistent", messages);
8575
8670
  }
8576
8671
  return {
8672
+ ...profile === 2 ? { reviewProfile: 2 } : {},
8577
8673
  requestId: plan.requestId,
8578
8674
  environment: "production",
8579
8675
  connectorId,
@@ -8701,8 +8797,36 @@ function typedStatus2(error) {
8701
8797
  const status = error.status;
8702
8798
  return typeof status === "number" && Number.isInteger(status) && status >= 100 && status <= 599 ? status : void 0;
8703
8799
  }
8704
- function remoteError(error, phase, messages) {
8800
+ function typedPublicationReason(error, code) {
8801
+ if (error === null || typeof error !== "object") return void 0;
8802
+ const status = typedStatus2(error);
8803
+ if (status === void 0 || status < 400 || status > 499) return void 0;
8804
+ const reason = error.publicationReason;
8805
+ return isPublicationErrorReasonFor(code, reason) ? reason : void 0;
8806
+ }
8807
+ function publicationReasonText(reason, schemaReviewMessages) {
8808
+ switch (reason) {
8809
+ case "publication_schema_review_too_large":
8810
+ return schemaReviewMessages.schemaReviewTooLarge;
8811
+ case "publication_review_profile_invalid":
8812
+ return schemaReviewMessages.reviewProfileInvalid;
8813
+ case "schema_review_receipt_mismatch":
8814
+ return schemaReviewMessages.receiptMismatch;
8815
+ case "publication_plan_stale":
8816
+ return schemaReviewMessages.planStale;
8817
+ }
8818
+ }
8819
+ function remoteError(error, phase, messages, schemaReviewMessages) {
8705
8820
  const code = typedCode2(error) ?? "AP_NETWORK_ERROR";
8821
+ const publicationReason = schemaReviewMessages === void 0 ? void 0 : typedPublicationReason(error, code);
8822
+ if (publicationReason !== void 0 && schemaReviewMessages !== void 0) {
8823
+ return schemaReviewFailure(
8824
+ code,
8825
+ publicationReason,
8826
+ publicationReasonText(publicationReason, schemaReviewMessages),
8827
+ typedStatus2(error)
8828
+ );
8829
+ }
8706
8830
  return new PublishCommandError(
8707
8831
  code,
8708
8832
  `${phase}_failed`,
@@ -8764,6 +8888,42 @@ function writeSafeJson(writer, value) {
8764
8888
  function writePlan(writer, plan) {
8765
8889
  writeSafeJson(writer, { phase: "plan", ...plan });
8766
8890
  }
8891
+ function writeSchemaReviewSummary(writer, plan, schemaReviewMessages) {
8892
+ if (plan.reviewProfile !== 2) return;
8893
+ const reviewed = plan.tools.filter((tool) => (tool.schemaReview?.enums.length ?? 0) > 0);
8894
+ if (reviewed.length === 0) return;
8895
+ interactive(writer, schemaReviewMessages.heading);
8896
+ for (const tool of reviewed) {
8897
+ const review = tool.schemaReview;
8898
+ if (!review) continue;
8899
+ const count = (change) => review.enums.filter((entry) => entry.change === change).length;
8900
+ interactive(
8901
+ writer,
8902
+ schemaReviewMessages.toolSummary({
8903
+ toolName: terminalSafeText(tool.toolName),
8904
+ total: review.enums.length,
8905
+ added: count("added"),
8906
+ changed: count("changed"),
8907
+ removed: count("removed"),
8908
+ unchanged: count("unchanged"),
8909
+ valueReviewRequired: review.humanValueReviewRequired
8910
+ })
8911
+ );
8912
+ }
8913
+ if (reviewed.some((tool) => tool.schemaReview?.humanValueReviewRequired === true)) {
8914
+ interactive(writer, schemaReviewMessages.valueReviewInWebAdmin);
8915
+ }
8916
+ }
8917
+ function candidateNeedsReviewProfile2(candidateContract) {
8918
+ return (0, import_tool_contract9.selectPublicationReviewProfile)({
8919
+ requestedProfile: CLI_PUBLICATION_REVIEW_PROFILE,
8920
+ candidateContract,
8921
+ currentTools: []
8922
+ }) === 2;
8923
+ }
8924
+ function applyPublicationWithProfile(client, projectId, idempotencyKey, body, session) {
8925
+ return session.kind === "negotiated" ? client.applyPublication(projectId, idempotencyKey, body, REVIEW_PROFILE_REQUEST) : client.applyPublication(projectId, idempotencyKey, body);
8926
+ }
8767
8927
  function writeResult(writer, result) {
8768
8928
  writeSafeJson(writer, { phase: "result", ...result });
8769
8929
  }
@@ -8856,7 +9016,13 @@ async function sendInitialApplyWithSameAnchorRetry(input) {
8856
9016
  for (let attempt = 0; attempt < INITIAL_APPLY_MAX_ATTEMPTS; attempt += 1) {
8857
9017
  try {
8858
9018
  const result = parsePublicationResult(
8859
- await input.client.applyPublication(input.projectId, input.idempotencyKey, input.body),
9019
+ await applyPublicationWithProfile(
9020
+ input.client,
9021
+ input.projectId,
9022
+ input.idempotencyKey,
9023
+ input.body,
9024
+ input.session
9025
+ ),
8860
9026
  input.plan,
8861
9027
  input.messages
8862
9028
  );
@@ -8882,7 +9048,7 @@ async function sendInitialApplyWithSameAnchorRetry(input) {
8882
9048
  return { kind: "confirmation_required", details: confirmationRequired };
8883
9049
  }
8884
9050
  if (!malformedConfirmationAnchor && !initialApplyResultMayBeUnknown(error)) {
8885
- throw remoteError(error, "initial_apply", input.messages);
9051
+ throw remoteError(error, "initial_apply", input.messages, input.schemaReviewMessages);
8886
9052
  }
8887
9053
  if (attempt === INITIAL_APPLY_MAX_ATTEMPTS - 1) {
8888
9054
  throw new PublishCommandError(
@@ -9007,7 +9173,7 @@ async function pollPublication(client, projectId, details, plan, writer, runtime
9007
9173
  }
9008
9174
  throw confirmationStopped("AP_CONFIRMATION_EXPIRED", "publication_poll_attempt_limit", messages);
9009
9175
  }
9010
- async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAULT_PUBLISH_MESSAGES, scopeRegistrationMessages = DEFAULT_SCOPE_REGISTRATION_MESSAGES2) {
9176
+ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAULT_PUBLISH_MESSAGES, scopeRegistrationMessages = DEFAULT_SCOPE_REGISTRATION_MESSAGES2, schemaReviewMessages = DEFAULT_SCHEMA_REVIEW_MESSAGES) {
9011
9177
  const normalized = normalizePublishOptions(options, messages);
9012
9178
  const project = loadPublicationProject(runtime.loadProject, cwd, messages);
9013
9179
  const projectId = project.manifest.project_id;
@@ -9028,18 +9194,25 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
9028
9194
  const client = runtime.createClient(normalized.profile);
9029
9195
  let rawPlan;
9030
9196
  try {
9031
- rawPlan = await client.planPublication(projectId, planRequest);
9197
+ rawPlan = await client.planPublication(projectId, planRequest, REVIEW_PROFILE_REQUEST);
9032
9198
  } catch (error) {
9033
- throw remoteError(error, "plan", messages);
9199
+ throw remoteError(error, "plan", messages, schemaReviewMessages);
9034
9200
  }
9201
+ const negotiated = negotiateReviewProfile(rawPlan, messages, schemaReviewMessages);
9202
+ const session = negotiated.session;
9035
9203
  const plan = parsePlan(
9036
- rawPlan,
9204
+ negotiated.body,
9037
9205
  connectorId,
9038
9206
  planRequest.candidateCommitment,
9039
9207
  expectedToolNames,
9208
+ session.profile,
9040
9209
  messages
9041
9210
  );
9042
9211
  writePlan(writer, plan);
9212
+ writeSchemaReviewSummary(writer, plan, schemaReviewMessages);
9213
+ if (session.kind === "legacy" && plan.blockedReasons.includes("opaque_change") && candidateNeedsReviewProfile2(planRequest.candidateContract)) {
9214
+ interactive(writer, schemaReviewMessages.adminApiUpdatePending);
9215
+ }
9043
9216
  if (plan.blockedReasons.includes("connector_mismatch")) {
9044
9217
  interactive(writer, messages.connectorMismatchRemediation);
9045
9218
  }
@@ -9070,7 +9243,9 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
9070
9243
  idempotencyKey,
9071
9244
  body: initialApplyRequest,
9072
9245
  plan,
9073
- messages
9246
+ session,
9247
+ messages,
9248
+ schemaReviewMessages
9074
9249
  });
9075
9250
  let details;
9076
9251
  if (initial.kind === "response") {
@@ -9099,7 +9274,13 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
9099
9274
  }
9100
9275
  try {
9101
9276
  const result = parsePublicationResult(
9102
- await client.applyPublication(projectId, idempotencyKey, applyRequest(decision.confirmation)),
9277
+ await applyPublicationWithProfile(
9278
+ client,
9279
+ projectId,
9280
+ idempotencyKey,
9281
+ applyRequest(decision.confirmation),
9282
+ session
9283
+ ),
9103
9284
  plan,
9104
9285
  messages,
9105
9286
  details.publicationId
@@ -9109,7 +9290,7 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
9109
9290
  } catch (error) {
9110
9291
  if (error instanceof PublishCommandError && error.code === "AP_RESPONSE_INVALID") {
9111
9292
  } else if (!approvedApplyResultMayBeUnknown(error)) {
9112
- throw remoteError(error, "approved_apply", messages);
9293
+ throw remoteError(error, "approved_apply", messages, schemaReviewMessages);
9113
9294
  }
9114
9295
  }
9115
9296
  const recovered = await pollPublication(
@@ -9132,7 +9313,7 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
9132
9313
  }
9133
9314
  writeResult(writer, recovered.result);
9134
9315
  }
9135
- function registerPublish(program, writer, cwd, createClient, description2 = "Tool Contract\u3092production publication workflow\u3067\u5B89\u5168\u306B\u516C\u958B\u3057\u307E\u3059", runtime = createPublishCommandRuntime(createClient), messages = DEFAULT_PUBLISH_MESSAGES, scopeRegistrationMessages = DEFAULT_SCOPE_REGISTRATION_MESSAGES2) {
9316
+ function registerPublish(program, writer, cwd, createClient, description2 = "Tool Contract\u3092production publication workflow\u3067\u5B89\u5168\u306B\u516C\u958B\u3057\u307E\u3059", runtime = createPublishCommandRuntime(createClient), messages = DEFAULT_PUBLISH_MESSAGES, scopeRegistrationMessages = DEFAULT_SCOPE_REGISTRATION_MESSAGES2, schemaReviewMessages = DEFAULT_SCHEMA_REVIEW_MESSAGES) {
9136
9317
  program.command("publish").description(description2).option("--connector <connector-uuid>", messages.connectorOption).option("--dry-run", messages.dryRunOption, false).option("--apply", messages.applyOption, false).option("--yes", messages.yesOption, false).option("--profile <name>", messages.profileOption, DEFAULT_PROFILE_NAME).option("--project <project-uuid>", messages.projectOption).action(async (commandOptions) => {
9137
9318
  await runPublishCommand(
9138
9319
  commandOptions,
@@ -9140,7 +9321,8 @@ function registerPublish(program, writer, cwd, createClient, description2 = "Too
9140
9321
  cwd(),
9141
9322
  runtime,
9142
9323
  messages,
9143
- scopeRegistrationMessages
9324
+ scopeRegistrationMessages,
9325
+ schemaReviewMessages
9144
9326
  );
9145
9327
  });
9146
9328
  }
@@ -9989,7 +10171,8 @@ function buildProgram(writer = defaultWriter, cwd = () => process.cwd(), locale
9989
10171
  text.publishDescription,
9990
10172
  void 0,
9991
10173
  messages.publish,
9992
- scopeRegistrationMessages
10174
+ scopeRegistrationMessages,
10175
+ import_localization13.PUBLICATION_SCHEMA_REVIEW_CLI_MESSAGES[locale]
9993
10176
  );
9994
10177
  return program;
9995
10178
  }
package/dist/bin.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  ConfirmationRequiredError,
4
4
  maskSecrets,
5
5
  runCli
6
- } from "./chunk-VFSDVWMN.js";
6
+ } from "./chunk-2PG5NEI2.js";
7
7
  import "./chunk-7LSHSW4Q.js";
8
8
 
9
9
  // src/bin.ts