Index of every page on this site: llms.txt
All skills
masheev avatar

/masheev-client-tools

@21d3a39
by masheevmasheev/skills1 stars
Run it yourself

Use when defining client-side tools that the Masheev AI agent can invoke in the browser. Covers ClientToolDefinition with JSON Schema and Zod, the execute function with progress reporting, approval flows (needsApproval), rich responses (cards, quick replies), tool registration via init() and updateTools(), and the action:invoke / action:result event flow. Use this skill when someone asks to "add tools to the chat", "let the AI call my functions", "create client tools", or "give the AI access to my app data".

Use this Skill: https://skilld.dev/gh/masheev/skills/masheev-client-tools

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈134 tokens for metadata: the name and description. ≈1.3k when used: this file. ≈2.2k more on demand in 1 file.

Description uses 6.7% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈536 characters, or 6.7%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Masheev Client Tools

Client tools let the AI agent call functions running in the user's browser. The AI decides when to use a tool based on its name and description, executes it via the SDK, and uses the result to continue the conversation.

How It Works

  1. You define tools with a name, description, JSON Schema parameters, and an execute function
  2. The SDK sends tool definitions to the server when the session starts
  3. During conversation, the AI decides to invoke a tool
  4. The SDK calls your execute function in the browser
  5. The result is sent back to the AI, which uses it to respond

Defining Tools

With Zod (recommended)

import { clientTool } from "@masheev/embed-sdk/headless";
import { z } from "zod";

const searchProducts = clientTool({
  name: "search_products",
  description: "Search the product catalog by query, category, or price range",
  parameters: z.object({
    query: z.string().describe("Search keywords"),
    category: z.string().optional().describe("Product category"),
    maxPrice: z.number().optional().describe("Maximum price in USD"),
  }),
  execute: async (args, { onProgress }) => {
    onProgress("Searching products...");
    const results = await fetch(`/api/products?q=${args.query}`).then((r) => r.json());
    return {
      success: true,
      data: { products: results.slice(0, 5) },
      display: "card",
      components: {
        card: {
          title: `Found ${results.length} products`,
          fields: results.slice(0, 3).map((p) => ({ label: p.name, value: `$${p.price}` })),
        },
        quickReplies: [
          { label: "Show more", value: "Show me more results" },
          { label: "Filter by price", value: "Only show products under $50" },
        ],
      },
    };
  },
});

With JSON Schema

const searchProducts: ClientToolDefinition = {
  name: "search_products",
  description: "Search the product catalog",
  parameters: {
    type: "object",
    properties: {
      query: { type: "string", description: "Search keywords" },
      category: { type: "string", description: "Product category" },
      maxPrice: { type: "number", description: "Max price in USD" },
    },
    required: ["query"],
  },
  execute: async (args, { onProgress }) => {
    // ... same as above
  },
};

Registration

At initialization

init({
  inboxId: "YOUR_INBOX_ID",
  tools: [searchProducts, checkInventory, addToCart],
  instructions: "Use search_products when the user asks about products. Use addToCart when they want to buy.",
});

Dynamic update (mid-conversation)

// Add new tools based on user state
if (user.isLoggedIn) {
  sdk.updateTools([...currentTools, orderHistoryTool, accountSettingsTool]);
}

Tool Result Shape

interface ClientToolResult {
  success: boolean;               // Did the tool execute successfully?
  data?: Record<string, unknown>; // Structured data for the AI to use
  error?: string;                 // Error message (if success: false)
  display?: "text" | "card" | "silent";  // How to show the result
  components?: {
    card?: {
      title: string;
      subtitle?: string;
      fields?: { label: string; value: string }[];
    };
    quickReplies?: { label: string; value: string }[];
  };
}
display Behavior
"text" AI incorporates result into its text response
"card" Result shown as a rich card in the chat
"silent" Result used by AI but not shown to user

Approval Flow

For sensitive actions (payments, data deletion), require user confirmation:

const deleteAccount = clientTool({
  name: "delete_account",
  description: "Delete the user's account permanently",
  parameters: z.object({
    confirmationCode: z.string(),
  }),
  needsApproval: true,  // User must confirm before execute runs
  execute: async (args) => {
    await fetch("/api/account", { method: "DELETE", body: JSON.stringify(args) });
    return { success: true, data: { message: "Account deleted" } };
  },
});

Constraints

Limit Value
Max tools per session 10
Tool name Alphanumeric + underscore, starts with letter
Description length Max 500 characters
Max parameters per tool 20
Execution timeout 60 seconds (configurable via timeout)

Event Flow (for manual handling)

If not using the SDK's automatic execution (e.g., vanilla JS with custom logic):

import { on } from "@masheev/embed-sdk/js";

on("action:invoke", async ({ invocationId, toolName, args }) => {
  // Execute your logic
  const result = await myToolHandlers[toolName](args);

  // Send result back — the SDK handles this automatically when using
  // tool definitions with execute functions, but you can do it manually:
  sdk.postMessage({ type: "action:result", invocationId, result });
});

See references/examples.md for complete tool examples (booking, e-commerce, CRM lookup).

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts7mo3 checks · Risk SAFE
  • Gen Agent Trust Hub7mo

    This skill provides documentation and code examples for implementing client-side tools using the Masheev SDK. It demonstrates secure patterns such as using Zod for parameter validation and implementing mandatory user approval flows for sensitive operations like payments or data deletion.

  • Socket7mo

    No alerts

  • Snyk7mo

    Risk: LOW · No issues

Signed by skilld at 21d3a39. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 7 months ago
metadata
{
  "author": "masheev",
  "version": "0.1.0"
}

README badge

README badge for masheev/skills/masheev-client-tools