apps 0.0.1-beta.1 → 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 (118) hide show
  1. package/README.md +65 -43
  2. package/framework-reference.json +1 -1
  3. package/js/browser-XIPJGLH2.js +65 -0
  4. package/js/{chunk-SATWJKN6.js → chunk-27F7W2LG.js} +1 -1
  5. package/js/{chunk-HDJH3RPR.js → chunk-57RKNWL2.js} +2 -2
  6. package/js/{chunk-2HHMABB6.js → chunk-5T57N25Q.js} +61 -13
  7. package/js/{chunk-6IIO4NPI.js → chunk-72JNVHPK.js} +21 -9
  8. package/js/{chunk-FW5HBOIK.js → chunk-CDL5PM2Q.js} +307 -169
  9. package/js/{chunk-X7SFGU4Q.js → chunk-CRDWFA74.js} +28 -9
  10. package/js/{chunk-G7IE6BKC.js → chunk-EPT3ZP52.js} +8 -8
  11. package/js/chunk-FL2QR3XW.js +507 -0
  12. package/js/{chunk-OHRT55C4.js → chunk-IJX4CYZO.js} +3 -6
  13. package/js/{chunk-ZTFQHGEB.js → chunk-IPI4MFSN.js} +3 -5
  14. package/js/{chunk-YEJOQEII.js → chunk-JU7VHODU.js} +1 -1
  15. package/js/chunk-KUMBKVJD.js +39 -0
  16. package/js/{chunk-EVJUVWN2.js → chunk-M3B3DE4K.js} +2 -2
  17. package/js/{chunk-ZJWDMTE3.js → chunk-MKWZPDR6.js} +3 -3
  18. package/js/{chunk-BMOIAIVR.js → chunk-N7YDVXYJ.js} +49 -1
  19. package/js/chunk-NKLWZJLE.js +172 -0
  20. package/js/{chunk-ZCAMUXSG.js → chunk-ODEIDRGW.js} +3 -4
  21. package/js/{chunk-M6ZRRIBI.js → chunk-PJJ24GU7.js} +1 -1
  22. package/js/{chunk-FZJOYIZO.js → chunk-PZB6T6KU.js} +1 -1
  23. package/js/chunk-R3EV5FTO.js +97 -0
  24. package/js/{chunk-6YBRWRK3.js → chunk-RFVIONFX.js} +43 -14
  25. package/js/{chunk-QKHR7BMF.js → chunk-UK573G7W.js} +1 -1
  26. package/js/{chunk-NCYXZN2G.js → chunk-UVL56Z6E.js} +390 -23
  27. package/js/{chunk-KOXMLKTM.js → chunk-V5KNQVCT.js} +308 -316
  28. package/js/{chunk-4LPG6RCH.js → chunk-VFZKSM3T.js} +5 -25
  29. package/js/{chunk-IHQ4ML7K.js → chunk-WLE7WX2U.js} +554 -102
  30. package/js/{chunk-RBAC33PQ.js → chunk-YXQHV65J.js} +58 -83
  31. package/js/chunk-Z5M2LQOZ.js +209 -0
  32. package/js/{chunk-PLCMJREA.js → chunk-ZQINWV4W.js} +60 -20
  33. package/js/client.js +10 -26
  34. package/js/contracts.js +70 -15
  35. package/js/effect.js +19 -19
  36. package/js/es-APDZKREY.js +40968 -0
  37. package/js/graphql.js +34 -39
  38. package/js/host.js +23 -23
  39. package/js/index.js +199 -195
  40. package/js/mcp/effect.js +21 -21
  41. package/js/mcp/stdio.js +25 -25
  42. package/js/mcp.js +60 -44
  43. package/js/openapi.js +826 -41682
  44. package/js/react.js +3 -3
  45. package/js/skills/effect.js +3 -4
  46. package/js/skills.js +53 -17
  47. package/js/storage/facet.js +4 -4
  48. package/js/ui/auth/contracts.js +8 -9
  49. package/js/ui/auth.js +16 -14
  50. package/js/ui/contracts.js +4 -4
  51. package/js/ui/serving.js +9 -8
  52. package/package.json +1 -1
  53. package/runtime.json +1 -1
  54. package/types/app-cache/src/contracts/cache.d.ts +42 -2
  55. package/types/app-cache/src/index.d.ts +59 -1
  56. package/types/app-data/src/contracts/database.d.ts +33 -6
  57. package/types/app-data/src/implementation/schema.d.ts +2 -17
  58. package/types/apps/src/contracts/app.d.ts +7 -6
  59. package/types/apps/src/contracts/cache.d.ts +4 -1
  60. package/types/apps/src/contracts/failure.d.ts +25 -0
  61. package/types/apps/src/contracts/host.d.ts +34 -679
  62. package/types/apps/src/contracts/mcp.d.ts +16 -0
  63. package/types/apps/src/contracts/openapi.d.ts +11 -1
  64. package/types/apps/src/contracts/operations.d.ts +0 -5
  65. package/types/apps/src/contracts/protocol-version.d.ts +6 -0
  66. package/types/apps/src/contracts/protocols/1.d.ts +1589 -0
  67. package/types/apps/src/contracts/protocols/2.d.ts +668 -0
  68. package/types/apps/src/contracts/protocols/3.d.ts +676 -0
  69. package/types/apps/src/contracts/protocols/4.d.ts +1229 -0
  70. package/types/apps/src/contracts/protocols/5.d.ts +1090 -0
  71. package/types/apps/src/contracts/provider.d.ts +51 -5
  72. package/types/apps/src/contracts/router.d.ts +59 -0
  73. package/types/apps/src/contracts/skills.d.ts +17 -8
  74. package/types/apps/src/contracts/storage.d.ts +3 -3
  75. package/types/apps/src/contracts/ui-auth.d.ts +6 -14
  76. package/types/apps/src/contracts/workflows.d.ts +34 -3
  77. package/types/apps/src/graphql.d.ts +1 -3
  78. package/types/apps/src/implementation/account-router.d.ts +12 -0
  79. package/types/apps/src/implementation/app.d.ts +5 -4
  80. package/types/apps/src/implementation/cache.d.ts +3 -1
  81. package/types/apps/src/implementation/catalog-cache.d.ts +9 -2
  82. package/types/apps/src/implementation/elicitation.d.ts +1 -1
  83. package/types/apps/src/implementation/failure-detail.d.ts +25 -0
  84. package/types/apps/src/implementation/graphql-catalog.d.ts +1 -4
  85. package/types/apps/src/implementation/mcp-catalog.d.ts +1 -4
  86. package/types/apps/src/implementation/mcp-client.d.ts +35 -19
  87. package/types/apps/src/implementation/mcp.d.ts +35 -19
  88. package/types/apps/src/implementation/openapi-compile.d.ts +3 -2
  89. package/types/apps/src/implementation/openapi-document.d.ts +0 -2
  90. package/types/apps/src/implementation/openapi-names.d.ts +18 -0
  91. package/types/apps/src/implementation/openapi-request.d.ts +0 -1
  92. package/types/apps/src/implementation/openapi-source.d.ts +7 -7
  93. package/types/apps/src/implementation/operations.d.ts +26 -3
  94. package/types/apps/src/implementation/protocol-operations.d.ts +3 -4
  95. package/types/apps/src/implementation/provider.d.ts +9 -4
  96. package/types/apps/src/implementation/router-catalog.d.ts +225 -0
  97. package/types/apps/src/implementation/router.d.ts +59 -0
  98. package/types/apps/src/implementation/schema.d.ts +5 -6
  99. package/types/apps/src/implementation/storage.d.ts +5 -3
  100. package/types/apps/src/implementation/swagger-client.d.ts +28 -0
  101. package/types/apps/src/implementation/ui-auth.d.ts +11 -5
  102. package/types/apps/src/implementation/ui-serving.d.ts +4 -2
  103. package/types/apps/src/implementation/webhooks.d.ts +1 -1
  104. package/types/apps/src/implementation/workflow-context.d.ts +11 -3
  105. package/types/apps/src/index.d.ts +5 -4
  106. package/types/apps/src/mcp-stdio.d.ts +2 -5
  107. package/types/apps/src/mcp.d.ts +5 -4
  108. package/types/apps/src/openapi.d.ts +6 -6
  109. package/types/apps/src/skills.d.ts +6 -3
  110. package/types/apps/src/ui-auth.d.ts +2 -2
  111. package/types/telemetry/src/browser-operations.d.ts +5 -2
  112. package/js/chunk-PZ36XMXW.js +0 -93
  113. package/js/chunk-SWPD52J7.js +0 -35
  114. package/js/chunk-TE4KO4HI.js +0 -47
  115. package/js/chunk-W7D7WVSY.js +0 -18
  116. package/types/apps/src/contracts/dynamic-tools.d.ts +0 -13
  117. package/types/apps/src/implementation/account-operations.d.ts +0 -151
  118. package/types/apps/src/implementation/dynamic-tools.d.ts +0 -8
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,18 +43,19 @@ 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
- `liveOpenapiOperations` reads an OpenAPI document through `ctx.cache`. Generated
53
+ `liveOpenapiRouter` reads an OpenAPI document through `ctx.cache`. Generated
53
54
  imports retain a source URL, allowed origin, and static credential bindings in
