MCPcopy Create free account
hub / github.com/ChatGPTBox-dev/chatGPTBox / executeApi

Function executeApi

src/background/index.mjs:352–512  ·  view source on GitHub ↗
(session, port, config)

Source from the content-addressed store, hash-verified

350}
351
352async function executeApi(session, port, config) {
353 console.log(
354 `[background] executeApi called for model: ${session.modelName}, apiMode: ${session.apiMode}`,
355 )
356 const redactedSession = redactSensitiveFields(session)
357 const redactedConfig = redactSensitiveFields(config)
358 console.debug('[background] Full session details (redacted):', redactedSession)
359 console.debug('[background] Full config details (redacted):', redactedConfig)
360 if (session.apiMode) {
361 console.debug(
362 '[background] Session apiMode details (redacted):',
363 redactSensitiveFields(session.apiMode),
364 )
365 }
366 try {
367 if (isUsingChatgptWebModel(session)) {
368 console.debug('[background] Using ChatGPT Web Model')
369 let tabId
370 if (
371 config.chatgptTabId &&
372 config.customChatGptWebApiUrl === defaultConfig.customChatGptWebApiUrl
373 ) {
374 try {
375 const tab = await Browser.tabs.get(config.chatgptTabId)
376 if (tab) tabId = tab.id
377 } catch (e) {
378 console.warn(
379 `[background] Failed to get ChatGPT tab with ID ${config.chatgptTabId}:`,
380 e.message,
381 )
382 }
383 }
384 if (tabId) {
385 console.debug(`[background] ChatGPT Tab ID ${tabId} found.`)
386 const hasMatchingProxy = Boolean(port.proxy && port._proxyTabId === tabId)
387 if (!hasMatchingProxy) {
388 if (port.proxy) {
389 console.debug(
390 `[background] Existing proxy tab ${port._proxyTabId} does not match ${tabId}; reconnecting.`,
391 )
392 } else {
393 console.debug('[background] port.proxy not found, calling setPortProxy.')
394 }
395 setPortProxy(port, tabId)
396 }
397 if (port.proxy && port._proxyTabId === tabId) {
398 if (hasMatchingProxy) {
399 console.debug('[background] Proxy already established; forwarding session.')
400 }
401 console.debug('[background] Posting message to proxy tab:', { session: redactedSession })
402 try {
403 port.proxy.postMessage({ session })
404 } catch (e) {
405 console.warn(
406 '[background] Error posting message to existing proxy tab in executeApi (ChatGPT Web Model):',
407 e,
408 '. Attempting to reconnect.',
409 { session: redactedSession },

Callers 1

index.mjsFile · 0.85

Calls 15

redactSensitiveFieldsFunction · 0.90
isUsingChatgptWebModelFunction · 0.90
getChatGptAccessTokenFunction · 0.90
isUsingClaudeWebModelFunction · 0.90
getClaudeSessionKeyFunction · 0.90
isUsingMoonshotWebModelFunction · 0.90
isUsingBingWebModelFunction · 0.90
getBingAccessTokenFunction · 0.90
isUsingModelNameFunction · 0.90

Tested by

no test coverage detected