@vibevibes/sdk 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +200 -263
- package/dist/index.cjs +35 -5503
- package/dist/index.d.cts +50 -1720
- package/dist/index.d.ts +50 -1720
- package/dist/index.js +34 -5417
- package/package.json +69 -67
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 vibevibes
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 vibevibes
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,263 +1,200 @@
|
|
|
1
|
-
# @vibevibes/sdk
|
|
2
|
-
|
|
3
|
-
The primitives for building agent-native experiences — shared interactive apps where humans and AI collaborate in real-time through a shared state, shared tools, and a shared canvas.
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @vibevibes/sdk
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
Peer dependencies: `react` (18 or 19), `zod`. Optional: `yjs`.
|
|
12
|
-
|
|
13
|
-
## Quick Start
|
|
14
|
-
|
|
15
|
-
```tsx
|
|
16
|
-
import { defineExperience, defineTool } from "@vibevibes/sdk";
|
|
17
|
-
import { z } from "zod";
|
|
18
|
-
|
|
19
|
-
const tools = [
|
|
20
|
-
defineTool({
|
|
21
|
-
name: "counter.increment",
|
|
22
|
-
description: "Add to the counter",
|
|
23
|
-
input_schema: z.object({
|
|
24
|
-
amount: z.number().default(1).describe("Amount to add"),
|
|
25
|
-
}),
|
|
26
|
-
handler: async (ctx, input) => {
|
|
27
|
-
const count = (ctx.state.count || 0) + input.amount;
|
|
28
|
-
ctx.setState({ ...ctx.state, count });
|
|
29
|
-
return { count };
|
|
30
|
-
},
|
|
31
|
-
}),
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
function Canvas({ sharedState, callTool }) {
|
|
35
|
-
return (
|
|
36
|
-
<div>
|
|
37
|
-
<h1>{sharedState.count || 0}</h1>
|
|
38
|
-
<button onClick={() => callTool("counter.increment", { amount: 1 })}>
|
|
39
|
-
+1
|
|
40
|
-
</button>
|
|
41
|
-
</div>
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export default defineExperience({
|
|
46
|
-
manifest: {
|
|
47
|
-
id: "counter",
|
|
48
|
-
version: "0.0.1",
|
|
49
|
-
title: "Counter",
|
|
50
|
-
description: "A shared counter",
|
|
51
|
-
requested_capabilities: [],
|
|
52
|
-
},
|
|
53
|
-
Canvas,
|
|
54
|
-
tools,
|
|
55
|
-
});
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
That's a complete experience. Humans click the button. Agents call the same tool via MCP. Both mutate the same state. Both see the same canvas.
|
|
59
|
-
|
|
60
|
-
## Core Concepts
|
|
61
|
-
|
|
62
|
-
**Tools are the only way to mutate state.** Every tool has a Zod schema for validation and a handler that calls `ctx.setState()`. Humans use tools via the Canvas. Agents use the same tools via MCP. No backdoors.
|
|
63
|
-
|
|
64
|
-
**Canvas is a React component.** It receives the current shared state and a `callTool` function. It re-renders on every state change.
|
|
65
|
-
|
|
66
|
-
**Agents are actors, not assistants.** They join rooms, watch for events, react with tools, and persist memory. Same participation model as humans.
|
|
67
|
-
|
|
68
|
-
## Defining Tools
|
|
69
|
-
|
|
70
|
-
```tsx
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
##
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
import { undoTool, useUndo } from "@vibevibes/sdk";
|
|
202
|
-
|
|
203
|
-
// Add to tools array
|
|
204
|
-
const tools = [...yourTools, undoTool(z)];
|
|
205
|
-
|
|
206
|
-
// In Canvas
|
|
207
|
-
const { undo, redo, canUndo, canRedo } = useUndo(sharedState, callTool);
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
## Tests
|
|
211
|
-
|
|
212
|
-
Inline tests for tool handlers, run with `npm test`:
|
|
213
|
-
|
|
214
|
-
```tsx
|
|
215
|
-
import { defineTest } from "@vibevibes/sdk";
|
|
216
|
-
|
|
217
|
-
tests: [
|
|
218
|
-
defineTest({
|
|
219
|
-
name: "increment adds to count",
|
|
220
|
-
run: async ({ tool, ctx, expect }) => {
|
|
221
|
-
const inc = tool("counter.increment");
|
|
222
|
-
const c = ctx({ state: { count: 5 } });
|
|
223
|
-
await inc.handler(c, { amount: 3 });
|
|
224
|
-
expect(c.getState().count).toBe(8);
|
|
225
|
-
},
|
|
226
|
-
}),
|
|
227
|
-
]
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
## Manifest
|
|
231
|
-
|
|
232
|
-
```tsx
|
|
233
|
-
type ExperienceManifest = {
|
|
234
|
-
id: string;
|
|
235
|
-
version: string;
|
|
236
|
-
title: string;
|
|
237
|
-
description: string;
|
|
238
|
-
requested_capabilities: string[]; // e.g. ["room.spawn"]
|
|
239
|
-
agentSlots?: AgentSlot[];
|
|
240
|
-
category?: string; // "games", "productivity", "creative", etc.
|
|
241
|
-
tags?: string[];
|
|
242
|
-
netcode?: "default" | "tick" | "p2p-ephemeral";
|
|
243
|
-
tickRateMs?: number; // For tick netcode
|
|
244
|
-
hotKeys?: string[]; // Keys routed through ephemeral channel
|
|
245
|
-
};
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
## How It Works
|
|
249
|
-
|
|
250
|
-
```
|
|
251
|
-
Browser (Canvas) <--WebSocket--> Server <--HTTP--> MCP (Agent)
|
|
252
|
-
| |
|
|
253
|
-
callTool(name, input) validates input (Zod)
|
|
254
|
-
runs handler(ctx, input)
|
|
255
|
-
ctx.setState(newState)
|
|
256
|
-
broadcasts to all clients
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
All state lives on the server. The Canvas renders it. Tools are the only mutation path. Both humans and agents use the same tools.
|
|
260
|
-
|
|
261
|
-
## License
|
|
262
|
-
|
|
263
|
-
MIT
|
|
1
|
+
# @vibevibes/sdk
|
|
2
|
+
|
|
3
|
+
The primitives for building agent-native experiences — shared interactive apps where humans and AI collaborate in real-time through a shared state, shared tools, and a shared canvas.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @vibevibes/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Peer dependencies: `react` (18 or 19), `zod`. Optional: `yjs`.
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { defineExperience, defineTool } from "@vibevibes/sdk";
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
|
|
19
|
+
const tools = [
|
|
20
|
+
defineTool({
|
|
21
|
+
name: "counter.increment",
|
|
22
|
+
description: "Add to the counter",
|
|
23
|
+
input_schema: z.object({
|
|
24
|
+
amount: z.number().default(1).describe("Amount to add"),
|
|
25
|
+
}),
|
|
26
|
+
handler: async (ctx, input) => {
|
|
27
|
+
const count = (ctx.state.count || 0) + input.amount;
|
|
28
|
+
ctx.setState({ ...ctx.state, count });
|
|
29
|
+
return { count };
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
function Canvas({ sharedState, callTool }) {
|
|
35
|
+
return (
|
|
36
|
+
<div>
|
|
37
|
+
<h1>{sharedState.count || 0}</h1>
|
|
38
|
+
<button onClick={() => callTool("counter.increment", { amount: 1 })}>
|
|
39
|
+
+1
|
|
40
|
+
</button>
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default defineExperience({
|
|
46
|
+
manifest: {
|
|
47
|
+
id: "counter",
|
|
48
|
+
version: "0.0.1",
|
|
49
|
+
title: "Counter",
|
|
50
|
+
description: "A shared counter",
|
|
51
|
+
requested_capabilities: [],
|
|
52
|
+
},
|
|
53
|
+
Canvas,
|
|
54
|
+
tools,
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
That's a complete experience. Humans click the button. Agents call the same tool via MCP. Both mutate the same state. Both see the same canvas.
|
|
59
|
+
|
|
60
|
+
## Core Concepts
|
|
61
|
+
|
|
62
|
+
**Tools are the only way to mutate state.** Every tool has a Zod schema for validation and a handler that calls `ctx.setState()`. Humans use tools via the Canvas. Agents use the same tools via MCP. No backdoors.
|
|
63
|
+
|
|
64
|
+
**Canvas is a React component.** It receives the current shared state and a `callTool` function. It re-renders on every state change.
|
|
65
|
+
|
|
66
|
+
**Agents are actors, not assistants.** They join rooms, watch for events, react with tools, and persist memory. Same participation model as humans.
|
|
67
|
+
|
|
68
|
+
## Defining Tools
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
defineTool({
|
|
72
|
+
name: "board.place",
|
|
73
|
+
description: "Place a piece on the board",
|
|
74
|
+
input_schema: z.object({
|
|
75
|
+
x: z.number(),
|
|
76
|
+
y: z.number(),
|
|
77
|
+
piece: z.string(),
|
|
78
|
+
}),
|
|
79
|
+
handler: async (ctx, input) => {
|
|
80
|
+
const board = { ...ctx.state.board };
|
|
81
|
+
board[`${input.x},${input.y}`] = input.piece;
|
|
82
|
+
ctx.setState({ ...ctx.state, board });
|
|
83
|
+
return { placed: true };
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Tool Handler Context
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
type ToolCtx = {
|
|
92
|
+
roomId: string;
|
|
93
|
+
actorId: string; // Who called this tool
|
|
94
|
+
owner?: string; // Owner extracted from actorId
|
|
95
|
+
state: Record<string, any>; // Current shared state (read)
|
|
96
|
+
setState: (s: Record<string, any>) => void; // Set new state (write)
|
|
97
|
+
timestamp: number;
|
|
98
|
+
memory: Record<string, any>; // Agent's persistent memory
|
|
99
|
+
setMemory: (updates: Record<string, any>) => void;
|
|
100
|
+
};
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Always spread existing state: `ctx.setState({ ...ctx.state, key: value })`.
|
|
104
|
+
|
|
105
|
+
## Canvas Props
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
type CanvasProps = {
|
|
109
|
+
actorId: string;
|
|
110
|
+
sharedState: Record<string, any>;
|
|
111
|
+
callTool: (name: string, input: any) => Promise<any>;
|
|
112
|
+
participants: string[];
|
|
113
|
+
ephemeralState: Record<string, Record<string, any>>;
|
|
114
|
+
setEphemeral: (data: Record<string, any>) => void;
|
|
115
|
+
stream?: (name: string, input: Record<string, unknown>) => void;
|
|
116
|
+
};
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Agent Slots
|
|
120
|
+
|
|
121
|
+
Define named agent roles for multi-agent experiences:
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
manifest: {
|
|
125
|
+
agentSlots: [
|
|
126
|
+
{
|
|
127
|
+
role: "game-master",
|
|
128
|
+
systemPrompt: "You are the game master.",
|
|
129
|
+
allowedTools: ["world.narrate", "npc.speak"],
|
|
130
|
+
autoSpawn: true,
|
|
131
|
+
maxInstances: 1,
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Tests
|
|
138
|
+
|
|
139
|
+
Inline tests for tool handlers:
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
import { defineTest } from "@vibevibes/sdk";
|
|
143
|
+
|
|
144
|
+
tests: [
|
|
145
|
+
defineTest({
|
|
146
|
+
name: "increment adds to count",
|
|
147
|
+
run: async ({ tool, ctx, expect }) => {
|
|
148
|
+
const inc = tool("counter.increment");
|
|
149
|
+
const c = ctx({ state: { count: 5 } });
|
|
150
|
+
await inc.handler(c, { amount: 3 });
|
|
151
|
+
expect(c.getState().count).toBe(8);
|
|
152
|
+
},
|
|
153
|
+
}),
|
|
154
|
+
]
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Manifest
|
|
158
|
+
|
|
159
|
+
```tsx
|
|
160
|
+
type ExperienceManifest = {
|
|
161
|
+
id: string;
|
|
162
|
+
version: string;
|
|
163
|
+
title: string;
|
|
164
|
+
description: string;
|
|
165
|
+
requested_capabilities: string[];
|
|
166
|
+
agentSlots?: AgentSlot[];
|
|
167
|
+
participantSlots?: ParticipantSlot[];
|
|
168
|
+
category?: string;
|
|
169
|
+
tags?: string[];
|
|
170
|
+
netcode?: "default" | "tick" | "p2p-ephemeral";
|
|
171
|
+
tickRateMs?: number;
|
|
172
|
+
hotKeys?: string[];
|
|
173
|
+
};
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## How It Works
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
Browser (Canvas) <--WebSocket--> Server <--HTTP--> MCP (Agent)
|
|
180
|
+
| |
|
|
181
|
+
callTool(name, input) validates input (Zod)
|
|
182
|
+
runs handler(ctx, input)
|
|
183
|
+
ctx.setState(newState)
|
|
184
|
+
broadcasts to all clients
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
All state lives on the server. The Canvas renders it. Tools are the only mutation path. Both humans and agents use the same tools.
|
|
188
|
+
|
|
189
|
+
## Ecosystem
|
|
190
|
+
|
|
191
|
+
| Package | Description |
|
|
192
|
+
|---------|-------------|
|
|
193
|
+
| **@vibevibes/sdk** (this) | Define experiences — tools, canvas, state |
|
|
194
|
+
| [@vibevibes/mcp](https://github.com/vibevibes/mcp) | Runtime server — MCP + WebSocket + browser viewer |
|
|
195
|
+
| [create-vibevibes](https://github.com/vibevibes/create) | `npx create-vibevibes my-exp` — scaffold in seconds |
|
|
196
|
+
| [experiences](https://github.com/vibevibes/experiences) | Example experiences — fork and remix |
|
|
197
|
+
|
|
198
|
+
## License
|
|
199
|
+
|
|
200
|
+
MIT
|