@andpipes/cli 0.1.4 → 0.1.6
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/README.md +2 -0
- package/dist/bin.cjs +503 -144
- package/dist/bin.js +1 -1
- package/dist/{chunk-VFSDVWMN.js → chunk-TTC7UVIV.js} +483 -116
- package/dist/index.cjs +507 -148
- package/dist/index.d.cts +63 -7
- package/dist/index.d.ts +63 -7
- package/dist/index.js +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -145,7 +145,7 @@ function readVersion() {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
// src/cli.ts
|
|
148
|
-
var
|
|
148
|
+
var import_localization14 = require("@andpipes/localization");
|
|
149
149
|
var import_commander = require("commander");
|
|
150
150
|
|
|
151
151
|
// src/commands/audit-export.ts
|
|
@@ -619,6 +619,26 @@ var ConfirmationRequiredError = class extends Error {
|
|
|
619
619
|
}
|
|
620
620
|
};
|
|
621
621
|
|
|
622
|
+
// src/lib/publication-review-profile.ts
|
|
623
|
+
var CLI_PUBLICATION_REVIEW_PROFILE = 2;
|
|
624
|
+
var PUBLICATION_ERROR_REASON_CODES = Object.freeze({
|
|
625
|
+
publication_plan_stale: "AP_CONFLICT",
|
|
626
|
+
publication_review_profile_invalid: "AP_INPUT_INVALID",
|
|
627
|
+
publication_schema_review_too_large: "AP_INPUT_INVALID",
|
|
628
|
+
schema_review_receipt_mismatch: "AP_CONFLICT"
|
|
629
|
+
});
|
|
630
|
+
function isPublicationErrorReasonFor(code, reason) {
|
|
631
|
+
return typeof reason === "string" && Object.hasOwn(PUBLICATION_ERROR_REASON_CODES, reason) && PUBLICATION_ERROR_REASON_CODES[reason] === code;
|
|
632
|
+
}
|
|
633
|
+
function parsePublicationErrorReason(status, code, details) {
|
|
634
|
+
if (status < 400 || status > 499) return void 0;
|
|
635
|
+
if (details === null || typeof details !== "object" || Array.isArray(details)) return void 0;
|
|
636
|
+
const record = details;
|
|
637
|
+
const keys = Object.keys(record);
|
|
638
|
+
if (keys.length !== 1 || keys[0] !== "reason") return void 0;
|
|
639
|
+
return isPublicationErrorReasonFor(code, record.reason) ? record.reason : void 0;
|
|
640
|
+
}
|
|
641
|
+
|
|
622
642
|
// src/lib/backend.ts
|
|
623
643
|
var ADMIN_API_ORIGIN = "https://api.andpipe.com";
|
|
624
644
|
var ADMIN_API_TIMEOUT_MS = 1e4;
|
|
@@ -648,6 +668,7 @@ var AdminApiClientError = class extends Error {
|
|
|
648
668
|
detailsAbsent;
|
|
649
669
|
scopeRegistrationReason;
|
|
650
670
|
publishGateToolNames;
|
|
671
|
+
publicationReason;
|
|
651
672
|
constructor(code, message, status, confirmationRequired, openApiAuthModeMismatch, safeDetails = {}) {
|
|
652
673
|
super(message);
|
|
653
674
|
this.name = "AdminApiClientError";
|
|
@@ -658,6 +679,7 @@ var AdminApiClientError = class extends Error {
|
|
|
658
679
|
this.detailsAbsent = safeDetails.detailsAbsent === true;
|
|
659
680
|
this.scopeRegistrationReason = safeDetails.scopeRegistrationReason;
|
|
660
681
|
this.publishGateToolNames = safeDetails.publishGateToolNames === void 0 ? void 0 : Object.freeze([...safeDetails.publishGateToolNames]);
|
|
682
|
+
this.publicationReason = safeDetails.publicationReason;
|
|
661
683
|
}
|
|
662
684
|
};
|
|
663
685
|
function clientError(code, message, status) {
|
|
@@ -872,7 +894,8 @@ function withKnownResponseStatus(error, responseStatus) {
|
|
|
872
894
|
{
|
|
873
895
|
detailsAbsent: error.detailsAbsent,
|
|
874
896
|
...error.scopeRegistrationReason === void 0 ? {} : { scopeRegistrationReason: error.scopeRegistrationReason },
|
|
875
|
-
...error.publishGateToolNames === void 0 ? {} : { publishGateToolNames: error.publishGateToolNames }
|
|
897
|
+
...error.publishGateToolNames === void 0 ? {} : { publishGateToolNames: error.publishGateToolNames },
|
|
898
|
+
...error.publicationReason === void 0 ? {} : { publicationReason: error.publicationReason }
|
|
876
899
|
}
|
|
877
900
|
);
|
|
878
901
|
}
|
|
@@ -941,6 +964,7 @@ function safeApiError(status, value) {
|
|
|
941
964
|
const code = typeof candidate === "string" && SAFE_AP_CODE_RE.test(candidate) ? candidate : "AP_HTTP_ERROR";
|
|
942
965
|
const confirmationRequired = code === "AP_CONFIRMATION_REQUIRED" && status === 409 ? parsePublicationConfirmationRequiredDetails(errorRecord?.details) : void 0;
|
|
943
966
|
const openApiAuthModeMismatch = code === "AP_CONFLICT" && status === 409 ? parseOpenApiImportAuthModeMismatch(errorRecord?.details) : void 0;
|
|
967
|
+
const publicationReason = parsePublicationErrorReason(status, code, errorRecord?.details);
|
|
944
968
|
return new AdminApiClientError(
|
|
945
969
|
code,
|
|
946
970
|
`Admin API request failed (${code}; HTTP ${status})`,
|
|
@@ -950,7 +974,8 @@ function safeApiError(status, value) {
|
|
|
950
974
|
{
|
|
951
975
|
// AP error envelopeを受け取れた場合だけ「detailsなし」を判定できる。
|
|
952
976
|
detailsAbsent: errorRecord !== void 0 && (errorRecord.details === null || errorRecord.details === void 0),
|
|
953
|
-
...parseScopeRegistrationErrorDetails(status, errorRecord?.details)
|
|
977
|
+
...parseScopeRegistrationErrorDetails(status, errorRecord?.details),
|
|
978
|
+
...publicationReason === void 0 ? {} : { publicationReason }
|
|
954
979
|
}
|
|
955
980
|
);
|
|
956
981
|
}
|
|
@@ -1084,6 +1109,13 @@ function publicationPlanBody(input) {
|
|
|
1084
1109
|
...input.templateProvenance === void 0 ? {} : { templateProvenance: input.templateProvenance }
|
|
1085
1110
|
};
|
|
1086
1111
|
}
|
|
1112
|
+
function publicationReviewProfileOption(options) {
|
|
1113
|
+
if (options === void 0) return void 0;
|
|
1114
|
+
if (options === null || typeof options !== "object" || Object.keys(options).join(",") !== "reviewProfile" || options.reviewProfile !== 2) {
|
|
1115
|
+
throw clientError("AP_INPUT_INVALID", "tool publication review profile option is invalid");
|
|
1116
|
+
}
|
|
1117
|
+
return options.reviewProfile;
|
|
1118
|
+
}
|
|
1087
1119
|
function publicationApplyBody(input) {
|
|
1088
1120
|
const common = publicationPlanBody(input);
|
|
1089
1121
|
if (!import_tool_contract.PUBLICATION_SHA256_COMMITMENT_RE.test(input.planCommitment)) {
|
|
@@ -1439,6 +1471,10 @@ var AdminApiClient = class {
|
|
|
1439
1471
|
this.#sleep = options.sleep ?? ((milliseconds) => new Promise((resolve7) => setTimeout(resolve7, milliseconds)));
|
|
1440
1472
|
}
|
|
1441
1473
|
async #request(path, options = {}) {
|
|
1474
|
+
return (await this.#requestWithHeaders(path, options)).value;
|
|
1475
|
+
}
|
|
1476
|
+
/** 2xx bodyと、そのresponse headerを返す。headerはcommand層が必要な値だけを読む。 */
|
|
1477
|
+
async #requestWithHeaders(path, options = {}) {
|
|
1442
1478
|
const url = buildUrl(path);
|
|
1443
1479
|
const method = options.method ?? "GET";
|
|
1444
1480
|
const attempts = method === "GET" ? ADMIN_API_MAX_GET_ATTEMPTS : 1;
|
|
@@ -1460,6 +1496,9 @@ var AdminApiClient = class {
|
|
|
1460
1496
|
if (options.authenticated !== false) headers.set("Authorization", `Bearer ${this.#token}`);
|
|
1461
1497
|
if (body !== void 0) headers.set("Content-Type", "application/json");
|
|
1462
1498
|
if (options.idempotencyKey) headers.set("Idempotency-Key", options.idempotencyKey);
|
|
1499
|
+
if (options.reviewProfile !== void 0) {
|
|
1500
|
+
headers.set(import_tool_contract.PUBLICATION_REVIEW_PROFILE_HEADER, String(options.reviewProfile));
|
|
1501
|
+
}
|
|
1463
1502
|
response = await this.#fetch(url, {
|
|
1464
1503
|
method,
|
|
1465
1504
|
headers,
|
|
@@ -1516,8 +1555,8 @@ var AdminApiClient = class {
|
|
|
1516
1555
|
}
|
|
1517
1556
|
throw safeApiError(response.status, errorBody);
|
|
1518
1557
|
}
|
|
1519
|
-
if (options.responseType === "text") return text;
|
|
1520
|
-
return parseJson(text);
|
|
1558
|
+
if (options.responseType === "text") return { value: text, headers: response.headers };
|
|
1559
|
+
return { value: parseJson(text), headers: response.headers };
|
|
1521
1560
|
}
|
|
1522
1561
|
throw clientError("AP_NETWORK_ERROR", "Admin API request failed");
|
|
1523
1562
|
}
|
|
@@ -1663,24 +1702,41 @@ var AdminApiClient = class {
|
|
|
1663
1702
|
status: connector.status
|
|
1664
1703
|
};
|
|
1665
1704
|
}
|
|
1666
|
-
async planPublication(projectId, body) {
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1705
|
+
async planPublication(projectId, body, options) {
|
|
1706
|
+
const reviewProfile = publicationReviewProfileOption(options);
|
|
1707
|
+
const response = await this.#requestWithHeaders(
|
|
1708
|
+
`/v1/projects/${assertProjectId(projectId)}/tool-publications:plan`,
|
|
1709
|
+
{
|
|
1710
|
+
method: "POST",
|
|
1711
|
+
body: publicationPlanBody(body),
|
|
1712
|
+
maxRequestBytes: ADMIN_API_PUBLICATION_REQUEST_MAX_BYTES,
|
|
1713
|
+
maxResponseBytes: ADMIN_API_PUBLICATION_RESPONSE_MAX_BYTES,
|
|
1714
|
+
...reviewProfile === void 0 ? {} : { reviewProfile }
|
|
1715
|
+
}
|
|
1716
|
+
);
|
|
1717
|
+
if (reviewProfile === void 0) return response.value;
|
|
1718
|
+
const planResponse = {
|
|
1719
|
+
body: response.value,
|
|
1720
|
+
reviewProfileHeader: response.headers.get(import_tool_contract.PUBLICATION_REVIEW_PROFILE_HEADER)
|
|
1721
|
+
};
|
|
1722
|
+
return planResponse;
|
|
1673
1723
|
}
|
|
1674
|
-
|
|
1724
|
+
/**
|
|
1725
|
+
* 初回apply(confirmation=null)と承認済みapply。options付き (#730) だけreview profile headerを送る。
|
|
1726
|
+
* request bodyとIdempotency-Keyはheaderの有無で変えない。
|
|
1727
|
+
*/
|
|
1728
|
+
async applyPublication(projectId, idempotencyKey, body, options) {
|
|
1675
1729
|
if (!/^[A-Za-z0-9._:-]{22,200}$/u.test(idempotencyKey)) {
|
|
1676
1730
|
throw clientError("AP_INPUT_INVALID", "tool publication Idempotency-Key is invalid");
|
|
1677
1731
|
}
|
|
1732
|
+
const reviewProfile = publicationReviewProfileOption(options);
|
|
1678
1733
|
return this.#request(`/v1/projects/${assertProjectId(projectId)}/tool-publications`, {
|
|
1679
1734
|
method: "POST",
|
|
1680
1735
|
body: publicationApplyBody(body),
|
|
1681
1736
|
idempotencyKey,
|
|
1682
1737
|
maxRequestBytes: ADMIN_API_PUBLICATION_REQUEST_MAX_BYTES,
|
|
1683
|
-
maxResponseBytes: ADMIN_API_PUBLICATION_RESPONSE_MAX_BYTES
|
|
1738
|
+
maxResponseBytes: ADMIN_API_PUBLICATION_RESPONSE_MAX_BYTES,
|
|
1739
|
+
...reviewProfile === void 0 ? {} : { reviewProfile }
|
|
1684
1740
|
});
|
|
1685
1741
|
}
|
|
1686
1742
|
async planOpenApiImport(projectId, input) {
|
|
@@ -3236,8 +3292,8 @@ async function downloadAuditExportArtifact(input) {
|
|
|
3236
3292
|
} finally {
|
|
3237
3293
|
reader.releaseLock();
|
|
3238
3294
|
}
|
|
3239
|
-
const
|
|
3240
|
-
if (bytes !== authorization.manifest.byteCount ||
|
|
3295
|
+
const sha2563 = hash.digest("hex");
|
|
3296
|
+
if (bytes !== authorization.manifest.byteCount || sha2563 !== authorization.manifest.contentSha256) {
|
|
3241
3297
|
throw new UsageError("\u76E3\u67FB\u30A8\u30AF\u30B9\u30DD\u30FC\u30C8\u306E\u5185\u5BB9\u304C\u7F72\u540Dmanifest\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093");
|
|
3242
3298
|
}
|
|
3243
3299
|
await file.sync();
|
|
@@ -3256,7 +3312,7 @@ async function downloadAuditExportArtifact(input) {
|
|
|
3256
3312
|
} finally {
|
|
3257
3313
|
await directory.close();
|
|
3258
3314
|
}
|
|
3259
|
-
return { output: canonicalTarget, sha256:
|
|
3315
|
+
return { output: canonicalTarget, sha256: sha2563, bytes };
|
|
3260
3316
|
} finally {
|
|
3261
3317
|
clearTimeout(timeout);
|
|
3262
3318
|
await file.close().catch(() => void 0);
|
|
@@ -8498,22 +8554,253 @@ function registerLogs(program, writer, locale = import_localization8.DEFAULT_LOC
|
|
|
8498
8554
|
});
|
|
8499
8555
|
}
|
|
8500
8556
|
|
|
8501
|
-
// src/commands/
|
|
8502
|
-
var
|
|
8503
|
-
var
|
|
8557
|
+
// src/commands/muse.ts
|
|
8558
|
+
var import_node_crypto12 = require("crypto");
|
|
8559
|
+
var import_node_fs12 = require("fs");
|
|
8560
|
+
var import_node_path13 = require("path");
|
|
8504
8561
|
var import_localization10 = require("@andpipes/localization");
|
|
8505
|
-
var
|
|
8562
|
+
var import_tool_contract9 = require("@andpipes/tool-contract");
|
|
8506
8563
|
|
|
8507
|
-
// src/commands/
|
|
8508
|
-
var
|
|
8564
|
+
// src/commands/validate.ts
|
|
8565
|
+
var import_node_fs11 = require("fs");
|
|
8566
|
+
var import_node_path12 = require("path");
|
|
8509
8567
|
var import_localization9 = require("@andpipes/localization");
|
|
8510
|
-
|
|
8568
|
+
function resolveContractPath(file, cwd, locale = import_localization9.DEFAULT_LOCALE) {
|
|
8569
|
+
const messages = import_localization9.CLI_MESSAGES[locale].validate;
|
|
8570
|
+
if (file) {
|
|
8571
|
+
const abs = (0, import_node_path12.resolve)(cwd, file);
|
|
8572
|
+
if (!(0, import_node_fs11.existsSync)(abs)) {
|
|
8573
|
+
throw new UsageError(messages.fileNotFound(file));
|
|
8574
|
+
}
|
|
8575
|
+
return abs;
|
|
8576
|
+
}
|
|
8577
|
+
for (const candidate of import_tool_contract4.CONTRACT_FILENAMES) {
|
|
8578
|
+
const abs = (0, import_node_path12.resolve)(cwd, candidate);
|
|
8579
|
+
if ((0, import_node_fs11.existsSync)(abs)) {
|
|
8580
|
+
return abs;
|
|
8581
|
+
}
|
|
8582
|
+
}
|
|
8583
|
+
throw new UsageError(messages.defaultFileNotFound(import_tool_contract4.CONTRACT_FILENAMES));
|
|
8584
|
+
}
|
|
8585
|
+
function loadContract(path, locale = import_localization9.DEFAULT_LOCALE) {
|
|
8586
|
+
void locale;
|
|
8587
|
+
return loadContractFile(path).contract;
|
|
8588
|
+
}
|
|
8589
|
+
function registerValidate(program, writer, cwd, locale = import_localization9.DEFAULT_LOCALE) {
|
|
8590
|
+
const text = import_localization9.LOCALIZED_TEXT[locale].cli;
|
|
8591
|
+
const messages = import_localization9.CLI_MESSAGES[locale].validate;
|
|
8592
|
+
program.command("validate").description(`${text.validateDescription} (10 checks)`).option("--file <path>", messages.fileOption).action((opts) => {
|
|
8593
|
+
const path = resolveContractPath(opts.file, cwd(), locale);
|
|
8594
|
+
const loaded = loadContractFile(path);
|
|
8595
|
+
const report = loaded.report;
|
|
8596
|
+
const publishGate = loaded.publishGate;
|
|
8597
|
+
json(writer, { checks: report.results, publishGate });
|
|
8598
|
+
const fail2 = report.results.filter((r) => r.status === "fail").length;
|
|
8599
|
+
const pending = report.results.filter((r) => r.status === "pending").length;
|
|
8600
|
+
const pass = report.results.filter((r) => r.status === "pass").length;
|
|
8601
|
+
info(
|
|
8602
|
+
writer,
|
|
8603
|
+
`${text.resultLabel}: pass=${pass} fail=${fail2} pending=${pending} (pending=${text.backendPending})`
|
|
8604
|
+
);
|
|
8605
|
+
info(
|
|
8606
|
+
writer,
|
|
8607
|
+
messages.publishGateSummary(publishGate.errors.length, publishGate.warnings.length)
|
|
8608
|
+
);
|
|
8609
|
+
if (!report.ok || !publishGate.ok) {
|
|
8610
|
+
process.exitCode = 1;
|
|
8611
|
+
info(writer, messages.failed);
|
|
8612
|
+
}
|
|
8613
|
+
});
|
|
8614
|
+
}
|
|
8615
|
+
|
|
8616
|
+
// src/commands/muse.ts
|
|
8617
|
+
var DEFAULT_MUSE_OUTPUT_DIR = "andpipe-muse-preparation";
|
|
8618
|
+
var OUTPUT_DIR_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/u;
|
|
8619
|
+
var MAX_MUSE_FILE_BYTES = 8 * 1024 * 1024;
|
|
8620
|
+
var MUSE_PREPARATION_FILE_KEYS = Object.freeze(
|
|
8621
|
+
{
|
|
8622
|
+
"muse/connector.internal.json": "connector",
|
|
8623
|
+
"muse/openapi.json": "openapi",
|
|
8624
|
+
"muse/SKILL.md": "skill",
|
|
8625
|
+
"muse/setup.md": "setup",
|
|
8626
|
+
"muse/compatibility.json": "compatibility",
|
|
8627
|
+
"provenance/build.json": "provenance"
|
|
8628
|
+
}
|
|
8629
|
+
);
|
|
8630
|
+
var REASON_KEYS = {
|
|
8631
|
+
invalid_input: "invalid_input",
|
|
8632
|
+
selection_required: "selection_required",
|
|
8633
|
+
selection_invalid: "selection_invalid",
|
|
8634
|
+
contract_invalid: "contract_invalid",
|
|
8635
|
+
schema_unsupported: "schema_unsupported",
|
|
8636
|
+
sensitive_content: "sensitive_content",
|
|
8637
|
+
risk_unsupported: "risk_unsupported"
|
|
8638
|
+
};
|
|
8639
|
+
function parseToolNames(value, locale) {
|
|
8640
|
+
const names = (value ?? "").split(",").map((name) => name.trim()).filter((name) => name.length > 0);
|
|
8641
|
+
if (names.length === 0) throw new UsageError(import_localization10.MUSE_SETUP_MESSAGES[locale].cli.toolsRequired);
|
|
8642
|
+
return names;
|
|
8643
|
+
}
|
|
8644
|
+
function parseOutputDir(value, locale) {
|
|
8645
|
+
const output = value ?? DEFAULT_MUSE_OUTPUT_DIR;
|
|
8646
|
+
if (!OUTPUT_DIR_RE.test(output) || output === "." || output === "..") {
|
|
8647
|
+
throw new UsageError(import_localization10.MUSE_SETUP_MESSAGES[locale].cli.outputInvalid);
|
|
8648
|
+
}
|
|
8649
|
+
return output;
|
|
8650
|
+
}
|
|
8651
|
+
function sha2562(text) {
|
|
8652
|
+
return `sha256:${(0, import_node_crypto12.createHash)("sha256").update(text, "utf8").digest("hex")}`;
|
|
8653
|
+
}
|
|
8654
|
+
function createOwnedDirectory(path) {
|
|
8655
|
+
(0, import_node_fs12.mkdirSync)(path, { mode: 448 });
|
|
8656
|
+
return ownedDirectoryIdentity(path);
|
|
8657
|
+
}
|
|
8658
|
+
function ownedDirectoryIdentity(path) {
|
|
8659
|
+
let stat2;
|
|
8660
|
+
try {
|
|
8661
|
+
stat2 = (0, import_node_fs12.lstatSync)(path);
|
|
8662
|
+
} catch {
|
|
8663
|
+
throw new LocalFilePolicyError("local_file_changed", "output directory changed after create");
|
|
8664
|
+
}
|
|
8665
|
+
const identity = localRootIdentityFromStat(stat2, "local_file_changed", "output directory");
|
|
8666
|
+
assertOwnerOnlyLocalWrite(identity, "output directory");
|
|
8667
|
+
return identity;
|
|
8668
|
+
}
|
|
8669
|
+
function errorCode(error) {
|
|
8670
|
+
const code = typeof error === "object" && error !== null ? error.code : null;
|
|
8671
|
+
return typeof code === "string" && /^[A-Z][A-Z0-9_]{1,31}$/u.test(code) ? code : null;
|
|
8672
|
+
}
|
|
8673
|
+
function museWriteOrder(paths) {
|
|
8674
|
+
const isProvenance = (path) => path.startsWith("provenance/");
|
|
8675
|
+
return [...paths].sort(
|
|
8676
|
+
(left, right) => isProvenance(left) === isProvenance(right) ? left < right ? -1 : 1 : isProvenance(left) ? 1 : -1
|
|
8677
|
+
);
|
|
8678
|
+
}
|
|
8679
|
+
function writeBundle(root, output, files, locale) {
|
|
8680
|
+
const messages = import_localization10.MUSE_SETUP_MESSAGES[locale].cli;
|
|
8681
|
+
const target = (0, import_node_path13.join)(root, output);
|
|
8682
|
+
const ordered = museWriteOrder(Object.keys(files));
|
|
8683
|
+
const directoryNames = /* @__PURE__ */ new Set();
|
|
8684
|
+
for (const path of ordered) {
|
|
8685
|
+
const [directory, name, ...rest] = path.split("/");
|
|
8686
|
+
if (!directory || !name || rest.length > 0 || !MUSE_PREPARATION_FILE_KEYS[path]) {
|
|
8687
|
+
throw new LocalFilePolicyError("local_file_invalid", "unexpected preparation file path");
|
|
8688
|
+
}
|
|
8689
|
+
directoryNames.add(directory);
|
|
8690
|
+
}
|
|
8691
|
+
try {
|
|
8692
|
+
(0, import_node_fs12.mkdirSync)(target, { mode: 448 });
|
|
8693
|
+
} catch (error) {
|
|
8694
|
+
const code = errorCode(error);
|
|
8695
|
+
if (code === "EEXIST") throw new UsageError(messages.outputExists(output));
|
|
8696
|
+
throw new UsageError(`${messages.outputCreateFailed(output)}${code ? ` (${code})` : ""}`);
|
|
8697
|
+
}
|
|
8698
|
+
try {
|
|
8699
|
+
const targetIdentity = ownedDirectoryIdentity(target);
|
|
8700
|
+
const directories = /* @__PURE__ */ new Map();
|
|
8701
|
+
for (const directory of directoryNames) {
|
|
8702
|
+
assertLocalRootSecurityIdentity(target, targetIdentity, "muse output directory");
|
|
8703
|
+
directories.set(directory, createOwnedDirectory((0, import_node_path13.join)(target, directory)));
|
|
8704
|
+
}
|
|
8705
|
+
for (const path of ordered) {
|
|
8706
|
+
const [directory, name] = path.split("/");
|
|
8707
|
+
const expected = directories.get(directory);
|
|
8708
|
+
assertLocalRootSecurityIdentity(target, targetIdentity, "muse output directory");
|
|
8709
|
+
const delta = writePrivateFileNoReplace(
|
|
8710
|
+
name,
|
|
8711
|
+
(0, import_node_path13.join)(target, directory),
|
|
8712
|
+
files[path],
|
|
8713
|
+
MAX_MUSE_FILE_BYTES,
|
|
8714
|
+
{ expectedRootIdentity: expected }
|
|
8715
|
+
);
|
|
8716
|
+
directories.set(directory, localRootIdentityWithNlink(expected, expected.nlink + delta));
|
|
8717
|
+
}
|
|
8718
|
+
} catch (error) {
|
|
8719
|
+
const reason = error instanceof LocalFilePolicyError ? ` (${error.reason})` : "";
|
|
8720
|
+
throw new UsageError(`${messages.outputIncomplete(output)}${reason}`);
|
|
8721
|
+
}
|
|
8722
|
+
}
|
|
8723
|
+
function runMusePrepare(options, writer, cwd, locale = import_localization10.DEFAULT_LOCALE) {
|
|
8724
|
+
const messages = import_localization10.MUSE_SETUP_MESSAGES[locale];
|
|
8725
|
+
const toolNames = parseToolNames(options.tools, locale);
|
|
8726
|
+
const output = parseOutputDir(options.output, locale);
|
|
8727
|
+
const anchor = captureLocalRootPath(cwd);
|
|
8728
|
+
const loaded = loadContractFile(resolveContractPath(options.file, cwd, locale));
|
|
8729
|
+
const selected = new Set(toolNames);
|
|
8730
|
+
const result = (0, import_tool_contract9.prepareMuseBundle)(
|
|
8731
|
+
loaded.tools.filter((tool) => selected.has(tool.tool)),
|
|
8732
|
+
{ toolNames }
|
|
8733
|
+
);
|
|
8734
|
+
const flags = {
|
|
8735
|
+
enabled: result.enabled,
|
|
8736
|
+
liveVerified: result.liveVerified,
|
|
8737
|
+
submissionReady: result.submissionReady
|
|
8738
|
+
};
|
|
8739
|
+
if (result.status === "blocked") {
|
|
8740
|
+
const reason = messages.reasons[REASON_KEYS[result.reason]];
|
|
8741
|
+
json(writer, { status: "blocked", reason: result.reason, ...flags });
|
|
8742
|
+
info(writer, messages.cli.blocked);
|
|
8743
|
+
info(writer, `${messages.cli.reasonLabel}: ${reason.cause}`);
|
|
8744
|
+
info(writer, `${messages.cli.fixLabel}: ${reason.fix}`);
|
|
8745
|
+
process.exitCode = 1;
|
|
8746
|
+
return;
|
|
8747
|
+
}
|
|
8748
|
+
assertLocalRootSecurityIdentity(anchor.root, anchor.rootIdentity, "muse output");
|
|
8749
|
+
writeBundle(anchor.root, output, result.files, locale);
|
|
8750
|
+
const paths = Object.keys(result.files).sort();
|
|
8751
|
+
json(writer, {
|
|
8752
|
+
status: "prepared",
|
|
8753
|
+
output,
|
|
8754
|
+
contentHash: result.contentHash,
|
|
8755
|
+
...flags,
|
|
8756
|
+
files: paths.map((path) => ({ path, sha256: sha2562(result.files[path]) }))
|
|
8757
|
+
});
|
|
8758
|
+
info(writer, messages.cli.prepared(output));
|
|
8759
|
+
info(writer, messages.cli.notConnected);
|
|
8760
|
+
for (const path of paths) {
|
|
8761
|
+
const key = MUSE_PREPARATION_FILE_KEYS[path];
|
|
8762
|
+
if (key) info(writer, ` ${output}/${path}: ${messages.files[key]}`);
|
|
8763
|
+
}
|
|
8764
|
+
info(writer, `${messages.cli.statesHeading}:`);
|
|
8765
|
+
for (const key of import_localization10.MUSE_SETUP_STATE_KEYS) {
|
|
8766
|
+
const state = messages.states[key];
|
|
8767
|
+
info(
|
|
8768
|
+
writer,
|
|
8769
|
+
`- ${state.title}: ${key === "prepared" ? messages.cli.preparedNow : state.status}`
|
|
8770
|
+
);
|
|
8771
|
+
}
|
|
8772
|
+
info(writer, messages.cli.nextStep);
|
|
8773
|
+
}
|
|
8774
|
+
function registerMuse(program, writer, cwd, locale = import_localization10.DEFAULT_LOCALE) {
|
|
8775
|
+
const messages = import_localization10.MUSE_SETUP_MESSAGES[locale].cli;
|
|
8776
|
+
const muse = program.command("muse").description(messages.groupDescription);
|
|
8777
|
+
muse.command("prepare").description(messages.prepareDescription).option(
|
|
8778
|
+
"--tools <names>",
|
|
8779
|
+
messages.toolsOption,
|
|
8780
|
+
(value, previous) => previous === void 0 ? value : `${previous},${value}`
|
|
8781
|
+
).option("--file <path>", messages.fileOption).option("--output <dir>", messages.outputOption, DEFAULT_MUSE_OUTPUT_DIR).action((options) => runMusePrepare(options, writer, cwd(), locale));
|
|
8782
|
+
}
|
|
8783
|
+
|
|
8784
|
+
// src/commands/oauth.ts
|
|
8785
|
+
var import_node_crypto14 = require("crypto");
|
|
8786
|
+
var import_node_fs13 = require("fs");
|
|
8787
|
+
var import_localization12 = require("@andpipes/localization");
|
|
8788
|
+
var import_tool_contract11 = require("@andpipes/tool-contract");
|
|
8789
|
+
|
|
8790
|
+
// src/commands/publish.ts
|
|
8791
|
+
var import_node_crypto13 = require("crypto");
|
|
8792
|
+
var import_localization11 = require("@andpipes/localization");
|
|
8793
|
+
var import_tool_contract10 = require("@andpipes/tool-contract");
|
|
8511
8794
|
var UUID_RE6 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
|
|
8512
8795
|
var SAFE_AP_CODE_RE2 = /^AP_[A-Z0-9_]{1,64}$/u;
|
|
8513
8796
|
var PUBLICATION_RESPONSE_MAX_BYTES = 96 * 1024;
|
|
8514
8797
|
var INITIAL_APPLY_MAX_ATTEMPTS = 3;
|
|
8515
|
-
var DEFAULT_PUBLISH_MESSAGES =
|
|
8516
|
-
var DEFAULT_SCOPE_REGISTRATION_MESSAGES2 =
|
|
8798
|
+
var DEFAULT_PUBLISH_MESSAGES = import_localization11.CLI_MESSAGES.ja.publish;
|
|
8799
|
+
var DEFAULT_SCOPE_REGISTRATION_MESSAGES2 = import_localization11.OAUTH_SCOPE_REGISTRATION_MESSAGES.ja.cli;
|
|
8800
|
+
var DEFAULT_SCHEMA_REVIEW_MESSAGES = import_localization11.PUBLICATION_SCHEMA_REVIEW_CLI_MESSAGES.ja;
|
|
8801
|
+
var REVIEW_PROFILE_REQUEST = Object.freeze({
|
|
8802
|
+
reviewProfile: CLI_PUBLICATION_REVIEW_PROFILE
|
|
8803
|
+
});
|
|
8517
8804
|
var PLAN_KEYS = [
|
|
8518
8805
|
"requestId",
|
|
8519
8806
|
"environment",
|
|
@@ -8599,7 +8886,7 @@ function createPublishCommandRuntime(createClient) {
|
|
|
8599
8886
|
return {
|
|
8600
8887
|
createClient,
|
|
8601
8888
|
loadProject: loadDevProject,
|
|
8602
|
-
randomUuid: () => (0,
|
|
8889
|
+
randomUuid: () => (0, import_node_crypto13.randomUUID)(),
|
|
8603
8890
|
monotonicNow: () => Number(process.hrtime.bigint() / 1000000n),
|
|
8604
8891
|
wallNow: () => Date.now(),
|
|
8605
8892
|
sleep: (milliseconds) => new Promise((resolve7) => setTimeout(resolve7, milliseconds))
|
|
@@ -8645,7 +8932,7 @@ function responseInvalid(reason, messages) {
|
|
|
8645
8932
|
}
|
|
8646
8933
|
function assertCanonicalResponseSize(value, reason, messages, maxBytes = PUBLICATION_RESPONSE_MAX_BYTES) {
|
|
8647
8934
|
try {
|
|
8648
|
-
(0,
|
|
8935
|
+
(0, import_tool_contract10.assertCanonicalPublicationSize)(value, maxBytes);
|
|
8649
8936
|
} catch {
|
|
8650
8937
|
throw responseInvalid(reason, messages);
|
|
8651
8938
|
}
|
|
@@ -8654,7 +8941,7 @@ function isCanonicalUuid(value) {
|
|
|
8654
8941
|
return typeof value === "string" && UUID_RE6.test(value);
|
|
8655
8942
|
}
|
|
8656
8943
|
function isCommitment(value) {
|
|
8657
|
-
return typeof value === "string" &&
|
|
8944
|
+
return typeof value === "string" && import_tool_contract10.PUBLICATION_SHA256_COMMITMENT_RE.test(value);
|
|
8658
8945
|
}
|
|
8659
8946
|
function isCanonicalTimestamp(value) {
|
|
8660
8947
|
if (typeof value !== "string" || value.length > 64) return false;
|
|
@@ -8663,20 +8950,51 @@ function isCanonicalTimestamp(value) {
|
|
|
8663
8950
|
}
|
|
8664
8951
|
function isStrictlySorted(values) {
|
|
8665
8952
|
return values.every(
|
|
8666
|
-
(value, index) => index === 0 || (0,
|
|
8953
|
+
(value, index) => index === 0 || (0, import_tool_contract10.comparePublicationUnicodeCodePoints)(values[index - 1], value) < 0
|
|
8667
8954
|
);
|
|
8668
8955
|
}
|
|
8669
8956
|
function parseWarnings(value, messages) {
|
|
8670
8957
|
try {
|
|
8671
|
-
return (0,
|
|
8958
|
+
return (0, import_tool_contract10.parsePublicationWarningsDto)(value);
|
|
8672
8959
|
} catch {
|
|
8673
8960
|
throw responseInvalid("publication_warnings_invalid", messages);
|
|
8674
8961
|
}
|
|
8675
8962
|
}
|
|
8676
|
-
function
|
|
8963
|
+
function schemaReviewFailure(code, reason, text, status) {
|
|
8964
|
+
return new PublishCommandError(code, reason, `${text} (${reason})`, status);
|
|
8965
|
+
}
|
|
8966
|
+
function negotiateReviewProfile(response, messages, schemaReviewMessages) {
|
|
8967
|
+
const envelope = asRecord4(response);
|
|
8968
|
+
if (!envelope || !hasExactKeys3(envelope, ["body", "reviewProfileHeader"]) || envelope.reviewProfileHeader !== null && typeof envelope.reviewProfileHeader !== "string") {
|
|
8969
|
+
throw responseInvalid("publication_plan_invalid", messages);
|
|
8970
|
+
}
|
|
8971
|
+
const header = envelope.reviewProfileHeader;
|
|
8972
|
+
if (header !== null && header !== "1" && header !== "2") {
|
|
8973
|
+
throw schemaReviewFailure(
|
|
8974
|
+
"AP_RESPONSE_INVALID",
|
|
8975
|
+
"publication_review_profile_header_invalid",
|
|
8976
|
+
schemaReviewMessages.reviewProfileHeaderInvalid
|
|
8977
|
+
);
|
|
8978
|
+
}
|
|
8979
|
+
const body = asRecord4(envelope.body);
|
|
8980
|
+
const bodyDeclaresProfile = body !== null && Object.hasOwn(body, "reviewProfile");
|
|
8981
|
+
const profile = header === "2" ? 2 : 1;
|
|
8982
|
+
if (profile === 2 ? !bodyDeclaresProfile || body?.reviewProfile !== 2 : bodyDeclaresProfile) {
|
|
8983
|
+
throw schemaReviewFailure(
|
|
8984
|
+
"AP_CONFLICT",
|
|
8985
|
+
"publication_review_profile_mismatch",
|
|
8986
|
+
schemaReviewMessages.reviewProfileMismatch
|
|
8987
|
+
);
|
|
8988
|
+
}
|
|
8989
|
+
return {
|
|
8990
|
+
session: header === null ? { kind: "legacy", profile: 1 } : { kind: "negotiated", profile },
|
|
8991
|
+
body: envelope.body
|
|
8992
|
+
};
|
|
8993
|
+
}
|
|
8994
|
+
function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, profile, messages) {
|
|
8677
8995
|
assertCanonicalResponseSize(value, "publication_plan_too_large", messages);
|
|
8678
8996
|
const plan = asRecord4(value);
|
|
8679
|
-
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(
|
|
8997
|
+
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(
|
|
8680
8998
|
(reason) => typeof reason === "string" && BLOCKED_REASONS.has(reason)
|
|
8681
8999
|
) || !isStrictlySorted(plan.blockedReasons) || plan.applyAllowed !== (plan.blockedReasons.length === 0)) {
|
|
8682
9000
|
throw responseInvalid("publication_plan_invalid", messages);
|
|
@@ -8684,7 +9002,8 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8684
9002
|
const blockedReasons = plan.blockedReasons;
|
|
8685
9003
|
let safeDiff;
|
|
8686
9004
|
try {
|
|
8687
|
-
safeDiff = (0,
|
|
9005
|
+
safeDiff = (0, import_tool_contract10.parsePublicationSafeDiffDto)({
|
|
9006
|
+
...profile === 2 ? { reviewProfile: 2 } : {},
|
|
8688
9007
|
tools: plan.tools,
|
|
8689
9008
|
retainedTools: plan.retainedTools,
|
|
8690
9009
|
warnings: plan.warnings
|
|
@@ -8692,13 +9011,16 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8692
9011
|
} catch {
|
|
8693
9012
|
throw responseInvalid("publication_safe_diff_invalid", messages);
|
|
8694
9013
|
}
|
|
9014
|
+
if (safeDiff.reviewProfile === 2 !== (profile === 2)) {
|
|
9015
|
+
throw responseInvalid("publication_safe_diff_invalid", messages);
|
|
9016
|
+
}
|
|
8695
9017
|
const tools = safeDiff.tools;
|
|
8696
9018
|
const toolNames = tools.map((tool) => tool.toolName);
|
|
8697
9019
|
if (!isStrictlySorted(toolNames) || JSON.stringify(toolNames) !== JSON.stringify(expectedToolNames)) {
|
|
8698
9020
|
throw responseInvalid("publication_plan_tools_order_invalid", messages);
|
|
8699
9021
|
}
|
|
8700
9022
|
const warnings = safeDiff.warnings;
|
|
8701
|
-
const expectedPlanCommitment = (0,
|
|
9023
|
+
const expectedPlanCommitment = (0, import_tool_contract10.publicationCommitment)(profile === 2 ? "planV2" : "plan", {
|
|
8702
9024
|
candidateCommitment,
|
|
8703
9025
|
baseCommitment: plan.baseCommitment,
|
|
8704
9026
|
connectorId,
|
|
@@ -8726,6 +9048,7 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8726
9048
|
throw responseInvalid("publication_plan_gate_inconsistent", messages);
|
|
8727
9049
|
}
|
|
8728
9050
|
return {
|
|
9051
|
+
...profile === 2 ? { reviewProfile: 2 } : {},
|
|
8729
9052
|
requestId: plan.requestId,
|
|
8730
9053
|
environment: "production",
|
|
8731
9054
|
connectorId,
|
|
@@ -8751,7 +9074,7 @@ function parseToolResults(value, messages) {
|
|
|
8751
9074
|
}
|
|
8752
9075
|
const tools = value.map((candidate) => {
|
|
8753
9076
|
const tool = asRecord4(candidate);
|
|
8754
|
-
if (!tool || !hasExactKeys3(tool, ["toolName", "operation", "toolId", "versionId", "version"]) || !(0,
|
|
9077
|
+
if (!tool || !hasExactKeys3(tool, ["toolName", "operation", "toolId", "versionId", "version"]) || !(0, import_tool_contract10.isSafeToolName)(tool.toolName) || tool.operation !== "create" && tool.operation !== "update" || !isCanonicalUuid(tool.toolId) || !isCanonicalUuid(tool.versionId) || typeof tool.version !== "number" || !Number.isSafeInteger(tool.version) || tool.version < 1) {
|
|
8755
9078
|
throw responseInvalid("publication_result_tool_invalid", messages);
|
|
8756
9079
|
}
|
|
8757
9080
|
const operation = tool.operation;
|
|
@@ -8808,7 +9131,7 @@ function parsePublicationResult(value, plan, messages, expectedPublicationId) {
|
|
|
8808
9131
|
function parseConfirmation(value, messages) {
|
|
8809
9132
|
if (value === null) return null;
|
|
8810
9133
|
const confirmation = asRecord4(value);
|
|
8811
|
-
if (!confirmation || !hasExactKeys3(confirmation, ["confirmationId", "signature", "confirmed"]) || !isCanonicalUuid(confirmation.confirmationId) || typeof confirmation.signature !== "string" || !
|
|
9134
|
+
if (!confirmation || !hasExactKeys3(confirmation, ["confirmationId", "signature", "confirmed"]) || !isCanonicalUuid(confirmation.confirmationId) || typeof confirmation.signature !== "string" || !import_tool_contract10.PUBLICATION_CONFIRMATION_SIGNATURE_RE.test(confirmation.signature) || confirmation.confirmed !== true) {
|
|
8812
9135
|
throw responseInvalid("publication_confirmation_invalid", messages);
|
|
8813
9136
|
}
|
|
8814
9137
|
return {
|
|
@@ -8853,8 +9176,36 @@ function typedStatus2(error) {
|
|
|
8853
9176
|
const status = error.status;
|
|
8854
9177
|
return typeof status === "number" && Number.isInteger(status) && status >= 100 && status <= 599 ? status : void 0;
|
|
8855
9178
|
}
|
|
8856
|
-
function
|
|
9179
|
+
function typedPublicationReason(error, code) {
|
|
9180
|
+
if (error === null || typeof error !== "object") return void 0;
|
|
9181
|
+
const status = typedStatus2(error);
|
|
9182
|
+
if (status === void 0 || status < 400 || status > 499) return void 0;
|
|
9183
|
+
const reason = error.publicationReason;
|
|
9184
|
+
return isPublicationErrorReasonFor(code, reason) ? reason : void 0;
|
|
9185
|
+
}
|
|
9186
|
+
function publicationReasonText(reason, schemaReviewMessages) {
|
|
9187
|
+
switch (reason) {
|
|
9188
|
+
case "publication_schema_review_too_large":
|
|
9189
|
+
return schemaReviewMessages.schemaReviewTooLarge;
|
|
9190
|
+
case "publication_review_profile_invalid":
|
|
9191
|
+
return schemaReviewMessages.reviewProfileInvalid;
|
|
9192
|
+
case "schema_review_receipt_mismatch":
|
|
9193
|
+
return schemaReviewMessages.receiptMismatch;
|
|
9194
|
+
case "publication_plan_stale":
|
|
9195
|
+
return schemaReviewMessages.planStale;
|
|
9196
|
+
}
|
|
9197
|
+
}
|
|
9198
|
+
function remoteError(error, phase, messages, schemaReviewMessages) {
|
|
8857
9199
|
const code = typedCode2(error) ?? "AP_NETWORK_ERROR";
|
|
9200
|
+
const publicationReason = schemaReviewMessages === void 0 ? void 0 : typedPublicationReason(error, code);
|
|
9201
|
+
if (publicationReason !== void 0 && schemaReviewMessages !== void 0) {
|
|
9202
|
+
return schemaReviewFailure(
|
|
9203
|
+
code,
|
|
9204
|
+
publicationReason,
|
|
9205
|
+
publicationReasonText(publicationReason, schemaReviewMessages),
|
|
9206
|
+
typedStatus2(error)
|
|
9207
|
+
);
|
|
9208
|
+
}
|
|
8858
9209
|
return new PublishCommandError(
|
|
8859
9210
|
code,
|
|
8860
9211
|
`${phase}_failed`,
|
|
@@ -8916,6 +9267,42 @@ function writeSafeJson(writer, value) {
|
|
|
8916
9267
|
function writePlan(writer, plan) {
|
|
8917
9268
|
writeSafeJson(writer, { phase: "plan", ...plan });
|
|
8918
9269
|
}
|
|
9270
|
+
function writeSchemaReviewSummary(writer, plan, schemaReviewMessages) {
|
|
9271
|
+
if (plan.reviewProfile !== 2) return;
|
|
9272
|
+
const reviewed = plan.tools.filter((tool) => (tool.schemaReview?.enums.length ?? 0) > 0);
|
|
9273
|
+
if (reviewed.length === 0) return;
|
|
9274
|
+
interactive(writer, schemaReviewMessages.heading);
|
|
9275
|
+
for (const tool of reviewed) {
|
|
9276
|
+
const review = tool.schemaReview;
|
|
9277
|
+
if (!review) continue;
|
|
9278
|
+
const count = (change) => review.enums.filter((entry) => entry.change === change).length;
|
|
9279
|
+
interactive(
|
|
9280
|
+
writer,
|
|
9281
|
+
schemaReviewMessages.toolSummary({
|
|
9282
|
+
toolName: terminalSafeText(tool.toolName),
|
|
9283
|
+
total: review.enums.length,
|
|
9284
|
+
added: count("added"),
|
|
9285
|
+
changed: count("changed"),
|
|
9286
|
+
removed: count("removed"),
|
|
9287
|
+
unchanged: count("unchanged"),
|
|
9288
|
+
valueReviewRequired: review.humanValueReviewRequired
|
|
9289
|
+
})
|
|
9290
|
+
);
|
|
9291
|
+
}
|
|
9292
|
+
if (reviewed.some((tool) => tool.schemaReview?.humanValueReviewRequired === true)) {
|
|
9293
|
+
interactive(writer, schemaReviewMessages.valueReviewInWebAdmin);
|
|
9294
|
+
}
|
|
9295
|
+
}
|
|
9296
|
+
function candidateNeedsReviewProfile2(candidateContract) {
|
|
9297
|
+
return (0, import_tool_contract10.selectPublicationReviewProfile)({
|
|
9298
|
+
requestedProfile: CLI_PUBLICATION_REVIEW_PROFILE,
|
|
9299
|
+
candidateContract,
|
|
9300
|
+
currentTools: []
|
|
9301
|
+
}) === 2;
|
|
9302
|
+
}
|
|
9303
|
+
function applyPublicationWithProfile(client, projectId, idempotencyKey, body, session) {
|
|
9304
|
+
return session.kind === "negotiated" ? client.applyPublication(projectId, idempotencyKey, body, REVIEW_PROFILE_REQUEST) : client.applyPublication(projectId, idempotencyKey, body);
|
|
9305
|
+
}
|
|
8919
9306
|
function writeResult(writer, result) {
|
|
8920
9307
|
writeSafeJson(writer, { phase: "result", ...result });
|
|
8921
9308
|
}
|
|
@@ -8931,11 +9318,11 @@ function freezeJson(value) {
|
|
|
8931
9318
|
return value;
|
|
8932
9319
|
}
|
|
8933
9320
|
function prepareCandidate(project) {
|
|
8934
|
-
const canonical = (0,
|
|
9321
|
+
const canonical = (0, import_tool_contract10.assertCanonicalPublicationSize)(project.contract.root);
|
|
8935
9322
|
const candidateContract = freezeJson(JSON.parse(canonical));
|
|
8936
9323
|
return {
|
|
8937
9324
|
candidateContract,
|
|
8938
|
-
candidateCommitment: (0,
|
|
9325
|
+
candidateCommitment: (0, import_tool_contract10.publicationCommitment)("candidate", candidateContract)
|
|
8939
9326
|
};
|
|
8940
9327
|
}
|
|
8941
9328
|
function loadPublicationProject(loadProject, cwd, messages = DEFAULT_PUBLISH_MESSAGES) {
|
|
@@ -8969,15 +9356,15 @@ function assertManifestProject(project, requestedProjectId, messages = DEFAULT_P
|
|
|
8969
9356
|
}
|
|
8970
9357
|
function buildLocalPublicationCandidate(project, connectorId, messages = DEFAULT_PUBLISH_MESSAGES) {
|
|
8971
9358
|
const candidate = prepareCandidate(project);
|
|
8972
|
-
const localToolNames = project.contract.tools.map((tool) => (0,
|
|
8973
|
-
if (localToolNames.some((name) => !(0,
|
|
9359
|
+
const localToolNames = project.contract.tools.map((tool) => (0, import_tool_contract10.toolName)(tool));
|
|
9360
|
+
if (localToolNames.some((name) => !(0, import_tool_contract10.isSafeToolName)(name))) {
|
|
8974
9361
|
throw new PublishCommandError(
|
|
8975
9362
|
"AP_INPUT_INVALID",
|
|
8976
9363
|
"publication_candidate_tool_invalid",
|
|
8977
9364
|
messages.failure("publication_candidate_tool_invalid")
|
|
8978
9365
|
);
|
|
8979
9366
|
}
|
|
8980
|
-
const expectedToolNames = localToolNames.sort(
|
|
9367
|
+
const expectedToolNames = localToolNames.sort(import_tool_contract10.comparePublicationUnicodeCodePoints);
|
|
8981
9368
|
return {
|
|
8982
9369
|
planRequest: {
|
|
8983
9370
|
environment: "production",
|
|
@@ -9008,7 +9395,13 @@ async function sendInitialApplyWithSameAnchorRetry(input) {
|
|
|
9008
9395
|
for (let attempt = 0; attempt < INITIAL_APPLY_MAX_ATTEMPTS; attempt += 1) {
|
|
9009
9396
|
try {
|
|
9010
9397
|
const result = parsePublicationResult(
|
|
9011
|
-
await
|
|
9398
|
+
await applyPublicationWithProfile(
|
|
9399
|
+
input.client,
|
|
9400
|
+
input.projectId,
|
|
9401
|
+
input.idempotencyKey,
|
|
9402
|
+
input.body,
|
|
9403
|
+
input.session
|
|
9404
|
+
),
|
|
9012
9405
|
input.plan,
|
|
9013
9406
|
input.messages
|
|
9014
9407
|
);
|
|
@@ -9034,7 +9427,7 @@ async function sendInitialApplyWithSameAnchorRetry(input) {
|
|
|
9034
9427
|
return { kind: "confirmation_required", details: confirmationRequired };
|
|
9035
9428
|
}
|
|
9036
9429
|
if (!malformedConfirmationAnchor && !initialApplyResultMayBeUnknown(error)) {
|
|
9037
|
-
throw remoteError(error, "initial_apply", input.messages);
|
|
9430
|
+
throw remoteError(error, "initial_apply", input.messages, input.schemaReviewMessages);
|
|
9038
9431
|
}
|
|
9039
9432
|
if (attempt === INITIAL_APPLY_MAX_ATTEMPTS - 1) {
|
|
9040
9433
|
throw new PublishCommandError(
|
|
@@ -9159,7 +9552,7 @@ async function pollPublication(client, projectId, details, plan, writer, runtime
|
|
|
9159
9552
|
}
|
|
9160
9553
|
throw confirmationStopped("AP_CONFIRMATION_EXPIRED", "publication_poll_attempt_limit", messages);
|
|
9161
9554
|
}
|
|
9162
|
-
async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAULT_PUBLISH_MESSAGES, scopeRegistrationMessages = DEFAULT_SCOPE_REGISTRATION_MESSAGES2) {
|
|
9555
|
+
async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAULT_PUBLISH_MESSAGES, scopeRegistrationMessages = DEFAULT_SCOPE_REGISTRATION_MESSAGES2, schemaReviewMessages = DEFAULT_SCHEMA_REVIEW_MESSAGES) {
|
|
9163
9556
|
const normalized = normalizePublishOptions(options, messages);
|
|
9164
9557
|
const project = loadPublicationProject(runtime.loadProject, cwd, messages);
|
|
9165
9558
|
const projectId = project.manifest.project_id;
|
|
@@ -9180,18 +9573,25 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
9180
9573
|
const client = runtime.createClient(normalized.profile);
|
|
9181
9574
|
let rawPlan;
|
|
9182
9575
|
try {
|
|
9183
|
-
rawPlan = await client.planPublication(projectId, planRequest);
|
|
9576
|
+
rawPlan = await client.planPublication(projectId, planRequest, REVIEW_PROFILE_REQUEST);
|
|
9184
9577
|
} catch (error) {
|
|
9185
|
-
throw remoteError(error, "plan", messages);
|
|
9578
|
+
throw remoteError(error, "plan", messages, schemaReviewMessages);
|
|
9186
9579
|
}
|
|
9580
|
+
const negotiated = negotiateReviewProfile(rawPlan, messages, schemaReviewMessages);
|
|
9581
|
+
const session = negotiated.session;
|
|
9187
9582
|
const plan = parsePlan(
|
|
9188
|
-
|
|
9583
|
+
negotiated.body,
|
|
9189
9584
|
connectorId,
|
|
9190
9585
|
planRequest.candidateCommitment,
|
|
9191
9586
|
expectedToolNames,
|
|
9587
|
+
session.profile,
|
|
9192
9588
|
messages
|
|
9193
9589
|
);
|
|
9194
9590
|
writePlan(writer, plan);
|
|
9591
|
+
writeSchemaReviewSummary(writer, plan, schemaReviewMessages);
|
|
9592
|
+
if (session.kind === "legacy" && plan.blockedReasons.includes("opaque_change") && candidateNeedsReviewProfile2(planRequest.candidateContract)) {
|
|
9593
|
+
interactive(writer, schemaReviewMessages.adminApiUpdatePending);
|
|
9594
|
+
}
|
|
9195
9595
|
if (plan.blockedReasons.includes("connector_mismatch")) {
|
|
9196
9596
|
interactive(writer, messages.connectorMismatchRemediation);
|
|
9197
9597
|
}
|
|
@@ -9222,7 +9622,9 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
9222
9622
|
idempotencyKey,
|
|
9223
9623
|
body: initialApplyRequest,
|
|
9224
9624
|
plan,
|
|
9225
|
-
|
|
9625
|
+
session,
|
|
9626
|
+
messages,
|
|
9627
|
+
schemaReviewMessages
|
|
9226
9628
|
});
|
|
9227
9629
|
let details;
|
|
9228
9630
|
if (initial.kind === "response") {
|
|
@@ -9251,7 +9653,13 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
9251
9653
|
}
|
|
9252
9654
|
try {
|
|
9253
9655
|
const result = parsePublicationResult(
|
|
9254
|
-
await
|
|
9656
|
+
await applyPublicationWithProfile(
|
|
9657
|
+
client,
|
|
9658
|
+
projectId,
|
|
9659
|
+
idempotencyKey,
|
|
9660
|
+
applyRequest(decision.confirmation),
|
|
9661
|
+
session
|
|
9662
|
+
),
|
|
9255
9663
|
plan,
|
|
9256
9664
|
messages,
|
|
9257
9665
|
details.publicationId
|
|
@@ -9261,7 +9669,7 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
9261
9669
|
} catch (error) {
|
|
9262
9670
|
if (error instanceof PublishCommandError && error.code === "AP_RESPONSE_INVALID") {
|
|
9263
9671
|
} else if (!approvedApplyResultMayBeUnknown(error)) {
|
|
9264
|
-
throw remoteError(error, "approved_apply", messages);
|
|
9672
|
+
throw remoteError(error, "approved_apply", messages, schemaReviewMessages);
|
|
9265
9673
|
}
|
|
9266
9674
|
}
|
|
9267
9675
|
const recovered = await pollPublication(
|
|
@@ -9284,7 +9692,7 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
9284
9692
|
}
|
|
9285
9693
|
writeResult(writer, recovered.result);
|
|
9286
9694
|
}
|
|
9287
|
-
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) {
|
|
9695
|
+
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) {
|
|
9288
9696
|
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) => {
|
|
9289
9697
|
await runPublishCommand(
|
|
9290
9698
|
commandOptions,
|
|
@@ -9292,7 +9700,8 @@ function registerPublish(program, writer, cwd, createClient, description2 = "Too
|
|
|
9292
9700
|
cwd(),
|
|
9293
9701
|
runtime,
|
|
9294
9702
|
messages,
|
|
9295
|
-
scopeRegistrationMessages
|
|
9703
|
+
scopeRegistrationMessages,
|
|
9704
|
+
schemaReviewMessages
|
|
9296
9705
|
);
|
|
9297
9706
|
});
|
|
9298
9707
|
}
|
|
@@ -9312,8 +9721,8 @@ function isUrl(value) {
|
|
|
9312
9721
|
function field(meta, snake, camel) {
|
|
9313
9722
|
return snake in meta ? meta[snake] : meta[camel];
|
|
9314
9723
|
}
|
|
9315
|
-
function validateOAuthMetadata(meta, locale =
|
|
9316
|
-
const messages =
|
|
9724
|
+
function validateOAuthMetadata(meta, locale = import_localization12.DEFAULT_LOCALE) {
|
|
9725
|
+
const messages = import_localization12.CLI_MESSAGES[locale].oauth;
|
|
9317
9726
|
const results = [];
|
|
9318
9727
|
if (!meta || typeof meta !== "object" || Array.isArray(meta)) {
|
|
9319
9728
|
return {
|
|
@@ -9384,7 +9793,7 @@ var RESOURCE_NOT_FOUND_CODES = /* @__PURE__ */ new Set([
|
|
|
9384
9793
|
"AP_TOOL_VERSION_NOT_FOUND"
|
|
9385
9794
|
]);
|
|
9386
9795
|
function createOAuthScopeRegisterRuntime(createClient = (profile) => createAdminApiClient({ profile })) {
|
|
9387
|
-
return { createClient, loadProject: loadDevProject, randomUuid: () => (0,
|
|
9796
|
+
return { createClient, loadProject: loadDevProject, randomUuid: () => (0, import_node_crypto14.randomUUID)() };
|
|
9388
9797
|
}
|
|
9389
9798
|
var OAuthScopeRegistrationCommandError = class extends Error {
|
|
9390
9799
|
constructor(code, reason, message, status) {
|
|
@@ -9407,9 +9816,9 @@ function parseDraftOption(value, messages) {
|
|
|
9407
9816
|
}
|
|
9408
9817
|
return { toolId, versionId };
|
|
9409
9818
|
}
|
|
9410
|
-
function normalizeOAuthScopeRegisterOptions(options, locale =
|
|
9411
|
-
const messages =
|
|
9412
|
-
const cliMessages =
|
|
9819
|
+
function normalizeOAuthScopeRegisterOptions(options, locale = import_localization12.DEFAULT_LOCALE) {
|
|
9820
|
+
const messages = import_localization12.OAUTH_SCOPE_REGISTRATION_MESSAGES[locale].cli;
|
|
9821
|
+
const cliMessages = import_localization12.CLI_MESSAGES[locale];
|
|
9413
9822
|
const apply = options.apply === true;
|
|
9414
9823
|
if (options.yes === true && !apply) throw new UsageError(messages.yesRequiresApply);
|
|
9415
9824
|
if (apply && options.yes !== true) {
|
|
@@ -9436,8 +9845,8 @@ function normalizeOAuthScopeRegisterOptions(options, locale = import_localizatio
|
|
|
9436
9845
|
if (options.connector !== void 0) throw new UsageError(messages.draftConnectorConflict);
|
|
9437
9846
|
if (options.project === void 0) throw new UsageError(messages.draftRequiresProject);
|
|
9438
9847
|
const projectId = canonicalUuidOption(options.project, "--project", cliMessages.publish);
|
|
9439
|
-
const drafts = rawDrafts.map((value) => parseDraftOption(value, messages)).sort((left, right) => (0,
|
|
9440
|
-
if (drafts.length >
|
|
9848
|
+
const drafts = rawDrafts.map((value) => parseDraftOption(value, messages)).sort((left, right) => (0, import_tool_contract11.comparePublicationUnicodeCodePoints)(left.toolId, right.toolId));
|
|
9849
|
+
if (drafts.length > import_tool_contract11.OAUTH_SCOPE_REGISTRATION_MAX_DRAFTS || drafts.some((draft, index) => index > 0 && drafts[index - 1]?.toolId === draft.toolId)) {
|
|
9441
9850
|
throw new UsageError(messages.draftInvalid);
|
|
9442
9851
|
}
|
|
9443
9852
|
return { kind: "saved_drafts", projectId, drafts, apply, profile };
|
|
@@ -9554,8 +9963,8 @@ async function projectAccessibility(client, projectId, error) {
|
|
|
9554
9963
|
}
|
|
9555
9964
|
}
|
|
9556
9965
|
function localCandidateSource(normalized, cwd, runtime, locale) {
|
|
9557
|
-
const messages =
|
|
9558
|
-
const publishMessages =
|
|
9966
|
+
const messages = import_localization12.OAUTH_SCOPE_REGISTRATION_MESSAGES[locale].cli;
|
|
9967
|
+
const publishMessages = import_localization12.CLI_MESSAGES[locale].publish;
|
|
9559
9968
|
const project = loadPublicationProject(runtime.loadProject, cwd, publishMessages);
|
|
9560
9969
|
const projectId = assertManifestProject(project, normalized.projectId, publishMessages);
|
|
9561
9970
|
const connectorId = normalized.connectorId ?? project.manifest.connector_id;
|
|
@@ -9564,7 +9973,7 @@ function localCandidateSource(normalized, cwd, runtime, locale) {
|
|
|
9564
9973
|
try {
|
|
9565
9974
|
candidate = buildLocalPublicationCandidate(project, connectorId, publishMessages);
|
|
9566
9975
|
} catch (error) {
|
|
9567
|
-
if (error instanceof
|
|
9976
|
+
if (error instanceof import_tool_contract11.PublicationCanonicalizationError && error.reason === "publication_value_too_large") {
|
|
9568
9977
|
throw new OAuthScopeRegistrationCommandError(
|
|
9569
9978
|
"AP_INPUT_INVALID",
|
|
9570
9979
|
"publication_candidate_too_large",
|
|
@@ -9584,8 +9993,8 @@ function localCandidateSource(normalized, cwd, runtime, locale) {
|
|
|
9584
9993
|
expectedToolNames: candidate.expectedToolNames
|
|
9585
9994
|
};
|
|
9586
9995
|
}
|
|
9587
|
-
async function runOAuthScopeRegisterCommand(options, writer, cwd, runtime, locale =
|
|
9588
|
-
const messages =
|
|
9996
|
+
async function runOAuthScopeRegisterCommand(options, writer, cwd, runtime, locale = import_localization12.DEFAULT_LOCALE) {
|
|
9997
|
+
const messages = import_localization12.OAUTH_SCOPE_REGISTRATION_MESSAGES[locale];
|
|
9589
9998
|
const normalized = normalizeOAuthScopeRegisterOptions(options, locale);
|
|
9590
9999
|
const target = normalized.kind === "saved_drafts" ? {
|
|
9591
10000
|
projectId: normalized.projectId,
|
|
@@ -9633,7 +10042,7 @@ async function runOAuthScopeRegisterCommand(options, writer, cwd, runtime, local
|
|
|
9633
10042
|
throw new OAuthScopeRegistrationCommandError(
|
|
9634
10043
|
"AP_NETWORK_ERROR",
|
|
9635
10044
|
"secure_random_invalid",
|
|
9636
|
-
|
|
10045
|
+
import_localization12.CLI_MESSAGES[locale].publish.failure("secure_random_invalid")
|
|
9637
10046
|
);
|
|
9638
10047
|
}
|
|
9639
10048
|
let applied;
|
|
@@ -9663,7 +10072,7 @@ function upstreamOAuthWizardUrl(profile, projectId, connectorId) {
|
|
|
9663
10072
|
return url.toString();
|
|
9664
10073
|
}
|
|
9665
10074
|
async function loadOAuthMetadata(opts, locale) {
|
|
9666
|
-
const messages =
|
|
10075
|
+
const messages = import_localization12.CLI_MESSAGES[locale];
|
|
9667
10076
|
if (opts.file && opts.issuer) {
|
|
9668
10077
|
throw new UsageError("--file \u3068 --issuer \u306F\u540C\u6642\u306B\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093");
|
|
9669
10078
|
}
|
|
@@ -9674,13 +10083,13 @@ async function loadOAuthMetadata(opts, locale) {
|
|
|
9674
10083
|
throw new UsageError(messages.oauth.fileRequired);
|
|
9675
10084
|
}
|
|
9676
10085
|
try {
|
|
9677
|
-
return JSON.parse((0,
|
|
10086
|
+
return JSON.parse((0, import_node_fs13.readFileSync)(opts.file, "utf8"));
|
|
9678
10087
|
} catch (error) {
|
|
9679
10088
|
throw new UsageError(messages.oauth.metadataReadFailed(error.message));
|
|
9680
10089
|
}
|
|
9681
10090
|
}
|
|
9682
10091
|
async function runOAuthMetadataValidate(opts, writer, locale) {
|
|
9683
|
-
const messages =
|
|
10092
|
+
const messages = import_localization12.CLI_MESSAGES[locale];
|
|
9684
10093
|
const parsed = await loadOAuthMetadata(opts, locale);
|
|
9685
10094
|
const report = validateOAuthMetadata(parsed, locale);
|
|
9686
10095
|
json(writer, report.results);
|
|
@@ -9691,8 +10100,8 @@ async function runOAuthMetadataValidate(opts, writer, locale) {
|
|
|
9691
10100
|
info(writer, messages.oauth.metadataOk);
|
|
9692
10101
|
}
|
|
9693
10102
|
}
|
|
9694
|
-
function registerOauth(program, writer, locale =
|
|
9695
|
-
const messages =
|
|
10103
|
+
function registerOauth(program, writer, locale = import_localization12.DEFAULT_LOCALE, dependencies = {}) {
|
|
10104
|
+
const messages = import_localization12.CLI_MESSAGES[locale];
|
|
9696
10105
|
const oauth = program.command("oauth").description(messages.oauth.commandDescription);
|
|
9697
10106
|
oauth.command("init").description(messages.oauth.initDescription).requiredOption("--provider <name>", messages.oauth.providerOption).action((opts) => {
|
|
9698
10107
|
info(writer, messages.oauth.templateHeading(opts.provider));
|
|
@@ -9735,7 +10144,7 @@ function registerOauth(program, writer, locale = import_localization10.DEFAULT_L
|
|
|
9735
10144
|
});
|
|
9736
10145
|
json(writer, result);
|
|
9737
10146
|
});
|
|
9738
|
-
const registration =
|
|
10147
|
+
const registration = import_localization12.OAUTH_SCOPE_REGISTRATION_MESSAGES[locale].cli;
|
|
9739
10148
|
const scopeRegisterRuntime = dependencies.scopeRegisterRuntime ?? createOAuthScopeRegisterRuntime();
|
|
9740
10149
|
const cwd = dependencies.cwd ?? (() => process.cwd());
|
|
9741
10150
|
scopes.command("register").description(registration.commandDescription).option("--project <project-uuid>", registration.projectOption).option("--connector <connector-uuid>", registration.connectorOption).option(
|
|
@@ -9839,11 +10248,11 @@ function registerOauth(program, writer, locale = import_localization10.DEFAULT_L
|
|
|
9839
10248
|
}
|
|
9840
10249
|
|
|
9841
10250
|
// src/commands/openapi.ts
|
|
9842
|
-
var
|
|
9843
|
-
var
|
|
9844
|
-
var
|
|
10251
|
+
var import_node_crypto15 = require("crypto");
|
|
10252
|
+
var import_node_path14 = require("path");
|
|
10253
|
+
var import_tool_contract12 = require("@andpipes/tool-contract");
|
|
9845
10254
|
function createOpenApiImportRuntime(createClient = (profile) => createAdminApiClient({ profile })) {
|
|
9846
|
-
return { createClient, idempotencyKey:
|
|
10255
|
+
return { createClient, idempotencyKey: import_node_crypto15.randomUUID };
|
|
9847
10256
|
}
|
|
9848
10257
|
function normalizedOptions(options) {
|
|
9849
10258
|
if (!options.file || !options.project || !options.connector) {
|
|
@@ -9899,8 +10308,8 @@ async function runOpenApiImportCommand(options, writer, cwd, runtime = createOpe
|
|
|
9899
10308
|
if (normalized.apply && !/^[a-f0-9]{64}$/.test(normalized.planCommitment ?? "")) {
|
|
9900
10309
|
throw new UsageError("--apply \u306B\u306Fpreview\u3067\u5F97\u305F --plan-commitment \u304C\u5FC5\u9808\u3067\u3059");
|
|
9901
10310
|
}
|
|
9902
|
-
const snapshot = readBoundedLocalFileSnapshot((0,
|
|
9903
|
-
maxBytes:
|
|
10311
|
+
const snapshot = readBoundedLocalFileSnapshot((0, import_node_path14.resolve)(cwd, normalized.file), {
|
|
10312
|
+
maxBytes: import_tool_contract12.OPENAPI_IMPORT_MAX_SOURCE_BYTES,
|
|
9904
10313
|
root: cwd
|
|
9905
10314
|
});
|
|
9906
10315
|
const baseRequest = {
|
|
@@ -9921,7 +10330,7 @@ async function runOpenApiImportCommand(options, writer, cwd, runtime = createOpe
|
|
|
9921
10330
|
if (normalized.sideEffectFree.length > 0) {
|
|
9922
10331
|
if (normalized.apply) {
|
|
9923
10332
|
try {
|
|
9924
|
-
const unclassified = (0,
|
|
10333
|
+
const unclassified = (0, import_tool_contract12.importOpenApi)(snapshot.text, {
|
|
9925
10334
|
format: normalized.format,
|
|
9926
10335
|
baseUrl: normalized.baseUrl,
|
|
9927
10336
|
serviceName: normalized.serviceName,
|
|
@@ -9932,7 +10341,7 @@ async function runOpenApiImportCommand(options, writer, cwd, runtime = createOpe
|
|
|
9932
10341
|
unclassified.operations
|
|
9933
10342
|
);
|
|
9934
10343
|
} catch (error) {
|
|
9935
|
-
if (error instanceof
|
|
10344
|
+
if (error instanceof import_tool_contract12.OpenApiImportError) {
|
|
9936
10345
|
throw new UsageError(`OpenAPI\u304B\u3089Tool Contract\u3092\u751F\u6210\u3067\u304D\u307E\u305B\u3093: ${error.message}`);
|
|
9937
10346
|
}
|
|
9938
10347
|
throw error;
|
|
@@ -9987,15 +10396,15 @@ function registerOpenApi(program, writer, cwd, runtime = createOpenApiImportRunt
|
|
|
9987
10396
|
}
|
|
9988
10397
|
|
|
9989
10398
|
// src/commands/review-package.ts
|
|
9990
|
-
var
|
|
10399
|
+
var import_localization13 = require("@andpipes/localization");
|
|
9991
10400
|
var TARGETS = ["chatgpt", "claude", "generic_mcp"];
|
|
9992
|
-
function assertTarget(value, locale =
|
|
10401
|
+
function assertTarget(value, locale = import_localization13.DEFAULT_LOCALE) {
|
|
9993
10402
|
if (!TARGETS.includes(value)) {
|
|
9994
|
-
throw new UsageError(
|
|
10403
|
+
throw new UsageError(import_localization13.CLI_MESSAGES[locale].reviewPackage.invalidTarget(value, TARGETS));
|
|
9995
10404
|
}
|
|
9996
10405
|
}
|
|
9997
|
-
function registerReviewPackage(program, writer, locale =
|
|
9998
|
-
const messages =
|
|
10406
|
+
function registerReviewPackage(program, writer, locale = import_localization13.DEFAULT_LOCALE, cwd = () => process.cwd()) {
|
|
10407
|
+
const messages = import_localization13.CLI_MESSAGES[locale];
|
|
9999
10408
|
const reviewPackage = program.command("review-package").description(messages.reviewPackage.commandDescription);
|
|
10000
10409
|
reviewPackage.command("generate").description(messages.reviewPackage.generateDescription).requiredOption("--project <project>", messages.common.projectOption).requiredOption("--package-version <version>", messages.reviewPackage.packageVersionOption).option("--target <target>", messages.reviewPackage.targetOption).option(
|
|
10001
10410
|
"--from-template",
|
|
@@ -10056,65 +10465,13 @@ function registerReviewPackage(program, writer, locale = import_localization11.D
|
|
|
10056
10465
|
});
|
|
10057
10466
|
}
|
|
10058
10467
|
|
|
10059
|
-
// src/commands/validate.ts
|
|
10060
|
-
var import_node_fs12 = require("fs");
|
|
10061
|
-
var import_node_path13 = require("path");
|
|
10062
|
-
var import_localization12 = require("@andpipes/localization");
|
|
10063
|
-
function resolveContractPath(file, cwd, locale = import_localization12.DEFAULT_LOCALE) {
|
|
10064
|
-
const messages = import_localization12.CLI_MESSAGES[locale].validate;
|
|
10065
|
-
if (file) {
|
|
10066
|
-
const abs = (0, import_node_path13.resolve)(cwd, file);
|
|
10067
|
-
if (!(0, import_node_fs12.existsSync)(abs)) {
|
|
10068
|
-
throw new UsageError(messages.fileNotFound(file));
|
|
10069
|
-
}
|
|
10070
|
-
return abs;
|
|
10071
|
-
}
|
|
10072
|
-
for (const candidate of import_tool_contract4.CONTRACT_FILENAMES) {
|
|
10073
|
-
const abs = (0, import_node_path13.resolve)(cwd, candidate);
|
|
10074
|
-
if ((0, import_node_fs12.existsSync)(abs)) {
|
|
10075
|
-
return abs;
|
|
10076
|
-
}
|
|
10077
|
-
}
|
|
10078
|
-
throw new UsageError(messages.defaultFileNotFound(import_tool_contract4.CONTRACT_FILENAMES));
|
|
10079
|
-
}
|
|
10080
|
-
function loadContract(path, locale = import_localization12.DEFAULT_LOCALE) {
|
|
10081
|
-
void locale;
|
|
10082
|
-
return loadContractFile(path).contract;
|
|
10083
|
-
}
|
|
10084
|
-
function registerValidate(program, writer, cwd, locale = import_localization12.DEFAULT_LOCALE) {
|
|
10085
|
-
const text = import_localization12.LOCALIZED_TEXT[locale].cli;
|
|
10086
|
-
const messages = import_localization12.CLI_MESSAGES[locale].validate;
|
|
10087
|
-
program.command("validate").description(`${text.validateDescription} (10 checks)`).option("--file <path>", messages.fileOption).action((opts) => {
|
|
10088
|
-
const path = resolveContractPath(opts.file, cwd(), locale);
|
|
10089
|
-
const loaded = loadContractFile(path);
|
|
10090
|
-
const report = loaded.report;
|
|
10091
|
-
const publishGate = loaded.publishGate;
|
|
10092
|
-
json(writer, { checks: report.results, publishGate });
|
|
10093
|
-
const fail2 = report.results.filter((r) => r.status === "fail").length;
|
|
10094
|
-
const pending = report.results.filter((r) => r.status === "pending").length;
|
|
10095
|
-
const pass = report.results.filter((r) => r.status === "pass").length;
|
|
10096
|
-
info(
|
|
10097
|
-
writer,
|
|
10098
|
-
`${text.resultLabel}: pass=${pass} fail=${fail2} pending=${pending} (pending=${text.backendPending})`
|
|
10099
|
-
);
|
|
10100
|
-
info(
|
|
10101
|
-
writer,
|
|
10102
|
-
messages.publishGateSummary(publishGate.errors.length, publishGate.warnings.length)
|
|
10103
|
-
);
|
|
10104
|
-
if (!report.ok || !publishGate.ok) {
|
|
10105
|
-
process.exitCode = 1;
|
|
10106
|
-
info(writer, messages.failed);
|
|
10107
|
-
}
|
|
10108
|
-
});
|
|
10109
|
-
}
|
|
10110
|
-
|
|
10111
10468
|
// src/cli.ts
|
|
10112
|
-
function buildProgram(writer = defaultWriter, cwd = () => process.cwd(), locale = (0,
|
|
10113
|
-
const text =
|
|
10114
|
-
const messages =
|
|
10115
|
-
const scopeRegistrationMessages =
|
|
10469
|
+
function buildProgram(writer = defaultWriter, cwd = () => process.cwd(), locale = (0, import_localization14.normalizeLocale)(process.env.ANDPIPE_LOCALE ?? process.env.LANG)) {
|
|
10470
|
+
const text = import_localization14.LOCALIZED_TEXT[locale].cli;
|
|
10471
|
+
const messages = import_localization14.CLI_MESSAGES[locale];
|
|
10472
|
+
const scopeRegistrationMessages = import_localization14.OAUTH_SCOPE_REGISTRATION_MESSAGES[locale].cli;
|
|
10116
10473
|
const program = new import_commander.Command();
|
|
10117
|
-
program.name(CLI_NAME).description(text.description).option("--locale <locale>", messages.localeOption,
|
|
10474
|
+
program.name(CLI_NAME).description(text.description).option("--locale <locale>", messages.localeOption, import_localization14.DEFAULT_LOCALE).version(readVersion());
|
|
10118
10475
|
registerAuth(program, writer, locale);
|
|
10119
10476
|
registerAuditExport(program, writer, locale);
|
|
10120
10477
|
registerInit(
|
|
@@ -10137,6 +10494,7 @@ function buildProgram(writer = defaultWriter, cwd = () => process.cwd(), locale
|
|
|
10137
10494
|
registerDoctor(program, writer, locale);
|
|
10138
10495
|
registerLogs(program, writer, locale);
|
|
10139
10496
|
registerTemplate(program, writer, cwd);
|
|
10497
|
+
registerMuse(program, writer, cwd, locale);
|
|
10140
10498
|
registerPublish(
|
|
10141
10499
|
program,
|
|
10142
10500
|
writer,
|
|
@@ -10145,20 +10503,21 @@ function buildProgram(writer = defaultWriter, cwd = () => process.cwd(), locale
|
|
|
10145
10503
|
text.publishDescription,
|
|
10146
10504
|
void 0,
|
|
10147
10505
|
messages.publish,
|
|
10148
|
-
scopeRegistrationMessages
|
|
10506
|
+
scopeRegistrationMessages,
|
|
10507
|
+
import_localization14.PUBLICATION_SCHEMA_REVIEW_CLI_MESSAGES[locale]
|
|
10149
10508
|
);
|
|
10150
10509
|
return program;
|
|
10151
10510
|
}
|
|
10152
10511
|
function localeFromArgv(argv) {
|
|
10153
10512
|
const localeIndex = argv.indexOf("--locale");
|
|
10154
10513
|
if (localeIndex >= 0) {
|
|
10155
|
-
return (0,
|
|
10514
|
+
return (0, import_localization14.normalizeLocale)(argv[localeIndex + 1]);
|
|
10156
10515
|
}
|
|
10157
10516
|
const inlineLocale = argv.find((arg) => arg.startsWith("--locale="));
|
|
10158
10517
|
if (inlineLocale) {
|
|
10159
|
-
return (0,
|
|
10518
|
+
return (0, import_localization14.normalizeLocale)(inlineLocale.slice("--locale=".length));
|
|
10160
10519
|
}
|
|
10161
|
-
return (0,
|
|
10520
|
+
return (0, import_localization14.normalizeLocale)(process.env.ANDPIPE_LOCALE ?? process.env.LANG);
|
|
10162
10521
|
}
|
|
10163
10522
|
async function runCli(argv, writer = defaultWriter) {
|
|
10164
10523
|
await buildProgram(writer, () => process.cwd(), localeFromArgv(argv)).parseAsync(argv);
|