54
55
  `openapi.json`. The framework compiles a revision on a cache miss. It writes each
55
56
  operation and shared schema before publishing the current revision. A warm call
56
57
  reads that revision and the requested operation's schema dependencies. It does
57
- not download, parse, or read the full catalog. `openapiOperations` remains the
58
+ not download, parse, or read the full catalog. `openapiRouter` remains the
58
59
  lower-level helper for already normalized metadata.
59
60
  `parameterDefaults` binds path, query or header values to the selected account.
60
61
  Those parameters become optional and publish their value as the schema `default`;
@@ -68,25 +69,28 @@ Accounts bind at execution time. Live documents cannot change credential
68
69
  placement or send credentials to another origin. Editing generated source and
69
70
  redeploying is required to change those static choices.
70
71
 
71
- Authenticated templates use `provider.many()` and `accountOperations` from `apps`:
72
+ Authenticated templates use `provider.many()` and `accountRouter` from `apps`:
72
73
 
73
74
  ```ts
74
- export default defineApp({ accounts: { service: provider.many() } }, async ({ accounts, signal }) =>
75
- accountOperations(
76
- accounts.service,
77
- (account) =>
78
- mcpOperations({
79
- url: "https://example.com/mcp",
80
- headers: { Authorization: "Bearer " + account.fields.token },
81
- signal,
82
- }),
83
- { signal },
84
- ),
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
+ }),
85
89
  );
86
90
  ```
