@raycast/api
Version:
Build extensions for Raycast with React and Node.js.
1,411 lines (1,359 loc) • 293 kB
TypeScript
import { ForwardRefExoticComponent } from 'react';
import { FunctionComponent } from 'react';
import { JSX } from 'react/jsx-runtime';
import { PathLike } from 'fs';
import { ReactElement } from 'react';
import { ReactNode } from 'react';
import { RefAttributes } from 'react';
/**
* A context-specific action that can be performed by the user.
*
* @remarks
* Assign keyboard shortcuts to items to make it easier for users to perform frequently used actions.
*
* @example
* ```typescript
* import { ActionPanel, Action, List } from "@raycast/api";
*
* export default function Command() {
* return (
* <List navigationTitle="Open Pull Requests">
* <List.Item
* title="Docs: Update API Reference"
* subtitle="#1"
* actions={
* <ActionPanel title="#1 in raycast/extensions">
* <Action.OpenInBrowser url="https://github.com/raycast/extensions/pull/1" />
* <Action.CopyToClipboard title="Copy Pull Request Number" content="#1" />
* <Action title="Close Pull Request" onAction={() => console.log("Close PR #1")} />
* </ActionPanel>
* }
* />
* </List>
* );
* }
* ```
*/
export declare const Action: FunctionComponent<ActionProps> & ConvenienceActions & {
Style: typeof ActionStyle;
};
export declare namespace Action {
export type Props = ActionProps;
export type Style = ActionStyle;
export namespace CopyToClipboard {
/**
* Props of the {@link Action.CopyToClipboard} React component.
*/
export type Props = CopyToClipboardProps;
}
export namespace CreateQuicklink {
/**
* Props of the {@link Action.CreateQuicklink} React component.
*/
export type Props = CreateQuicklinkProps;
}
export namespace CreateSnippet {
/**
* Props of the {@link Action.CreateSnippet} React component.
*/
export type Props = CreateSnippetProps;
}
export namespace InstallMCPServer {
/**
* Props of the {@link Action.InstallMCPServer} React component.
*/
export type Props = InstallMCPServerProps;
}
export namespace Open {
/**
* Props of the {@link Action.Open} React component.
*/
export type Props = OpenProps;
}
export namespace OpenInBrowser {
/**
* Props of the {@link Action.OpenInBrowser} React component.
*/
export type Props = OpenInBrowserProps;
}
export namespace OpenWith {
/**
* Props of the {@link Action.OpenWith} React component.
*/
export type Props = OpenWithProps;
}
export namespace Paste {
/**
* Props of the {@link Action.Paste} React component.
*/
export type Props = PasteProps;
}
export namespace Push {
/**
* Props of the {@link Action.Push} React component.
*/
export type Props = PushProps;
}
export namespace ShowInFinder {
/**
* Props of the {@link Action.ShowInFinder} React component.
*/
export type Props = ShowInFinderProps;
}
export namespace SubmitForm {
/**
* Props of the {@link Action.SubmitForm} React component.
*/
export type Props<T extends Form.Values> = SubmitFormProps<T>;
}
export namespace Trash {
/**
* Props of the {@link Action.Trash} React component.
*/
export type Props = TrashProps;
}
export namespace ToggleQuickLook {
/**
* Props of the {@link Action.ToggleQuickLook} React component.
*/
export type Props = ToggleQuickLookProps;
}
export namespace PickDate {
/**
* Props of the {@link Action.PickDate} React component.
*/
export type Props = PickDateProps;
/**
* The types of date components the user can pick
* * `Date` - only year, month, and day can be picked
* * `DateTime` - hour and second can be picked in addition to year, month and day
*/
export type Type = DatePickerType_2;
}
}
/**
* Exposes a list of actions that can be performed by the user.
*
* @remarks
* Often items are context-aware, e.g. based on the selected list item. Actions can be grouped into semantic
* sections and can have keyboard shortcuts assigned.
*
* The first and second action become the primary and secondary action. They automatically get the default keyboard shortcuts assigned.
* In {@link List}, {@link Grid}, and {@link Detail}, this is `↵` for the primary and `⌘` `↵` for the secondary action. In {@link Form} it's `⌘` `↵` for the primary and
* `⌘` `⇧` `↵` for the secondary.
* Keep in mind that while you can specify an alternative shortcut for the primary and secondary actions, it won't be displayed in the Action Panel.
*
* @example
* ```typescript
* import { ActionPanel, Action, List } from "@raycast/api";
*
* export default function Command() {
* return (
* <List navigationTitle="Open Pull Requests">
* <List.Item
* title="Docs: Update API Reference"
* subtitle="#1"
* actions={
* <ActionPanel title="#1 in raycast/extensions">
* <Action.OpenInBrowser url="https://github.com/raycast/extensions/pull/1" />
* <Action.CopyToClipboard
* title="Copy Pull Request URL"
* content="https://github.com/raycast/extensions/pull/1"
* />
* </ActionPanel>
* }
* />
* </List>
* );
* }
* ```
*/
export declare const ActionPanel: FunctionComponent<ActionPanelProps_2> & DeprecatedActionPanelMembers & ActionPanelMembers;
export declare namespace ActionPanel {
/**
* Props of the {@link ActionPanel} React component.
*/
export type Props = ActionPanelProps_2;
/**
* Supported children for the {@link ActionPanel} components.
*/
export type Children = ActionPanelChildren_2;
export namespace Section {
/**
* Props of the {@link ActionPanel.Section} React component.
*/
export type Props = SectionProps;
/**
* Supported children for the {@link ActionPanel.Section} component.
*/
export type Children = SectionChildren;
}
export namespace Submenu {
/**
* Props of the {@link ActionPanel.Submenu} React component.
*/
export type Props = SubmenuProps;
/**
* Supported children for the {@link ActionPanel.Submenu} components.
*/
export type Children = SubmenuChildren;
}
}
/**
* @deprecated Use {@link ActionPanel.Children} instead.
*/
export declare type ActionPanelChildren = ActionPanel.Children;
declare type ActionPanelChildren_2 = ReactElement<ActionPanel.Section.Props> | ReactElement<ActionPanel.Section.Props>[] | ActionPanel.Section.Children | null;
/**
* @deprecated Use {@link Action} instead.
*/
export declare const ActionPanelItem: FunctionComponent<ActionProps> & ConvenienceActions & {
Style: ActionStyle;
};
/**
* @deprecated Use {@link Action.Props} instead.
*/
export declare interface ActionPanelItemProps extends Action.Props {
}
declare interface ActionPanelMembers {
/**
* A group of visually separated items.
*
* @remarks
* Use sections when the {@link ActionPanel} contains a lot of actions to help guide the user to related actions.
* For example, create a section for all copy actions.
*
* @example
* ```typescript
* import { ActionPanel, Action, List } from "@raycast/api";
*
* export default function Command() {
* return (
* <List navigationTitle="Open Pull Requests">
* <List.Item
* title="Docs: Update API Reference"
* subtitle="#1"
* actions={
* <ActionPanel title="#1 in raycast/extensions">
* <ActionPanel.Section title="Copy">
* <Action.CopyToClipboard title="Copy Pull Request Number" content="#1" />
* <Action.CopyToClipboard
* title="Copy Pull Request URL"
* content="https://github.com/raycast/extensions/pull/1"
* />
* <Action.CopyToClipboard title="Copy Pull Request Title" content="Docs: Update API Reference" />
* </ActionPanel.Section>
* <ActionPanel.Section title="Danger zone">
* <Action title="Close Pull Request" onAction={() => console.log("Close PR #1")} />
* </ActionPanel.Section>
* </ActionPanel>
* }
* />
* </List>
* );
* }
* ```
*/
Section: typeof Section;
/**
* An action that replaces the current ActionPanel with its children when selected.
*
* @remarks
* This is handy when an action needs to select from a range of options. For example, to add a label to a GitHub pull request
* or an assignee to a todo.
*
* @example
* ```typescript
* import { ActionPanel, Color, Icon, List, Action } from "@raycast/api";
*
* export default function Command() {
* return (
* <List navigationTitle="Open Pull Requests">
* <List.Item
* title="Docs: Update API Reference"
* subtitle="#1"
* actions={
* <ActionPanel title="#1 in raycast/extensions">
* <ActionPanel.Submenu title="Add Label">
* <Action
* icon={{ source: Icon.Circle, tintColor: Color.Red }}
* title="Bug"
* onAction={() => console.log("Add bug label")}
* />
* <Action
* icon={{ source: Icon.Circle, tintColor: Color.Yellow }}
* title="Enhancement"
* onAction={() => console.log("Add enhancement label")}
* />
* <Action
* icon={{ source: Icon.Circle, tintColor: Color.Blue }}
* title="Help Wanted"
* onAction={() => console.log("Add help wanted label")}
* />
* </ActionPanel.Submenu>
* </ActionPanel>
* }
* />
* </List>
* );
* }
* ```
*/
Submenu: typeof Submenu;
}
/**
* @deprecated Use {@link ActionPanel.Props} instead.
*/
export declare interface ActionPanelProps extends ActionPanel.Props {
}
declare interface ActionPanelProps_2 {
/**
* Sections or Actions. If {@link Action} elements are specified, a default section is automatically created.
*/
children?: ReactNode;
/**
* The title displayed at the top of the panel
*/
title?: string;
}
/**
* @deprecated Use {@link ActionPanel.Section} instead.
*/
export declare const ActionPanelSection: typeof ActionPanel.Section;
/**
* @deprecated Use {@link ActionPanel.Section.Children} instead.
*/
export declare type ActionPanelSectionChildren = ActionPanel.Section.Children;
/**
* @deprecated Use {@link ActionPanel.Section.Props} instead.
*/
export declare interface ActionPanelSectionProps extends ActionPanel.Section.Props {
}
/**
* @deprecated No alternative :(
*/
export declare interface ActionPanelState {
/**
* @deprecated No alternative :(
*/
update: (actionPanel: ReactNode) => void;
}
/**
* @deprecated Use {@link ActionPanel.Submenu} instead.
*/
export declare const ActionPanelSubmenu: typeof ActionPanel.Submenu;
/**
* @deprecated Use {@link ActionPanel.Submenu.Props} instead.
*/
export declare interface ActionPanelSubmenuProps extends ActionPanel.Submenu.Props {
}
/**
* Props of the {@link Action} React component.
*/
declare interface ActionProps {
/**
* ID of the item.
* @deprecated - This is an internal prop which should not have been exposed. You can safely remove it.
*/
id?: string;
/**
* The title displayed for the Action.
*/
title: string;
/**
* The icon displayed for the Action.
*/
icon?: Image.ImageLike | undefined | null;
/**
* Defines the visual style of the Action.
*
* @remarks
* Use {@link Action.Style.Regular} for displaying a regular actions.
* Use {@link Action.Style.Destructive} when your action has something that user should be careful about.
* Use the confirmation {@link Alert} if the action is doing something that user cannot revert.
* @defaultValue {@link Action.Style.Regular}
*/
style?: ActionStyle;
/**
* The keyboard shortcut for the Action.
*
* @remarks
* The first and second action in an {@link ActionPanel} become the primary and secondary action. They automatically get the default keyboard shortcuts assigned.
* In {@link List}, {@link Grid} ,and {@link Detail}, this is `↵` for the primary and `⌘` `↵` for the secondary action. In {@link Form} it's `⌘` `↵` for the primary and `⌘` `⇧` `↵` for the secondary.
* Keep in mind that while you can specify an alternative shortcut for the primary and secondary actions, it won't be displayed in the Action Panel.
*/
shortcut?: Keyboard.Shortcut | undefined | null;
/**
* Callback that is triggered when the Action is selected.
*/
onAction?: () => void;
/**
* Indicates whether the Action should be focused automatically when the parent ActionPanel (or Actionpanel.Submenu) opens.
*/
autoFocus?: boolean;
}
/**
* Components that support an Action Panel.
*/
declare interface ActionsInterface {
/**
* A reference to an {@link ActionPanel}.
*/
actions?: ReactNode;
}
/**
* Defines the visual style of the Action.
*
* @remarks
* Use {@link Action.Style.Regular} for displaying a regular actions.
* Use {@link Action.Style.Destructive} when your action has something that user should be careful about.
* Use the confirmation {@link Alert} if the action is doing something that user cannot revert.
*/
declare enum ActionStyle {
Regular = "regular",
Destructive = "destructive"
}
export declare namespace AI {
/**
* Returns a prompt completion.
*
* @param prompt - The prompt to ask the AI.
* @param options - Options to control which and how the AI model should behave.
*
* @example
* ```typescript
* import { Detail, AI, LaunchProps } from "@raycast/api";
* import { usePromise } from "@raycast/utils";
* import { useState } from "react";
*
* export default function Command(props: LaunchProps<{ arguments: { prompt: string } }>) {
* const [data, setData] = useState("");
* const { isLoading } = usePromise(
* async (prompt) => {
* const stream = AI.ask(prompt);
* stream.on("data", (data) => {
* setData((x) => x + data);
* });
* await stream;
* },
* [props.arguments.prompt]
* );
*
* return <Detail isLoading={isLoading} markdown={data} />;
* }
* ```
*/
export function ask(prompt: string, options?: AskOptions): Promise<string> & {
on(event: "data", listener: (chunk: string) => void): void;
};
export type AskOptions = {
/**
* Concrete tasks, such as fixing grammar, require less creativity while open-ended questions, such as generating ideas, require more.
* If a number is passed, it needs to be in the range 0-2. For larger values, 2 will be used. For lower values, 0 will be used.
*/
creativity?: Creativity;
/**
* The AI model to use to answer to the prompt.
*/
model?: Model | __DeprecatedModelUnion;
/**
* Abort signal to cancel the request.
*/
signal?: AbortSignal;
};
/**
* Concrete tasks, such as fixing grammar, require less creativity while open-ended questions, such as generating ideas, require more.
* If a number is passed, it needs to be in the range 0-2. For larger values, 2 will be used. For lower values, 0 will be used.
*/
export type Creativity = "none" | "low" | "medium" | "high" | "maximum" | number;
/**
* The AI model to use to answer to the prompt.
* @defaultValue `AI.Model["OpenAI_GPT4o-mini"]`
*/
export enum Model {
OpenAI_GPT4 = "openai-gpt-4",
"OpenAI_GPT4-turbo" = "openai-gpt-4-turbo",
"OpenAI_GPT4.1" = "openai-gpt-4.1",
"OpenAI_GPT4.1-nano" = "openai-gpt-4.1-nano",
"OpenAI_GPT4.1-mini" = "openai-gpt-4.1-mini",
OpenAI_GPT4o = "openai-gpt-4o",
"OpenAI_GPT4o-mini" = "openai-gpt-4o-mini",
"OpenAI_o1-preview" = "openai_o1-o1-preview",
"OpenAI_o1-mini" = "openai_o1-o1-mini",
"OpenAI_o3-mini" = "openai_o1-o3-mini",
"OpenAI_o4-mini" = "openai_o1-o4-mini",
OpenAI_o1 = "openai_o1-o1",
OpenAI_o3 = "openai_o1-o3",
Anthropic_Claude_Haiku = "anthropic-claude-haiku",
Anthropic_Claude_Opus = "anthropic-claude-opus",
Anthropic_Claude_Sonnet = "anthropic-claude-sonnet",
"Anthropic_Claude_Sonnet_3.7" = "anthropic-claude-3-7-sonnet-latest",
Mistral_Nemo = "mistral-nemo",
Mistral_Large = "mistral-large",
Mistral_Small = "mistral-small",
Mistral_Codestral = "mistral-codestral",
Llama3_70B = "llama3-70b",
"Llama3.3_70B" = "groq-llama-3.3-70b-versatile",
"Llama3.1_8B" = "llama3.1-8b",
"Llama3.1_405B" = "llama3.1-405b",
"Llama4_Scout" = "groq-meta-llama/llama-4-scout-17b-16e-instruct",
Perplexity_Sonar = "perplexity-sonar",
Perplexity_Sonar_Pro = "perplexity-sonar-pro",
Perplexity_Sonar_Reasoning = "perplexity-sonar-reasoning",
Perplexity_Sonar_Reasoning_Pro = "perplexity-sonar-reasoning-pro",
DeepSeek_R1 = "together-deepseek-ai/DeepSeek-R1",
DeepSeek_V3 = "together-deepseek-ai/DeepSeek-V3",
"DeepSeek_R1_Distill_Llama_3.3_70B" = "groq-deepseek-r1-distill-llama-70b",
"Google_Gemini_2.0_Flash" = "google-gemini-2.0-flash",
"Google_Gemini_2.0_Flash_Thinking" = "google-gemini-2.0-flash-thinking",
"Google_Gemini_2.5_Flash" = "google-gemini-2.5-flash",
"Google_Gemini_2.5_Pro" = "google-gemini-2.5-pro",
xAI_Grok_2 = "xai-grok-2-latest",
xAI_Grok_3 = "xai-grok-3",
xAI_Grok_3_Mini = "xai-grok-3-mini",
/** @deprecated Use `AI.Model["OpenAI_GPT4o-mini"]` instead */
"OpenAI_GPT3.5-turbo-instruct" = "openai-gpt-4o-mini",
/** @deprecated Use `AI.Model.Llama3_70B` instead */
Llama2_70B = "llama2-70b",
/** @deprecated Use `AI.Model.Perplexity_Sonar` instead */
Perplexity_Sonar_Medium_Online = "perplexity-sonar",
/** @deprecated Use `AI.Model.Perplexity_Sonar` instead */
Perplexity_Sonar_Small_Online = "perplexity-sonar",
/** @deprecated Use `AI.Model.Llama3_70B` instead */
Codellama_70B_instruct = "codellama-70b-instruct",
/** @deprecated Use `AI.Model.Perplexity_Sonar` instead */
Perplexity_Llama3_Sonar_Large = "perplexity-sonar",
/** @deprecated Use `AI.Model.Perplexity_Sonar` instead */
Perplexity_Llama3_Sonar_Small = "perplexity-sonar",
/** @deprecated Use `AI.Model["OpenAI_GPT4o-mini"]` instead */
"OpenAI_GPT3.5-turbo" = "openai-gpt-4o-mini",
/** @deprecated Use `AI.Model["Llama3.3_70B"]` instead */
"Llama3.1_70B" = "groq-llama-3.3-70b-versatile",
/** @deprecated Use `AI.Model.Perplexity_Sonar_Pro` instead */
"Perplexity_Llama3.1_Sonar_Huge" = "perplexity-sonar-pro",
/** @deprecated Use `AI.Model.Perplexity_Sonar` instead */
"Perplexity_Llama3.1_Sonar_Large" = "perplexity-sonar",
/** @deprecated Use `AI.Model.Perplexity_Sonar` instead */
"Perplexity_Llama3.1_Sonar_Small" = "perplexity-sonar",
/** @deprecated Use `AI.Model.Mistral_Large` instead */
"Mistral_Large2" = "mistral-large",
/** @deprecated Use `AI.Model["DeepSeek_R1_Distill_Llama_3.3_70B"]` instead */
"Groq_DeepSeek_R1_Distill_Llama_3.3_70B" = "groq-deepseek-r1-distill-llama-70b",
/** @deprecated Use `AI.Model.Together_DeepSeek_R1` instead */
"Together_DeepSeek_R1" = "together-deepseek-ai/DeepSeek-R1",
/** @deprecated Use `AI.Model.Mistral_Nemo` instead */
"MixtraL_8x7B" = "mistral-nemo",
/** @deprecated Use `AI.Model["Google_Gemini_2.0_Flash"]` instead */
"Google_Gemini_1.5_Flash" = "google-gemini-1.5-flash",
/** @deprecated Use `AI.Model["Google_Gemini_2.0_Flash"]` instead */
"Google_Gemini_1.5_Pro" = "google-gemini-1.5-pro",
/** @deprecated Use `AI.Model.Mistral_Nemo` instead */
Mixtral_8x7B = "mistral-nemo",
/** @deprecated Use `AI.Model.Mistral_Nemo` instead */
"Qwen_2.5_32B" = "groq-qwen-2.5-32b"
}
/** @deprecated Use the `AI.Model` enum instead */
export type __DeprecatedModelUnion = "openai-gpt-3.5-turbo-instruct" | "openai-gpt-3.5-turbo" | "openai-gpt-4" | "openai-gpt-4-turbo" | "anthropic-claude-haiku" | "anthropic-claude-opus" | "anthropic-claude-sonnet" | "perplexity-sonar-medium-online" | "perplexity-sonar-small-online" | "llama2-70b" | "mixtral-8x7b" | "codellama-70b-instruct" | "gpt-3.5-turbo" | "gpt-3.5-turbo-instruct" | "gpt-4" | "text-davinci-003";
}
export declare namespace Alert {
/**
* The options to create an {@link Alert}.
*
* @example
* ```typescript
* import { confirmAlert, Alert } from "@raycast/api";
*
* export default async () => {
* const options: Alert.Options = {
* title: "Finished cooking",
* message: "Delicious pasta for lunch",
* primaryAction: {
* title: 'Do something',
* onAction: () => {
* // while you can register a handler for an action, it's more elegant
* // to use the `if (await confirmAlert(...)) { ... }` pattern
* console.log("The alert action has been triggered")
* }
* }
* };
* await confirmAlert(options);
* };
* ```
*/
export interface Options {
/**
* The icon of an alert to illustrate the action. Displayed on the top.
*/
icon?: Image.ImageLike;
/**
* The title of an alert. Displayed below the icon.
*/
title: string;
/**
* An additional message for an Alert. Useful to show more information, e.g. a confirmation message for a destructive action.
*/
message?: string;
/**
* The primary Action the user can take.
*/
primaryAction?: ActionOptions;
/**
* The Action to dismiss the alert. There usually shouldn't be any side effects when the user takes this action.
*/
dismissAction?: ActionOptions;
/**
* If set to true, the Alert will also display a `Do not show this message again` checkbox. When checked, the answer
* is persisted and directly returned to the extension the next time the alert should be shown, without the user
* actually seeing the alert.
*
* @remarks
* Once an alert is dismissed, a `Reset Confirmation Dialogs` button will appear in the command's settings pane,
* in case users want to reconsider their answers.
*/
rememberUserChoice?: boolean;
}
/**
* The options to create an {@link Alert} Action.
*/
export interface ActionOptions {
/**
* The title of the action.
*/
title: string;
/**
* The style of the action.
*/
style?: ActionStyle;
/**
* A callback called when the action is triggered.
*/
onAction?: () => void;
}
/**
* Defines the visual style of an Action of the Alert.
*
* @remarks
* Use {@link Alert.ActionStyle.Default} for confirmations of a positive action.
* Use {@link Alert.ActionStyle.Destructive} for confirmations of a destructive action (eg. deleting a file).
*/
export enum ActionStyle {
Default = "default",
Cancel = "cancel",
Destructive = "destructive"
}
}
/**
* @deprecated Use {@link Alert.ActionOptions} instead
*/
export declare interface AlertActionOptions extends Alert.ActionOptions {
}
/**
* @deprecated Use {@link Alert.ActionStyle} instead
*/
export declare const AlertActionStyle: typeof Alert.ActionStyle;
/**
* @deprecated Use {@link Alert.Options} instead
*/
export declare interface AlertOptions extends Alert.Options {
}
/**
* @deprecated Use {@link LocalStorage.allItems} instead
*/
export declare const allLocalStorageItems: typeof LocalStorage.allItems;
/**
* An object that represents a locally installed application on the system.
*
* @remarks
* It can be used to open files or folders in a specific application. Use {@link getApplications} or
* {@link getDefaultApplication} to get applications that can open a specific file or folder.
*/
export declare interface Application {
/**
* The display name of the application.
*/
name: string;
/**
* The localized name of the application.
*/
localizedName?: string;
/**
* The absolute path to the application bundle, e.g. `/Applications/Raycast.app`,
*/
path: string;
/**
* The bundle identifier of the application, e.g. `com.raycast.macos`.
*/
bundleId?: string;
}
/**
* A record type holding the arguments (entered in Raycast Root Search Bar) that have been passed to the command.
*/
declare interface Arguments {
/**
* The representation of arguments given that key here is the `name` defined in manifest file and value is the user's input
*/
[item: string]: any;
}
/** @deprecated Use {@link LaunchProps} directly */
export declare interface ArgumentsLaunchProps {
arguments?: Arguments;
}
export declare namespace BrowserExtension {
/**
* Get the content of an opened tab.
* @param options - Options to control which content to get.
* @returns A Promise that resolves with the content of the tab.
*
* @example
* ```typescript
* import { BrowserExtension } from "@raycast/api";
*
* export default async () => {
* const html = await BrowserExtension.getContent({ format: "html" });
* console.log(html);
* };
* ```
*/
export function getContent(options?: {
/**
* The format of the content.
*
* - `html`: `document.documentElement.outerHTML`
* - `text`: `document.body.innerText`
* - `markdown`: A heuristic to get the "content" of the document and convert it to markdown. Think of it as the "reader mode" of a browser.
*
* @defaultValue `html`
*/
format?: "html" | "text" | "markdown";
/**
* Only returns the content of the element that matches the [CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_selectors).
*
* If the selector matches multiple elements, only the first one is returned.
* If the selector doesn't match any element, an empty string is returned.
*
* When using a CSS selector, the `format` option can not be `markdown`.
*/
cssSelector?: string;
/**
* The ID of the tab to get the content from. If not specified, the content of the active tab of the focused window is returned.
*/
tabId?: number;
}): Promise<string>;
export interface Tab {
/**
* The ID of the tab. Tab IDs are unique within a browser session.
*/
id: number;
/**
* The URL the tab is displaying.
*/
url: string;
/**
* The title of the tab. It may also be `undefined` if the tab is loading.
*/
title?: string;
/**
* The URL of the tab's [favicon](https://developer.mozilla.org/en-US/docs/Glossary/Favicon). It may also be `undefined` if the tab is loading.
*/
favicon?: string;
/**
* Whether the tab is active in its window.
* There can only be one active tab per window but if there are multiple browser windows, there can be multiple active tabs.
*/
active: boolean;
}
/**
* Get the list of browser tabs.
* @returns A Promise that resolves with the list of tabs.
*
* @example
* ```typescript
* import { BrowserExtension } from "@raycast/api";
*
* export default async () => {
* const tabs = await BrowserExtension.getTabs();
* console.log(tabs);
* };
* ```
*/
export function getTabs(): Promise<Tab[]>;
}
/**
* Caching abstraction that stores data on disk and supports LRU (least recently used) access.
* Since extensions can only consume up to a max. heap memory size, the cache only maintains a lightweight index in memory
* and stores the actual data in separate files on disk in the extension's support directory.
*
* The Cache class provides CRUD-style methods (get, set, remove) to update and retrieve data synchronously based on a key.
* The data must be a string and it is up to the client to decide which serialization format to use.
* A typical use case would be to use `JSON.stringify` and `JSON.parse`.
*
* @remarks By default, the cache is shared between the entry points of an extension. Use {@link Cache.Options} to configure
* a `namespace` per command if needed (for example, set it to `environment.commandName`).
*
* @example
* ```typescript
* import { Cache } from "@raycast/api";
*
* const cache = new Cache();
* cache.set("items", JSON.stringify([{ id: "1", title: "Item 1" }]));
* console.log(JSON.parse(cache.get("items")));
* ```
*/
export declare class Cache {
static get STORAGE_DIRECTORY_NAME(): string;
static get DEFAULT_CAPACITY(): number;
private directory;
private namespace?;
private capacity;
private journal;
private storage;
private subscribers;
constructor(options?: Cache.Options);
/**
* @returns the full path to the directory where the data is stored on disk.
*/
get storageDirectory(): string;
/**
* @returns the data for the given key. If there is no data for the key, `undefined` is returned.
* @remarks If you want to just check for the existence of a key, use {@link has}.
*/
get(key: string): string | undefined;
/**
* @returns `true` if data for the key exists, `false` otherwise.
* @remarks You can use this method to check for entries without affecting the LRU access.
*/
has(key: string): boolean;
/**
* @returns `true` if the cache is empty, `false` otherwise.
*/
get isEmpty(): boolean;
/**
* Sets the data for the given key.
* If the data exceeds the configured `capacity`, the least recently used entries are removed.
* This also notifies registered subscribers (see {@link subscribe}).
*/
set(key: string, data: string): void;
/**
* Removes the data for the given key.
* This also notifies registered subscribers (see {@link subscribe}).
* @returns `true` if data for the key was removed, `false` otherwise.
*/
remove(key: string): boolean;
/**
* Clears all stored data.
* This also notifies registered subscribers (see {@link subscribe}) unless the `notifySubscribers` option is set to `false`.
*/
clear(options?: {
notifySubscribers: boolean;
}): void;
/**
* Registers a new subscriber that gets notified when cache data is set or removed.
* @returns a function that can be called to remove the subscriber.
*/
subscribe(subscriber: Cache.Subscriber): Cache.Subscription;
private maintainCapacity;
private notifySubscribers;
}
export declare namespace Cache {
/**
* The options for creating a new {@link Cache}.
*/
export interface Options {
/**
* If set, the Cache will be namespaced via a subdirectory.
* This can be useful to separate the caches for individual commands of an extension.
* By default, the cache is shared between the commands of an extension.
*/
namespace?: string;
/**
* The parent directory for the cache data.
* @deprecated this parameter will be removed in the future – use the default directory.
*/
directory?: string;
/**
* The capacity in bytes. If the stored data exceeds the capacity, the least recently used data is removed.
* The default capacity is 10 MB.
*/
capacity?: number;
}
export type Subscriber = (key: string | undefined, data: string | undefined) => void;
export type Subscription = () => void;
}
/**
* Report the provided exception to the Developer Hub.
* This helps in handling failures gracefully while staying informed about the occurrence of the failure.
*
* @param exception - The exception you want to report.
*/
export declare function captureException(exception: unknown): void;
/**
* See {@link Form.Checkbox}
*/
declare const Checkbox: ForwardRefExoticComponent<CheckboxProps & RefAttributes<CheckboxRef>>;
/**
* See {@link Form.Checkbox.Props}
*/
declare interface CheckboxProps extends FormItemProps_2<boolean> {
/**
* The label displayed on the right side of the checkbox.
*/
label: string;
}
/**
* Form.Checkbox Ref type.
*/
declare type CheckboxRef = FormItemRef;
/**
* @deprecated Use {@link Clipboard.clear} instead
*/
export declare const clearClipboard: typeof Clipboard.clear;
/**
* @deprecated Use {@link LocalStorage.clear} instead
*/
export declare const clearLocalStorage: typeof LocalStorage.clear;
/**
* Clear the text in the search bar.
*
* @param options - Can be used to control the behaviour after the search bar is cleared.
* @returns A Promise that resolves when the search bar is cleared.
*/
export declare function clearSearchBar(options?: {
/**
* Can be used to force scrolling to the top. Defaults to scrolling to the top after the
* the search bar was cleared.
*/
forceScrollToTop?: boolean;
}): Promise<void>;
export declare namespace Clipboard {
/**
* Copies content to the clipboard.
*
* @param content - The content to copy to the clipboard.
* @param options - Options for the copy operation.
* @returns A Promise that resolves when the content is copied to the clipboard.
*
* @example
* ```typescript
* import { Clipboard } from "@raycast/api";
*
* export default async () => {
* await Clipboard.copy("https://raycast.com");
*
* const textContent: Clipboard.Content = {
* text: "https://raycast.com",
* }
*
* await Clipboard.copy(textContent);
*
* const fileContent: Clipboard.Content = {
* file: "/path/to/file.pdf",
* }
*
* await Clipboard.copy(fileContent);
*
* await Clipboard.copy("SecretPassword", { concealed: true });
* };
* ```
*/
export function copy(content: string | number | Content, options?: CopyOptions): Promise<void>;
/**
* Clears the current clipboard contents.
*
* @returns A Promise that resolves when the clipboard is cleared.
*
* @example
* ```typescript
* import { Clipboard } from "@raycast/api";
*
* export default async () => {
* await Clipboard.clear();
* };
* ```
*/
export function clear(): Promise<void>;
/**
* Pastes content to the current selection of the frontmost application.
*
* @param content - The content to insert at the cursor.
* @returns A Promise that resolves when the content is pasted.
*
* @example
* ```typescript
* import { Clipboard } from "@raycast/api";
*
* export default async () => {
* await Clipboard.paste("I really like Raycast's API");
* };
* ```
*/
export function paste(content: string | number | Content): Promise<void>;
/**
* Reads the clipboard content as plain text, file name, or HTML.
*
* @param options - Options for the read operation.
* @returns A Promise that resolves when the clipboard content was read.
*
* @example
* ```typescript
* import { Clipboard } from "@raycast/api";
*
* export default async () => {
* const { text, file, html } = await Clipboard.read();
* console.log(text);
* console.log(file);
* console.log(html);
* };
* ```
*/
export function read(options?: {
/**
* Specify an offset to access the Clipboard History. Minimum value is 0, maximum value is 5.
*
* @defaultValue `0`
*/
offset?: number;
}): Promise<ReadContent>;
/**
* Reads the clipboard as plain text.
*
* @param options - Options for the readText operation.
* @returns A promise that resolves when the clipboard content was read as plain text.
*
* @example
* ```typescript
* import { Clipboard } from "@raycast/api";
*
* export default async () => {
* const text = await Clipboard.readText();
* console.log(text);
* };
* ```
*/
export function readText(options?: {
/**
* Specify an offset to access the Clipboard History. Minimum value is 0, maximum value is 5.
*
* @defaultValue `0`
*/
offset?: number;
}): Promise<string | undefined>;
/**
* Type of the content read from the {@link Clipboard}.
*
* @example
* ```typescript
* import { Clipboard } from "@raycast/api";
*
* const content: Clipboard.ReadContent = {
* text: "filename.pdf",
* file: "/path/to/filename.pdf",
* html: "<a href='/path/to/filename.pdf'>filename.pdf</p>",
* }
* ```
*/
export type ReadContent = {
text: string;
file?: string;
html?: string;
};
/**
* Type of the content copied and pasted to and from the {@link Clipboard}.
*
* @example
* ```typescript
* import { Clipboard } from "@raycast/api";
*
* const textContent: Clipboard.Content = {
* text: "text to copy",
* }
*
* const fileContent: Clipboard.Content = {
* file: "/path/to/file.pdf",
* }
* ```
*/
export type Content = {
/**
* The text representation of the content.
*/
text: string;
} | {
/**
* The file representation of the content.
*/
file: PathLike;
} | {
/**
* The HTML representation of the content.
*/
html: string;
/**
* The alternative text representation of the content.
*/
text?: string;
};
export type CopyOptions = {
/**
* @deprecated Use `concealed` instead.
*/
transient?: boolean;
/**
* Indicates whether the content be treated as confidential. If `true`, it will not be recorded in the Clipboard History.
*/
concealed?: boolean;
};
}
/**
* Closes the main Raycast window.
*
* @param options - Can be used to control the behaviour after closing the main window.
* @returns A Promise that resolves when the main window is closed.
*
* @example
* ```typescript
* import { closeMainWindow } from "@raycast/api";
* import { setTimeout } from "timers/promises";
*
* export default async () => {
* await setTimeout(1000);
* await closeMainWindow({ clearRootSearch: true });
* };
* ```
*/
export declare function closeMainWindow(options?: {
/**
* Clears the text in the root search bar and scrolls to the top
*
* @defaultValue `false`
*/
clearRootSearch?: boolean;
/**
* Defines the pop to root behavior ({@link PopToRootType}); the default is to to respect the user's "Pop to Root Search" preference in Raycast
*/
popToRootType?: PopToRootType;
}): Promise<void>;
/**
* The standard colors. Use those colors for consistency.
*
* @remarks
* The colors automatically adapt to the Raycast theme (light or dark).
*
* @example
* ```typescript
* import { Color, Icon, List } from "@raycast/api";
*
* export default function Command() {
* return (
* <List>
* <List.Item title="Blue" icon={{ source: Icon.Circle, tintColor: Color.Blue }} />
* <List.Item title="Green" icon={{ source: Icon.Circle, tintColor: Color.Green }} />
* <List.Item title="Magenta" icon={{ source: Icon.Circle, tintColor: Color.Magenta }} />
* <List.Item title="Orange" icon={{ source: Icon.Circle, tintColor: Color.Orange }} />
* <List.Item title="Purple" icon={{ source: Icon.Circle, tintColor: Color.Purple }} />
* <List.Item title="Red" icon={{ source: Icon.Circle, tintColor: Color.Red }} />
* <List.Item title="Yellow" icon={{ source: Icon.Circle, tintColor: Color.Yellow }} />
* <List.Item title="PrimaryText" icon={{ source: Icon.Circle, tintColor: Color.PrimaryText }} />
* <List.Item title="SecondaryText" icon={{ source: Icon.Circle, tintColor: Color.SecondaryText }} />
* </List>
* );
* };
* ```
*/
export declare enum Color {
Blue = "raycast-blue",
Green = "raycast-green",
Magenta = "raycast-magenta",
Orange = "raycast-orange",
Purple = "raycast-purple",
Red = "raycast-red",
Yellow = "raycast-yellow",
PrimaryText = "raycast-primary-text",
SecondaryText = "raycast-secondary-text"
}
export declare namespace Color {
/**
* Union type for the supported color types.
*
* {@link Color.Raw} will be dynamically adjusted to achieve high contrast with the Raycast user interface.
*
* @example
* ```typescript
* import { Color, Icon, List } from "@raycast/api";
*
* export default function Command() {
* return (
* <List>
* <List.Item title="Built-in color" icon={{ source: Icon.Circle, tintColor: Color.Red }} />
* <List.Item title="HEX" icon={{ source: Icon.Circle, tintColor: "#FF0000" }} />
* <List.Item title="Short HEX" icon={{ source: Icon.Circle, tintColor: "#F00" }} />
* <List.Item title="RGBA" icon={{ source: Icon.Circle, tintColor: "rgb(255, 0, 0)" }} />
* <List.Item title="RGBA Percentage" icon={{ source: Icon.Circle, tintColor: "rgb(255, 0, 0, 1.0)" }} />
* <List.Item title="HSL" icon={{ source: Icon.Circle, tintColor: "hsla(200, 20%, 33%, 0.2)" }} />
* <List.Item title="Keywords" icon={{ source: Icon.Circle, tintColor: "red" }} />
* </List>
* );
* };
* ```
*/
export type ColorLike = Color | Color.Dynamic | Color.Raw;
/**
* A dynamic color applies different colors depending on the active Raycast theme.
*
* @example
* ```typescript
* import { Color, Icon, List } from "@raycast/api";
*
* export default function Command() {
* return (
* <List>
* <List.Item title="Dynamic Tint Color" icon={{ source: Icon.Circle, tintColor: { light: "#FF01FF", dark: "#FFFF50", adjustContrast: true } }} />
* <List.Item title="Dynamic Tint Color" icon={{ source: Icon.Circle, tintColor: { light: "#FF01FF", dark: "#FFFF50" } }} />
* </List>
* );
* };
* ```
*/
export interface Dynamic {
/**
* The color which is used in light theme.
*/
light: Color.Raw;
/**
* The color which is used in dark theme.
*/
dark: Color.Raw;
/**
* Enables dynamic contrast adjustment for light and dark theme color.
*
* @remarks
* Colors different to the built-in {@link Color} can be dynamically adjusted to achieve high contrast with the
* Raycast user interface. This makes it easy to guarantee a good look and feel when you aren't in control of the
* color, e.g. get it via a network request.
*
* @defaultValue `true`
*/
adjustContrast?: boolean | undefined | null;
}
/**
* You can use any of the following color formats:
* - HEX, e.g `#FF0000`
* - Short HEX, e.g. `#F00`
* - RGBA, e.g. `rgb(255, 0, 0)`
* - RGBA Percentage, e.g. `rgb(255, 0, 0, 1.0)`
* - HSL, e.g. `hsla(200, 20%, 33%, 0.2)`
* - Keywords, e.g. `red`
*/
export type Raw = string;
/**
* @deprecated `Color.Brown` isn't part of the custom themes and might look off
* for some users. Use another color instead.
*/
const Brown: Color.Dynamic;
}
/**
* @deprecated Use {@link Color.ColorLike} instead
*/
export declare type ColorLike = Color.ColorLike;
/**
* Creates and shows a confirmation Alert with the given options.
*
* @param options - The options used to create the Alert.
* @returns A Promise that resolves to a boolean when the user triggers one of the actions.
* It will be `true` for the primary Action, `false` for the dismiss Action.
*
* @example
* ```typescript
* import { confirmAlert } from "@raycast/api";
*
* export default async () => {
* if (await confirmAlert({ title: "Are you sure?" })) {
* // do something
* }
* };
* ```
*/
export declare function confirmAlert(options: Alert.Options): Promise<boolean>;
declare interface ConvenienceActions {
/**
* Action that copies the content to the clipboard.
*
* @remarks
* The main window is closed, and a HUD is shown after the content was copied to the clipboard.
*
* @example
* ```typescript
* import { ActionPanel, Action, Detail } from "@raycast/api";
*
* export default function Command() {
* return (
* <Detail
* markdown="Press `⌘ + .` and share some love."
* actions={
* <ActionPanel>
* <Action.CopyToClipboard content="I ❤️ Raycast" shortcut={{ modifiers: ["cmd"], key: "." }} />
* </ActionPanel>
* }
* />
* );
* }
* ```
*/
CopyToClipboard: typeof CopyToClipboard;
/**
* An action to open a file or folder with a specific application, just as if you had double-clicked the
* file's icon.
*
* @remarks
* The main window is closed after the file is opened.
*
* @example
* ```typescript
* import { ActionPanel, Detail, Action } from "@raycast/api";
*
* export default function Command() {
* return (
* <Detail
* markdown="Check out your extension code."
* actions={
* <ActionPanel>
* <Action.Open title="Open Folder" target={__dirname} />
* </ActionPanel>
* }
* />
* );
* }
* ```
*/
Open: typeof Open;
/**
* Action that opens a URL in the default browser.
*
* @remarks
* The main window is closed after the URL is opened in the browser.
*
* @example
* ```typescript
* import { ActionPanel, Detail, Action } from "@raycast/api";
*
* export default function Command() {
* return (
* <Detail
* markdown="Join the gang!"
* actions={
* <ActionPanel>
* <Action.OpenInBrowser url="https://raycast.com/jobs" />
* </ActionPanel>
* }
* />
* );
* }
* ```
*/
OpenInBrowser: typeof OpenInBrowser;
/**
* Action that opens a file or folder with a specific application.
*
* @remarks
* The action opens a sub-menu with all applications that can open the file or folder.
* The main window is closed after the file is opened in the specified application.
*