{"version":3,"file":"AIUIMedia.mjs","names":[],"sources":["../../../../../src/plugins/AIComponents/GenerativeUI/AIUIMedia.ts"],"sourcesContent":["/**\n * Decides what a reply's UI loads for an image, video or sound the agent linked to: the URL to\n * load, which may be another, or `null` not to load it. The agent writes these links, so one\n * could track the person or reach their network. The counterpart of `mediaURL` in StreamChatAI.\n */\nexport type AIUIMediaURL = (url: URL) => URL | string | null | undefined;\n\nconst PRIVATE_HOST =\n  /^(localhost|.*\\.localhost|.*\\.local|.*\\.internal|0\\.0\\.0\\.0|127\\.\\d+\\.\\d+\\.\\d+|10\\.\\d+\\.\\d+\\.\\d+|192\\.168\\.\\d+\\.\\d+|169\\.254\\.\\d+\\.\\d+|172\\.(1[6-9]|2\\d|3[01])\\.\\d+\\.\\d+|\\[(::1?|f[cd][0-9a-f]*:.*|fe[89ab][0-9a-f]*:.*|::ffff:.*)\\])$/i;\n\n/**\n * Whether `url` is a public web link: http or https, to a host that isn't this device or its\n * network, such as `localhost` or `192.168.1.1`.\n */\nexport const isPublicWebURL = (url: URL) =>\n  (url.protocol === 'http:' || url.protocol === 'https:') &&\n  !PRIVATE_HOST.test(url.hostname);\n\n/**\n * The media a reply's UI loads by default: public web links, and links to the page's own\n * site. Others, such as `data:` URLs or addresses on the person's network, don't load.\n */\nexport const aiUIPublicMediaURL: AIUIMediaURL = (url) =>\n  isPublicWebURL(url) ||\n  (typeof window !== 'undefined' && url.origin === window.location.origin)\n    ? url\n    : null;\n\n/**\n * The address to load for a link the agent wrote, as `mediaURL` decides it, or `undefined` not\n * to load anything. Renderers call it before they draw an image, video or sound.\n */\nexport const aiUIMediaSource = (\n  value: unknown,\n  mediaURL: AIUIMediaURL = aiUIPublicMediaURL,\n): string | undefined => {\n  if (typeof value !== 'string' || value.trim() === '') return undefined;\n  let url: URL;\n  try {\n    url = new URL(\n      value.trim(),\n      typeof window === 'undefined' ? undefined : window.location.href,\n    );\n  } catch {\n    return undefined;\n  }\n  const decided = mediaURL(url);\n  if (decided === null || decided === undefined) return undefined;\n  return typeof decided === 'string' ? decided : decided.href;\n};\n"],"mappings":";AAOA,IAAM,eACJ;;;;;AAMF,IAAa,kBAAkB,SAC5B,IAAI,aAAa,WAAW,IAAI,aAAa,aAC9C,CAAC,aAAa,KAAK,IAAI,QAAQ;;;;;AAMjC,IAAa,sBAAoC,QAC/C,eAAe,GAAG,KACjB,OAAO,WAAW,eAAe,IAAI,WAAW,OAAO,SAAS,SAC7D,MACA;;;;;AAMN,IAAa,mBACX,OACA,WAAyB,uBACF;CACvB,IAAI,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,IAAI,OAAO,KAAA;CAC7D,IAAI;CACJ,IAAI;EACF,MAAM,IAAI,IACR,MAAM,KAAK,GACX,OAAO,WAAW,cAAc,KAAA,IAAY,OAAO,SAAS,IAC9D;CACF,QAAQ;EACN;CACF;CACA,MAAM,UAAU,SAAS,GAAG;CAC5B,IAAI,YAAY,QAAQ,YAAY,KAAA,GAAW,OAAO,KAAA;CACtD,OAAO,OAAO,YAAY,WAAW,UAAU,QAAQ;AACzD"}