dotdo 0.0.1

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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +444 -0
  3. package/package.json +69 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Nathan Clevenger
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,444 @@
1
+ # DO
2
+
3
+ > **The AI-Native Durable Object that lets any AI Agent or Human .do anything.**
4
+
5
+ DO is the foundational infrastructure layer powering the entire [.do](https://dotdo.ai) platform. Built on Cloudflare's edge runtime, it's the intelligent substrate that enables [Functions.do](https://functions.do), [Database.do](https://database.do), [Workflows.do](https://workflows.do), [APIs.do](https://apis.do), [Events.do](https://events.do), [Actions.do](https://actions.do), and every other .do service - all rolling up to [Platform.do](https://platform.do).
6
+
7
+ ```
8
+ ┌─────────────────────────────────────────────────────────────────────────────┐
9
+ │ Platform.do │
10
+ │ ┌─────────────┬─────────────┬─────────────┬─────────────┬─────────────┐ │
11
+ │ │ Functions.do│ Database.do │ Workflows.do│ Events.do │ Actions.do │ │
12
+ │ ├─────────────┼─────────────┼─────────────┼─────────────┼─────────────┤ │
13
+ │ │ APIs.do │ RPC.do │ CLI.do │ MCP.do │ Agents.do │ │
14
+ │ └─────────────┴─────────────┴─────────────┴─────────────┴─────────────┘ │
15
+ │ │ │
16
+ │ ┌─────────┴─────────┐ │
17
+ │ │ DO │ ← AI-Native Durable Object │
18
+ │ │ (This Package) │ │
19
+ │ └───────────────────┘ │
20
+ │ │ │
21
+ │ ┌─────────────────────────────────┴───────────────────────────────────┐ │
22
+ │ │ Cloudflare Workers + Durable Objects + SQLite │ │
23
+ │ └─────────────────────────────────────────────────────────────────────┘ │
24
+ └─────────────────────────────────────────────────────────────────────────────┘
25
+ ```
26
+
27
+ ## Why DO?
28
+
29
+ The future of software is AI-native. Every application will be built for AI agents and humans to collaborate seamlessly. DO provides:
30
+
31
+ - **Graph-Native Data**: Things and Relationships form a semantic knowledge graph
32
+ - **Event Sourcing**: Immutable audit trails for compliance and AI reasoning
33
+ - **Durable Execution**: Actions with state machines, retries, and guaranteed delivery
34
+ - **Multi-Transport**: Workers RPC, HTTP, WebSocket, and MCP for AI tool integration
35
+ - **Edge-First**: Runs on Cloudflare's global edge network for sub-100ms latency
36
+
37
+ ## Installation
38
+
39
+ ```bash
40
+ npm install @dotdo/do
41
+ ```
42
+
43
+ ## Quick Start
44
+
45
+ ```typescript
46
+ import { DO } from '@dotdo/do'
47
+
48
+ export class MyDO extends DO {
49
+ // Your custom methods are automatically exposed via RPC
50
+ async processOrder(orderId: string) {
51
+ // Track the event (immutable audit trail)
52
+ await this.track({
53
+ type: 'Order.processing',
54
+ source: 'order-service',
55
+ data: { orderId }
56
+ })
57
+
58
+ // Create a durable action that survives failures
59
+ return this.doAction({
60
+ actor: 'system',
61
+ object: `order:${orderId}`,
62
+ action: 'process'
63
+ })
64
+ }
65
+ }
66
+ ```
67
+
68
+ ## The Data Model
69
+
70
+ DO implements a rich data model designed for AI agents and complex business logic:
71
+
72
+ ```
73
+ ┌─────────────────────────────────────────────────────────────────────────────┐
74
+ │ DO Data Model │
75
+ │ │
76
+ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
77
+ │ │ Things │────────→│Relationships│←────────│ Things │ │
78
+ │ │ (Nodes) │ │ (Edges) │ │ (Nodes) │ │
79
+ │ └─────────────┘ └─────────────┘ └─────────────┘ │
80
+ │ │
81
+ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
82
+ │ │ Events │ │ Actions │ │ Artifacts │ │
83
+ │ │ (Immutable) │ │ (Durable) │ │ (Cached) │ │
84
+ │ └─────────────┘ └─────────────┘ └─────────────┘ │
85
+ │ │
86
+ │ ┌─────────────────────────────────────────────────────────────┐ │
87
+ │ │ Workflows │ │
88
+ │ │ (Orchestration & State Machines) │ │
89
+ │ └─────────────────────────────────────────────────────────────┘ │
90
+ └─────────────────────────────────────────────────────────────────────────────┘
91
+ ```
92
+
93
+ ### Things (Graph Nodes)
94
+
95
+ URL-addressable entities that form the nodes of your knowledge graph:
96
+
97
+ ```typescript
98
+ // Create a Thing with semantic addressing
99
+ const user = await this.Thing.create({
100
+ ns: 'acme.com', // Namespace
101
+ type: 'user', // Entity type
102
+ id: 'john', // Unique ID
103
+ data: {
104
+ name: 'John Doe',
105
+ email: 'john@acme.com'
106
+ }
107
+ })
108
+ // URL: https://acme.com/user/john
109
+
110
+ // Traverse the graph
111
+ const posts = await this.Thing.related(user.url, 'authored')
112
+ const followers = await this.Thing.references(user.url, 'follows')
113
+ ```
114
+
115
+ ### Relationships (Graph Edges)
116
+
117
+ Typed connections between Things that enable semantic queries:
118
+
119
+ ```typescript
120
+ // Create a relationship
121
+ await this.relate({
122
+ from: 'https://acme.com/user/john',
123
+ type: 'authored',
124
+ to: 'https://acme.com/post/hello-world',
125
+ data: { role: 'primary' }
126
+ })
127
+
128
+ // Query relationships
129
+ const authorships = await this.relationships(userUrl, 'authored')
130
+ ```
131
+
132
+ ### Events (Immutable Audit Trail)
133
+
134
+ Append-only event log for compliance, debugging, and AI reasoning:
135
+
136
+ ```typescript
137
+ // Track an event (immutable, no updates or deletes)
138
+ const event = await this.track({
139
+ type: 'Order.created',
140
+ source: 'checkout-service',
141
+ data: { orderId: '123', amount: 99.99 },
142
+ correlationId: 'request-abc'
143
+ })
144
+
145
+ // Query events for AI analysis
146
+ const orderEvents = await this.queryEvents({
147
+ type: 'Order.created',
148
+ after: new Date('2024-01-01'),
149
+ correlationId: 'request-abc'
150
+ })
151
+ ```
152
+
153
+ ### Actions (Durable Execution)
154
+
155
+ Long-running operations with state machines, retries, and guaranteed delivery:
156
+
157
+ ```typescript
158
+ // Fire-and-forget (queued for processing)
159
+ await this.send({
160
+ actor: 'user:123',
161
+ object: 'invoice:456',
162
+ action: 'generate'
163
+ })
164
+
165
+ // Durable execution with retries
166
+ const action = await this.doAction({
167
+ actor: 'system',
168
+ object: 'report:789',
169
+ action: 'compile',
170
+ metadata: {
171
+ maxRetries: 3,
172
+ retryDelay: 1000
173
+ }
174
+ })
175
+
176
+ // State transitions
177
+ await this.completeAction(action.id, { url: 'https://...' })
178
+ // or
179
+ await this.failAction(action.id, 'Compilation failed')
180
+ ```
181
+
182
+ ### Artifacts (Intelligent Caching)
183
+
184
+ Cache derived content with TTL and hash-based invalidation:
185
+
186
+ ```typescript
187
+ // Store compiled artifact
188
+ await this.storeArtifact({
189
+ key: 'module:user-service',
190
+ type: 'esm',
191
+ source: 'https://github.com/acme/user-service',
192
+ sourceHash: 'abc123',
193
+ content: compiledModule,
194
+ expiresAt: new Date(Date.now() + 86400000) // 24h TTL
195
+ })
196
+
197
+ // Retrieve with cache hit
198
+ const cached = await this.getArtifactBySource(sourceUrl, 'esm')
199
+ ```
200
+
201
+ ### Workflows (Orchestration)
202
+
203
+ Event-driven workflows with state machines and human-in-the-loop:
204
+
205
+ ```typescript
206
+ async handleWorkflow($: WorkflowContext) {
207
+ // Register event handlers
208
+ $.on.Order.created = async (event) => {
209
+ await $.do('process', event.data)
210
+ $.set('status', 'processing')
211
+ }
212
+
213
+ // Schedule recurring tasks
214
+ $.every.cron('0 * * * *') = async () => {
215
+ await $.send('cleanup', { olderThan: '24h' })
216
+ }
217
+
218
+ // Access persistent state
219
+ const status = $.get('status')
220
+ }
221
+ ```
222
+
223
+ ## Multi-Transport Architecture
224
+
225
+ DO speaks every protocol your AI agents and applications need:
226
+
227
+ ### Workers RPC (Native Performance)
228
+
229
+ ```typescript
230
+ // Direct service binding calls
231
+ const user = await env.DATABASE.get(id).Thing.get('https://acme.com/user/john')
232
+ const events = await env.DATABASE.get(id).queryEvents({ type: 'User.created' })
233
+ ```
234
+
235
+ ### HTTP RPC (Universal Access)
236
+
237
+ ```bash
238
+ curl -X POST https://your-do.workers.dev/rpc \
239
+ -H 'Authorization: Bearer $TOKEN' \
240
+ -H 'Content-Type: application/json' \
241
+ -d '{"method": "Thing.create", "params": [{"ns": "acme.com", "type": "user", "id": "jane", "data": {"name": "Jane"}}]}'
242
+ ```
243
+
244
+ ### MCP (AI Tool Integration)
245
+
246
+ DO is a first-class MCP server, exposing tools for AI agents:
247
+
248
+ ```bash
249
+ # Discover available tools
250
+ curl https://your-do.workers.dev/mcp
251
+
252
+ # Search across all data
253
+ curl -X POST https://your-do.workers.dev/mcp/tools/search \
254
+ -d '{"query": "active premium users", "collections": ["users"]}'
255
+
256
+ # Fetch any resource
257
+ curl -X POST https://your-do.workers.dev/mcp/tools/fetch \
258
+ -d '{"target": "https://acme.com/user/john"}'
259
+
260
+ # Execute code in sandbox
261
+ curl -X POST https://your-do.workers.dev/mcp/tools/do \
262
+ -d '{"code": "return users.filter(u => u.premium)"}'
263
+ ```
264
+
265
+ ### WebSocket (Real-time)
266
+
267
+ ```typescript
268
+ const ws = new WebSocket('wss://your-do.workers.dev')
269
+ ws.send(JSON.stringify({
270
+ jsonrpc: '2.0',
271
+ method: 'Thing.list',
272
+ params: [{ type: 'notification', limit: 10 }]
273
+ }))
274
+ ```
275
+
276
+ ### REST API (HATEOAS)
277
+
278
+ ```bash
279
+ # Discover endpoints
280
+ curl https://your-do.workers.dev/
281
+
282
+ # Standard CRUD
283
+ curl https://your-do.workers.dev/api/users
284
+ curl -X POST https://your-do.workers.dev/api/users -d '{"name": "John"}'
285
+ ```
286
+
287
+ ## Authentication & Security
288
+
289
+ Enterprise-grade auth with JWT validation, RBAC, and rate limiting:
290
+
291
+ ```typescript
292
+ import { DO, requirePermission } from '@dotdo/do'
293
+
294
+ export class SecureDO extends DO {
295
+ @requirePermission('orders:write')
296
+ async createOrder(data: OrderData) {
297
+ // Auth context automatically available
298
+ const { userId, organizationId, permissions } = this.getAuthContext()
299
+
300
+ return this.create('orders', {
301
+ ...data,
302
+ createdBy: userId,
303
+ organization: organizationId
304
+ })
305
+ }
306
+ }
307
+ ```
308
+
309
+ **Supported auth methods:**
310
+ - Bearer JWT with JWKS validation (WorkOS integration)
311
+ - API keys via `X-API-Key` header
312
+ - Basic authentication
313
+ - Custom auth context via `X-Auth-Context` header
314
+ - Session management with expiry and refresh
315
+
316
+ **Security features:**
317
+ - Role-based access control (RBAC) with wildcards
318
+ - Rate limiting per user/IP with fail-closed semantics
319
+ - Input validation via Zod schemas
320
+ - Sandboxed code execution with blocked globals
321
+
322
+ ## Class Hierarchy
323
+
324
+ DO extends the Cloudflare ecosystem:
325
+
326
+ ```
327
+ DurableObject (Cloudflare)
328
+ └── Server (agents)
329
+ └── Agent (agents)
330
+ └── DO (@dotdo/do) ← You are here
331
+ └── MongoDB (mongo.do)
332
+ └── Redis (redis.do)
333
+ └── Neo4j (neo4j.do)
334
+ └── Your custom classes
335
+ ```
336
+
337
+ ## The .do Ecosystem
338
+
339
+ DO is the foundation that powers:
340
+
341
+ | Service | Purpose |
342
+ |---------|---------|
343
+ | [Functions.do](https://functions.do) | Atomic, composable business logic |
344
+ | [Database.do](https://database.do) | AI-native data with vector search |
345
+ | [Workflows.do](https://workflows.do) | Declarative orchestration |
346
+ | [APIs.do](https://apis.do) | Unified REST/GraphQL gateway |
347
+ | [Events.do](https://events.do) | Event sourcing and streaming |
348
+ | [Actions.do](https://actions.do) | Durable execution and retries |
349
+ | [RPC.do](https://rpc.do) | Multi-transport RPC framework |
350
+ | [MCP.do](https://mcp.do) | Model Context Protocol server |
351
+ | [CLI.do](https://cli.do) | Developer tooling |
352
+ | [Agents.do](https://agents.do) | AI agent deployment |
353
+
354
+ All powered by [Platform.do](https://platform.do) - Business-as-Code infrastructure.
355
+
356
+ ## Configuration
357
+
358
+ ```toml
359
+ # wrangler.toml
360
+ name = "my-do"
361
+
362
+ [[durable_objects.bindings]]
363
+ name = "MY_DO"
364
+ class_name = "MyDO"
365
+
366
+ [[migrations]]
367
+ tag = "v1"
368
+ new_sqlite_classes = ["MyDO"]
369
+ ```
370
+
371
+ ## Advanced Features
372
+
373
+ ### Change Data Capture (CDC)
374
+
375
+ Stream changes to data warehouses:
376
+
377
+ ```typescript
378
+ // Create batch for analytics export
379
+ const batch = await this.createCDCBatch({
380
+ startTime: yesterday,
381
+ endTime: now
382
+ })
383
+
384
+ // Transform to Parquet and export to R2
385
+ await this.transformBatch(batch.id)
386
+ ```
387
+
388
+ ### Schema Migrations
389
+
390
+ Version and evolve your schema:
391
+
392
+ ```typescript
393
+ const migrations = [
394
+ {
395
+ version: 1,
396
+ name: 'add-premium-flag',
397
+ up: 'ALTER TABLE users ADD COLUMN premium BOOLEAN DEFAULT FALSE',
398
+ down: 'ALTER TABLE users DROP COLUMN premium'
399
+ }
400
+ ]
401
+ ```
402
+
403
+ ### Deployment Router
404
+
405
+ Multi-version deployments with health checks:
406
+
407
+ ```typescript
408
+ // Route traffic to healthy deployments
409
+ const router = new DeployRouter({
410
+ healthCheck: {
411
+ interval: 30000,
412
+ threshold: 3
413
+ }
414
+ })
415
+ ```
416
+
417
+ ## Philosophy
418
+
419
+ > "Build the infrastructure that enables Autonomous General Intelligence to operate millions of profitable businesses, transforming every industry and empowering every professional."
420
+
421
+ DO embodies this vision by providing:
422
+
423
+ 1. **Semantic Data**: Things and Relationships model real-world entities and their connections
424
+ 2. **Audit Trails**: Events create immutable records for compliance and AI reasoning
425
+ 3. **Durable Execution**: Actions guarantee operations complete even across failures
426
+ 4. **AI-First Protocols**: MCP integration makes every DO a tool for AI agents
427
+ 5. **Edge Performance**: Sub-100ms latency globally via Cloudflare's network
428
+
429
+ ## Related Packages
430
+
431
+ - [`agents`](https://www.npmjs.com/package/agents) - Base Agent class for Durable Objects
432
+ - [`@dotdo/middleware`](https://www.npmjs.com/package/@dotdo/middleware) - Middleware utilities
433
+ - [`hono`](https://www.npmjs.com/package/hono) - Lightweight web framework
434
+
435
+ ## License
436
+
437
+ MIT
438
+
439
+ ---
440
+
441
+ <p align="center">
442
+ <strong>Built by <a href="https://dotdo.ai">.do</a></strong><br>
443
+ <em>Let any AI Agent or Human .do anything.</em>
444
+ </p>
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "dotdo",
3
+ "version": "0.0.1",
4
+ "description": "Base DO class for Cloudflare Workers - an agentic database that can DO anything",
5
+ "author": "Nathan Clevenger",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "files": [
11
+ "dist",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/index.js",
18
+ "types": "./dist/index.d.ts"
19
+ },
20
+ "./rpc": {
21
+ "import": "./dist/rpc/index.js",
22
+ "types": "./dist/rpc/index.d.ts"
23
+ },
24
+ "./mcp": {
25
+ "import": "./dist/mcp/index.js",
26
+ "types": "./dist/mcp/index.d.ts"
27
+ }
28
+ },
29
+ "scripts": {
30
+ "build": "tsup",
31
+ "dev": "tsup --watch",
32
+ "test": "vitest run",
33
+ "test:watch": "vitest",
34
+ "typecheck": "tsc --noEmit"
35
+ },
36
+ "dependencies": {
37
+ "agents": "^0.0.66",
38
+ "hono": "^4.6.0",
39
+ "zod": "^4.3.5"
40
+ },
41
+ "devDependencies": {
42
+ "@cloudflare/vitest-pool-workers": "^0.11.1",
43
+ "@cloudflare/workers-types": "^4.20240925.0",
44
+ "@types/node": "^20.19.27",
45
+ "tsup": "^8.5.1",
46
+ "typescript": "^5.6.0",
47
+ "vitest": "^3.2.4"
48
+ },
49
+ "peerDependencies": {
50
+ "wrangler": "^4.0.0"
51
+ },
52
+ "peerDependenciesMeta": {
53
+ "wrangler": {
54
+ "optional": true
55
+ }
56
+ },
57
+ "keywords": [
58
+ "cloudflare",
59
+ "workers",
60
+ "durable-objects",
61
+ "rpc",
62
+ "mcp",
63
+ "database",
64
+ "agentic"
65
+ ],
66
+ "engines": {
67
+ "node": ">=18.0.0"
68
+ }
69
+ }