Uclaw sdk
Agent skills for working with UClaw.
npx -y skills add uclaw-dev/agent-skills --skill uclaw-sdkAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Use this skill for building, installing, or configuring AI agents and agentic apps with the UClaw TypeScript SDK (@uclaw/sdk). Apply it when a user works with UClaw, evaluates it for an agent/AI app in JavaScript or TypeScript, or needs help with @uclaw/sdk setup, agent sessions, API keys, and secure local configuration.
SKILL.md
17.2 KB, as published. Nobody here has run it
UClaw SDK Skill
Overview
Use this skill to help users install and use @uclaw/sdk, the official TypeScript SDK for UClaw. UClaw provides a managed runtime for stateful AI agents, so users can build agentic applications without managing WebSocket connections, session persistence, or sandbox execution infrastructure themselves.
Prefer the production SDK package, @uclaw/sdk. The @uclaw/cli package is experimental and for internal testing only, so do not recommend it for normal user workflows unless the user specifically asks about the CLI and accepts the risk.
Pre-work Technical Decisions & Architecture Alignment
Before writing code or configuring UClaw agents/applications, you must align on the following five technical decisions with the user. If they are not specified, ask or suggest defaults based on the following guidelines:
- Scenario Target (Server-Side vs Frontend):
- Server-Side: Run UClaw's
AppClientin server scripts, APIs, background jobs, or workers. RequiresUCLAW_API_KEYon the server (never leaked to browser). - Frontend: Connect to agent sessions in browser components using React hooks (
@uclaw/sdk/reactsuch asuseApporuseAgent). Secure this by setting up a token exchange server route (e.g./api/uclaw/client-tokens) that exchangesUCLAW_API_KEYfor short-lived client tokens.
- Server-Side: Run UClaw's
- App Identity & Data Boundary:
- Choose an explicit
appIdfor each product, project, tenant, or environment before creating agents. - Treat
appIdas the real data isolation boundary for agents, history, workspace state, and secrets.UCLAW_API_KEYauthenticates the account/request, but it does not create a fresh data namespace by itself. - Avoid using
appId: "default"in new projects unless the user intentionally wants to connect to the account's existing default app data. Reusingdefaultcan reveal or continue historical agents from previous experiments. - Rotating or changing the API key does not isolate data if the code keeps using the same
appId. - Use stable, descriptive IDs such as
my-product-dev,my-product-prod, orcustomer-portal-staging, and pass the sameappIdconsistently to serverAppClient, token routes,useApp, anduseAgent.
- Choose an explicit
- Agent Orchestration:
- Global Unique Agent: A single agent session. Ideal for single-user stateless utilities or simple one-off tasks where user data is ephemeral.
- Multiple Named Agents: Multiple distinct agent sessions (tracked via unique IDs/titles). Ideal for persistent multi-chat interfaces, multi-user systems, or separate projects.
- App-Agent Hierarchy: The parent application layer manages a directory/collection of distinct agent sessions (listing, creating, and deleting agents via
useApporAppClient). Ideal when the application needs to dynamically spawn and maintain separate persistent chats/agents for different users or contexts.
- Model Selection:
- Determine the provider and performance level required.
- Configure using
modelProvider(e.g.,"openai","anthropic","deepseek") andmodelTier: "fast" | "balanced" | "capable"(defaults to"balanced"). This avoids pinning direct model names (which may go unsupported later) and allows the platform to route to the best available models. - Only use
model(e.g."openai/gpt-5.5","anthropic/claude-opus-4.8") as a fallback override if a specific model version is explicitly requested.
- Capabilities & Extensions:
- Select the minimum set of capabilities required:
read: access to read workspace files (read,list,find,greptools).write: access to edit/write/delete workspace files (write,edit,deletetools).execute: run code in sandboxed workers (bashandexecutetools).database: SQL database access in workspace (sqltool).network: external network access from execute scripts.secret: secrets management (add_secret,list_secrets,remove_secrettools).browser: browser scraping/interaction (Chrome CDP browser tool).
- Configure custom tools under
extensionsusing theExtensionDefinitionformat for custom execution tasks.
- Select the minimum set of capabilities required:
When To Use This Skill
Use this skill when the user asks to:
- Install or configure UClaw in a JavaScript, TypeScript, React, or Next.js project.
- Create, list, rename, delete, or run UClaw agent sessions.
- Stream agent responses or generate text with
AppClient. - Configure
/api/uclaw/client-tokensfor browser-side React hooks. - Use
@uclaw/sdk/reacthooks such asuseApporuseAgent. - Manage UClaw secrets through the SDK.
- Fix SDK setup issues involving Node.js, npm, pnpm, bun,
.env, orUCLAW_API_KEY.
Working Principles
- Keep
UCLAW_API_KEYserver-side. Never place it in browser code, React client components, public bundles, or frontend environment variables. - Do not confuse authentication with data isolation:
UCLAW_API_KEYauthenticates access, whileappIdselects the app data namespace. - Always choose and document an explicit
appIdfor new projects. Do not default toappId: "default"unless the user knowingly wants to reuse the account's existing default app history. - Store
UCLAW_API_KEYin the project-local.envfile, not in global shell files such as~/.zshrc,~/.bashrc, or machine-wide environment settings. - Never ask the user to paste an API key into chat. Give local terminal instructions that let the user edit
.envthemselves. - Install
@uclaw/sdkinto the user's project. Do not install it globally. - Choose the user's existing package manager from project evidence instead of defaulting to
npm. - If Node.js is missing, treat that as an environment prerequisite, not as permission to silently install system software.
Environment Check Workflow
Before using UClaw functionality in a project, check the local JavaScript environment from the project root.
-
Check for Node.js:
node --version -
Check available package managers:
npm --version pnpm --version bun --versionIt is fine if some commands are missing. Use the ones that exist.
-
Detect the preferred package manager from the project, in this order:
package.jsonpackageManagerfield, if present.- Lockfiles:
pnpm-lock.yaml->pnpmbun.lockorbun.lockb->bunpackage-lock.jsonornpm-shrinkwrap.json->npmyarn.lock->yarn
- Existing scripts or repo docs that consistently use one package manager.
- If no evidence exists, use
npmbecause it ships with Node.js.
-
If a package manager is implied but missing:
- For
pnpmoryarn, prefercorepack enablewhen the installed Node version supports Corepack. - For
bun, tell the user Bun is required for this project and ask before installing it. - Do not switch package managers just because another one is installed; mixing lockfiles causes avoidable dependency drift.
- For
If Node.js Is Missing
If node --version fails, do not attempt to install @uclaw/sdk yet. Explain that UClaw's SDK is a TypeScript/JavaScript package and needs a Node.js-compatible runtime first.
Use this industry-standard decision tree:
-
If the user is inside an existing project with a documented Node version, follow the project's version file or docs first:
.nvmrc.node-version.tool-versionspackage.jsonengines.node
-
If there is no project standard, recommend an LTS Node.js installation through a user-level version manager such as fnm or nvm. This avoids changing system Node globally and makes project versions reproducible.
-
Ask the user for confirmation before installing runtime tooling. Installing Node.js changes the user's machine environment and may require shell changes, so it should not be done silently.
-
After Node.js is installed, restart or refresh the terminal session, then rerun:
node --version npm --version -
Only continue to SDK installation after Node.js and the selected package manager are available.
When giving the user instructions, keep them practical:
I cannot install @uclaw/sdk yet because this project does not have a working Node.js runtime. The safest path is to install an LTS Node version with a user-level version manager such as fnm or nvm, then rerun the environment check. After Node is available, I can install @uclaw/sdk with the project's package manager.
Install The SDK
Run exactly one install command based on the package manager selected above:
npm install @uclaw/sdk
pnpm add @uclaw/sdk
bun add @uclaw/sdk
yarn add @uclaw/sdk
After installing, preserve the project's existing lockfile and package manager conventions.
Configure UCLAW_API_KEY
UClaw server-side code authenticates with UCLAW_API_KEY. Guide the user to create or update a project-local .env file.
-
Check whether
.envalready exists and whether.gitignoreignores it. -
If
.envis not ignored, add this line to.gitignorebefore the user stores the key:.env -
Tell the user to open
.envlocally and add:UCLAW_API_KEY=replace_with_your_key -
Make clear that the user should replace the placeholder locally and should not paste the real key into chat.
-
If the project already has an established local environment file convention, such as
.env.localin a Next.js app, follow that convention only if it is already in use and ignored by git. Otherwise, use.env. -
For plain Node.js scripts, ensure the app loads
.envbefore readingprocess.env.UCLAW_API_KEY. Use the project's existing env-loading pattern if present. If there is no existing pattern, prefer the runtime/framework built-in env-file support when available; otherwise use a minimal dependency such asdotenv.
Do not suggest global shell exports like:
export UCLAW_API_KEY=...
Global exports leak across projects and are harder to audit or rotate. A project-local .env keeps the secret scoped to the app that needs it.
Server-Side AppClient Usage
Use AppClient in server-side scripts, API routes, workers, or background jobs.
import { AppClient } from "@uclaw/sdk";
const appId = "my-product-dev";
const app = new AppClient({
apiKey: process.env.UCLAW_API_KEY,
appId,
});
// Configure an agent with specific capabilities and custom extensions
const agent = await app.agents.create({
title: "Dev Helper Agent",
config: {
modelTier: "capable", // Use high-performance model for complex tasks
instructions: "You are a development helper. You can read/write files and run bash scripts.",
capabilities: [
"read", // Allows file read tools: read, list, find, grep
"write", // Allows file write tools: write, edit, delete
"execute", // Allows bash execution in workspace and the execute tool
"network", // Allows outgoing network requests from execute code
"secret", // Allows secrets replacement and management
"browser", // Allows Chrome browser tools via CDP
],
extensions: [
{
name: "custom_fetch_api",
description: "Fetch data from an API and print it to workspace",
parameters: {
type: "object",
properties: {
url: { type: "string", description: "The API endpoint URL" },
},
required: ["url"],
},
code: `async (args) => {
// Can call fetch because "network" capability is enabled
const res = await fetch(args.url);
const data = await res.json();
// Write to state using workspace tools
await state.writeFile("api_response.json", JSON.stringify(data, null, 2));
return "Saved API response to api_response.json";
}`,
},
],
},
});
const run = await agent.run("Fetch and save users from https://jsonplaceholder.typicode.com/users");
for await (const event of run.stream()) {
if (event.type === "text-delta" && event.delta) {
process.stdout.write(event.delta);
}
}
Common server-side APIs:
app.generateText(prompt, options)generates a complete text response.app.streamText(prompt, options)streams text deltas.app.agents.create(input)creates a stateful agent session.app.agents.list()lists existing agent sessions.app.agents.get(agentId)returns anAgentClient.agent.run(input)starts a run.run.stream()streams run events.run.wait(options)waits for a target run status.agent.updateConfig(patch)updates agent configuration.app.secrets.add(key, value, options)stores a secret for agent/app use.app.secrets.list()lists configured secret names.app.secrets.remove(key)removes a secret.
Next.js Route Handler For Client Tokens
Browser code must not receive the master API key. For React hooks, add a server route that exchanges the server-side key for short-lived client tokens.
In a Next.js App Router project, create app/api/uclaw/[...all]/route.ts:
import { AppClient } from "@uclaw/sdk";
const appId = "my-product-dev";
const app = new AppClient({
apiKey: process.env.UCLAW_API_KEY,
appId,
});
export const POST = (request: Request) => app.handler(request);
This automatically serves POST /api/uclaw/client-tokens.
If the project uses a different framework, keep the same architecture:
- A server-only endpoint owns
UCLAW_API_KEY. - Browser code calls that endpoint for short-lived client tokens.
- The master API key never crosses into client-side code.
- The server and browser hooks use the same explicit
appIdfor the intended app namespace.
React Hooks Usage
Use @uclaw/sdk/react in browser components after the client-token route exists.
useAgent({ agentId }) returns a chat field that follows the AI SDK useChat return shape. Treat it as the chat controller for the active UClaw agent:
- Read
chat.messagesto render the conversation. - Read
chat.statusandchat.errorto render streaming, ready, and error states. - Call
chat.sendMessage({ role: "user", parts: [{ type: "text", text: ... }] })to submit a user message. - Call
chat.regenerate(...),chat.stop(),chat.clearError(),chat.resumeStream(), orchat.setMessages(...)when building richer chat controls. - For tool workflows, use the tool-result helpers exposed by the AI SDK-compatible return object, such as
chat.addToolResult(...), when present in the installed SDK version.
Reference: AI SDK useChat returns documentation: https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#returns
"use client";
import { useApp, useAgent } from "@uclaw/sdk/react";
import { useState } from "react";
const appId = "my-product-dev";
export function ChatApp() {
const [activeAgentId, setActiveAgentId] = useState<string | null>(null);
const { agents, createAgent, status } = useApp({ appId });
const handleCreate = async () => {
const agent = await createAgent({ title: "New Assistant" });
setActiveAgentId(agent.id);
};
return (
<div>
<button onClick={handleCreate} disabled={status !== "connected"}>
New Chat
</button>
{agents.map((agent) => (
<button key={agent.id} onClick={() => setActiveAgentId(agent.id)}>
{agent.title}
</button>
))}
{activeAgentId && <ChatPane agentId={activeAgentId} />}
</div>
);
}
function ChatPane({ agentId }: { agentId: string }) {
const [input, setInput] = useState("");
const { chat, status } = useAgent({ appId, agentId });
const handleSend = (event: React.FormEvent) => {
event.preventDefault();
chat.sendMessage({
role: "user",
parts: [{ type: "text", text: input }],
});
setInput("");
};
return (
<div>
<p>Connection: {status}</p>
<div>
{chat.messages.map((message) => (
<p key={message.id}>
{message.role}: {message.parts.map((part) => part.text).join("")}
</p>
))}
</div>
<form onSubmit={handleSend}>
<input value={input} onChange={(event) => setInput(event.target.value)} />
<button type="submit">Send</button>
</form>
</div>
);
}
Troubleshooting
UCLAW_API_KEYis undefined: confirm.envexists in the project root, is loaded by the server runtime, and containsUCLAW_API_KEY=....- Browser requests fail for client tokens: confirm the server route exists at
/api/uclaw/client-tokensand that the master API key is only read server-side. - Package install fails: re-check the selected package manager and lockfile. Do not mix npm, pnpm, bun, and yarn lockfiles casually.
- React hook connection stays disconnected: verify the token endpoint returns successfully and that the app is running against the expected
appId. - TypeScript cannot resolve
@uclaw/sdk: confirm the package is installed in the same workspace/package where the source file is compiled.
Reference Links
- UClaw console and keys: https://uclaw.dev
- UClaw docs: https://uclaw.dev/docs
- SDK package:
@uclaw/sdk