@amaster.ai/cli 1.1.55 → 1.1.56
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/cli.cjs +149 -5
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +149 -5
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -966,6 +966,9 @@ async function tryDetectNearestApplicationType(startDir = process.cwd()) {
|
|
|
966
966
|
// src/marketplace/install.ts
|
|
967
967
|
var execFileAsync = promisify(execFile);
|
|
968
968
|
var ADDON_PROMPT_FILE_NAME = "PROMPT.md";
|
|
969
|
+
var DEFAULT_WORKFLOW_API_ENDPOINT = "http://workflow-api:5001";
|
|
970
|
+
var WORKFLOW_DATASET_ID_PATH = "/openapi/mcp/dataset-id";
|
|
971
|
+
var RAW_UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
969
972
|
var AddonInstallConflictError = class extends Error {
|
|
970
973
|
constructor(input) {
|
|
971
974
|
super(`Addon ${input.operation} has ${input.conflicts.length} conflict(s)`);
|
|
@@ -1621,12 +1624,147 @@ function buildInstalledAddonMeta(options) {
|
|
|
1621
1624
|
async function ensureParentDirectory(filePath) {
|
|
1622
1625
|
await mkdir(dirname(filePath), { recursive: true });
|
|
1623
1626
|
}
|
|
1624
|
-
async function writePlannedFiles(targetDir, planFiles) {
|
|
1627
|
+
async function writePlannedFiles(targetDir, planFiles, contentByTargetPath = /* @__PURE__ */ new Map()) {
|
|
1625
1628
|
for (const file of planFiles) {
|
|
1626
1629
|
const absoluteTargetPath = ensurePathInsideTarget(targetDir, file.targetPath);
|
|
1627
1630
|
await ensureParentDirectory(absoluteTargetPath);
|
|
1628
|
-
|
|
1631
|
+
const content = contentByTargetPath.get(file.targetPath);
|
|
1632
|
+
if (content === void 0) {
|
|
1633
|
+
await copyFile(file.sourcePath, absoluteTargetPath);
|
|
1634
|
+
} else {
|
|
1635
|
+
await writeFile(absoluteTargetPath, content);
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
function normalizeNonEmptyString(value) {
|
|
1640
|
+
const normalized = value?.trim();
|
|
1641
|
+
return normalized || void 0;
|
|
1642
|
+
}
|
|
1643
|
+
function isWorkflowYamlFile(file) {
|
|
1644
|
+
return file.memberType === "workflow" && /\.ya?ml$/i.test(file.targetPath);
|
|
1645
|
+
}
|
|
1646
|
+
function isDatasetIDPlaceholder(value) {
|
|
1647
|
+
const normalized = value.trim().toLowerCase().replace(/ /g, "");
|
|
1648
|
+
return [
|
|
1649
|
+
"",
|
|
1650
|
+
"__workflow_dataset_id__",
|
|
1651
|
+
"workflow_dataset_id",
|
|
1652
|
+
"workflow-dataset-id",
|
|
1653
|
+
"workflowdatasetid",
|
|
1654
|
+
"{{workflow_dataset_id}}",
|
|
1655
|
+
"${workflow_dataset_id}",
|
|
1656
|
+
"<workflow_dataset_id>",
|
|
1657
|
+
"__dataset_id__",
|
|
1658
|
+
"dataset_id",
|
|
1659
|
+
"{{dataset_id}}",
|
|
1660
|
+
"${dataset_id}",
|
|
1661
|
+
"<dataset_id>"
|
|
1662
|
+
].includes(normalized);
|
|
1663
|
+
}
|
|
1664
|
+
function datasetIDsCanBeAutoBound(value) {
|
|
1665
|
+
if (value === void 0 || value === null) {
|
|
1666
|
+
return true;
|
|
1667
|
+
}
|
|
1668
|
+
if (typeof value === "string") {
|
|
1669
|
+
return isDatasetIDPlaceholder(value);
|
|
1670
|
+
}
|
|
1671
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string" && isDatasetIDPlaceholder(item));
|
|
1672
|
+
}
|
|
1673
|
+
function bindKnowledgeRetrievalDatasetIDs(node, datasetID) {
|
|
1674
|
+
if (Array.isArray(node)) {
|
|
1675
|
+
return node.some((item) => bindKnowledgeRetrievalDatasetIDs(item, datasetID));
|
|
1676
|
+
}
|
|
1677
|
+
if (!isPlainObject(node)) {
|
|
1678
|
+
return false;
|
|
1679
|
+
}
|
|
1680
|
+
let changed = false;
|
|
1681
|
+
if (node.type === "knowledge-retrieval" && datasetIDsCanBeAutoBound(node.dataset_ids)) {
|
|
1682
|
+
node.dataset_ids = [datasetID];
|
|
1683
|
+
changed = true;
|
|
1684
|
+
}
|
|
1685
|
+
for (const value of Object.values(node)) {
|
|
1686
|
+
if (bindKnowledgeRetrievalDatasetIDs(value, datasetID)) {
|
|
1687
|
+
changed = true;
|
|
1688
|
+
}
|
|
1629
1689
|
}
|
|
1690
|
+
return changed;
|
|
1691
|
+
}
|
|
1692
|
+
function resolveWorkflowDatasetBindingContext(options) {
|
|
1693
|
+
const sandboxOrganizationCode = normalizeNonEmptyString(process.env.WORKSPACE_ORG_CODE) ?? normalizeNonEmptyString(process.env.ORG_CODE);
|
|
1694
|
+
const organizationCode = normalizeNonEmptyString(options.organizationCode) ?? sandboxOrganizationCode;
|
|
1695
|
+
if (!organizationCode) {
|
|
1696
|
+
return null;
|
|
1697
|
+
}
|
|
1698
|
+
const configuredEndpoint = normalizeNonEmptyString(process.env.AMASTER_WORKFLOW_URL) ?? normalizeNonEmptyString(process.env.WORKFLOW_API_URL);
|
|
1699
|
+
if (!configuredEndpoint && !sandboxOrganizationCode) {
|
|
1700
|
+
return null;
|
|
1701
|
+
}
|
|
1702
|
+
return {
|
|
1703
|
+
organizationCode,
|
|
1704
|
+
endpoint: (configuredEndpoint ?? DEFAULT_WORKFLOW_API_ENDPOINT).replace(/\/+$/, "")
|
|
1705
|
+
};
|
|
1706
|
+
}
|
|
1707
|
+
async function fetchWorkflowDSLDatasetID(context) {
|
|
1708
|
+
const endpoint = new URL(`${context.endpoint}${WORKFLOW_DATASET_ID_PATH}`);
|
|
1709
|
+
endpoint.searchParams.set("org_code", context.organizationCode);
|
|
1710
|
+
let response;
|
|
1711
|
+
try {
|
|
1712
|
+
response = await fetch(endpoint.toString(), { headers: { Accept: "application/json" } });
|
|
1713
|
+
} catch (error) {
|
|
1714
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1715
|
+
throw new Error(`Failed to resolve Workflow DSL dataset id: ${message}`);
|
|
1716
|
+
}
|
|
1717
|
+
if (!response.ok) {
|
|
1718
|
+
throw new Error(`Failed to resolve Workflow DSL dataset id: Workflow API returned ${response.status}`);
|
|
1719
|
+
}
|
|
1720
|
+
let payload;
|
|
1721
|
+
try {
|
|
1722
|
+
payload = await response.json();
|
|
1723
|
+
} catch {
|
|
1724
|
+
throw new Error("Failed to resolve Workflow DSL dataset id: Workflow API returned invalid JSON");
|
|
1725
|
+
}
|
|
1726
|
+
const root = isPlainObject(payload) ? payload : {};
|
|
1727
|
+
const data = isPlainObject(root.data) ? root.data : {};
|
|
1728
|
+
const datasetID = typeof root.workflow_dsl_dataset_id === "string" ? root.workflow_dsl_dataset_id.trim() : typeof data.workflow_dsl_dataset_id === "string" ? data.workflow_dsl_dataset_id.trim() : "";
|
|
1729
|
+
if (!datasetID) {
|
|
1730
|
+
throw new Error("Failed to resolve Workflow DSL dataset id: response is missing workflow_dsl_dataset_id");
|
|
1731
|
+
}
|
|
1732
|
+
if (RAW_UUID_PATTERN.test(datasetID)) {
|
|
1733
|
+
throw new Error("Failed to resolve Workflow DSL dataset id: Workflow API returned a raw UUID");
|
|
1734
|
+
}
|
|
1735
|
+
return datasetID;
|
|
1736
|
+
}
|
|
1737
|
+
async function prepareWorkflowDatasetBinding(options, plan) {
|
|
1738
|
+
const context = resolveWorkflowDatasetBindingContext(options);
|
|
1739
|
+
if (!context) {
|
|
1740
|
+
return null;
|
|
1741
|
+
}
|
|
1742
|
+
const candidates = [];
|
|
1743
|
+
for (const file of plan.files) {
|
|
1744
|
+
if (!isWorkflowYamlFile(file)) {
|
|
1745
|
+
continue;
|
|
1746
|
+
}
|
|
1747
|
+
const content = await readFile(file.sourcePath, "utf8");
|
|
1748
|
+
const parsed = YAML2.parse(content);
|
|
1749
|
+
if (bindKnowledgeRetrievalDatasetIDs(parsed, "__workflow_dataset_binding_probe__")) {
|
|
1750
|
+
candidates.push({ file, content });
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
if (!candidates.length) {
|
|
1754
|
+
return null;
|
|
1755
|
+
}
|
|
1756
|
+
const workflowDSLDatasetID = await fetchWorkflowDSLDatasetID(context);
|
|
1757
|
+
const contentByTargetPath = /* @__PURE__ */ new Map();
|
|
1758
|
+
for (const candidate of candidates) {
|
|
1759
|
+
const parsed = YAML2.parse(candidate.content);
|
|
1760
|
+
if (bindKnowledgeRetrievalDatasetIDs(parsed, workflowDSLDatasetID)) {
|
|
1761
|
+
contentByTargetPath.set(candidate.file.targetPath, YAML2.stringify(parsed));
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
return {
|
|
1765
|
+
contentByTargetPath,
|
|
1766
|
+
boundFiles: [...contentByTargetPath.keys()]
|
|
1767
|
+
};
|
|
1630
1768
|
}
|
|
1631
1769
|
async function writeAddonPromptFile(targetDir, addonName, promptContent) {
|
|
1632
1770
|
const promptTargetPath = getAddonPromptTargetPath(addonName);
|
|
@@ -2566,6 +2704,7 @@ async function materializeAddon(options) {
|
|
|
2566
2704
|
} else if (previousMeta) {
|
|
2567
2705
|
await validateUpgradeConflicts(targetDir, plan, existingMetas, previousMeta);
|
|
2568
2706
|
}
|
|
2707
|
+
const workflowDatasetBinding = await prepareWorkflowDatasetBinding(options, plan);
|
|
2569
2708
|
const removedFiles = previousMeta ? await removeObsoleteFiles(targetDir, previousMeta, new Set(plan.files.map((file) => file.targetPath))) : [];
|
|
2570
2709
|
const restoredSettingsFiles = await restoreObsoleteSettings(
|
|
2571
2710
|
targetDir,
|
|
@@ -2575,7 +2714,7 @@ async function materializeAddon(options) {
|
|
|
2575
2714
|
);
|
|
2576
2715
|
const npm = resolveInstallNpm(plan.manifest);
|
|
2577
2716
|
const packageJsonFiles = await applyNpmDependencies(targetDir, npm);
|
|
2578
|
-
await writePlannedFiles(targetDir, plan.files);
|
|
2717
|
+
await writePlannedFiles(targetDir, plan.files, workflowDatasetBinding?.contentByTargetPath);
|
|
2579
2718
|
const settingsResult = await applyPlannedSettings(targetDir, plan.settings);
|
|
2580
2719
|
const promptContent = options.promptContent?.trim() || void 0;
|
|
2581
2720
|
const promptFiles = await writeAddonPromptFile(targetDir, plan.manifest.name, promptContent);
|
|
@@ -2617,7 +2756,8 @@ async function materializeAddon(options) {
|
|
|
2617
2756
|
requirements,
|
|
2618
2757
|
missingRequirements: buildMissingRequirements(requirements),
|
|
2619
2758
|
npm,
|
|
2620
|
-
llmGuidance
|
|
2759
|
+
llmGuidance,
|
|
2760
|
+
workflowDatasetBinding: workflowDatasetBinding ? { boundFiles: workflowDatasetBinding.boundFiles } : void 0
|
|
2621
2761
|
};
|
|
2622
2762
|
}
|
|
2623
2763
|
async function installAddonFromExtractedDirectory(options) {
|
|
@@ -4318,7 +4458,8 @@ function renderAddonInstallResult(result, operation, options) {
|
|
|
4318
4458
|
version: result.meta.version,
|
|
4319
4459
|
applicationType: result.meta.applicationType
|
|
4320
4460
|
},
|
|
4321
|
-
llmGuidance: result.llmGuidance
|
|
4461
|
+
llmGuidance: result.llmGuidance,
|
|
4462
|
+
...result.workflowDatasetBinding ? { workflowDatasetBinding: result.workflowDatasetBinding } : {}
|
|
4322
4463
|
};
|
|
4323
4464
|
if (options.json) {
|
|
4324
4465
|
renderOutput(output, options);
|
|
@@ -4332,6 +4473,9 @@ function renderAddonInstallResult(result, operation, options) {
|
|
|
4332
4473
|
if (result.removedFiles.length) {
|
|
4333
4474
|
lines.push(`Removed files: ${result.removedFiles.length}`);
|
|
4334
4475
|
}
|
|
4476
|
+
if (result.workflowDatasetBinding?.boundFiles.length) {
|
|
4477
|
+
lines.push(`Bound encrypted Workflow dataset IDs: ${result.workflowDatasetBinding.boundFiles.join(", ")}`);
|
|
4478
|
+
}
|
|
4335
4479
|
if (result.llmGuidance.webRoutes?.length) {
|
|
4336
4480
|
lines.push("Next: wire web routes from llmGuidance.webRoutes.");
|
|
4337
4481
|
}
|