@meistrari/tela-cli 1.3.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) {
|
|
@@ -368782,7 +368819,7 @@ var require_output_schema = __commonJS({
|
|
|
368782
368819
|
"../../packages/workflow-code/dist/compiler/output-schema.js"(exports2) {
|
|
368783
368820
|
"use strict";
|
|
368784
368821
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
368785
|
-
exports2.CROP_OUTPUT_JSON_SCHEMA = exports2.SPLITTER_OUTPUT_JSON_SCHEMA = exports2.FILE_INPUT_JSON_SCHEMA = exports2.FILE_OUTPUT_JSON_SCHEMA = void 0;
|
|
368822
|
+
exports2.DOC_TEMPLATE_OUTPUT_JSON_SCHEMA = exports2.CROP_OUTPUT_JSON_SCHEMA = exports2.SPLITTER_OUTPUT_JSON_SCHEMA = exports2.FILE_INPUT_JSON_SCHEMA = exports2.FILE_OUTPUT_JSON_SCHEMA = void 0;
|
|
368786
368823
|
exports2.createPromptOutputJsonSchema = createPromptOutputJsonSchema;
|
|
368787
368824
|
exports2.selectOutputJsonSchema = selectOutputJsonSchema;
|
|
368788
368825
|
exports2.isFileCompatibleOutputJsonSchema = isFileCompatibleOutputJsonSchema;
|
|
@@ -368834,6 +368871,17 @@ var require_output_schema = __commonJS({
|
|
|
368834
368871
|
required: Object.freeze(["indexes", "originalFile", "file"])
|
|
368835
368872
|
})
|
|
368836
368873
|
});
|
|
368874
|
+
exports2.DOC_TEMPLATE_OUTPUT_JSON_SCHEMA = Object.freeze({
|
|
368875
|
+
type: "object",
|
|
368876
|
+
properties: Object.freeze({
|
|
368877
|
+
generatedDocument: exports2.FILE_OUTPUT_JSON_SCHEMA,
|
|
368878
|
+
generatedAt: Object.freeze({ type: "string" }),
|
|
368879
|
+
permalinkUrl: Object.freeze({ type: "string" }),
|
|
368880
|
+
permalinkId: Object.freeze({ type: "string" }),
|
|
368881
|
+
permalinkExpiresAt: Object.freeze({ anyOf: Object.freeze([{ type: "string" }, { type: "null" }]) })
|
|
368882
|
+
}),
|
|
368883
|
+
required: Object.freeze(["generatedDocument", "generatedAt"])
|
|
368884
|
+
});
|
|
368837
368885
|
function createPromptOutputJsonSchema(schema) {
|
|
368838
368886
|
return schema === void 0 || schema === null ? void 0 : { type: "object", properties: schema };
|
|
368839
368887
|
}
|
|
@@ -369176,7 +369224,7 @@ var require_rewrite_refs = __commonJS({
|
|
|
369176
369224
|
const targetInfo = targetResolution.target;
|
|
369177
369225
|
const targetKey = targetInfo?.effectiveKey ?? target.text;
|
|
369178
369226
|
if (!targetInfo) {
|
|
369179
|
-
diagnostics.push(targetResolution
|
|
369227
|
+
diagnostics.push(unresolvedTargetDiagnostic(targetResolution, targetKey, context.nodeName));
|
|
369180
369228
|
return void 0;
|
|
369181
369229
|
}
|
|
369182
369230
|
if (targetInfo.nodeIndex !== void 0 && targetInfo.nodeIndex >= context.currentNodeIndex) {
|
|
@@ -369189,6 +369237,15 @@ var require_rewrite_refs = __commonJS({
|
|
|
369189
369237
|
expression = safeAccess(expression, segment);
|
|
369190
369238
|
return expression;
|
|
369191
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
|
+
}
|
|
369192
369249
|
function extractPath(node, expectedTarget, context, diagnostics) {
|
|
369193
369250
|
const segments = [];
|
|
369194
369251
|
let current = node;
|
|
@@ -369259,6 +369316,13 @@ var require_rewrite_refs = __commonJS({
|
|
|
369259
369316
|
hint: `Move "${targetKey}" before "${nodeName}" or remove the reference.`
|
|
369260
369317
|
};
|
|
369261
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
|
+
}
|
|
369262
369326
|
function unsupportedStandalonePaths(nodeName) {
|
|
369263
369327
|
return {
|
|
369264
369328
|
code: "code.ref.unsupported_paths",
|
|
@@ -369272,6 +369336,149 @@ var require_rewrite_refs = __commonJS({
|
|
|
369272
369336
|
}
|
|
369273
369337
|
});
|
|
369274
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
|
+
|
|
369275
369482
|
// ../../packages/workflow-code/dist/compiler/code-extraction/extract.js
|
|
369276
369483
|
var require_extract3 = __commonJS({
|
|
369277
369484
|
"../../packages/workflow-code/dist/compiler/code-extraction/extract.js"(exports2) {
|
|
@@ -369281,6 +369488,7 @@ var require_extract3 = __commonJS({
|
|
|
369281
369488
|
};
|
|
369282
369489
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
369283
369490
|
exports2.extractInlineCode = extractInlineCode;
|
|
369491
|
+
exports2.extractConditionExpression = extractConditionExpression;
|
|
369284
369492
|
exports2.resolveBuiltRefTargetResult = resolveBuiltRefTargetResult;
|
|
369285
369493
|
exports2.resolveIdentifierDeclarationWithChecker = resolveIdentifierDeclarationWithChecker;
|
|
369286
369494
|
var typescript_1 = __importDefault(require_typescript3());
|
|
@@ -369290,7 +369498,10 @@ var require_extract3 = __commonJS({
|
|
|
369290
369498
|
var program_1 = require_program();
|
|
369291
369499
|
var rewrite_refs_1 = require_rewrite_refs();
|
|
369292
369500
|
var output_schema_2 = require_output_schema();
|
|
369501
|
+
var refs_1 = require_refs();
|
|
369502
|
+
var condition_provenance_1 = require_condition_provenance();
|
|
369293
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"]);
|
|
369294
369505
|
function extractInlineCode(input) {
|
|
369295
369506
|
const binding = input.node[contracts_1.CODE_BINDING];
|
|
369296
369507
|
if (!binding) {
|
|
@@ -369356,7 +369567,9 @@ var require_extract3 = __commonJS({
|
|
|
369356
369567
|
nodeName: input.node.name,
|
|
369357
369568
|
inputNamesByKey: input.inputNamesByKey,
|
|
369358
369569
|
nodeNamesByKey: input.nodeNamesByKey,
|
|
369359
|
-
nodeIndexesByKey: input.nodeIndexesByKey
|
|
369570
|
+
nodeIndexesByKey: input.nodeIndexesByKey,
|
|
369571
|
+
nodeIdentitiesByKey: input.nodeIdentitiesByKey,
|
|
369572
|
+
currentNode: input.currentNode
|
|
369360
369573
|
});
|
|
369361
369574
|
if (rewritten.diagnostics.length > 0)
|
|
369362
369575
|
return { code: "", diagnostics: rewritten.diagnostics, preservedImports };
|
|
@@ -369369,6 +369582,92 @@ var require_extract3 = __commonJS({
|
|
|
369369
369582
|
preservedImports
|
|
369370
369583
|
};
|
|
369371
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
|
+
}
|
|
369372
369671
|
function createCodeInputSchemaBindings(input) {
|
|
369373
369672
|
const inputBindings = input.builtInputs.map((declaration) => ({
|
|
369374
369673
|
name: declaration.name,
|
|
@@ -369376,11 +369675,662 @@ var require_extract3 = __commonJS({
|
|
|
369376
369675
|
required: declaration.required
|
|
369377
369676
|
}));
|
|
369378
369677
|
const nodeBindings = input.builtNodes.slice(0, input.currentNodeIndex).flatMap((node) => {
|
|
369379
|
-
const
|
|
369678
|
+
const nodeId = input.nodeIdsByKey.get(node.key ?? node.name);
|
|
369679
|
+
const schema = nodeId === void 0 ? void 0 : input.nodeOutputSchemasById.get(nodeId);
|
|
369380
369680
|
return schema ? [{ name: node.name, schema, required: true }] : [];
|
|
369381
369681
|
});
|
|
369382
369682
|
return [...inputBindings, ...nodeBindings];
|
|
369383
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
|
+
}
|
|
369384
370334
|
function resolveHandler(call, sourceFile, checker) {
|
|
369385
370335
|
const handler = getHandlerExpression(call);
|
|
369386
370336
|
if (!handler)
|
|
@@ -369512,7 +370462,7 @@ var require_extract3 = __commonJS({
|
|
|
369512
370462
|
if (effectiveKey) {
|
|
369513
370463
|
const staticTarget = resolveBuiltRefTargetByEffectiveKey(effectiveKey, context);
|
|
369514
370464
|
if (staticTarget)
|
|
369515
|
-
return
|
|
370465
|
+
return staticTarget;
|
|
369516
370466
|
}
|
|
369517
370467
|
if (declaration)
|
|
369518
370468
|
return resolveBuiltRefTargetFromBuildArrays(identifier, declaration, checker, context);
|
|
@@ -369521,12 +370471,40 @@ var require_extract3 = __commonJS({
|
|
|
369521
370471
|
function resolveBuiltRefTargetByEffectiveKey(effectiveKey, context) {
|
|
369522
370472
|
const inputName = context.inputNamesByKey.get(effectiveKey);
|
|
369523
370473
|
if (inputName)
|
|
369524
|
-
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;
|
|
369525
370478
|
const nodeName = context.nodeNamesByKey.get(effectiveKey);
|
|
369526
370479
|
if (nodeName)
|
|
369527
|
-
return { kind: "node", effectiveKey, runtimeName: nodeName, nodeIndex: context.nodeIndexesByKey.get(effectiveKey) };
|
|
370480
|
+
return { target: { kind: "node", effectiveKey, runtimeName: nodeName, nodeIndex: context.nodeIndexesByKey.get(effectiveKey) } };
|
|
369528
370481
|
return void 0;
|
|
369529
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
|
+
}
|
|
369530
370508
|
function resolveBuiltRefTargetFromBuildArrays(identifier, declaration, checker, context) {
|
|
369531
370509
|
const candidates = [];
|
|
369532
370510
|
let unsupportedDynamicBuildArray = false;
|
|
@@ -369576,10 +370554,13 @@ var require_extract3 = __commonJS({
|
|
|
369576
370554
|
return false;
|
|
369577
370555
|
}
|
|
369578
370556
|
const builtNode = context.builtNodes[match];
|
|
369579
|
-
if (builtNode)
|
|
370557
|
+
if (builtNode && isOutputProducingNode(builtNode))
|
|
369580
370558
|
candidates.push({ kind: "node", effectiveKey: builtNode.key ?? builtNode.name, runtimeName: builtNode.name, nodeIndex: match });
|
|
369581
370559
|
return false;
|
|
369582
370560
|
}
|
|
370561
|
+
function isOutputProducingNode(node) {
|
|
370562
|
+
return node.nodeKind !== "condition" && node.nodeKind !== "stop";
|
|
370563
|
+
}
|
|
369583
370564
|
function uniqueBuiltRefTarget(candidates) {
|
|
369584
370565
|
if (candidates.length === 0)
|
|
369585
370566
|
return void 0;
|
|
@@ -370102,7 +371083,27 @@ var require_extract3 = __commonJS({
|
|
|
370102
371083
|
}
|
|
370103
371084
|
function isDeclaredInsideRoot(identifier, root, checker) {
|
|
370104
371085
|
const symbol3 = checker.getSymbolAtLocation(identifier);
|
|
370105
|
-
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;
|
|
370106
371107
|
}
|
|
370107
371108
|
function nodeContains(root, node) {
|
|
370108
371109
|
const sourceFile = root.getSourceFile();
|
|
@@ -370390,6 +371391,14 @@ var require_extract3 = __commonJS({
|
|
|
370390
371391
|
const printer = typescript_1.default.createPrinter({ removeComments: false });
|
|
370391
371392
|
return sourceFile.statements.map((statement) => printer.printNode(typescript_1.default.EmitHint.Unspecified, statement, sourceFileForNode(statement) ?? sourceFile)).join("\n\n");
|
|
370392
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
|
+
}
|
|
370393
371402
|
function sourceFileForNode(node) {
|
|
370394
371403
|
return node.getSourceFile() ?? typescript_1.default.getOriginalNode(node)?.getSourceFile();
|
|
370395
371404
|
}
|
|
@@ -370522,154 +371531,6 @@ ${code}`;
|
|
|
370522
371531
|
}
|
|
370523
371532
|
});
|
|
370524
371533
|
|
|
370525
|
-
// ../../packages/workflow-code/dist/compiler/refs.js
|
|
370526
|
-
var require_refs = __commonJS({
|
|
370527
|
-
"../../packages/workflow-code/dist/compiler/refs.js"(exports2) {
|
|
370528
|
-
"use strict";
|
|
370529
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
370530
|
-
exports2.resolvePromptRefs = resolvePromptRefs;
|
|
370531
|
-
exports2.resolveReferenceRecordRefs = resolveReferenceRecordRefs;
|
|
370532
|
-
exports2.resolveWorkflowRef = resolveWorkflowRef;
|
|
370533
|
-
exports2.resolveExclusiveRef = resolveExclusiveRef;
|
|
370534
|
-
var workflow_shared_1 = require_cjs2();
|
|
370535
|
-
function resolvePromptRefs(context) {
|
|
370536
|
-
const diagnostics = [];
|
|
370537
|
-
let prompt = context.prompt;
|
|
370538
|
-
for (const ref of context.refs) {
|
|
370539
|
-
const resolved = resolveWorkflowRef(ref, context);
|
|
370540
|
-
diagnostics.push(...resolved.diagnostics);
|
|
370541
|
-
if (!resolved.reference)
|
|
370542
|
-
continue;
|
|
370543
|
-
prompt = prompt.split(ref.token).join(resolved.reference);
|
|
370544
|
-
}
|
|
370545
|
-
return { prompt, diagnostics };
|
|
370546
|
-
}
|
|
370547
|
-
function resolveReferenceRecordRefs(context) {
|
|
370548
|
-
const diagnostics = [];
|
|
370549
|
-
const values = { ...context.values };
|
|
370550
|
-
for (const ref of context.refs) {
|
|
370551
|
-
const resolved = resolveWorkflowRef(ref, context);
|
|
370552
|
-
if (resolved.reference) {
|
|
370553
|
-
values[ref.key] = resolved.reference;
|
|
370554
|
-
continue;
|
|
370555
|
-
}
|
|
370556
|
-
diagnostics.push(...resolved.diagnostics.map((diagnostic) => ({
|
|
370557
|
-
...diagnostic,
|
|
370558
|
-
message: diagnostic.message.replace("Prompt reference", `Reference record ${ref.key} reference`)
|
|
370559
|
-
})));
|
|
370560
|
-
}
|
|
370561
|
-
return { values: Object.freeze(values), diagnostics };
|
|
370562
|
-
}
|
|
370563
|
-
function resolveWorkflowRef(ref, context) {
|
|
370564
|
-
const resolved = ref.targetKind === "input" ? resolveInputRef(ref, context) : resolveNodeRef(ref, context);
|
|
370565
|
-
if (!resolved) {
|
|
370566
|
-
return {
|
|
370567
|
-
diagnostics: [{
|
|
370568
|
-
code: "compiler.ref.dangling",
|
|
370569
|
-
severity: "error",
|
|
370570
|
-
message: `Prompt reference ${ref.targetKey} does not match a workflow input or previous node`
|
|
370571
|
-
}]
|
|
370572
|
-
};
|
|
370573
|
-
}
|
|
370574
|
-
if (resolved === "forward") {
|
|
370575
|
-
return {
|
|
370576
|
-
diagnostics: [{
|
|
370577
|
-
code: "compiler.ref.forward",
|
|
370578
|
-
severity: "error",
|
|
370579
|
-
message: `Prompt reference ${ref.targetKey} points to a future workflow node`
|
|
370580
|
-
}]
|
|
370581
|
-
};
|
|
370582
|
-
}
|
|
370583
|
-
if (resolved === "scope") {
|
|
370584
|
-
return {
|
|
370585
|
-
diagnostics: [{
|
|
370586
|
-
code: "compiler.ref.scope",
|
|
370587
|
-
severity: "error",
|
|
370588
|
-
message: `Prompt reference ${ref.targetKey} points to a workflow node outside the visible scope`
|
|
370589
|
-
}]
|
|
370590
|
-
};
|
|
370591
|
-
}
|
|
370592
|
-
return {
|
|
370593
|
-
reference: resolved.reference,
|
|
370594
|
-
inputType: "inputType" in resolved ? resolved.inputType : void 0,
|
|
370595
|
-
nodeId: "nodeId" in resolved ? resolved.nodeId : void 0,
|
|
370596
|
-
diagnostics: []
|
|
370597
|
-
};
|
|
370598
|
-
}
|
|
370599
|
-
function resolveExclusiveRef(ref, context) {
|
|
370600
|
-
const resolved = resolveWorkflowRef(ref, context);
|
|
370601
|
-
if (resolved.reference)
|
|
370602
|
-
return resolved;
|
|
370603
|
-
return {
|
|
370604
|
-
diagnostics: resolved.diagnostics.map((diagnostic) => ({
|
|
370605
|
-
...diagnostic,
|
|
370606
|
-
message: diagnostic.message.replace("Prompt reference", "Exclusive reference")
|
|
370607
|
-
}))
|
|
370608
|
-
};
|
|
370609
|
-
}
|
|
370610
|
-
function resolveInputRef(ref, context) {
|
|
370611
|
-
const id = context.inputIdsByKey.get(ref.targetKey);
|
|
370612
|
-
if (!id)
|
|
370613
|
-
return void 0;
|
|
370614
|
-
const reference = workflow_shared_1.InputReferenceURI.fromVariable({ name: id });
|
|
370615
|
-
return {
|
|
370616
|
-
reference: formatPromptReference(reference, ref),
|
|
370617
|
-
inputType: context.inputTypesByKey?.get(ref.targetKey)
|
|
370618
|
-
};
|
|
370619
|
-
}
|
|
370620
|
-
function resolveNodeRef(ref, context) {
|
|
370621
|
-
const candidates = context.nodeIdentitiesByKey.get(ref.targetKey) ?? [];
|
|
370622
|
-
if (candidates.length === 0)
|
|
370623
|
-
return void 0;
|
|
370624
|
-
const visible = findVisibleCandidate(ref.targetKey, context);
|
|
370625
|
-
if (visible) {
|
|
370626
|
-
const reference = workflow_shared_1.ActionOutputReferenceURI.fromStepId(visible.id);
|
|
370627
|
-
return { reference: formatPromptReference(reference, ref), nodeId: visible.id };
|
|
370628
|
-
}
|
|
370629
|
-
if (candidates.some((candidate) => samePath(candidate.scopePath, context.currentNode.scopePath) && candidate.sequenceIndex >= context.currentNode.sequenceIndex)) {
|
|
370630
|
-
return "forward";
|
|
370631
|
-
}
|
|
370632
|
-
return "scope";
|
|
370633
|
-
}
|
|
370634
|
-
function findVisibleCandidate(key, context) {
|
|
370635
|
-
const currentScopeCandidate = resolvePriorCandidateInScope(key, context.currentNode.scopePath, context.currentNode.sequenceIndex, context);
|
|
370636
|
-
if (currentScopeCandidate)
|
|
370637
|
-
return currentScopeCandidate;
|
|
370638
|
-
for (const ancestorMapPath of [...context.currentNode.ancestorMapPaths].reverse()) {
|
|
370639
|
-
const ancestorMap = context.nodesByPath.get(pathKey(ancestorMapPath));
|
|
370640
|
-
if (!ancestorMap)
|
|
370641
|
-
continue;
|
|
370642
|
-
const candidate = resolvePriorCandidateInScope(key, ancestorMap.scopePath, ancestorMap.sequenceIndex, context);
|
|
370643
|
-
if (candidate)
|
|
370644
|
-
return candidate;
|
|
370645
|
-
}
|
|
370646
|
-
return void 0;
|
|
370647
|
-
}
|
|
370648
|
-
function resolvePriorCandidateInScope(key, scopePath, beforeSequenceIndex, context) {
|
|
370649
|
-
const candidates = (context.nodeIdentitiesByKey.get(key) ?? []).filter((candidate) => samePath(candidate.scopePath, scopePath) && candidate.sequenceIndex < beforeSequenceIndex).sort((left, right) => right.sequenceIndex - left.sequenceIndex);
|
|
370650
|
-
const nearest = candidates[0];
|
|
370651
|
-
if (!nearest)
|
|
370652
|
-
return void 0;
|
|
370653
|
-
if (candidates.filter((candidate) => candidate.sequenceIndex === nearest.sequenceIndex).length > 1)
|
|
370654
|
-
return void 0;
|
|
370655
|
-
return nearest;
|
|
370656
|
-
}
|
|
370657
|
-
function samePath(left, right) {
|
|
370658
|
-
return left.length === right.length && left.every((segment, index) => segment === right[index]);
|
|
370659
|
-
}
|
|
370660
|
-
function pathKey(path3) {
|
|
370661
|
-
return path3.join(".");
|
|
370662
|
-
}
|
|
370663
|
-
function formatPromptReference(reference, ref) {
|
|
370664
|
-
if (ref.path && ref.path.length > 0)
|
|
370665
|
-
reference.appendPath([...ref.path]);
|
|
370666
|
-
if ("format" in ref && ref.format)
|
|
370667
|
-
reference.setFormat(ref.format);
|
|
370668
|
-
return reference.toReference();
|
|
370669
|
-
}
|
|
370670
|
-
}
|
|
370671
|
-
});
|
|
370672
|
-
|
|
370673
371534
|
// ../../packages/workflow-code/dist/compiler/modules.js
|
|
370674
371535
|
var require_modules = __commonJS({
|
|
370675
371536
|
"../../packages/workflow-code/dist/compiler/modules.js"(exports2) {
|
|
@@ -370679,6 +371540,7 @@ var require_modules = __commonJS({
|
|
|
370679
371540
|
var contracts_1 = require_contracts();
|
|
370680
371541
|
var workflow_shared_1 = require_cjs2();
|
|
370681
371542
|
var remote_1 = require_remote();
|
|
371543
|
+
var condition_provenance_1 = require_condition_provenance();
|
|
370682
371544
|
var reference_1 = require_reference();
|
|
370683
371545
|
var asset_1 = require_asset();
|
|
370684
371546
|
var extract_1 = require_extract3();
|
|
@@ -370756,6 +371618,42 @@ var require_modules = __commonJS({
|
|
|
370756
371618
|
output: (0, ids_1.defaultOutputPortId)(nodeId)
|
|
370757
371619
|
};
|
|
370758
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
|
+
}
|
|
370759
371657
|
function collectRemoteInputFacts(values, refs, context) {
|
|
370760
371658
|
const refsByInputName = new Map((refs ?? []).map((ref) => [ref.key, ref]));
|
|
370761
371659
|
const inputsByKey = new Map(context.builtInputs.map((input) => [input.key ?? input.name, input]));
|
|
@@ -370932,6 +371830,171 @@ var require_modules = __commonJS({
|
|
|
370932
371830
|
message: `Map node ${nodeName || "<unnamed>"}: ${message}`
|
|
370933
371831
|
};
|
|
370934
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
|
+
};
|
|
370935
371998
|
var codeModule = {
|
|
370936
371999
|
kind: "code",
|
|
370937
372000
|
actionId: workflow_shared_1.WORKFLOW_ACTION_IDS.codeExecution,
|
|
@@ -370960,11 +372023,13 @@ var require_modules = __commonJS({
|
|
|
370960
372023
|
builtInputs: context.builtInputs,
|
|
370961
372024
|
builtNodes: context.builtNodes,
|
|
370962
372025
|
currentNodeIndex: context.nodeIndex,
|
|
372026
|
+
nodeIdentitiesByKey: context.nodeIdentitiesByKey,
|
|
372027
|
+
currentNode: context.currentNode,
|
|
370963
372028
|
inputNamesByKey: context.inputNamesByKey,
|
|
370964
372029
|
nodeNamesByKey: context.nodeNamesByKey,
|
|
372030
|
+
nodeIdsByKey: context.nodeIdsByKey,
|
|
370965
372031
|
nodeIndexesByKey: context.nodeIndexesByKey,
|
|
370966
|
-
nodeOutputSchemasById: context.nodeOutputSchemasById
|
|
370967
|
-
nodeIdsByKey: context.nodeIdsByKey
|
|
372032
|
+
nodeOutputSchemasById: context.nodeOutputSchemasById
|
|
370968
372033
|
});
|
|
370969
372034
|
context.diagnostics.push(...extracted.diagnostics);
|
|
370970
372035
|
if (extracted.diagnostics.some((item) => item.severity === "error"))
|
|
@@ -371106,6 +372171,255 @@ var require_modules = __commonJS({
|
|
|
371106
372171
|
diagnostics.push(invalidDocumentInputDiagnostic(node, "crop", "type must be pdf"));
|
|
371107
372172
|
return diagnostics;
|
|
371108
372173
|
}
|
|
372174
|
+
var DOCX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
372175
|
+
var docTemplateModule = {
|
|
372176
|
+
kind: "doc-template",
|
|
372177
|
+
actionId: workflow_shared_1.WORKFLOW_ACTION_IDS.documentTemplater,
|
|
372178
|
+
createFailedInput() {
|
|
372179
|
+
return {
|
|
372180
|
+
vaultUrl: "vault://00000000-0000-4000-8000-000000000000",
|
|
372181
|
+
placeholders: [],
|
|
372182
|
+
outputFilename: "compilation-failed.docx",
|
|
372183
|
+
mustache: false,
|
|
372184
|
+
createPermalink: false
|
|
372185
|
+
};
|
|
372186
|
+
},
|
|
372187
|
+
validate(node) {
|
|
372188
|
+
return validateDocTemplateInput(node);
|
|
372189
|
+
},
|
|
372190
|
+
lower(node, context) {
|
|
372191
|
+
if (validateDocTemplateInput(node).length > 0)
|
|
372192
|
+
return void 0;
|
|
372193
|
+
const template = lowerDocTemplateSource(node.input.template, context);
|
|
372194
|
+
const placeholders = lowerDocTemplatePlaceholders(node, context);
|
|
372195
|
+
context.diagnostics.push(...template.diagnostics, ...placeholders.diagnostics);
|
|
372196
|
+
if (!template.reference)
|
|
372197
|
+
return void 0;
|
|
372198
|
+
const templateFilename = node.input.templateFilename ?? template.lock?.name;
|
|
372199
|
+
const templateFileSize = node.input.templateFileSize ?? template.lock?.size;
|
|
372200
|
+
context.diagnostics.push(...validateKnownTemplateMetadata(node, template.lock));
|
|
372201
|
+
const linearPorts = defaultLinearPorts(context.nodeId);
|
|
372202
|
+
return {
|
|
372203
|
+
node: {
|
|
372204
|
+
id: context.nodeId,
|
|
372205
|
+
name: node.name,
|
|
372206
|
+
actionId: workflow_shared_1.WORKFLOW_ACTION_IDS.documentTemplater,
|
|
372207
|
+
ports: [
|
|
372208
|
+
{ id: linearPorts.input, dir: "in", type: "default" },
|
|
372209
|
+
{ id: linearPorts.output, dir: "out", type: "default" }
|
|
372210
|
+
],
|
|
372211
|
+
input: {
|
|
372212
|
+
vaultUrl: template.reference,
|
|
372213
|
+
placeholders: Object.entries(placeholders.values).map(([key, reference]) => ({ key, reference })),
|
|
372214
|
+
outputFilename: node.input.outputFilename,
|
|
372215
|
+
mustache: node.input.mustache ?? false,
|
|
372216
|
+
createPermalink: node.input.createPermalink ?? false,
|
|
372217
|
+
...templateFilename === void 0 ? {} : { templateFilename },
|
|
372218
|
+
...templateFileSize === void 0 ? {} : { templateFileSize }
|
|
372219
|
+
}
|
|
372220
|
+
},
|
|
372221
|
+
linearPorts,
|
|
372222
|
+
outputSchema: output_schema_1.DOC_TEMPLATE_OUTPUT_JSON_SCHEMA,
|
|
372223
|
+
vaultRefs: [...template.vaultRefs, ...placeholders.vaultRefs],
|
|
372224
|
+
...(0, reference_1.isWorkflowCodeVaultReference)(template.reference) ? { vaultRequirements: [{
|
|
372225
|
+
reference: template.reference,
|
|
372226
|
+
...templateFilename === void 0 ? {} : { expectedName: templateFilename },
|
|
372227
|
+
...templateFileSize === void 0 ? {} : { expectedSize: templateFileSize },
|
|
372228
|
+
requiredExtension: ".docx",
|
|
372229
|
+
requiredMimeType: DOCX_MIME_TYPE
|
|
372230
|
+
}] } : {}
|
|
372231
|
+
};
|
|
372232
|
+
}
|
|
372233
|
+
};
|
|
372234
|
+
function validateDocTemplateInput(node) {
|
|
372235
|
+
if (!node.input || typeof node.input !== "object")
|
|
372236
|
+
return [invalidDocTemplateInputDiagnostic(node, "input must be an object")];
|
|
372237
|
+
const diagnostics = [];
|
|
372238
|
+
if (!isVaultSource(node.input.template) && !isExclusiveWorkflowRef(node.input.template))
|
|
372239
|
+
diagnostics.push(invalidDocTemplateInputDiagnostic(node, "template must be vault.ref(), vault.asset(), or a workflow reference callback"));
|
|
372240
|
+
if (typeof node.input.outputFilename !== "string" || node.input.outputFilename.trim().length === 0)
|
|
372241
|
+
diagnostics.push(invalidDocTemplateInputDiagnostic(node, "outputFilename must be a non-empty string"));
|
|
372242
|
+
if (!isRecord3(node.input.placeholders))
|
|
372243
|
+
diagnostics.push(invalidDocTemplateInputDiagnostic(node, "placeholders must be an object"));
|
|
372244
|
+
else if (Object.entries(node.input.placeholders).some(([key, value]) => key.trim().length === 0 || !isReferencePlaceholder(value) && !isVaultSource(value)))
|
|
372245
|
+
diagnostics.push(invalidDocTemplateInputDiagnostic(node, "placeholder keys must be non-empty and values must be string literals or compatible refs"));
|
|
372246
|
+
if (node.input.mustache !== void 0 && typeof node.input.mustache !== "boolean")
|
|
372247
|
+
diagnostics.push(invalidDocTemplateInputDiagnostic(node, "mustache must be a boolean"));
|
|
372248
|
+
if (node.input.createPermalink !== void 0 && typeof node.input.createPermalink !== "boolean")
|
|
372249
|
+
diagnostics.push(invalidDocTemplateInputDiagnostic(node, "createPermalink must be a boolean"));
|
|
372250
|
+
if (node.input.templateFilename !== void 0 && (typeof node.input.templateFilename !== "string" || !hasDocxExtension(node.input.templateFilename)))
|
|
372251
|
+
diagnostics.push(invalidDocTemplateInputDiagnostic(node, "templateFilename must name a .docx file"));
|
|
372252
|
+
if (node.input.templateFileSize !== void 0 && (typeof node.input.templateFileSize !== "number" || !Number.isFinite(node.input.templateFileSize) || node.input.templateFileSize < 0))
|
|
372253
|
+
diagnostics.push(invalidDocTemplateInputDiagnostic(node, "templateFileSize must be a non-negative finite number"));
|
|
372254
|
+
if (isVaultAsset(node.input.template)) {
|
|
372255
|
+
const assetName = node.input.template.name ?? node.input.template.path;
|
|
372256
|
+
if (!hasDocxExtension(assetName))
|
|
372257
|
+
diagnostics.push(invalidDocTemplateInputDiagnostic(node, "vault.asset() template must name a .docx file"));
|
|
372258
|
+
if (node.input.template.mimeType !== void 0 && node.input.template.mimeType !== DOCX_MIME_TYPE)
|
|
372259
|
+
diagnostics.push(invalidDocTemplateInputDiagnostic(node, `vault.asset() template MIME type must be ${DOCX_MIME_TYPE}`));
|
|
372260
|
+
}
|
|
372261
|
+
return diagnostics;
|
|
372262
|
+
}
|
|
372263
|
+
function invalidDocTemplateInputDiagnostic(node, detail) {
|
|
372264
|
+
return {
|
|
372265
|
+
code: "compiler.module.invalid_input",
|
|
372266
|
+
severity: "error",
|
|
372267
|
+
message: `Node ${node.name || "<unnamed>"} has invalid docTemplate input: ${detail}`
|
|
372268
|
+
};
|
|
372269
|
+
}
|
|
372270
|
+
function lowerDocTemplateSource(source, context) {
|
|
372271
|
+
if (isExclusiveWorkflowRef(source)) {
|
|
372272
|
+
const compatibility = validateDocTemplateSourceTarget(source, context);
|
|
372273
|
+
if (compatibility.length > 0)
|
|
372274
|
+
return { vaultRefs: [], diagnostics: compatibility };
|
|
372275
|
+
const resolved = (0, refs_1.resolveExclusiveRef)(source, {
|
|
372276
|
+
inputIdsByKey: context.inputIdsByKey,
|
|
372277
|
+
nodeIdentitiesByKey: context.nodeIdentitiesByKey,
|
|
372278
|
+
nodesByPath: context.nodesByPath,
|
|
372279
|
+
currentNode: context.currentNode
|
|
372280
|
+
});
|
|
372281
|
+
return { reference: resolved.reference, vaultRefs: [], diagnostics: resolved.diagnostics };
|
|
372282
|
+
}
|
|
372283
|
+
if (isVaultRef(source)) {
|
|
372284
|
+
if (!(0, reference_1.isWorkflowCodeVaultReference)(source.reference))
|
|
372285
|
+
return { vaultRefs: [], diagnostics: [invalidVaultRefDiagnostic(source.reference)] };
|
|
372286
|
+
return { reference: source.reference, vaultRefs: [source.reference], diagnostics: [] };
|
|
372287
|
+
}
|
|
372288
|
+
if (!isVaultAsset(source))
|
|
372289
|
+
return { vaultRefs: [], diagnostics: [] };
|
|
372290
|
+
const lock = context.vaultAssetsByKey.get((0, asset_1.workflowCodeVaultAssetKey)(context.workflowKey, source));
|
|
372291
|
+
if (!lock || !(0, reference_1.isWorkflowCodeVaultReference)(lock.ref)) {
|
|
372292
|
+
return {
|
|
372293
|
+
vaultRefs: [],
|
|
372294
|
+
diagnostics: [{
|
|
372295
|
+
code: "vault.asset.missing_lock",
|
|
372296
|
+
severity: "error",
|
|
372297
|
+
message: `Vault asset ${source.path} has no uploaded lock for this workflow`,
|
|
372298
|
+
hint: "Run tela workflow sync so the CLI can upload and lock the local asset before compilation."
|
|
372299
|
+
}]
|
|
372300
|
+
};
|
|
372301
|
+
}
|
|
372302
|
+
return {
|
|
372303
|
+
reference: lock.ref,
|
|
372304
|
+
lock,
|
|
372305
|
+
vaultRefs: [lock.ref],
|
|
372306
|
+
diagnostics: []
|
|
372307
|
+
};
|
|
372308
|
+
}
|
|
372309
|
+
function validateDocTemplateSourceTarget(source, context) {
|
|
372310
|
+
if (source.targetKind === "input") {
|
|
372311
|
+
const target2 = context.builtInputs.find((input) => (input.key ?? input.name) === source.targetKey);
|
|
372312
|
+
if (!target2 || target2.inputType === "text")
|
|
372313
|
+
return [];
|
|
372314
|
+
return [incompatibleDocTemplateSourceDiagnostic(source.targetKey)];
|
|
372315
|
+
}
|
|
372316
|
+
const target = resolveVisibleNodeOutput(source.targetKey, context);
|
|
372317
|
+
if (!target)
|
|
372318
|
+
return [];
|
|
372319
|
+
const directStringLlm = target.declaration?.nodeKind === "llm" && target.declaration.schema == null && (source.path?.length ?? 0) === 0;
|
|
372320
|
+
const selectedSchema = (0, output_schema_1.selectOutputJsonSchema)(target.schema, source.path ?? []);
|
|
372321
|
+
return directStringLlm || (0, output_schema_1.isStringCompatibleOutputJsonSchema)(selectedSchema) ? [] : [incompatibleDocTemplateSourceDiagnostic(source.targetKey)];
|
|
372322
|
+
}
|
|
372323
|
+
function incompatibleDocTemplateSourceDiagnostic(targetKey) {
|
|
372324
|
+
return {
|
|
372325
|
+
code: "compiler.ref.incompatible",
|
|
372326
|
+
severity: "error",
|
|
372327
|
+
message: `Template reference ${targetKey} does not select a string-compatible value for docTemplate.input.template`
|
|
372328
|
+
};
|
|
372329
|
+
}
|
|
372330
|
+
function lowerDocTemplatePlaceholders(node, context) {
|
|
372331
|
+
const diagnostics = validateDocTemplatePlaceholderCompatibility(node, context);
|
|
372332
|
+
const resolved = (0, refs_1.resolveReferenceRecordRefs)({
|
|
372333
|
+
values: node.input.placeholders,
|
|
372334
|
+
refs: node.placeholderRefs ?? [],
|
|
372335
|
+
inputIdsByKey: context.inputIdsByKey,
|
|
372336
|
+
inputTypesByKey: context.inputTypesByKey,
|
|
372337
|
+
nodeIdentitiesByKey: context.nodeIdentitiesByKey,
|
|
372338
|
+
nodesByPath: context.nodesByPath,
|
|
372339
|
+
currentNode: context.currentNode
|
|
372340
|
+
});
|
|
372341
|
+
diagnostics.push(...resolved.diagnostics);
|
|
372342
|
+
const values = {};
|
|
372343
|
+
const vaultRefs = [];
|
|
372344
|
+
for (const [key, value] of Object.entries(resolved.values)) {
|
|
372345
|
+
if (typeof value === "string") {
|
|
372346
|
+
values[key] = value;
|
|
372347
|
+
continue;
|
|
372348
|
+
}
|
|
372349
|
+
if (isVaultRef(value)) {
|
|
372350
|
+
if ((0, reference_1.isWorkflowCodeVaultReference)(value.reference)) {
|
|
372351
|
+
values[key] = value.reference;
|
|
372352
|
+
vaultRefs.push(value.reference);
|
|
372353
|
+
} else {
|
|
372354
|
+
diagnostics.push(invalidVaultRefDiagnostic(value.reference));
|
|
372355
|
+
}
|
|
372356
|
+
continue;
|
|
372357
|
+
}
|
|
372358
|
+
if (isVaultAsset(value)) {
|
|
372359
|
+
const lock = context.vaultAssetsByKey.get((0, asset_1.workflowCodeVaultAssetKey)(context.workflowKey, value));
|
|
372360
|
+
if (!lock || !(0, reference_1.isWorkflowCodeVaultReference)(lock.ref)) {
|
|
372361
|
+
diagnostics.push({
|
|
372362
|
+
code: "vault.asset.missing_lock",
|
|
372363
|
+
severity: "error",
|
|
372364
|
+
message: `Vault asset ${value.path} has no uploaded lock for this workflow`,
|
|
372365
|
+
hint: "Run tela workflow sync so the CLI can upload and lock the local asset before compilation."
|
|
372366
|
+
});
|
|
372367
|
+
} else {
|
|
372368
|
+
values[key] = lock.ref;
|
|
372369
|
+
vaultRefs.push(lock.ref);
|
|
372370
|
+
}
|
|
372371
|
+
}
|
|
372372
|
+
}
|
|
372373
|
+
return { values: Object.freeze(values), vaultRefs, diagnostics };
|
|
372374
|
+
}
|
|
372375
|
+
function validateDocTemplatePlaceholderCompatibility(node, context) {
|
|
372376
|
+
const diagnostics = [];
|
|
372377
|
+
for (const ref of node.placeholderRefs ?? []) {
|
|
372378
|
+
if (ref.targetKind === "input") {
|
|
372379
|
+
if (context.inputTypesByKey.get(ref.targetKey) === "file")
|
|
372380
|
+
diagnostics.push(incompatibleDocTemplatePlaceholderDiagnostic(ref.key, ref.targetKey));
|
|
372381
|
+
continue;
|
|
372382
|
+
}
|
|
372383
|
+
const target = resolveVisibleNodeOutput(ref.targetKey, context);
|
|
372384
|
+
if (!target)
|
|
372385
|
+
continue;
|
|
372386
|
+
const directStringLlm = target.declaration?.nodeKind === "llm" && target.declaration.schema == null && (ref.path?.length ?? 0) === 0;
|
|
372387
|
+
const selected = (0, output_schema_1.selectOutputJsonSchema)(target.schema, ref.path ?? []);
|
|
372388
|
+
if (!directStringLlm && !(0, output_schema_1.isStringCompatibleOutputJsonSchema)(selected))
|
|
372389
|
+
diagnostics.push(incompatibleDocTemplatePlaceholderDiagnostic(ref.key, ref.targetKey));
|
|
372390
|
+
}
|
|
372391
|
+
return diagnostics;
|
|
372392
|
+
}
|
|
372393
|
+
function incompatibleDocTemplatePlaceholderDiagnostic(key, targetKey) {
|
|
372394
|
+
return {
|
|
372395
|
+
code: "compiler.ref.incompatible",
|
|
372396
|
+
severity: "error",
|
|
372397
|
+
message: `Placeholder ${key} reference ${targetKey} does not select a string-compatible value`
|
|
372398
|
+
};
|
|
372399
|
+
}
|
|
372400
|
+
function validateKnownTemplateMetadata(node, lock) {
|
|
372401
|
+
if (!lock)
|
|
372402
|
+
return [];
|
|
372403
|
+
const diagnostics = [];
|
|
372404
|
+
if (node.input.templateFilename !== void 0 && lock.name !== void 0 && node.input.templateFilename !== lock.name)
|
|
372405
|
+
diagnostics.push(invalidDocTemplateInputDiagnostic(node, `templateFilename ${node.input.templateFilename} does not match locked asset name ${lock.name}`));
|
|
372406
|
+
if (node.input.templateFileSize !== void 0 && lock.size !== void 0 && node.input.templateFileSize !== lock.size)
|
|
372407
|
+
diagnostics.push(invalidDocTemplateInputDiagnostic(node, `templateFileSize ${node.input.templateFileSize} does not match locked asset size ${lock.size}`));
|
|
372408
|
+
if (lock.name !== void 0 && !hasDocxExtension(lock.name))
|
|
372409
|
+
diagnostics.push(invalidDocTemplateInputDiagnostic(node, `locked asset name ${lock.name} is not a .docx file`));
|
|
372410
|
+
if (lock.mimeType !== void 0 && lock.mimeType !== DOCX_MIME_TYPE)
|
|
372411
|
+
diagnostics.push(invalidDocTemplateInputDiagnostic(node, `locked asset MIME type ${lock.mimeType} is not ${DOCX_MIME_TYPE}`));
|
|
372412
|
+
return diagnostics;
|
|
372413
|
+
}
|
|
372414
|
+
function hasDocxExtension(value) {
|
|
372415
|
+
return value.toLowerCase().endsWith(".docx");
|
|
372416
|
+
}
|
|
372417
|
+
function isReferencePlaceholder(value) {
|
|
372418
|
+
return typeof value === "string";
|
|
372419
|
+
}
|
|
372420
|
+
function isVaultSource(value) {
|
|
372421
|
+
return isVaultRef(value) || isVaultAsset(value);
|
|
372422
|
+
}
|
|
371109
372423
|
function validateSplitterInput(node) {
|
|
371110
372424
|
if (!node.input || typeof node.input !== "object")
|
|
371111
372425
|
return [invalidSplitterInputDiagnostic(node, "input must be an object")];
|
|
@@ -371220,19 +372534,32 @@ var require_modules = __commonJS({
|
|
|
371220
372534
|
}
|
|
371221
372535
|
function validateExclusiveFileTarget(file2, context, targetField) {
|
|
371222
372536
|
if (file2.targetKind === "input") {
|
|
371223
|
-
const
|
|
371224
|
-
if (!
|
|
372537
|
+
const target2 = context.builtInputs.find((input) => (input.key ?? input.name) === file2.targetKey);
|
|
372538
|
+
if (!target2 || target2.inputType === "file")
|
|
371225
372539
|
return [];
|
|
371226
372540
|
return [incompatibleDocumentRefDiagnostic(file2.targetKey, targetField)];
|
|
371227
372541
|
}
|
|
371228
|
-
const
|
|
371229
|
-
if (
|
|
372542
|
+
const target = resolveVisibleNodeOutput(file2.targetKey, context);
|
|
372543
|
+
if (!target)
|
|
371230
372544
|
return [];
|
|
371231
|
-
const selectedSchema = (0, output_schema_1.selectOutputJsonSchema)(
|
|
371232
|
-
if (selectedSchema === void 0 && context.remoteMode.kind === "symbolic" && context.remoteTemplateNodeIds.has(
|
|
372545
|
+
const selectedSchema = (0, output_schema_1.selectOutputJsonSchema)(target.schema, file2.path ?? []);
|
|
372546
|
+
if (selectedSchema === void 0 && context.remoteMode.kind === "symbolic" && context.remoteTemplateNodeIds.has(target.id))
|
|
371233
372547
|
return [];
|
|
371234
372548
|
return (0, output_schema_1.isFileCompatibleOutputJsonSchema)(selectedSchema) ? [] : [incompatibleDocumentRefDiagnostic(file2.targetKey, targetField)];
|
|
371235
372549
|
}
|
|
372550
|
+
function resolveVisibleNodeOutput(targetKey, context) {
|
|
372551
|
+
const identity2 = (0, refs_1.resolveVisibleNodeIdentity)(targetKey, {
|
|
372552
|
+
nodeIdentitiesByKey: context.nodeIdentitiesByKey,
|
|
372553
|
+
currentNode: context.currentNode
|
|
372554
|
+
});
|
|
372555
|
+
if (!identity2)
|
|
372556
|
+
return void 0;
|
|
372557
|
+
return {
|
|
372558
|
+
id: identity2.id,
|
|
372559
|
+
declaration: context.nodeDeclarationsById.get(identity2.id),
|
|
372560
|
+
schema: context.nodeOutputSchemasById.get(identity2.id)
|
|
372561
|
+
};
|
|
372562
|
+
}
|
|
371236
372563
|
function incompatibleDocumentRefDiagnostic(targetKey, targetField) {
|
|
371237
372564
|
return {
|
|
371238
372565
|
code: "compiler.ref.incompatible",
|
|
@@ -371453,9 +372780,12 @@ var require_modules = __commonJS({
|
|
|
371453
372780
|
[remoteAgentModule.kind, remoteAgentModule],
|
|
371454
372781
|
[remoteTemplateModule.kind, remoteTemplateModule],
|
|
371455
372782
|
[codeModule.kind, codeModule],
|
|
372783
|
+
[conditionModule.kind, conditionModule],
|
|
372784
|
+
[stopModule.kind, stopModule],
|
|
371456
372785
|
[mapModule.kind, mapModule],
|
|
371457
372786
|
[splitterModule.kind, splitterModule],
|
|
371458
|
-
[cropModule.kind, cropModule]
|
|
372787
|
+
[cropModule.kind, cropModule],
|
|
372788
|
+
[docTemplateModule.kind, docTemplateModule]
|
|
371459
372789
|
]);
|
|
371460
372790
|
}
|
|
371461
372791
|
});
|
|
@@ -371469,20 +372799,64 @@ var require_validation = __commonJS({
|
|
|
371469
372799
|
var modules_1 = require_modules();
|
|
371470
372800
|
function validateDeclaration(declaration) {
|
|
371471
372801
|
const nodes = flattenValidationNodes(declaration.nodes);
|
|
372802
|
+
const stopPlacementDiagnostics = [];
|
|
372803
|
+
validateStopPlacement(declaration.nodes, { directConditionBranch: false, insideMapBody: false }, stopPlacementDiagnostics);
|
|
371472
372804
|
return [
|
|
371473
372805
|
...validateWorkflowIdentity(declaration),
|
|
371474
372806
|
...validateInputIdentities(declaration.inputs),
|
|
371475
372807
|
...validateNodeIdentities(declaration.nodes),
|
|
371476
|
-
...validateModuleInputs(nodes)
|
|
372808
|
+
...validateModuleInputs(nodes),
|
|
372809
|
+
...stopPlacementDiagnostics
|
|
371477
372810
|
];
|
|
371478
372811
|
}
|
|
371479
372812
|
function flattenValidationNodes(nodes) {
|
|
371480
372813
|
return nodes.flatMap((node) => {
|
|
371481
|
-
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))
|
|
371482
372827
|
return [node];
|
|
371483
372828
|
return [node, ...flattenValidationNodes(node.nodes)];
|
|
371484
372829
|
});
|
|
371485
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
|
+
}
|
|
371486
372860
|
function validateWorkflowIdentity(declaration) {
|
|
371487
372861
|
if (typeof declaration.workflow.workflowKey === "string" && declaration.workflow.workflowKey.trim().length > 0)
|
|
371488
372862
|
return [];
|
|
@@ -371509,6 +372883,7 @@ var require_validation = __commonJS({
|
|
|
371509
372883
|
}
|
|
371510
372884
|
function validateNodeIdentities(nodes, scopePath = []) {
|
|
371511
372885
|
const validNodes = nodes.filter(isNodeLike);
|
|
372886
|
+
const authoredIdentityNodes = validNodes.filter((node) => !isCompilerOwnedTopologyNode(node));
|
|
371512
372887
|
const scopeLabel = scopePath.length > 0 ? `workflow node at ${scopePath.join(".")}` : "workflow node";
|
|
371513
372888
|
return [
|
|
371514
372889
|
...nodes.filter((node) => !isNodeLike(node)).map(() => ({
|
|
@@ -371516,14 +372891,33 @@ var require_validation = __commonJS({
|
|
|
371516
372891
|
severity: "error",
|
|
371517
372892
|
message: `${scopeLabel} must be an object declaration`
|
|
371518
372893
|
})),
|
|
371519
|
-
...findEmpty(
|
|
371520
|
-
...findEmpty(
|
|
371521
|
-
...findDuplicates(
|
|
371522
|
-
...findDuplicates(
|
|
371523
|
-
...findDuplicates(
|
|
371524
|
-
...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]))
|
|
371525
372900
|
];
|
|
371526
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
|
+
}
|
|
371527
372921
|
function validateModuleInputs(nodes) {
|
|
371528
372922
|
const diagnostics = [];
|
|
371529
372923
|
for (const node of nodes) {
|
|
@@ -371597,24 +372991,69 @@ var require_transpile = __commonJS({
|
|
|
371597
372991
|
}
|
|
371598
372992
|
function createTopologyEdges(records, loweredByPath) {
|
|
371599
372993
|
const edges = [];
|
|
371600
|
-
function lowerSequence(sequence) {
|
|
371601
|
-
|
|
371602
|
-
|
|
371603
|
-
const
|
|
371604
|
-
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)
|
|
371605
372999
|
continue;
|
|
371606
|
-
edges.push(createEdge(source.node.id, source.linearPorts.output, target.node.id, target.linearPorts.input));
|
|
371607
|
-
}
|
|
371608
|
-
for (const record2 of sequence) {
|
|
371609
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
|
+
}
|
|
371610
373023
|
const root = record2.children[0];
|
|
371611
373024
|
const loweredRoot = root ? loweredByPath.get(pathKey(root.path)) : void 0;
|
|
371612
|
-
if (lowered
|
|
373025
|
+
if (lowered.subgraphOutputPort && loweredRoot?.linearPorts) {
|
|
371613
373026
|
edges.push(createEdge(lowered.node.id, lowered.subgraphOutputPort, loweredRoot.node.id, loweredRoot.linearPorts.input));
|
|
371614
373027
|
}
|
|
371615
373028
|
if (record2.children.length > 0)
|
|
371616
373029
|
lowerSequence(record2.children);
|
|
371617
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));
|
|
371618
373057
|
}
|
|
371619
373058
|
lowerSequence(records);
|
|
371620
373059
|
return edges;
|
|
@@ -371645,14 +373084,80 @@ var require_transpile = __commonJS({
|
|
|
371645
373084
|
return createFailedCodeNode(workflowKey, declaration);
|
|
371646
373085
|
if (declaration.node.nodeKind === "map")
|
|
371647
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);
|
|
371648
373091
|
if (declaration.node.nodeKind === "splitter")
|
|
371649
373092
|
return createFailedSplitterNode(workflowKey, declaration);
|
|
371650
373093
|
if (declaration.node.nodeKind === "crop")
|
|
371651
373094
|
return createFailedCropNode(workflowKey, declaration);
|
|
373095
|
+
if (declaration.node.nodeKind === "doc-template")
|
|
373096
|
+
return createFailedDocTemplateNode(workflowKey, declaration);
|
|
371652
373097
|
if (declaration.node.nodeKind === "remote-executable" || declaration.node.nodeKind === "remote-agent" || declaration.node.nodeKind === "remote-template")
|
|
371653
373098
|
return createFailedRemoteNode(workflowKey, declaration);
|
|
371654
373099
|
return createFailedPromptNode(workflowKey, declaration);
|
|
371655
373100
|
}
|
|
373101
|
+
function createFailedDocTemplateNode(workflowKey, declaration) {
|
|
373102
|
+
const nodeId = (0, ids_1.stableNodeId)(workflowKey, declaration.node, declaration.path);
|
|
373103
|
+
const linearPorts = failedNodePorts(nodeId);
|
|
373104
|
+
const module3 = modules_1.nodeModuleRegistry.get(declaration.node.nodeKind);
|
|
373105
|
+
return {
|
|
373106
|
+
declarationIndex: declaration.ordinal,
|
|
373107
|
+
path: declaration.path,
|
|
373108
|
+
scopePath: declaration.scopePath,
|
|
373109
|
+
sequenceIndex: declaration.sequenceIndex,
|
|
373110
|
+
linearPorts,
|
|
373111
|
+
node: {
|
|
373112
|
+
id: nodeId,
|
|
373113
|
+
name: declaration.node.name,
|
|
373114
|
+
actionId: module3?.actionId ?? workflow_shared_1.WORKFLOW_ACTION_IDS.documentTemplater,
|
|
373115
|
+
ports: workflowNodePorts(linearPorts),
|
|
373116
|
+
input: module3?.createFailedInput(declaration.node) ?? {}
|
|
373117
|
+
}
|
|
373118
|
+
};
|
|
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
|
+
}
|
|
371656
373161
|
function createFailedRemoteNode(workflowKey, declaration) {
|
|
371657
373162
|
const nodeId = (0, ids_1.stableNodeId)(workflowKey, declaration.node, declaration.path);
|
|
371658
373163
|
const linearPorts = failedNodePorts(nodeId);
|
|
@@ -371804,12 +373309,14 @@ var require_transpile = __commonJS({
|
|
|
371804
373309
|
{ id: linearPorts.output, dir: "out", type: "default" }
|
|
371805
373310
|
];
|
|
371806
373311
|
}
|
|
371807
|
-
function createNodeRecords(nodes, scopePath = [], ancestorMapPaths = [], ordinalOffset = { value: 0 }) {
|
|
373312
|
+
function createNodeRecords(nodes, scopePath = [], ancestorMapPaths = [], ancestorScopes = [], ordinalOffset = { value: 0 }) {
|
|
371808
373313
|
const records = [];
|
|
371809
373314
|
nodes.forEach((node, sequenceIndex) => {
|
|
371810
373315
|
const path3 = [...scopePath, sequenceIndex];
|
|
371811
373316
|
const ordinal = ordinalOffset.value++;
|
|
371812
|
-
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) : [];
|
|
371813
373320
|
records.push({
|
|
371814
373321
|
node,
|
|
371815
373322
|
path: path3,
|
|
@@ -371817,18 +373324,43 @@ var require_transpile = __commonJS({
|
|
|
371817
373324
|
sequenceIndex,
|
|
371818
373325
|
ordinal,
|
|
371819
373326
|
ancestorMapPaths,
|
|
371820
|
-
|
|
373327
|
+
ancestorScopes,
|
|
373328
|
+
children,
|
|
373329
|
+
branches
|
|
371821
373330
|
});
|
|
371822
373331
|
});
|
|
371823
373332
|
return records;
|
|
371824
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
|
+
}
|
|
371825
373357
|
function flattenRecords(records) {
|
|
371826
|
-
return records.flatMap((record2) => [record2, ...flattenRecords(record2.children)]);
|
|
373358
|
+
return records.flatMap((record2) => [record2, ...flattenRecords(record2.children), ...record2.branches.flatMap((branch) => flattenRecords(branch.records))]);
|
|
371827
373359
|
}
|
|
371828
373360
|
function validateMapTopology(nodes) {
|
|
371829
373361
|
const diagnostics = [];
|
|
371830
373362
|
for (const item of nodes) {
|
|
371831
|
-
if (item.
|
|
373363
|
+
if (item.ancestorMapPaths.length === 0)
|
|
371832
373364
|
continue;
|
|
371833
373365
|
if (item.node.nodeKind === "code") {
|
|
371834
373366
|
diagnostics.push({
|
|
@@ -371841,7 +373373,7 @@ var require_transpile = __commonJS({
|
|
|
371841
373373
|
return diagnostics;
|
|
371842
373374
|
}
|
|
371843
373375
|
function isUnsupportedMapBodyNode(item) {
|
|
371844
|
-
return item.
|
|
373376
|
+
return item.ancestorMapPaths.length > 0 && item.node.nodeKind === "code";
|
|
371845
373377
|
}
|
|
371846
373378
|
function createChildNodeIdsByParentId(workflowKey, nodes) {
|
|
371847
373379
|
const ids = /* @__PURE__ */ new Map();
|
|
@@ -371861,6 +373393,23 @@ var require_transpile = __commonJS({
|
|
|
371861
373393
|
function createLoweredByPath(nodes) {
|
|
371862
373394
|
return new Map(nodes.map((node) => [pathKey(node.path), node]));
|
|
371863
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
|
+
}
|
|
371864
373413
|
function createScopedIdentities(workflowKey, records) {
|
|
371865
373414
|
const nodesByPath = /* @__PURE__ */ new Map();
|
|
371866
373415
|
const identitiesByKey = /* @__PURE__ */ new Map();
|
|
@@ -371868,13 +373417,17 @@ var require_transpile = __commonJS({
|
|
|
371868
373417
|
const key = record2.node.key ?? record2.node.name;
|
|
371869
373418
|
const identity2 = {
|
|
371870
373419
|
key,
|
|
373420
|
+
runtimeName: record2.node.name,
|
|
371871
373421
|
id: (0, ids_1.stableNodeId)(workflowKey, record2.node, record2.path),
|
|
371872
373422
|
path: record2.path,
|
|
371873
373423
|
scopePath: record2.scopePath,
|
|
371874
373424
|
sequenceIndex: record2.sequenceIndex,
|
|
371875
|
-
ancestorMapPaths: record2.ancestorMapPaths
|
|
373425
|
+
ancestorMapPaths: record2.ancestorMapPaths,
|
|
373426
|
+
ancestorScopes: record2.ancestorScopes
|
|
371876
373427
|
};
|
|
371877
373428
|
nodesByPath.set(pathKey(record2.path), identity2);
|
|
373429
|
+
if (record2.node.nodeKind === "condition" || record2.node.nodeKind === "stop")
|
|
373430
|
+
continue;
|
|
371878
373431
|
const identities = identitiesByKey.get(key) ?? [];
|
|
371879
373432
|
identities.push(identity2);
|
|
371880
373433
|
identitiesByKey.set(key, identities);
|
|
@@ -371908,17 +373461,18 @@ var require_transpile = __commonJS({
|
|
|
371908
373461
|
});
|
|
371909
373462
|
const inputTypesByKey = new Map(declarationInputs.map((declaration) => [declaration.key ?? declaration.name, declaration.inputType]));
|
|
371910
373463
|
const topLevelNodes = flattenedNodes.filter((node) => node.scopePath.length === 0);
|
|
373464
|
+
const outputProducingTopLevelNodes = topLevelNodes.filter(({ node }) => node.nodeKind !== "condition" && node.nodeKind !== "stop");
|
|
371911
373465
|
const nodeIdsByKey = /* @__PURE__ */ new Map();
|
|
371912
373466
|
const nodeIndexesByKey = /* @__PURE__ */ new Map();
|
|
371913
|
-
|
|
373467
|
+
outputProducingTopLevelNodes.forEach(({ node, path: path3, ordinal }) => {
|
|
371914
373468
|
const key = node.key ?? node.name;
|
|
371915
373469
|
nodeIdsByKey.set(key, (0, ids_1.stableNodeId)(workflowKey, node, path3));
|
|
371916
373470
|
nodeIndexesByKey.set(key, ordinal);
|
|
371917
373471
|
});
|
|
371918
373472
|
const { nodesByPath, nodeIdentitiesByKey } = createScopedIdentities(workflowKey, flattenedNodes);
|
|
373473
|
+
const nodeDeclarationsById = new Map(flattenedNodes.map(({ node, path: path3 }) => [(0, ids_1.stableNodeId)(workflowKey, node, path3), node]));
|
|
371919
373474
|
const inputNamesByKey = new Map(declarationInputs.map((declaration) => [declaration.key ?? declaration.name, declaration.name]));
|
|
371920
|
-
const nodeNamesByKey = new Map(
|
|
371921
|
-
const nodeOutputSchemasByKey = /* @__PURE__ */ new Map();
|
|
373475
|
+
const nodeNamesByKey = new Map(outputProducingTopLevelNodes.map(({ node }) => [node.key ?? node.name, node.name]));
|
|
371922
373476
|
const nodeOutputSchemasById = /* @__PURE__ */ new Map();
|
|
371923
373477
|
const remoteTemplateNodeIds = new Set(flattenedNodes.filter(({ node }) => node.nodeKind === "remote-template").map(({ node, path: path3 }) => (0, ids_1.stableNodeId)(workflowKey, node, path3)));
|
|
371924
373478
|
const buildBinding = input.declaration[contracts_1.BUILD_BINDING];
|
|
@@ -371930,10 +373484,13 @@ var require_transpile = __commonJS({
|
|
|
371930
373484
|
...declaration.description !== void 0 ? { description: declaration.description } : {}
|
|
371931
373485
|
}));
|
|
371932
373486
|
const childNodeIdsByParentId = createChildNodeIdsByParentId(workflowKey, flattenedNodes);
|
|
373487
|
+
const invalidStopPlacementPathKeys = collectInvalidStopPlacementPathKeys(rootRecords);
|
|
371933
373488
|
const loweredModuleNodesByDeclaration = flattenedNodes.map((flattened, index) => {
|
|
371934
373489
|
const { node } = flattened;
|
|
371935
373490
|
if (isUnsupportedMapBodyNode(flattened))
|
|
371936
373491
|
return void 0;
|
|
373492
|
+
if (node.nodeKind === "stop" && invalidStopPlacementPathKeys.has(pathKey(flattened.path)))
|
|
373493
|
+
return void 0;
|
|
371937
373494
|
const module3 = modules_1.nodeModuleRegistry.get(node.nodeKind);
|
|
371938
373495
|
if (!module3)
|
|
371939
373496
|
return void 0;
|
|
@@ -371947,17 +373504,19 @@ var require_transpile = __commonJS({
|
|
|
371947
373504
|
nodesByPath,
|
|
371948
373505
|
currentNode: nodesByPath.get(pathKey(flattened.path)) ?? {
|
|
371949
373506
|
key: node.key ?? node.name,
|
|
373507
|
+
runtimeName: node.name,
|
|
371950
373508
|
id: (0, ids_1.stableNodeId)(workflowKey, node, flattened.path),
|
|
371951
373509
|
path: flattened.path,
|
|
371952
373510
|
scopePath: flattened.scopePath,
|
|
371953
373511
|
sequenceIndex: flattened.sequenceIndex,
|
|
371954
|
-
ancestorMapPaths: flattened.ancestorMapPaths
|
|
373512
|
+
ancestorMapPaths: flattened.ancestorMapPaths,
|
|
373513
|
+
ancestorScopes: flattened.ancestorScopes
|
|
371955
373514
|
},
|
|
371956
373515
|
nodeIdsByKey,
|
|
371957
373516
|
nodeIndexesByKey,
|
|
373517
|
+
nodeDeclarationsById,
|
|
371958
373518
|
inputNamesByKey,
|
|
371959
373519
|
nodeNamesByKey,
|
|
371960
|
-
nodeOutputSchemasByKey,
|
|
371961
373520
|
nodeOutputSchemasById,
|
|
371962
373521
|
remoteTemplateNodeIds,
|
|
371963
373522
|
builtInputs: declarationInputs,
|
|
@@ -371970,10 +373529,8 @@ var require_transpile = __commonJS({
|
|
|
371970
373529
|
remoteRefs,
|
|
371971
373530
|
diagnostics
|
|
371972
373531
|
});
|
|
371973
|
-
if (lowered?.outputSchema !== void 0)
|
|
371974
|
-
nodeOutputSchemasByKey.set(node.key ?? node.name, lowered.outputSchema);
|
|
373532
|
+
if (lowered?.outputSchema !== void 0)
|
|
371975
373533
|
nodeOutputSchemasById.set((0, ids_1.stableNodeId)(workflowKey, node, flattened.path), lowered.outputSchema);
|
|
371976
|
-
}
|
|
371977
373534
|
return lowered ? {
|
|
371978
373535
|
...lowered,
|
|
371979
373536
|
declarationIndex: index,
|
|
@@ -371985,6 +373542,7 @@ var require_transpile = __commonJS({
|
|
|
371985
373542
|
const loweredModuleNodes = loweredModuleNodesByDeclaration.filter(isLoweredModuleNodeWithIndex);
|
|
371986
373543
|
const vaultRefs = [...new Set(loweredModuleNodes.flatMap((item) => item.vaultRefs ?? []))].sort((left, right) => left.localeCompare(right));
|
|
371987
373544
|
const vaultAssets = collectVaultAssetUses(flattenedNodes, workflowKey);
|
|
373545
|
+
const vaultRequirements = [...new Map(loweredModuleNodes.flatMap((item) => item.vaultRequirements ?? []).map((item) => [JSON.stringify(item), item])).values()].sort((left, right) => JSON.stringify(left).localeCompare(JSON.stringify(right)));
|
|
371988
373546
|
const loweredByPath = createLoweredByPath(loweredModuleNodes);
|
|
371989
373547
|
const nodes = loweredModuleNodes.map((item) => item.node);
|
|
371990
373548
|
const edges = createTopologyEdges(rootRecords, loweredByPath);
|
|
@@ -372027,7 +373585,8 @@ var require_transpile = __commonJS({
|
|
|
372027
373585
|
},
|
|
372028
373586
|
resources: Object.freeze({
|
|
372029
373587
|
vaultRefs: Object.freeze(vaultRefs),
|
|
372030
|
-
...vaultAssets.length === 0 ? {} : { vaultAssets: Object.freeze(vaultAssets) }
|
|
373588
|
+
...vaultAssets.length === 0 ? {} : { vaultAssets: Object.freeze(vaultAssets) },
|
|
373589
|
+
...vaultRequirements.length === 0 ? {} : { vaultRequirements: Object.freeze(vaultRequirements) }
|
|
372031
373590
|
}),
|
|
372032
373591
|
diagnostics
|
|
372033
373592
|
});
|
|
@@ -372035,9 +373594,7 @@ var require_transpile = __commonJS({
|
|
|
372035
373594
|
function collectVaultAssetUses(records, workflowKey) {
|
|
372036
373595
|
const byKey = /* @__PURE__ */ new Map();
|
|
372037
373596
|
for (const { node } of records) {
|
|
372038
|
-
|
|
372039
|
-
continue;
|
|
372040
|
-
const values = Array.isArray(node.input.file) ? node.input.file : [node.input.file];
|
|
373597
|
+
const values = node.nodeKind === "doc-template" ? [node.input.template, ...Object.values(node.input.placeholders)] : node.nodeKind === "splitter" || node.nodeKind === "crop" ? Array.isArray(node.input.file) ? node.input.file : [node.input.file] : [];
|
|
372041
373598
|
for (const value of values) {
|
|
372042
373599
|
if (!isVaultAsset(value))
|
|
372043
373600
|
continue;
|
|
@@ -372583,6 +374140,7 @@ var require_evaluate_source = __commonJS({
|
|
|
372583
374140
|
var node_path_1 = require("node:path");
|
|
372584
374141
|
var node_vm_1 = require("node:vm");
|
|
372585
374142
|
var typescript_1 = __importDefault(require_typescript3());
|
|
374143
|
+
var condition_provenance_1 = require_condition_provenance();
|
|
372586
374144
|
var hash_1 = require_hash();
|
|
372587
374145
|
var diagnostics_1 = require_diagnostics();
|
|
372588
374146
|
function evaluateWorkflowSource(entrypoint, compilerOptions = {}, sourceRoot = (0, node_path_1.dirname)((0, node_path_1.resolve)(entrypoint))) {
|
|
@@ -372633,10 +374191,12 @@ var require_evaluate_source = __commonJS({
|
|
|
372633
374191
|
includeSourceOnlyLocalModules(resolvedPath, content, files, compilerOptions, sourceRoot, /* @__PURE__ */ new Set([resolvedPath]));
|
|
372634
374192
|
let outputText;
|
|
372635
374193
|
let sourceMap;
|
|
374194
|
+
let trustedConditionSourceToken;
|
|
372636
374195
|
try {
|
|
372637
374196
|
const transpiled = transpileWorkflowSource(content, resolvedPath, compilerOptions, sourceRoot);
|
|
372638
374197
|
outputText = transpiled.outputText;
|
|
372639
374198
|
sourceMap = transpiled.sourceMap;
|
|
374199
|
+
trustedConditionSourceToken = transpiled.trustedConditionSourceToken;
|
|
372640
374200
|
} catch (error48) {
|
|
372641
374201
|
if (error48 instanceof SourceEvaluationError)
|
|
372642
374202
|
throw error48;
|
|
@@ -372690,7 +374250,9 @@ var require_evaluate_source = __commonJS({
|
|
|
372690
374250
|
exports: exports3,
|
|
372691
374251
|
module: module3,
|
|
372692
374252
|
process: createWorkflowProcessFacade(),
|
|
372693
|
-
__workflowCodeRandomUUID: node_crypto_1.randomUUID
|
|
374253
|
+
__workflowCodeRandomUUID: node_crypto_1.randomUUID,
|
|
374254
|
+
__workflowCodeTrustConditionBinding: condition_provenance_1.trustConditionBinding,
|
|
374255
|
+
__workflowCodeTrustedConditionSourceToken: trustedConditionSourceToken
|
|
372694
374256
|
});
|
|
372695
374257
|
new node_vm_1.Script(`${prelude}${outputText}`, { filename: resolvedPath }).runInNewContext(sandbox, {
|
|
372696
374258
|
contextCodeGeneration: { strings: false, wasm: false }
|
|
@@ -372774,6 +374336,7 @@ var require_evaluate_source = __commonJS({
|
|
|
372774
374336
|
return exportClause.elements.some((element) => element.isTypeOnly);
|
|
372775
374337
|
}
|
|
372776
374338
|
function transpileWorkflowSource(content, fileName, compilerOptions, sourceRoot) {
|
|
374339
|
+
const trustedConditionSourceToken = (0, node_crypto_1.randomUUID)();
|
|
372777
374340
|
const result = typescript_1.default.transpileModule(content, {
|
|
372778
374341
|
fileName,
|
|
372779
374342
|
compilerOptions: {
|
|
@@ -372787,15 +374350,16 @@ var require_evaluate_source = __commonJS({
|
|
|
372787
374350
|
target: typescript_1.default.ScriptTarget.ES2022
|
|
372788
374351
|
},
|
|
372789
374352
|
transformers: {
|
|
372790
|
-
before: [createWorkflowCodeSourceMarkerTransformer(fileName, compilerOptions, sourceRoot)]
|
|
374353
|
+
before: [createWorkflowCodeSourceMarkerTransformer(fileName, compilerOptions, sourceRoot, trustedConditionSourceToken)]
|
|
372791
374354
|
}
|
|
372792
374355
|
});
|
|
372793
374356
|
return {
|
|
372794
374357
|
outputText: result.outputText,
|
|
372795
|
-
sourceMap: parseWorkflowSourceMap(result.sourceMapText)
|
|
374358
|
+
sourceMap: parseWorkflowSourceMap(result.sourceMapText),
|
|
374359
|
+
trustedConditionSourceToken
|
|
372796
374360
|
};
|
|
372797
374361
|
}
|
|
372798
|
-
function createWorkflowCodeSourceMarkerTransformer(fileName, compilerOptions, sourceRoot) {
|
|
374362
|
+
function createWorkflowCodeSourceMarkerTransformer(fileName, compilerOptions, sourceRoot, trustedConditionSourceToken) {
|
|
372799
374363
|
return (context) => (root) => {
|
|
372800
374364
|
const sourceFile = root;
|
|
372801
374365
|
const baseBindings = collectWorkflowCodeImportBindings(root, fileName, compilerOptions, sourceRoot, createWorkflowCodeImportBindingContext());
|
|
@@ -372812,6 +374376,8 @@ var require_evaluate_source = __commonJS({
|
|
|
372812
374376
|
collectWorkflowCodeAliasBindings(node, node.statements, "agent", scopedBindings.promptNodeBindings, scopedBindings.promptNodeNamespaceBindings, scopedBindings.promptNodeNamespaceMemberBindings);
|
|
372813
374377
|
collectWorkflowCodeAliasBindings(node, node.statements, "llm", scopedBindings.promptNodeBindings, scopedBindings.promptNodeNamespaceBindings, scopedBindings.promptNodeNamespaceMemberBindings);
|
|
372814
374378
|
collectWorkflowCodeAliasBindings(node, node.statements, "map", scopedBindings.promptNodeBindings, scopedBindings.promptNodeNamespaceBindings, scopedBindings.promptNodeNamespaceMemberBindings);
|
|
374379
|
+
collectWorkflowCodeAliasBindings(node, node.statements, "docTemplate", scopedBindings.promptNodeBindings, scopedBindings.promptNodeNamespaceBindings, scopedBindings.promptNodeNamespaceMemberBindings);
|
|
374380
|
+
collectWorkflowCodeAliasBindings(node, node.statements, "condition", scopedBindings.promptNodeBindings, scopedBindings.promptNodeNamespaceBindings, scopedBindings.promptNodeNamespaceMemberBindings);
|
|
372815
374381
|
return typescript_1.default.visitEachChild(node, createVisit(scopedBindings), context);
|
|
372816
374382
|
}
|
|
372817
374383
|
if (isForLikeStatement(node)) {
|
|
@@ -372820,9 +374386,8 @@ var require_evaluate_source = __commonJS({
|
|
|
372820
374386
|
}
|
|
372821
374387
|
if (typescript_1.default.isCallExpression(node) && isWorkflowBuildCallExpression(node.expression, bindings.buildBindings, bindings.buildNamespaceBindings, bindings.buildNamespaceMemberBindings)) {
|
|
372822
374388
|
const [workflowArg, optionsArg, ...rest] = node.arguments;
|
|
372823
|
-
if (workflowArg && optionsArg && typescript_1.default.isObjectLiteralExpression(optionsArg)
|
|
372824
|
-
const
|
|
372825
|
-
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));
|
|
372826
374391
|
const updatedNode = typescript_1.default.factory.updateCallExpression(node, node.expression, node.typeArguments, [workflowArg, updatedOptions, ...rest]);
|
|
372827
374392
|
return typescript_1.default.visitEachChild(updatedNode, visit, context);
|
|
372828
374393
|
}
|
|
@@ -372834,12 +374399,8 @@ var require_evaluate_source = __commonJS({
|
|
|
372834
374399
|
if (typescript_1.default.isCallExpression(node) && isWorkflowCodeCallExpression(node.expression, bindings.codeBindings, bindings.codeNamespaceBindings, bindings.codeNamespaceMemberBindings)) {
|
|
372835
374400
|
const [firstArg, ...rest] = node.arguments;
|
|
372836
374401
|
if (firstArg && typescript_1.default.isObjectLiteralExpression(firstArg)) {
|
|
372837
|
-
|
|
372838
|
-
|
|
372839
|
-
const updatedArg = typescript_1.default.factory.updateObjectLiteralExpression(firstArg, [...firstArg.properties, marker]);
|
|
372840
|
-
return typescript_1.default.factory.updateCallExpression(node, node.expression, node.typeArguments, [updatedArg, ...rest]);
|
|
372841
|
-
}
|
|
372842
|
-
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]);
|
|
372843
374404
|
}
|
|
372844
374405
|
if (firstArg) {
|
|
372845
374406
|
const rejectedArg = typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("__workflowCodeRejectNonInlineCodeOptions"), void 0, [firstArg, createWorkflowCodeSourceMarker(fileName, node, root)]);
|
|
@@ -372848,11 +374409,17 @@ var require_evaluate_source = __commonJS({
|
|
|
372848
374409
|
}
|
|
372849
374410
|
if (typescript_1.default.isCallExpression(node) && isWorkflowPromptNodeCallExpression(node.expression, bindings.promptNodeBindings, bindings.promptNodeNamespaceBindings, bindings.promptNodeNamespaceMemberBindings)) {
|
|
372850
374411
|
const [firstArg, ...rest] = node.arguments;
|
|
372851
|
-
if (firstArg && typescript_1.default.isObjectLiteralExpression(firstArg)
|
|
372852
|
-
const
|
|
372853
|
-
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);
|
|
372854
374414
|
return typescript_1.default.factory.updateCallExpression(node, node.expression, node.typeArguments, [updatedArg, ...rest]);
|
|
372855
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
|
+
}
|
|
372856
374423
|
}
|
|
372857
374424
|
return typescript_1.default.visitEachChild(node, visit, context);
|
|
372858
374425
|
};
|
|
@@ -372948,8 +374515,18 @@ var require_evaluate_source = __commonJS({
|
|
|
372948
374515
|
bindings.promptNodeNamespaceBindings.delete(name);
|
|
372949
374516
|
bindings.promptNodeNamespaceMemberBindings.delete(name);
|
|
372950
374517
|
}
|
|
372951
|
-
function
|
|
372952
|
-
|
|
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;
|
|
372953
374530
|
}
|
|
372954
374531
|
function createWorkflowCodeSourceMarker(fileName, node, sourceFile) {
|
|
372955
374532
|
return typescript_1.default.factory.createObjectLiteralExpression([
|
|
@@ -372980,7 +374557,7 @@ var require_evaluate_source = __commonJS({
|
|
|
372980
374557
|
return Boolean(namespaceMemberBindings.get(root)?.has(members.join(".")));
|
|
372981
374558
|
}
|
|
372982
374559
|
function isPromptNodeMemberName(name) {
|
|
372983
|
-
return name === "agent" || name === "llm" || name === "map";
|
|
374560
|
+
return name === "agent" || name === "condition" || name === "docTemplate" || name === "llm" || name === "map";
|
|
372984
374561
|
}
|
|
372985
374562
|
function isWorkflowCodeMemberExpression(expression, memberName, memberBindings, namespaceBindings, namespaceMemberBindings) {
|
|
372986
374563
|
const unwrapped = unwrapExpression(expression);
|
|
@@ -373500,7 +375077,7 @@ var require_evaluate_source = __commonJS({
|
|
|
373500
375077
|
}
|
|
373501
375078
|
}
|
|
373502
375079
|
function addWorkflowCodePromptNodeMembersToExport(prefix, exportedNamespaces) {
|
|
373503
|
-
for (const memberName of ["agent", "llm", "map"])
|
|
375080
|
+
for (const memberName of ["agent", "condition", "llm", "map"])
|
|
373504
375081
|
exportedNamespaces.add(`${prefix}.${memberName}`);
|
|
373505
375082
|
}
|
|
373506
375083
|
function addWorkflowCodeNamespaceMembersToExport(members, prefix, exportedNamespaces) {
|
|
@@ -373586,7 +375163,7 @@ var require_evaluate_source = __commonJS({
|
|
|
373586
375163
|
exportedNames.codeNamespaces.add(statement.exportClause.name.text);
|
|
373587
375164
|
for (const exportedName of targetExports.codeNamespaces)
|
|
373588
375165
|
exportedNames.codeNamespaces.add(`${statement.exportClause.name.text}.${exportedName}`);
|
|
373589
|
-
for (const memberName of ["agent", "llm", "map"]) {
|
|
375166
|
+
for (const memberName of ["agent", "condition", "llm", "map"]) {
|
|
373590
375167
|
if (targetExports.promptNodes.has(memberName))
|
|
373591
375168
|
exportedNames.promptNodeNamespaces.add(`${statement.exportClause.name.text}.${memberName}`);
|
|
373592
375169
|
}
|
|
@@ -373616,6 +375193,8 @@ var require_evaluate_source = __commonJS({
|
|
|
373616
375193
|
exportedNames.build.add("build");
|
|
373617
375194
|
exportedNames.code.add("code");
|
|
373618
375195
|
exportedNames.promptNodes.add("agent");
|
|
375196
|
+
exportedNames.promptNodes.add("docTemplate");
|
|
375197
|
+
exportedNames.promptNodes.add("condition");
|
|
373619
375198
|
exportedNames.promptNodes.add("llm");
|
|
373620
375199
|
exportedNames.promptNodes.add("map");
|
|
373621
375200
|
return;
|
|
@@ -373787,12 +375366,17 @@ const __workflowCodeApi = (() => {
|
|
|
373787
375366
|
toString: () => registerRefUse(use, refs),
|
|
373788
375367
|
[Symbol.toPrimitive]: () => registerRefUse(use, refs),
|
|
373789
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
|
+
}
|
|
373790
375373
|
const renderPrompt = (input, source) => {
|
|
373791
375374
|
if (typeof input === 'string')
|
|
373792
375375
|
return freeze({ prompt: input, refs: freeze([]) })
|
|
373793
375376
|
const refs = []
|
|
373794
375377
|
const prompt = input(freeze({
|
|
373795
375378
|
ref(target, path) {
|
|
375379
|
+
assertOutputRefTarget(target, source)
|
|
373796
375380
|
const targetKey = target.key ?? target.name
|
|
373797
375381
|
if (path && (path.__workflowCodePathTargetKind !== target.kind || path.__workflowCodePathTargetKey !== targetKey))
|
|
373798
375382
|
throwAuthoringDiagnostic('ref path source must match ref target', source)
|
|
@@ -373803,7 +375387,7 @@ const __workflowCodeApi = (() => {
|
|
|
373803
375387
|
}
|
|
373804
375388
|
return createRefValue(use, refs)
|
|
373805
375389
|
},
|
|
373806
|
-
paths(target) { return createPathProxy([], target.kind, target.key ?? target.name) },
|
|
375390
|
+
paths(target) { assertOutputRefTarget(target, source); return createPathProxy([], target.kind, target.key ?? target.name) },
|
|
373807
375391
|
}))
|
|
373808
375392
|
if (typeof prompt !== 'string')
|
|
373809
375393
|
throwAuthoringDiagnostic('prompt callback must return a string', source)
|
|
@@ -373811,6 +375395,7 @@ const __workflowCodeApi = (() => {
|
|
|
373811
375395
|
}
|
|
373812
375396
|
const exclusiveRefContext = (source) => freeze({
|
|
373813
375397
|
ref(target, path) {
|
|
375398
|
+
assertOutputRefTarget(target, source)
|
|
373814
375399
|
const targetKey = target.key ?? target.name
|
|
373815
375400
|
if (path && (path.__workflowCodePathTargetKind !== target.kind || path.__workflowCodePathTargetKey !== targetKey))
|
|
373816
375401
|
throwAuthoringDiagnostic('ref path source must match ref target', source)
|
|
@@ -373821,7 +375406,7 @@ const __workflowCodeApi = (() => {
|
|
|
373821
375406
|
...(path ? { path: freeze([...path[pathKey]]) } : {}),
|
|
373822
375407
|
})
|
|
373823
375408
|
},
|
|
373824
|
-
paths(target) { return createPathProxy([], target.kind, target.key ?? target.name) },
|
|
375409
|
+
paths(target) { assertOutputRefTarget(target, source); return createPathProxy([], target.kind, target.key ?? target.name) },
|
|
373825
375410
|
})
|
|
373826
375411
|
const isVaultRef = (value) => value && typeof value === 'object' && !Array.isArray(value) && value.kind === 'vault-ref'
|
|
373827
375412
|
const isVaultAsset = (value) => value && typeof value === 'object' && !Array.isArray(value) && value.kind === 'vault-asset'
|
|
@@ -373840,12 +375425,13 @@ const __workflowCodeApi = (() => {
|
|
|
373840
375425
|
const refs = []
|
|
373841
375426
|
const record = input(freeze({
|
|
373842
375427
|
ref(target, path) {
|
|
375428
|
+
assertOutputRefTarget(target, source)
|
|
373843
375429
|
const targetKey = target.key ?? target.name
|
|
373844
375430
|
if (path && (path.__workflowCodePathTargetKind !== target.kind || path.__workflowCodePathTargetKey !== targetKey))
|
|
373845
375431
|
throwAuthoringDiagnostic('ref path source must match ref target', source)
|
|
373846
375432
|
return createRefValue({ targetKind: target.kind, targetKey, ...(path ? { path: path[pathKey] } : {}) }, refs)
|
|
373847
375433
|
},
|
|
373848
|
-
paths(target) { return createPathProxy([], target.kind, target.key ?? target.name) },
|
|
375434
|
+
paths(target) { assertOutputRefTarget(target, source); return createPathProxy([], target.kind, target.key ?? target.name) },
|
|
373849
375435
|
}))
|
|
373850
375436
|
if (!record || typeof record !== 'object' || Array.isArray(record))
|
|
373851
375437
|
throwAuthoringDiagnostic('reference record callback must return an object', source)
|
|
@@ -373982,6 +375568,11 @@ const __workflowCodeApi = (() => {
|
|
|
373982
375568
|
}
|
|
373983
375569
|
const buildBindingKey = Symbol.for('@meistrari/workflow-code/build-binding')
|
|
373984
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
|
|
373985
375576
|
const buildWorkflow = (workflow, options) => {
|
|
373986
375577
|
if (options.input !== undefined && options.inputs !== undefined)
|
|
373987
375578
|
throwAuthoringDiagnostic('Use either input or inputs, not both.')
|
|
@@ -373998,6 +375589,7 @@ const __workflowCodeApi = (() => {
|
|
|
373998
375589
|
if (typeof input !== 'function') {
|
|
373999
375590
|
if (!input || typeof input !== 'object' || (input.kind !== 'input' && input.kind !== 'node'))
|
|
374000
375591
|
throwAuthoringDiagnostic(label + ' must return exactly one workflow reference', source)
|
|
375592
|
+
assertOutputRefTarget(input, source)
|
|
374001
375593
|
if (input.kind === 'input' && input.inputType !== 'file')
|
|
374002
375594
|
throwAuthoringDiagnostic(label + ' must reference a file input or node output', source)
|
|
374003
375595
|
return freeze({ token: '__workflow_code_ref_0__', targetKind: input.kind, targetKey: input.key ?? input.name })
|
|
@@ -374005,6 +375597,7 @@ const __workflowCodeApi = (() => {
|
|
|
374005
375597
|
const refs = []
|
|
374006
375598
|
const rendered = String(input(freeze({
|
|
374007
375599
|
ref(target, path) {
|
|
375600
|
+
assertOutputRefTarget(target, source)
|
|
374008
375601
|
if (target.kind === 'input' && target.inputType !== 'file')
|
|
374009
375602
|
throwAuthoringDiagnostic(label + ' must reference a file input or node output', source)
|
|
374010
375603
|
const targetKey = target.key ?? target.name
|
|
@@ -374017,7 +375610,7 @@ const __workflowCodeApi = (() => {
|
|
|
374017
375610
|
}
|
|
374018
375611
|
return createRefValue(use, refs)
|
|
374019
375612
|
},
|
|
374020
|
-
paths(target) { return createPathProxy([], target.kind, target.key ?? target.name) },
|
|
375613
|
+
paths(target) { assertOutputRefTarget(target, source); return createPathProxy([], target.kind, target.key ?? target.name) },
|
|
374021
375614
|
})))
|
|
374022
375615
|
const registered = refs[0]
|
|
374023
375616
|
if (refs.length !== 1 || !registered || rendered !== registered.token)
|
|
@@ -374074,6 +375667,58 @@ const __workflowCodeApi = (() => {
|
|
|
374074
375667
|
})
|
|
374075
375668
|
return freeze(declaration)
|
|
374076
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
|
+
})
|
|
374077
375722
|
const splitterNode = (options) => {
|
|
374078
375723
|
if (!options || typeof options !== 'object' || !options.input || typeof options.input !== 'object')
|
|
374079
375724
|
throwAuthoringDiagnostic('splitter.input must be an object', options && typeof options === 'object' ? options.__workflowCodeSource : undefined)
|
|
@@ -374113,17 +375758,48 @@ const __workflowCodeApi = (() => {
|
|
|
374113
375758
|
}),
|
|
374114
375759
|
})
|
|
374115
375760
|
}
|
|
375761
|
+
const docTemplateNode = (options) => {
|
|
375762
|
+
if (!options || typeof options !== 'object' || !options.input || typeof options.input !== 'object')
|
|
375763
|
+
throwAuthoringDiagnostic('docTemplate.input must be an object', options && typeof options === 'object' ? options.__workflowCodeSource : undefined)
|
|
375764
|
+
assertNonEmptyString(options.name, 'docTemplate.name', options.__workflowCodeSource)
|
|
375765
|
+
assertNonEmptyString(options.input.outputFilename, 'docTemplate.input.outputFilename', options.__workflowCodeSource)
|
|
375766
|
+
const template = typeof options.input.template === 'function'
|
|
375767
|
+
? options.input.template(exclusiveRefContext(options.__workflowCodeSource))
|
|
375768
|
+
: options.input.template
|
|
375769
|
+
if (!isVaultRef(template) && !isVaultAsset(template) && !isWorkflowRef(template))
|
|
375770
|
+
throwAuthoringDiagnostic('docTemplate.input.template must be vault.ref(), vault.asset(), or a workflow reference callback', options.__workflowCodeSource)
|
|
375771
|
+
const placeholders = renderReferenceRecord(options.input.placeholders ?? {}, options.__workflowCodeSource)
|
|
375772
|
+
return freeze({
|
|
375773
|
+
kind: 'node',
|
|
375774
|
+
nodeKind: 'doc-template',
|
|
375775
|
+
name: options.name,
|
|
375776
|
+
...(options.key !== undefined ? { key: options.key } : {}),
|
|
375777
|
+
input: freeze({
|
|
375778
|
+
template,
|
|
375779
|
+
placeholders: placeholders.values,
|
|
375780
|
+
outputFilename: options.input.outputFilename,
|
|
375781
|
+
...(options.input.mustache === undefined ? {} : { mustache: options.input.mustache }),
|
|
375782
|
+
...(options.input.createPermalink === undefined ? {} : { createPermalink: options.input.createPermalink }),
|
|
375783
|
+
...(options.input.templateFilename === undefined ? {} : { templateFilename: options.input.templateFilename }),
|
|
375784
|
+
...(options.input.templateFileSize === undefined ? {} : { templateFileSize: options.input.templateFileSize }),
|
|
375785
|
+
}),
|
|
375786
|
+
...(placeholders.refs.length === 0 ? {} : { placeholderRefs: placeholders.refs }),
|
|
375787
|
+
})
|
|
375788
|
+
}
|
|
374116
375789
|
return freeze({
|
|
374117
375790
|
agent: (ref, options) => publishedAgent(ref, options),
|
|
374118
375791
|
build: buildWorkflow,
|
|
374119
375792
|
canvas: canvasNode,
|
|
374120
375793
|
code: codeNode,
|
|
374121
375794
|
crop: cropNode,
|
|
375795
|
+
docTemplate: docTemplateNode,
|
|
375796
|
+
condition: conditionNode,
|
|
374122
375797
|
input: freeze({ text: (options) => baseInput('text', options), file: (options) => baseInput('file', options) }),
|
|
374123
375798
|
llm: (options) => promptNode('llm', options, llmInput),
|
|
374124
375799
|
map: mapNode,
|
|
374125
375800
|
splitter: splitterNode,
|
|
374126
375801
|
template: templateNode,
|
|
375802
|
+
stop: stopNode,
|
|
374127
375803
|
vault: freeze({
|
|
374128
375804
|
asset: (path, options = {}) => freeze({
|
|
374129
375805
|
kind: 'vault-asset',
|
|
@@ -374149,6 +375825,7 @@ const __workflowCodePackageFacade = (() => {
|
|
|
374149
375825
|
const workflowCodeBindingKeys = new Set([
|
|
374150
375826
|
Symbol.for('@meistrari/workflow-code/code-binding'),
|
|
374151
375827
|
Symbol.for('@meistrari/workflow-code/build-binding'),
|
|
375828
|
+
Symbol.for('@meistrari/workflow-code/condition-binding'),
|
|
374152
375829
|
Symbol.for('@meistrari/workflow-code/remote-ref-binding'),
|
|
374153
375830
|
])
|
|
374154
375831
|
const cache = new WeakMap()
|
|
@@ -374278,6 +375955,33 @@ const __workflowCodeRejectNonInlineBuildOptions = (_options, source) => {
|
|
|
374278
375955
|
stack: new Error('Workflow Code build() calls must use an inline object literal options argument.').stack,
|
|
374279
375956
|
}))
|
|
374280
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
|
+
}
|
|
374281
375985
|
const require = ((hostRequire) => {
|
|
374282
375986
|
delete globalThis.__workflowCodeRequire
|
|
374283
375987
|
return (specifier) => {
|
|
@@ -376253,8 +377957,8 @@ var require_vault_preflight = __commonJS({
|
|
|
376253
377957
|
}
|
|
376254
377958
|
const results = await Promise.all(references.map(async (reference) => {
|
|
376255
377959
|
try {
|
|
376256
|
-
await input.vaultApi?.validateVaultRef({ reference });
|
|
376257
|
-
return
|
|
377960
|
+
const metadata = await input.vaultApi?.validateVaultRef({ reference });
|
|
377961
|
+
return validateRequirements(reference, metadata, input.compiled);
|
|
376258
377962
|
} catch (error48) {
|
|
376259
377963
|
if (hasDiagnostics(error48))
|
|
376260
377964
|
return error48.diagnostics;
|
|
@@ -376264,6 +377968,27 @@ var require_vault_preflight = __commonJS({
|
|
|
376264
377968
|
const diagnostics = results.flat();
|
|
376265
377969
|
return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: createValidation(references) };
|
|
376266
377970
|
}
|
|
377971
|
+
function validateRequirements(reference, metadata, compiled) {
|
|
377972
|
+
if (!metadata)
|
|
377973
|
+
return [];
|
|
377974
|
+
const requirements = compiled.flatMap((item) => item.resources.vaultRequirements ?? []).filter((requirement) => requirement.reference === reference);
|
|
377975
|
+
const diagnostics = [];
|
|
377976
|
+
for (const requirement of requirements) {
|
|
377977
|
+
if (requirement.expectedName !== void 0 && metadata.name !== void 0 && requirement.expectedName !== metadata.name) {
|
|
377978
|
+
diagnostics.push((0, diagnostics_1.diagnostic)("vault.template.metadata_mismatch", "error", `Vault template ${reference} is named ${metadata.name}, not the declared ${requirement.expectedName}.`, "Update templateFilename or select the matching Vault file before syncing."));
|
|
377979
|
+
}
|
|
377980
|
+
if (requirement.expectedSize !== void 0 && metadata.size !== void 0 && requirement.expectedSize !== metadata.size) {
|
|
377981
|
+
diagnostics.push((0, diagnostics_1.diagnostic)("vault.template.metadata_mismatch", "error", `Vault template ${reference} has size ${metadata.size}, not the declared ${requirement.expectedSize}.`, "Update templateFileSize or select the matching Vault file before syncing."));
|
|
377982
|
+
}
|
|
377983
|
+
if (requirement.requiredExtension !== void 0 && metadata.name !== void 0 && !metadata.name.toLowerCase().endsWith(requirement.requiredExtension)) {
|
|
377984
|
+
diagnostics.push((0, diagnostics_1.diagnostic)("vault.template.invalid_file", "error", `Vault template ${reference} is named ${metadata.name}; docTemplate() requires a ${requirement.requiredExtension} file.`, "Upload a .docx template or correct the Vault reference before syncing."));
|
|
377985
|
+
}
|
|
377986
|
+
if (requirement.requiredMimeType !== void 0 && metadata.mimeType !== void 0 && metadata.mimeType !== requirement.requiredMimeType) {
|
|
377987
|
+
diagnostics.push((0, diagnostics_1.diagnostic)("vault.template.invalid_file", "error", `Vault template ${reference} has MIME type ${metadata.mimeType}; docTemplate() requires ${requirement.requiredMimeType}.`, "Upload a .docx template or correct the Vault reference before syncing."));
|
|
377988
|
+
}
|
|
377989
|
+
}
|
|
377990
|
+
return diagnostics;
|
|
377991
|
+
}
|
|
376267
377992
|
function collectVaultRefs(compiled) {
|
|
376268
377993
|
return [...new Set(compiled.flatMap((item) => item.resources?.vaultRefs ?? []))].sort((left, right) => left.localeCompare(right));
|
|
376269
377994
|
}
|
|
@@ -376574,12 +378299,21 @@ var require_remote_api2 = __commonJS({
|
|
|
376574
378299
|
throw workflowApiError("vault.ref.inaccessible", "The active Tela environment does not configure a Vault service URL.", "Add services.vault to the active Tela environment and retry.");
|
|
376575
378300
|
}
|
|
376576
378301
|
try {
|
|
376577
|
-
await vaultRequest(`/files/${encodeURIComponent((0, reference_1.vaultReferenceId)(input.reference))}`, {
|
|
378302
|
+
const result = await vaultRequest(`/files/${encodeURIComponent((0, reference_1.vaultReferenceId)(input.reference))}`, {
|
|
376578
378303
|
failureCode: "vault.ref.inaccessible",
|
|
376579
378304
|
invalidResponseCode: "vault.ref.inaccessible",
|
|
376580
378305
|
failureMessage: (status2) => `Vault reference ${input.reference} is not accessible in the active Tela context (HTTP ${status2}).`,
|
|
376581
378306
|
failureHint: "Check the selected workspace, context credentials, and file permissions."
|
|
376582
378307
|
});
|
|
378308
|
+
const metadata = isRecord3(result.metadata) ? result.metadata : {};
|
|
378309
|
+
const name = typeof metadata.originalFileName === "string" ? metadata.originalFileName : typeof metadata.name === "string" ? metadata.name : void 0;
|
|
378310
|
+
const size = typeof metadata.size === "number" ? metadata.size : typeof result.size === "number" ? result.size : void 0;
|
|
378311
|
+
const mimeType = typeof metadata.mimeType === "string" ? metadata.mimeType : void 0;
|
|
378312
|
+
return {
|
|
378313
|
+
...name === void 0 ? {} : { name },
|
|
378314
|
+
...size === void 0 ? {} : { size },
|
|
378315
|
+
...mimeType === void 0 ? {} : { mimeType }
|
|
378316
|
+
};
|
|
376583
378317
|
} catch (error48) {
|
|
376584
378318
|
if (hasDiagnostics(error48))
|
|
376585
378319
|
throw error48;
|
|
@@ -376947,18 +378681,30 @@ var require_vault_assets = __commonJS({
|
|
|
376947
378681
|
"../../packages/workflow-code/dist/cli/sync/vault-assets.js"(exports2) {
|
|
376948
378682
|
"use strict";
|
|
376949
378683
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
378684
|
+
exports2.snapshotPreparedWorkflowVaultAssets = snapshotPreparedWorkflowVaultAssets;
|
|
378685
|
+
exports2.prepareWorkflowVaultAssetUploads = prepareWorkflowVaultAssetUploads;
|
|
378686
|
+
exports2.uploadPreparedWorkflowVaultAssets = uploadPreparedWorkflowVaultAssets;
|
|
376950
378687
|
exports2.prepareWorkflowVaultAssets = prepareWorkflowVaultAssets;
|
|
376951
378688
|
var node_crypto_1 = require("node:crypto");
|
|
376952
378689
|
var node_fs_1 = require("node:fs");
|
|
376953
378690
|
var promises_1 = require("node:fs/promises");
|
|
376954
378691
|
var node_path_1 = require("node:path");
|
|
376955
378692
|
var diagnostics_1 = require_diagnostics();
|
|
376956
|
-
|
|
378693
|
+
function snapshotPreparedWorkflowVaultAssets(assets) {
|
|
378694
|
+
return assets.map((asset) => asset.previous ?? Object.freeze({
|
|
378695
|
+
...asset.asset,
|
|
378696
|
+
name: asset.name,
|
|
378697
|
+
resolvedPath: asset.resolvedPath,
|
|
378698
|
+
contentHash: asset.contentHash,
|
|
378699
|
+
size: asset.content.byteLength,
|
|
378700
|
+
// The compiler only needs lock-derived local metadata at this stage.
|
|
378701
|
+
ref: `vault://${asset.contentHash}`,
|
|
378702
|
+
uploadedAt: ""
|
|
378703
|
+
}));
|
|
378704
|
+
}
|
|
378705
|
+
async function prepareWorkflowVaultAssetUploads(input) {
|
|
376957
378706
|
if (input.assets.length === 0)
|
|
376958
378707
|
return { ok: true, value: [] };
|
|
376959
|
-
if (!input.vaultApi) {
|
|
376960
|
-
return { ok: false, diagnostics: [(0, diagnostics_1.diagnostic)("vault.asset.upload_failed", "error", "Vault assets cannot be uploaded because the active remote client has no Vault service.", "Configure services.vault for the active Tela environment and retry before syncing.")] };
|
|
376961
|
-
}
|
|
376962
378708
|
const existingByKey = new Map((input.existing ?? []).map((asset) => [asset.key, asset]));
|
|
376963
378709
|
const prepared = [];
|
|
376964
378710
|
let projectRoot;
|
|
@@ -376998,33 +378744,70 @@ var require_vault_assets = __commonJS({
|
|
|
376998
378744
|
}
|
|
376999
378745
|
const contentHash = (0, node_crypto_1.createHash)("sha256").update(content).digest("hex");
|
|
377000
378746
|
const previous = existingByKey.get(asset.key);
|
|
377001
|
-
|
|
377002
|
-
|
|
378747
|
+
const name = asset.name ?? (0, node_path_1.basename)(resolvedPath);
|
|
378748
|
+
prepared.push(Object.freeze({
|
|
378749
|
+
asset,
|
|
378750
|
+
name,
|
|
378751
|
+
resolvedPath,
|
|
378752
|
+
content,
|
|
378753
|
+
contentHash,
|
|
378754
|
+
...previous?.contentHash === contentHash ? { previous } : {}
|
|
378755
|
+
}));
|
|
378756
|
+
}
|
|
378757
|
+
return { ok: true, value: prepared };
|
|
378758
|
+
}
|
|
378759
|
+
async function uploadPreparedWorkflowVaultAssets(input) {
|
|
378760
|
+
if (input.assets.length === 0)
|
|
378761
|
+
return { ok: true, value: [] };
|
|
378762
|
+
if (!input.vaultApi) {
|
|
378763
|
+
return { ok: false, diagnostics: [(0, diagnostics_1.diagnostic)("vault.asset.upload_failed", "error", "Vault assets cannot be uploaded because the active remote client has no Vault service.", "Configure services.vault for the active Tela environment and retry before syncing.")] };
|
|
378764
|
+
}
|
|
378765
|
+
const uploaded = [];
|
|
378766
|
+
for (const asset of input.assets) {
|
|
378767
|
+
if (asset.previous) {
|
|
378768
|
+
uploaded.push(asset.previous);
|
|
377003
378769
|
continue;
|
|
377004
378770
|
}
|
|
377005
|
-
const name = asset.name ?? (0, node_path_1.basename)(resolvedPath);
|
|
377006
378771
|
try {
|
|
377007
378772
|
const ref = await input.vaultApi.uploadVaultAsset({
|
|
377008
|
-
name,
|
|
377009
|
-
...asset.mimeType === void 0 ? {} : { mimeType: asset.mimeType },
|
|
377010
|
-
content
|
|
378773
|
+
name: asset.name,
|
|
378774
|
+
...asset.asset.mimeType === void 0 ? {} : { mimeType: asset.asset.mimeType },
|
|
378775
|
+
content: asset.content
|
|
377011
378776
|
});
|
|
377012
|
-
|
|
377013
|
-
...asset,
|
|
377014
|
-
name,
|
|
377015
|
-
resolvedPath,
|
|
377016
|
-
contentHash,
|
|
377017
|
-
size: content.byteLength,
|
|
378777
|
+
uploaded.push(Object.freeze({
|
|
378778
|
+
...asset.asset,
|
|
378779
|
+
name: asset.name,
|
|
378780
|
+
resolvedPath: asset.resolvedPath,
|
|
378781
|
+
contentHash: asset.contentHash,
|
|
378782
|
+
size: asset.content.byteLength,
|
|
377018
378783
|
ref,
|
|
377019
378784
|
uploadedAt: input.now?.() ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
377020
378785
|
}));
|
|
378786
|
+
const persisted = await input.onUploaded?.(snapshotKnownWorkflowVaultAssets(input.assets, uploaded));
|
|
378787
|
+
if (persisted !== void 0 && !persisted.ok)
|
|
378788
|
+
return persisted;
|
|
377021
378789
|
} catch (error48) {
|
|
377022
378790
|
if (hasDiagnostics(error48))
|
|
377023
378791
|
return { ok: false, diagnostics: error48.diagnostics };
|
|
377024
|
-
return { ok: false, diagnostics: [(0, diagnostics_1.diagnostic)("vault.asset.upload_failed", "error", `Vault asset ${asset.path} could not be uploaded.`, "Check the active Vault service and retry sync.")] };
|
|
378792
|
+
return { ok: false, diagnostics: [(0, diagnostics_1.diagnostic)("vault.asset.upload_failed", "error", `Vault asset ${asset.asset.path} could not be uploaded.`, "Check the active Vault service and retry sync.")] };
|
|
377025
378793
|
}
|
|
377026
378794
|
}
|
|
377027
|
-
return { ok: true, value:
|
|
378795
|
+
return { ok: true, value: uploaded };
|
|
378796
|
+
}
|
|
378797
|
+
function snapshotKnownWorkflowVaultAssets(plans, uploaded) {
|
|
378798
|
+
return plans.flatMap((plan, index) => {
|
|
378799
|
+
const snapshot = uploaded[index] ?? plan.previous;
|
|
378800
|
+
return snapshot === void 0 ? [] : [snapshot];
|
|
378801
|
+
});
|
|
378802
|
+
}
|
|
378803
|
+
async function prepareWorkflowVaultAssets(input) {
|
|
378804
|
+
if (input.assets.length > 0 && !input.vaultApi) {
|
|
378805
|
+
return { ok: false, diagnostics: [(0, diagnostics_1.diagnostic)("vault.asset.upload_failed", "error", "Vault assets cannot be uploaded because the active remote client has no Vault service.", "Configure services.vault for the active Tela environment and retry before syncing.")] };
|
|
378806
|
+
}
|
|
378807
|
+
const prepared = await prepareWorkflowVaultAssetUploads(input);
|
|
378808
|
+
if (!prepared.ok)
|
|
378809
|
+
return prepared;
|
|
378810
|
+
return await uploadPreparedWorkflowVaultAssets({ assets: prepared.value, vaultApi: input.vaultApi, now: input.now });
|
|
377028
378811
|
}
|
|
377029
378812
|
function isWithinRoot(path3, rootDir) {
|
|
377030
378813
|
const relativePath = (0, node_path_1.relative)((0, node_path_1.resolve)(rootDir), path3);
|
|
@@ -377036,6 +378819,79 @@ var require_vault_assets = __commonJS({
|
|
|
377036
378819
|
}
|
|
377037
378820
|
});
|
|
377038
378821
|
|
|
378822
|
+
// ../../packages/workflow-code/dist/cli/sync/vault-locks.js
|
|
378823
|
+
var require_vault_locks = __commonJS({
|
|
378824
|
+
"../../packages/workflow-code/dist/cli/sync/vault-locks.js"(exports2) {
|
|
378825
|
+
"use strict";
|
|
378826
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
378827
|
+
exports2.createWorkflowVaultAssetLockPersister = createWorkflowVaultAssetLockPersister;
|
|
378828
|
+
var diagnostics_1 = require_diagnostics();
|
|
378829
|
+
var state_1 = require_state2();
|
|
378830
|
+
async function createWorkflowVaultAssetLockPersister(input) {
|
|
378831
|
+
const lockfilePath = (0, state_1.deriveLockfilePath)(input.cwd, input.facts);
|
|
378832
|
+
if (!lockfilePath.ok)
|
|
378833
|
+
return { ok: false, diagnostics: lockfilePath.diagnostics };
|
|
378834
|
+
const remote = await fetchPromptSnapshot(input.remoteApi, input.facts);
|
|
378835
|
+
if (!remote.ok)
|
|
378836
|
+
return { ok: false, diagnostics: remote.diagnostics };
|
|
378837
|
+
let current = input.existing;
|
|
378838
|
+
return {
|
|
378839
|
+
ok: true,
|
|
378840
|
+
value: {
|
|
378841
|
+
persist: async (vaultAssets) => {
|
|
378842
|
+
const plan = (0, state_1.planRemoteSnapshotWrite)(lockfilePath.value, input.facts, remote.value, current, void 0, vaultAssets);
|
|
378843
|
+
if (!plan.ok)
|
|
378844
|
+
return { ok: false, diagnostics: plan.diagnostics };
|
|
378845
|
+
const written = await (0, state_1.writePlannedLockfile)(plan.value);
|
|
378846
|
+
if (!written.ok)
|
|
378847
|
+
return { ok: false, diagnostics: written.diagnostics };
|
|
378848
|
+
current = {
|
|
378849
|
+
path: lockfilePath.value,
|
|
378850
|
+
hash: written.value.hash,
|
|
378851
|
+
content: plan.value.content,
|
|
378852
|
+
lockfile: plan.value.lockfile
|
|
378853
|
+
};
|
|
378854
|
+
return { ok: true, value: current };
|
|
378855
|
+
}
|
|
378856
|
+
}
|
|
378857
|
+
};
|
|
378858
|
+
}
|
|
378859
|
+
async function fetchPromptSnapshot(remoteApi, facts) {
|
|
378860
|
+
const promptId = facts.context.promptId;
|
|
378861
|
+
if (promptId === void 0) {
|
|
378862
|
+
return {
|
|
378863
|
+
ok: false,
|
|
378864
|
+
diagnostics: [(0, diagnostics_1.diagnostic)("state.prompt_id.missing", "error", `Workflow target ${facts.targetName} has no prompt id for context ${facts.context.key}`, "Add promptId to the active workflow context binding before retrying the upload.")]
|
|
378865
|
+
};
|
|
378866
|
+
}
|
|
378867
|
+
try {
|
|
378868
|
+
const snapshot = await remoteApi.fetchPromptSnapshot({
|
|
378869
|
+
promptId,
|
|
378870
|
+
projectId: facts.context.projectId
|
|
378871
|
+
});
|
|
378872
|
+
if (snapshot.prompt.id !== promptId) {
|
|
378873
|
+
return {
|
|
378874
|
+
ok: false,
|
|
378875
|
+
diagnostics: [(0, diagnostics_1.diagnostic)("sync.remote.prompt_mismatch", "error", `Remote prompt ${snapshot.prompt.id} does not match configured prompt ${promptId}`, "Check the workflow target promptId binding.")]
|
|
378876
|
+
};
|
|
378877
|
+
}
|
|
378878
|
+
return { ok: true, value: snapshot };
|
|
378879
|
+
} catch (error48) {
|
|
378880
|
+
return {
|
|
378881
|
+
ok: false,
|
|
378882
|
+
diagnostics: diagnosticsFromError(error48)
|
|
378883
|
+
};
|
|
378884
|
+
}
|
|
378885
|
+
}
|
|
378886
|
+
function diagnosticsFromError(error48) {
|
|
378887
|
+
if (error48 && typeof error48 === "object" && "diagnostics" in error48 && Array.isArray(error48.diagnostics))
|
|
378888
|
+
return error48.diagnostics;
|
|
378889
|
+
const detail = error48 instanceof Error ? ` ${error48.message}` : "";
|
|
378890
|
+
return [(0, diagnostics_1.diagnostic)("sync.remote.request_failed", "error", `Unable to fetch the workflow state before persisting uploaded Vault assets.${detail}`, "Check the active Tela context and retry sync.")];
|
|
378891
|
+
}
|
|
378892
|
+
}
|
|
378893
|
+
});
|
|
378894
|
+
|
|
377039
378895
|
// ../../packages/workflow-code/dist/cli/sync/index.js
|
|
377040
378896
|
var require_sync2 = __commonJS({
|
|
377041
378897
|
"../../packages/workflow-code/dist/cli/sync/index.js"(exports2) {
|
|
@@ -377062,6 +378918,7 @@ var require_sync2 = __commonJS({
|
|
|
377062
378918
|
__exportStar(require_remote_api2(), exports2);
|
|
377063
378919
|
__exportStar(require_types5(), exports2);
|
|
377064
378920
|
__exportStar(require_vault_assets(), exports2);
|
|
378921
|
+
__exportStar(require_vault_locks(), exports2);
|
|
377065
378922
|
__exportStar(require_vault_preflight(), exports2);
|
|
377066
378923
|
}
|
|
377067
378924
|
});
|
|
@@ -377503,7 +379360,7 @@ var require_publish2 = __commonJS({
|
|
|
377503
379360
|
tsconfig: configResult.value.config.tsconfig,
|
|
377504
379361
|
targets: resolved.targets,
|
|
377505
379362
|
rootDir: context.cwd,
|
|
377506
|
-
|
|
379363
|
+
remoteApi
|
|
377507
379364
|
});
|
|
377508
379365
|
if (!prepared.ok)
|
|
377509
379366
|
return { exitCode: 1, diagnostics: [...environmentCreationDiagnostics, ...prepared.diagnostics], compiled: prepared.compiled };
|
|
@@ -377596,7 +379453,7 @@ var require_publish2 = __commonJS({
|
|
|
377596
379453
|
return { ok: true, targets: Object.entries(workflows).map(([name, target]) => ({ name, target })) };
|
|
377597
379454
|
}
|
|
377598
379455
|
async function preparePublishTargets(options2) {
|
|
377599
|
-
const
|
|
379456
|
+
const staged = [];
|
|
377600
379457
|
for (const selected of options2.targets) {
|
|
377601
379458
|
const source = await (0, load_source_1.loadWorkflowSource)((0, node_path_1.dirname)(options2.configPath), selected.target, options2.configEnv, options2.tsconfig);
|
|
377602
379459
|
if (!source.ok)
|
|
@@ -377640,26 +379497,75 @@ var require_publish2 = __commonJS({
|
|
|
377640
379497
|
if (!lockfileIdentity.ok)
|
|
377641
379498
|
return { ok: false, diagnostics: lockfileIdentity.diagnostics, compiled: initial };
|
|
377642
379499
|
}
|
|
377643
|
-
const
|
|
379500
|
+
const vaultPlans = await (0, sync_1.prepareWorkflowVaultAssetUploads)({
|
|
377644
379501
|
rootDir: (0, node_path_1.dirname)(options2.configPath),
|
|
377645
379502
|
assets: initial.resources.vaultAssets ?? [],
|
|
377646
|
-
existing: existing.ok ? existing.value.lockfile.vaultAssets : void 0
|
|
377647
|
-
vaultApi: options2.vaultApi
|
|
379503
|
+
existing: existing.ok ? existing.value.lockfile.vaultAssets : void 0
|
|
377648
379504
|
});
|
|
377649
|
-
if (!
|
|
377650
|
-
return { ok: false, diagnostics:
|
|
377651
|
-
const
|
|
379505
|
+
if (!vaultPlans.ok)
|
|
379506
|
+
return { ok: false, diagnostics: vaultPlans.diagnostics, compiled: initial };
|
|
379507
|
+
const preflight = (0, compiler_1.transpileWorkflow)({
|
|
377652
379508
|
targetName: selected.name,
|
|
377653
379509
|
workflowKey: selected.target.workflowKey,
|
|
377654
379510
|
title: selected.target.title,
|
|
377655
379511
|
declaration: source.value.declaration,
|
|
377656
379512
|
source: source.value.source,
|
|
379513
|
+
vaultAssets: (0, sync_1.snapshotPreparedWorkflowVaultAssets)(vaultPlans.value)
|
|
379514
|
+
});
|
|
379515
|
+
if (preflight.diagnostics.some((item) => item.severity === "error"))
|
|
379516
|
+
return { ok: false, diagnostics: [...preflight.diagnostics], compiled: preflight };
|
|
379517
|
+
staged.push({
|
|
379518
|
+
...selected,
|
|
379519
|
+
source: source.value,
|
|
379520
|
+
preflight,
|
|
379521
|
+
vaultPlans: vaultPlans.value,
|
|
379522
|
+
...existing.ok ? { lockfileState: existing.value } : {}
|
|
379523
|
+
});
|
|
379524
|
+
}
|
|
379525
|
+
const prepared = [];
|
|
379526
|
+
for (const stagedTarget of staged) {
|
|
379527
|
+
let onUploaded;
|
|
379528
|
+
if (stagedTarget.vaultPlans.some((asset) => asset.previous === void 0)) {
|
|
379529
|
+
const persister = await (0, sync_1.createWorkflowVaultAssetLockPersister)({
|
|
379530
|
+
cwd: options2.rootDir,
|
|
379531
|
+
facts: {
|
|
379532
|
+
targetName: stagedTarget.name,
|
|
379533
|
+
workflowKey: stagedTarget.preflight.workflowKey,
|
|
379534
|
+
context: {
|
|
379535
|
+
key: stagedTarget.identity.contextKey ?? "default",
|
|
379536
|
+
...stagedTarget.identity.contextId === void 0 ? {} : { id: stagedTarget.identity.contextId },
|
|
379537
|
+
projectId: stagedTarget.identity.projectId,
|
|
379538
|
+
promptId: stagedTarget.identity.promptId
|
|
379539
|
+
}
|
|
379540
|
+
},
|
|
379541
|
+
existing: stagedTarget.lockfileState,
|
|
379542
|
+
remoteApi: options2.remoteApi
|
|
379543
|
+
});
|
|
379544
|
+
if (!persister.ok)
|
|
379545
|
+
return { ok: false, diagnostics: persister.diagnostics, compiled: stagedTarget.preflight };
|
|
379546
|
+
onUploaded = persister.value.persist;
|
|
379547
|
+
}
|
|
379548
|
+
const vaultAssets = await (0, sync_1.uploadPreparedWorkflowVaultAssets)({
|
|
379549
|
+
assets: stagedTarget.vaultPlans,
|
|
379550
|
+
vaultApi: options2.remoteApi,
|
|
379551
|
+
...onUploaded === void 0 ? {} : { onUploaded }
|
|
379552
|
+
});
|
|
379553
|
+
if (!vaultAssets.ok)
|
|
379554
|
+
return { ok: false, diagnostics: vaultAssets.diagnostics, compiled: stagedTarget.preflight };
|
|
379555
|
+
const compiled = (0, compiler_1.transpileWorkflow)({
|
|
379556
|
+
targetName: stagedTarget.name,
|
|
379557
|
+
workflowKey: stagedTarget.target.workflowKey,
|
|
379558
|
+
title: stagedTarget.target.title,
|
|
379559
|
+
declaration: stagedTarget.source.declaration,
|
|
379560
|
+
source: stagedTarget.source.source,
|
|
377657
379561
|
vaultAssets: vaultAssets.value
|
|
377658
379562
|
});
|
|
377659
379563
|
if (compiled.diagnostics.some((item) => item.severity === "error"))
|
|
377660
379564
|
return { ok: false, diagnostics: [...compiled.diagnostics], compiled };
|
|
377661
379565
|
prepared.push({
|
|
377662
|
-
|
|
379566
|
+
name: stagedTarget.name,
|
|
379567
|
+
target: stagedTarget.target,
|
|
379568
|
+
identity: stagedTarget.identity,
|
|
377663
379569
|
compiled,
|
|
377664
379570
|
vaultAssets: vaultAssets.value
|
|
377665
379571
|
});
|
|
@@ -377871,30 +379777,14 @@ var require_sync3 = __commonJS({
|
|
|
377871
379777
|
const existing = await (0, state_1.readLockfile)(lockPath.value);
|
|
377872
379778
|
if (!existing.ok && existing.diagnostics[0]?.code !== "state.lockfile.missing")
|
|
377873
379779
|
return { ok: false, diagnostics: existing.diagnostics, compiled: initialSymbolic };
|
|
377874
|
-
const vaultAssets = await (0, sync_1.prepareWorkflowVaultAssets)({
|
|
377875
|
-
rootDir: options2.projectDir,
|
|
377876
|
-
assets: initialSymbolic.resources.vaultAssets ?? [],
|
|
377877
|
-
existing: existing.ok ? existing.value.lockfile.vaultAssets : void 0,
|
|
377878
|
-
vaultApi: options2.vaultApi
|
|
377879
|
-
});
|
|
377880
|
-
if (!vaultAssets.ok)
|
|
377881
|
-
return { ok: false, diagnostics: vaultAssets.diagnostics, compiled: initialSymbolic };
|
|
377882
|
-
const symbolic = (0, compiler_1.transpileWorkflow)({
|
|
377883
|
-
targetName: selected.name,
|
|
377884
|
-
workflowKey: selected.target.workflowKey,
|
|
377885
|
-
title: selected.target.title,
|
|
377886
|
-
declaration: sourceResult.value.declaration,
|
|
377887
|
-
source: sourceResult.value.source,
|
|
377888
|
-
vaultAssets: vaultAssets.value
|
|
377889
|
-
});
|
|
377890
|
-
if (symbolic.diagnostics.some((item) => item.severity === "error"))
|
|
377891
|
-
return { ok: false, diagnostics: [...symbolic.diagnostics], compiled: symbolic };
|
|
377892
379780
|
symbolicPrepared.push({
|
|
377893
379781
|
...selected,
|
|
377894
379782
|
source: sourceResult.value,
|
|
377895
|
-
symbolic,
|
|
377896
|
-
compiled:
|
|
377897
|
-
vaultAssets:
|
|
379783
|
+
symbolic: initialSymbolic,
|
|
379784
|
+
compiled: initialSymbolic,
|
|
379785
|
+
vaultAssets: [],
|
|
379786
|
+
...existing.ok ? { lockfile: existing.value.lockfile } : {},
|
|
379787
|
+
...existing.ok ? { lockfileState: existing.value } : {},
|
|
377898
379788
|
identity: {
|
|
377899
379789
|
contextKey: identity2.value.contextKey,
|
|
377900
379790
|
contextId: identity2.value.contextId,
|
|
@@ -377905,7 +379795,7 @@ var require_sync3 = __commonJS({
|
|
|
377905
379795
|
}
|
|
377906
379796
|
const needsCatalog = options2.catalogApi !== void 0 || symbolicPrepared.some((item) => item.symbolic.remoteRefs.length > 0);
|
|
377907
379797
|
if (!needsCatalog)
|
|
377908
|
-
return {
|
|
379798
|
+
return await prepareVaultAssetsForTargets({ ...options2, remoteApi: options2.vaultApi }, symbolicPrepared);
|
|
377909
379799
|
let api;
|
|
377910
379800
|
try {
|
|
377911
379801
|
api = options2.catalogApi ?? await (0, catalog_1.createWorkflowCatalogApi)();
|
|
@@ -377928,19 +379818,12 @@ var require_sync3 = __commonJS({
|
|
|
377928
379818
|
}
|
|
377929
379819
|
const prepared = [];
|
|
377930
379820
|
for (const item of symbolicPrepared) {
|
|
377931
|
-
const facts = factsForPrepared(item);
|
|
377932
|
-
const lockPath = (0, state_1.deriveLockfilePath)(options2.rootDir, facts);
|
|
377933
|
-
if (!lockPath.ok)
|
|
377934
|
-
return { ok: false, diagnostics: lockPath.diagnostics, compiled: item.symbolic };
|
|
377935
|
-
const existing = await (0, state_1.readLockfile)(lockPath.value);
|
|
377936
|
-
if (!existing.ok && existing.diagnostics[0]?.code !== "state.lockfile.missing")
|
|
377937
|
-
return { ok: false, diagnostics: existing.diagnostics, compiled: item.symbolic };
|
|
377938
379821
|
const initialGenerated = (0, catalog_1.validateAndLockRemoteRefs)({
|
|
377939
379822
|
contextId: snapshot.context.id,
|
|
377940
379823
|
workspaceId: snapshot.context.workspaceId,
|
|
377941
379824
|
snapshot,
|
|
377942
379825
|
refs: item.symbolic.remoteRefs,
|
|
377943
|
-
existing:
|
|
379826
|
+
existing: item.lockfile?.generatedMetadata
|
|
377944
379827
|
});
|
|
377945
379828
|
if (initialGenerated.diagnostics.some((diagnostic) => diagnostic.severity === "error"))
|
|
377946
379829
|
return { ok: false, diagnostics: [...initialGenerated.diagnostics], compiled: item.symbolic };
|
|
@@ -377958,26 +379841,87 @@ var require_sync3 = __commonJS({
|
|
|
377958
379841
|
workspaceId: snapshot.context.workspaceId,
|
|
377959
379842
|
snapshot,
|
|
377960
379843
|
refs: compiled.remoteRefs,
|
|
377961
|
-
existing:
|
|
379844
|
+
existing: item.lockfile?.generatedMetadata
|
|
377962
379845
|
});
|
|
377963
379846
|
const diagnostics = [...generated.diagnostics, ...compiled.diagnostics];
|
|
377964
|
-
if (diagnostics.some((diagnostic) => diagnostic.severity === "error"))
|
|
379847
|
+
if (diagnostics.some((diagnostic) => diagnostic.severity === "error" && diagnostic.code !== "vault.asset.missing_lock"))
|
|
377965
379848
|
return { ok: false, diagnostics, compiled };
|
|
377966
|
-
prepared.push({
|
|
379849
|
+
prepared.push({
|
|
379850
|
+
...item,
|
|
379851
|
+
generatedMetadata: generated.locks,
|
|
379852
|
+
remote: { kind: "resolved", snapshot, locks: generated.locks.refs },
|
|
379853
|
+
compiled
|
|
379854
|
+
});
|
|
377967
379855
|
}
|
|
377968
|
-
return {
|
|
379856
|
+
return await prepareVaultAssetsForTargets({ ...options2, remoteApi: options2.vaultApi }, prepared);
|
|
377969
379857
|
}
|
|
377970
|
-
function
|
|
377971
|
-
|
|
377972
|
-
|
|
377973
|
-
|
|
377974
|
-
|
|
377975
|
-
|
|
377976
|
-
|
|
377977
|
-
|
|
377978
|
-
|
|
379858
|
+
async function prepareVaultAssetsForTargets(options2, targets) {
|
|
379859
|
+
const staged = [];
|
|
379860
|
+
for (const target of targets) {
|
|
379861
|
+
const vaultAssets = await (0, sync_1.prepareWorkflowVaultAssetUploads)({
|
|
379862
|
+
rootDir: options2.projectDir,
|
|
379863
|
+
assets: target.symbolic.resources.vaultAssets ?? [],
|
|
379864
|
+
existing: target.lockfile?.vaultAssets
|
|
379865
|
+
});
|
|
379866
|
+
if (!vaultAssets.ok)
|
|
379867
|
+
return { ok: false, diagnostics: vaultAssets.diagnostics, compiled: target.compiled };
|
|
379868
|
+
const preflight = (0, compiler_1.transpileWorkflow)({
|
|
379869
|
+
targetName: target.name,
|
|
379870
|
+
workflowKey: target.target.workflowKey,
|
|
379871
|
+
title: target.target.title,
|
|
379872
|
+
declaration: target.source.declaration,
|
|
379873
|
+
source: target.source.source,
|
|
379874
|
+
...target.remote === void 0 ? {} : { remote: target.remote },
|
|
379875
|
+
vaultAssets: (0, sync_1.snapshotPreparedWorkflowVaultAssets)(vaultAssets.value)
|
|
379876
|
+
});
|
|
379877
|
+
if (preflight.diagnostics.some((item) => item.severity === "error"))
|
|
379878
|
+
return { ok: false, diagnostics: [...preflight.diagnostics], compiled: preflight };
|
|
379879
|
+
staged.push({ target, vaultAssets: vaultAssets.value });
|
|
379880
|
+
}
|
|
379881
|
+
const prepared = [];
|
|
379882
|
+
for (const item of staged) {
|
|
379883
|
+
let onUploaded;
|
|
379884
|
+
if (item.vaultAssets.some((asset) => asset.previous === void 0)) {
|
|
379885
|
+
const persister = await (0, sync_1.createWorkflowVaultAssetLockPersister)({
|
|
379886
|
+
cwd: options2.rootDir,
|
|
379887
|
+
facts: {
|
|
379888
|
+
targetName: item.target.name,
|
|
379889
|
+
workflowKey: item.target.symbolic.workflowKey,
|
|
379890
|
+
context: {
|
|
379891
|
+
key: item.target.identity.contextKey ?? "default",
|
|
379892
|
+
...item.target.identity.contextId === void 0 ? {} : { id: item.target.identity.contextId },
|
|
379893
|
+
projectId: item.target.identity.projectId,
|
|
379894
|
+
promptId: item.target.identity.promptId
|
|
379895
|
+
}
|
|
379896
|
+
},
|
|
379897
|
+
existing: item.target.lockfileState,
|
|
379898
|
+
remoteApi: options2.remoteApi
|
|
379899
|
+
});
|
|
379900
|
+
if (!persister.ok)
|
|
379901
|
+
return { ok: false, diagnostics: persister.diagnostics, compiled: item.target.compiled };
|
|
379902
|
+
onUploaded = persister.value.persist;
|
|
377979
379903
|
}
|
|
377980
|
-
|
|
379904
|
+
const vaultAssets = await (0, sync_1.uploadPreparedWorkflowVaultAssets)({
|
|
379905
|
+
assets: item.vaultAssets,
|
|
379906
|
+
vaultApi: options2.vaultApi,
|
|
379907
|
+
...onUploaded === void 0 ? {} : { onUploaded }
|
|
379908
|
+
});
|
|
379909
|
+
if (!vaultAssets.ok)
|
|
379910
|
+
return { ok: false, diagnostics: vaultAssets.diagnostics, compiled: item.target.compiled };
|
|
379911
|
+
const compiled = (0, compiler_1.transpileWorkflow)({
|
|
379912
|
+
targetName: item.target.name,
|
|
379913
|
+
workflowKey: item.target.target.workflowKey,
|
|
379914
|
+
title: item.target.target.title,
|
|
379915
|
+
declaration: item.target.source.declaration,
|
|
379916
|
+
source: item.target.source.source,
|
|
379917
|
+
...item.target.remote === void 0 ? {} : { remote: item.target.remote },
|
|
379918
|
+
vaultAssets: vaultAssets.value
|
|
379919
|
+
});
|
|
379920
|
+
if (compiled.diagnostics.some((item2) => item2.severity === "error"))
|
|
379921
|
+
return { ok: false, diagnostics: [...compiled.diagnostics], compiled };
|
|
379922
|
+
prepared.push({ ...item.target, compiled, vaultAssets: vaultAssets.value });
|
|
379923
|
+
}
|
|
379924
|
+
return { ok: true, targets: prepared };
|
|
377981
379925
|
}
|
|
377982
379926
|
function renderSingleSyncResult(item) {
|
|
377983
379927
|
return {
|