87
91
 
88
92
  MCP and GraphQL helpers accept `cache: ctx.cache.forAccount(account)` (or
89
- `ctx.cache` for a public source). They return `{ dynamicTools }`, cache remote
93
+ `ctx.cache` for a public source). They return a dynamic router, cache remote
90
94
  metadata, and compile only the selected tool. The defaults are five minutes fresh
91
95
  plus five minutes stale. Use `freshFor` / `staleFor` to change the windows, or
92
96
  `revalidate: true` to await a refresh. Tool results are never cached.
@@ -171,7 +175,7 @@ and [hosting notes](../../notes/app-ui.md).
171
175
 
172
176
  ## Webhooks
173
177
 
174
- Expose `webhooks: { issueOpened }` beside queries and mutations. Each definition
178
+ Expose `webhooks: { issueOpened }` beside `tools`. Each definition
175
179
  has an `account` requirement, `config` and `state` schemas, and async `register`,
176
180
  `handle`, and `unregister` callbacks. Register and unregister must be idempotent;
177
181
  handle must verify the provider signature before acting.
@@ -243,39 +247,57 @@ errors are explicit. Background refreshes have a 30-second deadline.
243
247
  bounded JSON batches with a retention duration. These support immutable pieces
244
248
  that must be stored before a manifest becomes visible.
245
249
 
246
- `dynamicTools({ list, resolve })` separates descriptions from executable
247
- operations. `list()` returns tool metadata with qualified names such as
248
- `queries.getProject`. `resolve(name)` returns a query/mutation declaration or
249
- `undefined`. The host validates input and applies approval policy after resolving
250
- an operation. `accountOperations` preserves this separation. Static operations
251
- can run without resolving the source; listings reject duplicate names.
252
-
253
- Assign the resolver to the app's `dynamicTools` field. The helper returns only
254
- `list` and `resolve`, never static query or mutation maps. Both static maps are
255
- optional, so an app can contain only dynamic tools.
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.
256
277
 
257
278
  ```ts
258
279
  export default defineApp(
259
280
  { accounts: {} },
260
281
  {
261
- dynamicTools: dynamicTools({
282
+ tools: dynamicRouter({
262
283
  list: async () => [
263
284
  {
264
- name: "queries.ping",
285
+ name: "ping",
265
286
  description: "Return pong",
266
287
  inputSchema: { type: "object", properties: {} },
267
288
  readOnly: true,
268
289
  },
269
290
  ],
270
291
  resolve: async (name) =>
271
- name === "queries.ping" ? query({ input: object({}) }, async () => "pong") : undefined,
292
+ name === "ping" ? query({ input: object({}) }, async () => "pong") : undefined,
272
293
  }),
273
294
  },
274
295
  );
275
296
  ```
276
297
 
277
- Names include `queries.` or `mutations.`. `list` describes available tools;
278
- `resolve` returns the matching query or mutation declaration.
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.
279
301
 
280
302
  `ctx.cache.revalidate(options)` takes the same options as `get`, but always
281
303
  awaits a refresh. Concurrent refreshes share a load. The previous value stays