dotdo 0.0.2 → 0.1.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.
Files changed (313) hide show
  1. package/cli/README.md +238 -0
  2. package/cli/agent.ts +72 -0
  3. package/cli/bin.js +44 -0
  4. package/cli/bin.ts +38 -0
  5. package/cli/build.ts +157 -0
  6. package/cli/commands/auth/login.ts +14 -0
  7. package/cli/commands/auth/logout.ts +6 -0
  8. package/cli/commands/auth/whoami.ts +16 -0
  9. package/cli/commands/deploy-multi.ts +245 -0
  10. package/cli/commands/dev/deploy.ts +100 -0
  11. package/cli/commands/dev/dev.ts +95 -0
  12. package/cli/commands/dev/logs.ts +91 -0
  13. package/cli/commands/dev-local.ts +88 -0
  14. package/cli/commands/do-ops.ts +314 -0
  15. package/cli/commands/index.ts +100 -0
  16. package/cli/commands/init.ts +247 -0
  17. package/cli/commands/introspect/emitter.ts +315 -0
  18. package/cli/commands/introspect/index.ts +193 -0
  19. package/cli/commands/link.ts +598 -0
  20. package/cli/commands/snippets.ts +415 -0
  21. package/cli/commands/tunnel.ts +239 -0
  22. package/cli/device-auth.ts +289 -0
  23. package/cli/fallback.ts +12 -0
  24. package/cli/index.ts +121 -0
  25. package/cli/main.ts +246 -0
  26. package/cli/mcp-stdio.ts +790 -0
  27. package/cli/package.json +62 -0
  28. package/cli/runtime/do-registry.ts +193 -0
  29. package/cli/runtime/embedded-db.ts +344 -0
  30. package/cli/runtime/index.ts +9 -0
  31. package/cli/runtime/miniflare-adapter.ts +162 -0
  32. package/cli/sandbox.ts +82 -0
  33. package/cli/src/args.ts +174 -0
  34. package/cli/src/auth.ts +55 -0
  35. package/cli/src/commands/call.ts +84 -0
  36. package/cli/src/commands/charge.ts +96 -0
  37. package/cli/src/commands/config.ts +115 -0
  38. package/cli/src/commands/email.ts +112 -0
  39. package/cli/src/commands/llm.ts +115 -0
  40. package/cli/src/commands/queue.ts +134 -0
  41. package/cli/src/commands/text.ts +86 -0
  42. package/cli/src/config.ts +185 -0
  43. package/cli/src/output.ts +246 -0
  44. package/cli/src/rpc.ts +192 -0
  45. package/cli/utils/config.ts +282 -0
  46. package/cli/utils/detect.ts +73 -0
  47. package/cli/utils/index.ts +15 -0
  48. package/cli/utils/logger.ts +232 -0
  49. package/dist/ai/template-literals.js +2 -2
  50. package/dist/ai/template-literals.js.map +1 -1
  51. package/dist/api/middleware/auth.js +3 -2
  52. package/dist/api/middleware/auth.js.map +1 -1
  53. package/dist/db/iceberg/inverted-index.js +1 -1
  54. package/dist/db/iceberg/inverted-index.js.map +1 -1
  55. package/dist/db/iceberg/puffin.js.map +1 -1
  56. package/dist/db/json-indexes.js.map +1 -1
  57. package/dist/db/objects.js.map +1 -1
  58. package/dist/db/primitives/dag-scheduler/index.js +1 -1
  59. package/dist/db/primitives/dag-scheduler/index.js.map +1 -1
  60. package/dist/db/primitives/observability.js.map +1 -1
  61. package/dist/db/primitives/schema-evolution.js.map +1 -1
  62. package/dist/db/primitives/temporal-store.js.map +1 -1
  63. package/dist/db/primitives/typed-column-store.js.map +1 -1
  64. package/dist/db/primitives/utils/duration.js.map +1 -1
  65. package/dist/db/primitives/utils/murmur3.js +12 -14
  66. package/dist/db/primitives/utils/murmur3.js.map +1 -1
  67. package/dist/db/primitives/window-manager.js.map +1 -1
  68. package/dist/db/stores.js.map +1 -1
  69. package/dist/db/things.js.map +1 -1
  70. package/dist/lib/DODispatcher.js +2 -2
  71. package/dist/lib/DODispatcher.js.map +1 -1
  72. package/dist/lib/auto-wiring.js.map +1 -1
  73. package/dist/lib/channels/email.js +1 -1
  74. package/dist/lib/channels/email.js.map +1 -1
  75. package/dist/lib/channels/slack-blockkit.js.map +1 -1
  76. package/dist/lib/cloudflare/ai.js +1 -1
  77. package/dist/lib/cloudflare/ai.js.map +1 -1
  78. package/dist/lib/cloudflare/kv.js +1 -1
  79. package/dist/lib/cloudflare/kv.js.map +1 -1
  80. package/dist/lib/cloudflare/r2.js +3 -3
  81. package/dist/lib/cloudflare/r2.js.map +1 -1
  82. package/dist/lib/cloudflare/vectorize.js.map +1 -1
  83. package/dist/lib/cloudflare/workflows.js.map +1 -1
  84. package/dist/lib/executors/AgenticFunctionExecutor.js.map +1 -1
  85. package/dist/lib/executors/CodeFunctionExecutor.js.map +1 -1
  86. package/dist/lib/executors/GenerativeFunctionExecutor.js.map +1 -1
  87. package/dist/lib/executors/HumanFunctionExecutor.js +1 -1
  88. package/dist/lib/executors/HumanFunctionExecutor.js.map +1 -1
  89. package/dist/lib/executors/ParallelStepExecutor.js.map +1 -1
  90. package/dist/lib/experiments.js.map +1 -1
  91. package/dist/lib/flags/store.js.map +1 -1
  92. package/dist/lib/functions/FunctionComposition.js.map +1 -1
  93. package/dist/lib/functions/FunctionMiddleware.js.map +1 -1
  94. package/dist/lib/functions/FunctionRegistry.js.map +1 -1
  95. package/dist/lib/humans/templates.js.map +1 -1
  96. package/dist/lib/identity.js +2 -2
  97. package/dist/lib/identity.js.map +1 -1
  98. package/dist/lib/logging/index.js.map +1 -1
  99. package/dist/lib/mixins/bash.js +1 -73
  100. package/dist/lib/mixins/bash.js.map +1 -1
  101. package/dist/lib/mixins/git.js +0 -5
  102. package/dist/lib/mixins/git.js.map +1 -1
  103. package/dist/lib/mixins/npm.js.map +1 -1
  104. package/dist/lib/noun-id.js.map +1 -1
  105. package/dist/lib/rate-limit/sliding-window.js.map +1 -1
  106. package/dist/lib/rpc/bindings.js.map +1 -1
  107. package/dist/lib/safe-stringify.js.map +1 -1
  108. package/dist/lib/sandbox/miniflare-sandbox.js.map +1 -1
  109. package/dist/lib/sqids.js.map +1 -1
  110. package/dist/lib/sql/adapters/node-sql-parser.js.map +1 -1
  111. package/dist/lib/sql/adapters/pgsql-parser.js +19 -18
  112. package/dist/lib/sql/adapters/pgsql-parser.js.map +1 -1
  113. package/dist/metrics/hunch.js.map +1 -1
  114. package/dist/objects/API.js +1 -1
  115. package/dist/objects/API.js.map +1 -1
  116. package/dist/objects/Agent.js.map +1 -1
  117. package/dist/objects/Browser.js.map +1 -1
  118. package/dist/objects/CLI.js.map +1 -1
  119. package/dist/objects/DOBase.js.map +1 -1
  120. package/dist/objects/DOCache.js +153 -0
  121. package/dist/objects/DOCache.js.map +1 -0
  122. package/dist/objects/DOFull.js.map +1 -1
  123. package/dist/objects/Entity.js.map +1 -1
  124. package/dist/objects/Human.js.map +1 -1
  125. package/dist/objects/IcebergMetadataDO.js.map +1 -1
  126. package/dist/objects/IntegrationsDO.js.map +1 -1
  127. package/dist/objects/ObservabilityBroadcaster.js.map +1 -1
  128. package/dist/objects/Package.js.map +1 -1
  129. package/dist/objects/Product.js +1 -1
  130. package/dist/objects/Product.js.map +1 -1
  131. package/dist/objects/SaaS.js.map +1 -1
  132. package/dist/objects/SandboxDO.js.map +1 -1
  133. package/dist/objects/Service.js.map +1 -1
  134. package/dist/objects/VectorShardDO.js +9 -7
  135. package/dist/objects/VectorShardDO.js.map +1 -1
  136. package/dist/objects/Workflow.js.map +1 -1
  137. package/dist/objects/WorkflowFactory.js.map +1 -1
  138. package/dist/objects/WorkflowRuntime.js.map +1 -1
  139. package/dist/objects/lifecycle/Branch.js.map +1 -1
  140. package/dist/objects/lifecycle/Clone.js +1 -1
  141. package/dist/objects/lifecycle/Clone.js.map +1 -1
  142. package/dist/objects/lifecycle/Compact.js.map +1 -1
  143. package/dist/objects/lifecycle/Shard.js.map +1 -1
  144. package/dist/objects/persistence/checkpoint-manager.js.map +1 -1
  145. package/dist/objects/persistence/migration-runner.js.map +1 -1
  146. package/dist/objects/persistence/replication-manager.js +2 -2
  147. package/dist/objects/persistence/replication-manager.js.map +1 -1
  148. package/dist/objects/persistence/tiered-storage-manager.js.map +1 -1
  149. package/dist/objects/persistence/wal-manager.js.map +1 -1
  150. package/dist/objects/transport/auth-layer.js.map +1 -1
  151. package/dist/objects/transport/chain.js.map +1 -1
  152. package/dist/objects/transport/mcp-server.js +7 -6
  153. package/dist/objects/transport/mcp-server.js.map +1 -1
  154. package/dist/objects/transport/rest-autowire.js +3 -2
  155. package/dist/objects/transport/rest-autowire.js.map +1 -1
  156. package/dist/objects/transport/rest-router.js.map +1 -1
  157. package/dist/objects/transport/rpc-server.js +18 -15
  158. package/dist/objects/transport/rpc-server.js.map +1 -1
  159. package/dist/objects/transport/shared.js +2 -1
  160. package/dist/objects/transport/shared.js.map +1 -1
  161. package/dist/snippets/artifacts-ingest.js.map +1 -1
  162. package/dist/snippets/artifacts-serve.js.map +1 -1
  163. package/dist/snippets/search.js.map +1 -1
  164. package/dist/workflows/ScheduleManager.js.map +1 -1
  165. package/dist/workflows/StepResultStorage.js.map +1 -1
  166. package/dist/workflows/WaitForEventManager.js.map +1 -1
  167. package/dist/workflows/compat/backends/cloudflare-workflows.js.map +1 -1
  168. package/dist/workflows/compat/inngest/index.js.map +1 -1
  169. package/dist/workflows/compat/qstash/index.js.map +1 -1
  170. package/dist/workflows/compat/temporal/client.js.map +1 -1
  171. package/dist/workflows/compat/temporal/index.js.map +1 -1
  172. package/dist/workflows/compat/trigger/index.js.map +1 -1
  173. package/dist/workflows/compat/utils/index.js.map +1 -1
  174. package/dist/workflows/context/correlation.js +2 -2
  175. package/dist/workflows/context/correlation.js.map +1 -1
  176. package/dist/workflows/context/experiment.js +1 -1
  177. package/dist/workflows/context/experiment.js.map +1 -1
  178. package/dist/workflows/context/flag.js +1 -1
  179. package/dist/workflows/context/flag.js.map +1 -1
  180. package/dist/workflows/context/measure.js +1 -1
  181. package/dist/workflows/context/measure.js.map +1 -1
  182. package/dist/workflows/context/rate-limit.js.map +1 -1
  183. package/dist/workflows/data/entity-events/entity-events.js.map +1 -1
  184. package/dist/workflows/data/experiment/index.js.map +1 -1
  185. package/dist/workflows/data/goal/context.js +1 -1
  186. package/dist/workflows/data/goal/context.js.map +1 -1
  187. package/dist/workflows/data/measure/index.js +1 -1
  188. package/dist/workflows/data/measure/index.js.map +1 -1
  189. package/dist/workflows/data/stream/index.js +10 -76
  190. package/dist/workflows/data/stream/index.js.map +1 -1
  191. package/dist/workflows/data/track/context.js.map +1 -1
  192. package/dist/workflows/data/view/context.js.map +1 -1
  193. package/dist/workflows/domain.js.map +1 -1
  194. package/dist/workflows/flags.js +1 -1
  195. package/dist/workflows/flags.js.map +1 -1
  196. package/dist/workflows/hash.js.map +1 -1
  197. package/dist/workflows/on.js +1 -1
  198. package/dist/workflows/on.js.map +1 -1
  199. package/dist/workflows/schedule-builder.js.map +1 -1
  200. package/dist/workflows/visibility/index.js +0 -2
  201. package/dist/workflows/visibility/index.js.map +1 -1
  202. package/dist/workflows/visibility/query-parser.js.map +1 -1
  203. package/package.json +18 -3
  204. package/dist/api/analytics/router.js +0 -601
  205. package/dist/api/analytics/router.js.map +0 -1
  206. package/dist/api/index.js +0 -158
  207. package/dist/api/index.js.map +0 -1
  208. package/dist/api/middleware/error-handling.js +0 -176
  209. package/dist/api/middleware/error-handling.js.map +0 -1
  210. package/dist/api/middleware/request-id.js +0 -21
  211. package/dist/api/middleware/request-id.js.map +0 -1
  212. package/dist/api/pages.js +0 -1180
  213. package/dist/api/pages.js.map +0 -1
  214. package/dist/api/routes/api.js +0 -612
  215. package/dist/api/routes/api.js.map +0 -1
  216. package/dist/api/routes/browsers.js +0 -471
  217. package/dist/api/routes/browsers.js.map +0 -1
  218. package/dist/api/routes/do.js +0 -188
  219. package/dist/api/routes/do.js.map +0 -1
  220. package/dist/api/routes/mcp.js +0 -459
  221. package/dist/api/routes/mcp.js.map +0 -1
  222. package/dist/api/routes/obs.js +0 -445
  223. package/dist/api/routes/obs.js.map +0 -1
  224. package/dist/api/routes/openapi.js +0 -794
  225. package/dist/api/routes/openapi.js.map +0 -1
  226. package/dist/api/routes/rpc.js +0 -1103
  227. package/dist/api/routes/rpc.js.map +0 -1
  228. package/dist/api/routes/sandboxes.js +0 -389
  229. package/dist/api/routes/sandboxes.js.map +0 -1
  230. package/dist/api/test-do.js +0 -38
  231. package/dist/api/test-do.js.map +0 -1
  232. package/dist/api/types.js +0 -11
  233. package/dist/api/types.js.map +0 -1
  234. package/dist/cli/bin.js +0 -2
  235. package/dist/cli/main.js +0 -52342
  236. package/dist/do/bash.js +0 -35
  237. package/dist/do/bash.js.map +0 -1
  238. package/dist/do/fs.js +0 -25
  239. package/dist/do/fs.js.map +0 -1
  240. package/dist/do/full.js +0 -61
  241. package/dist/do/full.js.map +0 -1
  242. package/dist/do/git.js +0 -28
  243. package/dist/do/git.js.map +0 -1
  244. package/dist/do/index.js +0 -52
  245. package/dist/do/index.js.map +0 -1
  246. package/dist/lib/agent/tools/bash.js +0 -336
  247. package/dist/lib/agent/tools/bash.js.map +0 -1
  248. package/dist/lib/agent/tools/edit.js +0 -157
  249. package/dist/lib/agent/tools/edit.js.map +0 -1
  250. package/dist/lib/agent/tools/glob.js +0 -137
  251. package/dist/lib/agent/tools/glob.js.map +0 -1
  252. package/dist/lib/agent/tools/grep.js +0 -315
  253. package/dist/lib/agent/tools/grep.js.map +0 -1
  254. package/dist/lib/agent/tools/index.js +0 -71
  255. package/dist/lib/agent/tools/index.js.map +0 -1
  256. package/dist/lib/agent/tools/read.js +0 -212
  257. package/dist/lib/agent/tools/read.js.map +0 -1
  258. package/dist/lib/agent/tools/types.js +0 -197
  259. package/dist/lib/agent/tools/types.js.map +0 -1
  260. package/dist/lib/agent/tools/write.js +0 -159
  261. package/dist/lib/agent/tools/write.js.map +0 -1
  262. package/dist/lib/mixins/index.js +0 -29
  263. package/dist/lib/mixins/index.js.map +0 -1
  264. package/dist/primitives/bashx/src/ast/analyze.js +0 -1472
  265. package/dist/primitives/bashx/src/ast/analyze.js.map +0 -1
  266. package/dist/primitives/bashx/src/ast/parser.js +0 -1488
  267. package/dist/primitives/bashx/src/ast/parser.js.map +0 -1
  268. package/dist/primitives/bashx/src/do/commands/crypto.js +0 -1954
  269. package/dist/primitives/bashx/src/do/commands/crypto.js.map +0 -1
  270. package/dist/primitives/bashx/src/do/commands/data-processing.js +0 -1812
  271. package/dist/primitives/bashx/src/do/commands/data-processing.js.map +0 -1
  272. package/dist/primitives/bashx/src/do/commands/extended-utils.js +0 -804
  273. package/dist/primitives/bashx/src/do/commands/extended-utils.js.map +0 -1
  274. package/dist/primitives/bashx/src/do/commands/math-control.js +0 -1122
  275. package/dist/primitives/bashx/src/do/commands/math-control.js.map +0 -1
  276. package/dist/primitives/bashx/src/do/commands/posix-utils.js +0 -1015
  277. package/dist/primitives/bashx/src/do/commands/posix-utils.js.map +0 -1
  278. package/dist/primitives/bashx/src/do/commands/system-utils.js +0 -687
  279. package/dist/primitives/bashx/src/do/commands/system-utils.js.map +0 -1
  280. package/dist/primitives/bashx/src/do/commands/test-command.js +0 -523
  281. package/dist/primitives/bashx/src/do/commands/test-command.js.map +0 -1
  282. package/dist/primitives/bashx/src/do/commands/text-processing.js +0 -1550
  283. package/dist/primitives/bashx/src/do/commands/text-processing.js.map +0 -1
  284. package/dist/primitives/bashx/src/do/container-executor.js +0 -429
  285. package/dist/primitives/bashx/src/do/container-executor.js.map +0 -1
  286. package/dist/primitives/bashx/src/do/index.js +0 -668
  287. package/dist/primitives/bashx/src/do/index.js.map +0 -1
  288. package/dist/primitives/bashx/src/do/tiered-executor.js +0 -2647
  289. package/dist/primitives/bashx/src/do/tiered-executor.js.map +0 -1
  290. package/dist/primitives/bashx/src/do/worker.js +0 -352
  291. package/dist/primitives/bashx/src/do/worker.js.map +0 -1
  292. package/dist/primitives/bashx/src/types.js +0 -10
  293. package/dist/primitives/bashx/src/types.js.map +0 -1
  294. package/dist/primitives/fsx/core/backend.js +0 -480
  295. package/dist/primitives/fsx/core/backend.js.map +0 -1
  296. package/dist/primitives/fsx/core/constants.js +0 -140
  297. package/dist/primitives/fsx/core/constants.js.map +0 -1
  298. package/dist/primitives/fsx/core/fsx.js +0 -1184
  299. package/dist/primitives/fsx/core/fsx.js.map +0 -1
  300. package/dist/primitives/fsx/core/glob/glob.js +0 -438
  301. package/dist/primitives/fsx/core/glob/glob.js.map +0 -1
  302. package/dist/primitives/fsx/core/glob/index.js +0 -8
  303. package/dist/primitives/fsx/core/glob/index.js.map +0 -1
  304. package/dist/primitives/fsx/core/glob/match.js +0 -392
  305. package/dist/primitives/fsx/core/glob/match.js.map +0 -1
  306. package/dist/primitives/fsx/core/types.js +0 -307
  307. package/dist/primitives/fsx/core/types.js.map +0 -1
  308. package/dist/sdk/capnweb-compat.js +0 -42
  309. package/dist/sdk/capnweb-compat.js.map +0 -1
  310. package/dist/sdk/client.js +0 -20
  311. package/dist/sdk/client.js.map +0 -1
  312. package/dist/sdk/index.js +0 -17
  313. package/dist/sdk/index.js.map +0 -1
