{"version":3,"file":"instructions.mjs","names":[],"sources":["../../../../src/plugins/A2UI/instructions.ts"],"sourcesContent":["// What teaches an agent's model to write A2UI, and what checks what it is shown. It runs the\n// A2UI core alone, without the React renderer, so it runs on a server or in a build too.\nimport {\n  Catalog,\n  type ComponentApi,\n  getComponentReferences,\n  MAX_GLOBAL_DEPTH,\n  MessageProcessor,\n  RELAXED_VALIDATION,\n} from '@a2ui/web_core';\nimport { basicCatalog } from '@a2ui/web_core/catalogs/basic/v1';\n\nimport type { AIUIComponent } from '../AIComponents/GenerativeUI/AIUIComponent';\nimport type { AIUIComponentDefinition } from '../AIComponents/GenerativeUI/AIUIComponentDefinition';\nimport { isRecord } from '../AIComponents/GenerativeUI/AIUIHelpers';\nimport {\n  A2UI_PROTOCOL_OVERVIEW,\n  type A2UIInstructionsConfig,\n  A2UIInstructionsError,\n  blocksIn,\n  fenceOf,\n  sorted,\n  toolLine,\n  TOOLS_INTRODUCTION,\n  writing,\n} from './A2UIInstructions';\nimport { A2UI_VERSION, a2uiMessagesIn, normalizeA2UIMessage } from './A2UIStream';\nimport {\n  A2UI_DEFAULT_CATALOG_ID,\n  A2UI_LEGACY_CATALOG_ID,\n  a2uiAppCatalogDocument,\n} from './catalogDocument';\n\ntype Entry = ComponentApi;\n\nconst definitionOf = (component: AIUIComponent | AIUIComponentDefinition) =>\n  'definition' in component ? component.definition : component;\n\n/**\n * The catalog an agent writes with: the basic catalog, or what `keep` names of it without what\n * `remove` names, and the app's components, but one named like a basic component it keeps.\n */\nexport const a2uiCatalogFor = ({\n  catalogId = A2UI_DEFAULT_CATALOG_ID,\n  components = [],\n  keep,\n  remove = [],\n}: Pick<A2UIInstructionsConfig, 'catalogId' | 'components' | 'keep' | 'remove'> = {}) => {\n  const kept = keep && new Set(keep);\n  const removed = new Set(remove);\n  const ofBasic = (names: Iterable<string>) =>\n    [...names].filter((name) => (!kept || kept.has(name)) && !removed.has(name));\n  const basicComponents = ofBasic(basicCatalog.components.keys());\n  const definitions = components.map(definitionOf);\n  const app = definitions.length\n    ? [\n        ...Catalog.fromJson(\n          a2uiAppCatalogDocument(catalogId, definitions, { bindings: false }),\n          A2UI_VERSION,\n        ).components.values(),\n      ].filter(({ name }) => !basicComponents.includes(name))\n    : [];\n  // The catalog's guidelines, without its examples: they name the basic catalog rather than\n  // this one, and components `keep` may leave out.\n  const guidelines = basicCatalog.instructions?.split('\\n## Examples')[0].trim();\n  return (basicCatalog as unknown as Catalog<Entry>).derive({\n    catalogId,\n    components: [...basicComponents, ...app],\n    functions: ofBasic(basicCatalog.functions.keys()),\n    ...(guidelines ? { instructions: guidelines } : {}),\n  });\n};\n\n/**\n * The instructions that teach an agent's model to write A2UI the app's renderer shows, in\n * Markdown: how a reply carries its UI, the protocol, the catalog's guidelines and the catalog\n * itself with the app's components, then what `config` adds. The same as StreamChatA2UI's\n * `A2UIInstructions`. Throws an `A2UIInstructionsError` when an example would not render.\n */\nexport const a2uiInstructionsText = (config: A2UIInstructionsConfig = {}) => {\n  const catalog = a2uiCatalogFor(config);\n  const fence = fenceOf(config.fence);\n  const broken = (config.examples ?? []).flatMap((example) =>\n    blocksIn(example, fence).flatMap((block) =>\n      a2uiProblemsWith(block, catalog).map((problem) => `example: ${problem}`),\n    ),\n  );\n  if (broken.length) throw new A2UIInstructionsError(broken);\n  const { instructions, ...document } = catalog.toJson() as Record<string, unknown>;\n  const { examples = [], notes = [], preamble, rules = [], tools = [] } = config;\n  return [\n    ...(preamble ? [preamble] : []),\n    writing(fence, catalog.id),\n    A2UI_PROTOCOL_OVERVIEW,\n    ...(typeof instructions === 'string' && instructions ? [instructions] : []),\n    ...(notes.length ? [`## The app's components\\n\\n${notes.join('\\n')}`] : []),\n    ...(tools.length\n      ? [`${TOOLS_INTRODUCTION}\\n\\n${tools.map(toolLine).join('\\n')}`]\n      : []),\n    `## The catalog \\`${catalog.id}\\`\\n\\n\\`\\`\\`json\\n${JSON.stringify(sorted(document))}\\n\\`\\`\\``,\n    ...(rules.length\n      ? [`## Rules\\n\\n${rules.map((rule, index) => `${index + 1}. ${rule}`).join('\\n')}`]\n      : []),\n    ...(examples.length ? [`## Examples\\n\\n${examples.join('\\n\\n')}`] : []),\n  ].join('\\n\\n');\n};\n\ntype Components = Map<string, Record<string, unknown>>;\n\nconst MESSAGE_KINDS = [\n  'createSurface',\n  'updateComponents',\n  'updateDataModel',\n  'deleteSurface',\n  'callRendererFunction',\n  'agentFunctionResponse',\n];\n\nconst componentsOf = (value: unknown) =>\n  Array.isArray(value) ? value.filter(isRecord) : [];\n\nconst duplicates = (components: Record<string, unknown>[], surfaceId: string) => {\n  const seen = new Set<unknown>();\n  const repeated = new Set<unknown>();\n  for (const { id } of components) {\n    if (seen.has(id)) repeated.add(id);\n    seen.add(id);\n  }\n  return [...repeated].map(\n    (id) => `surface ${surfaceId} defines ${String(id)} more than once in one message`,\n  );\n};\n\n/**\n * What is wrong with the A2UI messages of `text` for a renderer with `catalog`, or nothing\n * when they render as written: messages it can't read, components it doesn't have or that don't\n * fit their schemas, and references that lead nowhere. As StreamChatA2UI's `A2UIProgram`, with\n * each component checked against its schema by the A2UI core as a renderer checks it.\n */\nexport const a2uiProblemsWith = (text: string, catalog: Catalog<Entry>) => {\n  const problems: string[] = [];\n  const surfaces = new Map<string, Components>();\n  let created = false;\n  for (const raw of a2uiMessagesIn(text)) {\n    let json: unknown;\n    try {\n      json = JSON.parse(raw);\n    } catch {\n      json = undefined;\n    }\n    if (!isRecord(json)) {\n      problems.push(`this isn't JSON: ${raw.slice(0, 80)}`);\n      continue;\n    }\n    const message = normalizeA2UIMessage(json, catalog.id);\n    const kind = MESSAGE_KINDS.find((name) => name in message);\n    const body = kind ? message[kind] : undefined;\n    const surfaceId = isRecord(body) ? body.surfaceId : undefined;\n    if (!kind) {\n      problems.push(`this isn't an A2UI message: ${raw.slice(0, 80)}`);\n    } else if (kind === 'callRendererFunction' || kind === 'agentFunctionResponse') {\n      problems.push(\"a reply's UI calls no functions\");\n    } else if (typeof surfaceId !== 'string' || !isRecord(body)) {\n      problems.push(`a ${kind} names no surfaceId`);\n    } else if (kind === 'createSurface') {\n      if (surfaces.has(surfaceId)) {\n        problems.push(\n          `surface ${surfaceId} is created again: delete it first, or change it with updateComponents and updateDataModel`,\n        );\n        continue;\n      }\n      created = true;\n      const components = componentsOf(body.components);\n      problems.push(...duplicates(components, surfaceId));\n      // The renderer with the default id also shows the default's former id.\n      const named = body.catalogId;\n      const isFormerDefault =\n        catalog.id === A2UI_DEFAULT_CATALOG_ID && named === A2UI_LEGACY_CATALOG_ID;\n      if (typeof named === 'string' && named !== catalog.id && !isFormerDefault) {\n        problems.push(\n          `surface ${surfaceId} names the catalog ${body.catalogId}, not ${catalog.id}`,\n        );\n      }\n      surfaces.set(\n        surfaceId,\n        new Map(components.map((component) => [String(component.id), component])),\n      );\n    } else if (kind === 'updateComponents') {\n      const kept = surfaces.get(surfaceId);\n      if (!kept) {\n        problems.push(`surface ${surfaceId} gets components before it is created`);\n        continue;\n      }\n      const components = componentsOf(body.components);\n      problems.push(...duplicates(components, surfaceId));\n      for (const component of components) kept.set(String(component.id), component);\n    } else if (kind === 'updateDataModel' && !surfaces.has(surfaceId)) {\n      problems.push(`surface ${surfaceId} gets data before it is created`);\n    } else if (kind === 'deleteSurface') {\n      // What a deleted surface held never shows; its id may be created again.\n      surfaces.delete(surfaceId);\n    }\n  }\n  if (!created) problems.push('nothing renders: there is no createSurface');\n  for (const [surfaceId, components] of surfaces) {\n    problems.push(...surfaceProblems(components, surfaceId, catalog));\n  }\n  return problems;\n};\n\n// Each component checked against its schema, by the A2UI core as a renderer checks it, then\n// what the surface's components make together.\nconst surfaceProblems = (\n  components: Components,\n  surfaceId: string,\n  catalog: Catalog<Entry>,\n) => {\n  const problems: string[] = [];\n  const processor = new MessageProcessor([catalog], undefined, {\n    reportErrorsOnly: true,\n  });\n  const config = { ...RELAXED_VALIDATION, allowUnknownElements: false };\n  processor.processMessagesWithErrors(\n    {\n      createSurface: { catalogId: catalog.id, surfaceId: 'lint' },\n      version: A2UI_VERSION,\n    },\n    { validationConfig: config },\n  );\n  const references = new Map<string, string[]>();\n  const ids = [...components.keys()].sort();\n  for (const id of ids) {\n    const component = components.get(id) as Record<string, unknown>;\n    const errors = processor.processMessagesWithErrors(\n      {\n        updateComponents: { components: [component], surfaceId: 'lint' },\n        version: A2UI_VERSION,\n      },\n      { validationConfig: config },\n    );\n    // A cycle is told once, with the depth, below.\n    for (const { error } of errors) {\n      if (error.code === 'RECURSION_LIMIT_EXCEEDED') continue;\n      problems.push(`${id}: ${String(error.message)}`);\n    }\n    let children: string[] = [];\n    try {\n      children = [...getComponentReferences(component, catalog)].map(([child]) => child);\n    } catch {\n      children = [];\n    }\n    references.set(id, children);\n  }\n  for (const [id, children] of references) {\n    for (const child of children) {\n      if (!components.has(child))\n        problems.push(`${id} holds ${child}, which is not defined`);\n    }\n  }\n  if (!components.has('root')) {\n    return [...problems, `surface ${surfaceId} has no component with the id root`];\n  }\n  const reached = new Set<string>();\n  const next = ['root'];\n  while (next.length) {\n    const id = next.pop() as string;\n    if (reached.has(id)) continue;\n    reached.add(id);\n    next.push(...(references.get(id) ?? []));\n  }\n  for (const id of ids) {\n    if (!reached.has(id)) problems.push(`${id} is defined but nothing holds it`);\n  }\n  return [...problems, ...nestingProblems(references, surfaceId)];\n};\n\n// A component that holds itself, directly or through others, never finishes rendering, and a\n// renderer stops at MAX_GLOBAL_DEPTH levels.\nconst nestingProblems = (references: Map<string, string[]>, surfaceId: string) => {\n  const problems: string[] = [];\n  const depths = new Map<string, number>();\n  const visiting = new Set<string>();\n  let reportedCycle = false;\n  const depthOf = (id: string): number => {\n    const known = depths.get(id);\n    if (known !== undefined) return known;\n    if (visiting.has(id)) {\n      if (!reportedCycle) {\n        problems.push(\n          `${id} holds itself through its children, so it never finishes rendering`,\n        );\n        reportedCycle = true;\n      }\n      return 0;\n    }\n    visiting.add(id);\n    const deepest = Math.max(\n      0,\n      ...(references.get(id) ?? []).filter((child) => references.has(child)).map(depthOf),\n    );\n    visiting.delete(id);\n    depths.set(id, deepest + 1);\n    return deepest + 1;\n  };\n  if (references.has('root') && depthOf('root') > MAX_GLOBAL_DEPTH) {\n    problems.push(\n      `surface ${surfaceId} nests components deeper than ${MAX_GLOBAL_DEPTH} levels`,\n    );\n  }\n  for (const id of [...references.keys()].sort()) depthOf(id);\n  return problems;\n};\n\n/** What is wrong with the A2UI messages of `text` for the catalog `config` makes, or nothing. */\nexport const a2uiProblemsIn = (\n  text: string,\n  config: Pick<\n    A2UIInstructionsConfig,\n    'catalogId' | 'components' | 'keep' | 'remove'\n  > = {},\n) => a2uiProblemsWith(text, a2uiCatalogFor(config));\n"],"mappings":";;;;;;;AAmCA,IAAM,gBAAgB,cACpB,gBAAgB,YAAY,UAAU,aAAa;;;;;AAMrD,IAAa,kBAAkB,EAC7B,YAAY,yBACZ,aAAa,CAAC,GACd,MACA,SAAS,CAAC,MACsE,CAAC,MAAM;CACvF,MAAM,OAAO,QAAQ,IAAI,IAAI,IAAI;CACjC,MAAM,UAAU,IAAI,IAAI,MAAM;CAC9B,MAAM,WAAW,UACf,CAAC,GAAG,KAAK,CAAC,CAAC,QAAQ,UAAU,CAAC,QAAQ,KAAK,IAAI,IAAI,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC;CAC7E,MAAM,kBAAkB,QAAQ,aAAa,WAAW,KAAK,CAAC;CAC9D,MAAM,cAAc,WAAW,IAAI,YAAY;CAC/C,MAAM,MAAM,YAAY,SACpB,CACE,GAAG,QAAQ,SACT,uBAAuB,WAAW,aAAa,EAAE,UAAU,MAAM,CAAC,GAAA,KAEpE,CAAC,CAAC,WAAW,OAAO,CACtB,CAAC,CAAC,QAAQ,EAAE,WAAW,CAAC,gBAAgB,SAAS,IAAI,CAAC,IACtD,CAAC;CAGL,MAAM,aAAa,aAAa,cAAc,MAAM,eAAe,CAAC,CAAC,EAAE,CAAC,KAAK;CAC7E,OAAQ,aAA2C,OAAO;EACxD;EACA,YAAY,CAAC,GAAG,iB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