apps 0.0.1-beta.0 → 0.0.1-beta.10

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 (141) hide show
  1. package/README.md +145 -30
  2. package/framework-reference.json +1 -1
  3. package/js/browser-XIPJGLH2.js +65 -0
  4. package/js/{chunk-36DNRFZQ.js → chunk-27F7W2LG.js} +1 -1
  5. package/js/{chunk-VFUZI3NY.js → chunk-57RKNWL2.js} +4 -4
  6. package/js/{chunk-BPEFS4YF.js → chunk-5T57N25Q.js} +122 -18
  7. package/js/chunk-72JNVHPK.js +41 -0
  8. package/js/{chunk-2OTCEKL2.js → chunk-CDL5PM2Q.js} +2643 -1646
  9. package/js/{chunk-KWTCHVLT.js → chunk-CRDWFA74.js} +69 -54
  10. package/js/chunk-CZ7CSFO4.js +39 -0
  11. package/js/{chunk-WIDTG42X.js → chunk-EPT3ZP52.js} +79 -26
  12. package/js/chunk-FL2QR3XW.js +507 -0
  13. package/js/{chunk-3ANFZFCV.js → chunk-IJX4CYZO.js} +15 -18
  14. package/js/chunk-IPI4MFSN.js +78 -0
  15. package/js/chunk-JU7VHODU.js +104 -0
  16. package/js/chunk-KUMBKVJD.js +39 -0
  17. package/js/{chunk-YDR4CPJA.js → chunk-M3B3DE4K.js} +8 -8
  18. package/js/chunk-MKWZPDR6.js +63 -0
  19. package/js/{chunk-7JXHF5IF.js → chunk-N7YDVXYJ.js} +49 -1
  20. package/js/chunk-NKLWZJLE.js +172 -0
  21. package/js/{chunk-OWD2YICM.js → chunk-ODEIDRGW.js} +116 -88
  22. package/js/{chunk-D6BKYP2L.js → chunk-PJJ24GU7.js} +4 -4
  23. package/js/{chunk-EP6AEUZO.js → chunk-PZB6T6KU.js} +1 -1
  24. package/js/chunk-R3EV5FTO.js +97 -0
  25. package/js/chunk-RFVIONFX.js +189 -0
  26. package/js/{chunk-W7Q5EOTS.js → chunk-UK573G7W.js} +32 -32
  27. package/js/chunk-UVL56Z6E.js +6641 -0
  28. package/js/{chunk-Q2FD5IBM.js → chunk-V5KNQVCT.js} +505 -124
  29. package/js/{chunk-SBKHUC5L.js → chunk-VFZKSM3T.js} +5 -25
  30. package/js/{chunk-HP7E42X6.js → chunk-WLE7WX2U.js} +1158 -232
  31. package/js/{chunk-X3YBZCJW.js → chunk-YXQHV65J.js} +58 -62
  32. package/js/chunk-Z5M2LQOZ.js +209 -0
  33. package/js/{chunk-R6JMJSVT.js → chunk-ZQINWV4W.js} +60 -20
  34. package/js/client.js +11 -27
  35. package/js/contracts.js +138 -27
  36. package/js/effect.js +20 -15
  37. package/js/es-APDZKREY.js +40968 -0
  38. package/js/graphql.js +220 -123
  39. package/js/host.js +75 -19
  40. package/js/index.js +261 -117
  41. package/js/mcp/effect.js +24 -17
  42. package/js/mcp/stdio.js +26 -21
  43. package/js/mcp.js +127 -26
  44. package/js/openapi.js +3048 -150
  45. package/js/operations/approval.js +1 -1
  46. package/js/react.js +4 -4
  47. package/js/skills/effect.js +11 -0
  48. package/js/skills.js +893 -0
  49. package/js/storage/facet.js +7 -7
  50. package/js/ui/auth/contracts.js +9 -10
  51. package/js/ui/auth.js +17 -15
  52. package/js/ui/contracts.js +5 -5
  53. package/js/ui/serving.js +14 -13
  54. package/package.json +9 -1
  55. package/runtime.json +1 -1
  56. package/types/app-cache/src/contracts/cache.d.ts +119 -0
  57. package/types/app-cache/src/index.d.ts +93 -0
  58. package/types/app-data/src/contracts/database.d.ts +33 -6
  59. package/types/app-data/src/implementation/schema.d.ts +2 -17
  60. package/types/apps/src/contracts/api-response-error.d.ts +43 -0
  61. package/types/apps/src/contracts/app.d.ts +16 -4
  62. package/types/apps/src/contracts/cache.d.ts +44 -0
  63. package/types/apps/src/contracts/dynamic-skills.d.ts +10 -0
  64. package/types/apps/src/contracts/failure.d.ts +25 -0
  65. package/types/apps/src/contracts/graphql.d.ts +18 -1
  66. package/types/apps/src/contracts/host.d.ts +76 -528
  67. package/types/apps/src/contracts/mcp.d.ts +19 -1
  68. package/types/apps/src/contracts/openapi-compile.d.ts +11 -0
  69. package/types/apps/src/contracts/openapi-document.d.ts +53 -0
  70. package/types/apps/src/contracts/openapi.d.ts +160 -30
  71. package/types/apps/src/contracts/operations.d.ts +0 -5
  72. package/types/apps/src/contracts/protocol-version.d.ts +6 -0
  73. package/types/apps/src/contracts/protocols/1.d.ts +1589 -0
  74. package/types/apps/src/contracts/protocols/2.d.ts +668 -0
  75. package/types/apps/src/contracts/protocols/3.d.ts +676 -0
  76. package/types/apps/src/contracts/protocols/4.d.ts +1229 -0
  77. package/types/apps/src/contracts/protocols/5.d.ts +1090 -0
  78. package/types/apps/src/contracts/provider-error.d.ts +15 -0
  79. package/types/apps/src/contracts/provider.d.ts +69 -6
  80. package/types/apps/src/contracts/router.d.ts +59 -0
  81. package/types/apps/src/contracts/skills.d.ts +122 -0
  82. package/types/apps/src/contracts/storage.d.ts +3 -3
  83. package/types/apps/src/contracts/swagger-client.d.ts +29 -0
  84. package/types/apps/src/contracts/ui-auth.d.ts +6 -14
  85. package/types/apps/src/contracts/workflows.d.ts +34 -3
  86. package/types/apps/src/graphql.d.ts +5 -7
  87. package/types/apps/src/host.d.ts +1 -0
  88. package/types/apps/src/implementation/account-router.d.ts +12 -0
  89. package/types/apps/src/implementation/app.d.ts +5 -4
  90. package/types/apps/src/implementation/cache-session.d.ts +7 -0
  91. package/types/apps/src/implementation/cache.d.ts +8 -0
  92. package/types/apps/src/implementation/catalog-cache.d.ts +36 -0
  93. package/types/apps/src/implementation/dynamic-skills.d.ts +7 -0
  94. package/types/apps/src/implementation/elicitation.d.ts +13 -13
  95. package/types/apps/src/implementation/failure-detail.d.ts +25 -0
  96. package/types/apps/src/implementation/git.d.ts +25 -0
  97. package/types/apps/src/implementation/graphql-catalog.d.ts +7 -0
  98. package/types/apps/src/implementation/graphql.d.ts +81 -3
  99. package/types/apps/src/implementation/inflate.d.ts +16 -0
  100. package/types/apps/src/implementation/input-problems.d.ts +3 -0
  101. package/types/apps/src/implementation/mcp-call.d.ts +3 -2
  102. package/types/apps/src/implementation/mcp-catalog.d.ts +9 -0
  103. package/types/apps/src/implementation/mcp-client.d.ts +39 -22
  104. package/types/apps/src/implementation/mcp-stdio.d.ts +1 -1
  105. package/types/apps/src/implementation/mcp-tools.d.ts +6 -3
  106. package/types/apps/src/implementation/mcp.d.ts +55 -2
  107. package/types/apps/src/implementation/openapi-compile.d.ts +120 -0
  108. package/types/apps/src/implementation/openapi-document.d.ts +51 -0
  109. package/types/apps/src/implementation/openapi-names.d.ts +18 -0
  110. package/types/apps/src/implementation/openapi-request.d.ts +10 -4
  111. package/types/apps/src/implementation/openapi-source.d.ts +36 -0
  112. package/types/apps/src/implementation/openapi.d.ts +39 -3
  113. package/types/apps/src/implementation/operations.d.ts +26 -3
  114. package/types/apps/src/implementation/protocol-operations.d.ts +3 -4
  115. package/types/apps/src/implementation/provider-error.d.ts +10 -0
  116. package/types/apps/src/implementation/provider.d.ts +9 -4
  117. package/types/apps/src/implementation/router-catalog.d.ts +225 -0
  118. package/types/apps/src/implementation/router.d.ts +59 -0
  119. package/types/apps/src/implementation/schema.d.ts +11 -6
  120. package/types/apps/src/implementation/skill-files.d.ts +10 -0
  121. package/types/apps/src/implementation/skills.d.ts +43 -0
  122. package/types/apps/src/implementation/storage.d.ts +5 -3
  123. package/types/apps/src/implementation/swagger-client.d.ts +28 -0
  124. package/types/apps/src/implementation/ui-auth.d.ts +11 -5
  125. package/types/apps/src/implementation/ui-serving.d.ts +4 -2
  126. package/types/apps/src/implementation/webhooks.d.ts +1 -1
  127. package/types/apps/src/implementation/workflow-context.d.ts +11 -3
  128. package/types/apps/src/index.d.ts +11 -3
  129. package/types/apps/src/mcp-stdio.d.ts +2 -5
  130. package/types/apps/src/mcp.d.ts +8 -7
  131. package/types/apps/src/openapi.d.ts +8 -6
  132. package/types/apps/src/skills.d.ts +75 -0
  133. package/types/apps/src/ui-auth.d.ts +2 -2
  134. package/types/telemetry/src/browser-operations.d.ts +5 -2
  135. package/types/telemetry/src/config.d.ts +2 -0
  136. package/js/chunk-22WRQZT7.js +0 -389
  137. package/js/chunk-BKVL7XAJ.js +0 -47
  138. package/js/chunk-C24KEZXR.js +0 -59
  139. package/js/chunk-LOKGDT6B.js +0 -28
  140. package/js/chunk-MLKGABMK.js +0 -9
  141. package/types/apps/src/implementation/account-operations.d.ts +0 -32
