MCPcopy
hub / github.com/gencay/vscode-chatgpt / prepareConversation

Method prepareConversation

src/chatgpt-view-provider.ts:82–112  ·  view source on GitHub ↗
(reset?: boolean)

Source from the content-addressed store, hash-verified

80 }
81
82 private async prepareConversation(reset?: boolean): Promise<boolean> {
83 this.sessionToken = await this.context.globalState.get("chatgpt-session-token") as string;
84
85 if (this.sessionToken == null) {
86 await vscode.window
87 .showInputBox({
88 title: "OpenAPI ChatpGPT session token",
89 prompt: "Please enter your OpenAPI session token (__Secure-next-auth.session-token). See Readme for more details on how to get the session token",
90 ignoreFocusOut: true,
91 placeHolder: "Enter the JWT Token starting with ey***"
92 })
93 .then((value) => {
94 reset = true;
95 this.sessionToken = value!;
96 this.context.globalState.update("chatgpt-session-token", this.sessionToken);
97 });
98 }
99
100 if (reset || this.chatGptApi == null || this.chatGptConversation == null) {
101 try {
102 this.chatGptApi = new ChatGPTAPI({ sessionToken: this.sessionToken });
103 this.chatGptConversation = this.chatGptApi.getConversation();
104 } catch (error: any) {
105 vscode.window.showErrorMessage("Failed to instantiate the ChatGPT API. Try ChatGPT: Clear session", error?.message);
106 this.sendMessage({ type: 'addError' });
107 return false;
108 }
109 }
110
111 return true;
112 }
113
114 public async sendApiRequest(prompt: string, code?: string) {
115 await this.prepareConversation();

Callers 2

resolveWebviewViewMethod · 0.95
sendApiRequestMethod · 0.95

Calls 1

sendMessageMethod · 0.95

Tested by

no test coverage detected