MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / addUnionBranch

Function addUnionBranch

packages/core/sdk/src/shape-inference.ts:154–164  ·  view source on GitHub ↗
(union: InferredShape, branch: InferredShape)

Source from the content-addressed store, hash-verified

152};
153
154const addUnionBranch = (union: InferredShape, branch: InferredShape): InferredShape => {
155 if (isUnknown(union) || isUnknown(branch)) return UNKNOWN;
156 const branches = [...(union.anyOf ?? [union])];
157 const index = branches.findIndex((existing) => existing.type === branch.type);
158 const next =
159 index === -1
160 ? [...branches, branch]
161 : branches.map((existing, i) => (i === index ? mergeShapes(existing, branch) : existing));
162 if (next.length > MAX_ANYOF) return UNKNOWN;
163 return next.length === 1 ? (next[0] ?? UNKNOWN) : { anyOf: next };
164};
165
166/**
167 * One tool's accumulated muscle memory: the merged shape plus enough

Callers 1

mergeShapesFunction · 0.85

Calls 2

isUnknownFunction · 0.85
mergeShapesFunction · 0.85

Tested by

no test coverage detected