{"version":3,"file":"utils.cjs","names":[],"sources":["../../src/runnables/utils.ts"],"sourcesContent":["import { StreamEvent } from \"../tracers/event_stream.js\";\nimport type { RunnableInterface } from \"./types.js\";\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isRunnableInterface(thing: any): thing is RunnableInterface {\n  return thing ? thing.lc_runnable : false;\n}\n\n/**\n * Utility to filter the root event in the streamEvents implementation.\n * This is simply binding the arguments to the namespace to make save on\n * a bit of typing in the streamEvents implementation.\n *\n * TODO: Refactor and remove.\n */\nexport class _RootEventFilter {\n  includeNames?: string[];\n\n  includeTypes?: string[];\n\n  includeTags?: string[];\n\n  excludeNames?: string[];\n\n  excludeTypes?: string[];\n\n  excludeTags?: string[];\n\n  constructor(fields: {\n    includeNames?: string[];\n    includeTypes?: string[];\n    includeTags?: string[];\n    excludeNames?: string[];\n    excludeTypes?: string[];\n    excludeTags?: string[];\n  }) {\n    this.includeNames = fields.includeNames;\n    this.includeTypes = fields.includeTypes;\n    this.includeTags = fields.includeTags;\n    this.excludeNames = fields.excludeNames;\n    this.excludeTypes = fields.excludeTypes;\n    this.excludeTags = fields.excludeTags;\n  }\n\n  includeEvent(event: StreamEvent, rootType: string): boolean {\n    let include =\n      this.includeNames === undefined &&\n      this.includeTypes === undefined &&\n      this.includeTags === undefined;\n    const eventTags = event.tags ?? [];\n\n    if (this.includeNames !== undefined) {\n      include = include || this.includeNames.includes(event.name);\n    }\n    if (this.includeTypes !== undefined) {\n      include = include || this.includeTypes.includes(rootType);\n    }\n    if (this.includeTags !== undefined) {\n      include =\n        include || eventTags.some((tag) => this.includeTags?.includes(tag));\n    }\n\n    if (this.excludeNames !== undefined) {\n      include = include && !this.excludeNames.includes(event.name);\n    }\n    if (this.excludeTypes !== undefined) {\n      include = include && !this.excludeTypes.includes(rootType);\n    }\n    if (this.excludeTags !== undefined) {\n      include =\n        include && eventTags.every((tag) => !this.excludeTags?.includes(tag));\n    }\n\n    return include;\n  }\n}\n\nexport const toBase64Url = (str: string): string => {\n  // Use btoa for compatibility, assume ASCII\n  const encoded = btoa(str);\n  return encoded.replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n};\n"],"mappings":";AAIA,SAAgB,oBAAoB,OAAwC;CAC1E,OAAO,QAAQ,MAAM,cAAc;AACrC;;;;;;;;AASA,IAAa,mBAAb,MAA8B;CAC5B;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA,YAAY,QAOT;EACD,KAAK,eAAe,OAAO;EAC3B,KAAK,eAAe,OAAO;EAC3B,KAAK,cAAc,OAAO;EAC1B,KAAK,eAAe,OAAO;EAC3B,KAAK,eAAe,OAAO;EAC3B,KAAK,cAAc,OAAO;CAC5B;CAEA,aAAa,OAAoB,UAA2B;EAC1D,IAAI,UACF,KAAK,iBAAiB,KAAA,KACtB,KAAK,iBAAiB,KAAA,KACtB,KAAK,gBAAgB,KAAA;EACvB,MAAM,YAAY,MAAM,QAAQ,CAAC;EAEjC,IAAI,KAAK,iBAAiB,KAAA,GACxB,UAAU,WAAW,KAAK,aAAa,SAAS,MAAM,IAAI;EAE5D,IAAI,KAAK,iBAAiB,KAAA,GACxB,UAAU,WAAW,KAAK,aAAa,SAAS,QAAQ;EAE1D,IAAI,KAAK,gBAAgB,KAAA,GACvB,UACE,WAAW,UAAU,MAAM,QAAQ,KAAK,aAAa,SAAS,GAAG,CAAC;EAGtE,IAAI,KAAK,iBAAiB,KAAA,GACxB,UAAU,WAAW,CAAC,KAAK,aAAa,SAAS,MAAM,IAAI;EAE7D,IAAI,KAAK,iBAAiB,KAAA,GACxB,UAAU,WAAW,CAAC,KAAK,aAAa,SAAS,QAAQ;EAE3D,IAAI,KAAK,gBAAgB,KAAA,GACvB,UACE,WAAW,UAAU,OAAO,QAAQ,CAAC,KAAK,aAAa,SAAS,GAAG,CAAC;EAGxE,OAAO;CACT;AACF;AAEA,MAAa,eAAe,QAAwB;CAGlD,OADgB,KAAK,GACR,CAAC,CAAC,QAAQ,OAAO,GAAG,CAAC,CAAC,QAAQ,OAAO,GAAG,CAAC,CAAC,QAAQ,OAAO,EAAE;AAC1E"}