Files
OmniRoute/src/shared/hooks/useCopyToClipboard.ts
diegosouzapw 71d14209a4 feat: OmniRoute v1.0.0 — Intelligent AI Gateway & Universal LLM Proxy
OmniRoute is an intelligent API gateway that unifies 20+ AI providers behind a single
OpenAI-compatible endpoint. Features include intelligent routing with 6 strategies,
multi-format translation (OpenAI/Claude/Gemini/Responses API), circuit breakers,
semantic caching, combo fallback chains, real-time health monitoring, and a full
dashboard with provider management, analytics, and CLI tool integration.

Key highlights:
- 20+ providers (Claude Code, Codex, Gemini CLI, GitHub Copilot, iFlow, Qwen, Kiro, etc.)
- 6 routing strategies (Fill First, Round Robin, P2C, Random, Least Used, Cost Optimized)
- Export/Import database backup with full archive support
- Translator Playground with 4 modes (Playground, Chat Tester, Test Bench, Live Monitor)
- 100% TypeScript across src/ and open-sse/
- Docker support with multi-stage builds
- Comprehensive documentation and 9 dashboard screenshots
2026-02-18 00:02:15 -03:00

62 lines
1.5 KiB
TypeScript

"use client";
import { useState, useCallback, useRef } from "react";
/**
* Fallback copy using legacy execCommand (works on HTTP)
*/
function fallbackCopy(text) {
const textarea = document.createElement("textarea");
textarea.value = text;
textarea.style.position = "fixed";
textarea.style.left = "-9999px";
textarea.style.top = "-9999px";
textarea.style.opacity = "0";
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
try {
document.execCommand("copy");
} catch {
// ignore
}
document.body.removeChild(textarea);
}
/**
* Hook for copy to clipboard with feedback
* @param {number} resetDelay - Time in ms before resetting copied state (default: 2000)
* @returns {{ copied: string|null, copy: (text: string, id?: string) => void }}
*/
export function useCopyToClipboard(resetDelay = 2000) {
const [copied, setCopied] = useState(null);
const timeoutRef = useRef(null);
const copy = useCallback(
async (text, id = "default") => {
try {
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(text);
} else {
fallbackCopy(text);
}
} catch {
fallbackCopy(text);
}
setCopied(id);
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
timeoutRef.current = setTimeout(() => {
setCopied(null);
}, resetDelay);
},
[resetDelay]
);
return { copied, copy };
}