@@ -1,794 +0,0 @@
1
- import { OpenAPIHono, createRoute, z } from '@hono/zod-openapi';
2
- /**
3
- * OpenAPI Routes for /api/*
4
- *
5
- * Implements the same functionality as api.ts but with OpenAPI schema generation
6
- * using @hono/zod-openapi.
7
- */
8
- // ============================================================================
9
- // Zod Schemas
10
- // ============================================================================
11
- // Thing schema - represents a resource in the system
12
- export const ThingSchema = z
13
- .object({
14
- id: z.string().uuid().openapi({ description: 'Unique identifier (UUID)' }),
15
- $id: z.string().openapi({ description: 'Qualified identifier (thing:{id})', example: 'thing:123e4567-e89b-12d3-a456-426614174000' }),
16
- $type: z.string().openapi({ description: 'Type URL or "thing"', example: 'thing' }),
17
- name: z.string().min(1).max(10000).openapi({ description: 'Name of the thing', example: 'My Thing' }),
18
- data: z.record(z.string(), z.unknown()).optional().openapi({ description: 'Additional data' }),
19
- createdAt: z.string().datetime().openapi({ description: 'Creation timestamp (ISO 8601)', example: '2024-01-01T00:00:00.000Z' }),
20
- updatedAt: z.string().datetime().openapi({ description: 'Last update timestamp (ISO 8601)', example: '2024-01-01T00:00:00.000Z' }),
21
- })
22
- .openapi('Thing', {});
23
- // Error schema - standard error response
24
- export const ErrorSchema = z
25
- .object({
26
- code: z.string().openapi({ description: 'Error code', example: 'NOT_FOUND' }),
27
- message: z.string().openapi({ description: 'Human-readable error message', example: 'Thing not found' }),
28
- details: z.record(z.string(), z.array(z.string())).optional().openapi({ description: 'Field-specific error details' }),
29
- })
30
- .openapi('Error', {});
31
- // Error response wrapper
32
- export const ErrorResponseSchema = z.object({
33
- error: ErrorSchema,
34
- });
35
- // Create thing request
36
- export const CreateThingRequestSchema = z
37
- .object({
38
- name: z.string().min(1).max(10000).openapi({ description: 'Name of the thing', example: 'My New Thing' }),
39
- $type: z.string().optional().openapi({ description: 'Type URL or "thing"', example: 'thing' }),
40
- data: z.record(z.string(), z.unknown()).optional().openapi({ description: 'Additional data' }),
41
- })
42
- .openapi('CreateThingRequest', {});
43
- // Update thing request
44
- export const UpdateThingRequestSchema = z
45
- .object({
46
- name: z.string().min(1).max(10000).optional().openapi({ description: 'Updated name', example: 'Updated Thing' }),
47
- data: z.record(z.string(), z.unknown()).optional().openapi({ description: 'Updated data' }),
48
- })
49
- .openapi('UpdateThingRequest', {});
50
- // Health response
51
- export const HealthResponseSchema = z
52
- .object({
53
- status: z.literal('ok').openapi({ description: 'Health status', example: 'ok' }),
54
- timestamp: z.string().datetime().openapi({ description: 'Current timestamp (ISO 8601)', example: '2024-01-01T00:00:00.000Z' }),
55
- })
56
- .openapi('HealthResponse', {});
57
- // JSON-RPC schemas for MCP
58
- export const JsonRpcRequestSchema = z
59
- .object({
60
- jsonrpc: z.literal('2.0').openapi({ description: 'JSON-RPC version' }),
61
- id: z.union([z.string(), z.number()]).optional().openapi({ description: 'Request ID' }),
62
- method: z.string().openapi({ description: 'Method name', example: 'initialize' }),
63
- params: z.record(z.string(), z.unknown()).optional().openapi({ description: 'Method parameters' }),
64
- })
65
- .openapi('JsonRpcRequest', {});
66
- export const JsonRpcResponseSchema = z
67
- .object({
68
- jsonrpc: z.literal('2.0').openapi({ description: 'JSON-RPC version' }),
69
- id: z.union([z.string(), z.number(), z.null()]).openapi({ description: 'Request ID' }),
70
- result: z.unknown().optional().openapi({ description: 'Success result' }),
71
- error: z
72
- .object({
73
- code: z.number().openapi({ description: 'Error code' }),
74
- message: z.string().openapi({ description: 'Error message' }),
75
- data: z.unknown().optional().openapi({ description: 'Error data' }),
76
- })
77
- .optional()
78
- .openapi({ description: 'Error object' }),
79
- })
80
- .openapi('JsonRpcResponse', {});
81
- // RPC schemas
82
- export const RpcRequestSchema = z
83
- .object({
84
- id: z.string().openapi({ description: 'Request ID' }),
85
- type: z.enum(['call', 'batch', 'resolve', 'dispose']).openapi({ description: 'Request type' }),
86
- calls: z
87
- .array(z.object({
88
- promiseId: z.string(),
89
- target: z.record(z.string(), z.unknown()),
90
- method: z.string(),
91
- args: z.array(z.record(z.string(), z.unknown())),
92
- }))
93
- .optional(),
94
- })
95
- .openapi('RpcRequest', {});
96
- export const RpcResponseSchema = z
97
- .object({
98
- id: z.string().openapi({ description: 'Request ID' }),
99
- type: z.enum(['result', 'error', 'batch']).openapi({ description: 'Response type' }),
100
- results: z.array(z.record(z.string(), z.unknown())).optional(),
101
- error: z
102
- .object({
103
- code: z.string(),
104
- message: z.string(),
105
- data: z.unknown().optional(),
106
- })
107
- .optional(),
108
- })
109
- .openapi('RpcResponse', {});
110
- const things = new Map();
111
- // ============================================================================
112
- // Route Definitions
113
- // ============================================================================
114
- // Health check route
115
- const healthRoute = createRoute({
116
- method: 'get',
117
- path: '/health',
118
- operationId: 'getHealth',
119
- summary: 'Health check',
120
- description: 'Returns the health status of the API service',
121
- tags: ['Health'],
122
- responses: {
123
- 200: {
124
- description: 'Service is healthy',
125
- content: {
126
- 'application/json': {
127
- schema: HealthResponseSchema,
128
- example: { status: 'ok', timestamp: '2024-01-01T00:00:00.000Z' },
129
- },
130
- },
131
- },
132
- },
133
- });
134
- // List things route
135
- const listThingsRoute = createRoute({
136
- method: 'get',
137
- path: '/things',
138
- operationId: 'getThings',
139
- summary: 'List all things',
140
- description: 'Returns a paginated list of all things. Supports limit and offset query parameters for pagination.',
141
- tags: ['Things'],
142
- request: {
143
- query: z.object({
144
- limit: z.string().optional().openapi({ description: 'Maximum number of items to return (default: 100)', example: '10' }),
145
- offset: z.string().optional().openapi({ description: 'Number of items to skip (default: 0)', example: '0' }),
146
- }),
147
- },
148
- responses: {
149
- 200: {
150
- description: 'List of things',
151
- content: {
152
- 'application/json': {
153
- schema: z.array(ThingSchema),
154
- example: [
155
- {
156
- id: '123e4567-e89b-12d3-a456-426614174000',
157
- $id: 'thing:123e4567-e89b-12d3-a456-426614174000',
158
- $type: 'thing',
159
- name: 'Example Thing',
160
- createdAt: '2024-01-01T00:00:00.000Z',
161
- updatedAt: '2024-01-01T00:00:00.000Z',
162
- },
163
- ],
164
- },
165
- },
166
- },
167
- },
168
- });
169
- // Create thing route
170
- const createThingRoute = createRoute({
171
- method: 'post',
172
- path: '/things',
173
- operationId: 'createThing',
174
- summary: 'Create a new thing',
175
- description: 'Creates a new thing with the provided name and optional data. Returns the created thing with generated ID and timestamps.',
176
- tags: ['Things'],
177
- request: {
178
- body: {
179
- required: true,
180
- content: {
181
- 'application/json': {
182
- schema: CreateThingRequestSchema,
183
- example: { name: 'My New Thing', $type: 'thing', data: { key: 'value' } },
184
- },
185
- },
186
- },
187
- },
188
- responses: {
189
- 201: {
190
- description: 'Thing created successfully',
191
- content: {
192
- 'application/json': {
193
- schema: ThingSchema,
194
- example: {
195
- id: '123e4567-e89b-12d3-a456-426614174000',
196
- $id: 'thing:123e4567-e89b-12d3-a456-426614174000',
197
- $type: 'thing',
198
- name: 'My New Thing',
199
- data: { key: 'value' },
200
- createdAt: '2024-01-01T00:00:00.000Z',
201
- updatedAt: '2024-01-01T00:00:00.000Z',
202
- },
203
- },
204
- },
205
- },
206
- 400: {
207
- description: 'Bad request - invalid JSON or missing Content-Type',
208
- content: {
209
- 'application/json': {
210
- schema: ErrorResponseSchema,
211
- example: { error: { code: 'BAD_REQUEST', message: 'Invalid JSON body' } },
212
- },
213
- },
214
- },
215
- 422: {
216
- description: 'Validation error - invalid field values',
217
- content: {
218
- 'application/json': {
219
- schema: ErrorResponseSchema,
220
- example: { error: { code: 'UNPROCESSABLE_ENTITY', message: 'Validation failed: name is required', details: { name: ['Name is required'] } } },
221
- },
222
- },
223
- },
224
- },
225
- });
226
- // Get thing by ID route
227
- const getThingRoute = createRoute({
228
- method: 'get',
229
- path: '/things/{id}',
230
- operationId: 'getThing',
231
- summary: 'Get a thing by ID',
232
- description: 'Returns a single thing by its unique identifier',
233
- tags: ['Things'],
234
- request: {
235
- params: z.object({
236
- id: z.string().uuid().openapi({ description: 'Thing ID (UUID)', example: '123e4567-e89b-12d3-a456-426614174000' }),
237
- }),
238
- },
239
- responses: {
240
- 200: {
241
- description: 'Thing found',
242
- content: {
243
- 'application/json': {
244
- schema: ThingSchema,
245
- example: {
246
- id: '123e4567-e89b-12d3-a456-426614174000',
247
- $id: 'thing:123e4567-e89b-12d3-a456-426614174000',
248
- $type: 'thing',
249
- name: 'Example Thing',
250
- createdAt: '2024-01-01T00:00:00.000Z',
251
- updatedAt: '2024-01-01T00:00:00.000Z',
252
- },
253
- },
254
- },
255
- },
256
- 404: {
257
- description: 'Thing not found',
258
- content: {
259
- 'application/json': {
260
- schema: ErrorResponseSchema,
261
- example: { error: { code: 'NOT_FOUND', message: 'Thing not found' } },
262
- },
263
- },
264
- },
265
- },
266
- });
267
- // Update thing route
268
- const updateThingRoute = createRoute({
269
- method: 'put',
270
- path: '/things/{id}',
271
- operationId: 'updateThing',
272
- summary: 'Update a thing',
273
- description: 'Updates an existing thing with the provided fields',
274
- tags: ['Things'],
275
- request: {
276
- params: z.object({
277
- id: z.string().uuid().openapi({ description: 'Thing ID (UUID)', example: '123e4567-e89b-12d3-a456-426614174000' }),
278
- }),
279
- body: {
280
- required: true,
281
- content: {
282
- 'application/json': {
283
- schema: UpdateThingRequestSchema,
284
- example: { name: 'Updated Thing Name' },
285
- },
286
- },
287
- },
288
- },
289
- responses: {
290
- 200: {
291
- description: 'Thing updated successfully',
292
- content: {
293
- 'application/json': {
294
- schema: ThingSchema,
295
- example: {
296
- id: '123e4567-e89b-12d3-a456-426614174000',
297
- $id: 'thing:123e4567-e89b-12d3-a456-426614174000',
298
- $type: 'thing',
299
- name: 'Updated Thing Name',
300
- createdAt: '2024-01-01T00:00:00.000Z',
301
- updatedAt: '2024-01-02T00:00:00.000Z',
302
- },
303
- },
304
- },
305
- },
306
- 400: {
307
- description: 'Bad request - invalid JSON',
308
- content: {
309
- 'application/json': {
310
- schema: ErrorResponseSchema,
311
- example: { error: { code: 'BAD_REQUEST', message: 'Invalid JSON body' } },
312
- },
313
- },
314
- },
315
- 404: {
316
- description: 'Thing not found',
317
- content: {
318
- 'application/json': {
319
- schema: ErrorResponseSchema,
320
- example: { error: { code: 'NOT_FOUND', message: 'Thing not found' } },
321
- },
322
- },
323
- },
324
- },
325
- });
326
- // Delete thing route
327
- const deleteThingRoute = createRoute({
328
- method: 'delete',
329
- path: '/things/{id}',
330
- operationId: 'deleteThing',
331
- summary: 'Delete a thing',
332
- description: 'Deletes a thing by its unique identifier. Returns 204 on success.',
333
- tags: ['Things'],
334
- request: {
335
- params: z.object({
336
- id: z.string().uuid().openapi({ description: 'Thing ID (UUID)', example: '123e4567-e89b-12d3-a456-426614174000' }),
337
- }),
338
- },
339
- responses: {
340
- 204: {
341
- description: 'Thing deleted successfully (no content)',
342
- },
343
- 404: {
344
- description: 'Thing not found',
345
- content: {
346
- 'application/json': {
347
- schema: ErrorResponseSchema,
348
- example: { error: { code: 'NOT_FOUND', message: 'Thing not found' } },
349
- },
350
- },
351
- },
352
- },
353
- });
354
- // Protected route
355
- const protectedRoute = createRoute({
356
- method: 'get',
357
- path: '/protected',
358
- operationId: 'getProtected',
359
- summary: 'Protected endpoint',
360
- description: 'A protected endpoint that requires authentication. Returns 401 if not authenticated.',
361
- tags: ['Auth'],
362
- security: [{ bearerAuth: [] }, { apiKey: [] }],
363
- responses: {
364
- 200: {
365
- description: 'Access granted',
366
- content: {
367
- 'application/json': {
368
- schema: z.object({ message: z.string() }),
369
- example: { message: 'Access granted' },
370
- },
371
- },
372
- },
373
- 401: {
374
- description: 'Unauthorized - authentication required',
375
- content: {
376
- 'application/json': {
377
- schema: ErrorResponseSchema,
378
- example: { error: { code: 'UNAUTHORIZED', message: 'Authentication required' } },
379
- },
380
- },
381
- },
382
- },
383
- });
384
- // Admin settings route
385
- const adminSettingsRoute = createRoute({
386
- method: 'get',
387
- path: '/admin/settings',
388
- operationId: 'getAdminSettings',
389
- summary: 'Get admin settings',
390
- description: 'Retrieves admin settings. Requires admin role.',
391
- tags: ['Admin'],
392
- security: [{ bearerAuth: [] }],
393
- responses: {
394
- 200: {
395
- description: 'Admin settings',
396
- content: {
397
- 'application/json': {
398
- schema: z.object({ settings: z.record(z.string(), z.unknown()) }),
399
- },
400
- },
401
- },
402
- 401: {
403
- description: 'Unauthorized',
404
- content: {
405
- 'application/json': {
406
- schema: ErrorResponseSchema,
407
- },
408
- },
409
- },
410
- 403: {
411
- description: 'Forbidden - admin permission required',
412
- content: {
413
- 'application/json': {
414
- schema: ErrorResponseSchema,
415
- example: { error: { code: 'FORBIDDEN', message: 'Access denied - admin permission required' } },
416
- },
417
- },
418
- },
419
- },
420
- });
421
- // ============================================================================
422
- // MCP Routes
423
- // ============================================================================
424
- const mcpPostRoute = createRoute({
425
- method: 'post',
426
- path: '',
427
- operationId: 'mcpPost',
428
- summary: 'MCP JSON-RPC endpoint',
429
- description: 'Handle JSON-RPC 2.0 requests for the Model Context Protocol (MCP). Supports batch requests.',
430
- tags: ['MCP'],
431
- request: {
432
- headers: z.object({
433
- 'Mcp-Session-Id': z.string().optional().openapi({ description: 'Session identifier for stateful operations' }),
434
- }),
435
- body: {
436
- required: true,
437
- content: {
438
- 'application/json': {
439
- schema: z.union([JsonRpcRequestSchema, z.array(JsonRpcRequestSchema)]),
440
- example: { jsonrpc: '2.0', id: 1, method: 'initialize', params: {} },
441
- },
442
- },
443
- },
444
- },
445
- responses: {
446
- 200: {
447
- description: 'JSON-RPC response',
448
- content: {
449
- 'application/json': {
450
- schema: z.union([JsonRpcResponseSchema, z.array(JsonRpcResponseSchema)]),
451
- example: { jsonrpc: '2.0', id: 1, result: { protocolVersion: '2024-11-05' } },
452
- },
453
- },
454
- },
455
- },
456
- });
457
- const mcpGetRoute = createRoute({
458
- method: 'get',
459
- path: '',
460
- operationId: 'mcpGet',
461
- summary: 'MCP SSE stream',
462
- description: 'Server-Sent Events (SSE) stream for receiving MCP server-initiated notifications. Requires an established session.',
463
- tags: ['MCP'],
464
- request: {
465
- headers: z.object({
466
- 'Mcp-Session-Id': z.string().openapi({ description: 'Session identifier' }),
467
- }),
468
- },
469
- responses: {
470
- 200: {
471
- description: 'SSE event stream',
472
- content: {
473
- 'text/event-stream': {
474
- schema: z.string().openapi({ description: 'Server-Sent Events stream' }),
475
- },
476
- },
477
- },
478
- 400: {
479
- description: 'Bad request - missing session ID',
480
- content: {
481
- 'application/json': {
482
- schema: ErrorResponseSchema,
483
- },
484
- },
485
- },
486
- 404: {
487
- description: 'Session not found',
488
- content: {
489
- 'application/json': {
490
- schema: ErrorResponseSchema,
491
- },
492
- },
493
- },
494
- },
495
- });
496
- const mcpDeleteRoute = createRoute({
497
- method: 'delete',
498
- path: '',
499
- operationId: 'mcpDelete',
500
- summary: 'Terminate MCP session',
501
- description: 'Terminates an MCP session and cleans up associated resources.',
502
- tags: ['MCP'],
503
- request: {
504
- headers: z.object({
505
- 'Mcp-Session-Id': z.string().openapi({ description: 'Session identifier to terminate' }),
506
- }),
507
- },
508
- responses: {
509
- 204: {
510
- description: 'Session terminated successfully',
511
- },
512
- 400: {
513
- description: 'Bad request - missing session ID',
514
- content: {
515
- 'application/json': {
516
- schema: ErrorResponseSchema,
517
- },
518
- },
519
- },
520
- 404: {
521
- description: 'Session not found',
522
- content: {
523
- 'application/json': {
524
- schema: ErrorResponseSchema,
525
- },
526
- },
527
- },
528
- },
529
- });
530
- // ============================================================================
531
- // RPC Routes
532
- // ============================================================================
533
- const rpcPostRoute = createRoute({
534
- method: 'post',
535
- path: '',
536
- operationId: 'rpcPost',
537
- summary: 'RPC batch endpoint',
538
- description: 'HTTP POST endpoint for batch RPC calls. Supports Capnweb-style promise pipelining and pass-by-reference.',
539
- tags: ['RPC'],
540
- request: {
541
- body: {
542
- required: true,
543
- content: {
544
- 'application/json': {
545
- schema: RpcRequestSchema,
546
- example: {
547
- id: 'req-1',
548
- type: 'call',
549
- calls: [{ promiseId: 'p1', target: { type: 'root' }, method: 'echo', args: [{ type: 'value', value: 'hello' }] }],
550
- },
551
- },
552
- },
553
- },
554
- },
555
- responses: {
556
- 200: {
557
- description: 'RPC response',
558
- content: {
559
- 'application/json': {
560
- schema: RpcResponseSchema,
561
- example: { id: 'req-1', type: 'batch', results: [{ promiseId: 'p1', type: 'value', value: 'hello' }] },
562
- },
563
- },
564
- },
565
- },
566
- });
567
- const rpcGetRoute = createRoute({
568
- method: 'get',
569
- path: '',
570
- operationId: 'rpcGet',
571
- summary: 'RPC WebSocket endpoint',
572
- description: 'WebSocket endpoint for streaming RPC. Supports JSON-RPC 2.0 protocol over WebSocket for real-time bidirectional communication.',
573
- tags: ['RPC'],
574
- responses: {
575
- 101: {
576
- description: 'WebSocket upgrade successful',
577
- },
578
- 200: {
579
- description: 'RPC endpoint info (when accessed without WebSocket upgrade)',
580
- content: {
581
- 'application/json': {
582
- schema: z.object({
583
- message: z.string(),
584
- methods: z.array(z.string()),
585
- hint: z.string(),
586
- }),
587
- example: {
588
- message: 'RPC endpoint - use POST for HTTP batch mode or WebSocket for streaming',
589
- methods: ['echo', 'add', 'multiply', 'getUser'],
590
- hint: 'Connect with WebSocket protocol for streaming RPC',
591
- },
592
- },
593
- },
594
- },
595
- },
596
- });
597
- // ============================================================================
598
- // Create OpenAPI Hono App
599
- // ============================================================================
600
- export const openapiRoutes = new OpenAPIHono();
601
- // Register API routes with handlers
602
- openapiRoutes.openapi(healthRoute, (c) => {
603
- return c.json({ status: 'ok', timestamp: new Date().toISOString() });
604
- });
605
- openapiRoutes.openapi(listThingsRoute, (c) => {
606
- const limitParam = c.req.query('limit');
607
- const offsetParam = c.req.query('offset');
608
- const limit = limitParam ? parseInt(limitParam, 10) : 100;
609
- const offset = offsetParam ? parseInt(offsetParam, 10) : 0;
610
- const allThings = Array.from(things.values());
611
- const paginated = allThings.slice(offset, offset + limit);
612
- return c.json(paginated);
613
- });
614
- openapiRoutes.openapi(createThingRoute, async (c) => {
615
- const body = c.req.valid('json');
616
- const id = crypto.randomUUID();
617
- const now = new Date().toISOString();
618
- const thing = {
619
- id,
620
- $id: `thing:${id}`,
621
- $type: body.$type || 'thing',
622
- name: body.name,
623
- data: body.data,
624
- createdAt: now,
625
- updatedAt: now,
626
- };
627
- things.set(id, thing);
628
- return c.json(thing, 201);
629
- });
630
- openapiRoutes.openapi(getThingRoute, (c) => {
631
- const { id } = c.req.valid('param');
632
- const thing = things.get(id);
633
- if (!thing) {
634
- return c.json({ error: { code: 'NOT_FOUND', message: 'Thing not found' } }, 404);
635
- }
636
- return c.json(thing, 200);
637
- });
638
- openapiRoutes.openapi(updateThingRoute, async (c) => {
639
- const { id } = c.req.valid('param');
640
- const body = c.req.valid('json');
641
- const existing = things.get(id);
642
- if (!existing) {
643
- return c.json({ error: { code: 'NOT_FOUND', message: 'Thing not found' } }, 404);
644
- }
645
- const updated = {
646
- ...existing,
647
- name: body.name ?? existing.name,
648
- data: body.data ?? existing.data,
649
- updatedAt: new Date().toISOString(),
650
- };
651
- things.set(id, updated);
652
- return c.json(updated, 200);
653
- });
654
- openapiRoutes.openapi(deleteThingRoute, (c) => {
655
- const { id } = c.req.valid('param');
656
- const existed = things.delete(id);
657
- if (!existed) {
658
- return c.json({ error: { code: 'NOT_FOUND', message: 'Thing not found' } }, 404);
659
- }
660
- return new Response(null, { status: 204 });
661
- });
662
- openapiRoutes.openapi(protectedRoute, (c) => {
663
- return c.json({ error: { code: 'UNAUTHORIZED', message: 'Authentication required' } }, 401);
664
- });
665
- openapiRoutes.openapi(adminSettingsRoute, (c) => {
666
- return c.json({ error: { code: 'FORBIDDEN', message: 'Access denied - admin permission required' } }, 403);
667
- });
668
- // ============================================================================
669
- // MCP Routes App
670
- // ============================================================================
671
- export const mcpOpenapiRoutes = new OpenAPIHono();
672
- // Register MCP routes (handlers will forward to actual MCP implementation)
673
- mcpOpenapiRoutes.openapi(mcpPostRoute, async (c) => {
674
- // Forward to actual MCP handler
675
- const { handleMcpRequest } = await import('./mcp');
676
- const response = await handleMcpRequest(c.req.raw);
677
- return response;
678
- });
679
- mcpOpenapiRoutes.openapi(mcpGetRoute, async (c) => {
680
- const { handleMcpRequest } = await import('./mcp');
681
- const response = await handleMcpRequest(c.req.raw);
682
- return response;
683
- });
684
- mcpOpenapiRoutes.openapi(mcpDeleteRoute, async (c) => {
685
- const { handleMcpRequest } = await import('./mcp');
686
- const response = await handleMcpRequest(c.req.raw);
687
- return response;
688
- });
689
- // ============================================================================
690
- // RPC Routes App
691
- // ============================================================================
692
- export const rpcOpenapiRoutes = new OpenAPIHono();
693
- // RPC routes just document the endpoints
694
- rpcOpenapiRoutes.openapi(rpcPostRoute, async (c) => {
695
- const { rpcRoutes } = await import('./rpc');
696
- // Create a new request for the /rpc POST handler
697
- const req = new Request(c.req.url, {
698
- method: 'POST',
699
- headers: c.req.raw.headers,
700
- body: c.req.raw.body,
701
- });
702
- const app = new OpenAPIHono();
703
- app.route('/', rpcRoutes);
704
- return app.fetch(req, c.env);
705
- });
706
- rpcOpenapiRoutes.openapi(rpcGetRoute, (c) => {
707
- return c.json({
708
- message: 'RPC endpoint - use POST for HTTP batch mode or WebSocket for streaming',
709
- methods: ['echo', 'add', 'multiply', 'ping', 'getUser', 'getData', 'getPosts'],
710
- hint: 'Connect with WebSocket protocol for streaming RPC',
711
- });
712
- });
713
- // ============================================================================
714
- // OpenAPI Document Configuration
715
- // ============================================================================
716
- export function getOpenAPIDocument() {
717
- // Create a combined app with all routes for doc generation
718
- const docApp = new OpenAPIHono();
719
- // Register security schemes using the registry
720
- docApp.openAPIRegistry.registerComponent('securitySchemes', 'bearerAuth', {
721
- type: 'http',
722
- scheme: 'bearer',
723
- bearerFormat: 'JWT',
724
- description: 'JWT Bearer token authentication. Obtain a token via the auth flow and include it in the Authorization header.',
725
- });
726
- docApp.openAPIRegistry.registerComponent('securitySchemes', 'apiKey', {
727
- type: 'apiKey',
728
- in: 'header',
729
- name: 'X-API-Key',
730
- description: 'API key authentication. Include your API key in the X-API-Key header.',
731
- });
732
- // Mount API routes at /api
733
- docApp.route('/api', openapiRoutes);
734
- // Mount MCP routes at /mcp
735
- docApp.route('/mcp', mcpOpenapiRoutes);
736
- // Mount RPC routes at /rpc
737
- docApp.route('/rpc', rpcOpenapiRoutes);
738
- return docApp.getOpenAPI31Document({
739
- openapi: '3.1.0',
740
- info: {
741
- title: 'dotdo API',
742
- version: '0.0.1',
743
- description: 'The dotdo platform API provides REST endpoints for managing things, MCP protocol support for AI tools, and RPC endpoints for real-time communication.',
744
- contact: {
745
- name: 'dotdo Team',
746
- url: 'https://github.com/dotdo',
747
- email: 'support@dotdo.dev',
748
- },
749
- license: {
750
- name: 'MIT',
751
- url: 'https://opensource.org/licenses/MIT',
752
- },
753
- },
754
- servers: [
755
- {
756
- url: 'https://api.dotdo.dev',
757
- description: 'Production server',
758
- },
759
- {
760
- url: 'http://localhost:8787',
761
- description: 'Local development server',
762
- },
763
- ],
764
- tags: [
765
- {
766
- name: 'Things',
767
- description: 'CRUD operations for things - the core resource type',
768
- },
769
- {
770
- name: 'Health',
771
- description: 'Health check and status endpoints',
772
- },
773
- {
774
- name: 'Auth',
775
- description: 'Authentication and authorization endpoints',
776
- },
777
- {
778
- name: 'Admin',
779
- description: 'Administrative endpoints requiring elevated permissions',
780
- },
781
- {
782
- name: 'MCP',
783
- description: 'Model Context Protocol (MCP) endpoints for AI tool integration',
784
- },
785
- {
786
- name: 'RPC',
787
- description: 'Remote Procedure Call endpoints with WebSocket support',
788
- },
789
- ],
790
- security: [],
791
- });
792
- }
793
- export default openapiRoutes;
794
- //# sourceMappingURL=openapi.js.map