@vibevibes/sdk 0.1.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 ADDED
@@ -0,0 +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.
package/README.md ADDED
@@ -0,0 +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
+ 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