{"version":3,"file":"AIClientIdentity.mjs","names":[],"sources":["../../../../../src/plugins/AIComponents/ToolCalls/AIClientIdentity.ts"],"sourcesContent":["import { nanoid } from 'nanoid';\n\nconst STORAGE_KEY = 'io.getstream.ai.client-id';\n\n// Used when the browser keeps nothing (storage blocked, private mode, server rendering), so\n// the id still holds for as long as the page lives.\nlet inMemoryId: string | undefined;\n\nconst createId = () =>\n  'web-' +\n  (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function'\n    ? crypto.randomUUID()\n    : nanoid());\n\nconst readStored = () => {\n  try {\n    return globalThis.localStorage?.getItem(STORAGE_KEY) ?? undefined;\n  } catch {\n    return undefined;\n  }\n};\n\nconst store = (id: string) => {\n  try {\n    globalThis.localStorage?.setItem(STORAGE_KEY, id);\n  } catch {\n    // Kept in memory only.\n  }\n};\n\n/**\n * A stable identifier for this install (this browser profile), for addressing client tool\n * calls to it. Put it in the custom data of the person's message (`client_id`) so the agent\n * can copy it onto the calls it makes while answering, and pass it to `AIToolApprover` as\n * `clientId`.\n */\nexport const AIClientIdentity = {\n  /**\n   * This install's identifier, created on first use and kept in `localStorage`. Where storage\n   * is unavailable it lives in memory, for as long as the page does.\n   */\n  installId(): string {\n    const saved = readStored() ?? inMemoryId;\n    if (saved) return saved;\n    const created = createId();\n    inMemoryId = created;\n    store(created);\n    return created;\n  },\n};\n"],"mappings":";;AAEA,IAAM,cAAc;AAIpB,IAAI;AAEJ,IAAM,iBACJ,UACC,OAAO,WAAW,eAAe,OAAO,OAAO,eAAe,aAC3D,OAAO,WAAW,IAClB,OAAO;AAEb,IAAM,mBAAmB;CACvB,IAAI;EACF,OAAO,WAAW,cAAc,QAAQ,WAAW,KAAK,KAAA;CAC1D,QAAQ;EACN;CACF;AACF;AAEA,IAAM,SAAS,OAAe;CAC5B,IAAI;EACF,WAAW,cAAc,QAAQ,aAAa,EAAE;CAClD,QAAQ,CAER;AACF;;;;;;;AAQA,IAAa,mBAAmB;;;;;AAK9B,YAAoB;CAClB,MAAM,QAAQ,WAAW,KAAK;CAC9B,IAAI,OAAO,OAAO;CAClB,MAAM,UAAU,SAAS;CACzB,aAAa;CACb,MAAM,OAAO;CACb,OAAO;AACT,EACF"}