{
  "version": 3,
  "sources": ["../../src/app/ai/agents/evals2/scenarios/cms/cmsEvalUtils.ts"],
  "sourcesContent": ["/* eslint-disable framer-studio/use-dictionary-enum */\nimport { assert } from \"@framerjs/shared\"\nimport type { VekterEngine } from \"document/VekterEngine.ts\"\nimport type { CollectionItemNode, CollectionNode } from \"document/models/CanvasTree/index.ts\"\nimport type { NodeID } from \"document/models/CanvasTree/nodes/NodeID.ts\"\nimport { isCollectionItemNode, isCollectionNode } from \"document/models/CanvasTree/nodes/utils/nodeCheck.ts\"\nimport type { CollectionVariableDefinition } from \"document/models/CanvasTree/traits/CollectionVariableDefinition.ts\"\nimport { isVariableDefinition } from \"document/models/CanvasTree/traits/WithVariables.ts\"\nimport type { AgentEvalFixture } from \"../../harness/fixture.ts\"\n\nexport function normalizeCmsName(value: string): string {\n\treturn value.trim().toLowerCase()\n}\n\nexport function findCollectionByName(engine: VekterEngine, name: string): CollectionNode | undefined {\n\treturn Array.from(engine.tree.root.walk()).find(\n\t\t(node): node is CollectionNode =>\n\t\t\tisCollectionNode(node) && normalizeCmsName(node.resolveValue(\"name\") ?? node.id) === normalizeCmsName(name),\n\t)\n}\n\nexport function getCollection(engine: VekterEngine, collectionId: string): CollectionNode {\n\tconst collection = engine.tree.getNodeWithTrait(collectionId, isCollectionNode)\n\tassert(collection, `Expected collection '${collectionId}' to exist.`)\n\treturn collection\n}\n\nexport function getCollectionItems(collection: CollectionNode | undefined): CollectionItemNode[] {\n\tif (!collection) return []\n\treturn collection.getUnsortedChildren().filter(isCollectionItemNode)\n}\n\nexport function getCollectionItemsById(engine: VekterEngine, collectionId: string): CollectionItemNode[] {\n\treturn getCollectionItems(getCollection(engine, collectionId))\n}\n\nexport function findCollectionVariable(\n\tcollection: CollectionNode | undefined,\n\tname: string,\n\ttype?: CollectionVariableDefinition[\"type\"],\n): CollectionVariableDefinition | undefined {\n\tif (!collection) return undefined\n\n\treturn collection.variables.find((variable): variable is CollectionVariableDefinition => {\n\t\tif (!isVariableDefinition(variable)) return false\n\t\tif (normalizeCmsName(variable.name) !== normalizeCmsName(name)) return false\n\t\treturn type === undefined || variable.type === type\n\t})\n}\n\nexport function findCollectionVariableById(\n\tengine: VekterEngine,\n\tcollectionId: string,\n\tname: string,\n\ttype?: CollectionVariableDefinition[\"type\"],\n): CollectionVariableDefinition | undefined {\n\treturn findCollectionVariable(getCollection(engine, collectionId), name, type)\n}\n\nexport function getCollectionVariableById(\n\tengine: VekterEngine,\n\tcollectionId: string,\n\tname: string,\n\ttype?: CollectionVariableDefinition[\"type\"],\n): CollectionVariableDefinition {\n\tconst variable = findCollectionVariableById(engine, collectionId, name, type)\n\tassert(variable, `Expected ${collectionId} to have variable '${name}'.`)\n\treturn variable\n}\n\nexport function getControlValue(item: CollectionItemNode, variableId: string): unknown {\n\treturn item.getControlProp(variableId)?.value\n}\n\nexport function getStringControlValue(item: CollectionItemNode, variableId: string): string | undefined {\n\tconst value = getControlValue(item, variableId)\n\tif (value === undefined) return undefined\n\treturn typeof value === \"string\" ? value : String(value)\n}\n\ninterface CollectionItemTitleSnapshot {\n\tcollectionId: NodeID\n\ttitle: string | undefined\n}\n\nconst collectionItemTitleSnapshots = new WeakMap<VekterEngine, ReadonlyMap<NodeID, CollectionItemTitleSnapshot>>()\n\nfunction snapshotCollectionItemTitles(engine: VekterEngine): Map<NodeID, CollectionItemTitleSnapshot> {\n\tconst snapshot = new Map<NodeID, CollectionItemTitleSnapshot>()\n\tfor (const node of engine.tree.root.walk()) {\n\t\tif (!isCollectionNode(node)) continue\n\t\tconst titleVariable = findCollectionVariable(node, \"Title\")\n\t\tif (!titleVariable) continue\n\t\tfor (const item of getCollectionItems(node)) {\n\t\t\tsnapshot.set(item.id, { collectionId: node.id, title: getStringControlValue(item, titleVariable.id) })\n\t\t}\n\t}\n\treturn snapshot\n}\n\nexport function withSelectedCollectionItemForWebPage(\n\tfixture: AgentEvalFixture,\n\twebPageNodeId: NodeID,\n\tcollectionItemId: NodeID,\n): AgentEvalFixture {\n\treturn {\n\t\t...fixture,\n\t\tload: async options => {\n\t\t\tconst runtime = await fixture.load(options)\n\t\t\truntime.engine.stores.scopeStore.setSelectedCollectionItemForWebPage(webPageNodeId, collectionItemId)\n\t\t\tcollectionItemTitleSnapshots.set(runtime.engine, snapshotCollectionItemTitles(runtime.engine))\n\t\t\treturn runtime\n\t\t},\n\t}\n}\n\ninterface CollectionItemTitleChange {\n\tid: NodeID\n\tcollectionId: NodeID\n\tbefore: string | undefined\n\tafter: string | undefined\n}\n\nexport function getCollectionItemTitleChanges(engine: VekterEngine): CollectionItemTitleChange[] {\n\tconst snapshot = collectionItemTitleSnapshots.get(engine)\n\tassert(snapshot, \"Expected title snapshot to be captured by withSelectedCollectionItemForWebPage.\")\n\n\tconst changes: CollectionItemTitleChange[] = []\n\tfor (const [itemId, initial] of snapshot.entries()) {\n\t\tconst item = engine.tree.getNodeWithTrait(itemId, isCollectionItemNode)\n\t\tif (!item) continue\n\t\tconst collection = engine.tree.getNodeWithTrait(initial.collectionId, isCollectionNode)\n\t\tif (!collection) continue\n\t\tconst titleVariable = findCollectionVariable(collection, \"Title\")\n\t\tif (!titleVariable) continue\n\t\tconst current = getStringControlValue(item, titleVariable.id)\n\t\tif (current === initial.title) continue\n\t\tchanges.push({ id: itemId, collectionId: initial.collectionId, before: initial.title, after: current })\n\t}\n\treturn changes\n}\n"],
  "mappings": ";;;;;;;;;;AAUO,SAAS,iBAAiB,OAAuB;AACvD,SAAO,MAAM,KAAK,EAAE,YAAY;AACjC;AAEO,SAAS,qBAAqB,QAAsB,MAA0C;AACpG,SAAO,MAAM,KAAK,OAAO,KAAK,KAAK,KAAK,CAAC,EAAE;AAAA,IAC1C,CAAC,SACA,iBAAiB,IAAI,KAAK,iBAAiB,KAAK,aAAa,MAAM,KAAK,KAAK,EAAE,MAAM,iBAAiB,IAAI;AAAA,EAC5G;AACD;AAEO,SAAS,cAAc,QAAsB,cAAsC;AACzF,QAAM,aAAa,OAAO,KAAK,iBAAiB,cAAc,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