package/README.md CHANGED
@@ -11,22 +11,22 @@ For local testing, install the tarball made by `bun run pack` in this directory.
11
11
 
12
12
  ```ts
13
13
  import { defineApp } from "apps";
14
- import { mcpOperations } from "apps/mcp";
14
+ import { mcpRouter } from "apps/mcp";
15
15
 
16
16
  export default defineApp({ accounts: {} }, async ({ signal }) => ({
17
- ...(await mcpOperations({
17
+ tools: await mcpRouter({
18
18
  url: "https://mcp.deepwiki.com/mcp",
19
19
  ...(signal === undefined ? {} : { signal }),
20
- })),
20
+ }),
21
21
  }));
22
22
  ```
23
23
 
24
- | Import | Helper | App dependency |
25
- | ---------------- | ------------------- | --------------------------- |
26
- | `apps/mcp` | `mcpOperations` | `@modelcontextprotocol/sdk` |
27
- | `apps/mcp/stdio` | `stdioOperations` | `@modelcontextprotocol/sdk` |
28
- | `apps/graphql` | `graphqlOperations` | `graphql` |
29
- | `apps/openapi` | `openapiOperations` | None |
24
+ | Import | Helper | App dependency |
25
+ | ---------------- | --------------- | --------------------------- |
26
+ | `apps/mcp` | `mcpRouter` | `@modelcontextprotocol/sdk` |
27
+ | `apps/mcp/stdio` | `stdioRouter` | `@modelcontextprotocol/sdk` |
28
+ | `apps/graphql` | `graphqlRouter` | `graphql` |
29
+ | `apps/openapi` | `openapiRouter` | None |
30
30
 
