Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions packages/ui/src/adapters/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ export class McpAdapter implements ProtocolAdapter {
// Keep defaults, overlay with host values when present.
const base = this.createDefaultContext();

const theme = ctx.theme === "dark" ? "dark" : ctx.theme === "light" ? "light" : base.theme;
let theme: "light" | "dark" = base.theme;
if (ctx.theme === "dark" || ctx.theme === "light") {
theme = ctx.theme;
}
const displayMode =
ctx.displayMode === "fullscreen" || ctx.displayMode === "pip" || ctx.displayMode === "inline"
? (ctx.displayMode as HostContext["displayMode"])
Expand Down Expand Up @@ -459,18 +462,12 @@ export class McpAdapter implements ProtocolAdapter {
}

// Fallback logging when MCP logging unavailable
const logMapping: Record<typeof level, typeof console.log> = {
// eslint-disable-next-line no-console
debug: console.debug,
// eslint-disable-next-line no-console
info: console.info,
// eslint-disable-next-line no-console
warning: console.warn,
// eslint-disable-next-line no-console
error: console.error,
};
// eslint-disable-next-line no-console
const logFn = logMapping[level] ?? console.log;
/* eslint-disable no-console */
const logFn =
{ debug: console.debug, info: console.info, warning: console.warn, error: console.error }[
level
] ?? console.log;
/* eslint-enable no-console */
logFn("[MCP Apps]", data);
}

Expand Down
19 changes: 6 additions & 13 deletions packages/ui/src/adapters/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,12 @@ export class MockAdapter implements ProtocolAdapter {
// === Logging ===

log(level: string, data: unknown): void {
// Mock adapter uses console for logging
const logMapping: Record<string, typeof console.log> = {
// eslint-disable-next-line no-console
debug: console.debug,
// eslint-disable-next-line no-console
info: console.info,
// eslint-disable-next-line no-console
warning: console.warn,
// eslint-disable-next-line no-console
error: console.error,
};
// eslint-disable-next-line no-console
const logFn = logMapping[level] ?? console.log;
/* eslint-disable no-console */
const logFn =
{ debug: console.debug, info: console.info, warning: console.warn, error: console.error }[
level
] ?? console.log;
/* eslint-enable no-console */
logFn("[MockAdapter]", data);
}

Expand Down
10 changes: 3 additions & 7 deletions packages/ui/src/adapters/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,14 +608,10 @@ export class OpenAIAdapter implements ProtocolAdapter {
log(level: string, data: unknown): void {
/* eslint-disable no-console */
const logFn =
{
debug: console.debug,
info: console.info,
warning: console.warn,
error: console.error,
}[level] ?? console.log;
{ debug: console.debug, info: console.info, warning: console.warn, error: console.error }[
level
] ?? console.log;
/* eslint-enable no-console */

logFn("[ChatGPT Apps]", data);
}

Expand Down
14 changes: 2 additions & 12 deletions packages/ui/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,10 @@ export function createAppsClient<T extends ToolDefs = ToolDefs>(
// === Files (Optional) ===

...(adapter.uploadFile && {
uploadFile: (file: File) => {
if (adapter.uploadFile) {
return adapter.uploadFile(file);
}
throw new Error("uploadFile not supported");
},
uploadFile: adapter.uploadFile.bind(adapter),
}),
...(adapter.getFileDownloadUrl && {
getFileDownloadUrl: (fileId: string) => {
if (adapter.getFileDownloadUrl) {
return adapter.getFileDownloadUrl(fileId);
}
throw new Error("getFileDownloadUrl not supported");
},
getFileDownloadUrl: adapter.getFileDownloadUrl.bind(adapter),
}),

// === Resources ===
Expand Down
36 changes: 11 additions & 25 deletions packages/ui/src/detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,6 @@

import type { DetectedProtocol } from "./types";

/**
* Check if we're in a ChatGPT sandbox environment
*/
function isChatGPTSandbox(): boolean {
// Check URL patterns that indicate ChatGPT sandbox
const url = window.location.href;
if (url.includes("/api/apps/chatgpt/") || url.includes("chatgpt")) {
return true;
}

// Check for ChatGPT-specific sandbox proxy indicators
if (url.includes("sandbox-proxy") || url.includes("widget-content")) {
return true;
}

// Check referrer
const referrer = document.referrer;
if (referrer.includes("chatgpt") || referrer.includes("openai.com")) {
return true;
}

return false;
}

/**
* Detect the current host protocol
*
Expand All @@ -55,7 +31,17 @@ export function detectProtocol(): DetectedProtocol {
}

// Check for ChatGPT sandbox environment (SDK will be injected)
if (isChatGPTSandbox()) {
const url = window.location.href;
const referrer = document.referrer;
const isChatGPTSandbox =
url.includes("/api/apps/chatgpt/") ||
url.includes("chatgpt") ||
url.includes("sandbox-proxy") ||
url.includes("widget-content") ||
referrer.includes("chatgpt") ||
referrer.includes("openai.com");

if (isChatGPTSandbox) {
return "openai";
}

Expand Down
8 changes: 2 additions & 6 deletions packages/ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ export { detectProtocol } from "./detection";
// CLIENT FACTORY (INTERNAL)
// =============================================================================

export { createAppsClient } from "./client";

// =============================================================================
// CLIENT FACTORY
// =============================================================================

import type { AppsClient, CreateClientOptions, ToolDefs } from "./types";
import type { ProtocolAdapter } from "./adapters/types";
import { detectProtocol } from "./detection";
Expand All @@ -122,6 +116,8 @@ import { OpenAIAdapter } from "./adapters/openai";
import { createAppsClient } from "./client";
import { clientDebugLogger } from "./debug/logger";

export { createAppsClient } from "./client";

/**
* Create an adapter based on detected or forced protocol
*/
Expand Down