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MAAO,CAAE,QADO,EAAmB,QAAW,QAAS,MAAE,GAC5B,gBAAmB,KAAK,gBAAiB,UAAa,KAAK,UAC5F,CACA,qBAAM,GACF,KAAM,kBAAmB,KAAK,QAC1B,MAAM,IAAI,UAAU,6BAExB,MAAM,EAAI,QAAQ,QAAQ,OAAO,CAAE,iBAAiB,EAAM,QAAS,CAAE,OAAQ,oCAAoC,KAAK,OAAsB,mBAAS,eAAgB,KAAM,IACrK,QAAiB,EAAE,IAAI,4CAC7B,IACI,KAAK,OAAsB,cAAI,EAAS,QAAQ,cAAc,KAAK,IAAI,MAAM,yCAAyC,GAAG,QAAQ,oCAAqC,IAAI,QAAQ,IAAK,IACvL,KAAK,OAAsB,cAAI,EAAS,KAAkB,YAC1D,KAAK,iBACT,CACA,MAAO,GACH,QAAQ,IAAI,4BACZ,QAAQ,IAAI,EAAS,KACzB,CACJ,EAEJ,QAAQ,QAAU","file":"/npm/tchatgpt@1.0.1/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/tchatgpt@1.0.1/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n    return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Chatbot = void 0;\nconst axios_1 = __importDefault(require(\"axios\"));\nconst uuid_1 = require(\"uuid\");\nclass Chatbot {\n    constructor(config, conversation_id = null) {\n        this.headers = {};\n        this.config = config;\n        this.conversation_id = conversation_id;\n        this.parent_id = this.generate_uuid();\n        this.refresh_headers();\n    }\n    reset_chat() {\n        this.conversation_id = null;\n        this.parent_id = this.generate_uuid();\n    }\n    refresh_headers() {\n        this.headers = {\n            \"Accept\": \"application/json\",\n            \"Authorization\": \"Bearer \" + this.config['Authorization'],\n            \"Content-Type\": \"application/json\"\n        };\n    }\n    generate_uuid() {\n        return (0, uuid_1.v4)();\n    }\n    async get_chat_response(prompt) {\n        const data = {\n            \"action\": \"next\",\n            \"messages\": [\n                { \"id\": this.generate_uuid(),\n                    \"role\": \"user\",\n                    \"content\": { \"content_type\": \"text\", \"parts\": [prompt] }\n                }\n            ],\n            \"conversation_id\": this.conversation_id,\n            \"parent_message_id\": this.parent_id,\n            \"model\": \"text-davinci-002-render\"\n        };\n        const response = await axios_1.default.post(\"https://chat.openai.com/backend-api/conversation\", data, { headers: this.headers });\n        let response2;\n        try {\n            response2 = response.data.split(\"\\n\").at(-5);\n        }\n        catch {\n            console.log(response.data);\n            throw new TypeError(\"Error: Response is not a text/event-stream\");\n        }\n        try {\n            response2 = response2?.slice(6);\n        }\n        catch {\n            console.log(response2);\n            throw new TypeError(\"Response is not in the correct format\");\n        }\n        response2 = JSON.parse(response2);\n        this.parent_id = response2[\"message\"][\"id\"];\n        this.conversation_id = response2[\"conversation_id\"];\n        const message = response2[\"message\"][\"content\"][\"parts\"][0];\n        return { 'message': message, 'conversation_id': this.conversation_id, 'parent_id': this.parent_id };\n    }\n    async refresh_session() {\n        if (!('session_token' in this.config)) {\n            throw new TypeError(\"No session token provided\");\n        }\n        const s = axios_1.default.create({ withCredentials: true, headers: { cookie: `__Secure-next-auth.session-token=${this.config['session_token']}; ` }, validateStatus: () => true });\n        const response = await s.get(\"https://chat.openai.com/api/auth/session\");\n        try {\n            this.config['session_token'] = response.headers[\"set-cookie\"].join(\"\").match(/__Secure-next-auth.session-token=.+?;/)[0].replace(\"__Secure-next-auth.session-token=\", \"\").replace(\";\", \"\");\n            this.config['Authorization'] = response.data[\"accessToken\"];\n            this.refresh_headers();\n        }\n        catch (e) {\n            console.log(\"Error refreshing session\");\n            console.log(response.data);\n        }\n    }\n}\nexports.Chatbot = Chatbot;\n"]}