31
31
  MCP and GraphQL are optional peers. Subpath imports isolate their module graphs;
32
32
  optional peers keep unused libraries out of the dependency installation. The
@@ -43,34 +43,58 @@ Declare the needed peer in the deployed app's `package.json`, for example:
43
43
  ```
44
44
 
45
45
  Product runtimes compile authored source and declared dependencies inside workerd,
46
- then retain the executable Worker modules. Declare `apps` in `package.json` to
47
- select its npm version for both server and browser code. Use an exact version to
48
- keep rebuilds repeatable. Apps with no `apps` dependency use the host's framework.
46
+ then retain the executable Worker modules. Every app declares the exact `apps`
47
+ version in `package.json`; it selects the framework for both server and browser
48
+ code and keeps rebuilds repeatable. A build without it fails and names the
49
+ version the host ships.
49
50
  In this repository, playground workspaces use `"apps": "workspace:*"` for development;
50
51
  replace that workspace reference with a released version before deployment.
51
52
 
52
- `openapiOperations` accepts normalized operations from the template generator,
53
- credential placement metadata, and an optional selected account. It does not
54
- parse a raw OpenAPI specification. `packages/app-templates` owns that compiler.
55
- No extra OpenAPI parser is installed in the app.
56
-
57
- Authenticated templates use `provider.many()` and `accountOperations` from `apps`:
53
+ `liveOpenapiRouter` reads an OpenAPI document through `ctx.cache`. Generated
54
+ imports retain a source URL, allowed origin, and static credential bindings in
55
+ `openapi.json`. The framework compiles a revision on a cache miss. It writes each
56
+ operation and shared schema before publishing the current revision. A warm call
57
+ reads that revision and the requested operation's schema dependencies. It does
58
+ not download, parse, or read the full catalog. `openapiRouter` remains the
59
+ lower-level helper for already normalized metadata.
60
+ `parameterDefaults` binds path, query or header values to the selected account.
61
+ Those parameters become optional and publish their value as the schema `default`;
62
+ an explicit value still wins.
63
+
64
+ The default refresh window is five minutes fresh plus five minutes stale.
65
+ `freshFor` and `staleFor` can change it. A stale read schedules a bounded refresh;
66
+ a failed refresh keeps the last successful revision until its stale window ends.
67
+ The source URL and static compilation configuration identify a shared source.
68
+ Accounts bind at execution time. Live documents cannot change credential
69
+ placement or send credentials to another origin. Editing generated source and
70
+ redeploying is required to change those static choices.
71
+
72
+ Authenticated templates use `provider.many()` and `accountRouter` from `apps`:
58
73
 
59
74
  ```ts
