@amaster.ai/cli 1.1.55 → 1.1.56-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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.cjs
CHANGED
|
@@ -993,6 +993,9 @@ async function tryDetectNearestApplicationType(startDir = process.cwd()) {
|
|
|
993
993
|
// src/marketplace/install.ts
|
|
994
994
|
var execFileAsync = util.promisify(child_process.execFile);
|
|
995
995
|
var ADDON_PROMPT_FILE_NAME = "PROMPT.md";
|
|
996
|
+
var DEFAULT_WORKFLOW_API_ENDPOINT = "http://workflow-api:5001";
|
|
997
|
+
var WORKFLOW_DATASET_ID_PATH = "/openapi/mcp/dataset-id";
|
|
998
|
+
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;
|
|
996
999
|
var AddonInstallConflictError = class extends Error {
|
|
997
1000
|
constructor(input) {
|
|
998
1001
|
super(`Addon ${input.operation} has ${input.conflicts.length} conflict(s)`);
|
|
@@ -1648,12 +1651,147 @@ function buildInstalledAddonMeta(options) {
|
|
|
1648
1651
|
async function ensureParentDirectory(filePath) {
|
|
1649
1652
|
await promises$1.mkdir(path.dirname(filePath), { recursive: true });
|
|
1650
1653
|
}
|
|
1651
|
-
async function writePlannedFiles(targetDir, planFiles) {
|
|
1654
|
+
async function writePlannedFiles(targetDir, planFiles, contentByTargetPath = /* @__PURE__ */ new Map()) {
|
|
1652
1655
|
for (const file of planFiles) {
|
|
1653
1656
|
const absoluteTargetPath = ensurePathInsideTarget(targetDir, file.targetPath);
|
|
1654
1657
|
await ensureParentDirectory(absoluteTargetPath);
|
|
1655
|
-
|
|
1658
|
+
const content = contentByTargetPath.get(file.targetPath);
|
|
1659
|
+
if (content === void 0) {
|
|
1660
|
+
await promises$1.copyFile(file.sourcePath, absoluteTargetPath);
|
|
1661
|
+
} else {
|
|
1662
|
+
await promises$1.writeFile(absoluteTargetPath, content);
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
function normalizeNonEmptyString(value) {
|
|
1667
|
+
const normalized = value?.trim();
|
|
1668
|
+
return normalized || void 0;
|
|
1669
|
+
}
|
|
1670
|
+
function isWorkflowYamlFile(file) {
|
|
1671
|
+
return file.memberType === "workflow" && /\.ya?ml$/i.test(file.targetPath);
|
|
1672
|
+
}
|
|
1673
|
+
function isDatasetIDPlaceholder(value) {
|
|
1674
|
+
const normalized = value.trim().toLowerCase().replace(/ /g, "");
|
|
1675
|
+
return [
|
|
1676
|
+
"",
|
|
1677
|
+
"__workflow_dataset_id__",
|
|
1678
|
+
"workflow_dataset_id",
|
|
1679
|
+
"workflow-dataset-id",
|
|
1680
|
+
"workflowdatasetid",
|
|
1681
|
+
"{{workflow_dataset_id}}",
|
|
1682
|
+
"${workflow_dataset_id}",
|
|
1683
|
+
"<workflow_dataset_id>",
|
|
1684
|
+
"__dataset_id__",
|
|
1685
|
+
"dataset_id",
|
|
1686
|
+
"{{dataset_id}}",
|
|
1687
|
+
"${dataset_id}",
|
|
1688
|
+
"<dataset_id>"
|
|
1689
|
+
].includes(normalized);
|
|
1690
|
+
}
|
|
1691
|
+
function datasetIDsCanBeAutoBound(value) {
|
|
1692
|
+
if (value === void 0 || value === null) {
|
|
1693
|
+
return true;
|
|
1694
|
+
}
|
|
1695
|
+
if (typeof value === "string") {
|
|
1696
|
+
return isDatasetIDPlaceholder(value);
|
|
1697
|
+
}
|
|
1698
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string" && isDatasetIDPlaceholder(item));
|
|
1699
|
+
}
|
|
1700
|
+
function bindKnowledgeRetrievalDatasetIDs(node, datasetID) {
|
|
1701
|
+
if (Array.isArray(node)) {
|
|
1702
|
+
return node.some((item) => bindKnowledgeRetrievalDatasetIDs(item, datasetID));
|
|
1703
|
+
}
|
|
1704
|
+
if (!isPlainObject(node)) {
|
|
1705
|
+
return false;
|
|
1706
|
+
}
|
|
1707
|
+
let changed = false;
|
|
1708
|
+
if (node.type === "knowledge-retrieval" && datasetIDsCanBeAutoBound(node.dataset_ids)) {
|
|
1709
|
+
node.dataset_ids = [datasetID];
|
|
1710
|
+
changed = true;
|
|
1711
|
+
}
|
|
1712
|
+
for (const value of Object.values(node)) {
|
|
1713
|
+
if (bindKnowledgeRetrievalDatasetIDs(value, datasetID)) {
|
|
1714
|
+
changed = true;
|
|
1715
|
+
}
|
|
1656
1716
|
}
|
|
1717
|
+
return changed;
|
|
1718
|
+
}
|
|
1719
|
+
function resolveWorkflowDatasetBindingContext(options) {
|
|
1720
|
+
const sandboxOrganizationCode = normalizeNonEmptyString(process.env.WORKSPACE_ORG_CODE) ?? normalizeNonEmptyString(process.env.ORG_CODE);
|
|
1721
|
+
const organizationCode = normalizeNonEmptyString(options.organizationCode) ?? sandboxOrganizationCode;
|
|
1722
|
+
if (!organizationCode) {
|
|
1723
|
+
return null;
|
|
1724
|
+
}
|
|
1725
|
+
const configuredEndpoint = normalizeNonEmptyString(process.env.AMASTER_WORKFLOW_URL) ?? normalizeNonEmptyString(process.env.WORKFLOW_API_URL);
|
|
1726
|
+
if (!configuredEndpoint && !sandboxOrganizationCode) {
|
|
1727
|
+
return null;
|
|
1728
|
+
}
|
|
1729
|
+
return {
|
|
1730
|
+
organizationCode,
|
|
1731
|
+
endpoint: (configuredEndpoint ?? DEFAULT_WORKFLOW_API_ENDPOINT).replace(/\/+$/, "")
|
|
1732
|
+
};
|
|
1733
|
+
}
|
|
1734
|
+
async function fetchWorkflowDSLDatasetID(context) {
|
|
1735
|
+
const endpoint = new URL(`${context.endpoint}${WORKFLOW_DATASET_ID_PATH}`);
|
|
1736
|
+
endpoint.searchParams.set("org_code", context.organizationCode);
|
|
1737
|
+
let response;
|
|
1738
|
+
try {
|
|
1739
|
+
response = await fetch(endpoint.toString(), { headers: { Accept: "application/json" } });
|
|
1740
|
+
} catch (error) {
|
|
1741
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1742
|
+
throw new Error(`Failed to resolve Workflow DSL dataset id: ${message}`);
|
|
1743
|
+
}
|
|
1744
|
+
if (!response.ok) {
|
|
1745
|
+
throw new Error(`Failed to resolve Workflow DSL dataset id: Workflow API returned ${response.status}`);
|
|
1746
|
+
}
|
|
1747
|
+
let payload;
|
|
1748
|
+
try {
|
|
1749
|
+
payload = await response.json();
|
|
1750
|
+
} catch {
|
|
1751
|
+
throw new Error("Failed to resolve Workflow DSL dataset id: Workflow API returned invalid JSON");
|
|
1752
|
+
}
|
|
1753
|
+
const root = isPlainObject(payload) ? payload : {};
|
|
1754
|
+
const data = isPlainObject(root.data) ? root.data : {};
|
|
1755
|
+
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() : "";
|
|
1756
|
+
if (!datasetID) {
|
|
1757
|
+
throw new Error("Failed to resolve Workflow DSL dataset id: response is missing workflow_dsl_dataset_id");
|
|
1758
|
+
}
|
|
1759
|
+
if (RAW_UUID_PATTERN.test(datasetID)) {
|
|
1760
|
+
throw new Error("Failed to resolve Workflow DSL dataset id: Workflow API returned a raw UUID");
|
|
1761
|
+
}
|
|
1762
|
+
return datasetID;
|
|
1763
|
+
}
|
|
1764
|
+
async function prepareWorkflowDatasetBinding(options, plan) {
|
|
1765
|
+
const context = resolveWorkflowDatasetBindingContext(options);
|
|
1766
|
+
if (!context) {
|
|
1767
|
+
return null;
|
|
1768
|
+
}
|
|
1769
|
+
const candidates = [];
|
|
1770
|
+
for (const file of plan.files) {
|
|
1771
|
+
if (!isWorkflowYamlFile(file)) {
|
|
1772
|
+
continue;
|
|
1773
|
+
}
|
|
1774
|
+
const content = await promises$1.readFile(file.sourcePath, "utf8");
|
|
1775
|
+
const parsed = YAML2__default.default.parse(content);
|
|
1776
|
+
if (bindKnowledgeRetrievalDatasetIDs(parsed, "__workflow_dataset_binding_probe__")) {
|
|
1777
|
+
candidates.push({ file, content });
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
if (!candidates.length) {
|
|
1781
|
+
return null;
|
|
1782
|
+
}
|
|
1783
|
+
const workflowDSLDatasetID = await fetchWorkflowDSLDatasetID(context);
|
|
1784
|
+
const contentByTargetPath = /* @__PURE__ */ new Map();
|
|
1785
|
+
for (const candidate of candidates) {
|
|
1786
|
+
const parsed = YAML2__default.default.parse(candidate.content);
|
|
1787
|
+
if (bindKnowledgeRetrievalDatasetIDs(parsed, workflowDSLDatasetID)) {
|
|
1788
|
+
contentByTargetPath.set(candidate.file.targetPath, YAML2__default.default.stringify(parsed));
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
return {
|
|
1792
|
+
contentByTargetPath,
|
|
1793
|
+
boundFiles: [...contentByTargetPath.keys()]
|
|
1794
|
+
};
|
|
1657
1795
|
}
|
|
1658
1796
|
async function writeAddonPromptFile(targetDir, addonName, promptContent) {
|
|
1659
1797
|
const promptTargetPath = getAddonPromptTargetPath(addonName);
|
|
@@ -2593,6 +2731,7 @@ async function materializeAddon(options) {
|
|
|
2593
2731
|
} else if (previousMeta) {
|
|
2594
2732
|
await validateUpgradeConflicts(targetDir, plan, existingMetas, previousMeta);
|
|
2595
2733
|
}
|
|
2734
|
+
const workflowDatasetBinding = await prepareWorkflowDatasetBinding(options, plan);
|
|
2596
2735
|
const removedFiles = previousMeta ? await removeObsoleteFiles(targetDir, previousMeta, new Set(plan.files.map((file) => file.targetPath))) : [];
|
|
2597
2736
|
const restoredSettingsFiles = await restoreObsoleteSettings(
|
|
2598
2737
|
targetDir,
|
|
@@ -2602,7 +2741,7 @@ async function materializeAddon(options) {
|
|
|
2602
2741
|
);
|
|
2603
2742
|
const npm = resolveInstallNpm(plan.manifest);
|
|
2604
2743
|
const packageJsonFiles = await applyNpmDependencies(targetDir, npm);
|
|
2605
|
-
await writePlannedFiles(targetDir, plan.files);
|
|
2744
|
+
await writePlannedFiles(targetDir, plan.files, workflowDatasetBinding?.contentByTargetPath);
|
|
2606
2745
|
const settingsResult = await applyPlannedSettings(targetDir, plan.settings);
|
|
2607
2746
|
const promptContent = options.promptContent?.trim() || void 0;
|
|
2608
2747
|
const promptFiles = await writeAddonPromptFile(targetDir, plan.manifest.name, promptContent);
|
|
@@ -2644,7 +2783,8 @@ async function materializeAddon(options) {
|
|
|
2644
2783
|
requirements,
|
|
2645
2784
|
missingRequirements: buildMissingRequirements(requirements),
|
|
2646
2785
|
npm,
|
|
2647
|
-
llmGuidance
|
|
2786
|
+
llmGuidance,
|
|
2787
|
+
workflowDatasetBinding: workflowDatasetBinding ? { boundFiles: workflowDatasetBinding.boundFiles } : void 0
|
|
2648
2788
|
};
|
|
2649
2789
|
}
|
|
2650
2790
|
async function installAddonFromExtractedDirectory(options) {
|
|
@@ -4345,7 +4485,8 @@ function renderAddonInstallResult(result, operation, options) {
|
|
|
4345
4485
|
version: result.meta.version,
|
|
4346
4486
|
applicationType: result.meta.applicationType
|
|
4347
4487
|
},
|
|
4348
|
-
llmGuidance: result.llmGuidance
|
|
4488
|
+
llmGuidance: result.llmGuidance,
|
|
4489
|
+
...result.workflowDatasetBinding ? { workflowDatasetBinding: result.workflowDatasetBinding } : {}
|
|
4349
4490
|
};
|
|
4350
4491
|
if (options.json) {
|
|
4351
4492
|
renderOutput(output, options);
|
|
@@ -4359,6 +4500,9 @@ function renderAddonInstallResult(result, operation, options) {
|
|
|
4359
4500
|
if (result.removedFiles.length) {
|
|
4360
4501
|
lines.push(`Removed files: ${result.removedFiles.length}`);
|
|
4361
4502
|
}
|
|
4503
|
+
if (result.workflowDatasetBinding?.boundFiles.length) {
|
|
4504
|
+
lines.push(`Bound encrypted Workflow dataset IDs: ${result.workflowDatasetBinding.boundFiles.join(", ")}`);
|
|
4505
|
+
}
|
|
4362
4506
|
if (result.llmGuidance.webRoutes?.length) {
|
|
4363
4507
|
lines.push("Next: wire web routes from llmGuidance.webRoutes.");
|
|
4364
4508
|
}
|