{"version":3,"file":"auth.cjs","names":["GoogleAbstractedFetchClient","GoogleAuth"],"sources":["../src/auth.ts"],"sourcesContent":["import { Readable } from \"stream\";\nimport {\n  AbstractStream,\n  ensureAuthOptionScopes,\n  GoogleAbstractedClientOps,\n  GoogleAbstractedFetchClient,\n  GoogleConnectionParams,\n  JsonStream,\n  SseJsonStream,\n  SseStream,\n} from \"@langchain/google-common\";\nimport { GoogleAuth, GoogleAuthOptions } from \"google-auth-library\";\n\nexport class NodeAbstractStream implements AbstractStream {\n  private baseStream: AbstractStream;\n\n  constructor(baseStream: AbstractStream, data: Readable) {\n    this.baseStream = baseStream;\n    const decoder = new TextDecoder(\"utf-8\");\n    data.on(\"data\", (data) => {\n      const text = decoder.decode(data, { stream: true });\n      this.appendBuffer(text);\n    });\n    data.on(\"end\", () => {\n      const rest = decoder.decode();\n      this.appendBuffer(rest);\n      this.closeBuffer();\n    });\n  }\n\n  appendBuffer(data: string): void {\n    return this.baseStream.appendBuffer(data);\n  }\n\n  closeBuffer(): void {\n    return this.baseStream.closeBuffer();\n  }\n\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\n  nextChunk(): Promise<any> {\n    return this.baseStream.nextChunk();\n  }\n\n  get streamDone(): boolean {\n    return this.baseStream.streamDone;\n  }\n}\n\nexport class NodeJsonStream extends NodeAbstractStream {\n  constructor(data: Readable) {\n    super(new JsonStream(), data);\n  }\n}\n\nexport class NodeSseStream extends NodeAbstractStream {\n  constructor(data: Readable) {\n    super(new SseStream(), data);\n  }\n}\n\nexport class NodeSseJsonStream extends NodeAbstractStream {\n  constructor(data: Readable) {\n    super(new SseJsonStream(), data);\n  }\n}\n\nexport class GAuthClient extends GoogleAbstractedFetchClient {\n  gauth: GoogleAuth;\n\n  constructor(fields?: GoogleConnectionParams<GoogleAuthOptions>) {\n    super();\n    const options = ensureAuthOptionScopes<GoogleAuthOptions>(\n      fields?.authOptions,\n      \"scopes\",\n      fields?.platformType\n    );\n    this.gauth = new GoogleAuth(options);\n    this._fetch = async (...args) => {\n      const url = args[0];\n      // eslint-disable-next-line @typescript-eslint/no-explicit-any\n      const opts: any = args[1] ?? {};\n      opts.responseType = \"stream\";\n      return await this.gauth.fetch(url, opts);\n    };\n  }\n\n  get clientType(): string {\n    return \"gauth\";\n  }\n\n  async getProjectId(): Promise<string> {\n    return this.gauth.getProjectId();\n  }\n\n  async request(opts: GoogleAbstractedClientOps): Promise<unknown> {\n    return this._request(opts?.url, opts, {});\n  }\n}\n"],"mappings":";;;AAkEA,IAAa,cAAb,cAAiCA,yBAAAA,4BAA4B;CAC3D;CAEA,YAAY,QAAoD;AAC9D,SAAO;AAMP,OAAK,QAAQ,IAAIC,oBAAAA,YAAAA,GAAAA,yBAAAA,wBAJf,QAAQ,aACR,UACA,QAAQ,aACT,CACmC;AACpC,OAAK,SAAS,OAAO,GAAG,SAAS;GAC/B,MAAM,MAAM,KAAK;GAEjB,MAAM,OAAY,KAAK,MAAM,EAAE;AAC/B,QAAK,eAAe;AACpB,UAAO,MAAM,KAAK,MAAM,MAAM,KAAK,KAAK;;;CAI5C,IAAI,aAAqB;AACvB,SAAO;;CAGT,MAAM,eAAgC;AACpC,SAAO,KAAK,MAAM,cAAc;;CAGlC,MAAM,QAAQ,MAAmD;AAC/D,SAAO,KAAK,SAAS,MAAM,KAAK,MAAM,EAAE,CAAC"}