60
- export default defineApp({ accounts: { service: provider.many() } }, async ({ accounts, signal }) =>
61
- accountOperations(
62
- accounts.service,
63
- (account) =>
64
- mcpOperations({
65
- url: "https://example.com/mcp",
66
- headers: { Authorization: "Bearer " + account.fields.token },
67
- signal,
68
- }),
69
- { signal },
70
- ),
75
+ export default defineApp(
76
+ { accounts: { service: provider.many() } },
77
+ async ({ accounts, signal }) => ({
78
+ tools: await accountRouter(
79
+ accounts.service,
80
+ (account) =>
81
+ mcpRouter({
82
+ url: "https://example.com/mcp",
83
+ headers: { Authorization: "Bearer " + account.fields.token },
84
+ signal,
85
+ }),
86
+ { signal },
87
+ ),
88
+ }),
71
89
  );
72
90
  ```
73
91
 
92
+ MCP and GraphQL helpers accept `cache: ctx.cache.forAccount(account)` (or
93
+ `ctx.cache` for a public source). They return a dynamic router, cache remote
94
+ metadata, and compile only the selected tool. The defaults are five minutes fresh
95
+ plus five minutes stale. Use `freshFor` / `staleFor` to change the windows, or
96
+ `revalidate: true` to await a refresh. Tool results are never cached.
97
+
74
98
  Each combined tool takes `{ accountId, input }`. `input` keeps the upstream shape;
75
99
  `accountId` must identify a selected account that exposes that tool. Discovery
76
100
  and validation remain specific to each account. An empty selection returns no
@@ -151,7 +175,7 @@ and [hosting notes](../../notes/app-ui.md).
151
175
 
152
176
  ## Webhooks
153
177
 
154
- Expose `webhooks: { issueOpened }` beside queries and mutations. Each definition
178
+ Expose `webhooks: { issueOpened }` beside `tools`. Each definition
155
179
  has an `account` requirement, `config` and `state` schemas, and async `register`,
156
180
  `handle`, and `unregister` callbacks. Register and unregister must be idempotent;
157
181
  handle must verify the provider signature before acting.
@@ -189,3 +213,94 @@ Local and self-host products run authored apps in Alchemy/workerd, using the
189
213
  same Worker build format and app-data facets as Cloud. Host filesystem and
190
214
  subprocess access are unavailable to app code. Agent `execute(code)` continues
191
215
  to use OpenCode CodeMode.
216
+
217
+ ## App cache and lazy sources
218
+
219
+ Every app context has `cache`. Keys must contain every input that changes the
220
+ result. The host adds app and build isolation. Use `forAccount(account)` for
221
+ private data; it also includes the current credential fingerprint. Use the
222
+ shared cache for public metadata that is identical across accounts.
223
+
224
+ ```ts
225
+ const projects = await ctx.cache.forAccount(ctx.accounts.service).get({
226
+ key: ["projects", region],
227
+ schema: array(object({ id: string(), name: string() })),
228
+ freshFor: "1 minute",
229
+ staleFor: "2 minutes",
230
+ load: async ({ fetch, signal }) => {
231
+ const response = await fetch(urlFor(region), { signal });
232
+ if (!response.ok) throw new Error("Project lookup failed");
233
+ return response.json();
234
+ },
235
+ });
236
+ ```
237
+
238
+ Use the loader's `fetch`, `signal`, and `cache` for background work. Their
239
+ lifetime can outlast the original request. Only successful, schema-valid JSON
240
+ is stored. Concurrent misses share a fenced lease. `invalidate(key)` revokes
241
+ both a cached value and an in-flight loader's right to publish it. Cache storage
242
+ is disposable and bounded: 2 MB per entry, 8 MB per write batch, 128 entries per
243
+ batch, 128 MB and 100,000 entries per app, and seven days of retention. Capacity
244
+ errors are explicit. Background refreshes have a 30-second deadline.
245
+
246
+ `read` and `readMany` read retained data without loading it. `write` stores
247
+ bounded JSON batches with a retention duration. These support immutable pieces
248
+ that must be stored before a manifest becomes visible.
249
+
250
+ ## Routers
251
+
252
+ An app's `tools` is a router. Keys form tool paths, and routers nest like tRPC's:
253
+ `router({ health, issues: router({ list, close }, { description }) })` exposes
254
+ `health`, `issues.list` and `issues.close`. Each query or mutation keeps its own
255
+ kind; names carry no `queries.` or `mutations.` prefix. Router options are
256
+ `title`, `description`, `instructions`, `icons` and `tags`. Instructions become a
257
+ skill named `tools` for the root router and `tools-<path>` below it, such as
258
+ `tools-issues`. Paths other than lowercase letters and digits get a slug and a
259
+ hash of the path, so names never collide. An authored skill with the same name
260
+ replaces the generated one. `router(source, options)` overrides a source's
261
+ metadata. Keys `__proto__`, `constructor` and `prototype` are reserved, and an
262
+ mutation can be mounted at only one path.
263
+
264
+ Protocol helpers return routers, so an app mounts several sources under keys.
265
+ `mcpRouter` takes its title, description, icons and instructions from the
266
+ server, and `liveOpenapiRouter` from the document's `info` and tags. `stdioRouter`,
267
+ `openapiRouter` and `graphqlRouter` carry no source metadata. A nested router that fails to load is reported on its own catalog entry;
268
+ the app's other tools still load. The root failing fails discovery.
269
+
270
+ `dynamicRouter({ list, resolve })` separates descriptions from executable
271
+ operations. `list()` returns tool metadata with names relative to the router,
272
+ such as `getProject`; names may contain dots. `resolve(name)` returns a
273
+ query/mutation declaration or `undefined`. The host validates input and applies
274
+ approval policy after resolving an operation. `accountRouter` preserves this
275
+ separation. Static operations run without resolving a source; listings reject
276
+ duplicate names.
277
+
278
+ ```ts
279
+ export default defineApp(
280
+ { accounts: {} },
281
+ {
282
+ tools: dynamicRouter({
283
+ list: async () => [
284
+ {
285
+ name: "ping",
286
+ description: "Return pong",
287
+ inputSchema: { type: "object", properties: {} },
288
+ readOnly: true,
289
+ },
290
+ ],
291
+ resolve: async (name) =>
292
+ name === "ping" ? query({ input: object({}) }, async () => "pong") : undefined,
293
+ }),
294
+ },
295
+ );
296
+ ```
297
+
298
+ Mark queries with `readOnly: true`; other listed tools are mutations. `list`
299
+ describes available tools; `resolve` returns the matching declaration. An
300
+ optional `meta()` returns the router's title, description and instructions.
301
+
302
+ `ctx.cache.revalidate(options)` takes the same options as `get`, but always
303
+ awaits a refresh. Concurrent refreshes share a load. The previous value stays
304
+ available to ordinary readers while refresh runs, and a failed refresh does not
305
+ remove it. Use this at an explicit connection or user refresh boundary; it is
306
+ not a reason to refresh on every tool call.