Skip to main content

Documentation Index

Fetch the complete documentation index at: https://sunpeak.ai/docs/llms.txt

Use this file to discover all available pages before exploring further.

sunpeak API

Overview

Returns a function to register tools that the host (or LLM) can call. Uses Standard Schema (Zod, ArkType, Valibot) for input/output validation. The returned handle supports enable(), disable(), remove(), and update(). For simpler static tool registration, see useAppTools. useRegisterTool provides lower-level control with dynamic registration and Standard Schema support.

Import

import { useRegisterTool } from 'sunpeak';

Signature

function useRegisterTool(): (
  name: string,
  config: RegisterToolConfig,
  cb: AppToolCallback
) => RegisteredAppTool | undefined

RegisterToolConfig

title
string
Human-readable title for the tool.
description
string
Description of what the tool does.
inputSchema
StandardSchemaV1
Input validation schema (Zod, ArkType, Valibot, etc.).
outputSchema
StandardSchemaV1
Output validation schema.
annotations
ToolAnnotations
Tool annotations (readOnly, destructive, idempotent hints).

Returns

registerTool
(name, config, cb) => RegisteredAppTool | undefined
Function to register a tool. Returns undefined if app is not connected.

RegisteredAppTool

enable()
() => void
Enable the tool.
disable()
() => void
Disable the tool.
remove()
() => void
Remove the tool registration.
update()
(updates) => void
Update the tool configuration.

Usage

import { useRegisterTool, useSendToolListChanged } from 'sunpeak';
import { useEffect } from 'react';

function SelectionTool({ selectedText }: { selectedText: string }) {
  const registerTool = useRegisterTool();
  const sendToolListChanged = useSendToolListChanged();

  useEffect(() => {
    const handle = registerTool(
      "get_selection",
      { description: "Get the user's current text selection" },
      () => ({
        content: [{ type: "text", text: selectedText }],
      })
    );
    if (handle) {
      sendToolListChanged();
      return () => {
        handle.remove();
        sendToolListChanged();
      };
    }
  }, [registerTool, sendToolListChanged, selectedText]);

  return <div>Selection tool registered</div>;
}