Is it possible to have extension that would copy paste selected text in new chat in something like LibreChat or Open-WEBUI? Both of those are ChatGPT like apps that are hosted in docker and accessed through WEB URL. Idea is to start new conversation using whatever user has selected.
So quick update. Managed to get this to work however this is launching from Safari window and not maintaining proper format when there are multiple lines.
// #popclip
// name: LibreChat
// icon: librechat.png
// identifier: ai.librechat.popclip.module
// description: Send selected text to LibreChat to start a new chat.
// popclipVersion: 4586
// keywords: librechat ai
// entitlements: [network]
import axios from "axios"; // We can remove axios import as we are not making API calls anymore
export const options = [
{
identifier: "baseUrl",
label: "LibreChat Base URL",
type: "string",
defaultValue: "https://librechat.domain.com",
description: "Base URL of your LibreChat instance (e.g., https://your-librechat-url)"
},
{
identifier: "model",
label: "Model",
type: "string",
defaultValue: "llama3.2:8b",
description: "Model to use in LibreChat (e.g., llama3.2:8b)"
},
{
identifier: "endpoint",
label: "Endpoint",
type: "string",
defaultValue: "ollama",
description: "Endpoint to use (e.g., ollama)"
},
{
identifier: "textMode",
label: "Response Handling",
type: "multiple",
values: ["append", "copy"], // Removed 'replace' as it's less relevant for URL opening
valueLabels: ["Append URL", "Copy URL"], // Adjusted labels to reflect URL opening
defaultValue: "append",
description: "How to handle the LibreChat URL after opening (Append opens, Copy copies URL)"
}
] as const;
type Options = InferOptions<typeof options>;
const chat: ActionFunction<Options> = async (input, options) => {
try {
const baseUrl = options.baseUrl.endsWith('/') ? options.baseUrl.slice(0, -1) : options.baseUrl; // Ensure no trailing slash
// Construct the URL for a new chat
const encodedPrompt = encodeURIComponent(input.text.trim());
const url = `${baseUrl}/c/new?prompt=${encodedPrompt}&model=${options.model}&endpoint=${options.endpoint}`;
// Handle text mode options for URL
const copyUrl = options.textMode === "copy" || popclip.modifiers.shift; // Shift key also triggers "copy"
if (copyUrl) {
popclip.copyText(url); // Copy the URL to clipboard
popclip.showText("URL Copied"); // Indicate URL was copied
} else {
popclip.openUrl(url); // Default: Open the URL in browser
popclip.showSuccess(); // Indicate URL was opened
}
} catch (e) {
popclip.showText(`Error: ${String(e)}`); // More generic error message
}
};
export const actions: Action<Options>[] = [
{
title: "LibreChat",
code: chat,
}
];