@getmagical/cli 0.9.2 → 0.10.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/README.md +53 -0
- package/dist/index.js +555 -163
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1897,13 +1897,13 @@ var require_ast = __commonJS({
|
|
|
1897
1897
|
helperExpression: function helperExpression(node) {
|
|
1898
1898
|
return node.type === "SubExpression" || (node.type === "MustacheStatement" || node.type === "BlockStatement") && !!(node.params && node.params.length || node.hash);
|
|
1899
1899
|
},
|
|
1900
|
-
scopedId: function scopedId(
|
|
1901
|
-
return /^\.|this\b/.test(
|
|
1900
|
+
scopedId: function scopedId(path22) {
|
|
1901
|
+
return /^\.|this\b/.test(path22.original);
|
|
1902
1902
|
},
|
|
1903
1903
|
// an ID is simple if it only has one part, and that part is not
|
|
1904
1904
|
// `..` or `this`.
|
|
1905
|
-
simpleId: function simpleId(
|
|
1906
|
-
return
|
|
1905
|
+
simpleId: function simpleId(path22) {
|
|
1906
|
+
return path22.parts.length === 1 && !AST.helpers.scopedId(path22) && !path22.depth;
|
|
1907
1907
|
}
|
|
1908
1908
|
}
|
|
1909
1909
|
};
|
|
@@ -2973,12 +2973,12 @@ var require_helpers2 = __commonJS({
|
|
|
2973
2973
|
loc
|
|
2974
2974
|
};
|
|
2975
2975
|
}
|
|
2976
|
-
function prepareMustache(
|
|
2976
|
+
function prepareMustache(path22, params, hash, open2, strip, locInfo) {
|
|
2977
2977
|
var escapeFlag = open2.charAt(3) || open2.charAt(2), escaped = escapeFlag !== "{" && escapeFlag !== "&";
|
|
2978
2978
|
var decorator = /\*/.test(open2);
|
|
2979
2979
|
return {
|
|
2980
2980
|
type: decorator ? "Decorator" : "MustacheStatement",
|
|
2981
|
-
path:
|
|
2981
|
+
path: path22,
|
|
2982
2982
|
params,
|
|
2983
2983
|
hash,
|
|
2984
2984
|
escaped,
|
|
@@ -3296,9 +3296,9 @@ var require_compiler = __commonJS({
|
|
|
3296
3296
|
},
|
|
3297
3297
|
DecoratorBlock: function DecoratorBlock(decorator) {
|
|
3298
3298
|
var program2 = decorator.program && this.compileProgram(decorator.program);
|
|
3299
|
-
var params = this.setupFullMustacheParams(decorator, program2, void 0),
|
|
3299
|
+
var params = this.setupFullMustacheParams(decorator, program2, void 0), path22 = decorator.path;
|
|
3300
3300
|
this.useDecorators = true;
|
|
3301
|
-
this.opcode("registerDecorator", params.length,
|
|
3301
|
+
this.opcode("registerDecorator", params.length, path22.original);
|
|
3302
3302
|
},
|
|
3303
3303
|
PartialStatement: function PartialStatement(partial) {
|
|
3304
3304
|
this.usePartial = true;
|
|
@@ -3362,46 +3362,46 @@ var require_compiler = __commonJS({
|
|
|
3362
3362
|
}
|
|
3363
3363
|
},
|
|
3364
3364
|
ambiguousSexpr: function ambiguousSexpr(sexpr, program2, inverse) {
|
|
3365
|
-
var
|
|
3366
|
-
this.opcode("getContext",
|
|
3365
|
+
var path22 = sexpr.path, name = path22.parts[0], isBlock = program2 != null || inverse != null;
|
|
3366
|
+
this.opcode("getContext", path22.depth);
|
|
3367
3367
|
this.opcode("pushProgram", program2);
|
|
3368
3368
|
this.opcode("pushProgram", inverse);
|
|
3369
|
-
|
|
3370
|
-
this.accept(
|
|
3369
|
+
path22.strict = true;
|
|
3370
|
+
this.accept(path22);
|
|
3371
3371
|
this.opcode("invokeAmbiguous", name, isBlock);
|
|
3372
3372
|
},
|
|
3373
3373
|
simpleSexpr: function simpleSexpr(sexpr) {
|
|
3374
|
-
var
|
|
3375
|
-
|
|
3376
|
-
this.accept(
|
|
3374
|
+
var path22 = sexpr.path;
|
|
3375
|
+
path22.strict = true;
|
|
3376
|
+
this.accept(path22);
|
|
3377
3377
|
this.opcode("resolvePossibleLambda");
|
|
3378
3378
|
},
|
|
3379
3379
|
helperSexpr: function helperSexpr(sexpr, program2, inverse) {
|
|
3380
|
-
var params = this.setupFullMustacheParams(sexpr, program2, inverse),
|
|
3380
|
+
var params = this.setupFullMustacheParams(sexpr, program2, inverse), path22 = sexpr.path, name = path22.parts[0];
|
|
3381
3381
|
if (this.options.knownHelpers[name]) {
|
|
3382
3382
|
this.opcode("invokeKnownHelper", params.length, name);
|
|
3383
3383
|
} else if (this.options.knownHelpersOnly) {
|
|
3384
3384
|
throw new _exception2["default"]("You specified knownHelpersOnly, but used the unknown helper " + name, sexpr);
|
|
3385
3385
|
} else {
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
this.accept(
|
|
3389
|
-
this.opcode("invokeHelper", params.length,
|
|
3386
|
+
path22.strict = true;
|
|
3387
|
+
path22.falsy = true;
|
|
3388
|
+
this.accept(path22);
|
|
3389
|
+
this.opcode("invokeHelper", params.length, path22.original, _ast2["default"].helpers.simpleId(path22));
|
|
3390
3390
|
}
|
|
3391
3391
|
},
|
|
3392
|
-
PathExpression: function PathExpression(
|
|
3393
|
-
this.addDepth(
|
|
3394
|
-
this.opcode("getContext",
|
|
3395
|
-
var name =
|
|
3392
|
+
PathExpression: function PathExpression(path22) {
|
|
3393
|
+
this.addDepth(path22.depth);
|
|
3394
|
+
this.opcode("getContext", path22.depth);
|
|
3395
|
+
var name = path22.parts[0], scoped = _ast2["default"].helpers.scopedId(path22), blockParamId = !path22.depth && !scoped && this.blockParamIndex(name);
|
|
3396
3396
|
if (blockParamId) {
|
|
3397
|
-
this.opcode("lookupBlockParam", blockParamId,
|
|
3397
|
+
this.opcode("lookupBlockParam", blockParamId, path22.parts);
|
|
3398
3398
|
} else if (!name) {
|
|
3399
3399
|
this.opcode("pushContext");
|
|
3400
|
-
} else if (
|
|
3400
|
+
} else if (path22.data) {
|
|
3401
3401
|
this.options.data = true;
|
|
3402
|
-
this.opcode("lookupData",
|
|
3402
|
+
this.opcode("lookupData", path22.depth, path22.parts, path22.strict);
|
|
3403
3403
|
} else {
|
|
3404
|
-
this.opcode("lookupOnContext",
|
|
3404
|
+
this.opcode("lookupOnContext", path22.parts, path22.falsy, path22.strict, scoped);
|
|
3405
3405
|
}
|
|
3406
3406
|
},
|
|
3407
3407
|
StringLiteral: function StringLiteral(string) {
|
|
@@ -3751,16 +3751,16 @@ var require_util = __commonJS({
|
|
|
3751
3751
|
}
|
|
3752
3752
|
exports.urlGenerate = urlGenerate;
|
|
3753
3753
|
function normalize(aPath) {
|
|
3754
|
-
var
|
|
3754
|
+
var path22 = aPath;
|
|
3755
3755
|
var url = urlParse(aPath);
|
|
3756
3756
|
if (url) {
|
|
3757
3757
|
if (!url.path) {
|
|
3758
3758
|
return aPath;
|
|
3759
3759
|
}
|
|
3760
|
-
|
|
3760
|
+
path22 = url.path;
|
|
3761
3761
|
}
|
|
3762
|
-
var isAbsolute = exports.isAbsolute(
|
|
3763
|
-
var parts =
|
|
3762
|
+
var isAbsolute = exports.isAbsolute(path22);
|
|
3763
|
+
var parts = path22.split(/\/+/);
|
|
3764
3764
|
for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
|
|
3765
3765
|
part = parts[i];
|
|
3766
3766
|
if (part === ".") {
|
|
@@ -3777,15 +3777,15 @@ var require_util = __commonJS({
|
|
|
3777
3777
|
}
|
|
3778
3778
|
}
|
|
3779
3779
|
}
|
|
3780
|
-
|
|
3781
|
-
if (
|
|
3782
|
-
|
|
3780
|
+
path22 = parts.join("/");
|
|
3781
|
+
if (path22 === "") {
|
|
3782
|
+
path22 = isAbsolute ? "/" : ".";
|
|
3783
3783
|
}
|
|
3784
3784
|
if (url) {
|
|
3785
|
-
url.path =
|
|
3785
|
+
url.path = path22;
|
|
3786
3786
|
return urlGenerate(url);
|
|
3787
3787
|
}
|
|
3788
|
-
return
|
|
3788
|
+
return path22;
|
|
3789
3789
|
}
|
|
3790
3790
|
exports.normalize = normalize;
|
|
3791
3791
|
function join(aRoot, aPath) {
|
|
@@ -6568,8 +6568,8 @@ var require_printer = __commonJS({
|
|
|
6568
6568
|
return this.accept(sexpr.path) + " " + params + hash;
|
|
6569
6569
|
};
|
|
6570
6570
|
PrintVisitor.prototype.PathExpression = function(id) {
|
|
6571
|
-
var
|
|
6572
|
-
return (id.data ? "@" : "") + "PATH:" +
|
|
6571
|
+
var path22 = id.parts.join("/");
|
|
6572
|
+
return (id.data ? "@" : "") + "PATH:" + path22;
|
|
6573
6573
|
};
|
|
6574
6574
|
PrintVisitor.prototype.StringLiteral = function(string) {
|
|
6575
6575
|
return '"' + string.value + '"';
|
|
@@ -7219,7 +7219,7 @@ function getErrorMessage(error) {
|
|
|
7219
7219
|
|
|
7220
7220
|
// src/program.ts
|
|
7221
7221
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
7222
|
-
import
|
|
7222
|
+
import path21 from "node:path";
|
|
7223
7223
|
import { setTimeout as sleep2 } from "node:timers/promises";
|
|
7224
7224
|
|
|
7225
7225
|
// ../common/dist/src/stdlib/json.util.js
|
|
@@ -12441,8 +12441,8 @@ var RENDER_TEMPLATE_ERROR_REASON_CATALOG = defineErrorReasonCatalog()([
|
|
|
12441
12441
|
]);
|
|
12442
12442
|
var storeReferencePathPattern = String.raw`store(?:\.[$A-Z_a-z][\w$]*)*`;
|
|
12443
12443
|
var storeReferenceMarkdownLinkTemplateRegex = new RegExp(String.raw`(?<open>\{\{\{?)\s*\[(?<path>${storeReferencePathPattern})\]\(\s*<?https?:\/\/\k<path>>?\s*\)\s*(?<close>\}\}\}?)`, "gu");
|
|
12444
|
-
function normalizeAutomationStoreTemplateLinkMatch([_match, open2,
|
|
12445
|
-
return open2 === "{{{" ? `{{{${
|
|
12444
|
+
function normalizeAutomationStoreTemplateLinkMatch([_match, open2, path22]) {
|
|
12445
|
+
return open2 === "{{{" ? `{{{${path22}}}}` : `{{${path22}}}`;
|
|
12446
12446
|
}
|
|
12447
12447
|
function normalizeAutomationStoreTemplateLinks(template) {
|
|
12448
12448
|
return template.replaceAll(storeReferenceMarkdownLinkTemplateRegex, (...args) => normalizeAutomationStoreTemplateLinkMatch(args));
|
|
@@ -12512,12 +12512,14 @@ function renderOutcomeList(outcomes) {
|
|
|
12512
12512
|
function formatCaseHeading(label, description) {
|
|
12513
12513
|
return `* **Case ${label}**: ${description}`;
|
|
12514
12514
|
}
|
|
12515
|
-
import_handlebars.default.registerHelper("renderIfElseList", (rawCases, rawElse) => {
|
|
12515
|
+
import_handlebars.default.registerHelper("renderIfElseList", (rawCases, rawElse, options) => {
|
|
12516
12516
|
const cases = z7.array(ConditionCaseSchema).min(1).parse(rawCases);
|
|
12517
12517
|
const elseOutcome = OutcomeType.optional().parse(rawElse);
|
|
12518
12518
|
const hasElseOutcomes = elseOutcome !== void 0 && elseOutcome.length > 0;
|
|
12519
12519
|
const totalOptions = cases.length + (hasElseOutcomes ? 1 : 0);
|
|
12520
|
-
const
|
|
12520
|
+
const literalStoreReferences = options.data?.literalStoreReferences === true;
|
|
12521
|
+
const preamble = literalStoreReferences ? `Conditional instruction: ${totalOptions} mutually exclusive case${totalOptions === 1 ? "" : "s"} (select once on entry).` : `You now have ${totalOptions} option${totalOptions === 1 ? "" : "s"}:`;
|
|
12522
|
+
const executionRules = "These cases are mutually exclusive alternatives, not sequential steps. Before evaluating a condition, check prior tool calls and results for outcomes already executed on this visit. If a case has begun, continue its unfinished outcomes without checking the conditions again. A successful tool result completes that outcome; when the selected case's final outcome succeeds, this entire conditional is complete and execution continues with the next instruction. Only on first entry, select the first matching case, or Otherwise if present and no condition matched. Otherwise never applies because a selected case changed its own condition. Retry failed actions within the selected case. Reevaluate only when an explicit loop or return instruction enters this conditional again.";
|
|
12521
12523
|
const ifBlocks = cases.map((c, idx) => {
|
|
12522
12524
|
const heading = formatCaseHeading(indexToLetters(idx), c.condition);
|
|
12523
12525
|
const outcomes = renderOutcomeList(c.outcome.map((o) => o.preview));
|
|
@@ -12527,7 +12529,13 @@ ${outcomes}`;
|
|
|
12527
12529
|
const elseHeading = formatCaseHeading(indexToLetters(cases.length), "Otherwise");
|
|
12528
12530
|
const elseBlock = hasElseOutcomes ? [elseHeading, renderOutcomeList(elseOutcome.map((o) => o.preview))] : [];
|
|
12529
12531
|
const fallthroughBlock = hasElseOutcomes ? [] : ["If no case matches, continue to the next instruction."];
|
|
12530
|
-
const result = [
|
|
12532
|
+
const result = [
|
|
12533
|
+
preamble,
|
|
12534
|
+
...literalStoreReferences ? [executionRules] : [],
|
|
12535
|
+
ifBlocks,
|
|
12536
|
+
...elseBlock,
|
|
12537
|
+
...fallthroughBlock
|
|
12538
|
+
].join("\n");
|
|
12531
12539
|
return new import_handlebars.default.SafeString(result);
|
|
12532
12540
|
});
|
|
12533
12541
|
function isPathExpression(expr) {
|
|
@@ -13931,18 +13939,18 @@ var specialCommands = {
|
|
|
13931
13939
|
// ../common/dist/src/utils/automation-store-path.util.js
|
|
13932
13940
|
var AUTOMATION_STORE_ROOT_PATH = "store";
|
|
13933
13941
|
var relativeStorePathRegex = /^[$A-Z_a-z][\w$]*(?:\.[$A-Z_a-z][\w$]*)*$/u;
|
|
13934
|
-
function normalizeStoreMutationPath(
|
|
13935
|
-
const trimmedPath =
|
|
13942
|
+
function normalizeStoreMutationPath(path22) {
|
|
13943
|
+
const trimmedPath = path22.trim();
|
|
13936
13944
|
const rootPrefix = `${AUTOMATION_STORE_ROOT_PATH}.`;
|
|
13937
13945
|
const relativePath = trimmedPath.startsWith(rootPrefix) ? trimmedPath.slice(rootPrefix.length) : trimmedPath;
|
|
13938
13946
|
if (!relativeStorePathRegex.test(relativePath)) {
|
|
13939
13947
|
return Err({
|
|
13940
13948
|
type: "invalid-automation-store-path",
|
|
13941
|
-
path:
|
|
13949
|
+
path: path22,
|
|
13942
13950
|
categories: ["customer_usage"],
|
|
13943
13951
|
statusCode: 400,
|
|
13944
13952
|
nonRetryable: true,
|
|
13945
|
-
message: `Automation store path "${
|
|
13953
|
+
message: `Automation store path "${path22}" is invalid.`,
|
|
13946
13954
|
suggestedAction: "Use a dot path relative to the automation store, such as patient.name or provider.clinic."
|
|
13947
13955
|
});
|
|
13948
13956
|
}
|
|
@@ -13955,16 +13963,16 @@ function findAutomationStorePathOverlap(paths) {
|
|
|
13955
13963
|
...new Set(paths.map(getCanonicalAutomationStoreMutationPath))
|
|
13956
13964
|
].toSorted((left, right) => (left === AUTOMATION_STORE_ROOT_PATH ? 0 : left.split(".").length) - (right === AUTOMATION_STORE_ROOT_PATH ? 0 : right.split(".").length));
|
|
13957
13965
|
for (const [index, ancestorPath] of canonicalPaths.entries()) {
|
|
13958
|
-
const descendantPath = canonicalPaths.slice(index + 1).find((
|
|
13966
|
+
const descendantPath = canonicalPaths.slice(index + 1).find((path22) => ancestorPath === AUTOMATION_STORE_ROOT_PATH || path22.startsWith(`${ancestorPath}.`));
|
|
13959
13967
|
if (descendantPath !== void 0) {
|
|
13960
13968
|
return { ancestorPath, descendantPath };
|
|
13961
13969
|
}
|
|
13962
13970
|
}
|
|
13963
13971
|
return void 0;
|
|
13964
13972
|
}
|
|
13965
|
-
function getCanonicalAutomationStoreMutationPath(
|
|
13966
|
-
const normalizedPath = normalizeStoreMutationPath(
|
|
13967
|
-
return normalizedPath._tag === "Ok" ? normalizedPath.value :
|
|
13973
|
+
function getCanonicalAutomationStoreMutationPath(path22) {
|
|
13974
|
+
const normalizedPath = normalizeStoreMutationPath(path22);
|
|
13975
|
+
return normalizedPath._tag === "Ok" ? normalizedPath.value : path22.trim();
|
|
13968
13976
|
}
|
|
13969
13977
|
|
|
13970
13978
|
// ../common/dist/src/constants/tool-declarations.js
|
|
@@ -14152,9 +14160,9 @@ var baseToolDeclarations = {
|
|
|
14152
14160
|
path: []
|
|
14153
14161
|
});
|
|
14154
14162
|
}
|
|
14155
|
-
const canonicalUpdatePaths = updates.map(({ path:
|
|
14163
|
+
const canonicalUpdatePaths = updates.map(({ path: path22 }) => getCanonicalAutomationStoreMutationPath(path22));
|
|
14156
14164
|
const canonicalClearPathSet = new Set(clears.map(getCanonicalAutomationStoreMutationPath));
|
|
14157
|
-
const conflictedUpdatePath = canonicalUpdatePaths.find((
|
|
14165
|
+
const conflictedUpdatePath = canonicalUpdatePaths.find((path22) => canonicalClearPathSet.has(path22));
|
|
14158
14166
|
if (conflictedUpdatePath !== void 0) {
|
|
14159
14167
|
context.addIssue({
|
|
14160
14168
|
code: "custom",
|
|
@@ -14687,9 +14695,9 @@ var magicalApiKeyPermissionPresets = [
|
|
|
14687
14695
|
import { z as z25 } from "zod";
|
|
14688
14696
|
|
|
14689
14697
|
// ../common/dist/src/utils/agent-knowledge-base-assets.util.js
|
|
14690
|
-
function getIsKnowledgeBaseAssetPathAllowed(
|
|
14691
|
-
const pathSegments =
|
|
14692
|
-
if (
|
|
14698
|
+
function getIsKnowledgeBaseAssetPathAllowed(path22) {
|
|
14699
|
+
const pathSegments = path22.split("/");
|
|
14700
|
+
if (path22.length === 0 || pathSegments.some((segment) => segment.length === 0)) {
|
|
14693
14701
|
return false;
|
|
14694
14702
|
}
|
|
14695
14703
|
const isTopLevelAssetPath = pathSegments[0] === "assets";
|
|
@@ -14744,29 +14752,29 @@ var ApiEmbeddedFileContentTypes = [
|
|
|
14744
14752
|
];
|
|
14745
14753
|
var API_EMBEDDED_FILE_PATH_PATTERN = /^(?:\[\*\]|[A-Za-z_$][\w$-]*)(?:\[\*\]|\.[A-Za-z_$][\w$-]*)*$/u;
|
|
14746
14754
|
var API_EMBEDDED_FILE_PATH_SEGMENT_PATTERN = /\[\*\]|[A-Za-z_$][\w$-]*/gu;
|
|
14747
|
-
function parseApiEmbeddedFilePath(
|
|
14748
|
-
if (!API_EMBEDDED_FILE_PATH_PATTERN.test(
|
|
14755
|
+
function parseApiEmbeddedFilePath(path22) {
|
|
14756
|
+
if (!API_EMBEDDED_FILE_PATH_PATTERN.test(path22)) {
|
|
14749
14757
|
return void 0;
|
|
14750
14758
|
}
|
|
14751
|
-
return [...
|
|
14759
|
+
return [...path22.matchAll(API_EMBEDDED_FILE_PATH_SEGMENT_PATTERN)].map(([segment]) => segment === "[*]" ? { type: "arrayWildcard" } : { key: segment, type: "property" });
|
|
14752
14760
|
}
|
|
14753
14761
|
var apiAgentEmbeddedFileSchema = z17.object({
|
|
14754
|
-
path: z17.string().trim().min(1, "Embedded file path is required.").refine((
|
|
14762
|
+
path: z17.string().trim().min(1, "Embedded file path is required.").refine((path22) => parseApiEmbeddedFilePath(path22) !== void 0, {
|
|
14755
14763
|
message: "Embedded file path must use object properties and [*] array wildcards."
|
|
14756
14764
|
}).describe("Path to a Base64 value relative to the projected API response. Supports object properties and [*] array wildcards."),
|
|
14757
14765
|
contentType: z17.enum(ApiEmbeddedFileContentTypes).describe("File type of the decoded Base64 value. Use auto to detect PDF, PNG, or JPEG from each file\u2019s contents. Unrecognized files are skipped.")
|
|
14758
14766
|
}).strict();
|
|
14759
14767
|
var apiAgentEmbeddedFilesSchema = z17.array(apiAgentEmbeddedFileSchema).superRefine((embeddedFiles, context) => {
|
|
14760
14768
|
const paths = /* @__PURE__ */ new Set();
|
|
14761
|
-
for (const [index, { path:
|
|
14762
|
-
if (paths.has(
|
|
14769
|
+
for (const [index, { path: path22 }] of embeddedFiles.entries()) {
|
|
14770
|
+
if (paths.has(path22)) {
|
|
14763
14771
|
context.addIssue({
|
|
14764
14772
|
code: z17.ZodIssueCode.custom,
|
|
14765
|
-
message: `Embedded file path "${
|
|
14773
|
+
message: `Embedded file path "${path22}" can only be configured once.`,
|
|
14766
14774
|
path: [index, "path"]
|
|
14767
14775
|
});
|
|
14768
14776
|
}
|
|
14769
|
-
paths.add(
|
|
14777
|
+
paths.add(path22);
|
|
14770
14778
|
}
|
|
14771
14779
|
}).describe("Base64 values to decode, upload as permanent files, and replace with file references in the projected API response.");
|
|
14772
14780
|
|
|
@@ -14776,13 +14784,13 @@ var API_REQUEST_FILE_PATH_PATTERN = /^[A-Za-z_$][\w$-]*(?:\.[A-Za-z_$][\w$-]*)*$
|
|
|
14776
14784
|
var API_REQUEST_BASE64_FILE_HELPER_PATTERN = /^\s*\{\{\s*base64File\s+(?<sourceInput>[^{}\s]+)\s*\}\}\s*$/u;
|
|
14777
14785
|
var API_REQUEST_BASE64_FILE_HELPER_USAGE_PATTERN = /\{\{\s*base64File\b/u;
|
|
14778
14786
|
var API_REQUEST_BASE64_FILE_HELPER_EXAMPLE = "{{base64File fileInput}}";
|
|
14779
|
-
function parseApiRequestFilePath(
|
|
14780
|
-
if (!API_REQUEST_FILE_PATH_PATTERN.test(
|
|
14787
|
+
function parseApiRequestFilePath(path22) {
|
|
14788
|
+
if (!API_REQUEST_FILE_PATH_PATTERN.test(path22)) {
|
|
14781
14789
|
return void 0;
|
|
14782
14790
|
}
|
|
14783
|
-
return
|
|
14791
|
+
return path22.split(".");
|
|
14784
14792
|
}
|
|
14785
|
-
function inspectApiRequestBase64FileHelperValue({ path:
|
|
14793
|
+
function inspectApiRequestBase64FileHelperValue({ path: path22, value }) {
|
|
14786
14794
|
const match = API_REQUEST_BASE64_FILE_HELPER_PATTERN.exec(value);
|
|
14787
14795
|
if (match === null) {
|
|
14788
14796
|
return API_REQUEST_BASE64_FILE_HELPER_USAGE_PATTERN.test(value) ? {
|
|
@@ -14790,7 +14798,7 @@ function inspectApiRequestBase64FileHelperValue({ path: path21, value }) {
|
|
|
14790
14798
|
issues: [
|
|
14791
14799
|
{
|
|
14792
14800
|
message: `Use ${API_REQUEST_BASE64_FILE_HELPER_EXAMPLE} as the entire JSON field value.`,
|
|
14793
|
-
path:
|
|
14801
|
+
path: path22
|
|
14794
14802
|
}
|
|
14795
14803
|
]
|
|
14796
14804
|
} : { helpers: [], issues: [] };
|
|
@@ -14802,24 +14810,24 @@ function inspectApiRequestBase64FileHelperValue({ path: path21, value }) {
|
|
|
14802
14810
|
issues: [
|
|
14803
14811
|
{
|
|
14804
14812
|
message: "Base64 file helper input must use an object property path.",
|
|
14805
|
-
path:
|
|
14813
|
+
path: path22
|
|
14806
14814
|
}
|
|
14807
14815
|
]
|
|
14808
14816
|
};
|
|
14809
14817
|
}
|
|
14810
14818
|
return {
|
|
14811
|
-
helpers: [{ destinationPath:
|
|
14819
|
+
helpers: [{ destinationPath: path22, sourceInput }],
|
|
14812
14820
|
issues: []
|
|
14813
14821
|
};
|
|
14814
14822
|
}
|
|
14815
|
-
function inspectApiRequestBase64FileHelpers(body,
|
|
14823
|
+
function inspectApiRequestBase64FileHelpers(body, path22 = []) {
|
|
14816
14824
|
if (typeof body === "string") {
|
|
14817
|
-
return inspectApiRequestBase64FileHelperValue({ path:
|
|
14825
|
+
return inspectApiRequestBase64FileHelperValue({ path: path22, value: body });
|
|
14818
14826
|
}
|
|
14819
14827
|
if (Array.isArray(body)) {
|
|
14820
14828
|
return body.reduce((inspection, value, index) => {
|
|
14821
14829
|
const nestedInspection = inspectApiRequestBase64FileHelpers(value, [
|
|
14822
|
-
...
|
|
14830
|
+
...path22,
|
|
14823
14831
|
index
|
|
14824
14832
|
]);
|
|
14825
14833
|
return {
|
|
@@ -14833,7 +14841,7 @@ function inspectApiRequestBase64FileHelpers(body, path21 = []) {
|
|
|
14833
14841
|
}
|
|
14834
14842
|
return Object.entries(body).reduce((inspection, [key, value]) => {
|
|
14835
14843
|
const nestedInspection = inspectApiRequestBase64FileHelpers(value, [
|
|
14836
|
-
...
|
|
14844
|
+
...path22,
|
|
14837
14845
|
key
|
|
14838
14846
|
]);
|
|
14839
14847
|
return {
|
|
@@ -14877,10 +14885,10 @@ function validateApiRequestBase64FileHelpers({ body, bodyType, context, supports
|
|
|
14877
14885
|
}
|
|
14878
14886
|
}
|
|
14879
14887
|
var apiAgentRequestFileEncodingSchema = z18.object({
|
|
14880
|
-
sourceInput: z18.string().trim().min(1, "File input is required.").refine((
|
|
14888
|
+
sourceInput: z18.string().trim().min(1, "File input is required.").refine((path22) => parseApiRequestFilePath(path22) !== void 0, {
|
|
14881
14889
|
message: "File input must use an object property path."
|
|
14882
14890
|
}).describe("API Agent input containing the file reference to encode."),
|
|
14883
|
-
destinationPath: z18.string().trim().min(1, "Request field is required.").refine((
|
|
14891
|
+
destinationPath: z18.string().trim().min(1, "Request field is required.").refine((path22) => parseApiRequestFilePath(path22) !== void 0, {
|
|
14884
14892
|
message: "Request field must use an object property path."
|
|
14885
14893
|
}).describe("JSON request body path where the encoded value is inserted."),
|
|
14886
14894
|
encoding: z18.literal("base64").describe("Encoding applied to the source file before insertion.")
|
|
@@ -15132,6 +15140,7 @@ var browserSOMEnvironmentOptionsSchema = z25.object({
|
|
|
15132
15140
|
environment: z25.literal("browser").describe("Browser environment using Set of Marks (SOM) for element identification."),
|
|
15133
15141
|
maxMediaToIncludeInMemory: z25.number().min(1).optional().describe("Maximum number of screenshots/media items to keep in the agent memory context."),
|
|
15134
15142
|
somFilter: somFilterConfigSchema.optional().describe("Default SOM overlay filter to apply for each browser iteration until the somFilter tool sets or clears a session filter."),
|
|
15143
|
+
somFrameTimeoutMs: z25.number().int().positive().optional().describe("Timeout in milliseconds for processing each child frame during SOM generation. Defaults to REMOTE_SESSION_SOM_FRAME_TIMEOUT_MS (7000 ms) when omitted. The overall 40000 ms SOM generation limit still applies."),
|
|
15135
15144
|
saveAuthCookiesAfterRun: z25.boolean().optional().describe("Whether to save authentication cookies after the run completes for reuse in future runs."),
|
|
15136
15145
|
suppressNativePrint: z25.boolean().optional().describe("Suppress native window.print dialogs for the whole browser session while still recording print calls."),
|
|
15137
15146
|
startingUrl: startingUrlSchema.describe("Initial URL to navigate to when the agent starts. Accepts a valid URL or a Handlebars template with agent inputs. If not provided, uses the current URL of the browser; if this is the first agent, it will be a blank page."),
|
|
@@ -15177,7 +15186,8 @@ var environmentOptionsSchema = z25.discriminatedUnion("environment", [
|
|
|
15177
15186
|
minimalEnvironmentOptionsSchema
|
|
15178
15187
|
]).describe("Environment configuration for the agent. Determines the execution context.");
|
|
15179
15188
|
var runSettingsBrowserSOMEnvironmentOptionsSchema = browserSOMEnvironmentOptionsSchema.omit({
|
|
15180
|
-
somFilter: true
|
|
15189
|
+
somFilter: true,
|
|
15190
|
+
somFrameTimeoutMs: true
|
|
15181
15191
|
}).describe("Browser environment configuration using Set of Marks (SOM) for element identification. This is the recommended browser mode for most use cases.");
|
|
15182
15192
|
var runSettingsEnvironmentOptionsSchema = z25.discriminatedUnion("environment", [
|
|
15183
15193
|
runSettingsBrowserSOMEnvironmentOptionsSchema,
|
|
@@ -15238,30 +15248,30 @@ function hasControlCharacter(value) {
|
|
|
15238
15248
|
}
|
|
15239
15249
|
return false;
|
|
15240
15250
|
}
|
|
15241
|
-
function isNormalizedRepoPath(
|
|
15242
|
-
if (
|
|
15251
|
+
function isNormalizedRepoPath(path22) {
|
|
15252
|
+
if (path22 === "/") {
|
|
15243
15253
|
return true;
|
|
15244
15254
|
}
|
|
15245
|
-
if (
|
|
15255
|
+
if (path22.length === 0 || path22.startsWith("/") || path22.startsWith("\\") || path22.includes("\\") || hasControlCharacter(path22) || windowsAbsolutePathPattern.test(path22)) {
|
|
15246
15256
|
return false;
|
|
15247
15257
|
}
|
|
15248
|
-
return
|
|
15258
|
+
return path22.split("/").every((segment) => segment.length > 0 && segment !== "." && segment !== ".." && segment !== ".git");
|
|
15249
15259
|
}
|
|
15250
|
-
function normalizeRepoPath(
|
|
15251
|
-
if (
|
|
15252
|
-
return
|
|
15260
|
+
function normalizeRepoPath(path22) {
|
|
15261
|
+
if (path22 === "/") {
|
|
15262
|
+
return path22;
|
|
15253
15263
|
}
|
|
15254
|
-
return
|
|
15264
|
+
return path22.replaceAll(/\/+$/gu, "");
|
|
15255
15265
|
}
|
|
15256
15266
|
var skillPathPattern = /^(?:skills\/.+|automations\/[^/]+\/skills\/.+|automations\/[^/]+\/agents\/[^/]+\/skills\/.+)$/u;
|
|
15257
15267
|
var skillRootPathPattern = /^(?:skills\/[^/]+|automations\/[^/]+\/skills\/[^/]+|automations\/[^/]+\/agents\/[^/]+\/skills\/[^/]+)$/u;
|
|
15258
15268
|
var repoPathSchema = z25.string().min(1).transform(normalizeRepoPath).refine(isNormalizedRepoPath, {
|
|
15259
15269
|
message: "Path must be a normalized repository-relative path."
|
|
15260
15270
|
});
|
|
15261
|
-
var registeredSkillPathSchema = repoPathSchema.refine((
|
|
15271
|
+
var registeredSkillPathSchema = repoPathSchema.refine((path22) => skillPathPattern.test(path22), {
|
|
15262
15272
|
message: "Skill paths must be under root, automation, or automation-agent skills."
|
|
15263
15273
|
});
|
|
15264
|
-
var registeredSkillRootPathSchema = registeredSkillPathSchema.refine((
|
|
15274
|
+
var registeredSkillRootPathSchema = registeredSkillPathSchema.refine((path22) => skillRootPathPattern.test(path22) && !path22.endsWith("/SKILL.md"), {
|
|
15265
15275
|
message: "Registered skill paths must identify a skill root directory."
|
|
15266
15276
|
});
|
|
15267
15277
|
var knowledgeBasePluginPermissionSchema = z25.object({
|
|
@@ -15910,13 +15920,13 @@ function getMentionedStandardCommand(instructions) {
|
|
|
15910
15920
|
const normalizedInstructions = instructions.toLowerCase();
|
|
15911
15921
|
return STANDARD_COMMAND_NAMES.find((commandName) => normalizedInstructions.includes(commandName.toLowerCase())) ?? null;
|
|
15912
15922
|
}
|
|
15913
|
-
function assertCustomInstructionsCommand({ commands, path:
|
|
15914
|
-
const customCommands = commands.flatMap((command, commandIndex) => command["commandName"] === "custom" ? [{ command, path: `${
|
|
15923
|
+
function assertCustomInstructionsCommand({ commands, path: path22 }) {
|
|
15924
|
+
const customCommands = commands.flatMap((command, commandIndex) => command["commandName"] === "custom" ? [{ command, path: `${path22}[${commandIndex.toString()}]` }] : []);
|
|
15915
15925
|
if (customCommands.length === 0) {
|
|
15916
15926
|
return;
|
|
15917
15927
|
}
|
|
15918
15928
|
if (customCommands.length > MAX_CUSTOM_COMMAND_COUNT) {
|
|
15919
|
-
throw createInvalidValueError(`${
|
|
15929
|
+
throw createInvalidValueError(`${path22} contains ${customCommands.length.toString()} custom commands. Use at most ${MAX_CUSTOM_COMMAND_COUNT.toString()} short custom commands per agent. Split policy, decision, outreach, and multi-step work into catalog commands or child agents instead.`);
|
|
15920
15930
|
}
|
|
15921
15931
|
for (const customCommand of customCommands) {
|
|
15922
15932
|
const instructions = getCustomInstructions(customCommand.command);
|
|
@@ -16298,7 +16308,7 @@ function isRecord3(value) {
|
|
|
16298
16308
|
function validateCustomInstructionsCommands({
|
|
16299
16309
|
commands,
|
|
16300
16310
|
ctx,
|
|
16301
|
-
path:
|
|
16311
|
+
path: path22
|
|
16302
16312
|
}) {
|
|
16303
16313
|
if (!Array.isArray(commands)) {
|
|
16304
16314
|
return;
|
|
@@ -16306,14 +16316,14 @@ function validateCustomInstructionsCommands({
|
|
|
16306
16316
|
const validationResult = fromThrowable(() => {
|
|
16307
16317
|
assertCustomInstructionsCommand({
|
|
16308
16318
|
commands: commands.map((command) => isRecord3(command) ? command : {}),
|
|
16309
|
-
path:
|
|
16319
|
+
path: path22.join(".").replaceAll(/\.(?<index>\d+)/gu, "[$<index>]")
|
|
16310
16320
|
});
|
|
16311
16321
|
}, "invalid-custom-instructions-command");
|
|
16312
16322
|
if (isErr(validationResult)) {
|
|
16313
16323
|
ctx.addIssue({
|
|
16314
16324
|
code: "custom",
|
|
16315
16325
|
message: `${getErrorMessage2(validationResult.error.cause)} Run mgcl catalog commands to find the standard command for this work.`,
|
|
16316
|
-
path:
|
|
16326
|
+
path: path22
|
|
16317
16327
|
});
|
|
16318
16328
|
}
|
|
16319
16329
|
}
|
|
@@ -16396,6 +16406,27 @@ var runDraftConfigInputSchema = automationRunStartConfigSchema.partial().omit({
|
|
|
16396
16406
|
networkTrafficCapture: runDraftNetworkTrafficCaptureInputSchema.nullable().optional()
|
|
16397
16407
|
}).strict();
|
|
16398
16408
|
var COMMAND_CATALOG_HELP = "When authoring raw instructionsCommands, run mgcl catalog commands and prefer a standard command.";
|
|
16409
|
+
var LIBRARY_ASSET_WORKBENCH_SELECTION = `libraryEntityId
|
|
16410
|
+
rootAgentId
|
|
16411
|
+
currentVersionId
|
|
16412
|
+
updatedAt
|
|
16413
|
+
summary {
|
|
16414
|
+
name
|
|
16415
|
+
agentCount
|
|
16416
|
+
edgeCount
|
|
16417
|
+
rootAgentIds
|
|
16418
|
+
agents {
|
|
16419
|
+
id
|
|
16420
|
+
name
|
|
16421
|
+
type
|
|
16422
|
+
kind
|
|
16423
|
+
description
|
|
16424
|
+
instructions
|
|
16425
|
+
tools
|
|
16426
|
+
childAgentIds
|
|
16427
|
+
parentAgentIds
|
|
16428
|
+
}
|
|
16429
|
+
}`;
|
|
16399
16430
|
var apiKeyAccessPolicies = {
|
|
16400
16431
|
baseline: { type: "baseline" },
|
|
16401
16432
|
automationRead: {
|
|
@@ -16440,6 +16471,10 @@ var apiKeyAccessPolicies = {
|
|
|
16440
16471
|
type: "allOf",
|
|
16441
16472
|
permissions: ["runs:execute", "runs:read", "store:write"]
|
|
16442
16473
|
},
|
|
16474
|
+
libraryDenied: {
|
|
16475
|
+
type: "denied",
|
|
16476
|
+
reason: "Shared library operations do not have a public API-key permission."
|
|
16477
|
+
},
|
|
16443
16478
|
skillsRead: {
|
|
16444
16479
|
type: "allOf",
|
|
16445
16480
|
permissions: ["skills:read"]
|
|
@@ -16550,6 +16585,7 @@ var agentEnvironmentOptionsSelection = ` environmentOptions {
|
|
|
16550
16585
|
... on AgentConfig_environmentOptions_Browser {
|
|
16551
16586
|
environment
|
|
16552
16587
|
somFilter
|
|
16588
|
+
somFrameTimeoutMs
|
|
16553
16589
|
maxMediaToIncludeInMemory
|
|
16554
16590
|
saveAuthCookiesAfterRun
|
|
16555
16591
|
startingUrl
|
|
@@ -17028,6 +17064,320 @@ query GetCaptureContext($automationId: ID, $recordingId: ID) {
|
|
|
17028
17064
|
metadata
|
|
17029
17065
|
rawEvents
|
|
17030
17066
|
}
|
|
17067
|
+
}`
|
|
17068
|
+
}),
|
|
17069
|
+
createOperationSpec({
|
|
17070
|
+
operationName: "ExportAgents",
|
|
17071
|
+
apiKeyAccess: {
|
|
17072
|
+
type: "denied",
|
|
17073
|
+
reason: "Agent transfer requires user login; shared library access has no API-key permission."
|
|
17074
|
+
},
|
|
17075
|
+
kind: "query",
|
|
17076
|
+
inputSchema: z28.object({
|
|
17077
|
+
ids: z28.array(z28.string().min(1)).min(1),
|
|
17078
|
+
libraryEntityId: z28.string().min(1).optional(),
|
|
17079
|
+
automationVersionId: z28.string().min(1).optional()
|
|
17080
|
+
}).refine(
|
|
17081
|
+
(input) => Boolean(input.libraryEntityId) !== Boolean(input.automationVersionId),
|
|
17082
|
+
{
|
|
17083
|
+
message: "Provide exactly one of --library-entity-id or --automation-version-id."
|
|
17084
|
+
}
|
|
17085
|
+
),
|
|
17086
|
+
cli: {
|
|
17087
|
+
name: "export-agents",
|
|
17088
|
+
path: ["agents", "export"],
|
|
17089
|
+
description: "Export complete selected agents as portable JSON. Use --json > agents.json. Requires user login.",
|
|
17090
|
+
resultKey: "exportAgents",
|
|
17091
|
+
options: [
|
|
17092
|
+
stringArrayOption({
|
|
17093
|
+
inputKey: "ids",
|
|
17094
|
+
flagName: "ids",
|
|
17095
|
+
description: "Agent IDs, including their dependencies.",
|
|
17096
|
+
required: true
|
|
17097
|
+
}),
|
|
17098
|
+
stringOption({
|
|
17099
|
+
inputKey: "libraryEntityId",
|
|
17100
|
+
flagName: "library-entity-id",
|
|
17101
|
+
description: "Source library asset ID (exclusive with --automation-version-id)."
|
|
17102
|
+
}),
|
|
17103
|
+
stringOption({
|
|
17104
|
+
inputKey: "automationVersionId",
|
|
17105
|
+
flagName: "automation-version-id",
|
|
17106
|
+
description: "Source saved automation version ID."
|
|
17107
|
+
})
|
|
17108
|
+
]
|
|
17109
|
+
},
|
|
17110
|
+
mcp: { fileName: "exportAgents.graphql" },
|
|
17111
|
+
document: `query ExportAgents($ids: [ID!]!, $libraryEntityId: ID, $automationVersionId: ID) {
|
|
17112
|
+
exportAgents(ids: $ids, libraryEntityId: $libraryEntityId, automationVersionId: $automationVersionId)
|
|
17113
|
+
}`
|
|
17114
|
+
}),
|
|
17115
|
+
createOperationSpec({
|
|
17116
|
+
operationName: "ImportAgents",
|
|
17117
|
+
apiKeyAccess: {
|
|
17118
|
+
type: "denied",
|
|
17119
|
+
reason: "Agent transfer requires user login; shared library access has no API-key permission."
|
|
17120
|
+
},
|
|
17121
|
+
kind: "mutation",
|
|
17122
|
+
inputSchema: z28.object({
|
|
17123
|
+
automationId: z28.string().min(1),
|
|
17124
|
+
baseVersionId: z28.string().min(1),
|
|
17125
|
+
data: z28.unknown().refine((value) => value !== void 0, {
|
|
17126
|
+
message: "Agent export data is required."
|
|
17127
|
+
})
|
|
17128
|
+
}),
|
|
17129
|
+
cli: {
|
|
17130
|
+
name: "import-agents",
|
|
17131
|
+
path: ["agents", "import"],
|
|
17132
|
+
description: "Append independent copies from an agent export file to a same-workspace draft. Keeps destination settings. Requires user login.",
|
|
17133
|
+
resultKey: "importAgents",
|
|
17134
|
+
options: [
|
|
17135
|
+
stringOption({
|
|
17136
|
+
inputKey: "automationId",
|
|
17137
|
+
flagName: "automation-id",
|
|
17138
|
+
description: "Destination draft automation ID.",
|
|
17139
|
+
required: true
|
|
17140
|
+
}),
|
|
17141
|
+
stringOption({
|
|
17142
|
+
inputKey: "baseVersionId",
|
|
17143
|
+
flagName: "base-version-id",
|
|
17144
|
+
description: "Current draftVersionId from a fresh automation fetch.",
|
|
17145
|
+
required: true
|
|
17146
|
+
}),
|
|
17147
|
+
stringOption({
|
|
17148
|
+
inputKey: "file",
|
|
17149
|
+
flagName: "file",
|
|
17150
|
+
description: "JSON file produced by agents export --json.",
|
|
17151
|
+
required: true,
|
|
17152
|
+
clientOnly: true
|
|
17153
|
+
})
|
|
17154
|
+
]
|
|
17155
|
+
},
|
|
17156
|
+
mcp: { fileName: "importAgents.graphql" },
|
|
17157
|
+
document: `mutation ImportAgents($automationId: ID!, $baseVersionId: ID!, $data: JSON!) {
|
|
17158
|
+
importAgents(automationId: $automationId, baseVersionId: $baseVersionId, data: $data)
|
|
17159
|
+
}`
|
|
17160
|
+
}),
|
|
17161
|
+
createOperationSpec({
|
|
17162
|
+
operationName: "LibraryAssetSearch",
|
|
17163
|
+
apiKeyAccess: apiKeyAccessPolicies.libraryDenied,
|
|
17164
|
+
kind: "query",
|
|
17165
|
+
inputSchema: z28.object({
|
|
17166
|
+
query: z28.string().min(1).optional(),
|
|
17167
|
+
limit: z28.number().int().min(1).max(50).optional()
|
|
17168
|
+
}),
|
|
17169
|
+
cli: {
|
|
17170
|
+
name: "library-asset-search",
|
|
17171
|
+
path: ["library", "search"],
|
|
17172
|
+
description: "Find shared library assets in the current workspace by name. Omit --query to list recent assets. Requires user login.",
|
|
17173
|
+
resultKey: "libraryAssetSearch",
|
|
17174
|
+
options: [
|
|
17175
|
+
stringOption({
|
|
17176
|
+
inputKey: "query",
|
|
17177
|
+
flagName: "query",
|
|
17178
|
+
description: "Case-insensitive substring of the asset name."
|
|
17179
|
+
}),
|
|
17180
|
+
numberOption({
|
|
17181
|
+
inputKey: "limit",
|
|
17182
|
+
flagName: "limit",
|
|
17183
|
+
description: "Maximum assets to return (1-50, default 20)."
|
|
17184
|
+
})
|
|
17185
|
+
]
|
|
17186
|
+
},
|
|
17187
|
+
mcp: { fileName: "libraryAssetSearch.graphql" },
|
|
17188
|
+
document: `query LibraryAssetSearch($query: String, $limit: Int) {
|
|
17189
|
+
libraryAssetSearch(query: $query, limit: $limit) {
|
|
17190
|
+
libraryEntityId
|
|
17191
|
+
rootAgentId
|
|
17192
|
+
name
|
|
17193
|
+
description
|
|
17194
|
+
currentVersionId
|
|
17195
|
+
updatedAt
|
|
17196
|
+
}
|
|
17197
|
+
}`
|
|
17198
|
+
}),
|
|
17199
|
+
createOperationSpec({
|
|
17200
|
+
operationName: "LibraryAssetWorkbench",
|
|
17201
|
+
apiKeyAccess: apiKeyAccessPolicies.libraryDenied,
|
|
17202
|
+
kind: "query",
|
|
17203
|
+
inputSchema: z28.object({
|
|
17204
|
+
libraryEntityId: z28.string().min(1)
|
|
17205
|
+
}),
|
|
17206
|
+
cli: {
|
|
17207
|
+
name: "library-asset-get",
|
|
17208
|
+
path: ["library", "get"],
|
|
17209
|
+
description: "Fetch a shared library asset and its agent tree. Requires user login.",
|
|
17210
|
+
resultKey: "libraryAssetWorkbench",
|
|
17211
|
+
options: [
|
|
17212
|
+
stringOption({
|
|
17213
|
+
inputKey: "libraryEntityId",
|
|
17214
|
+
flagName: "library-entity-id",
|
|
17215
|
+
description: "Library asset ID.",
|
|
17216
|
+
required: true
|
|
17217
|
+
})
|
|
17218
|
+
]
|
|
17219
|
+
},
|
|
17220
|
+
mcp: { fileName: "libraryAssetWorkbench.graphql" },
|
|
17221
|
+
document: `query LibraryAssetWorkbench($libraryEntityId: ID!) {
|
|
17222
|
+
libraryAssetWorkbench(libraryEntityId: $libraryEntityId) {
|
|
17223
|
+
${LIBRARY_ASSET_WORKBENCH_SELECTION}
|
|
17224
|
+
}
|
|
17225
|
+
}`
|
|
17226
|
+
}),
|
|
17227
|
+
createOperationSpec({
|
|
17228
|
+
operationName: "CreateLibraryAsset",
|
|
17229
|
+
apiKeyAccess: apiKeyAccessPolicies.libraryDenied,
|
|
17230
|
+
kind: "mutation",
|
|
17231
|
+
inputSchema: z28.object({
|
|
17232
|
+
assetName: z28.string().trim().min(1).optional()
|
|
17233
|
+
}),
|
|
17234
|
+
cli: {
|
|
17235
|
+
name: "create-library-asset",
|
|
17236
|
+
path: ["library", "create"],
|
|
17237
|
+
description: "Create an empty shared library asset with a single root agent. Requires user login.",
|
|
17238
|
+
resultKey: "createLibraryAsset",
|
|
17239
|
+
options: [
|
|
17240
|
+
stringOption({
|
|
17241
|
+
inputKey: "assetName",
|
|
17242
|
+
flagName: "name",
|
|
17243
|
+
description: 'Asset name. Defaults to "New Asset".'
|
|
17244
|
+
})
|
|
17245
|
+
]
|
|
17246
|
+
},
|
|
17247
|
+
mcp: { fileName: "createLibraryAsset.graphql" },
|
|
17248
|
+
document: `mutation CreateLibraryAsset($assetName: String) {
|
|
17249
|
+
createLibraryAsset(assetName: $assetName) {
|
|
17250
|
+
${LIBRARY_ASSET_WORKBENCH_SELECTION}
|
|
17251
|
+
}
|
|
17252
|
+
}`
|
|
17253
|
+
}),
|
|
17254
|
+
createOperationSpec({
|
|
17255
|
+
operationName: "ConvertAutomationSubtreeToLibraryAsset",
|
|
17256
|
+
apiKeyAccess: apiKeyAccessPolicies.libraryDenied,
|
|
17257
|
+
kind: "mutation",
|
|
17258
|
+
inputSchema: z28.object({
|
|
17259
|
+
draftAutomationId: z28.string().min(1),
|
|
17260
|
+
rootAgentId: z28.string().min(1),
|
|
17261
|
+
baseVersionId: z28.string().min(1),
|
|
17262
|
+
assetName: z28.string().trim().min(1).optional()
|
|
17263
|
+
}),
|
|
17264
|
+
cli: {
|
|
17265
|
+
name: "convert-to-library-asset",
|
|
17266
|
+
path: ["library", "convert"],
|
|
17267
|
+
description: "Convert an agent and its descendants in a draft automation into a new shared library asset. Requires user login.",
|
|
17268
|
+
resultKey: "convertAutomationSubtreeToLibraryAsset",
|
|
17269
|
+
options: [
|
|
17270
|
+
stringOption({
|
|
17271
|
+
inputKey: "draftAutomationId",
|
|
17272
|
+
flagName: "draft-automation-id",
|
|
17273
|
+
description: "Draft automation ID.",
|
|
17274
|
+
required: true
|
|
17275
|
+
}),
|
|
17276
|
+
stringOption({
|
|
17277
|
+
inputKey: "rootAgentId",
|
|
17278
|
+
flagName: "root-agent-id",
|
|
17279
|
+
description: "Agent that becomes the asset root.",
|
|
17280
|
+
required: true
|
|
17281
|
+
}),
|
|
17282
|
+
stringOption({
|
|
17283
|
+
inputKey: "baseVersionId",
|
|
17284
|
+
flagName: "base-version-id",
|
|
17285
|
+
description: "Current draftVersionId from a fresh automation fetch.",
|
|
17286
|
+
required: true
|
|
17287
|
+
}),
|
|
17288
|
+
stringOption({
|
|
17289
|
+
inputKey: "assetName",
|
|
17290
|
+
flagName: "name",
|
|
17291
|
+
description: "Asset name. Renames the root agent; defaults to its current name."
|
|
17292
|
+
})
|
|
17293
|
+
]
|
|
17294
|
+
},
|
|
17295
|
+
mcp: { fileName: "convertAutomationSubtreeToLibraryAsset.graphql" },
|
|
17296
|
+
document: `mutation ConvertAutomationSubtreeToLibraryAsset(
|
|
17297
|
+
$draftAutomationId: ID!
|
|
17298
|
+
$rootAgentId: ID!
|
|
17299
|
+
$baseVersionId: ID!
|
|
17300
|
+
$assetName: String
|
|
17301
|
+
) {
|
|
17302
|
+
convertAutomationSubtreeToLibraryAsset(
|
|
17303
|
+
draftAutomationId: $draftAutomationId
|
|
17304
|
+
rootAgentId: $rootAgentId
|
|
17305
|
+
baseVersionId: $baseVersionId
|
|
17306
|
+
assetName: $assetName
|
|
17307
|
+
) {
|
|
17308
|
+
automationId
|
|
17309
|
+
rootAgentId
|
|
17310
|
+
libraryEntityId
|
|
17311
|
+
libraryEntityVersionId
|
|
17312
|
+
convertedAgentIds
|
|
17313
|
+
draftVersionId
|
|
17314
|
+
lastSavedAt
|
|
17315
|
+
}
|
|
17316
|
+
}`
|
|
17317
|
+
}),
|
|
17318
|
+
createOperationSpec({
|
|
17319
|
+
operationName: "ImportLibraryAssetToAutomation",
|
|
17320
|
+
apiKeyAccess: apiKeyAccessPolicies.libraryDenied,
|
|
17321
|
+
kind: "mutation",
|
|
17322
|
+
inputSchema: z28.object({
|
|
17323
|
+
draftAutomationId: z28.string().min(1),
|
|
17324
|
+
libraryEntityId: z28.string().min(1),
|
|
17325
|
+
baseVersionId: z28.string().min(1),
|
|
17326
|
+
parentAgentId: z28.string().min(1).optional()
|
|
17327
|
+
}),
|
|
17328
|
+
cli: {
|
|
17329
|
+
name: "import-library-asset",
|
|
17330
|
+
path: ["library", "import"],
|
|
17331
|
+
description: "Import a shared library asset into a draft automation, optionally under a parent agent. The automation stays linked to the asset. Requires user login.",
|
|
17332
|
+
resultKey: "importLibraryAssetToAutomation",
|
|
17333
|
+
options: [
|
|
17334
|
+
stringOption({
|
|
17335
|
+
inputKey: "draftAutomationId",
|
|
17336
|
+
flagName: "draft-automation-id",
|
|
17337
|
+
description: "Draft automation ID.",
|
|
17338
|
+
required: true
|
|
17339
|
+
}),
|
|
17340
|
+
stringOption({
|
|
17341
|
+
inputKey: "libraryEntityId",
|
|
17342
|
+
flagName: "library-entity-id",
|
|
17343
|
+
description: "Library asset ID.",
|
|
17344
|
+
required: true
|
|
17345
|
+
}),
|
|
17346
|
+
stringOption({
|
|
17347
|
+
inputKey: "baseVersionId",
|
|
17348
|
+
flagName: "base-version-id",
|
|
17349
|
+
description: "Current draftVersionId from a fresh automation fetch.",
|
|
17350
|
+
required: true
|
|
17351
|
+
}),
|
|
17352
|
+
stringOption({
|
|
17353
|
+
inputKey: "parentAgentId",
|
|
17354
|
+
flagName: "parent-agent-id",
|
|
17355
|
+
description: "Existing agent to attach the asset under. Omit to add it top-level."
|
|
17356
|
+
})
|
|
17357
|
+
]
|
|
17358
|
+
},
|
|
17359
|
+
mcp: { fileName: "importLibraryAssetToAutomation.graphql" },
|
|
17360
|
+
document: `mutation ImportLibraryAssetToAutomation(
|
|
17361
|
+
$draftAutomationId: ID!
|
|
17362
|
+
$libraryEntityId: ID!
|
|
17363
|
+
$baseVersionId: ID!
|
|
17364
|
+
$parentAgentId: ID
|
|
17365
|
+
) {
|
|
17366
|
+
importLibraryAssetToAutomation(
|
|
17367
|
+
draftAutomationId: $draftAutomationId
|
|
17368
|
+
libraryEntityId: $libraryEntityId
|
|
17369
|
+
baseVersionId: $baseVersionId
|
|
17370
|
+
parentAgentId: $parentAgentId
|
|
17371
|
+
) {
|
|
17372
|
+
automationId
|
|
17373
|
+
parentAgentId
|
|
17374
|
+
rootAgentId
|
|
17375
|
+
libraryEntityId
|
|
17376
|
+
libraryEntityVersionId
|
|
17377
|
+
importedAgentIds
|
|
17378
|
+
draftVersionId
|
|
17379
|
+
lastSavedAt
|
|
17380
|
+
}
|
|
17031
17381
|
}`
|
|
17032
17382
|
}),
|
|
17033
17383
|
createOperationSpec({
|
|
@@ -21536,18 +21886,18 @@ async function downloadAuthenticatedFileFromApi({
|
|
|
21536
21886
|
organizationId,
|
|
21537
21887
|
outputPath,
|
|
21538
21888
|
overwrite = false,
|
|
21539
|
-
path:
|
|
21889
|
+
path: path22,
|
|
21540
21890
|
resolveApiBaseUrl,
|
|
21541
21891
|
timeoutMs
|
|
21542
21892
|
}) {
|
|
21543
|
-
if (!
|
|
21893
|
+
if (!path22.startsWith("/") || path22.startsWith("//")) {
|
|
21544
21894
|
throw new CliError(
|
|
21545
21895
|
"Authenticated file download path must be relative to the configured Magical API."
|
|
21546
21896
|
);
|
|
21547
21897
|
}
|
|
21548
21898
|
const normalizedApiBaseUrl = trimTrailingSlash(await resolveApiBaseUrl());
|
|
21549
21899
|
const apiBaseResult = safeUrlConstructor(`${normalizedApiBaseUrl}/`);
|
|
21550
|
-
const urlResult = safeUrlConstructor(`${normalizedApiBaseUrl}${
|
|
21900
|
+
const urlResult = safeUrlConstructor(`${normalizedApiBaseUrl}${path22}`);
|
|
21551
21901
|
if (isErr(apiBaseResult) || isErr(urlResult) || urlResult.value.origin !== apiBaseResult.value.origin || !urlResult.value.pathname.startsWith(apiBaseResult.value.pathname)) {
|
|
21552
21902
|
throw new CliError(
|
|
21553
21903
|
"Authenticated file download path must stay within the configured Magical API."
|
|
@@ -21644,16 +21994,16 @@ function buildPathwayRegressionAgentVersionPath({
|
|
|
21644
21994
|
leafPath,
|
|
21645
21995
|
runsPerPath
|
|
21646
21996
|
}) {
|
|
21647
|
-
const
|
|
21997
|
+
const path22 = `/pathway-regression/automation-versions/${encodeURIComponent(
|
|
21648
21998
|
automationVersionId
|
|
21649
21999
|
)}/agent-versions/${encodeURIComponent(agentVersionId)}/${leafPath}`;
|
|
21650
22000
|
if (runsPerPath === void 0) {
|
|
21651
|
-
return
|
|
22001
|
+
return path22;
|
|
21652
22002
|
}
|
|
21653
22003
|
const queryParams = new URLSearchParams({
|
|
21654
22004
|
runsPerPath: String(runsPerPath)
|
|
21655
22005
|
});
|
|
21656
|
-
return `${
|
|
22006
|
+
return `${path22}?${queryParams.toString()}`;
|
|
21657
22007
|
}
|
|
21658
22008
|
function applyAuthenticationHeaders({
|
|
21659
22009
|
accessToken,
|
|
@@ -21689,11 +22039,11 @@ function createFetchJson({
|
|
|
21689
22039
|
accessToken,
|
|
21690
22040
|
impersonatedOrganizationId,
|
|
21691
22041
|
allowOttoAuthorization,
|
|
21692
|
-
path:
|
|
22042
|
+
path: path22,
|
|
21693
22043
|
init,
|
|
21694
22044
|
organizationId
|
|
21695
22045
|
}) {
|
|
21696
|
-
const url = `${trimTrailingSlash(await resolveApiBaseUrl())}${
|
|
22046
|
+
const url = `${trimTrailingSlash(await resolveApiBaseUrl())}${path22}`;
|
|
21697
22047
|
const usesWorkOSApiKey = isWorkOSApiKey(accessToken);
|
|
21698
22048
|
const headers = new Headers(init?.headers);
|
|
21699
22049
|
applyAuthenticationHeaders({
|
|
@@ -21893,7 +22243,7 @@ function createMagicalApiClient({
|
|
|
21893
22243
|
organizationId,
|
|
21894
22244
|
outputPath,
|
|
21895
22245
|
overwrite = false,
|
|
21896
|
-
path:
|
|
22246
|
+
path: path22,
|
|
21897
22247
|
timeoutMs
|
|
21898
22248
|
}) {
|
|
21899
22249
|
await downloadAuthenticatedFileFromApi({
|
|
@@ -21906,7 +22256,7 @@ function createMagicalApiClient({
|
|
|
21906
22256
|
...maxSizeBytes === void 0 ? {} : { maxSizeBytes },
|
|
21907
22257
|
outputPath,
|
|
21908
22258
|
overwrite,
|
|
21909
|
-
path:
|
|
22259
|
+
path: path22,
|
|
21910
22260
|
resolveApiBaseUrl,
|
|
21911
22261
|
...timeoutMs === void 0 ? {} : { timeoutMs }
|
|
21912
22262
|
});
|
|
@@ -29039,6 +29389,55 @@ function resolveOpenCommand(url) {
|
|
|
29039
29389
|
return { executable: "xdg-open", args: [url] };
|
|
29040
29390
|
}
|
|
29041
29391
|
|
|
29392
|
+
// src/operation-variables.ts
|
|
29393
|
+
import { readFile as readFile5 } from "node:fs/promises";
|
|
29394
|
+
import path16 from "node:path";
|
|
29395
|
+
function parseOperationVariables(operationSpec, variables) {
|
|
29396
|
+
const parsedVariables = operationSpec.inputSchema.safeParse(variables);
|
|
29397
|
+
if (!parsedVariables.success) {
|
|
29398
|
+
throw new CliError(
|
|
29399
|
+
parsedVariables.error.issues[0]?.message ?? "Invalid command input."
|
|
29400
|
+
);
|
|
29401
|
+
}
|
|
29402
|
+
if (!isStringKeyedRecord(parsedVariables.data)) {
|
|
29403
|
+
throw new CliError("Invalid command input.");
|
|
29404
|
+
}
|
|
29405
|
+
return parsedVariables.data;
|
|
29406
|
+
}
|
|
29407
|
+
async function resolveOperationVariables({
|
|
29408
|
+
operationSpec,
|
|
29409
|
+
variables,
|
|
29410
|
+
options,
|
|
29411
|
+
workingDirectory = process.cwd()
|
|
29412
|
+
}) {
|
|
29413
|
+
return parseOperationVariables(
|
|
29414
|
+
operationSpec,
|
|
29415
|
+
operationSpec.operationName === "ImportAgents" ? {
|
|
29416
|
+
...variables,
|
|
29417
|
+
data: await readAgentImportFile(options["file"], workingDirectory)
|
|
29418
|
+
} : variables
|
|
29419
|
+
);
|
|
29420
|
+
}
|
|
29421
|
+
async function readAgentImportFile(file, workingDirectory) {
|
|
29422
|
+
if (typeof file !== "string" || !file.trim()) {
|
|
29423
|
+
throw new CliError(
|
|
29424
|
+
"Provide --file with the JSON file produced by agents export --json."
|
|
29425
|
+
);
|
|
29426
|
+
}
|
|
29427
|
+
const contents = await fromThrowable(
|
|
29428
|
+
async () => readFile5(path16.resolve(workingDirectory, file), "utf8"),
|
|
29429
|
+
"read-file-error"
|
|
29430
|
+
);
|
|
29431
|
+
if (isErr(contents)) {
|
|
29432
|
+
throw new CliError(`Could not read agent import file: ${file}`);
|
|
29433
|
+
}
|
|
29434
|
+
const parsed = safeJsonParseWithoutLogging(contents.value);
|
|
29435
|
+
if (isErr(parsed)) {
|
|
29436
|
+
throw new CliError("Agent import file is not valid JSON.");
|
|
29437
|
+
}
|
|
29438
|
+
return parsed.value;
|
|
29439
|
+
}
|
|
29440
|
+
|
|
29042
29441
|
// src/program-command-types.ts
|
|
29043
29442
|
var SESSION_ONLY_API_KEY_MANAGEMENT_COMMANDS = /* @__PURE__ */ new Set([
|
|
29044
29443
|
"auth keys list",
|
|
@@ -29777,7 +30176,7 @@ function addRunEvidenceCommands({
|
|
|
29777
30176
|
// src/self-update.ts
|
|
29778
30177
|
import { spawn as spawn3 } from "node:child_process";
|
|
29779
30178
|
import fs2 from "node:fs";
|
|
29780
|
-
import
|
|
30179
|
+
import path17 from "node:path";
|
|
29781
30180
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
29782
30181
|
var CLI_PACKAGE_NAME = "@getmagical/cli";
|
|
29783
30182
|
var DEFAULT_CLI_DIST_TAG2 = "latest";
|
|
@@ -29788,9 +30187,9 @@ function resolveInstalledPackageRoot({
|
|
|
29788
30187
|
packageName
|
|
29789
30188
|
}) {
|
|
29790
30189
|
const packagePathSegments = packageName.split("/");
|
|
29791
|
-
let currentPath =
|
|
30190
|
+
let currentPath = path17.dirname(entryFilePath);
|
|
29792
30191
|
for (; ; ) {
|
|
29793
|
-
const currentPathSegments = currentPath.split(
|
|
30192
|
+
const currentPathSegments = currentPath.split(path17.sep).filter(Boolean);
|
|
29794
30193
|
const currentPackageSegments = currentPathSegments.slice(
|
|
29795
30194
|
-packagePathSegments.length
|
|
29796
30195
|
);
|
|
@@ -29799,7 +30198,7 @@ function resolveInstalledPackageRoot({
|
|
|
29799
30198
|
)) {
|
|
29800
30199
|
return currentPath;
|
|
29801
30200
|
}
|
|
29802
|
-
const parentPath =
|
|
30201
|
+
const parentPath = path17.dirname(currentPath);
|
|
29803
30202
|
if (parentPath === currentPath) {
|
|
29804
30203
|
return null;
|
|
29805
30204
|
}
|
|
@@ -29809,14 +30208,14 @@ function resolveInstalledPackageRoot({
|
|
|
29809
30208
|
function resolveInstallPrefixFromPackageRoot(packageRootPath) {
|
|
29810
30209
|
let currentPath = packageRootPath;
|
|
29811
30210
|
for (; ; ) {
|
|
29812
|
-
if (
|
|
29813
|
-
const nodeModulesParentPath =
|
|
29814
|
-
if (
|
|
29815
|
-
return
|
|
30211
|
+
if (path17.basename(currentPath) === "node_modules") {
|
|
30212
|
+
const nodeModulesParentPath = path17.dirname(currentPath);
|
|
30213
|
+
if (path17.basename(nodeModulesParentPath) === "lib") {
|
|
30214
|
+
return path17.dirname(nodeModulesParentPath);
|
|
29816
30215
|
}
|
|
29817
30216
|
return nodeModulesParentPath;
|
|
29818
30217
|
}
|
|
29819
|
-
const parentPath =
|
|
30218
|
+
const parentPath = path17.dirname(currentPath);
|
|
29820
30219
|
if (parentPath === currentPath) {
|
|
29821
30220
|
return null;
|
|
29822
30221
|
}
|
|
@@ -29833,13 +30232,13 @@ function resolveManagedNpmCommand(installPrefix) {
|
|
|
29833
30232
|
if (process.platform === "win32") {
|
|
29834
30233
|
return null;
|
|
29835
30234
|
}
|
|
29836
|
-
const managedNodeExecutable =
|
|
30235
|
+
const managedNodeExecutable = path17.join(
|
|
29837
30236
|
installPrefix,
|
|
29838
30237
|
MANAGED_NODE_SUBPATH,
|
|
29839
30238
|
"bin",
|
|
29840
30239
|
"node"
|
|
29841
30240
|
);
|
|
29842
|
-
const managedNpmCli =
|
|
30241
|
+
const managedNpmCli = path17.join(
|
|
29843
30242
|
installPrefix,
|
|
29844
30243
|
MANAGED_NODE_SUBPATH,
|
|
29845
30244
|
"lib",
|
|
@@ -29938,8 +30337,8 @@ async function selfUpdateInstalledCli({
|
|
|
29938
30337
|
}
|
|
29939
30338
|
|
|
29940
30339
|
// src/settings.ts
|
|
29941
|
-
import { mkdir as mkdir4, readFile as
|
|
29942
|
-
import
|
|
30340
|
+
import { mkdir as mkdir4, readFile as readFile6, rm as rm4, writeFile as writeFile2 } from "node:fs/promises";
|
|
30341
|
+
import path18 from "node:path";
|
|
29943
30342
|
import { z as z44 } from "zod";
|
|
29944
30343
|
var cliSettingsSchema = z44.object({
|
|
29945
30344
|
env: z44.object({
|
|
@@ -29958,13 +30357,13 @@ function hasCliSettingsOverrides(settings) {
|
|
|
29958
30357
|
return Object.values(settings.env).some((value) => value !== void 0);
|
|
29959
30358
|
}
|
|
29960
30359
|
function resolveSettingsFilePath(stateFilePath) {
|
|
29961
|
-
return
|
|
30360
|
+
return path18.join(path18.dirname(stateFilePath), CLI_SETTINGS_FILE_NAME);
|
|
29962
30361
|
}
|
|
29963
30362
|
function createFileSettingsStore(stateFilePath) {
|
|
29964
30363
|
const settingsFilePath = resolveSettingsFilePath(stateFilePath);
|
|
29965
30364
|
return {
|
|
29966
30365
|
async load() {
|
|
29967
|
-
const fileContents = await
|
|
30366
|
+
const fileContents = await readFile6(settingsFilePath, "utf8").catch(
|
|
29968
30367
|
(error) => {
|
|
29969
30368
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
29970
30369
|
return null;
|
|
@@ -29994,7 +30393,7 @@ function createFileSettingsStore(stateFilePath) {
|
|
|
29994
30393
|
await rm4(settingsFilePath, { force: true });
|
|
29995
30394
|
return;
|
|
29996
30395
|
}
|
|
29997
|
-
await mkdir4(
|
|
30396
|
+
await mkdir4(path18.dirname(settingsFilePath), { recursive: true });
|
|
29998
30397
|
await writeFile2(
|
|
29999
30398
|
settingsFilePath,
|
|
30000
30399
|
`${JSON.stringify(settings, null, 2)}
|
|
@@ -30162,14 +30561,14 @@ import {
|
|
|
30162
30561
|
lstat as lstat2,
|
|
30163
30562
|
mkdir as mkdir5,
|
|
30164
30563
|
mkdtemp as mkdtemp2,
|
|
30165
|
-
readFile as
|
|
30564
|
+
readFile as readFile7,
|
|
30166
30565
|
readdir,
|
|
30167
30566
|
rename as rename4,
|
|
30168
30567
|
rm as rm5,
|
|
30169
30568
|
writeFile as writeFile3
|
|
30170
30569
|
} from "node:fs/promises";
|
|
30171
30570
|
import os3 from "node:os";
|
|
30172
|
-
import
|
|
30571
|
+
import path19 from "node:path";
|
|
30173
30572
|
import { z as z45 } from "zod";
|
|
30174
30573
|
var SKILLS_ROOT_PATH = "skills";
|
|
30175
30574
|
var METADATA_DIRECTORY_NAME = "skill-working-copies";
|
|
@@ -30240,12 +30639,12 @@ function normalizeRootSkillPath(skill) {
|
|
|
30240
30639
|
return `${SKILLS_ROOT_PATH}/${skillName}`;
|
|
30241
30640
|
}
|
|
30242
30641
|
function resolveWorkingCopyPath(workingDirectory, skillPath) {
|
|
30243
|
-
return
|
|
30642
|
+
return path19.resolve(workingDirectory, ...skillPath.split("/"));
|
|
30244
30643
|
}
|
|
30245
30644
|
function resolveMetadataPath(stateFilePath, workingCopyPath) {
|
|
30246
30645
|
const key = createHash3("sha256").update(workingCopyPath).digest("hex");
|
|
30247
|
-
return
|
|
30248
|
-
|
|
30646
|
+
return path19.join(
|
|
30647
|
+
path19.dirname(stateFilePath),
|
|
30249
30648
|
METADATA_DIRECTORY_NAME,
|
|
30250
30649
|
`${key}.json`
|
|
30251
30650
|
);
|
|
@@ -30273,7 +30672,7 @@ function metadataFilesToSnapshot(files) {
|
|
|
30273
30672
|
);
|
|
30274
30673
|
}
|
|
30275
30674
|
async function loadMetadata(metadataPath) {
|
|
30276
|
-
const fileContents = await
|
|
30675
|
+
const fileContents = await readFile7(metadataPath, "utf8").catch(
|
|
30277
30676
|
(error) => {
|
|
30278
30677
|
if (isMissingFileError3(error)) {
|
|
30279
30678
|
return null;
|
|
@@ -30297,7 +30696,7 @@ async function loadMetadata(metadataPath) {
|
|
|
30297
30696
|
return parsed.data;
|
|
30298
30697
|
}
|
|
30299
30698
|
async function saveMetadata(metadataPath, metadata) {
|
|
30300
|
-
await mkdir5(
|
|
30699
|
+
await mkdir5(path19.dirname(metadataPath), { recursive: true });
|
|
30301
30700
|
const temporaryPath = `${metadataPath}.${randomUUID6()}.tmp`;
|
|
30302
30701
|
await writeFile3(temporaryPath, `${JSON.stringify(metadata, null, 2)}
|
|
30303
30702
|
`, {
|
|
@@ -30374,7 +30773,7 @@ async function readDirectorySnapshot({
|
|
|
30374
30773
|
const nextSegments = [...segments, entry.name];
|
|
30375
30774
|
const relativePath = nextSegments.join("/");
|
|
30376
30775
|
assertSafeRelativeFilePath(relativePath);
|
|
30377
|
-
const filePath =
|
|
30776
|
+
const filePath = path19.join(currentDirectory, entry.name);
|
|
30378
30777
|
if (entry.isDirectory()) {
|
|
30379
30778
|
return await visit(filePath, nextSegments);
|
|
30380
30779
|
}
|
|
@@ -30383,7 +30782,7 @@ async function readDirectorySnapshot({
|
|
|
30383
30782
|
`Skill working copy contains unsupported entry "${filePath}". Only regular files and directories are allowed.`
|
|
30384
30783
|
);
|
|
30385
30784
|
}
|
|
30386
|
-
return [[`${skillPath}/${relativePath}`, await
|
|
30785
|
+
return [[`${skillPath}/${relativePath}`, await readFile7(filePath)]];
|
|
30387
30786
|
})
|
|
30388
30787
|
);
|
|
30389
30788
|
return nestedEntries.flat();
|
|
@@ -30409,8 +30808,8 @@ async function writeSnapshotContents(rootPath, snapshot, prefix) {
|
|
|
30409
30808
|
[...snapshot.entries()].map(async ([filePath, content]) => {
|
|
30410
30809
|
const relativePath = prefix === null ? filePath : filePath.slice(`${prefix}/`.length);
|
|
30411
30810
|
assertSafeRelativeFilePath(relativePath);
|
|
30412
|
-
const targetPath =
|
|
30413
|
-
await mkdir5(
|
|
30811
|
+
const targetPath = path19.join(rootPath, ...relativePath.split("/"));
|
|
30812
|
+
await mkdir5(path19.dirname(targetPath), { recursive: true });
|
|
30414
30813
|
await writeFile3(targetPath, content);
|
|
30415
30814
|
})
|
|
30416
30815
|
);
|
|
@@ -30420,11 +30819,11 @@ async function replaceWorkingCopy({
|
|
|
30420
30819
|
skillPath,
|
|
30421
30820
|
workingCopyPath
|
|
30422
30821
|
}) {
|
|
30423
|
-
const parentPath =
|
|
30822
|
+
const parentPath = path19.dirname(workingCopyPath);
|
|
30424
30823
|
await mkdir5(parentPath, { recursive: true });
|
|
30425
|
-
const temporaryPath =
|
|
30824
|
+
const temporaryPath = path19.join(
|
|
30426
30825
|
parentPath,
|
|
30427
|
-
`.mgcl-${
|
|
30826
|
+
`.mgcl-${path19.basename(workingCopyPath)}-${randomUUID6()}.tmp`
|
|
30428
30827
|
);
|
|
30429
30828
|
const backupPath = `${workingCopyPath}.${randomUUID6()}.bak`;
|
|
30430
30829
|
await mkdir5(temporaryPath);
|
|
@@ -30495,7 +30894,7 @@ async function clearDirectoryExceptGit(directoryPath) {
|
|
|
30495
30894
|
const entries = await readdir(directoryPath);
|
|
30496
30895
|
await Promise.all(
|
|
30497
30896
|
entries.filter((entry) => entry !== ".git").map(async (entry) => {
|
|
30498
|
-
await rm5(
|
|
30897
|
+
await rm5(path19.join(directoryPath, entry), {
|
|
30499
30898
|
force: true,
|
|
30500
30899
|
recursive: true
|
|
30501
30900
|
});
|
|
@@ -30507,7 +30906,7 @@ async function createPatch(before, after) {
|
|
|
30507
30906
|
return "";
|
|
30508
30907
|
}
|
|
30509
30908
|
const repositoryPath = await mkdtemp2(
|
|
30510
|
-
|
|
30909
|
+
path19.join(os3.tmpdir(), "mgcl-skills-diff-")
|
|
30511
30910
|
);
|
|
30512
30911
|
const patchResult = await fromThrowable(async () => {
|
|
30513
30912
|
await runGit(["init", "--quiet"], repositoryPath);
|
|
@@ -30829,8 +31228,8 @@ async function pushSkillWorkingCopy({
|
|
|
30829
31228
|
}
|
|
30830
31229
|
|
|
30831
31230
|
// src/state.ts
|
|
30832
|
-
import { mkdir as mkdir6, readFile as
|
|
30833
|
-
import
|
|
31231
|
+
import { mkdir as mkdir6, readFile as readFile8, rm as rm6, writeFile as writeFile4 } from "node:fs/promises";
|
|
31232
|
+
import path20 from "node:path";
|
|
30834
31233
|
import { z as z46 } from "zod";
|
|
30835
31234
|
var cliAccountSchema = z46.object({
|
|
30836
31235
|
clientId: z46.string().min(1),
|
|
@@ -30857,7 +31256,7 @@ function createFileStateStore(stateFilePath) {
|
|
|
30857
31256
|
},
|
|
30858
31257
|
async load() {
|
|
30859
31258
|
try {
|
|
30860
|
-
const fileContents = await
|
|
31259
|
+
const fileContents = await readFile8(stateFilePath, "utf8");
|
|
30861
31260
|
const parsed = cliStateSchema.safeParse(JSON.parse(fileContents));
|
|
30862
31261
|
if (!parsed.success) {
|
|
30863
31262
|
throw new CliError("Stored CLI state is invalid.");
|
|
@@ -30874,7 +31273,7 @@ function createFileStateStore(stateFilePath) {
|
|
|
30874
31273
|
}
|
|
30875
31274
|
},
|
|
30876
31275
|
async save(state) {
|
|
30877
|
-
await mkdir6(
|
|
31276
|
+
await mkdir6(path20.dirname(stateFilePath), { recursive: true });
|
|
30878
31277
|
await writeFile4(stateFilePath, `${JSON.stringify(state, null, 2)}
|
|
30879
31278
|
`);
|
|
30880
31279
|
}
|
|
@@ -30883,7 +31282,7 @@ function createFileStateStore(stateFilePath) {
|
|
|
30883
31282
|
function createFileRefreshTokenStore(refreshTokenFilePath) {
|
|
30884
31283
|
async function loadRefreshTokens() {
|
|
30885
31284
|
try {
|
|
30886
|
-
const fileContents = await
|
|
31285
|
+
const fileContents = await readFile8(refreshTokenFilePath, "utf8");
|
|
30887
31286
|
const parsed = refreshTokenFileSchema.safeParse(JSON.parse(fileContents));
|
|
30888
31287
|
if (!parsed.success) {
|
|
30889
31288
|
throw new CliError("Stored refresh tokens are invalid.");
|
|
@@ -30902,7 +31301,7 @@ function createFileRefreshTokenStore(refreshTokenFilePath) {
|
|
|
30902
31301
|
}
|
|
30903
31302
|
}
|
|
30904
31303
|
async function saveRefreshTokens(refreshTokens) {
|
|
30905
|
-
await mkdir6(
|
|
31304
|
+
await mkdir6(path20.dirname(refreshTokenFilePath), { recursive: true });
|
|
30906
31305
|
await writeFile4(
|
|
30907
31306
|
refreshTokenFilePath,
|
|
30908
31307
|
`${JSON.stringify(refreshTokens, null, 2)}
|
|
@@ -31234,18 +31633,6 @@ function collectOperationVariableInput(operationSpec, options) {
|
|
|
31234
31633
|
}
|
|
31235
31634
|
return variables;
|
|
31236
31635
|
}
|
|
31237
|
-
function parseOperationVariables(operationSpec, variables) {
|
|
31238
|
-
const parsedVariables = operationSpec.inputSchema.safeParse(variables);
|
|
31239
|
-
if (!parsedVariables.success) {
|
|
31240
|
-
throw new CliError(
|
|
31241
|
-
parsedVariables.error.issues[0]?.message ?? "Invalid command input."
|
|
31242
|
-
);
|
|
31243
|
-
}
|
|
31244
|
-
if (!isRecord7(parsedVariables.data)) {
|
|
31245
|
-
throw new CliError("Invalid command input.");
|
|
31246
|
-
}
|
|
31247
|
-
return parsedVariables.data;
|
|
31248
|
-
}
|
|
31249
31636
|
async function handleSelfUpdate(dependencies, options) {
|
|
31250
31637
|
const { selfUpdateCli } = dependencies;
|
|
31251
31638
|
if (!selfUpdateCli) {
|
|
@@ -31290,7 +31677,12 @@ async function handleOperationCommand(dependencies, operationSpec, commandOption
|
|
|
31290
31677
|
runtime: dependencies.classifyCommandRuntime,
|
|
31291
31678
|
workingDirectory: dependencies.workingDirectory ?? process.cwd()
|
|
31292
31679
|
});
|
|
31293
|
-
const variables =
|
|
31680
|
+
const variables = await resolveOperationVariables({
|
|
31681
|
+
operationSpec,
|
|
31682
|
+
variables: operationVariables,
|
|
31683
|
+
options: commandOptions,
|
|
31684
|
+
workingDirectory: dependencies.workingDirectory
|
|
31685
|
+
});
|
|
31294
31686
|
const apiKeyEnvironment = getApiKeyEnvironment(
|
|
31295
31687
|
dependencies,
|
|
31296
31688
|
commandOptions.apiKey
|
|
@@ -32323,12 +32715,12 @@ function createDefaultDependencies() {
|
|
|
32323
32715
|
return resolveDeploymentTarget({ savedEnv: settings.env, selectors });
|
|
32324
32716
|
};
|
|
32325
32717
|
const resolveApiBaseUrl = () => deploymentTargetContext.get().apiUrl;
|
|
32326
|
-
const accessTokenFilePath = runtimeConfig.accessTokenFilePath ??
|
|
32327
|
-
|
|
32718
|
+
const accessTokenFilePath = runtimeConfig.accessTokenFilePath ?? path21.join(
|
|
32719
|
+
path21.dirname(runtimeConfig.stateFilePath),
|
|
32328
32720
|
CLI_ACCESS_TOKEN_FILE_NAME
|
|
32329
32721
|
);
|
|
32330
|
-
const refreshTokenFilePath = runtimeConfig.refreshTokenFilePath ??
|
|
32331
|
-
|
|
32722
|
+
const refreshTokenFilePath = runtimeConfig.refreshTokenFilePath ?? path21.join(
|
|
32723
|
+
path21.dirname(runtimeConfig.stateFilePath),
|
|
32332
32724
|
CLI_REFRESH_TOKEN_FILE_NAME
|
|
32333
32725
|
);
|
|
32334
32726
|
const selfUpdateOptions = {
|
|
@@ -32346,8 +32738,8 @@ function createDefaultDependencies() {
|
|
|
32346
32738
|
io: createConsoleIo(),
|
|
32347
32739
|
openExternalUrl,
|
|
32348
32740
|
orgPreferencesStore: createFileOrgPreferencesStore(
|
|
32349
|
-
|
|
32350
|
-
|
|
32741
|
+
path21.join(
|
|
32742
|
+
path21.dirname(runtimeConfig.stateFilePath),
|
|
32351
32743
|
"organization-preferences"
|
|
32352
32744
|
)
|
|
32353
32745
|
),
|