Add yaak-actions crate for centralized action system

Implements a unified action system that serves as a single source of truth
for all operations in Yaak (Tauri app, CLI, plugins, deep links, MCP server).

Key features:
- ActionExecutor: Combined registry and execution engine with async RwLock
- ActionHandler: Trait-based handlers using async closures
- Context system: RequiredContext and CurrentContext for action availability
- Action groups: Organize related actions
- TypeScript bindings: Auto-generated via ts-rs for frontend use

Design highlights:
- Handlers are closures (no dependencies on other yaak crates)
- Registration requires both metadata and handler (prevents orphan actions)
- Flexible return values via serde_json::Value
- All methods are async using tokio

All 33 tests passing. Ready for integration with yaak-core and yaak-app.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Gregory Schier
2026-01-08 21:16:50 -08:00
parent c4ce458f79
commit 50b0e23d53
28 changed files with 1997 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
/**
* Availability status for an action.
*/
export type ActionAvailability = { "status": "available" } | { "status": "available-with-prompt",
/**
* Fields that will require prompting.
*/
prompt_fields: Array<string>, } | { "status": "unavailable",
/**
* Fields that are missing.
*/
missing_fields: Array<string>, } | { "status": "not-found" };
+13
View File
@@ -0,0 +1,13 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ActionGroupId } from "./ActionGroupId";
import type { ActionId } from "./ActionId";
import type { ActionScope } from "./ActionScope";
/**
* Errors that can occur during action operations.
*/
export type ActionError = { "type": "not-found" } & ActionId | { "type": "disabled", action_id: ActionId, reason: string, } | { "type": "invalid-scope", expected: ActionScope, actual: ActionScope, } | { "type": "timeout" } & ActionId | { "type": "plugin-error" } & string | { "type": "validation-error" } & string | { "type": "permission-denied" } & string | { "type": "cancelled" } | { "type": "internal" } & string | { "type": "context-missing",
/**
* The context fields that are missing.
*/
missing_fields: Array<string>, } | { "type": "group-not-found" } & ActionGroupId | { "type": "group-already-exists" } & ActionGroupId;
+10
View File
@@ -0,0 +1,10 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
/**
* Unique identifier for an action group.
*
* Format: `namespace:group-name`
* - Built-in: `yaak:export`
* - Plugin: `plugin.my-plugin:utilities`
*/
export type ActionGroupId = string;
+32
View File
@@ -0,0 +1,32 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ActionGroupId } from "./ActionGroupId";
import type { ActionScope } from "./ActionScope";
/**
* Metadata about an action group.
*/
export type ActionGroupMetadata = {
/**
* Unique identifier for this group.
*/
id: ActionGroupId,
/**
* Display name for the group.
*/
name: string,
/**
* Optional description of the group's purpose.
*/
description: string | null,
/**
* Icon to display for the group.
*/
icon: string | null,
/**
* Sort order for displaying groups (lower = earlier).
*/
order: number,
/**
* Optional scope restriction (if set, group only appears in this scope).
*/
scope: ActionScope | null, };
+18
View File
@@ -0,0 +1,18 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
/**
* Where an action group was registered from.
*/
export type ActionGroupSource = { "type": "builtin" } | { "type": "plugin",
/**
* Plugin reference ID.
*/
ref_id: string,
/**
* Plugin name.
*/
name: string, } | { "type": "dynamic",
/**
* Source identifier.
*/
source_id: string, };
+16
View File
@@ -0,0 +1,16 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ActionGroupMetadata } from "./ActionGroupMetadata";
import type { ActionMetadata } from "./ActionMetadata";
/**
* A group with its actions for UI rendering.
*/
export type ActionGroupWithActions = {
/**
* Group metadata.
*/
group: ActionGroupMetadata,
/**
* Actions in this group.
*/
actions: Array<ActionMetadata>, };
+10
View File
@@ -0,0 +1,10 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
/**
* Unique identifier for an action.
*
* Format: `namespace:category:name`
* - Built-in: `yaak:http-request:send`
* - Plugin: `plugin.copy-curl:http-request:copy`
*/
export type ActionId = string;
+54
View File
@@ -0,0 +1,54 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ActionGroupId } from "./ActionGroupId";
import type { ActionId } from "./ActionId";
import type { ActionScope } from "./ActionScope";
import type { RequiredContext } from "./RequiredContext";
/**
* Metadata about an action for discovery.
*/
export type ActionMetadata = {
/**
* Unique identifier for this action.
*/
id: ActionId,
/**
* Display label for the action.
*/
label: string,
/**
* Optional description of what the action does.
*/
description: string | null,
/**
* Icon name to display.
*/
icon: string | null,
/**
* The scope this action applies to.
*/
scope: ActionScope,
/**
* Keyboard shortcut (e.g., "Cmd+Enter").
*/
keyboardShortcut: string | null,
/**
* Whether the action requires a selection/target.
*/
requiresSelection: boolean,
/**
* Optional condition expression for when action is enabled.
*/
enabledCondition: string | null,
/**
* Optional group this action belongs to.
*/
groupId: ActionGroupId | null,
/**
* Sort order within a group (lower = earlier).
*/
order: number,
/**
* Context requirements for this action.
*/
requiredContext: RequiredContext, };
+10
View File
@@ -0,0 +1,10 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
/**
* Parameters passed to action handlers.
*/
export type ActionParams = {
/**
* Arbitrary JSON parameters.
*/
data: unknown, };
+23
View File
@@ -0,0 +1,23 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { InputPrompt } from "./InputPrompt";
/**
* Result of action execution.
*/
export type ActionResult = { "type": "success",
/**
* Optional data to return.
*/
data: unknown,
/**
* Optional message to display.
*/
message: string | null, } | { "type": "requires-input",
/**
* Prompt to show user.
*/
prompt: InputPrompt,
/**
* Continuation token.
*/
continuation_id: string, } | { "type": "cancelled" };
+6
View File
@@ -0,0 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
/**
* The scope in which an action can be invoked.
*/
export type ActionScope = "global" | "http-request" | "websocket-request" | "grpc-request" | "workspace" | "folder" | "environment" | "cookie-jar";
+18
View File
@@ -0,0 +1,18 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
/**
* Where an action was registered from.
*/
export type ActionSource = { "type": "builtin" } | { "type": "plugin",
/**
* Plugin reference ID.
*/
ref_id: string,
/**
* Plugin name.
*/
name: string, } | { "type": "dynamic",
/**
* Source identifier.
*/
source_id: string, };
+6
View File
@@ -0,0 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
/**
* The target entity for an action.
*/
export type ActionTarget = { "type": "none" } | { "type": "http-request", id: string, } | { "type": "websocket-request", id: string, } | { "type": "grpc-request", id: string, } | { "type": "workspace", id: string, } | { "type": "folder", id: string, } | { "type": "environment", id: string, } | { "type": "multiple", targets: Array<ActionTarget>, };
+6
View File
@@ -0,0 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
/**
* How strictly a context field is required.
*/
export type ContextRequirement = "not-required" | "optional" | "required" | "required-with-prompt";
+27
View File
@@ -0,0 +1,27 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ActionTarget } from "./ActionTarget";
/**
* Current context state from the application.
*/
export type CurrentContext = {
/**
* Current workspace ID (if any).
*/
workspaceId: string | null,
/**
* Current environment ID (if any).
*/
environmentId: string | null,
/**
* Currently selected target (if any).
*/
target: ActionTarget | null,
/**
* Whether a window context is available.
*/
hasWindow: boolean,
/**
* Whether the context provider can prompt for missing fields.
*/
canPrompt: boolean, };
+7
View File
@@ -0,0 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { SelectOption } from "./SelectOption";
/**
* A prompt for user input.
*/
export type InputPrompt = { "type": "text", label: string, placeholder: string | null, default_value: string | null, } | { "type": "select", label: string, options: Array<SelectOption>, } | { "type": "confirm", label: string, };
+23
View File
@@ -0,0 +1,23 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ContextRequirement } from "./ContextRequirement";
/**
* Specifies what context fields an action requires.
*/
export type RequiredContext = {
/**
* Action requires a workspace to be active.
*/
workspace: ContextRequirement,
/**
* Action requires an environment to be selected.
*/
environment: ContextRequirement,
/**
* Action requires a specific target entity (request, folder, etc.).
*/
target: ContextRequirement,
/**
* Action requires a window context (for UI operations).
*/
window: ContextRequirement, };
+6
View File
@@ -0,0 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
/**
* An option in a select prompt.
*/
export type SelectOption = { label: string, value: string, };