@meistrari/tela-cli 1.4.0 → 1.5.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/index.js
CHANGED
|
@@ -146996,7 +146996,7 @@ var require_contracts = __commonJS({
|
|
|
146996
146996
|
"../../packages/workflow-code/dist/contracts.js"(exports2) {
|
|
146997
146997
|
"use strict";
|
|
146998
146998
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
146999
|
-
exports2.BUILD_BINDING = exports2.CODE_BINDING = exports2.CODE_DIAGNOSTICS = exports2.REMOTE_REF_BINDING = void 0;
|
|
146999
|
+
exports2.CONDITION_BINDING = exports2.BUILD_BINDING = exports2.CODE_BINDING = exports2.CODE_DIAGNOSTICS = exports2.REMOTE_REF_BINDING = void 0;
|
|
147000
147000
|
exports2.REMOTE_REF_BINDING = /* @__PURE__ */ Symbol.for("@meistrari/workflow-code/remote-ref-binding");
|
|
147001
147001
|
exports2.CODE_DIAGNOSTICS = Object.freeze({
|
|
147002
147002
|
missingHandlerBinding: "code.source.missing_handler_binding",
|
|
@@ -147019,6 +147019,7 @@ var require_contracts = __commonJS({
|
|
|
147019
147019
|
});
|
|
147020
147020
|
exports2.CODE_BINDING = /* @__PURE__ */ Symbol.for("@meistrari/workflow-code/code-binding");
|
|
147021
147021
|
exports2.BUILD_BINDING = /* @__PURE__ */ Symbol.for("@meistrari/workflow-code/build-binding");
|
|
147022
|
+
exports2.CONDITION_BINDING = /* @__PURE__ */ Symbol.for("@meistrari/workflow-code/condition-binding");
|
|
147022
147023
|
}
|
|
147023
147024
|
});
|
|
147024
147025
|
|
|
@@ -154670,6 +154671,7 @@ var require_ids = __commonJS({
|
|
|
154670
154671
|
exports2.defaultInputPortId = defaultInputPortId;
|
|
154671
154672
|
exports2.defaultOutputPortId = defaultOutputPortId;
|
|
154672
154673
|
exports2.subgraphOutputPortId = subgraphOutputPortId;
|
|
154674
|
+
exports2.branchOutputPortId = branchOutputPortId;
|
|
154673
154675
|
exports2.defaultEdgeId = defaultEdgeId;
|
|
154674
154676
|
exports2.slugId = slugId;
|
|
154675
154677
|
function stableInputId(workflowKey, input, index) {
|
|
@@ -154687,6 +154689,9 @@ var require_ids = __commonJS({
|
|
|
154687
154689
|
function subgraphOutputPortId(nodeId) {
|
|
154688
154690
|
return `${nodeId}:out:subgraph`;
|
|
154689
154691
|
}
|
|
154692
|
+
function branchOutputPortId(nodeId, branchIndex) {
|
|
154693
|
+
return `${nodeId}:out:branch:${branchIndex}`;
|
|
154694
|
+
}
|
|
154690
154695
|
function defaultEdgeId(sourcePortId, targetPortId) {
|
|
154691
154696
|
return `from_${sourcePortId}_to_${targetPortId}`.replace(/[^\w:-]+/g, "_");
|
|
154692
154697
|
}
|
|
@@ -154769,6 +154774,23 @@ var require_remote = __commonJS({
|
|
|
154769
154774
|
}
|
|
154770
154775
|
});
|
|
154771
154776
|
|
|
154777
|
+
// ../../packages/workflow-code/dist/authoring/condition-provenance.js
|
|
154778
|
+
var require_condition_provenance = __commonJS({
|
|
154779
|
+
"../../packages/workflow-code/dist/authoring/condition-provenance.js"(exports2) {
|
|
154780
|
+
"use strict";
|
|
154781
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
154782
|
+
exports2.trustConditionBinding = trustConditionBinding;
|
|
154783
|
+
exports2.isTrustedConditionBinding = isTrustedConditionBinding;
|
|
154784
|
+
var trustedConditionBindings = /* @__PURE__ */ new WeakMap();
|
|
154785
|
+
function trustConditionBinding(declaration, binding) {
|
|
154786
|
+
trustedConditionBindings.set(binding, declaration);
|
|
154787
|
+
}
|
|
154788
|
+
function isTrustedConditionBinding(declaration, binding) {
|
|
154789
|
+
return trustedConditionBindings.get(binding) === declaration;
|
|
154790
|
+
}
|
|
154791
|
+
}
|
|
154792
|
+
});
|
|
154793
|
+
|
|
154772
154794
|
// ../../packages/workflow-code/dist/vault/reference.js
|
|
154773
154795
|
var require_reference = __commonJS({
|
|
154774
154796
|
"../../packages/workflow-code/dist/vault/reference.js"(exports2) {
|
|
@@ -368614,6 +368636,7 @@ var require_imports = __commonJS({
|
|
|
368614
368636
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
368615
368637
|
exports2.collectPreservedImports = collectPreservedImports;
|
|
368616
368638
|
exports2.collectMissingPackageImportDiagnostics = collectMissingPackageImportDiagnostics;
|
|
368639
|
+
exports2.collectUnsupportedConditionImportDiagnostics = collectUnsupportedConditionImportDiagnostics;
|
|
368617
368640
|
exports2.mergeLibraries = mergeLibraries;
|
|
368618
368641
|
exports2.packageNameFromSpecifier = packageNameFromSpecifier;
|
|
368619
368642
|
var node_module_1 = require("node:module");
|
|
@@ -368660,6 +368683,20 @@ var require_imports = __commonJS({
|
|
|
368660
368683
|
}
|
|
368661
368684
|
return [...diagnosticsByBuiltin.values(), ...diagnosticsByPackage.values()];
|
|
368662
368685
|
}
|
|
368686
|
+
function collectUnsupportedConditionImportDiagnostics(closureNodes, resolutionContext) {
|
|
368687
|
+
const referenced = collectReferencedIdentifiersFromNodes(closureNodes);
|
|
368688
|
+
const sourceFiles = new Set(closureNodes.map(sourceFileForNode).filter((sourceFile) => Boolean(sourceFile)));
|
|
368689
|
+
const diagnosticsBySpecifier = /* @__PURE__ */ new Map();
|
|
368690
|
+
for (const { specifier } of collectReferencedExternalImports(sourceFiles, referenced, resolutionContext)) {
|
|
368691
|
+
diagnosticsBySpecifier.set(specifier, {
|
|
368692
|
+
code: "condition.source.unsupported_package_import",
|
|
368693
|
+
severity: "error",
|
|
368694
|
+
message: `Condition predicate imports package "${specifier}", but condition expressions cannot load runtime packages.`,
|
|
368695
|
+
hint: "Move the package-dependent logic into a prior code() node and reference its output from the condition predicate."
|
|
368696
|
+
});
|
|
368697
|
+
}
|
|
368698
|
+
return [...diagnosticsBySpecifier.values()];
|
|
368699
|
+
}
|
|
368663
368700
|
function collectReferencedExternalImports(sourceFiles, referenced, resolutionContext) {
|
|
368664
368701
|
const imports = [];
|
|
368665
368702
|
for (const sourceFile of sourceFiles) {
|
|
@@ -369187,7 +369224,7 @@ var require_rewrite_refs = __commonJS({
|
|
|
369187
369224
|
const targetInfo = targetResolution.target;
|
|
369188
369225
|
const targetKey = targetInfo?.effectiveKey ?? target.text;
|
|
369189
369226
|
if (!targetInfo) {
|
|
369190
|
-
diagnostics.push(targetResolution
|
|
369227
|
+
diagnostics.push(unresolvedTargetDiagnostic(targetResolution, targetKey, context.nodeName));
|
|
369191
369228
|
return void 0;
|
|
369192
369229
|
}
|
|
369193
369230
|
if (targetInfo.nodeIndex !== void 0 && targetInfo.nodeIndex >= context.currentNodeIndex) {
|
|
@@ -369200,6 +369237,15 @@ var require_rewrite_refs = __commonJS({
|
|
|
369200
369237
|
expression = safeAccess(expression, segment);
|
|
369201
369238
|
return expression;
|
|
369202
369239
|
}
|
|
369240
|
+
function unresolvedTargetDiagnostic(targetResolution, targetKey, nodeName) {
|
|
369241
|
+
if (targetResolution.unsupportedDynamicBuildArray)
|
|
369242
|
+
return unsupportedDynamicBuildArray(targetKey, nodeName);
|
|
369243
|
+
if (targetResolution.refFailure === "forward")
|
|
369244
|
+
return forwardReference(targetKey, nodeName);
|
|
369245
|
+
if (targetResolution.refFailure === "scope")
|
|
369246
|
+
return scopeReference(targetKey, nodeName);
|
|
369247
|
+
return unknownTarget(targetKey, nodeName);
|
|
369248
|
+
}
|
|
369203
369249
|
function extractPath(node, expectedTarget, context, diagnostics) {
|
|
369204
369250
|
const segments = [];
|
|
369205
369251
|
let current = node;
|
|
@@ -369270,6 +369316,13 @@ var require_rewrite_refs = __commonJS({
|
|
|
369270
369316
|
hint: `Move "${targetKey}" before "${nodeName}" or remove the reference.`
|
|
369271
369317
|
};
|
|
369272
369318
|
}
|
|
369319
|
+
function scopeReference(targetKey, nodeName) {
|
|
369320
|
+
return {
|
|
369321
|
+
code: "code.ref.scope_reference",
|
|
369322
|
+
severity: "error",
|
|
369323
|
+
message: `Code node "${nodeName}" references "${targetKey}", but that node is outside the visible scope.`
|
|
369324
|
+
};
|
|
369325
|
+
}
|
|
369273
369326
|
function unsupportedStandalonePaths(nodeName) {
|
|
369274
369327
|
return {
|
|
369275
369328
|
code: "code.ref.unsupported_paths",
|
|
@@ -369283,6 +369336,149 @@ var require_rewrite_refs = __commonJS({
|
|
|
369283
369336
|
}
|
|
369284
369337
|
});
|
|
369285
369338
|
|
|
369339
|
+
// ../../packages/workflow-code/dist/compiler/refs.js
|
|
369340
|
+
var require_refs = __commonJS({
|
|
369341
|
+
"../../packages/workflow-code/dist/compiler/refs.js"(exports2) {
|
|
369342
|
+
"use strict";
|
|
369343
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
369344
|
+
exports2.resolvePromptRefs = resolvePromptRefs;
|
|
369345
|
+
exports2.resolveReferenceRecordRefs = resolveReferenceRecordRefs;
|
|
369346
|
+
exports2.resolveWorkflowRef = resolveWorkflowRef;
|
|
369347
|
+
exports2.resolveExclusiveRef = resolveExclusiveRef;
|
|
369348
|
+
exports2.resolveVisibleNodeIdentity = resolveVisibleNodeIdentity;
|
|
369349
|
+
var workflow_shared_1 = require_cjs2();
|
|
369350
|
+
function resolvePromptRefs(context) {
|
|
369351
|
+
const diagnostics = [];
|
|
369352
|
+
let prompt = context.prompt;
|
|
369353
|
+
for (const ref of context.refs) {
|
|
369354
|
+
const resolved = resolveWorkflowRef(ref, context);
|
|
369355
|
+
diagnostics.push(...resolved.diagnostics);
|
|
369356
|
+
if (!resolved.reference)
|
|
369357
|
+
continue;
|
|
369358
|
+
prompt = prompt.split(ref.token).join(resolved.reference);
|
|
369359
|
+
}
|
|
369360
|
+
return { prompt, diagnostics };
|
|
369361
|
+
}
|
|
369362
|
+
function resolveReferenceRecordRefs(context) {
|
|
369363
|
+
const diagnostics = [];
|
|
369364
|
+
const values = { ...context.values };
|
|
369365
|
+
for (const ref of context.refs) {
|
|
369366
|
+
const resolved = resolveWorkflowRef(ref, context);
|
|
369367
|
+
if (resolved.reference) {
|
|
369368
|
+
values[ref.key] = resolved.reference;
|
|
369369
|
+
continue;
|
|
369370
|
+
}
|
|
369371
|
+
diagnostics.push(...resolved.diagnostics.map((diagnostic) => ({
|
|
369372
|
+
...diagnostic,
|
|
369373
|
+
message: diagnostic.message.replace("Prompt reference", `Reference record ${ref.key} reference`)
|
|
369374
|
+
})));
|
|
369375
|
+
}
|
|
369376
|
+
return { values: Object.freeze(values), diagnostics };
|
|
369377
|
+
}
|
|
369378
|
+
function resolveWorkflowRef(ref, context) {
|
|
369379
|
+
const resolved = ref.targetKind === "input" ? resolveInputRef(ref, context) : resolveNodeRef(ref, context);
|
|
369380
|
+
if (!resolved) {
|
|
369381
|
+
return {
|
|
369382
|
+
diagnostics: [{
|
|
369383
|
+
code: "compiler.ref.dangling",
|
|
369384
|
+
severity: "error",
|
|
369385
|
+
message: `Prompt reference ${ref.targetKey} does not match a workflow input or previous node`
|
|
369386
|
+
}]
|
|
369387
|
+
};
|
|
369388
|
+
}
|
|
369389
|
+
if (resolved === "forward") {
|
|
369390
|
+
return {
|
|
369391
|
+
diagnostics: [{
|
|
369392
|
+
code: "compiler.ref.forward",
|
|
369393
|
+
severity: "error",
|
|
369394
|
+
message: `Prompt reference ${ref.targetKey} points to a future workflow node`
|
|
369395
|
+
}]
|
|
369396
|
+
};
|
|
369397
|
+
}
|
|
369398
|
+
if (resolved === "scope") {
|
|
369399
|
+
return {
|
|
369400
|
+
diagnostics: [{
|
|
369401
|
+
code: "compiler.ref.scope",
|
|
369402
|
+
severity: "error",
|
|
369403
|
+
message: `Prompt reference ${ref.targetKey} points to a workflow node outside the visible scope`
|
|
369404
|
+
}]
|
|
369405
|
+
};
|
|
369406
|
+
}
|
|
369407
|
+
return {
|
|
369408
|
+
reference: resolved.reference,
|
|
369409
|
+
inputType: "inputType" in resolved ? resolved.inputType : void 0,
|
|
369410
|
+
nodeId: "nodeId" in resolved ? resolved.nodeId : void 0,
|
|
369411
|
+
diagnostics: []
|
|
369412
|
+
};
|
|
369413
|
+
}
|
|
369414
|
+
function resolveExclusiveRef(ref, context) {
|
|
369415
|
+
const resolved = resolveWorkflowRef(ref, context);
|
|
369416
|
+
if (resolved.reference)
|
|
369417
|
+
return resolved;
|
|
369418
|
+
return {
|
|
369419
|
+
diagnostics: resolved.diagnostics.map((diagnostic) => ({
|
|
369420
|
+
...diagnostic,
|
|
369421
|
+
message: diagnostic.message.replace("Prompt reference", "Exclusive reference")
|
|
369422
|
+
}))
|
|
369423
|
+
};
|
|
369424
|
+
}
|
|
369425
|
+
function resolveInputRef(ref, context) {
|
|
369426
|
+
const id = context.inputIdsByKey.get(ref.targetKey);
|
|
369427
|
+
if (!id)
|
|
369428
|
+
return void 0;
|
|
369429
|
+
const reference = workflow_shared_1.InputReferenceURI.fromVariable({ name: id });
|
|
369430
|
+
return {
|
|
369431
|
+
reference: formatPromptReference(reference, ref),
|
|
369432
|
+
inputType: context.inputTypesByKey?.get(ref.targetKey)
|
|
369433
|
+
};
|
|
369434
|
+
}
|
|
369435
|
+
function resolveNodeRef(ref, context) {
|
|
369436
|
+
const candidates = context.nodeIdentitiesByKey.get(ref.targetKey) ?? [];
|
|
369437
|
+
if (candidates.length === 0)
|
|
369438
|
+
return void 0;
|
|
369439
|
+
const visible = resolveVisibleNodeIdentity(ref.targetKey, context);
|
|
369440
|
+
if (visible) {
|
|
369441
|
+
const reference = workflow_shared_1.ActionOutputReferenceURI.fromStepId(visible.id);
|
|
369442
|
+
return { reference: formatPromptReference(reference, ref), nodeId: visible.id };
|
|
369443
|
+
}
|
|
369444
|
+
if (candidates.some((candidate) => samePath(candidate.scopePath, context.currentNode.scopePath) && candidate.sequenceIndex >= context.currentNode.sequenceIndex)) {
|
|
369445
|
+
return "forward";
|
|
369446
|
+
}
|
|
369447
|
+
return "scope";
|
|
369448
|
+
}
|
|
369449
|
+
function resolveVisibleNodeIdentity(key, context) {
|
|
369450
|
+
const currentScopeCandidate = resolvePriorCandidateInScope(key, context.currentNode.scopePath, context.currentNode.sequenceIndex, context);
|
|
369451
|
+
if (currentScopeCandidate)
|
|
369452
|
+
return currentScopeCandidate;
|
|
369453
|
+
for (const boundary of [...context.currentNode.ancestorScopes].reverse()) {
|
|
369454
|
+
const candidate = resolvePriorCandidateInScope(key, boundary.scopePath, boundary.sequenceIndex, context);
|
|
369455
|
+
if (candidate)
|
|
369456
|
+
return candidate;
|
|
369457
|
+
}
|
|
369458
|
+
return void 0;
|
|
369459
|
+
}
|
|
369460
|
+
function resolvePriorCandidateInScope(key, scopePath, beforeSequenceIndex, context) {
|
|
369461
|
+
const candidates = (context.nodeIdentitiesByKey.get(key) ?? []).filter((candidate) => samePath(candidate.scopePath, scopePath) && candidate.sequenceIndex < beforeSequenceIndex).sort((left, right) => right.sequenceIndex - left.sequenceIndex);
|
|
369462
|
+
const nearest = candidates[0];
|
|
369463
|
+
if (!nearest)
|
|
369464
|
+
return void 0;
|
|
369465
|
+
if (candidates.filter((candidate) => candidate.sequenceIndex === nearest.sequenceIndex).length > 1)
|
|
369466
|
+
return void 0;
|
|
369467
|
+
return nearest;
|
|
369468
|
+
}
|
|
369469
|
+
function samePath(left, right) {
|
|
369470
|
+
return left.length === right.length && left.every((segment, index) => segment === right[index]);
|
|
369471
|
+
}
|
|
369472
|
+
function formatPromptReference(reference, ref) {
|
|
369473
|
+
if (ref.path && ref.path.length > 0)
|
|
369474
|
+
reference.appendPath([...ref.path]);
|
|
369475
|
+
if ("format" in ref && ref.format)
|
|
369476
|
+
reference.setFormat(ref.format);
|
|
369477
|
+
return reference.toReference();
|
|
369478
|
+
}
|
|
369479
|
+
}
|
|
369480
|
+
});
|
|
369481
|
+
|
|
369286
369482
|
// ../../packages/workflow-code/dist/compiler/code-extraction/extract.js
|
|
369287
369483
|
var require_extract3 = __commonJS({
|
|
369288
369484
|
"../../packages/workflow-code/dist/compiler/code-extraction/extract.js"(exports2) {
|
|
@@ -369292,6 +369488,7 @@ var require_extract3 = __commonJS({
|
|
|
369292
369488
|
};
|
|
369293
369489
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
369294
369490
|
exports2.extractInlineCode = extractInlineCode;
|
|
369491
|
+
exports2.extractConditionExpression = extractConditionExpression;
|
|
369295
369492
|
exports2.resolveBuiltRefTargetResult = resolveBuiltRefTargetResult;
|
|
369296
369493
|
exports2.resolveIdentifierDeclarationWithChecker = resolveIdentifierDeclarationWithChecker;
|
|
369297
369494
|
var typescript_1 = __importDefault(require_typescript3());
|
|
@@ -369301,7 +369498,10 @@ var require_extract3 = __commonJS({
|
|
|
369301
369498
|
var program_1 = require_program();
|
|
369302
369499
|
var rewrite_refs_1 = require_rewrite_refs();
|
|
369303
369500
|
var output_schema_2 = require_output_schema();
|
|
369501
|
+
var refs_1 = require_refs();
|
|
369502
|
+
var condition_provenance_1 = require_condition_provenance();
|
|
369304
369503
|
var RESERVED_RUNTIME_DECLARATION_NAMES = /* @__PURE__ */ new Set(["execute", "TelaInput"]);
|
|
369504
|
+
var READ_ONLY_OBJECT_INSPECTION_METHODS = /* @__PURE__ */ new Set(["keys", "hasOwn", "isFrozen", "isSealed", "isExtensible"]);
|
|
369305
369505
|
function extractInlineCode(input) {
|
|
369306
369506
|
const binding = input.node[contracts_1.CODE_BINDING];
|
|
369307
369507
|
if (!binding) {
|
|
@@ -369367,7 +369567,9 @@ var require_extract3 = __commonJS({
|
|
|
369367
369567
|
nodeName: input.node.name,
|
|
369368
369568
|
inputNamesByKey: input.inputNamesByKey,
|
|
369369
369569
|
nodeNamesByKey: input.nodeNamesByKey,
|
|
369370
|
-
nodeIndexesByKey: input.nodeIndexesByKey
|
|
369570
|
+
nodeIndexesByKey: input.nodeIndexesByKey,
|
|
369571
|
+
nodeIdentitiesByKey: input.nodeIdentitiesByKey,
|
|
369572
|
+
currentNode: input.currentNode
|
|
369371
369573
|
});
|
|
369372
369574
|
if (rewritten.diagnostics.length > 0)
|
|
369373
369575
|
return { code: "", diagnostics: rewritten.diagnostics, preservedImports };
|
|
@@ -369380,6 +369582,92 @@ var require_extract3 = __commonJS({
|
|
|
369380
369582
|
preservedImports
|
|
369381
369583
|
};
|
|
369382
369584
|
}
|
|
369585
|
+
function extractConditionExpression(input) {
|
|
369586
|
+
const binding = input.node[contracts_1.CONDITION_BINDING];
|
|
369587
|
+
if (!isConditionBindingObject(binding))
|
|
369588
|
+
return { diagnostics: [diagnostic("condition.source.missing_handler_binding", "Condition node is missing predicate binding")] };
|
|
369589
|
+
if (!(0, condition_provenance_1.isTrustedConditionBinding)(input.node, binding))
|
|
369590
|
+
return { diagnostics: [diagnostic("condition.source.untrusted_binding", "Condition node predicate binding was not produced by Workflow Code authoring evaluation")] };
|
|
369591
|
+
if (!hasOwnFunctionProperty(binding.handlers, input.caseName))
|
|
369592
|
+
return { diagnostics: [diagnostic("condition.source.missing_handler_binding", `Condition case "${input.caseName}" is missing predicate handler binding`)] };
|
|
369593
|
+
if (!binding.source)
|
|
369594
|
+
return { diagnostics: [diagnostic("condition.source.missing_handler", "Condition node is missing source marker")] };
|
|
369595
|
+
const file2 = input.source.files.find((snapshot) => snapshot.path === binding.source?.file);
|
|
369596
|
+
if (!file2)
|
|
369597
|
+
return { diagnostics: [diagnostic("condition.source.missing_handler", "Condition predicate source file was not included in source bundle")] };
|
|
369598
|
+
const sourceProgram = (0, program_1.createSourceProgram)(input.source);
|
|
369599
|
+
const sourceFile = sourceProgram.sourceFilesByPath.get(file2.path) ?? typescript_1.default.createSourceFile(file2.path, file2.content, typescript_1.default.ScriptTarget.ES2022, true, typescript_1.default.ScriptKind.TS);
|
|
369600
|
+
const call = findCodeCall(sourceFile, binding.source.pos, binding.source.end);
|
|
369601
|
+
const predicate = call ? getConditionPredicateExpression(call, input.caseName, sourceProgram.checker, collectStaticDependencySourceFiles(sourceFile, call, input.source.entrypoint, sourceProgram.checker, sourceProgram.sourceFilesByPath)) : void 0;
|
|
369602
|
+
if (!predicate)
|
|
369603
|
+
return { diagnostics: [diagnostic("condition.source.missing_handler", `Condition predicate for case "${input.caseName}" could not be located`)] };
|
|
369604
|
+
if (!isConditionFunction(predicate))
|
|
369605
|
+
return { diagnostics: [diagnostic("condition.source.unsupported_predicate", "Condition predicates must be inline function expressions")] };
|
|
369606
|
+
if (predicate.modifiers?.some((modifier) => modifier.kind === typescript_1.default.SyntaxKind.AsyncKeyword) || "asteriskToken" in predicate && predicate.asteriskToken)
|
|
369607
|
+
return { diagnostics: [diagnostic("condition.source.unsupported_predicate", "Condition predicates must be synchronous non-generator functions")] };
|
|
369608
|
+
if (containsAwait(predicate.body))
|
|
369609
|
+
return { diagnostics: [diagnostic("condition.source.unsupported_predicate", "Condition predicates cannot use await")] };
|
|
369610
|
+
if (!hasPredicateReturn(predicate))
|
|
369611
|
+
return { diagnostics: [diagnostic("condition.source.unsupported_predicate", "Condition predicates must return a boolean")] };
|
|
369612
|
+
const signature = sourceProgram.checker.getSignatureFromDeclaration(predicate);
|
|
369613
|
+
const returnType = signature ? sourceProgram.checker.getReturnTypeOfSignature(signature) : void 0;
|
|
369614
|
+
if (!returnType || isAnyOrUnknown(returnType) || !isBooleanLike(returnType, sourceProgram.checker) || isPromiseLike(returnType, sourceProgram.checker))
|
|
369615
|
+
return { diagnostics: [diagnostic("condition.source.unsupported_predicate", "Condition predicates must return boolean")] };
|
|
369616
|
+
const generatedHandlerName = createGeneratedConditionHandlerName(sourceFile);
|
|
369617
|
+
const helperBindings = collectCodeContextHelperBindings(predicate, generatedHandlerName, sourceProgram.checker);
|
|
369618
|
+
const closure = collectHelperClosure(predicate, generatedHandlerName, "Condition", sourceProgram.checker, helperBindings);
|
|
369619
|
+
const closureNodes = [...closure.declarations, predicate];
|
|
369620
|
+
const closureDiagnostics = [
|
|
369621
|
+
...closure.diagnostics,
|
|
369622
|
+
...detectUnsupportedPatterns(closureNodes),
|
|
369623
|
+
...detectUnsupportedContextHelperPropagation(closureNodes, sourceProgram.checker, helperBindings),
|
|
369624
|
+
...(0, imports_1.collectUnsupportedConditionImportDiagnostics)(closureNodes, {
|
|
369625
|
+
program: sourceProgram.program,
|
|
369626
|
+
sourceFilePaths: new Set(sourceProgram.sourceFilesByPath.keys())
|
|
369627
|
+
})
|
|
369628
|
+
];
|
|
369629
|
+
if (closureDiagnostics.length > 0)
|
|
369630
|
+
return { diagnostics: closureDiagnostics };
|
|
369631
|
+
const runtimeSource = createRuntimeSourceFile(sourceFile, [...closure.declarations, createInlineHandlerStatement(generatedHandlerName, predicate)], void 0);
|
|
369632
|
+
const buildSourceFile = input.buildSource ? sourceProgram.sourceFilesByPath.get(input.buildSource.file) : void 0;
|
|
369633
|
+
const rewritten = (0, rewrite_refs_1.rewriteCodeRefs)(runtimeSource, {
|
|
369634
|
+
checker: sourceProgram.checker,
|
|
369635
|
+
helperBindings,
|
|
369636
|
+
builtInputs: input.builtInputs,
|
|
369637
|
+
builtNodes: input.builtNodes,
|
|
369638
|
+
buildSource: input.buildSource,
|
|
369639
|
+
buildSourceFile,
|
|
369640
|
+
currentNodeIndex: input.currentNodeIndex,
|
|
369641
|
+
nodeName: "Condition",
|
|
369642
|
+
inputNamesByKey: input.inputNamesByKey,
|
|
369643
|
+
nodeNamesByKey: input.nodeNamesByKey,
|
|
369644
|
+
nodeIndexesByKey: input.nodeIndexesByKey,
|
|
369645
|
+
nodeIdentitiesByKey: input.nodeIdentitiesByKey,
|
|
369646
|
+
currentNode: input.currentNode
|
|
369647
|
+
});
|
|
369648
|
+
if (rewritten.diagnostics.length > 0)
|
|
369649
|
+
return { diagnostics: rewritten.diagnostics };
|
|
369650
|
+
const rewrittenPredicate = getVariableFunction(rewritten.sourceFile, generatedHandlerName);
|
|
369651
|
+
if (!rewrittenPredicate)
|
|
369652
|
+
return { diagnostics: [diagnostic("condition.source.missing_handler", `Condition predicate for case "${input.caseName}" could not be printed`)] };
|
|
369653
|
+
return {
|
|
369654
|
+
expression: printConditionExpressionWithClosure(rewrittenPredicate, rewritten.sourceFile, generatedHandlerName),
|
|
369655
|
+
diagnostics: []
|
|
369656
|
+
};
|
|
369657
|
+
}
|
|
369658
|
+
function isConditionBindingObject(value) {
|
|
369659
|
+
if (!value || typeof value !== "object")
|
|
369660
|
+
return false;
|
|
369661
|
+
const handlers = value.handlers;
|
|
369662
|
+
const source = value.source;
|
|
369663
|
+
return Boolean(handlers) && typeof handlers === "object" && !Array.isArray(handlers) && (source === void 0 || isWorkflowCodeSourceMarker(source));
|
|
369664
|
+
}
|
|
369665
|
+
function isWorkflowCodeSourceMarker(value) {
|
|
369666
|
+
return Boolean(value) && typeof value === "object" && typeof value.file === "string" && typeof value.pos === "number" && Number.isInteger(value.pos) && value.pos >= 0 && typeof value.end === "number" && Number.isInteger(value.end) && value.end >= value.pos;
|
|
369667
|
+
}
|
|
369668
|
+
function hasOwnFunctionProperty(value, property) {
|
|
369669
|
+
return Object.prototype.hasOwnProperty.call(value, property) && typeof value[property] === "function";
|
|
369670
|
+
}
|
|
369383
369671
|
function createCodeInputSchemaBindings(input) {
|
|
369384
369672
|
const inputBindings = input.builtInputs.map((declaration) => ({
|
|
369385
369673
|
name: declaration.name,
|
|
@@ -369393,6 +369681,656 @@ var require_extract3 = __commonJS({
|
|
|
369393
369681
|
});
|
|
369394
369682
|
return [...inputBindings, ...nodeBindings];
|
|
369395
369683
|
}
|
|
369684
|
+
function getConditionPredicateExpression(call, caseName, checker, sourceFiles) {
|
|
369685
|
+
const firstArg = call.arguments[0];
|
|
369686
|
+
if (!firstArg || !typescript_1.default.isObjectLiteralExpression(firstArg))
|
|
369687
|
+
return void 0;
|
|
369688
|
+
const casesExpression = getStaticObjectPropertyValue(firstArg, "cases", checker, /* @__PURE__ */ new Set(), call, sourceFiles);
|
|
369689
|
+
const casesObject = casesExpression ? resolveStaticObjectLiteral(casesExpression, checker, /* @__PURE__ */ new Set(), call, sourceFiles) : void 0;
|
|
369690
|
+
if (!casesObject)
|
|
369691
|
+
return void 0;
|
|
369692
|
+
const caseExpression = getStaticObjectPropertyValue(casesObject, caseName, checker, /* @__PURE__ */ new Set(), call, sourceFiles);
|
|
369693
|
+
const caseObject = caseExpression ? resolveStaticObjectLiteral(caseExpression, checker, /* @__PURE__ */ new Set(), call, sourceFiles) : void 0;
|
|
369694
|
+
if (!caseObject)
|
|
369695
|
+
return void 0;
|
|
369696
|
+
return getStaticObjectPropertyValue(caseObject, "when", checker, /* @__PURE__ */ new Set(), call, sourceFiles);
|
|
369697
|
+
}
|
|
369698
|
+
function getStaticObjectPropertyValue(objectLiteral, propertyName, checker, seen = /* @__PURE__ */ new Set(), sourceNode, sourceFiles = []) {
|
|
369699
|
+
let value;
|
|
369700
|
+
for (const property of objectLiteral.properties) {
|
|
369701
|
+
if (typescript_1.default.isSpreadAssignment(property)) {
|
|
369702
|
+
const spreadSeen = new Set(seen);
|
|
369703
|
+
const spreadObject = resolveStaticObjectLiteral(property.expression, checker, spreadSeen, sourceNode, sourceFiles);
|
|
369704
|
+
if (!spreadObject)
|
|
369705
|
+
return void 0;
|
|
369706
|
+
const spreadValue = getStaticObjectPropertyValue(spreadObject, propertyName, checker, spreadSeen, sourceNode, sourceFiles);
|
|
369707
|
+
if (spreadValue)
|
|
369708
|
+
value = spreadValue;
|
|
369709
|
+
continue;
|
|
369710
|
+
}
|
|
369711
|
+
if (getStaticPropertyNameText(property.name, checker) !== propertyName)
|
|
369712
|
+
continue;
|
|
369713
|
+
if (typescript_1.default.isPropertyAssignment(property))
|
|
369714
|
+
value = property.initializer;
|
|
369715
|
+
else if (typescript_1.default.isShorthandPropertyAssignment(property))
|
|
369716
|
+
value = property.name;
|
|
369717
|
+
else
|
|
369718
|
+
return void 0;
|
|
369719
|
+
}
|
|
369720
|
+
return value;
|
|
369721
|
+
}
|
|
369722
|
+
function resolveStaticObjectLiteral(expression, checker, seen = /* @__PURE__ */ new Set(), sourceNode, sourceFiles = []) {
|
|
369723
|
+
const unwrapped = unwrapStaticExpression(expression);
|
|
369724
|
+
if (typescript_1.default.isObjectLiteralExpression(unwrapped))
|
|
369725
|
+
return unwrapped;
|
|
369726
|
+
if (!typescript_1.default.isIdentifier(unwrapped))
|
|
369727
|
+
return void 0;
|
|
369728
|
+
const declaration = resolveIdentifierDeclarationWithChecker(unwrapped, checker);
|
|
369729
|
+
const initializer3 = declaration && typescript_1.default.isVariableDeclaration(declaration) && declaration.initializer ? unwrapStaticExpression(declaration.initializer) : void 0;
|
|
369730
|
+
if (!declaration || seen.has(declaration) || !typescript_1.default.isVariableDeclaration(declaration) || !isConstVariableDeclaration(declaration) || !initializer3 || !typescript_1.default.isObjectLiteralExpression(initializer3) && !typescript_1.default.isIdentifier(initializer3) || sourceNode !== void 0 && hasPotentialObjectMutationBefore(declaration, checker, sourceNode, sourceFiles)) {
|
|
369731
|
+
return void 0;
|
|
369732
|
+
}
|
|
369733
|
+
seen.add(declaration);
|
|
369734
|
+
return resolveStaticObjectLiteral(initializer3, checker, seen, sourceNode, sourceFiles);
|
|
369735
|
+
}
|
|
369736
|
+
function collectStaticDependencySourceFiles(sourceFile, sourceNode, entrypoint, checker, sourceFilesByPath) {
|
|
369737
|
+
const dependencies = /* @__PURE__ */ new Map();
|
|
369738
|
+
const entrypointSourceFile = sourceFilesByPath.get(entrypoint);
|
|
369739
|
+
const visited = /* @__PURE__ */ new Set();
|
|
369740
|
+
const addDependency = (dependency, end) => {
|
|
369741
|
+
const existing = dependencies.get(dependency.fileName);
|
|
369742
|
+
if (!existing || existing.end < end)
|
|
369743
|
+
dependencies.set(dependency.fileName, { sourceFile: dependency, end });
|
|
369744
|
+
};
|
|
369745
|
+
const collectBeforeSourceNode = (current) => {
|
|
369746
|
+
if (visited.has(current.fileName))
|
|
369747
|
+
return false;
|
|
369748
|
+
visited.add(current.fileName);
|
|
369749
|
+
for (const statement of current.statements) {
|
|
369750
|
+
if (current === sourceFile && statementContainsNode(statement, sourceNode)) {
|
|
369751
|
+
addDependency(current, sourceNode.getStart(current));
|
|
369752
|
+
return true;
|
|
369753
|
+
}
|
|
369754
|
+
const dependency = localModuleSourceFile(statement, checker, sourceFilesByPath);
|
|
369755
|
+
if (!dependency)
|
|
369756
|
+
continue;
|
|
369757
|
+
if (collectBeforeSourceNode(dependency)) {
|
|
369758
|
+
addDependency(current, statement.getFullStart());
|
|
369759
|
+
return true;
|
|
369760
|
+
}
|
|
369761
|
+
}
|
|
369762
|
+
addDependency(current, Number.POSITIVE_INFINITY);
|
|
369763
|
+
return false;
|
|
369764
|
+
};
|
|
369765
|
+
if (entrypointSourceFile)
|
|
369766
|
+
collectBeforeSourceNode(entrypointSourceFile);
|
|
369767
|
+
return [...dependencies.values()];
|
|
369768
|
+
}
|
|
369769
|
+
function statementContainsNode(statement, node) {
|
|
369770
|
+
return statement.getFullStart() <= node.pos && node.end <= statement.end;
|
|
369771
|
+
}
|
|
369772
|
+
function localModuleSourceFile(statement, checker, sourceFilesByPath) {
|
|
369773
|
+
if (!typescript_1.default.isImportDeclaration(statement) && !typescript_1.default.isExportDeclaration(statement) || !isRuntimeModuleReference(statement) || !statement.moduleSpecifier || !typescript_1.default.isStringLiteral(statement.moduleSpecifier)) {
|
|
369774
|
+
return void 0;
|
|
369775
|
+
}
|
|
369776
|
+
return (checker.getSymbolAtLocation(statement.moduleSpecifier)?.declarations ?? []).map((declaration) => sourceFilesByPath.get(declaration.getSourceFile().fileName)).find((sourceFile) => Boolean(sourceFile));
|
|
369777
|
+
}
|
|
369778
|
+
function isRuntimeModuleReference(statement) {
|
|
369779
|
+
if (typescript_1.default.isImportDeclaration(statement)) {
|
|
369780
|
+
const importClause = statement.importClause;
|
|
369781
|
+
if (!importClause)
|
|
369782
|
+
return true;
|
|
369783
|
+
if (importClause.isTypeOnly)
|
|
369784
|
+
return false;
|
|
369785
|
+
if (importClause.name || !importClause.namedBindings || typescript_1.default.isNamespaceImport(importClause.namedBindings))
|
|
369786
|
+
return true;
|
|
369787
|
+
return importClause.namedBindings.elements.length === 0 || importClause.namedBindings.elements.some((element) => !element.isTypeOnly);
|
|
369788
|
+
}
|
|
369789
|
+
if (statement.isTypeOnly || !statement.exportClause || typescript_1.default.isNamespaceExport(statement.exportClause))
|
|
369790
|
+
return !statement.isTypeOnly;
|
|
369791
|
+
return statement.exportClause.elements.length === 0 || statement.exportClause.elements.some((element) => !element.isTypeOnly);
|
|
369792
|
+
}
|
|
369793
|
+
function hasPotentialObjectMutationBefore(declaration, checker, sourceNode, sourceFiles = []) {
|
|
369794
|
+
if (!typescript_1.default.isIdentifier(declaration.name))
|
|
369795
|
+
return true;
|
|
369796
|
+
const declarationSourceFile = declaration.getSourceFile();
|
|
369797
|
+
const candidateSourceFiles = /* @__PURE__ */ new Map();
|
|
369798
|
+
const addCandidate = (candidate) => {
|
|
369799
|
+
const existing = candidateSourceFiles.get(candidate.sourceFile.fileName);
|
|
369800
|
+
if (!existing || existing.end < candidate.end)
|
|
369801
|
+
candidateSourceFiles.set(candidate.sourceFile.fileName, candidate);
|
|
369802
|
+
};
|
|
369803
|
+
addCandidate({
|
|
369804
|
+
sourceFile: declarationSourceFile,
|
|
369805
|
+
end: sourceNode?.getSourceFile() === declarationSourceFile && !isNestedInDeferredFunction(sourceNode) ? sourceNode.getStart(declarationSourceFile) : Number.POSITIVE_INFINITY
|
|
369806
|
+
});
|
|
369807
|
+
for (const sourceFile of sourceFiles)
|
|
369808
|
+
addCandidate(sourceFile);
|
|
369809
|
+
const ignoredCall = sourceNode && typescript_1.default.isCallExpression(sourceNode) ? sourceNode : void 0;
|
|
369810
|
+
return [...candidateSourceFiles.values()].some(({ sourceFile, end }) => {
|
|
369811
|
+
let foundMutation = false;
|
|
369812
|
+
const visit = (node, inDeferredFunction = false, inSourceCall = false) => {
|
|
369813
|
+
const isDeferredFunction = inDeferredFunction || typescript_1.default.isFunctionLike(node);
|
|
369814
|
+
const isSourceCall = inSourceCall || node === sourceNode;
|
|
369815
|
+
if (foundMutation || !isSourceCall && !isDeferredFunction && node.getStart(sourceFile) >= end)
|
|
369816
|
+
return;
|
|
369817
|
+
if (typescript_1.default.isIdentifier(node) && node !== declaration.name && isStaticObjectAliasReference(node, declaration, checker) && isPotentialObjectMutationReference(node, checker, ignoredCall)) {
|
|
369818
|
+
foundMutation = true;
|
|
369819
|
+
return;
|
|
369820
|
+
}
|
|
369821
|
+
typescript_1.default.forEachChild(node, (child) => visit(child, isDeferredFunction, isSourceCall));
|
|
369822
|
+
};
|
|
369823
|
+
visit(sourceFile);
|
|
369824
|
+
return foundMutation;
|
|
369825
|
+
});
|
|
369826
|
+
}
|
|
369827
|
+
function isNestedInDeferredFunction(node) {
|
|
369828
|
+
for (let current = node.parent; current && !typescript_1.default.isSourceFile(current); current = current.parent) {
|
|
369829
|
+
if (typescript_1.default.isFunctionLike(current))
|
|
369830
|
+
return true;
|
|
369831
|
+
}
|
|
369832
|
+
return false;
|
|
369833
|
+
}
|
|
369834
|
+
function isStaticObjectAliasReference(identifier, declaration, checker, seen = /* @__PURE__ */ new Set()) {
|
|
369835
|
+
const resolved = resolveStaticObjectAliasDeclaration(identifier, checker);
|
|
369836
|
+
if (resolved === declaration)
|
|
369837
|
+
return true;
|
|
369838
|
+
if (!resolved || seen.has(resolved)) {
|
|
369839
|
+
return false;
|
|
369840
|
+
}
|
|
369841
|
+
seen.add(resolved);
|
|
369842
|
+
if (typescript_1.default.isBindingElement(resolved)) {
|
|
369843
|
+
return isStaticObjectBindingAliasReference(resolved, declaration, checker, seen);
|
|
369844
|
+
}
|
|
369845
|
+
if (!typescript_1.default.isVariableDeclaration(resolved) || !resolved.initializer) {
|
|
369846
|
+
return false;
|
|
369847
|
+
}
|
|
369848
|
+
const initializer3 = unwrapStaticExpression(resolved.initializer);
|
|
369849
|
+
if (typescript_1.default.isObjectLiteralExpression(initializer3)) {
|
|
369850
|
+
return initializer3.properties.some((property) => {
|
|
369851
|
+
if (typescript_1.default.isPropertyAssignment(property))
|
|
369852
|
+
return isStaticObjectAliasExpression(property.initializer, declaration, checker, seen);
|
|
369853
|
+
if (typescript_1.default.isShorthandPropertyAssignment(property) && typescript_1.default.isIdentifier(property.name))
|
|
369854
|
+
return isStaticObjectAliasExpression(property.name, declaration, checker, seen);
|
|
369855
|
+
return typescript_1.default.isSpreadAssignment(property) && isStaticObjectAliasExpression(property.expression, declaration, checker, seen);
|
|
369856
|
+
});
|
|
369857
|
+
}
|
|
369858
|
+
return isStaticObjectAliasExpression(initializer3, declaration, checker, seen);
|
|
369859
|
+
}
|
|
369860
|
+
function resolveStaticObjectAliasDeclaration(identifier, checker) {
|
|
369861
|
+
return resolvedIdentifierDeclarations(identifier, checker).find((declaration) => typescript_1.default.isVariableDeclaration(declaration) || typescript_1.default.isBindingElement(declaration));
|
|
369862
|
+
}
|
|
369863
|
+
function variableDeclarationForBindingElement(bindingElement) {
|
|
369864
|
+
let bindingPattern = bindingElement.parent;
|
|
369865
|
+
if (!typescript_1.default.isObjectBindingPattern(bindingPattern))
|
|
369866
|
+
return void 0;
|
|
369867
|
+
while (typescript_1.default.isBindingElement(bindingPattern.parent)) {
|
|
369868
|
+
const parentBindingPattern = bindingPattern.parent.parent;
|
|
369869
|
+
if (!typescript_1.default.isObjectBindingPattern(parentBindingPattern))
|
|
369870
|
+
return void 0;
|
|
369871
|
+
bindingPattern = parentBindingPattern;
|
|
369872
|
+
}
|
|
369873
|
+
return typescript_1.default.isVariableDeclaration(bindingPattern.parent) ? bindingPattern.parent : void 0;
|
|
369874
|
+
}
|
|
369875
|
+
function bindingElementPropertyPath(bindingElement, checker) {
|
|
369876
|
+
const propertyNames = [];
|
|
369877
|
+
let includesRest = false;
|
|
369878
|
+
for (let current = bindingElement; current; ) {
|
|
369879
|
+
if (current.dotDotDotToken) {
|
|
369880
|
+
includesRest = true;
|
|
369881
|
+
} else {
|
|
369882
|
+
const propertyName = current.propertyName ? getStaticPropertyNameText(current.propertyName, checker) : typescript_1.default.isIdentifier(current.name) ? current.name.text : void 0;
|
|
369883
|
+
if (propertyName === void 0)
|
|
369884
|
+
return void 0;
|
|
369885
|
+
propertyNames.unshift(propertyName);
|
|
369886
|
+
}
|
|
369887
|
+
const bindingPattern = current.parent;
|
|
369888
|
+
if (!typescript_1.default.isObjectBindingPattern(bindingPattern) || !typescript_1.default.isBindingElement(bindingPattern.parent))
|
|
369889
|
+
break;
|
|
369890
|
+
current = bindingPattern.parent;
|
|
369891
|
+
}
|
|
369892
|
+
return { propertyNames, includesRest };
|
|
369893
|
+
}
|
|
369894
|
+
function hasPotentialObjectBindingDefaultAlias(bindingElement, declaration, checker, seen) {
|
|
369895
|
+
for (let current = bindingElement; current; ) {
|
|
369896
|
+
if (current.initializer && isStaticObjectAliasExpression(current.initializer, declaration, checker, new Set(seen)))
|
|
369897
|
+
return true;
|
|
369898
|
+
const bindingPattern = current.parent;
|
|
369899
|
+
if (!typescript_1.default.isObjectBindingPattern(bindingPattern) || !typescript_1.default.isBindingElement(bindingPattern.parent))
|
|
369900
|
+
return false;
|
|
369901
|
+
current = bindingPattern.parent;
|
|
369902
|
+
}
|
|
369903
|
+
return false;
|
|
369904
|
+
}
|
|
369905
|
+
function isStaticObjectBindingAliasReference(bindingElement, declaration, checker, seen) {
|
|
369906
|
+
if (typescript_1.default.isArrayBindingPattern(bindingElement.parent) || hasEnclosingArrayBindingPattern(bindingElement)) {
|
|
369907
|
+
return isStaticCollectionBindingAliasReference(bindingElement, declaration, checker, seen);
|
|
369908
|
+
}
|
|
369909
|
+
const variableDeclaration = variableDeclarationForBindingElement(bindingElement);
|
|
369910
|
+
const propertyPath = bindingElementPropertyPath(bindingElement, checker);
|
|
369911
|
+
if (!variableDeclaration?.initializer || !propertyPath)
|
|
369912
|
+
return false;
|
|
369913
|
+
if (hasPotentialObjectBindingDefaultAlias(bindingElement, declaration, checker, seen))
|
|
369914
|
+
return true;
|
|
369915
|
+
let expression = variableDeclaration.initializer;
|
|
369916
|
+
for (const propertyName of propertyPath.propertyNames) {
|
|
369917
|
+
if (isDirectStaticObjectAliasExpression(expression, declaration, checker, new Set(seen)))
|
|
369918
|
+
return true;
|
|
369919
|
+
const objectLiteral = resolveStaticObjectLiteralAlias(expression, checker, new Set(seen));
|
|
369920
|
+
if (!objectLiteral)
|
|
369921
|
+
return false;
|
|
369922
|
+
const propertyValue = getStaticObjectPropertyValue(objectLiteral, propertyName, checker, /* @__PURE__ */ new Set());
|
|
369923
|
+
if (propertyValue === void 0)
|
|
369924
|
+
return false;
|
|
369925
|
+
expression = propertyValue;
|
|
369926
|
+
}
|
|
369927
|
+
return propertyPath.includesRest ? isStaticObjectAliasExpression(expression, declaration, checker, new Set(seen)) : isDirectStaticObjectAliasExpression(expression, declaration, checker, new Set(seen));
|
|
369928
|
+
}
|
|
369929
|
+
function hasEnclosingArrayBindingPattern(bindingElement) {
|
|
369930
|
+
for (let current = bindingElement; current; ) {
|
|
369931
|
+
const pattern = current.parent;
|
|
369932
|
+
if (typescript_1.default.isArrayBindingPattern(pattern))
|
|
369933
|
+
return true;
|
|
369934
|
+
if (!typescript_1.default.isObjectBindingPattern(pattern) || !typescript_1.default.isBindingElement(pattern.parent))
|
|
369935
|
+
return false;
|
|
369936
|
+
current = pattern.parent;
|
|
369937
|
+
}
|
|
369938
|
+
return false;
|
|
369939
|
+
}
|
|
369940
|
+
function isStaticCollectionBindingAliasReference(bindingElement, declaration, checker, seen) {
|
|
369941
|
+
if (hasPotentialCollectionBindingDefaultAlias(bindingElement, declaration, checker, seen))
|
|
369942
|
+
return true;
|
|
369943
|
+
const values = getStaticCollectionBindingValues(bindingElement, checker);
|
|
369944
|
+
if (!values)
|
|
369945
|
+
return true;
|
|
369946
|
+
return values.some((value) => isStaticObjectAliasExpression(value, declaration, checker, new Set(seen)));
|
|
369947
|
+
}
|
|
369948
|
+
function hasPotentialCollectionBindingDefaultAlias(bindingElement, declaration, checker, seen) {
|
|
369949
|
+
for (let current = bindingElement; current; ) {
|
|
369950
|
+
if (current.initializer && isStaticObjectAliasExpression(current.initializer, declaration, checker, new Set(seen))) {
|
|
369951
|
+
return true;
|
|
369952
|
+
}
|
|
369953
|
+
const pattern = current.parent;
|
|
369954
|
+
if (!typescript_1.default.isObjectBindingPattern(pattern) && !typescript_1.default.isArrayBindingPattern(pattern))
|
|
369955
|
+
return true;
|
|
369956
|
+
if (!typescript_1.default.isBindingElement(pattern.parent))
|
|
369957
|
+
return false;
|
|
369958
|
+
current = pattern.parent;
|
|
369959
|
+
}
|
|
369960
|
+
return true;
|
|
369961
|
+
}
|
|
369962
|
+
function getStaticCollectionBindingValues(bindingElement, checker) {
|
|
369963
|
+
const pattern = bindingElement.parent;
|
|
369964
|
+
const source = getStaticBindingPatternSource(pattern, checker);
|
|
369965
|
+
if (!source)
|
|
369966
|
+
return void 0;
|
|
369967
|
+
if (typescript_1.default.isArrayBindingPattern(pattern)) {
|
|
369968
|
+
const arrayLiteral = resolveStaticArrayLiteralAlias(source, checker, /* @__PURE__ */ new Set(), bindingElement);
|
|
369969
|
+
const elements = arrayLiteral && expandStaticArrayElements(arrayLiteral, checker, bindingElement);
|
|
369970
|
+
if (!elements)
|
|
369971
|
+
return void 0;
|
|
369972
|
+
const elementIndex = pattern.elements.indexOf(bindingElement);
|
|
369973
|
+
if (elementIndex === -1)
|
|
369974
|
+
return void 0;
|
|
369975
|
+
if (bindingElement.dotDotDotToken)
|
|
369976
|
+
return elements.slice(elementIndex).filter((element) => Boolean(element));
|
|
369977
|
+
const value2 = elements[elementIndex];
|
|
369978
|
+
if (!value2 || isStaticUndefinedExpression(value2))
|
|
369979
|
+
return bindingElement.initializer ? [bindingElement.initializer] : [];
|
|
369980
|
+
return [value2];
|
|
369981
|
+
}
|
|
369982
|
+
if (!typescript_1.default.isObjectBindingPattern(pattern))
|
|
369983
|
+
return void 0;
|
|
369984
|
+
const objectLiteral = resolveStaticObjectLiteralAlias(source, checker, /* @__PURE__ */ new Set());
|
|
369985
|
+
if (!objectLiteral || bindingElement.dotDotDotToken)
|
|
369986
|
+
return void 0;
|
|
369987
|
+
const propertyName = bindingElement.propertyName ? getStaticPropertyNameText(bindingElement.propertyName, checker) : typescript_1.default.isIdentifier(bindingElement.name) ? bindingElement.name.text : void 0;
|
|
369988
|
+
if (propertyName === void 0)
|
|
369989
|
+
return void 0;
|
|
369990
|
+
const value = getStaticObjectPropertyValue(objectLiteral, propertyName, checker, /* @__PURE__ */ new Set());
|
|
369991
|
+
if (value === void 0 && hasUnresolvedStaticObjectSpread(objectLiteral, checker))
|
|
369992
|
+
return void 0;
|
|
369993
|
+
return value === void 0 ? [] : [value];
|
|
369994
|
+
}
|
|
369995
|
+
function hasUnresolvedStaticObjectSpread(objectLiteral, checker, seen = /* @__PURE__ */ new Set()) {
|
|
369996
|
+
return objectLiteral.properties.some((property) => {
|
|
369997
|
+
if (!typescript_1.default.isSpreadAssignment(property))
|
|
369998
|
+
return false;
|
|
369999
|
+
const spreadSeen = new Set(seen);
|
|
370000
|
+
const spreadObject = resolveStaticObjectLiteralAlias(property.expression, checker, spreadSeen);
|
|
370001
|
+
return !spreadObject || hasUnresolvedStaticObjectSpread(spreadObject, checker, spreadSeen);
|
|
370002
|
+
});
|
|
370003
|
+
}
|
|
370004
|
+
function getStaticBindingPatternSource(pattern, checker) {
|
|
370005
|
+
if (typescript_1.default.isVariableDeclaration(pattern.parent))
|
|
370006
|
+
return pattern.parent.initializer;
|
|
370007
|
+
if (!typescript_1.default.isBindingElement(pattern.parent))
|
|
370008
|
+
return void 0;
|
|
370009
|
+
const values = getStaticCollectionBindingValues(pattern.parent, checker);
|
|
370010
|
+
return values?.length === 1 ? values[0] : void 0;
|
|
370011
|
+
}
|
|
370012
|
+
function expandStaticArrayElements(arrayLiteral, checker, sourceNode) {
|
|
370013
|
+
const elements = [];
|
|
370014
|
+
for (const element of arrayLiteral.elements) {
|
|
370015
|
+
if (typescript_1.default.isOmittedExpression(element)) {
|
|
370016
|
+
elements.push(void 0);
|
|
370017
|
+
continue;
|
|
370018
|
+
}
|
|
370019
|
+
if (!typescript_1.default.isSpreadElement(element)) {
|
|
370020
|
+
elements.push(element);
|
|
370021
|
+
continue;
|
|
370022
|
+
}
|
|
370023
|
+
const nestedArray = resolveStaticArrayLiteralAlias(element.expression, checker, /* @__PURE__ */ new Set(), sourceNode);
|
|
370024
|
+
const nestedElements = nestedArray && expandStaticArrayElements(nestedArray, checker, sourceNode);
|
|
370025
|
+
if (!nestedElements)
|
|
370026
|
+
return void 0;
|
|
370027
|
+
elements.push(...nestedElements);
|
|
370028
|
+
}
|
|
370029
|
+
return elements;
|
|
370030
|
+
}
|
|
370031
|
+
function resolveStaticArrayLiteralAlias(expression, checker, seen, sourceNode) {
|
|
370032
|
+
const unwrapped = unwrapStaticExpression(expression);
|
|
370033
|
+
if (typescript_1.default.isArrayLiteralExpression(unwrapped))
|
|
370034
|
+
return unwrapped;
|
|
370035
|
+
if (!typescript_1.default.isIdentifier(unwrapped))
|
|
370036
|
+
return void 0;
|
|
370037
|
+
const declaration = resolvedIdentifierDeclarations(unwrapped, checker).find(typescript_1.default.isVariableDeclaration);
|
|
370038
|
+
if (!declaration?.initializer || !isConstVariableDeclaration(declaration) || seen.has(declaration)) {
|
|
370039
|
+
return void 0;
|
|
370040
|
+
}
|
|
370041
|
+
seen.add(declaration);
|
|
370042
|
+
return resolveStaticArrayLiteralAlias(declaration.initializer, checker, seen, sourceNode);
|
|
370043
|
+
}
|
|
370044
|
+
function isStaticUndefinedExpression(expression) {
|
|
370045
|
+
const unwrapped = unwrapStaticExpression(expression);
|
|
370046
|
+
return typescript_1.default.isIdentifier(unwrapped) && unwrapped.text === "undefined" || typescript_1.default.isVoidExpression(unwrapped);
|
|
370047
|
+
}
|
|
370048
|
+
function isDirectStaticObjectAliasExpression(expression, declaration, checker, seen) {
|
|
370049
|
+
const unwrapped = unwrapStaticExpression(expression);
|
|
370050
|
+
if (typescript_1.default.isPropertyAccessExpression(unwrapped) || typescript_1.default.isElementAccessExpression(unwrapped)) {
|
|
370051
|
+
if (isDirectStaticObjectAliasExpression(unwrapped.expression, declaration, checker, new Set(seen)))
|
|
370052
|
+
return true;
|
|
370053
|
+
const objectLiteral = resolveStaticObjectLiteralAlias(unwrapped.expression, checker, new Set(seen));
|
|
370054
|
+
const propertyName = typescript_1.default.isPropertyAccessExpression(unwrapped) ? unwrapped.name.text : unwrapped.argumentExpression && resolveStaticStringExpression(unwrapped.argumentExpression, checker);
|
|
370055
|
+
if (!objectLiteral || propertyName === void 0)
|
|
370056
|
+
return false;
|
|
370057
|
+
const propertyValue = getStaticObjectPropertyValue(objectLiteral, propertyName, checker, /* @__PURE__ */ new Set());
|
|
370058
|
+
return propertyValue === void 0 ? false : isDirectStaticObjectAliasExpression(propertyValue, declaration, checker, seen);
|
|
370059
|
+
}
|
|
370060
|
+
if (!typescript_1.default.isIdentifier(unwrapped))
|
|
370061
|
+
return false;
|
|
370062
|
+
const resolved = resolveStaticObjectAliasDeclaration(unwrapped, checker);
|
|
370063
|
+
if (resolved === declaration)
|
|
370064
|
+
return true;
|
|
370065
|
+
if (!resolved || seen.has(resolved))
|
|
370066
|
+
return false;
|
|
370067
|
+
seen.add(resolved);
|
|
370068
|
+
if (typescript_1.default.isBindingElement(resolved))
|
|
370069
|
+
return isStaticObjectBindingAliasReference(resolved, declaration, checker, seen);
|
|
370070
|
+
if (!typescript_1.default.isVariableDeclaration(resolved) || !resolved.initializer)
|
|
370071
|
+
return false;
|
|
370072
|
+
return isDirectStaticObjectAliasExpression(resolved.initializer, declaration, checker, seen);
|
|
370073
|
+
}
|
|
370074
|
+
function isStaticObjectAliasExpression(expression, declaration, checker, seen) {
|
|
370075
|
+
const unwrapped = unwrapStaticExpression(expression);
|
|
370076
|
+
if (typescript_1.default.isConditionalExpression(unwrapped)) {
|
|
370077
|
+
return isStaticObjectAliasExpression(unwrapped.whenTrue, declaration, checker, new Set(seen)) || isStaticObjectAliasExpression(unwrapped.whenFalse, declaration, checker, new Set(seen));
|
|
370078
|
+
}
|
|
370079
|
+
if (typescript_1.default.isBinaryExpression(unwrapped) && (unwrapped.operatorToken.kind === typescript_1.default.SyntaxKind.AmpersandAmpersandToken || unwrapped.operatorToken.kind === typescript_1.default.SyntaxKind.BarBarToken || unwrapped.operatorToken.kind === typescript_1.default.SyntaxKind.QuestionQuestionToken)) {
|
|
370080
|
+
return isStaticObjectAliasExpression(unwrapped.left, declaration, checker, new Set(seen)) || isStaticObjectAliasExpression(unwrapped.right, declaration, checker, new Set(seen));
|
|
370081
|
+
}
|
|
370082
|
+
if (typescript_1.default.isObjectLiteralExpression(unwrapped)) {
|
|
370083
|
+
return unwrapped.properties.some((property) => {
|
|
370084
|
+
if (typescript_1.default.isPropertyAssignment(property))
|
|
370085
|
+
return isStaticObjectAliasExpression(property.initializer, declaration, checker, seen);
|
|
370086
|
+
if (typescript_1.default.isShorthandPropertyAssignment(property) && typescript_1.default.isIdentifier(property.name))
|
|
370087
|
+
return isStaticObjectAliasExpression(property.name, declaration, checker, seen);
|
|
370088
|
+
if (!typescript_1.default.isSpreadAssignment(property))
|
|
370089
|
+
return true;
|
|
370090
|
+
const spreadObject = resolveStaticObjectLiteralAlias(property.expression, checker, new Set(seen));
|
|
370091
|
+
return !spreadObject || isStaticObjectAliasExpression(property.expression, declaration, checker, seen);
|
|
370092
|
+
});
|
|
370093
|
+
}
|
|
370094
|
+
if (typescript_1.default.isArrayLiteralExpression(unwrapped)) {
|
|
370095
|
+
return unwrapped.elements.some((element) => {
|
|
370096
|
+
if (typescript_1.default.isOmittedExpression(element))
|
|
370097
|
+
return false;
|
|
370098
|
+
if (!typescript_1.default.isSpreadElement(element))
|
|
370099
|
+
return isStaticObjectAliasExpression(element, declaration, checker, seen);
|
|
370100
|
+
const spreadArray = resolveStaticArrayLiteralAlias(element.expression, checker, /* @__PURE__ */ new Set());
|
|
370101
|
+
return !spreadArray || isStaticObjectAliasExpression(element.expression, declaration, checker, seen);
|
|
370102
|
+
});
|
|
370103
|
+
}
|
|
370104
|
+
if (typescript_1.default.isIdentifier(unwrapped))
|
|
370105
|
+
return isStaticObjectAliasReference(unwrapped, declaration, checker, seen);
|
|
370106
|
+
if (typescript_1.default.isPropertyAccessExpression(unwrapped) || typescript_1.default.isElementAccessExpression(unwrapped)) {
|
|
370107
|
+
const directBase = unwrapStaticExpression(unwrapped.expression);
|
|
370108
|
+
if (typescript_1.default.isIdentifier(directBase) && resolveStaticObjectAliasDeclaration(directBase, checker) === declaration) {
|
|
370109
|
+
return true;
|
|
370110
|
+
}
|
|
370111
|
+
const objectLiteral = resolveStaticObjectLiteralAlias(unwrapped.expression, checker, new Set(seen));
|
|
370112
|
+
const propertyName = typescript_1.default.isPropertyAccessExpression(unwrapped) ? unwrapped.name.text : unwrapped.argumentExpression && resolveStaticStringExpression(unwrapped.argumentExpression, checker);
|
|
370113
|
+
if (objectLiteral && propertyName) {
|
|
370114
|
+
const propertyValue = getStaticObjectPropertyValue(objectLiteral, propertyName, checker, /* @__PURE__ */ new Set());
|
|
370115
|
+
if (propertyValue !== void 0)
|
|
370116
|
+
return isStaticObjectAliasExpression(propertyValue, declaration, checker, seen);
|
|
370117
|
+
return hasUnresolvedStaticObjectSpread(objectLiteral, checker);
|
|
370118
|
+
}
|
|
370119
|
+
if (isStaticObjectAliasExpression(unwrapped.expression, declaration, checker, new Set(seen)))
|
|
370120
|
+
return true;
|
|
370121
|
+
}
|
|
370122
|
+
const accessBase = getPotentialObjectAliasAccessBase(unwrapped);
|
|
370123
|
+
return accessBase ? isStaticObjectAliasExpression(accessBase, declaration, checker, seen) : false;
|
|
370124
|
+
}
|
|
370125
|
+
function resolveStaticObjectLiteralAlias(expression, checker, seen) {
|
|
370126
|
+
const unwrapped = unwrapStaticExpression(expression);
|
|
370127
|
+
if (typescript_1.default.isObjectLiteralExpression(unwrapped))
|
|
370128
|
+
return unwrapped;
|
|
370129
|
+
if (!typescript_1.default.isIdentifier(unwrapped))
|
|
370130
|
+
return void 0;
|
|
370131
|
+
const resolved = resolveStaticObjectAliasDeclaration(unwrapped, checker);
|
|
370132
|
+
if (!resolved || seen.has(resolved) || !typescript_1.default.isVariableDeclaration(resolved) || !resolved.initializer)
|
|
370133
|
+
return void 0;
|
|
370134
|
+
seen.add(resolved);
|
|
370135
|
+
return resolveStaticObjectLiteralAlias(resolved.initializer, checker, seen);
|
|
370136
|
+
}
|
|
370137
|
+
function getPotentialObjectAliasAccessBase(expression) {
|
|
370138
|
+
if (typescript_1.default.isPropertyAccessExpression(expression))
|
|
370139
|
+
return expression.expression;
|
|
370140
|
+
if (typescript_1.default.isElementAccessExpression(expression))
|
|
370141
|
+
return expression.expression;
|
|
370142
|
+
return void 0;
|
|
370143
|
+
}
|
|
370144
|
+
function isPotentialObjectMutationReference(identifier, checker, ignoredCall) {
|
|
370145
|
+
for (let current = identifier; current.parent; current = current.parent) {
|
|
370146
|
+
const parent = current.parent;
|
|
370147
|
+
if (parent === ignoredCall)
|
|
370148
|
+
return false;
|
|
370149
|
+
if (typescript_1.default.isCallExpression(parent) && isReadOnlyObjectInspection(parent, identifier, checker))
|
|
370150
|
+
return false;
|
|
370151
|
+
if (typescript_1.default.isBinaryExpression(parent) && isAssignmentOperator(parent.operatorToken.kind) && (isDescendantOf(identifier, parent.left) || isDescendantOf(identifier, parent.right))) {
|
|
370152
|
+
return true;
|
|
370153
|
+
}
|
|
370154
|
+
if ((typescript_1.default.isPrefixUnaryExpression(parent) || typescript_1.default.isPostfixUnaryExpression(parent)) && isDescendantOf(identifier, parent.operand)) {
|
|
370155
|
+
return true;
|
|
370156
|
+
}
|
|
370157
|
+
if (typescript_1.default.isDeleteExpression(parent) && isDescendantOf(identifier, parent.expression))
|
|
370158
|
+
return true;
|
|
370159
|
+
if (typescript_1.default.isReturnStatement(parent) || typescript_1.default.isYieldExpression(parent))
|
|
370160
|
+
return true;
|
|
370161
|
+
if ((typescript_1.default.isCallExpression(parent) || typescript_1.default.isNewExpression(parent)) && parent !== ignoredCall && (parent.arguments?.some((argument) => isDescendantOf(identifier, argument)) || isDescendantOf(identifier, parent.expression))) {
|
|
370162
|
+
return true;
|
|
370163
|
+
}
|
|
370164
|
+
}
|
|
370165
|
+
return false;
|
|
370166
|
+
}
|
|
370167
|
+
function isReadOnlyObjectInspection(call, identifier, checker) {
|
|
370168
|
+
if (!typescript_1.default.isPropertyAccessExpression(call.expression) || !typescript_1.default.isIdentifier(call.expression.expression) || call.expression.expression.text !== "Object" || !isGlobalObjectIdentifier(call.expression.expression, checker) || !READ_ONLY_OBJECT_INSPECTION_METHODS.has(call.expression.name.text)) {
|
|
370169
|
+
return false;
|
|
370170
|
+
}
|
|
370171
|
+
return call.arguments[0] === identifier;
|
|
370172
|
+
}
|
|
370173
|
+
function isGlobalObjectIdentifier(identifier, checker) {
|
|
370174
|
+
const declarations = checker.getSymbolAtLocation(identifier)?.declarations;
|
|
370175
|
+
return Boolean(declarations?.length && declarations.every((declaration) => declaration.getSourceFile().isDeclarationFile));
|
|
370176
|
+
}
|
|
370177
|
+
function isDescendantOf(node, ancestor) {
|
|
370178
|
+
for (let current = node; current; current = current.parent) {
|
|
370179
|
+
if (current === ancestor)
|
|
370180
|
+
return true;
|
|
370181
|
+
}
|
|
370182
|
+
return false;
|
|
370183
|
+
}
|
|
370184
|
+
function getStaticPropertyNameText(name, checker) {
|
|
370185
|
+
if (typescript_1.default.isIdentifier(name) || typescript_1.default.isStringLiteral(name) || typescript_1.default.isNumericLiteral(name))
|
|
370186
|
+
return name.text;
|
|
370187
|
+
if (typescript_1.default.isComputedPropertyName(name))
|
|
370188
|
+
return resolveStaticStringExpression(name.expression, checker);
|
|
370189
|
+
return void 0;
|
|
370190
|
+
}
|
|
370191
|
+
function isConditionFunction(node) {
|
|
370192
|
+
return typescript_1.default.isArrowFunction(node) || typescript_1.default.isFunctionExpression(node);
|
|
370193
|
+
}
|
|
370194
|
+
function containsAwait(node) {
|
|
370195
|
+
let found = false;
|
|
370196
|
+
const visit = (current) => {
|
|
370197
|
+
if (found)
|
|
370198
|
+
return;
|
|
370199
|
+
if (typescript_1.default.isAwaitExpression(current)) {
|
|
370200
|
+
found = true;
|
|
370201
|
+
return;
|
|
370202
|
+
}
|
|
370203
|
+
typescript_1.default.forEachChild(current, visit);
|
|
370204
|
+
};
|
|
370205
|
+
visit(node);
|
|
370206
|
+
return found;
|
|
370207
|
+
}
|
|
370208
|
+
function hasPredicateReturn(predicate) {
|
|
370209
|
+
if (!typescript_1.default.isBlock(predicate.body))
|
|
370210
|
+
return true;
|
|
370211
|
+
let found = false;
|
|
370212
|
+
const visit = (node) => {
|
|
370213
|
+
if (found)
|
|
370214
|
+
return;
|
|
370215
|
+
if (node !== predicate.body && isNestedFunctionLike(node))
|
|
370216
|
+
return;
|
|
370217
|
+
if (typescript_1.default.isReturnStatement(node) && node.expression)
|
|
370218
|
+
found = true;
|
|
370219
|
+
typescript_1.default.forEachChild(node, visit);
|
|
370220
|
+
};
|
|
370221
|
+
visit(predicate.body);
|
|
370222
|
+
return found;
|
|
370223
|
+
}
|
|
370224
|
+
function isAnyOrUnknown(type2) {
|
|
370225
|
+
return Boolean(type2.flags & (typescript_1.default.TypeFlags.Any | typescript_1.default.TypeFlags.Unknown));
|
|
370226
|
+
}
|
|
370227
|
+
function isBooleanLike(type2, checker) {
|
|
370228
|
+
const booleanType2 = checker.getBooleanType();
|
|
370229
|
+
if (checker.isTypeAssignableTo(type2, booleanType2))
|
|
370230
|
+
return true;
|
|
370231
|
+
if (type2.isUnion())
|
|
370232
|
+
return type2.types.every((item) => checker.isTypeAssignableTo(item, booleanType2));
|
|
370233
|
+
return false;
|
|
370234
|
+
}
|
|
370235
|
+
function isPromiseLike(type2, checker) {
|
|
370236
|
+
void checker;
|
|
370237
|
+
return type2.getProperty("then") !== void 0;
|
|
370238
|
+
}
|
|
370239
|
+
function isNestedFunctionLike(node) {
|
|
370240
|
+
return typescript_1.default.isFunctionDeclaration(node) || typescript_1.default.isFunctionExpression(node) || typescript_1.default.isArrowFunction(node) || typescript_1.default.isMethodDeclaration(node) || typescript_1.default.isGetAccessorDeclaration(node) || typescript_1.default.isSetAccessorDeclaration(node) || typescript_1.default.isConstructorDeclaration(node);
|
|
370241
|
+
}
|
|
370242
|
+
function getVariableFunction(sourceFile, name) {
|
|
370243
|
+
for (const statement of sourceFile.statements) {
|
|
370244
|
+
if (!typescript_1.default.isVariableStatement(statement))
|
|
370245
|
+
continue;
|
|
370246
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
370247
|
+
if (!typescript_1.default.isIdentifier(declaration.name) || declaration.name.text !== name)
|
|
370248
|
+
continue;
|
|
370249
|
+
const initializer3 = declaration.initializer;
|
|
370250
|
+
if (initializer3 && (typescript_1.default.isArrowFunction(initializer3) || typescript_1.default.isFunctionExpression(initializer3)))
|
|
370251
|
+
return initializer3;
|
|
370252
|
+
}
|
|
370253
|
+
}
|
|
370254
|
+
return void 0;
|
|
370255
|
+
}
|
|
370256
|
+
function createGeneratedConditionHandlerName(sourceFile) {
|
|
370257
|
+
const names = /* @__PURE__ */ new Set();
|
|
370258
|
+
const visit = (node) => {
|
|
370259
|
+
if (typescript_1.default.isIdentifier(node))
|
|
370260
|
+
names.add(node.text);
|
|
370261
|
+
typescript_1.default.forEachChild(node, visit);
|
|
370262
|
+
};
|
|
370263
|
+
visit(sourceFile);
|
|
370264
|
+
let index = 0;
|
|
370265
|
+
while (names.has(`__workflowCondition${index === 0 ? "" : index}`))
|
|
370266
|
+
index++;
|
|
370267
|
+
return `__workflowCondition${index === 0 ? "" : index}`;
|
|
370268
|
+
}
|
|
370269
|
+
function printConditionExpressionWithClosure(predicate, sourceFile, generatedHandlerName) {
|
|
370270
|
+
const body = printConditionBody(predicate, sourceFile);
|
|
370271
|
+
const closure = printConditionClosure(sourceFile, generatedHandlerName);
|
|
370272
|
+
if (closure.length === 0)
|
|
370273
|
+
return body;
|
|
370274
|
+
return `(() => {
|
|
370275
|
+
${closure}
|
|
370276
|
+
return (${body})
|
|
370277
|
+
})()`;
|
|
370278
|
+
}
|
|
370279
|
+
function printConditionClosure(sourceFile, generatedHandlerName) {
|
|
370280
|
+
const statements2 = sourceFile.statements.filter((statement) => !isNamedVariableStatement(statement, generatedHandlerName));
|
|
370281
|
+
if (statements2.length === 0)
|
|
370282
|
+
return "";
|
|
370283
|
+
const printed = printFile(createRuntimeSourceFile(sourceFile, statements2, void 0));
|
|
370284
|
+
return transpileTypeScriptToJavaScript(printed);
|
|
370285
|
+
}
|
|
370286
|
+
function isNamedVariableStatement(statement, name) {
|
|
370287
|
+
return typescript_1.default.isVariableStatement(statement) && statement.declarationList.declarations.some((declaration) => typescript_1.default.isIdentifier(declaration.name) && declaration.name.text === name);
|
|
370288
|
+
}
|
|
370289
|
+
function printConditionBody(predicate, sourceFile) {
|
|
370290
|
+
if (!typescript_1.default.isBlock(predicate.body))
|
|
370291
|
+
return printConditionJavaScriptExpression(predicate.body, sourceFile);
|
|
370292
|
+
return `(() => {${printConditionJavaScriptBlockStatements(predicate.body.statements, sourceFile)}})()`;
|
|
370293
|
+
}
|
|
370294
|
+
function printConditionJavaScriptExpression(expression, sourceFile) {
|
|
370295
|
+
const expressionText = printExpression(expression, sourceFile);
|
|
370296
|
+
const javascript = transpileTypeScriptToJavaScript(`const __workflowConditionExpression = (${expressionText});`);
|
|
370297
|
+
const javascriptSourceFile = typescript_1.default.createSourceFile("workflow-condition-expression.js", javascript, typescript_1.default.ScriptTarget.ES2022, true, typescript_1.default.ScriptKind.JS);
|
|
370298
|
+
const initializer3 = findVariableInitializer(javascriptSourceFile, "__workflowConditionExpression");
|
|
370299
|
+
return initializer3 ? printExpression(unwrapParenthesizedExpression(initializer3), javascriptSourceFile) : expressionText;
|
|
370300
|
+
}
|
|
370301
|
+
function unwrapParenthesizedExpression(expression) {
|
|
370302
|
+
return typescript_1.default.isParenthesizedExpression(expression) ? unwrapParenthesizedExpression(expression.expression) : expression;
|
|
370303
|
+
}
|
|
370304
|
+
function printConditionJavaScriptBlockStatements(statements2, sourceFile) {
|
|
370305
|
+
const statementText = statements2.map((statement) => printStatement(statement, sourceFile)).join("\n");
|
|
370306
|
+
const javascript = transpileTypeScriptToJavaScript(`const __workflowConditionBlock = () => {
|
|
370307
|
+
${statementText}
|
|
370308
|
+
};`);
|
|
370309
|
+
const javascriptSourceFile = typescript_1.default.createSourceFile("workflow-condition-block.js", javascript, typescript_1.default.ScriptTarget.ES2022, true, typescript_1.default.ScriptKind.JS);
|
|
370310
|
+
const initializer3 = findVariableInitializer(javascriptSourceFile, "__workflowConditionBlock");
|
|
370311
|
+
const body = initializer3 && typescript_1.default.isArrowFunction(initializer3) && typescript_1.default.isBlock(initializer3.body) ? initializer3.body : void 0;
|
|
370312
|
+
return body ? body.statements.map((statement) => printStatement(statement, javascriptSourceFile)).join("") : statementText;
|
|
370313
|
+
}
|
|
370314
|
+
function findVariableInitializer(sourceFile, name) {
|
|
370315
|
+
for (const statement of sourceFile.statements) {
|
|
370316
|
+
if (!typescript_1.default.isVariableStatement(statement))
|
|
370317
|
+
continue;
|
|
370318
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
370319
|
+
if (typescript_1.default.isIdentifier(declaration.name) && declaration.name.text === name)
|
|
370320
|
+
return declaration.initializer;
|
|
370321
|
+
}
|
|
370322
|
+
}
|
|
370323
|
+
return void 0;
|
|
370324
|
+
}
|
|
370325
|
+
function transpileTypeScriptToJavaScript(source) {
|
|
370326
|
+
return typescript_1.default.transpileModule(source, {
|
|
370327
|
+
compilerOptions: {
|
|
370328
|
+
target: typescript_1.default.ScriptTarget.ES2022,
|
|
370329
|
+
module: typescript_1.default.ModuleKind.ESNext,
|
|
370330
|
+
removeComments: false
|
|
370331
|
+
}
|
|
370332
|
+
}).outputText.replace(/^"use strict";\r?\n?/u, "").trim();
|
|
370333
|
+
}
|
|
369396
370334
|
function resolveHandler(call, sourceFile, checker) {
|
|
369397
370335
|
const handler = getHandlerExpression(call);
|
|
369398
370336
|
if (!handler)
|
|
@@ -369524,7 +370462,7 @@ var require_extract3 = __commonJS({
|
|
|
369524
370462
|
if (effectiveKey) {
|
|
369525
370463
|
const staticTarget = resolveBuiltRefTargetByEffectiveKey(effectiveKey, context);
|
|
369526
370464
|
if (staticTarget)
|
|
369527
|
-
return
|
|
370465
|
+
return staticTarget;
|
|
369528
370466
|
}
|
|
369529
370467
|
if (declaration)
|
|
369530
370468
|
return resolveBuiltRefTargetFromBuildArrays(identifier, declaration, checker, context);
|
|
@@ -369533,12 +370471,40 @@ var require_extract3 = __commonJS({
|
|
|
369533
370471
|
function resolveBuiltRefTargetByEffectiveKey(effectiveKey, context) {
|
|
369534
370472
|
const inputName = context.inputNamesByKey.get(effectiveKey);
|
|
369535
370473
|
if (inputName)
|
|
369536
|
-
return { kind: "input", effectiveKey, runtimeName: inputName };
|
|
370474
|
+
return { target: { kind: "input", effectiveKey, runtimeName: inputName } };
|
|
370475
|
+
const scopedTarget = resolveScopedBuiltRefTarget(effectiveKey, context);
|
|
370476
|
+
if (scopedTarget)
|
|
370477
|
+
return scopedTarget;
|
|
369537
370478
|
const nodeName = context.nodeNamesByKey.get(effectiveKey);
|
|
369538
370479
|
if (nodeName)
|
|
369539
|
-
return { kind: "node", effectiveKey, runtimeName: nodeName, nodeIndex: context.nodeIndexesByKey.get(effectiveKey) };
|
|
370480
|
+
return { target: { kind: "node", effectiveKey, runtimeName: nodeName, nodeIndex: context.nodeIndexesByKey.get(effectiveKey) } };
|
|
369540
370481
|
return void 0;
|
|
369541
370482
|
}
|
|
370483
|
+
function resolveScopedBuiltRefTarget(effectiveKey, context) {
|
|
370484
|
+
const { currentNode, nodeIdentitiesByKey } = context;
|
|
370485
|
+
if (!nodeIdentitiesByKey || !currentNode)
|
|
370486
|
+
return void 0;
|
|
370487
|
+
const candidates = nodeIdentitiesByKey.get(effectiveKey) ?? [];
|
|
370488
|
+
if (candidates.length === 0)
|
|
370489
|
+
return void 0;
|
|
370490
|
+
const visible = (0, refs_1.resolveVisibleNodeIdentity)(effectiveKey, { nodeIdentitiesByKey, currentNode });
|
|
370491
|
+
if (visible) {
|
|
370492
|
+
return {
|
|
370493
|
+
target: {
|
|
370494
|
+
kind: "node",
|
|
370495
|
+
effectiveKey,
|
|
370496
|
+
runtimeName: visible.runtimeName
|
|
370497
|
+
}
|
|
370498
|
+
};
|
|
370499
|
+
}
|
|
370500
|
+
if (candidates.some((candidate) => samePath(candidate.scopePath, currentNode.scopePath) && candidate.sequenceIndex >= currentNode.sequenceIndex)) {
|
|
370501
|
+
return { refFailure: "forward" };
|
|
370502
|
+
}
|
|
370503
|
+
return { refFailure: "scope" };
|
|
370504
|
+
}
|
|
370505
|
+
function samePath(left, right) {
|
|
370506
|
+
return left.length === right.length && left.every((segment, index) => segment === right[index]);
|
|
370507
|
+
}
|
|
369542
370508
|
function resolveBuiltRefTargetFromBuildArrays(identifier, declaration, checker, context) {
|
|
369543
370509
|
const candidates = [];
|
|
369544
370510
|
let unsupportedDynamicBuildArray = false;
|
|
@@ -369588,10 +370554,13 @@ var require_extract3 = __commonJS({
|
|
|
369588
370554
|
return false;
|
|
369589
370555
|
}
|
|
369590
370556
|
const builtNode = context.builtNodes[match];
|
|
369591
|
-
if (builtNode)
|
|
370557
|
+
if (builtNode && isOutputProducingNode(builtNode))
|
|
369592
370558
|
candidates.push({ kind: "node", effectiveKey: builtNode.key ?? builtNode.name, runtimeName: builtNode.name, nodeIndex: match });
|
|
369593
370559
|
return false;
|
|
369594
370560
|
}
|
|
370561
|
+
function isOutputProducingNode(node) {
|
|
370562
|
+
return node.nodeKind !== "condition" && node.nodeKind !== "stop";
|
|
370563
|
+
}
|
|
369595
370564
|
function uniqueBuiltRefTarget(candidates) {
|
|
369596
370565
|
if (candidates.length === 0)
|
|
369597
370566
|
return void 0;
|
|
@@ -370114,7 +371083,27 @@ var require_extract3 = __commonJS({
|
|
|
370114
371083
|
}
|
|
370115
371084
|
function isDeclaredInsideRoot(identifier, root, checker) {
|
|
370116
371085
|
const symbol3 = checker.getSymbolAtLocation(identifier);
|
|
370117
|
-
return Boolean(symbol3?.declarations?.some((declaration) => nodeContains(root, declaration)));
|
|
371086
|
+
return Boolean(symbol3?.declarations?.some((declaration) => nodeContains(root, declaration))) || isLexicallyDeclaredInsideRoot(identifier, root);
|
|
371087
|
+
}
|
|
371088
|
+
function isLexicallyDeclaredInsideRoot(identifier, root) {
|
|
371089
|
+
let current = identifier.parent;
|
|
371090
|
+
while (current && current !== root) {
|
|
371091
|
+
const currentParameters = functionLikeParameters(current);
|
|
371092
|
+
if (currentParameters && currentParameters.some((parameter) => bindingNames(parameter.name).includes(identifier.text)))
|
|
371093
|
+
return true;
|
|
371094
|
+
if ((typescript_1.default.isBlock(current) || typescript_1.default.isModuleBlock(current) || typescript_1.default.isCaseClause(current) || typescript_1.default.isDefaultClause(current)) && blockBindingNames(current).has(identifier.text)) {
|
|
371095
|
+
return true;
|
|
371096
|
+
}
|
|
371097
|
+
current = current.parent;
|
|
371098
|
+
}
|
|
371099
|
+
const rootParameters = functionLikeParameters(root);
|
|
371100
|
+
return Boolean(rootParameters?.some((parameter) => bindingNames(parameter.name).includes(identifier.text)));
|
|
371101
|
+
}
|
|
371102
|
+
function functionLikeParameters(node) {
|
|
371103
|
+
if (typescript_1.default.isFunctionDeclaration(node) || typescript_1.default.isFunctionExpression(node) || typescript_1.default.isArrowFunction(node) || typescript_1.default.isMethodDeclaration(node) || typescript_1.default.isGetAccessorDeclaration(node) || typescript_1.default.isSetAccessorDeclaration(node) || typescript_1.default.isConstructorDeclaration(node)) {
|
|
371104
|
+
return [...node.parameters];
|
|
371105
|
+
}
|
|
371106
|
+
return void 0;
|
|
370118
371107
|
}
|
|
370119
371108
|
function nodeContains(root, node) {
|
|
370120
371109
|
const sourceFile = root.getSourceFile();
|
|
@@ -370402,6 +371391,14 @@ var require_extract3 = __commonJS({
|
|
|
370402
371391
|
const printer = typescript_1.default.createPrinter({ removeComments: false });
|
|
370403
371392
|
return sourceFile.statements.map((statement) => printer.printNode(typescript_1.default.EmitHint.Unspecified, statement, sourceFileForNode(statement) ?? sourceFile)).join("\n\n");
|
|
370404
371393
|
}
|
|
371394
|
+
function printExpression(expression, sourceFile) {
|
|
371395
|
+
const printer = typescript_1.default.createPrinter({ removeComments: false });
|
|
371396
|
+
return printer.printNode(typescript_1.default.EmitHint.Expression, expression, sourceFileForNode(expression) ?? sourceFile);
|
|
371397
|
+
}
|
|
371398
|
+
function printStatement(statement, sourceFile) {
|
|
371399
|
+
const printer = typescript_1.default.createPrinter({ removeComments: false });
|
|
371400
|
+
return printer.printNode(typescript_1.default.EmitHint.Unspecified, statement, sourceFileForNode(statement) ?? sourceFile);
|
|
371401
|
+
}
|
|
370405
371402
|
function sourceFileForNode(node) {
|
|
370406
371403
|
return node.getSourceFile() ?? typescript_1.default.getOriginalNode(node)?.getSourceFile();
|
|
370407
371404
|
}
|
|
@@ -370534,155 +371531,6 @@ ${code}`;
|
|
|
370534
371531
|
}
|
|
370535
371532
|
});
|
|
370536
371533
|
|
|
370537
|
-
// ../../packages/workflow-code/dist/compiler/refs.js
|
|
370538
|
-
var require_refs = __commonJS({
|
|
370539
|
-
"../../packages/workflow-code/dist/compiler/refs.js"(exports2) {
|
|
370540
|
-
"use strict";
|
|
370541
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
370542
|
-
exports2.resolvePromptRefs = resolvePromptRefs;
|
|
370543
|
-
exports2.resolveReferenceRecordRefs = resolveReferenceRecordRefs;
|
|
370544
|
-
exports2.resolveWorkflowRef = resolveWorkflowRef;
|
|
370545
|
-
exports2.resolveExclusiveRef = resolveExclusiveRef;
|
|
370546
|
-
exports2.resolveVisibleNodeIdentity = resolveVisibleNodeIdentity;
|
|
370547
|
-
var workflow_shared_1 = require_cjs2();
|
|
370548
|
-
function resolvePromptRefs(context) {
|
|
370549
|
-
const diagnostics = [];
|
|
370550
|
-
let prompt = context.prompt;
|
|
370551
|
-
for (const ref of context.refs) {
|
|
370552
|
-
const resolved = resolveWorkflowRef(ref, context);
|
|
370553
|
-
diagnostics.push(...resolved.diagnostics);
|
|
370554
|
-
if (!resolved.reference)
|
|
370555
|
-
continue;
|
|
370556
|
-
prompt = prompt.split(ref.token).join(resolved.reference);
|
|
370557
|
-
}
|
|
370558
|
-
return { prompt, diagnostics };
|
|
370559
|
-
}
|
|
370560
|
-
function resolveReferenceRecordRefs(context) {
|
|
370561
|
-
const diagnostics = [];
|
|
370562
|
-
const values = { ...context.values };
|
|
370563
|
-
for (const ref of context.refs) {
|
|
370564
|
-
const resolved = resolveWorkflowRef(ref, context);
|
|
370565
|
-
if (resolved.reference) {
|
|
370566
|
-
values[ref.key] = resolved.reference;
|
|
370567
|
-
continue;
|
|
370568
|
-
}
|
|
370569
|
-
diagnostics.push(...resolved.diagnostics.map((diagnostic) => ({
|
|
370570
|
-
...diagnostic,
|
|
370571
|
-
message: diagnostic.message.replace("Prompt reference", `Reference record ${ref.key} reference`)
|
|
370572
|
-
})));
|
|
370573
|
-
}
|
|
370574
|
-
return { values: Object.freeze(values), diagnostics };
|
|
370575
|
-
}
|
|
370576
|
-
function resolveWorkflowRef(ref, context) {
|
|
370577
|
-
const resolved = ref.targetKind === "input" ? resolveInputRef(ref, context) : resolveNodeRef(ref, context);
|
|
370578
|
-
if (!resolved) {
|
|
370579
|
-
return {
|
|
370580
|
-
diagnostics: [{
|
|
370581
|
-
code: "compiler.ref.dangling",
|
|
370582
|
-
severity: "error",
|
|
370583
|
-
message: `Prompt reference ${ref.targetKey} does not match a workflow input or previous node`
|
|
370584
|
-
}]
|
|
370585
|
-
};
|
|
370586
|
-
}
|
|
370587
|
-
if (resolved === "forward") {
|
|
370588
|
-
return {
|
|
370589
|
-
diagnostics: [{
|
|
370590
|
-
code: "compiler.ref.forward",
|
|
370591
|
-
severity: "error",
|
|
370592
|
-
message: `Prompt reference ${ref.targetKey} points to a future workflow node`
|
|
370593
|
-
}]
|
|
370594
|
-
};
|
|
370595
|
-
}
|
|
370596
|
-
if (resolved === "scope") {
|
|
370597
|
-
return {
|
|
370598
|
-
diagnostics: [{
|
|
370599
|
-
code: "compiler.ref.scope",
|
|
370600
|
-
severity: "error",
|
|
370601
|
-
message: `Prompt reference ${ref.targetKey} points to a workflow node outside the visible scope`
|
|
370602
|
-
}]
|
|
370603
|
-
};
|
|
370604
|
-
}
|
|
370605
|
-
return {
|
|
370606
|
-
reference: resolved.reference,
|
|
370607
|
-
inputType: "inputType" in resolved ? resolved.inputType : void 0,
|
|
370608
|
-
nodeId: "nodeId" in resolved ? resolved.nodeId : void 0,
|
|
370609
|
-
diagnostics: []
|
|
370610
|
-
};
|
|
370611
|
-
}
|
|
370612
|
-
function resolveExclusiveRef(ref, context) {
|
|
370613
|
-
const resolved = resolveWorkflowRef(ref, context);
|
|
370614
|
-
if (resolved.reference)
|
|
370615
|
-
return resolved;
|
|
370616
|
-
return {
|
|
370617
|
-
diagnostics: resolved.diagnostics.map((diagnostic) => ({
|
|
370618
|
-
...diagnostic,
|
|
370619
|
-
message: diagnostic.message.replace("Prompt reference", "Exclusive reference")
|
|
370620
|
-
}))
|
|
370621
|
-
};
|
|
370622
|
-
}
|
|
370623
|
-
function resolveInputRef(ref, context) {
|
|
370624
|
-
const id = context.inputIdsByKey.get(ref.targetKey);
|
|
370625
|
-
if (!id)
|
|
370626
|
-
return void 0;
|
|
370627
|
-
const reference = workflow_shared_1.InputReferenceURI.fromVariable({ name: id });
|
|
370628
|
-
return {
|
|
370629
|
-
reference: formatPromptReference(reference, ref),
|
|
370630
|
-
inputType: context.inputTypesByKey?.get(ref.targetKey)
|
|
370631
|
-
};
|
|
370632
|
-
}
|
|
370633
|
-
function resolveNodeRef(ref, context) {
|
|
370634
|
-
const candidates = context.nodeIdentitiesByKey.get(ref.targetKey) ?? [];
|
|
370635
|
-
if (candidates.length === 0)
|
|
370636
|
-
return void 0;
|
|
370637
|
-
const visible = resolveVisibleNodeIdentity(ref.targetKey, context);
|
|
370638
|
-
if (visible) {
|
|
370639
|
-
const reference = workflow_shared_1.ActionOutputReferenceURI.fromStepId(visible.id);
|
|
370640
|
-
return { reference: formatPromptReference(reference, ref), nodeId: visible.id };
|
|
370641
|
-
}
|
|
370642
|
-
if (candidates.some((candidate) => samePath(candidate.scopePath, context.currentNode.scopePath) && candidate.sequenceIndex >= context.currentNode.sequenceIndex)) {
|
|
370643
|
-
return "forward";
|
|
370644
|
-
}
|
|
370645
|
-
return "scope";
|
|
370646
|
-
}
|
|
370647
|
-
function resolveVisibleNodeIdentity(key, context) {
|
|
370648
|
-
const currentScopeCandidate = resolvePriorCandidateInScope(key, context.currentNode.scopePath, context.currentNode.sequenceIndex, context);
|
|
370649
|
-
if (currentScopeCandidate)
|
|
370650
|
-
return currentScopeCandidate;
|
|
370651
|
-
for (const ancestorMapPath of [...context.currentNode.ancestorMapPaths].reverse()) {
|
|
370652
|
-
const ancestorMap = context.nodesByPath.get(pathKey(ancestorMapPath));
|
|
370653
|
-
if (!ancestorMap)
|
|
370654
|
-
continue;
|
|
370655
|
-
const candidate = resolvePriorCandidateInScope(key, ancestorMap.scopePath, ancestorMap.sequenceIndex, context);
|
|
370656
|
-
if (candidate)
|
|
370657
|
-
return candidate;
|
|
370658
|
-
}
|
|
370659
|
-
return void 0;
|
|
370660
|
-
}
|
|
370661
|
-
function resolvePriorCandidateInScope(key, scopePath, beforeSequenceIndex, context) {
|
|
370662
|
-
const candidates = (context.nodeIdentitiesByKey.get(key) ?? []).filter((candidate) => samePath(candidate.scopePath, scopePath) && candidate.sequenceIndex < beforeSequenceIndex).sort((left, right) => right.sequenceIndex - left.sequenceIndex);
|
|
370663
|
-
const nearest = candidates[0];
|
|
370664
|
-
if (!nearest)
|
|
370665
|
-
return void 0;
|
|
370666
|
-
if (candidates.filter((candidate) => candidate.sequenceIndex === nearest.sequenceIndex).length > 1)
|
|
370667
|
-
return void 0;
|
|
370668
|
-
return nearest;
|
|
370669
|
-
}
|
|
370670
|
-
function samePath(left, right) {
|
|
370671
|
-
return left.length === right.length && left.every((segment, index) => segment === right[index]);
|
|
370672
|
-
}
|
|
370673
|
-
function pathKey(path3) {
|
|
370674
|
-
return path3.join(".");
|
|
370675
|
-
}
|
|
370676
|
-
function formatPromptReference(reference, ref) {
|
|
370677
|
-
if (ref.path && ref.path.length > 0)
|
|
370678
|
-
reference.appendPath([...ref.path]);
|
|
370679
|
-
if ("format" in ref && ref.format)
|
|
370680
|
-
reference.setFormat(ref.format);
|
|
370681
|
-
return reference.toReference();
|
|
370682
|
-
}
|
|
370683
|
-
}
|
|
370684
|
-
});
|
|
370685
|
-
|
|
370686
371534
|
// ../../packages/workflow-code/dist/compiler/modules.js
|
|
370687
371535
|
var require_modules = __commonJS({
|
|
370688
371536
|
"../../packages/workflow-code/dist/compiler/modules.js"(exports2) {
|
|
@@ -370692,6 +371540,7 @@ var require_modules = __commonJS({
|
|
|
370692
371540
|
var contracts_1 = require_contracts();
|
|
370693
371541
|
var workflow_shared_1 = require_cjs2();
|
|
370694
371542
|
var remote_1 = require_remote();
|
|
371543
|
+
var condition_provenance_1 = require_condition_provenance();
|
|
370695
371544
|
var reference_1 = require_reference();
|
|
370696
371545
|
var asset_1 = require_asset();
|
|
370697
371546
|
var extract_1 = require_extract3();
|
|
@@ -370769,6 +371618,42 @@ var require_modules = __commonJS({
|
|
|
370769
371618
|
output: (0, ids_1.defaultOutputPortId)(nodeId)
|
|
370770
371619
|
};
|
|
370771
371620
|
}
|
|
371621
|
+
var stopModule = {
|
|
371622
|
+
kind: "stop",
|
|
371623
|
+
actionId: workflow_shared_1.WORKFLOW_ACTION_IDS.stop,
|
|
371624
|
+
createFailedInput() {
|
|
371625
|
+
return null;
|
|
371626
|
+
},
|
|
371627
|
+
validate(node) {
|
|
371628
|
+
return hasValidStopDeclaration(node) ? [] : [invalidStopInputDiagnostic(node)];
|
|
371629
|
+
},
|
|
371630
|
+
lower(node, context) {
|
|
371631
|
+
if (!hasValidStopDeclaration(node))
|
|
371632
|
+
return void 0;
|
|
371633
|
+
const input = (0, ids_1.defaultInputPortId)(context.nodeId);
|
|
371634
|
+
return {
|
|
371635
|
+
node: {
|
|
371636
|
+
id: context.nodeId,
|
|
371637
|
+
name: node.name,
|
|
371638
|
+
actionId: workflow_shared_1.WORKFLOW_ACTION_IDS.stop,
|
|
371639
|
+
ports: [{ id: input, dir: "in", type: "default" }],
|
|
371640
|
+
input: null
|
|
371641
|
+
},
|
|
371642
|
+
linearPorts: { input },
|
|
371643
|
+
terminal: true
|
|
371644
|
+
};
|
|
371645
|
+
}
|
|
371646
|
+
};
|
|
371647
|
+
function hasValidStopDeclaration(node) {
|
|
371648
|
+
return Boolean(node) && typeof node === "object" && node.kind === "node" && node.nodeKind === "stop" && node.name === "Stop" && node.key === void 0 && node.input === null;
|
|
371649
|
+
}
|
|
371650
|
+
function invalidStopInputDiagnostic(node) {
|
|
371651
|
+
return {
|
|
371652
|
+
code: "compiler.module.invalid_input",
|
|
371653
|
+
severity: "error",
|
|
371654
|
+
message: `Node ${node.name || "<unnamed>"} has invalid stop declaration`
|
|
371655
|
+
};
|
|
371656
|
+
}
|
|
370772
371657
|
function collectRemoteInputFacts(values, refs, context) {
|
|
370773
371658
|
const refsByInputName = new Map((refs ?? []).map((ref) => [ref.key, ref]));
|
|
370774
371659
|
const inputsByKey = new Map(context.builtInputs.map((input) => [input.key ?? input.name, input]));
|
|
@@ -370945,6 +371830,171 @@ var require_modules = __commonJS({
|
|
|
370945
371830
|
message: `Map node ${nodeName || "<unnamed>"}: ${message}`
|
|
370946
371831
|
};
|
|
370947
371832
|
}
|
|
371833
|
+
function hasValidConditionInput(node) {
|
|
371834
|
+
if (!node || node.nodeKind !== "condition")
|
|
371835
|
+
return false;
|
|
371836
|
+
if (node.kind !== "node" || node.name !== "Condition" || "key" in node)
|
|
371837
|
+
return false;
|
|
371838
|
+
const input = node.input;
|
|
371839
|
+
if (!input || typeof input !== "object")
|
|
371840
|
+
return false;
|
|
371841
|
+
const cases = input.cases;
|
|
371842
|
+
const defaultBranch = input.default;
|
|
371843
|
+
return Array.isArray(cases) && cases.every((branch) => branch && typeof branch === "object" && typeof branch.name === "string" && branch.name.trim().length > 0 && Array.isArray(branch.nodes)) && (defaultBranch === void 0 || Boolean(defaultBranch && typeof defaultBranch === "object" && Array.isArray(defaultBranch.nodes)));
|
|
371844
|
+
}
|
|
371845
|
+
function validateConditionBinding(node) {
|
|
371846
|
+
const binding = node[contracts_1.CONDITION_BINDING];
|
|
371847
|
+
if (!isConditionBindingObject(binding)) {
|
|
371848
|
+
return [{
|
|
371849
|
+
code: "condition.source.missing_handler_binding",
|
|
371850
|
+
severity: "error",
|
|
371851
|
+
message: "Condition node is missing predicate binding"
|
|
371852
|
+
}];
|
|
371853
|
+
}
|
|
371854
|
+
const diagnostics = [];
|
|
371855
|
+
if (!(0, condition_provenance_1.isTrustedConditionBinding)(node, binding)) {
|
|
371856
|
+
diagnostics.push({
|
|
371857
|
+
code: "condition.source.untrusted_binding",
|
|
371858
|
+
severity: "error",
|
|
371859
|
+
message: "Condition node predicate binding was not produced by Workflow Code authoring evaluation"
|
|
371860
|
+
});
|
|
371861
|
+
}
|
|
371862
|
+
const caseNames = new Set(node.input.cases.map((branch) => branch.name));
|
|
371863
|
+
const handlerNames = Object.keys(binding.handlers);
|
|
371864
|
+
for (const branch of node.input.cases) {
|
|
371865
|
+
if (!hasOwnFunctionProperty(binding.handlers, branch.name)) {
|
|
371866
|
+
diagnostics.push({
|
|
371867
|
+
code: "condition.source.missing_handler_binding",
|
|
371868
|
+
severity: "error",
|
|
371869
|
+
message: `Condition case "${branch.name}" is missing predicate handler binding`
|
|
371870
|
+
});
|
|
371871
|
+
}
|
|
371872
|
+
}
|
|
371873
|
+
for (const handlerName of handlerNames) {
|
|
371874
|
+
if (!caseNames.has(handlerName)) {
|
|
371875
|
+
diagnostics.push({
|
|
371876
|
+
code: "condition.source.missing_handler_binding",
|
|
371877
|
+
severity: "error",
|
|
371878
|
+
message: `Condition predicate handler binding "${handlerName}" does not match a declared case`
|
|
371879
|
+
});
|
|
371880
|
+
}
|
|
371881
|
+
}
|
|
371882
|
+
if (binding.source !== void 0 && !isWorkflowCodeSourceMarker(binding.source)) {
|
|
371883
|
+
diagnostics.push({
|
|
371884
|
+
code: "condition.source.missing_handler",
|
|
371885
|
+
severity: "error",
|
|
371886
|
+
message: "Condition node has invalid source marker metadata"
|
|
371887
|
+
});
|
|
371888
|
+
}
|
|
371889
|
+
return diagnostics;
|
|
371890
|
+
}
|
|
371891
|
+
function isConditionBindingObject(value) {
|
|
371892
|
+
if (!value || typeof value !== "object")
|
|
371893
|
+
return false;
|
|
371894
|
+
const handlers = value.handlers;
|
|
371895
|
+
const source = value.source;
|
|
371896
|
+
return Boolean(handlers) && typeof handlers === "object" && !Array.isArray(handlers) && (source === void 0 || isWorkflowCodeSourceMarker(source));
|
|
371897
|
+
}
|
|
371898
|
+
function isWorkflowCodeSourceMarker(value) {
|
|
371899
|
+
return Boolean(value) && typeof value === "object" && typeof value.file === "string" && typeof value.pos === "number" && Number.isInteger(value.pos) && value.pos >= 0 && typeof value.end === "number" && Number.isInteger(value.end) && value.end >= value.pos;
|
|
371900
|
+
}
|
|
371901
|
+
function hasOwnFunctionProperty(value, property) {
|
|
371902
|
+
return Object.prototype.hasOwnProperty.call(value, property) && typeof value[property] === "function";
|
|
371903
|
+
}
|
|
371904
|
+
function invalidConditionInputDiagnostic(node) {
|
|
371905
|
+
return {
|
|
371906
|
+
code: "compiler.module.invalid_input",
|
|
371907
|
+
severity: "error",
|
|
371908
|
+
message: `Node ${node.name || "<unnamed>"} has invalid condition input`
|
|
371909
|
+
};
|
|
371910
|
+
}
|
|
371911
|
+
function guardConditionExpression(expression) {
|
|
371912
|
+
return `(() => {
|
|
371913
|
+
const value = (${expression})
|
|
371914
|
+
if (value !== null
|
|
371915
|
+
&& (typeof value === 'object' || typeof value === 'function')
|
|
371916
|
+
&& typeof value.then === 'function')
|
|
371917
|
+
throw new TypeError('Workflow Code condition predicate returned a thenable')
|
|
371918
|
+
if (typeof value !== 'boolean')
|
|
371919
|
+
throw new TypeError('Workflow Code condition predicate must return a boolean')
|
|
371920
|
+
return value
|
|
371921
|
+
})()`;
|
|
371922
|
+
}
|
|
371923
|
+
var conditionModule = {
|
|
371924
|
+
kind: "condition",
|
|
371925
|
+
actionId: workflow_shared_1.WORKFLOW_ACTION_IDS.condition,
|
|
371926
|
+
createFailedInput() {
|
|
371927
|
+
return { cases: [] };
|
|
371928
|
+
},
|
|
371929
|
+
validate(node) {
|
|
371930
|
+
const diagnostics = hasValidConditionInput(node) ? [] : [invalidConditionInputDiagnostic(node)];
|
|
371931
|
+
if (hasValidConditionInput(node)) {
|
|
371932
|
+
diagnostics.push(...validateConditionBinding(node));
|
|
371933
|
+
const branchCount = node.input.cases.length + (node.input.default ? 1 : 0);
|
|
371934
|
+
if (branchCount < 2 || node.input.cases.length === 1 && !node.input.default)
|
|
371935
|
+
diagnostics.push({ code: "compiler.condition.invalid_cardinality", severity: "error", message: "Condition requires at least two branches; one named case requires default" });
|
|
371936
|
+
}
|
|
371937
|
+
return diagnostics;
|
|
371938
|
+
},
|
|
371939
|
+
lower(node, context) {
|
|
371940
|
+
if (!hasValidConditionInput(node))
|
|
371941
|
+
return void 0;
|
|
371942
|
+
const extractedCases = node.input.cases.map((branch) => ({
|
|
371943
|
+
branch,
|
|
371944
|
+
extracted: (0, extract_1.extractConditionExpression)({
|
|
371945
|
+
node,
|
|
371946
|
+
caseName: branch.name,
|
|
371947
|
+
source: context.source,
|
|
371948
|
+
buildSource: context.buildSource,
|
|
371949
|
+
builtInputs: context.builtInputs,
|
|
371950
|
+
builtNodes: context.builtNodes,
|
|
371951
|
+
currentNodeIndex: context.nodeIndex,
|
|
371952
|
+
nodeIdentitiesByKey: context.nodeIdentitiesByKey,
|
|
371953
|
+
currentNode: context.currentNode,
|
|
371954
|
+
inputNamesByKey: context.inputNamesByKey,
|
|
371955
|
+
nodeNamesByKey: context.nodeNamesByKey,
|
|
371956
|
+
nodeIndexesByKey: context.nodeIndexesByKey
|
|
371957
|
+
})
|
|
371958
|
+
}));
|
|
371959
|
+
context.diagnostics.push(...extractedCases.flatMap((item) => item.extracted.diagnostics));
|
|
371960
|
+
if (extractedCases.some((item) => item.extracted.expression === void 0 || item.extracted.diagnostics.some((diagnostic) => diagnostic.severity === "error"))) {
|
|
371961
|
+
return void 0;
|
|
371962
|
+
}
|
|
371963
|
+
const cases = extractedCases.map(({ branch, extracted }) => ({
|
|
371964
|
+
branch,
|
|
371965
|
+
expression: guardConditionExpression(extracted.expression ?? "")
|
|
371966
|
+
}));
|
|
371967
|
+
const inputPort = (0, ids_1.defaultInputPortId)(context.nodeId);
|
|
371968
|
+
const branchPorts = node.input.cases.map((_2, index) => (0, ids_1.branchOutputPortId)(context.nodeId, index));
|
|
371969
|
+
const defaultPort = node.input.default ? (0, ids_1.branchOutputPortId)(context.nodeId, node.input.cases.length) : void 0;
|
|
371970
|
+
return {
|
|
371971
|
+
node: {
|
|
371972
|
+
id: context.nodeId,
|
|
371973
|
+
name: node.name,
|
|
371974
|
+
actionId: workflow_shared_1.WORKFLOW_ACTION_IDS.condition,
|
|
371975
|
+
ports: [
|
|
371976
|
+
{ id: inputPort, dir: "in", type: "default" },
|
|
371977
|
+
...branchPorts.map((id) => ({ id, dir: "out", type: "branch" })),
|
|
371978
|
+
...defaultPort ? [{ id: defaultPort, dir: "out", type: "branch" }] : []
|
|
371979
|
+
],
|
|
371980
|
+
input: {
|
|
371981
|
+
cases: cases.map(({ branch, expression }, index) => ({
|
|
371982
|
+
name: branch.name,
|
|
371983
|
+
condition: expression,
|
|
371984
|
+
steps: [],
|
|
371985
|
+
type: "code",
|
|
371986
|
+
portId: branchPorts[index]
|
|
371987
|
+
})),
|
|
371988
|
+
...node.input.default && defaultPort ? {
|
|
371989
|
+
default: { name: "Default", condition: null, steps: [], type: "code", portId: defaultPort }
|
|
371990
|
+
} : {}
|
|
371991
|
+
}
|
|
371992
|
+
},
|
|
371993
|
+
linearPorts: { input: inputPort, output: "" },
|
|
371994
|
+
branchOutputPorts: Object.freeze([...branchPorts, ...defaultPort ? [defaultPort] : []])
|
|
371995
|
+
};
|
|
371996
|
+
}
|
|
371997
|
+
};
|
|
370948
371998
|
var codeModule = {
|
|
370949
371999
|
kind: "code",
|
|
370950
372000
|
actionId: workflow_shared_1.WORKFLOW_ACTION_IDS.codeExecution,
|
|
@@ -370973,6 +372023,8 @@ var require_modules = __commonJS({
|
|
|
370973
372023
|
builtInputs: context.builtInputs,
|
|
370974
372024
|
builtNodes: context.builtNodes,
|
|
370975
372025
|
currentNodeIndex: context.nodeIndex,
|
|
372026
|
+
nodeIdentitiesByKey: context.nodeIdentitiesByKey,
|
|
372027
|
+
currentNode: context.currentNode,
|
|
370976
372028
|
inputNamesByKey: context.inputNamesByKey,
|
|
370977
372029
|
nodeNamesByKey: context.nodeNamesByKey,
|
|
370978
372030
|
nodeIdsByKey: context.nodeIdsByKey,
|
|
@@ -371497,9 +372549,7 @@ var require_modules = __commonJS({
|
|
|
371497
372549
|
}
|
|
371498
372550
|
function resolveVisibleNodeOutput(targetKey, context) {
|
|
371499
372551
|
const identity2 = (0, refs_1.resolveVisibleNodeIdentity)(targetKey, {
|
|
371500
|
-
inputIdsByKey: context.inputIdsByKey,
|
|
371501
372552
|
nodeIdentitiesByKey: context.nodeIdentitiesByKey,
|
|
371502
|
-
nodesByPath: context.nodesByPath,
|
|
371503
372553
|
currentNode: context.currentNode
|
|
371504
372554
|
});
|
|
371505
372555
|
if (!identity2)
|
|
@@ -371730,6 +372780,8 @@ var require_modules = __commonJS({
|
|
|
371730
372780
|
[remoteAgentModule.kind, remoteAgentModule],
|
|
371731
372781
|
[remoteTemplateModule.kind, remoteTemplateModule],
|
|
371732
372782
|
[codeModule.kind, codeModule],
|
|
372783
|
+
[conditionModule.kind, conditionModule],
|
|
372784
|
+
[stopModule.kind, stopModule],
|
|
371733
372785
|
[mapModule.kind, mapModule],
|
|
371734
372786
|
[splitterModule.kind, splitterModule],
|
|
371735
372787
|
[cropModule.kind, cropModule],
|
|
@@ -371747,20 +372799,64 @@ var require_validation = __commonJS({
|
|
|
371747
372799
|
var modules_1 = require_modules();
|
|
371748
372800
|
function validateDeclaration(declaration) {
|
|
371749
372801
|
const nodes = flattenValidationNodes(declaration.nodes);
|
|
372802
|
+
const stopPlacementDiagnostics = [];
|
|
372803
|
+
validateStopPlacement(declaration.nodes, { directConditionBranch: false, insideMapBody: false }, stopPlacementDiagnostics);
|
|
371750
372804
|
return [
|
|
371751
372805
|
...validateWorkflowIdentity(declaration),
|
|
371752
372806
|
...validateInputIdentities(declaration.inputs),
|
|
371753
372807
|
...validateNodeIdentities(declaration.nodes),
|
|
371754
|
-
...validateModuleInputs(nodes)
|
|
372808
|
+
...validateModuleInputs(nodes),
|
|
372809
|
+
...stopPlacementDiagnostics
|
|
371755
372810
|
];
|
|
371756
372811
|
}
|
|
371757
372812
|
function flattenValidationNodes(nodes) {
|
|
371758
372813
|
return nodes.flatMap((node) => {
|
|
371759
|
-
if (!isNodeLike(node)
|
|
372814
|
+
if (!isNodeLike(node))
|
|
372815
|
+
return [node];
|
|
372816
|
+
if (node.nodeKind === "condition") {
|
|
372817
|
+
const input = node.input;
|
|
372818
|
+
const cases = Array.isArray(input?.cases) ? input.cases : [];
|
|
372819
|
+
const defaultBranch = input?.default && typeof input.default === "object" && Array.isArray(input.default.nodes) ? input.default : void 0;
|
|
372820
|
+
return [node, ...cases.flatMap((branch) => {
|
|
372821
|
+
if (!branch || typeof branch !== "object" || !Array.isArray(branch.nodes))
|
|
372822
|
+
return [];
|
|
372823
|
+
return flattenValidationNodes(branch.nodes);
|
|
372824
|
+
}), ...defaultBranch ? flattenValidationNodes(defaultBranch.nodes) : []];
|
|
372825
|
+
}
|
|
372826
|
+
if (node.nodeKind !== "map" || !Array.isArray(node.nodes))
|
|
371760
372827
|
return [node];
|
|
371761
372828
|
return [node, ...flattenValidationNodes(node.nodes)];
|
|
371762
372829
|
});
|
|
371763
372830
|
}
|
|
372831
|
+
function validateStopPlacement(nodes, context, diagnostics) {
|
|
372832
|
+
nodes.forEach((node, index) => {
|
|
372833
|
+
if (!isNodeLike(node))
|
|
372834
|
+
return;
|
|
372835
|
+
const nodeContext = {
|
|
372836
|
+
...context,
|
|
372837
|
+
isFinalDirectNode: index === nodes.length - 1
|
|
372838
|
+
};
|
|
372839
|
+
if (node.nodeKind === "stop" && (!nodeContext.directConditionBranch || !nodeContext.isFinalDirectNode || nodeContext.insideMapBody)) {
|
|
372840
|
+
diagnostics.push({
|
|
372841
|
+
code: "compiler.stop.invalid_placement",
|
|
372842
|
+
severity: "error",
|
|
372843
|
+
message: "stop() is allowed only as the final direct node of a condition branch"
|
|
372844
|
+
});
|
|
372845
|
+
}
|
|
372846
|
+
if (node.nodeKind === "map" && Array.isArray(node.nodes))
|
|
372847
|
+
validateStopPlacement(node.nodes, { directConditionBranch: false, insideMapBody: true }, diagnostics);
|
|
372848
|
+
if (node.nodeKind === "condition") {
|
|
372849
|
+
const input = node.input;
|
|
372850
|
+
const cases = Array.isArray(input?.cases) ? input.cases : [];
|
|
372851
|
+
for (const branch of cases) {
|
|
372852
|
+
if (branch && typeof branch === "object" && Array.isArray(branch.nodes))
|
|
372853
|
+
validateStopPlacement(branch.nodes, { directConditionBranch: true, insideMapBody: context.insideMapBody }, diagnostics);
|
|
372854
|
+
}
|
|
372855
|
+
if (input?.default && typeof input.default === "object" && Array.isArray(input.default.nodes))
|
|
372856
|
+
validateStopPlacement(input.default.nodes, { directConditionBranch: true, insideMapBody: context.insideMapBody }, diagnostics);
|
|
372857
|
+
}
|
|
372858
|
+
});
|
|
372859
|
+
}
|
|
371764
372860
|
function validateWorkflowIdentity(declaration) {
|
|
371765
372861
|
if (typeof declaration.workflow.workflowKey === "string" && declaration.workflow.workflowKey.trim().length > 0)
|
|
371766
372862
|
return [];
|
|
@@ -371787,6 +372883,7 @@ var require_validation = __commonJS({
|
|
|
371787
372883
|
}
|
|
371788
372884
|
function validateNodeIdentities(nodes, scopePath = []) {
|
|
371789
372885
|
const validNodes = nodes.filter(isNodeLike);
|
|
372886
|
+
const authoredIdentityNodes = validNodes.filter((node) => !isCompilerOwnedTopologyNode(node));
|
|
371790
372887
|
const scopeLabel = scopePath.length > 0 ? `workflow node at ${scopePath.join(".")}` : "workflow node";
|
|
371791
372888
|
return [
|
|
371792
372889
|
...nodes.filter((node) => !isNodeLike(node)).map(() => ({
|
|
@@ -371794,14 +372891,33 @@ var require_validation = __commonJS({
|
|
|
371794
372891
|
severity: "error",
|
|
371795
372892
|
message: `${scopeLabel} must be an object declaration`
|
|
371796
372893
|
})),
|
|
371797
|
-
...findEmpty(
|
|
371798
|
-
...findEmpty(
|
|
371799
|
-
...findDuplicates(
|
|
371800
|
-
...findDuplicates(
|
|
371801
|
-
...findDuplicates(
|
|
371802
|
-
...validNodes.flatMap((node, index) =>
|
|
372894
|
+
...findEmpty(authoredIdentityNodes.map((node) => node.name), "compiler.node.invalid_name", `${scopeLabel} name`),
|
|
372895
|
+
...findEmpty(authoredIdentityNodes.flatMap((node) => node.key !== void 0 ? [node.key] : []), "compiler.node.invalid_name", `${scopeLabel} key`),
|
|
372896
|
+
...findDuplicates(authoredIdentityNodes.map((node) => node.name), "compiler.node.duplicate_name", `${scopeLabel} name`),
|
|
372897
|
+
...findDuplicates(authoredIdentityNodes.flatMap((node) => node.key !== void 0 ? [node.key] : []), "compiler.node.duplicate_name", `${scopeLabel} key`),
|
|
372898
|
+
...findDuplicates(authoredIdentityNodes.map((node) => node.key ?? node.name), "compiler.node.duplicate_name", `${scopeLabel} effective identity`),
|
|
372899
|
+
...validNodes.flatMap((node, index) => nestedIdentityScopes(node, [...scopePath, index]))
|
|
371803
372900
|
];
|
|
371804
372901
|
}
|
|
372902
|
+
function isCompilerOwnedTopologyNode(node) {
|
|
372903
|
+
return node.nodeKind === "condition" || node.nodeKind === "stop";
|
|
372904
|
+
}
|
|
372905
|
+
function nestedIdentityScopes(node, path3) {
|
|
372906
|
+
if (node.nodeKind === "map" && Array.isArray(node.nodes))
|
|
372907
|
+
return validateNodeIdentities(node.nodes, path3);
|
|
372908
|
+
if (node.nodeKind !== "condition")
|
|
372909
|
+
return [];
|
|
372910
|
+
const input = node.input;
|
|
372911
|
+
const cases = Array.isArray(input?.cases) ? input.cases : [];
|
|
372912
|
+
const branchDiagnostics = cases.flatMap((branch, branchIndex) => {
|
|
372913
|
+
if (!branch || typeof branch !== "object" || !Array.isArray(branch.nodes))
|
|
372914
|
+
return [];
|
|
372915
|
+
return validateNodeIdentities(branch.nodes, [...path3, branchIndex]);
|
|
372916
|
+
});
|
|
372917
|
+
const defaultIndex = cases.length;
|
|
372918
|
+
const defaultDiagnostics = input?.default && typeof input.default === "object" && Array.isArray(input.default.nodes) ? validateNodeIdentities(input.default.nodes, [...path3, defaultIndex]) : [];
|
|
372919
|
+
return [...branchDiagnostics, ...defaultDiagnostics];
|
|
372920
|
+
}
|
|
371805
372921
|
function validateModuleInputs(nodes) {
|
|
371806
372922
|
const diagnostics = [];
|
|
371807
372923
|
for (const node of nodes) {
|
|
@@ -371875,24 +372991,69 @@ var require_transpile = __commonJS({
|
|
|
371875
372991
|
}
|
|
371876
372992
|
function createTopologyEdges(records, loweredByPath) {
|
|
371877
372993
|
const edges = [];
|
|
371878
|
-
function lowerSequence(sequence) {
|
|
371879
|
-
|
|
371880
|
-
|
|
371881
|
-
const
|
|
371882
|
-
if (!
|
|
372994
|
+
function lowerSequence(sequence, continuation) {
|
|
372995
|
+
let pendingTails = [];
|
|
372996
|
+
for (let index = 0; index < sequence.length; index++) {
|
|
372997
|
+
const record2 = sequence[index];
|
|
372998
|
+
if (!record2)
|
|
371883
372999
|
continue;
|
|
371884
|
-
edges.push(createEdge(source.node.id, source.linearPorts.output, target.node.id, target.linearPorts.input));
|
|
371885
|
-
}
|
|
371886
|
-
for (const record2 of sequence) {
|
|
371887
373000
|
const lowered = loweredByPath.get(pathKey(record2.path));
|
|
373001
|
+
if (!lowered) {
|
|
373002
|
+
pendingTails = [];
|
|
373003
|
+
continue;
|
|
373004
|
+
}
|
|
373005
|
+
if (lowered.linearPorts)
|
|
373006
|
+
connectTails(pendingTails, lowered.node.id, lowered.linearPorts.input);
|
|
373007
|
+
if (lowered.branchOutputPorts)
|
|
373008
|
+
pendingTails = lowerConditionBranches(record2, lowered);
|
|
373009
|
+
else if (lowered.terminal)
|
|
373010
|
+
pendingTails = [];
|
|
373011
|
+
else if (lowered.linearPorts?.output)
|
|
373012
|
+
pendingTails = [{ nodeId: lowered.node.id, outputPortId: lowered.linearPorts.output }];
|
|
373013
|
+
else
|
|
373014
|
+
pendingTails = [];
|
|
373015
|
+
const next = sequence[index + 1] ?? continuation;
|
|
373016
|
+
const loweredNext = next ? loweredByPath.get(pathKey(next.path)) : void 0;
|
|
373017
|
+
if (loweredNext?.linearPorts) {
|
|
373018
|
+
connectTails(pendingTails, loweredNext.node.id, loweredNext.linearPorts.input);
|
|
373019
|
+
pendingTails = [];
|
|
373020
|
+
} else if (next) {
|
|
373021
|
+
pendingTails = [];
|
|
373022
|
+
}
|
|
371888
373023
|
const root = record2.children[0];
|
|
371889
373024
|
const loweredRoot = root ? loweredByPath.get(pathKey(root.path)) : void 0;
|
|
371890
|
-
if (lowered
|
|
373025
|
+
if (lowered.subgraphOutputPort && loweredRoot?.linearPorts) {
|
|
371891
373026
|
edges.push(createEdge(lowered.node.id, lowered.subgraphOutputPort, loweredRoot.node.id, loweredRoot.linearPorts.input));
|
|
371892
373027
|
}
|
|
371893
373028
|
if (record2.children.length > 0)
|
|
371894
373029
|
lowerSequence(record2.children);
|
|
371895
373030
|
}
|
|
373031
|
+
const loweredContinuation = continuation ? loweredByPath.get(pathKey(continuation.path)) : void 0;
|
|
373032
|
+
if (loweredContinuation?.linearPorts)
|
|
373033
|
+
connectTails(pendingTails, loweredContinuation.node.id, loweredContinuation.linearPorts.input);
|
|
373034
|
+
return pendingTails;
|
|
373035
|
+
}
|
|
373036
|
+
function lowerConditionBranches(record2, lowered) {
|
|
373037
|
+
const tails = [];
|
|
373038
|
+
for (const branch of record2.branches) {
|
|
373039
|
+
const port = lowered.branchOutputPorts?.[branch.portIndex];
|
|
373040
|
+
if (!port)
|
|
373041
|
+
continue;
|
|
373042
|
+
const branchRoot = branch.records[0];
|
|
373043
|
+
const loweredBranchRoot = branchRoot ? loweredByPath.get(pathKey(branchRoot.path)) : void 0;
|
|
373044
|
+
if (branchRoot && loweredBranchRoot?.linearPorts) {
|
|
373045
|
+
edges.push(createEdge(lowered.node.id, port, loweredBranchRoot.node.id, loweredBranchRoot.linearPorts.input));
|
|
373046
|
+
tails.push(...lowerSequence(branch.records));
|
|
373047
|
+
continue;
|
|
373048
|
+
}
|
|
373049
|
+
if (!branchRoot)
|
|
373050
|
+
tails.push({ nodeId: lowered.node.id, outputPortId: port });
|
|
373051
|
+
}
|
|
373052
|
+
return tails;
|
|
373053
|
+
}
|
|
373054
|
+
function connectTails(tails, targetId, targetPortId) {
|
|
373055
|
+
for (const tail of tails)
|
|
373056
|
+
edges.push(createEdge(tail.nodeId, tail.outputPortId, targetId, targetPortId));
|
|
371896
373057
|
}
|
|
371897
373058
|
lowerSequence(records);
|
|
371898
373059
|
return edges;
|
|
@@ -371923,6 +373084,10 @@ var require_transpile = __commonJS({
|
|
|
371923
373084
|
return createFailedCodeNode(workflowKey, declaration);
|
|
371924
373085
|
if (declaration.node.nodeKind === "map")
|
|
371925
373086
|
return createFailedMapNode(workflowKey, declaration);
|
|
373087
|
+
if (declaration.node.nodeKind === "condition")
|
|
373088
|
+
return createFailedConditionNode(workflowKey, declaration);
|
|
373089
|
+
if (declaration.node.nodeKind === "stop")
|
|
373090
|
+
return createFailedStopNode(workflowKey, declaration);
|
|
371926
373091
|
if (declaration.node.nodeKind === "splitter")
|
|
371927
373092
|
return createFailedSplitterNode(workflowKey, declaration);
|
|
371928
373093
|
if (declaration.node.nodeKind === "crop")
|
|
@@ -371952,6 +373117,47 @@ var require_transpile = __commonJS({
|
|
|
371952
373117
|
}
|
|
371953
373118
|
};
|
|
371954
373119
|
}
|
|
373120
|
+
function createFailedStopNode(workflowKey, declaration) {
|
|
373121
|
+
const nodeId = (0, ids_1.stableNodeId)(workflowKey, declaration.node, declaration.path);
|
|
373122
|
+
const linearPorts = failedNodePorts(nodeId);
|
|
373123
|
+
return {
|
|
373124
|
+
declarationIndex: declaration.ordinal,
|
|
373125
|
+
path: declaration.path,
|
|
373126
|
+
scopePath: declaration.scopePath,
|
|
373127
|
+
sequenceIndex: declaration.sequenceIndex,
|
|
373128
|
+
linearPorts,
|
|
373129
|
+
node: {
|
|
373130
|
+
id: nodeId,
|
|
373131
|
+
name: declaration.node.name,
|
|
373132
|
+
actionId: workflow_shared_1.WORKFLOW_ACTION_IDS.codeExecution,
|
|
373133
|
+
ports: workflowNodePorts(linearPorts),
|
|
373134
|
+
input: {
|
|
373135
|
+
code: "export async function execute(): Promise<never> {\n throw new Error('Workflow Code compilation failed for this stop node. Check compiler diagnostics before syncing this workflow.')\n}\n",
|
|
373136
|
+
language: "typescript",
|
|
373137
|
+
libraries: []
|
|
373138
|
+
}
|
|
373139
|
+
}
|
|
373140
|
+
};
|
|
373141
|
+
}
|
|
373142
|
+
function createFailedConditionNode(workflowKey, declaration) {
|
|
373143
|
+
const nodeId = (0, ids_1.stableNodeId)(workflowKey, declaration.node, declaration.path);
|
|
373144
|
+
const inputPort = (0, ids_1.defaultInputPortId)(nodeId);
|
|
373145
|
+
return {
|
|
373146
|
+
declarationIndex: declaration.ordinal,
|
|
373147
|
+
path: declaration.path,
|
|
373148
|
+
scopePath: declaration.scopePath,
|
|
373149
|
+
sequenceIndex: declaration.sequenceIndex,
|
|
373150
|
+
linearPorts: { input: inputPort, output: "" },
|
|
373151
|
+
branchOutputPorts: Object.freeze([]),
|
|
373152
|
+
node: {
|
|
373153
|
+
id: nodeId,
|
|
373154
|
+
name: declaration.node.name,
|
|
373155
|
+
actionId: workflow_shared_1.WORKFLOW_ACTION_IDS.condition,
|
|
373156
|
+
ports: [{ id: inputPort, dir: "in", type: "default" }],
|
|
373157
|
+
input: { cases: [] }
|
|
373158
|
+
}
|
|
373159
|
+
};
|
|
373160
|
+
}
|
|
371955
373161
|
function createFailedRemoteNode(workflowKey, declaration) {
|
|
371956
373162
|
const nodeId = (0, ids_1.stableNodeId)(workflowKey, declaration.node, declaration.path);
|
|
371957
373163
|
const linearPorts = failedNodePorts(nodeId);
|
|
@@ -372103,12 +373309,14 @@ var require_transpile = __commonJS({
|
|
|
372103
373309
|
{ id: linearPorts.output, dir: "out", type: "default" }
|
|
372104
373310
|
];
|
|
372105
373311
|
}
|
|
372106
|
-
function createNodeRecords(nodes, scopePath = [], ancestorMapPaths = [], ordinalOffset = { value: 0 }) {
|
|
373312
|
+
function createNodeRecords(nodes, scopePath = [], ancestorMapPaths = [], ancestorScopes = [], ordinalOffset = { value: 0 }) {
|
|
372107
373313
|
const records = [];
|
|
372108
373314
|
nodes.forEach((node, sequenceIndex) => {
|
|
372109
373315
|
const path3 = [...scopePath, sequenceIndex];
|
|
372110
373316
|
const ordinal = ordinalOffset.value++;
|
|
372111
|
-
const
|
|
373317
|
+
const boundary = { scopePath, sequenceIndex };
|
|
373318
|
+
const children = node.nodeKind === "map" && Array.isArray(node.nodes) ? createNodeRecords(node.nodes.filter(isNodeLike), path3, [...ancestorMapPaths, path3], [...ancestorScopes, boundary], ordinalOffset) : [];
|
|
373319
|
+
const branches = isValidConditionBranchContainer(node) ? createConditionBranchRecords(node, path3, ancestorMapPaths, [...ancestorScopes, boundary], ordinalOffset) : [];
|
|
372112
373320
|
records.push({
|
|
372113
373321
|
node,
|
|
372114
373322
|
path: path3,
|
|
@@ -372116,18 +373324,43 @@ var require_transpile = __commonJS({
|
|
|
372116
373324
|
sequenceIndex,
|
|
372117
373325
|
ordinal,
|
|
372118
373326
|
ancestorMapPaths,
|
|
372119
|
-
|
|
373327
|
+
ancestorScopes,
|
|
373328
|
+
children,
|
|
373329
|
+
branches
|
|
372120
373330
|
});
|
|
372121
373331
|
});
|
|
372122
373332
|
return records;
|
|
372123
373333
|
}
|
|
373334
|
+
function isValidConditionBranchContainer(node) {
|
|
373335
|
+
return node.nodeKind === "condition" && Boolean(node.input) && typeof node.input === "object" && Array.isArray(node.input.cases) && node.input.cases.every(isConditionBranchShape) && (node.input.default === void 0 || isConditionDefaultShape(node.input.default));
|
|
373336
|
+
}
|
|
373337
|
+
function isConditionBranchShape(branch) {
|
|
373338
|
+
return Boolean(branch) && typeof branch === "object" && typeof branch.name === "string" && Array.isArray(branch.nodes);
|
|
373339
|
+
}
|
|
373340
|
+
function isConditionDefaultShape(branch) {
|
|
373341
|
+
return Boolean(branch) && typeof branch === "object" && Array.isArray(branch.nodes);
|
|
373342
|
+
}
|
|
373343
|
+
function createConditionBranchRecords(node, conditionPath, ancestorMapPaths, ancestorScopes, ordinalOffset) {
|
|
373344
|
+
const records = node.input.cases.map((branch, branchIndex) => ({
|
|
373345
|
+
name: branch.name,
|
|
373346
|
+
portIndex: branchIndex,
|
|
373347
|
+
records: createNodeRecords(branch.nodes.filter(isNodeLike), [...conditionPath, branchIndex], ancestorMapPaths, ancestorScopes, ordinalOffset)
|
|
373348
|
+
}));
|
|
373349
|
+
if (!node.input.default)
|
|
373350
|
+
return records;
|
|
373351
|
+
return [...records, {
|
|
373352
|
+
name: "Default",
|
|
373353
|
+
portIndex: node.input.cases.length,
|
|
373354
|
+
records: createNodeRecords(node.input.default.nodes.filter(isNodeLike), [...conditionPath, node.input.cases.length], ancestorMapPaths, ancestorScopes, ordinalOffset)
|
|
373355
|
+
}];
|
|
373356
|
+
}
|
|
372124
373357
|
function flattenRecords(records) {
|
|
372125
|
-
return records.flatMap((record2) => [record2, ...flattenRecords(record2.children)]);
|
|
373358
|
+
return records.flatMap((record2) => [record2, ...flattenRecords(record2.children), ...record2.branches.flatMap((branch) => flattenRecords(branch.records))]);
|
|
372126
373359
|
}
|
|
372127
373360
|
function validateMapTopology(nodes) {
|
|
372128
373361
|
const diagnostics = [];
|
|
372129
373362
|
for (const item of nodes) {
|
|
372130
|
-
if (item.
|
|
373363
|
+
if (item.ancestorMapPaths.length === 0)
|
|
372131
373364
|
continue;
|
|
372132
373365
|
if (item.node.nodeKind === "code") {
|
|
372133
373366
|
diagnostics.push({
|
|
@@ -372140,7 +373373,7 @@ var require_transpile = __commonJS({
|
|
|
372140
373373
|
return diagnostics;
|
|
372141
373374
|
}
|
|
372142
373375
|
function isUnsupportedMapBodyNode(item) {
|
|
372143
|
-
return item.
|
|
373376
|
+
return item.ancestorMapPaths.length > 0 && item.node.nodeKind === "code";
|
|
372144
373377
|
}
|
|
372145
373378
|
function createChildNodeIdsByParentId(workflowKey, nodes) {
|
|
372146
373379
|
const ids = /* @__PURE__ */ new Map();
|
|
@@ -372160,6 +373393,23 @@ var require_transpile = __commonJS({
|
|
|
372160
373393
|
function createLoweredByPath(nodes) {
|
|
372161
373394
|
return new Map(nodes.map((node) => [pathKey(node.path), node]));
|
|
372162
373395
|
}
|
|
373396
|
+
function collectInvalidStopPlacementPathKeys(records) {
|
|
373397
|
+
const invalid = /* @__PURE__ */ new Set();
|
|
373398
|
+
function visit(sequence, context) {
|
|
373399
|
+
sequence.forEach((record2, index) => {
|
|
373400
|
+
const isFinalDirectNode = index === sequence.length - 1;
|
|
373401
|
+
if (record2.node.nodeKind === "stop" && (!context.directConditionBranch || !isFinalDirectNode || context.insideMapBody)) {
|
|
373402
|
+
invalid.add(pathKey(record2.path));
|
|
373403
|
+
}
|
|
373404
|
+
if (record2.children.length > 0)
|
|
373405
|
+
visit(record2.children, { directConditionBranch: false, insideMapBody: true });
|
|
373406
|
+
for (const branch of record2.branches)
|
|
373407
|
+
visit(branch.records, { directConditionBranch: true, insideMapBody: context.insideMapBody });
|
|
373408
|
+
});
|
|
373409
|
+
}
|
|
373410
|
+
visit(records, { directConditionBranch: false, insideMapBody: false });
|
|
373411
|
+
return invalid;
|
|
373412
|
+
}
|
|
372163
373413
|
function createScopedIdentities(workflowKey, records) {
|
|
372164
373414
|
const nodesByPath = /* @__PURE__ */ new Map();
|
|
372165
373415
|
const identitiesByKey = /* @__PURE__ */ new Map();
|
|
@@ -372167,13 +373417,17 @@ var require_transpile = __commonJS({
|
|
|
372167
373417
|
const key = record2.node.key ?? record2.node.name;
|
|
372168
373418
|
const identity2 = {
|
|
372169
373419
|
key,
|
|
373420
|
+
runtimeName: record2.node.name,
|
|
372170
373421
|
id: (0, ids_1.stableNodeId)(workflowKey, record2.node, record2.path),
|
|
372171
373422
|
path: record2.path,
|
|
372172
373423
|
scopePath: record2.scopePath,
|
|
372173
373424
|
sequenceIndex: record2.sequenceIndex,
|
|
372174
|
-
ancestorMapPaths: record2.ancestorMapPaths
|
|
373425
|
+
ancestorMapPaths: record2.ancestorMapPaths,
|
|
373426
|
+
ancestorScopes: record2.ancestorScopes
|
|
372175
373427
|
};
|
|
372176
373428
|
nodesByPath.set(pathKey(record2.path), identity2);
|
|
373429
|
+
if (record2.node.nodeKind === "condition" || record2.node.nodeKind === "stop")
|
|
373430
|
+
continue;
|
|
372177
373431
|
const identities = identitiesByKey.get(key) ?? [];
|
|
372178
373432
|
identities.push(identity2);
|
|
372179
373433
|
identitiesByKey.set(key, identities);
|
|
@@ -372207,9 +373461,10 @@ var require_transpile = __commonJS({
|
|
|
372207
373461
|
});
|
|
372208
373462
|
const inputTypesByKey = new Map(declarationInputs.map((declaration) => [declaration.key ?? declaration.name, declaration.inputType]));
|
|
372209
373463
|
const topLevelNodes = flattenedNodes.filter((node) => node.scopePath.length === 0);
|
|
373464
|
+
const outputProducingTopLevelNodes = topLevelNodes.filter(({ node }) => node.nodeKind !== "condition" && node.nodeKind !== "stop");
|
|
372210
373465
|
const nodeIdsByKey = /* @__PURE__ */ new Map();
|
|
372211
373466
|
const nodeIndexesByKey = /* @__PURE__ */ new Map();
|
|
372212
|
-
|
|
373467
|
+
outputProducingTopLevelNodes.forEach(({ node, path: path3, ordinal }) => {
|
|
372213
373468
|
const key = node.key ?? node.name;
|
|
372214
373469
|
nodeIdsByKey.set(key, (0, ids_1.stableNodeId)(workflowKey, node, path3));
|
|
372215
373470
|
nodeIndexesByKey.set(key, ordinal);
|
|
@@ -372217,7 +373472,7 @@ var require_transpile = __commonJS({
|
|
|
372217
373472
|
const { nodesByPath, nodeIdentitiesByKey } = createScopedIdentities(workflowKey, flattenedNodes);
|
|
372218
373473
|
const nodeDeclarationsById = new Map(flattenedNodes.map(({ node, path: path3 }) => [(0, ids_1.stableNodeId)(workflowKey, node, path3), node]));
|
|
372219
373474
|
const inputNamesByKey = new Map(declarationInputs.map((declaration) => [declaration.key ?? declaration.name, declaration.name]));
|
|
372220
|
-
const nodeNamesByKey = new Map(
|
|
373475
|
+
const nodeNamesByKey = new Map(outputProducingTopLevelNodes.map(({ node }) => [node.key ?? node.name, node.name]));
|
|
372221
373476
|
const nodeOutputSchemasById = /* @__PURE__ */ new Map();
|
|
372222
373477
|
const remoteTemplateNodeIds = new Set(flattenedNodes.filter(({ node }) => node.nodeKind === "remote-template").map(({ node, path: path3 }) => (0, ids_1.stableNodeId)(workflowKey, node, path3)));
|
|
372223
373478
|
const buildBinding = input.declaration[contracts_1.BUILD_BINDING];
|
|
@@ -372229,10 +373484,13 @@ var require_transpile = __commonJS({
|
|
|
372229
373484
|
...declaration.description !== void 0 ? { description: declaration.description } : {}
|
|
372230
373485
|
}));
|
|
372231
373486
|
const childNodeIdsByParentId = createChildNodeIdsByParentId(workflowKey, flattenedNodes);
|
|
373487
|
+
const invalidStopPlacementPathKeys = collectInvalidStopPlacementPathKeys(rootRecords);
|
|
372232
373488
|
const loweredModuleNodesByDeclaration = flattenedNodes.map((flattened, index) => {
|
|
372233
373489
|
const { node } = flattened;
|
|
372234
373490
|
if (isUnsupportedMapBodyNode(flattened))
|
|
372235
373491
|
return void 0;
|
|
373492
|
+
if (node.nodeKind === "stop" && invalidStopPlacementPathKeys.has(pathKey(flattened.path)))
|
|
373493
|
+
return void 0;
|
|
372236
373494
|
const module3 = modules_1.nodeModuleRegistry.get(node.nodeKind);
|
|
372237
373495
|
if (!module3)
|
|
372238
373496
|
return void 0;
|
|
@@ -372246,11 +373504,13 @@ var require_transpile = __commonJS({
|
|
|
372246
373504
|
nodesByPath,
|
|
372247
373505
|
currentNode: nodesByPath.get(pathKey(flattened.path)) ?? {
|
|
372248
373506
|
key: node.key ?? node.name,
|
|
373507
|
+
runtimeName: node.name,
|
|
372249
373508
|
id: (0, ids_1.stableNodeId)(workflowKey, node, flattened.path),
|
|
372250
373509
|
path: flattened.path,
|
|
372251
373510
|
scopePath: flattened.scopePath,
|
|
372252
373511
|
sequenceIndex: flattened.sequenceIndex,
|
|
372253
|
-
ancestorMapPaths: flattened.ancestorMapPaths
|
|
373512
|
+
ancestorMapPaths: flattened.ancestorMapPaths,
|
|
373513
|
+
ancestorScopes: flattened.ancestorScopes
|
|
372254
373514
|
},
|
|
372255
373515
|
nodeIdsByKey,
|
|
372256
373516
|
nodeIndexesByKey,
|
|
@@ -372880,6 +374140,7 @@ var require_evaluate_source = __commonJS({
|
|
|
372880
374140
|
var node_path_1 = require("node:path");
|
|
372881
374141
|
var node_vm_1 = require("node:vm");
|
|
372882
374142
|
var typescript_1 = __importDefault(require_typescript3());
|
|
374143
|
+
var condition_provenance_1 = require_condition_provenance();
|
|
372883
374144
|
var hash_1 = require_hash();
|
|
372884
374145
|
var diagnostics_1 = require_diagnostics();
|
|
372885
374146
|
function evaluateWorkflowSource(entrypoint, compilerOptions = {}, sourceRoot = (0, node_path_1.dirname)((0, node_path_1.resolve)(entrypoint))) {
|
|
@@ -372930,10 +374191,12 @@ var require_evaluate_source = __commonJS({
|
|
|
372930
374191
|
includeSourceOnlyLocalModules(resolvedPath, content, files, compilerOptions, sourceRoot, /* @__PURE__ */ new Set([resolvedPath]));
|
|
372931
374192
|
let outputText;
|
|
372932
374193
|
let sourceMap;
|
|
374194
|
+
let trustedConditionSourceToken;
|
|
372933
374195
|
try {
|
|
372934
374196
|
const transpiled = transpileWorkflowSource(content, resolvedPath, compilerOptions, sourceRoot);
|
|
372935
374197
|
outputText = transpiled.outputText;
|
|
372936
374198
|
sourceMap = transpiled.sourceMap;
|
|
374199
|
+
trustedConditionSourceToken = transpiled.trustedConditionSourceToken;
|
|
372937
374200
|
} catch (error48) {
|
|
372938
374201
|
if (error48 instanceof SourceEvaluationError)
|
|
372939
374202
|
throw error48;
|
|
@@ -372987,7 +374250,9 @@ var require_evaluate_source = __commonJS({
|
|
|
372987
374250
|
exports: exports3,
|
|
372988
374251
|
module: module3,
|
|
372989
374252
|
process: createWorkflowProcessFacade(),
|
|
372990
|
-
__workflowCodeRandomUUID: node_crypto_1.randomUUID
|
|
374253
|
+
__workflowCodeRandomUUID: node_crypto_1.randomUUID,
|
|
374254
|
+
__workflowCodeTrustConditionBinding: condition_provenance_1.trustConditionBinding,
|
|
374255
|
+
__workflowCodeTrustedConditionSourceToken: trustedConditionSourceToken
|
|
372991
374256
|
});
|
|
372992
374257
|
new node_vm_1.Script(`${prelude}${outputText}`, { filename: resolvedPath }).runInNewContext(sandbox, {
|
|
372993
374258
|
contextCodeGeneration: { strings: false, wasm: false }
|
|
@@ -373071,6 +374336,7 @@ var require_evaluate_source = __commonJS({
|
|
|
373071
374336
|
return exportClause.elements.some((element) => element.isTypeOnly);
|
|
373072
374337
|
}
|
|
373073
374338
|
function transpileWorkflowSource(content, fileName, compilerOptions, sourceRoot) {
|
|
374339
|
+
const trustedConditionSourceToken = (0, node_crypto_1.randomUUID)();
|
|
373074
374340
|
const result = typescript_1.default.transpileModule(content, {
|
|
373075
374341
|
fileName,
|
|
373076
374342
|
compilerOptions: {
|
|
@@ -373084,15 +374350,16 @@ var require_evaluate_source = __commonJS({
|
|
|
373084
374350
|
target: typescript_1.default.ScriptTarget.ES2022
|
|
373085
374351
|
},
|
|
373086
374352
|
transformers: {
|
|
373087
|
-
before: [createWorkflowCodeSourceMarkerTransformer(fileName, compilerOptions, sourceRoot)]
|
|
374353
|
+
before: [createWorkflowCodeSourceMarkerTransformer(fileName, compilerOptions, sourceRoot, trustedConditionSourceToken)]
|
|
373088
374354
|
}
|
|
373089
374355
|
});
|
|
373090
374356
|
return {
|
|
373091
374357
|
outputText: result.outputText,
|
|
373092
|
-
sourceMap: parseWorkflowSourceMap(result.sourceMapText)
|
|
374358
|
+
sourceMap: parseWorkflowSourceMap(result.sourceMapText),
|
|
374359
|
+
trustedConditionSourceToken
|
|
373093
374360
|
};
|
|
373094
374361
|
}
|
|
373095
|
-
function createWorkflowCodeSourceMarkerTransformer(fileName, compilerOptions, sourceRoot) {
|
|
374362
|
+
function createWorkflowCodeSourceMarkerTransformer(fileName, compilerOptions, sourceRoot, trustedConditionSourceToken) {
|
|
373096
374363
|
return (context) => (root) => {
|
|
373097
374364
|
const sourceFile = root;
|
|
373098
374365
|
const baseBindings = collectWorkflowCodeImportBindings(root, fileName, compilerOptions, sourceRoot, createWorkflowCodeImportBindingContext());
|
|
@@ -373110,6 +374377,7 @@ var require_evaluate_source = __commonJS({
|
|
|
373110
374377
|
collectWorkflowCodeAliasBindings(node, node.statements, "llm", scopedBindings.promptNodeBindings, scopedBindings.promptNodeNamespaceBindings, scopedBindings.promptNodeNamespaceMemberBindings);
|
|
373111
374378
|
collectWorkflowCodeAliasBindings(node, node.statements, "map", scopedBindings.promptNodeBindings, scopedBindings.promptNodeNamespaceBindings, scopedBindings.promptNodeNamespaceMemberBindings);
|
|
373112
374379
|
collectWorkflowCodeAliasBindings(node, node.statements, "docTemplate", scopedBindings.promptNodeBindings, scopedBindings.promptNodeNamespaceBindings, scopedBindings.promptNodeNamespaceMemberBindings);
|
|
374380
|
+
collectWorkflowCodeAliasBindings(node, node.statements, "condition", scopedBindings.promptNodeBindings, scopedBindings.promptNodeNamespaceBindings, scopedBindings.promptNodeNamespaceMemberBindings);
|
|
373113
374381
|
return typescript_1.default.visitEachChild(node, createVisit(scopedBindings), context);
|
|
373114
374382
|
}
|
|
373115
374383
|
if (isForLikeStatement(node)) {
|
|
@@ -373118,9 +374386,8 @@ var require_evaluate_source = __commonJS({
|
|
|
373118
374386
|
}
|
|
373119
374387
|
if (typescript_1.default.isCallExpression(node) && isWorkflowBuildCallExpression(node.expression, bindings.buildBindings, bindings.buildNamespaceBindings, bindings.buildNamespaceMemberBindings)) {
|
|
373120
374388
|
const [workflowArg, optionsArg, ...rest] = node.arguments;
|
|
373121
|
-
if (workflowArg && optionsArg && typescript_1.default.isObjectLiteralExpression(optionsArg)
|
|
373122
|
-
const
|
|
373123
|
-
const updatedOptions = typescript_1.default.factory.updateObjectLiteralExpression(optionsArg, [...optionsArg.properties, marker]);
|
|
374389
|
+
if (workflowArg && optionsArg && typescript_1.default.isObjectLiteralExpression(optionsArg)) {
|
|
374390
|
+
const updatedOptions = withTrustedWorkflowCodeSourceMarker(optionsArg, createWorkflowCodeSourceMarker(fileName, node, root));
|
|
373124
374391
|
const updatedNode = typescript_1.default.factory.updateCallExpression(node, node.expression, node.typeArguments, [workflowArg, updatedOptions, ...rest]);
|
|
373125
374392
|
return typescript_1.default.visitEachChild(updatedNode, visit, context);
|
|
373126
374393
|
}
|
|
@@ -373132,12 +374399,8 @@ var require_evaluate_source = __commonJS({
|
|
|
373132
374399
|
if (typescript_1.default.isCallExpression(node) && isWorkflowCodeCallExpression(node.expression, bindings.codeBindings, bindings.codeNamespaceBindings, bindings.codeNamespaceMemberBindings)) {
|
|
373133
374400
|
const [firstArg, ...rest] = node.arguments;
|
|
373134
374401
|
if (firstArg && typescript_1.default.isObjectLiteralExpression(firstArg)) {
|
|
373135
|
-
|
|
373136
|
-
|
|
373137
|
-
const updatedArg = typescript_1.default.factory.updateObjectLiteralExpression(firstArg, [...firstArg.properties, marker]);
|
|
373138
|
-
return typescript_1.default.factory.updateCallExpression(node, node.expression, node.typeArguments, [updatedArg, ...rest]);
|
|
373139
|
-
}
|
|
373140
|
-
return node;
|
|
374402
|
+
const updatedArg = withTrustedWorkflowCodeSourceMarker(firstArg, createWorkflowCodeSourceMarker(fileName, node, root));
|
|
374403
|
+
return typescript_1.default.factory.updateCallExpression(node, node.expression, node.typeArguments, [updatedArg, ...rest]);
|
|
373141
374404
|
}
|
|
373142
374405
|
if (firstArg) {
|
|
373143
374406
|
const rejectedArg = typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("__workflowCodeRejectNonInlineCodeOptions"), void 0, [firstArg, createWorkflowCodeSourceMarker(fileName, node, root)]);
|
|
@@ -373146,11 +374409,17 @@ var require_evaluate_source = __commonJS({
|
|
|
373146
374409
|
}
|
|
373147
374410
|
if (typescript_1.default.isCallExpression(node) && isWorkflowPromptNodeCallExpression(node.expression, bindings.promptNodeBindings, bindings.promptNodeNamespaceBindings, bindings.promptNodeNamespaceMemberBindings)) {
|
|
373148
374411
|
const [firstArg, ...rest] = node.arguments;
|
|
373149
|
-
if (firstArg && typescript_1.default.isObjectLiteralExpression(firstArg)
|
|
373150
|
-
const
|
|
373151
|
-
const updatedArg = typescript_1.default.factory.updateObjectLiteralExpression(firstArg, [...firstArg.properties, marker]);
|
|
374412
|
+
if (firstArg && typescript_1.default.isObjectLiteralExpression(firstArg)) {
|
|
374413
|
+
const updatedArg = withTrustedWorkflowCodeSourceMarker(firstArg, createWorkflowCodeSourceMarker(fileName, node, sourceFile), trustedConditionSourceToken);
|
|
373152
374414
|
return typescript_1.default.factory.updateCallExpression(node, node.expression, node.typeArguments, [updatedArg, ...rest]);
|
|
373153
374415
|
}
|
|
374416
|
+
if (firstArg) {
|
|
374417
|
+
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("__workflowCodeCallPromptNodeWithTrustedSource"), void 0, [
|
|
374418
|
+
node.expression,
|
|
374419
|
+
typescript_1.default.factory.createArrayLiteralExpression(node.arguments),
|
|
374420
|
+
createWorkflowCodeSourceMarker(fileName, node, root)
|
|
374421
|
+
]);
|
|
374422
|
+
}
|
|
373154
374423
|
}
|
|
373155
374424
|
return typescript_1.default.visitEachChild(node, visit, context);
|
|
373156
374425
|
};
|
|
@@ -373246,8 +374515,18 @@ var require_evaluate_source = __commonJS({
|
|
|
373246
374515
|
bindings.promptNodeNamespaceBindings.delete(name);
|
|
373247
374516
|
bindings.promptNodeNamespaceMemberBindings.delete(name);
|
|
373248
374517
|
}
|
|
373249
|
-
function
|
|
373250
|
-
|
|
374518
|
+
function withTrustedWorkflowCodeSourceMarker(objectLiteral, markerValue, trustedConditionSourceToken) {
|
|
374519
|
+
const marker = typescript_1.default.factory.createPropertyAssignment("__workflowCodeSource", markerValue);
|
|
374520
|
+
return typescript_1.default.factory.updateObjectLiteralExpression(objectLiteral, [
|
|
374521
|
+
...objectLiteral.properties.filter((property) => !(typescript_1.default.isPropertyAssignment(property) && (getWorkflowCodePropertyName(property.name) === "__workflowCodeSource" || getWorkflowCodePropertyName(property.name) === "__workflowCodeTrustedConditionSourceToken"))),
|
|
374522
|
+
marker,
|
|
374523
|
+
...trustedConditionSourceToken === void 0 ? [] : [typescript_1.default.factory.createPropertyAssignment("__workflowCodeTrustedConditionSourceToken", typescript_1.default.factory.createStringLiteral(trustedConditionSourceToken))]
|
|
374524
|
+
]);
|
|
374525
|
+
}
|
|
374526
|
+
function getWorkflowCodePropertyName(name) {
|
|
374527
|
+
if (typescript_1.default.isIdentifier(name) || typescript_1.default.isStringLiteral(name) || typescript_1.default.isNumericLiteral(name))
|
|
374528
|
+
return name.text;
|
|
374529
|
+
return void 0;
|
|
373251
374530
|
}
|
|
373252
374531
|
function createWorkflowCodeSourceMarker(fileName, node, sourceFile) {
|
|
373253
374532
|
return typescript_1.default.factory.createObjectLiteralExpression([
|
|
@@ -373278,7 +374557,7 @@ var require_evaluate_source = __commonJS({
|
|
|
373278
374557
|
return Boolean(namespaceMemberBindings.get(root)?.has(members.join(".")));
|
|
373279
374558
|
}
|
|
373280
374559
|
function isPromptNodeMemberName(name) {
|
|
373281
|
-
return name === "agent" || name === "docTemplate" || name === "llm" || name === "map";
|
|
374560
|
+
return name === "agent" || name === "condition" || name === "docTemplate" || name === "llm" || name === "map";
|
|
373282
374561
|
}
|
|
373283
374562
|
function isWorkflowCodeMemberExpression(expression, memberName, memberBindings, namespaceBindings, namespaceMemberBindings) {
|
|
373284
374563
|
const unwrapped = unwrapExpression(expression);
|
|
@@ -373798,7 +375077,7 @@ var require_evaluate_source = __commonJS({
|
|
|
373798
375077
|
}
|
|
373799
375078
|
}
|
|
373800
375079
|
function addWorkflowCodePromptNodeMembersToExport(prefix, exportedNamespaces) {
|
|
373801
|
-
for (const memberName of ["agent", "llm", "map"])
|
|
375080
|
+
for (const memberName of ["agent", "condition", "llm", "map"])
|
|
373802
375081
|
exportedNamespaces.add(`${prefix}.${memberName}`);
|
|
373803
375082
|
}
|
|
373804
375083
|
function addWorkflowCodeNamespaceMembersToExport(members, prefix, exportedNamespaces) {
|
|
@@ -373884,7 +375163,7 @@ var require_evaluate_source = __commonJS({
|
|
|
373884
375163
|
exportedNames.codeNamespaces.add(statement.exportClause.name.text);
|
|
373885
375164
|
for (const exportedName of targetExports.codeNamespaces)
|
|
373886
375165
|
exportedNames.codeNamespaces.add(`${statement.exportClause.name.text}.${exportedName}`);
|
|
373887
|
-
for (const memberName of ["agent", "llm", "map"]) {
|
|
375166
|
+
for (const memberName of ["agent", "condition", "llm", "map"]) {
|
|
373888
375167
|
if (targetExports.promptNodes.has(memberName))
|
|
373889
375168
|
exportedNames.promptNodeNamespaces.add(`${statement.exportClause.name.text}.${memberName}`);
|
|
373890
375169
|
}
|
|
@@ -373915,6 +375194,7 @@ var require_evaluate_source = __commonJS({
|
|
|
373915
375194
|
exportedNames.code.add("code");
|
|
373916
375195
|
exportedNames.promptNodes.add("agent");
|
|
373917
375196
|
exportedNames.promptNodes.add("docTemplate");
|
|
375197
|
+
exportedNames.promptNodes.add("condition");
|
|
373918
375198
|
exportedNames.promptNodes.add("llm");
|
|
373919
375199
|
exportedNames.promptNodes.add("map");
|
|
373920
375200
|
return;
|
|
@@ -374086,12 +375366,17 @@ const __workflowCodeApi = (() => {
|
|
|
374086
375366
|
toString: () => registerRefUse(use, refs),
|
|
374087
375367
|
[Symbol.toPrimitive]: () => registerRefUse(use, refs),
|
|
374088
375368
|
})
|
|
375369
|
+
const assertOutputRefTarget = (target, source) => {
|
|
375370
|
+
if (target && target.kind === 'node' && (target.nodeKind === 'condition' || target.nodeKind === 'stop'))
|
|
375371
|
+
throwAuthoringDiagnostic(target.nodeKind + '() does not produce a workflow output reference', source)
|
|
375372
|
+
}
|
|
374089
375373
|
const renderPrompt = (input, source) => {
|
|
374090
375374
|
if (typeof input === 'string')
|
|
374091
375375
|
return freeze({ prompt: input, refs: freeze([]) })
|
|
374092
375376
|
const refs = []
|
|
374093
375377
|
const prompt = input(freeze({
|
|
374094
375378
|
ref(target, path) {
|
|
375379
|
+
assertOutputRefTarget(target, source)
|
|
374095
375380
|
const targetKey = target.key ?? target.name
|
|
374096
375381
|
if (path && (path.__workflowCodePathTargetKind !== target.kind || path.__workflowCodePathTargetKey !== targetKey))
|
|
374097
375382
|
throwAuthoringDiagnostic('ref path source must match ref target', source)
|
|
@@ -374102,7 +375387,7 @@ const __workflowCodeApi = (() => {
|
|
|
374102
375387
|
}
|
|
374103
375388
|
return createRefValue(use, refs)
|
|
374104
375389
|
},
|
|
374105
|
-
paths(target) { return createPathProxy([], target.kind, target.key ?? target.name) },
|
|
375390
|
+
paths(target) { assertOutputRefTarget(target, source); return createPathProxy([], target.kind, target.key ?? target.name) },
|
|
374106
375391
|
}))
|
|
374107
375392
|
if (typeof prompt !== 'string')
|
|
374108
375393
|
throwAuthoringDiagnostic('prompt callback must return a string', source)
|
|
@@ -374110,6 +375395,7 @@ const __workflowCodeApi = (() => {
|
|
|
374110
375395
|
}
|
|
374111
375396
|
const exclusiveRefContext = (source) => freeze({
|
|
374112
375397
|
ref(target, path) {
|
|
375398
|
+
assertOutputRefTarget(target, source)
|
|
374113
375399
|
const targetKey = target.key ?? target.name
|
|
374114
375400
|
if (path && (path.__workflowCodePathTargetKind !== target.kind || path.__workflowCodePathTargetKey !== targetKey))
|
|
374115
375401
|
throwAuthoringDiagnostic('ref path source must match ref target', source)
|
|
@@ -374120,7 +375406,7 @@ const __workflowCodeApi = (() => {
|
|
|
374120
375406
|
...(path ? { path: freeze([...path[pathKey]]) } : {}),
|
|
374121
375407
|
})
|
|
374122
375408
|
},
|
|
374123
|
-
paths(target) { return createPathProxy([], target.kind, target.key ?? target.name) },
|
|
375409
|
+
paths(target) { assertOutputRefTarget(target, source); return createPathProxy([], target.kind, target.key ?? target.name) },
|
|
374124
375410
|
})
|
|
374125
375411
|
const isVaultRef = (value) => value && typeof value === 'object' && !Array.isArray(value) && value.kind === 'vault-ref'
|
|
374126
375412
|
const isVaultAsset = (value) => value && typeof value === 'object' && !Array.isArray(value) && value.kind === 'vault-asset'
|
|
@@ -374139,12 +375425,13 @@ const __workflowCodeApi = (() => {
|
|
|
374139
375425
|
const refs = []
|
|
374140
375426
|
const record = input(freeze({
|
|
374141
375427
|
ref(target, path) {
|
|
375428
|
+
assertOutputRefTarget(target, source)
|
|
374142
375429
|
const targetKey = target.key ?? target.name
|
|
374143
375430
|
if (path && (path.__workflowCodePathTargetKind !== target.kind || path.__workflowCodePathTargetKey !== targetKey))
|
|
374144
375431
|
throwAuthoringDiagnostic('ref path source must match ref target', source)
|
|
374145
375432
|
return createRefValue({ targetKind: target.kind, targetKey, ...(path ? { path: path[pathKey] } : {}) }, refs)
|
|
374146
375433
|
},
|
|
374147
|
-
paths(target) { return createPathProxy([], target.kind, target.key ?? target.name) },
|
|
375434
|
+
paths(target) { assertOutputRefTarget(target, source); return createPathProxy([], target.kind, target.key ?? target.name) },
|
|
374148
375435
|
}))
|
|
374149
375436
|
if (!record || typeof record !== 'object' || Array.isArray(record))
|
|
374150
375437
|
throwAuthoringDiagnostic('reference record callback must return an object', source)
|
|
@@ -374281,6 +375568,11 @@ const __workflowCodeApi = (() => {
|
|
|
374281
375568
|
}
|
|
374282
375569
|
const buildBindingKey = Symbol.for('@meistrari/workflow-code/build-binding')
|
|
374283
375570
|
const codeBindingKey = Symbol.for('@meistrari/workflow-code/code-binding')
|
|
375571
|
+
const conditionBindingKey = Symbol.for('@meistrari/workflow-code/condition-binding')
|
|
375572
|
+
const trustConditionBinding = globalThis.__workflowCodeTrustConditionBinding
|
|
375573
|
+
delete globalThis.__workflowCodeTrustConditionBinding
|
|
375574
|
+
const trustedConditionSourceToken = globalThis.__workflowCodeTrustedConditionSourceToken
|
|
375575
|
+
delete globalThis.__workflowCodeTrustedConditionSourceToken
|
|
374284
375576
|
const buildWorkflow = (workflow, options) => {
|
|
374285
375577
|
if (options.input !== undefined && options.inputs !== undefined)
|
|
374286
375578
|
throwAuthoringDiagnostic('Use either input or inputs, not both.')
|
|
@@ -374297,6 +375589,7 @@ const __workflowCodeApi = (() => {
|
|
|
374297
375589
|
if (typeof input !== 'function') {
|
|
374298
375590
|
if (!input || typeof input !== 'object' || (input.kind !== 'input' && input.kind !== 'node'))
|
|
374299
375591
|
throwAuthoringDiagnostic(label + ' must return exactly one workflow reference', source)
|
|
375592
|
+
assertOutputRefTarget(input, source)
|
|
374300
375593
|
if (input.kind === 'input' && input.inputType !== 'file')
|
|
374301
375594
|
throwAuthoringDiagnostic(label + ' must reference a file input or node output', source)
|
|
374302
375595
|
return freeze({ token: '__workflow_code_ref_0__', targetKind: input.kind, targetKey: input.key ?? input.name })
|
|
@@ -374304,6 +375597,7 @@ const __workflowCodeApi = (() => {
|
|
|
374304
375597
|
const refs = []
|
|
374305
375598
|
const rendered = String(input(freeze({
|
|
374306
375599
|
ref(target, path) {
|
|
375600
|
+
assertOutputRefTarget(target, source)
|
|
374307
375601
|
if (target.kind === 'input' && target.inputType !== 'file')
|
|
374308
375602
|
throwAuthoringDiagnostic(label + ' must reference a file input or node output', source)
|
|
374309
375603
|
const targetKey = target.key ?? target.name
|
|
@@ -374316,7 +375610,7 @@ const __workflowCodeApi = (() => {
|
|
|
374316
375610
|
}
|
|
374317
375611
|
return createRefValue(use, refs)
|
|
374318
375612
|
},
|
|
374319
|
-
paths(target) { return createPathProxy([], target.kind, target.key ?? target.name) },
|
|
375613
|
+
paths(target) { assertOutputRefTarget(target, source); return createPathProxy([], target.kind, target.key ?? target.name) },
|
|
374320
375614
|
})))
|
|
374321
375615
|
const registered = refs[0]
|
|
374322
375616
|
if (refs.length !== 1 || !registered || rendered !== registered.token)
|
|
@@ -374373,6 +375667,58 @@ const __workflowCodeApi = (() => {
|
|
|
374373
375667
|
})
|
|
374374
375668
|
return freeze(declaration)
|
|
374375
375669
|
}
|
|
375670
|
+
const conditionNode = (options) => {
|
|
375671
|
+
if (!options || typeof options !== 'object')
|
|
375672
|
+
throwAuthoringDiagnostic('condition.options must be an object')
|
|
375673
|
+
if (!options.cases || typeof options.cases !== 'object' || Array.isArray(options.cases))
|
|
375674
|
+
throwAuthoringDiagnostic('condition.cases must be an object', options.__workflowCodeSource)
|
|
375675
|
+
const freezeNodes = (nodes, label) => {
|
|
375676
|
+
if (!Array.isArray(nodes))
|
|
375677
|
+
throwAuthoringDiagnostic(label + ' must be an array', options.__workflowCodeSource)
|
|
375678
|
+
return freeze([...nodes])
|
|
375679
|
+
}
|
|
375680
|
+
const cases = Object.entries(options.cases).map(([name, branch]) => {
|
|
375681
|
+
if (name.trim().length === 0)
|
|
375682
|
+
throwAuthoringDiagnostic('condition.case name must be non-empty', options.__workflowCodeSource)
|
|
375683
|
+
if (/^(?:0|[1-9]d*)$/u.test(name) && Number(name) < 2 ** 32 - 1)
|
|
375684
|
+
throwAuthoringDiagnostic('condition.case name must not be an array-index string', options.__workflowCodeSource)
|
|
375685
|
+
if (!branch || typeof branch !== 'object' || typeof branch.when !== 'function')
|
|
375686
|
+
throwAuthoringDiagnostic('condition.cases.' + name + '.when must be a function', options.__workflowCodeSource)
|
|
375687
|
+
return freeze({ name, nodes: freezeNodes(branch.nodes, 'condition.cases.' + name + '.nodes') })
|
|
375688
|
+
})
|
|
375689
|
+
const defaultBranch = options.default === undefined ? undefined : freeze({ nodes: freezeNodes(options.default.nodes, 'condition.default.nodes') })
|
|
375690
|
+
const branchCount = cases.length + (defaultBranch ? 1 : 0)
|
|
375691
|
+
if (branchCount < 2 || (cases.length === 1 && !defaultBranch))
|
|
375692
|
+
throwAuthoringDiagnostic('condition requires at least two branches; one named case requires default', options.__workflowCodeSource)
|
|
375693
|
+
const declaration = {
|
|
375694
|
+
kind: 'node',
|
|
375695
|
+
nodeKind: 'condition',
|
|
375696
|
+
name: 'Condition',
|
|
375697
|
+
input: freeze({
|
|
375698
|
+
cases: freeze(cases),
|
|
375699
|
+
...(defaultBranch ? { default: defaultBranch } : {}),
|
|
375700
|
+
}),
|
|
375701
|
+
}
|
|
375702
|
+
const binding = freeze({
|
|
375703
|
+
handlers: freeze(Object.fromEntries(Object.entries(options.cases).map(([name, branch]) => [name, branch.when]))),
|
|
375704
|
+
source: options.__workflowCodeSource,
|
|
375705
|
+
})
|
|
375706
|
+
Object.defineProperty(declaration, conditionBindingKey, {
|
|
375707
|
+
enumerable: false,
|
|
375708
|
+
configurable: false,
|
|
375709
|
+
writable: false,
|
|
375710
|
+
value: binding,
|
|
375711
|
+
})
|
|
375712
|
+
if (typeof trustConditionBinding === 'function' && options.__workflowCodeTrustedConditionSourceToken === trustedConditionSourceToken)
|
|
375713
|
+
trustConditionBinding(declaration, binding)
|
|
375714
|
+
return freeze(declaration)
|
|
375715
|
+
}
|
|
375716
|
+
const stopNode = () => freeze({
|
|
375717
|
+
kind: 'node',
|
|
375718
|
+
nodeKind: 'stop',
|
|
375719
|
+
name: 'Stop',
|
|
375720
|
+
input: null,
|
|
375721
|
+
})
|
|
374376
375722
|
const splitterNode = (options) => {
|
|
374377
375723
|
if (!options || typeof options !== 'object' || !options.input || typeof options.input !== 'object')
|
|
374378
375724
|
throwAuthoringDiagnostic('splitter.input must be an object', options && typeof options === 'object' ? options.__workflowCodeSource : undefined)
|
|
@@ -374447,11 +375793,13 @@ const __workflowCodeApi = (() => {
|
|
|
374447
375793
|
code: codeNode,
|
|
374448
375794
|
crop: cropNode,
|
|
374449
375795
|
docTemplate: docTemplateNode,
|
|
375796
|
+
condition: conditionNode,
|
|
374450
375797
|
input: freeze({ text: (options) => baseInput('text', options), file: (options) => baseInput('file', options) }),
|
|
374451
375798
|
llm: (options) => promptNode('llm', options, llmInput),
|
|
374452
375799
|
map: mapNode,
|
|
374453
375800
|
splitter: splitterNode,
|
|
374454
375801
|
template: templateNode,
|
|
375802
|
+
stop: stopNode,
|
|
374455
375803
|
vault: freeze({
|
|
374456
375804
|
asset: (path, options = {}) => freeze({
|
|
374457
375805
|
kind: 'vault-asset',
|
|
@@ -374477,6 +375825,7 @@ const __workflowCodePackageFacade = (() => {
|
|
|
374477
375825
|
const workflowCodeBindingKeys = new Set([
|
|
374478
375826
|
Symbol.for('@meistrari/workflow-code/code-binding'),
|
|
374479
375827
|
Symbol.for('@meistrari/workflow-code/build-binding'),
|
|
375828
|
+
Symbol.for('@meistrari/workflow-code/condition-binding'),
|
|
374480
375829
|
Symbol.for('@meistrari/workflow-code/remote-ref-binding'),
|
|
374481
375830
|
])
|
|
374482
375831
|
const cache = new WeakMap()
|
|
@@ -374606,6 +375955,33 @@ const __workflowCodeRejectNonInlineBuildOptions = (_options, source) => {
|
|
|
374606
375955
|
stack: new Error('Workflow Code build() calls must use an inline object literal options argument.').stack,
|
|
374607
375956
|
}))
|
|
374608
375957
|
}
|
|
375958
|
+
const __workflowCodeRejectNonInlineConditionOptions = (_options, source) => {
|
|
375959
|
+
throw Object.freeze(Object.assign(Object.create(null), {
|
|
375960
|
+
__workflowCodeSourceDiagnostic: true,
|
|
375961
|
+
code: 'condition.source.non_inline_options',
|
|
375962
|
+
message: 'Workflow Code condition() calls must use an inline object literal options argument.',
|
|
375963
|
+
hint: 'Use condition({ ... }) or wf.condition({ ... }) directly so Workflow Code can attach trusted predicate source at ' + source.file,
|
|
375964
|
+
stack: new Error('Workflow Code condition() calls must use an inline object literal options argument.').stack,
|
|
375965
|
+
}))
|
|
375966
|
+
}
|
|
375967
|
+
const __workflowCodeWithoutUserSourceMarker = (value) => {
|
|
375968
|
+
if (value === null || typeof value !== 'object' || !Object.prototype.hasOwnProperty.call(value, '__workflowCodeSource'))
|
|
375969
|
+
return value
|
|
375970
|
+
if (Array.isArray(value))
|
|
375971
|
+
return value.map(__workflowCodeWithoutUserSourceMarker)
|
|
375972
|
+
const clone = {}
|
|
375973
|
+
for (const key of Object.keys(value)) {
|
|
375974
|
+
if (key !== '__workflowCodeSource')
|
|
375975
|
+
clone[key] = value[key]
|
|
375976
|
+
}
|
|
375977
|
+
return clone
|
|
375978
|
+
}
|
|
375979
|
+
const __workflowCodeCallPromptNodeWithTrustedSource = (callee, args, source) => {
|
|
375980
|
+
const sanitizedArgs = Array.isArray(args) ? args.map(__workflowCodeWithoutUserSourceMarker) : []
|
|
375981
|
+
if (callee === __workflowCodeApi.condition)
|
|
375982
|
+
return __workflowCodeRejectNonInlineConditionOptions(sanitizedArgs[0], source)
|
|
375983
|
+
return callee(...sanitizedArgs)
|
|
375984
|
+
}
|
|
374609
375985
|
const require = ((hostRequire) => {
|
|
374610
375986
|
delete globalThis.__workflowCodeRequire
|
|
374611
375987
|
return (specifier) => {
|