Files
orcs-code/src/hooks/usePromptsFromClaudeInChrome.tsx
Anandan 462a985d7e Remove embedded source map directives from tracked sources (#329)
Inline base64 source maps had been checked into tracked src files. This strips those comments from the repository without changing runtime behavior or adding ongoing guardrails, per the requested one-time cleanup scope.

Constraint: Keep this change limited to tracked source cleanup only
Rejected: Add CI/source verification guard | user requested one-time cleanup only
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: If these directives reappear, fix the producing transform instead of reintroducing repo-side cleanup code
Tested: rg -n "sourceMappingURL" ., bun run smoke, bun run verify:privacy, bun run test:provider, npm run test:provider-recommendation
Not-tested: bun run typecheck (repository has many pre-existing unrelated failures)

Co-authored-by: anandh8x <test@example.com>
2026-04-04 21:19:27 +08:00

71 lines
2.4 KiB
TypeScript

import { c as _c } from "react-compiler-runtime";
import type { ContentBlockParam } from '@anthropic-ai/sdk/resources/messages.mjs';
import { useEffect, useRef } from 'react';
import { logError } from 'src/utils/log.js';
import { z } from 'zod/v4';
import { callIdeRpc } from '../services/mcp/client.js';
import type { ConnectedMCPServer, MCPServerConnection } from '../services/mcp/types.js';
import type { PermissionMode } from '../types/permissions.js';
import { CLAUDE_IN_CHROME_MCP_SERVER_NAME, isTrackedClaudeInChromeTabId } from '../utils/claudeInChrome/common.js';
import { lazySchema } from '../utils/lazySchema.js';
import { enqueuePendingNotification } from '../utils/messageQueueManager.js';
// Schema for the prompt notification from Chrome extension (JSON-RPC 2.0 format)
const ClaudeInChromePromptNotificationSchema = lazySchema(() => z.object({
method: z.literal('notifications/message'),
params: z.object({
prompt: z.string(),
image: z.object({
type: z.literal('base64'),
media_type: z.enum(['image/jpeg', 'image/png', 'image/gif', 'image/webp']),
data: z.string()
}).optional(),
tabId: z.number().optional()
})
}));
/**
* A hook that listens for prompt notifications from the Claude for Chrome extension,
* enqueues them as user prompts, and syncs permission mode changes to the extension.
*/
export function usePromptsFromClaudeInChrome(mcpClients, toolPermissionMode) {
const $ = _c(6);
useRef(undefined);
let t0;
if ($[0] !== mcpClients) {
t0 = [mcpClients];
$[0] = mcpClients;
$[1] = t0;
} else {
t0 = $[1];
}
useEffect(_temp, t0);
let t1;
let t2;
if ($[2] !== mcpClients || $[3] !== toolPermissionMode) {
t1 = () => {
const chromeClient = findChromeClient(mcpClients);
if (!chromeClient) {
return;
}
const chromeMode = toolPermissionMode === "bypassPermissions" ? "skip_all_permission_checks" : "ask";
callIdeRpc("set_permission_mode", {
mode: chromeMode
}, chromeClient);
};
t2 = [mcpClients, toolPermissionMode];
$[2] = mcpClients;
$[3] = toolPermissionMode;
$[4] = t1;
$[5] = t2;
} else {
t1 = $[4];
t2 = $[5];
}
useEffect(t1, t2);
}
function _temp() {}
function findChromeClient(clients: MCPServerConnection[]): ConnectedMCPServer | undefined {
return clients.find((client): client is ConnectedMCPServer => client.type === 'connected' && client.name === CLAUDE_IN_CHROME_MCP_SERVER_NAME);
}