Docs · shapeshift-sdk 0.1.1
Connect your product
Add Shapeshift once and your customers can build their own features inside your app. This guide takes you from an empty project to add-ons on your screens.
These docs are also on GitHub, where you can suggest fixes. The package your app installs is on GitHub too, open source under MIT, and so is the example CRM behind the live demo.
Overview
Three pieces work together:
- Your server runs the
shapeshift-sdkpackage, open source under MIT. It tells Shapeshift what add-ons may see and do, and runs your own functions when an add-on asks. - Your screens use the React hooks to show add-ons and the Customize chat, in your own design.
- Shapeshift builds add-ons with AI, tests them, and runs them in a sandbox. It never gets your database or your code, only the actions you list.
The examples use Next.js. The server part only needs a JavaScript server that handles standard web requests, and the hooks need React.
1. Create a project
Create an account, then make a project with your product's name and the address your app runs at. Shapeshift calls your app there. The project page shows your project id and secret, ready to copy.
2. Install and settings
npm install shapeshift-sdk
Add these to your app's server settings. Keep the secret on your server: it signs every call between your app and Shapeshift.
SHAPESHIFT_PROJECT=your-project-id SHAPESHIFT_SECRET=your-project-secret # SHAPESHIFT_URL=... only if you use a different Shapeshift address
3. Describe your app
The manifest is how the AI learns your app. It says what your data looks like, which of your functions add-ons may call, and where on screen they may appear. Nothing outside it can ever be used.
manifest: {
app: "Acme CRM",
description: "A CRM for small sales teams.",
types: "type Lead = { id: string; name: string; value: number; status: string }",
ops: [
{ name: "leads.list", description: "All leads", args: "()", returns: "Lead[]" },
{ name: "leads.update", description: "Change a lead", args: "(id, patch)", returns: "Lead", writes: true },
],
spots: {
column: { description: "A column in the leads table", rowsName: "leads", rowsOp: "leads.list" },
panel: { description: "A card next to the leads table", rowsName: "leads", rowsOp: "leads.list" },
button: { description: "A button above the leads table", rowsName: "leads", rowsOp: "leads.list" },
},
}- types: your data shapes, written as TypeScript types.
- ops: the actions add-ons may call. Mark the ones that change data with
writes: true. Only buttons can use those. - spots: where add-ons can appear.
columnadds a value to every row,panelis a card next to the list,buttondoes work on click.rowsNameis what the rows are called androwsOpis the action that lists them. - snapshotOp (optional): an action that returns a short text summary of the company's data, so the AI can ask better questions.
4. Actions and sign-in
Next to the manifest you give one function per action, plus two small checks. Every action is called with the customer company and the person it runs for, so always filter by tenantId.
// lib/shapeshift.ts
import { createShapeshift } from "shapeshift-sdk/server";
export const shapeshift = createShapeshift({
manifest: { /* see step 3 */ },
// Your own functions, always run for one customer company (tenantId) and one person (userId).
actions: {
"leads.list": ({ tenantId }) => db.leads.findMany({ where: { tenantId } }),
"leads.update": ({ tenantId }, id, patch) => db.leads.update({ where: { id, tenantId }, data: patch }),
},
// Shapeshift can only act as people who really belong to that company.
isMember: (tenantId, userId) => db.members.exists({ tenantId, userId }),
// Who is signed in, using your own login.
getViewer: async (req) => {
const user = await getSignedInUser(req);
return user && { tenant: { id: user.companyId, name: user.companyName }, user: { id: user.id, name: user.name } };
},
});- isMember: Shapeshift only acts as people who really belong to the company.
- getViewer: tells Shapeshift who is signed in, using your own login. Return
nullwhen nobody is.
5. Add the route
One catch-all route handles signed calls from Shapeshift and the calls from your own screens.
// app/api/shapeshift/[...path]/route.ts
import { shapeshift } from "@/lib/shapeshift";
export const { GET, POST, PATCH, DELETE } = shapeshift.handler;Calls from Shapeshift must carry a valid signature from your project secret, or they're turned away. Calls from the browser need a signed-in viewer.
6. Show add-ons
Pass the rows on screen to useAddons. You get back this company's columns, panels and buttons, already run on those rows. You draw them in your own design.
"use client";
import { useAddons } from "shapeshift-sdk/react";
export function LeadsTable({ leads }) {
// Columns, side panels and buttons this company made, for the rows on screen.
const { data, run } = useAddons(leads);
return (
<>
{data?.buttons.map((b) => (
<button key={b.id} onClick={() => run(b.id)}>{b.label}</button>
))}
<table>
<thead>
<tr>
<th>Name</th>
{data?.columns.map((c) => <th key={c.id}>{c.label}</th>)}
</tr>
</thead>
<tbody>
{leads.map((lead) => (
<tr key={lead.id}>
<td>{lead.name}</td>
{data?.columns.map((c) => (
<td key={c.id}>{c.cells[lead.id]?.text}</td>
))}
</tr>
))}
</tbody>
</table>
</>
);
}- Columns:
cells[rowId]is{ text, tone }, where tone is good, warn, bad, info or neutral. - Panels:
blocksis a list of simple parts you draw:
{ type: "heading", text }
{ type: "text", text }
{ type: "stat", label, value, tone? }
{ type: "list", items: [{ title, subtitle?, badge?, tone?, rowId? }] }
{ type: "bars", items: [{ label, value }] }- Buttons:
run(id)runs one and returns{ ok, message }, then refreshes. - If a column or panel fails, it comes back with
ok: falseand anerror, so one broken add-on never breaks your page.
From server code you can do the same without the hook:
const viewer = await getViewerSomehow();
const { columns, panels, buttons } = await shapeshift.client(viewer).render(leads);7. The Customize chat
Put a Customize button somewhere in your app and open a chat built on useCustomize. The AI asks at most one question, then builds and tests a draft on the person's real data without changing anything. They see a preview and turn it on.
"use client";
import { useCustomize } from "shapeshift-sdk/react";
const chat = useCustomize();
chat.send("score each lead from 0 to 100"); // a question back, or a tested draft
chat.turns; // the conversation so far
chat.building; // true while the AI is working
chat.result; // the question, or the draft with its preview
chat.turnOn(draft); // goes live for this company
chat.reset(); // start over8. Add-ons page and activity
Give your customers a page to see, switch off, fix or delete their add-ons, and a log of what they did.
"use client";
import { useActivity, useAddonList } from "shapeshift-sdk/react";
const list = useAddonList();
list.addons; // this company's add-ons, with health
list.setEnabled(id, false); // turn one off
list.remove(id); // delete it
list.fix(id); // ask the AI to repair a paused one
list.undo(id); // put back the version before an automatic fix
list.recheck(); // test them all again now
const log = useActivity();
log.entries; // what each add-on did, newest first
log.more(); // load older entries9. Check the connection
Deploy your app, open your project in the dashboard and run the connection check. It reads your manifest through the signed route and tells you in plain words if anything is missing.
To see a full working setup, try the Leadline demo, a sample CRM connected exactly this way. Its code is on GitHub: example-crm.
Safety and control
- Add-ons run in a sandbox on Shapeshift's side, with time and memory limits.
- They can only call the actions in your manifest, for one company and one signed-in person.
- Columns and panels only read. Only buttons can call actions marked
writes: true. - Test runs never change data. A button's preview lists the changes it would make.
- From the dashboard you can block any action and switch off any add-on, for every customer.
- Every call to your app is signed with your project secret.
When you ship an update
When your manifest changes, every add-on that's on gets a test run against the new version. Working ones stay on. Broken ones go to the AI with the error and get fixed, or they're paused with a plain note for the customer. Any automatic fix can be undone.
Limits
- Up to 100 AI jobs a day per product.
- Each customer company gets up to 20 a day. You can lower that per project in the dashboard.
- An AI job is one Customize message or one repair. Running add-ons that are on doesn't count.
Shapeshift is free while in early access. See pricing.