@lakitu/sdk 0.1.44 → 0.1.46
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/CONTRIBUTING.md +344 -0
- package/README.md +237 -59
- package/cloudflare/index.ts +19 -0
- package/cloudflare/r2.ts +259 -0
- package/cloudflare/types.ts +51 -0
- package/cloudflare/workers/frames.ts +137 -0
- package/convex/cloud/gateway/auth.ts +66 -0
- package/convex/cloud/gateway/index.ts +85 -0
- package/convex/cloud/gateway/routing.ts +137 -0
- package/convex/cloud/gateway/whitelist.ts +154 -0
- package/convex/cloud/intentSchema/generate.ts +3 -2
- package/convex/cloud/models.ts +187 -0
- package/convex/cloud/schema.ts +34 -0
- package/convex/cloud/workflows/crudThreads.ts +38 -1
- package/convex/cloud/workflows/sandboxCache.ts +239 -0
- package/convex/sandbox/agent/codeExecLoop.ts +10 -4
- package/convex/sandbox/planning/beads.ts +120 -1
- package/dist/cli/commands/cloudflare.d.ts +22 -0
- package/dist/cli/commands/cloudflare.d.ts.map +1 -0
- package/dist/cli/commands/cloudflare.js +130 -0
- package/dist/cli/index.d.ts +4 -4
- package/dist/cli/index.js +10 -4
- package/dist/ksa/_shared/gateway.d.ts +76 -0
- package/dist/ksa/_shared/gateway.d.ts.map +1 -0
- package/dist/ksa/_shared/gateway.js +141 -0
- package/dist/ksa/_shared/localDb.d.ts +118 -0
- package/dist/ksa/_shared/localDb.d.ts.map +1 -0
- package/dist/ksa/_shared/localDb.js +256 -0
- package/dist/sdk/db.d.ts +17 -0
- package/dist/sdk/db.d.ts.map +1 -0
- package/dist/sdk/db.js +24 -0
- package/dist/sdk/gateway.d.ts +17 -0
- package/dist/sdk/gateway.d.ts.map +1 -0
- package/dist/sdk/gateway.js +19 -0
- package/dist/sdk/index.d.ts +19 -1
- package/dist/sdk/index.d.ts.map +1 -1
- package/dist/sdk/index.js +24 -1
- package/dist/sdk/template.d.ts +89 -0
- package/dist/sdk/template.d.ts.map +1 -0
- package/dist/sdk/template.js +77 -0
- package/docs/API.md +470 -0
- package/ksa/_shared/gateway.ts +6 -4
- package/ksa/_shared/localDb.ts +9 -7
- package/package.json +41 -9
- package/template/build.ts +146 -25
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
# Contributing to @lakitu/sdk
|
|
2
|
+
|
|
3
|
+
This guide covers development setup, workflows, and best practices for contributing to the Lakitu SDK.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Development Setup](#development-setup)
|
|
8
|
+
- [Repository Structure](#repository-structure)
|
|
9
|
+
- [Development Modes](#development-modes)
|
|
10
|
+
- [Making Changes](#making-changes)
|
|
11
|
+
- [Testing](#testing)
|
|
12
|
+
- [Publishing](#publishing)
|
|
13
|
+
- [SDK vs Implementation](#sdk-vs-implementation)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Development Setup
|
|
18
|
+
|
|
19
|
+
### Prerequisites
|
|
20
|
+
|
|
21
|
+
- [Bun](https://bun.sh) v1.0+
|
|
22
|
+
- [Node.js](https://nodejs.org) v20+
|
|
23
|
+
- [E2B Account](https://e2b.dev) with API key
|
|
24
|
+
- [Convex Account](https://convex.dev)
|
|
25
|
+
|
|
26
|
+
### Clone and Install
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
git clone https://github.com/shinyobjectz/lakitu.git
|
|
30
|
+
cd lakitu
|
|
31
|
+
bun install
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Environment Setup
|
|
35
|
+
|
|
36
|
+
Create `.env.local`:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
E2B_API_KEY=your-e2b-key
|
|
40
|
+
CONVEX_DEPLOYMENT=your-deployment
|
|
41
|
+
SANDBOX_JWT_SECRET=your-secret
|
|
42
|
+
OPENROUTER_API_KEY=your-openrouter-key
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Repository Structure
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
lakitu/
|
|
51
|
+
├── sdk/ # SDK entry points (compiled to dist/)
|
|
52
|
+
│ ├── index.ts # Main exports
|
|
53
|
+
│ ├── gateway.ts # Gateway re-exports
|
|
54
|
+
│ ├── db.ts # Local DB re-exports
|
|
55
|
+
│ ├── builders.ts # KSA definition builders
|
|
56
|
+
│ ├── primitives.ts # Sandbox primitives
|
|
57
|
+
│ └── types.ts # TypeScript types
|
|
58
|
+
│
|
|
59
|
+
├── ksa/ # KSA runtime modules (copied to sandbox)
|
|
60
|
+
│ ├── _shared/ # Shared utilities
|
|
61
|
+
│ │ ├── gateway.ts # Cloud gateway client
|
|
62
|
+
│ │ └── localDb.ts # Local Convex client
|
|
63
|
+
│ ├── _generated/ # Auto-generated registry
|
|
64
|
+
│ ├── file.ts # File operations KSA
|
|
65
|
+
│ └── browser.ts # Browser automation KSA
|
|
66
|
+
│
|
|
67
|
+
├── convex/ # Convex backends
|
|
68
|
+
│ ├── cloud/ # Cloud component (npm package)
|
|
69
|
+
│ │ ├── workflows/ # Thread, sandbox, session management
|
|
70
|
+
│ │ ├── gateway/ # HTTP gateway for sandbox calls
|
|
71
|
+
│ │ └── schema.ts # Cloud database schema
|
|
72
|
+
│ └── sandbox/ # Sandbox component (runs in E2B)
|
|
73
|
+
│ ├── agent/ # Code execution loop
|
|
74
|
+
│ ├── planning/ # Beads task tracking
|
|
75
|
+
│ └── state/ # File and artifact tracking
|
|
76
|
+
│
|
|
77
|
+
├── loro/ # CRDT utilities
|
|
78
|
+
│ ├── fs.ts # LoroFS - filesystem CRDT
|
|
79
|
+
│ └── beads.ts # LoroBeads - task graph CRDT
|
|
80
|
+
│
|
|
81
|
+
├── runtime/ # Sandbox runtime processes
|
|
82
|
+
│ ├── browser/ # Playwright browser automation
|
|
83
|
+
│ ├── pdf/ # PDF generation
|
|
84
|
+
│ └── lsp/ # Language server protocol
|
|
85
|
+
│
|
|
86
|
+
├── template/ # E2B template builder
|
|
87
|
+
│ └── build.ts # Template build script
|
|
88
|
+
│
|
|
89
|
+
├── cli/ # CLI commands
|
|
90
|
+
│ ├── commands/ # Individual commands
|
|
91
|
+
│ └── index.ts # CLI entry point
|
|
92
|
+
│
|
|
93
|
+
├── shared/ # Shared constants and types
|
|
94
|
+
├── tests/ # Test suites
|
|
95
|
+
└── docs/ # Documentation
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Development Modes
|
|
101
|
+
|
|
102
|
+
### As a Submodule (Recommended for SDK Development)
|
|
103
|
+
|
|
104
|
+
When Lakitu is used as a git submodule in another project:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# In parent project
|
|
108
|
+
cd submodules/lakitu-sdk
|
|
109
|
+
|
|
110
|
+
# Make changes
|
|
111
|
+
vim sdk/index.ts
|
|
112
|
+
|
|
113
|
+
# Commit to submodule
|
|
114
|
+
git add -A && git commit -m "feat: add new feature"
|
|
115
|
+
|
|
116
|
+
# Push submodule (triggers npm publish if version bumped)
|
|
117
|
+
git push origin main
|
|
118
|
+
|
|
119
|
+
# Back to parent, update submodule reference
|
|
120
|
+
cd ../..
|
|
121
|
+
git add submodules/lakitu-sdk
|
|
122
|
+
git commit -m "chore: update lakitu-sdk"
|
|
123
|
+
git push
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### As npm Package (For Consumers)
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Install latest
|
|
130
|
+
npm install @lakitu/sdk@latest
|
|
131
|
+
|
|
132
|
+
# Use in code
|
|
133
|
+
import { defineKSA, callGateway } from '@lakitu/sdk';
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Standalone Development
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# Clone directly
|
|
140
|
+
git clone https://github.com/shinyobjectz/lakitu.git
|
|
141
|
+
cd lakitu
|
|
142
|
+
|
|
143
|
+
# Install dependencies
|
|
144
|
+
bun install
|
|
145
|
+
|
|
146
|
+
# Run tests
|
|
147
|
+
bun test
|
|
148
|
+
|
|
149
|
+
# Build
|
|
150
|
+
bun run build
|
|
151
|
+
|
|
152
|
+
# Link locally for testing
|
|
153
|
+
npm link
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Making Changes
|
|
159
|
+
|
|
160
|
+
### SDK Code (`sdk/`)
|
|
161
|
+
|
|
162
|
+
The `sdk/` directory contains entry points that get compiled to `dist/`. These are what users import.
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
// sdk/index.ts - Main entry point
|
|
166
|
+
export { callGateway } from "./gateway";
|
|
167
|
+
export { localDb } from "./db";
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
After changes:
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
bun run build
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### KSA Code (`ksa/`)
|
|
177
|
+
|
|
178
|
+
KSA files are copied directly to the sandbox at build time. No compilation needed.
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
// ksa/myFeature.ts
|
|
182
|
+
import { callGateway } from "./_shared/gateway";
|
|
183
|
+
|
|
184
|
+
export const doThing = () => callGateway("path", {});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
After changes:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
bun sandbox:custom # Rebuild sandbox template
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Convex Code (`convex/`)
|
|
194
|
+
|
|
195
|
+
Two separate Convex projects:
|
|
196
|
+
|
|
197
|
+
- `convex/cloud/` - Cloud component, deployed as part of user's Convex app
|
|
198
|
+
- `convex/sandbox/` - Sandbox component, pre-deployed in E2B template
|
|
199
|
+
|
|
200
|
+
After cloud changes:
|
|
201
|
+
```bash
|
|
202
|
+
# Changes deploy with user's app automatically
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
After sandbox changes:
|
|
206
|
+
```bash
|
|
207
|
+
bun sandbox:custom # Must rebuild template
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Testing
|
|
213
|
+
|
|
214
|
+
### Unit Tests
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
bun test # Run all tests
|
|
218
|
+
bun test:watch # Watch mode
|
|
219
|
+
bun test:ui # Vitest UI
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Convex Integration Tests
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
bun test:convex # Run Convex tests
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Sandbox Integration Tests
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
bun test:integration # Full E2B sandbox tests
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Adding Tests
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
// tests/myFeature.test.ts
|
|
238
|
+
import { describe, it, expect } from 'vitest';
|
|
239
|
+
import { myFunction } from '../sdk/myFeature';
|
|
240
|
+
|
|
241
|
+
describe('myFeature', () => {
|
|
242
|
+
it('should work', () => {
|
|
243
|
+
expect(myFunction()).toBe(expected);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## Publishing
|
|
251
|
+
|
|
252
|
+
### Automatic (CI)
|
|
253
|
+
|
|
254
|
+
The GitHub Action publishes to npm when:
|
|
255
|
+
1. Version in `package.json` changes
|
|
256
|
+
2. Push to `main` branch
|
|
257
|
+
|
|
258
|
+
```yaml
|
|
259
|
+
# .github/workflows/publish.yml
|
|
260
|
+
if [ "$CURRENT" != "$NEW" ]; then npm publish; fi
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Manual
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
# Bump version
|
|
267
|
+
vim package.json # Change version
|
|
268
|
+
|
|
269
|
+
# Build and publish
|
|
270
|
+
bun run build
|
|
271
|
+
npm publish
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Version Strategy
|
|
275
|
+
|
|
276
|
+
- **Patch** (0.1.x): Bug fixes, doc updates
|
|
277
|
+
- **Minor** (0.x.0): New features, backward compatible
|
|
278
|
+
- **Major** (x.0.0): Breaking changes
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## SDK vs Implementation
|
|
283
|
+
|
|
284
|
+
Understanding what goes where:
|
|
285
|
+
|
|
286
|
+
### In the SDK (`@lakitu/sdk`)
|
|
287
|
+
|
|
288
|
+
- Core runtime (gateway, localDb, primitives)
|
|
289
|
+
- KSA builders and types
|
|
290
|
+
- Cloud Convex component
|
|
291
|
+
- Sandbox Convex component
|
|
292
|
+
- E2B template builder
|
|
293
|
+
- CLI commands
|
|
294
|
+
|
|
295
|
+
### In Implementation (User's Project)
|
|
296
|
+
|
|
297
|
+
- Project-specific KSAs (`convex/lakitu/ksa/`)
|
|
298
|
+
- Lakitu configuration (`convex/lakitu/config.ts`)
|
|
299
|
+
- Template customization (`convex/lakitu/template.config.ts`)
|
|
300
|
+
- Custom Convex features/services
|
|
301
|
+
- Gateway whitelist extensions
|
|
302
|
+
|
|
303
|
+
### Decision Guide
|
|
304
|
+
|
|
305
|
+
| Change | Where |
|
|
306
|
+
|--------|-------|
|
|
307
|
+
| New primitive (file, shell, etc.) | SDK `ksa/` |
|
|
308
|
+
| New gateway feature | SDK `convex/cloud/gateway/` |
|
|
309
|
+
| Project-specific capability | Implementation `convex/lakitu/ksa/` |
|
|
310
|
+
| Bug fix in agent loop | SDK `convex/sandbox/agent/` |
|
|
311
|
+
| New model preset | SDK `convex/cloud/models.ts` |
|
|
312
|
+
| Custom Convex backend | Implementation `convex/features/` |
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## Code Style
|
|
317
|
+
|
|
318
|
+
- **TypeScript** for all code
|
|
319
|
+
- **Bun** for runtime and package management
|
|
320
|
+
- **Vitest** for testing
|
|
321
|
+
- Use explicit types (no `any` without justification)
|
|
322
|
+
- Document public APIs with JSDoc
|
|
323
|
+
- Keep files focused and small
|
|
324
|
+
|
|
325
|
+
### Naming Conventions
|
|
326
|
+
|
|
327
|
+
- `camelCase` for functions and variables
|
|
328
|
+
- `PascalCase` for types and classes
|
|
329
|
+
- `UPPER_CASE` for constants
|
|
330
|
+
- `kebab-case` for file names (except TypeScript convention files)
|
|
331
|
+
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
## Getting Help
|
|
335
|
+
|
|
336
|
+
- [GitHub Issues](https://github.com/shinyobjectz/lakitu/issues)
|
|
337
|
+
- [Discord](#) (coming soon)
|
|
338
|
+
- [Discussions](https://github.com/shinyobjectz/lakitu/discussions)
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
## License
|
|
343
|
+
|
|
344
|
+
By contributing, you agree that your contributions will be licensed under the MIT License.
|