acrylblends 1.3.0 → 1.3.2

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 (68) hide show
  1. package/dist/index.js +5 -3
  2. package/dist/index.js.map +1 -1
  3. package/docs/framework/workshop/README.md +2 -0
  4. package/legacy/README.md +4 -1
  5. package/legacy/agent/858de7a1ad0b/src/app.ts +289 -0
  6. package/legacy/agent/858de7a1ad0b/src/routes.ts +145 -0
  7. package/legacy/agent/b96ba6e3598a/src/app.ts +285 -0
  8. package/legacy/agent/b96ba6e3598a/src/routes.ts +145 -0
  9. package/legacy/agent/ecbc84f1c1e5/src/app.ts +291 -0
  10. package/legacy/agent/ecbc84f1c1e5/src/routes.ts +145 -0
  11. package/legacy/blank/2447ac6d5d24/src/app.ts +61 -0
  12. package/legacy/blank/387f7e25aaeb/src/app.ts +81 -0
  13. package/legacy/blank/5b9f10e1ba5e/src/app.ts +61 -0
  14. package/legacy/blank/5f6dd8910c50/src/app.ts +152 -0
  15. package/legacy/blank/5f6dd8910c50/src/routes.ts +75 -0
  16. package/legacy/blank/a7e8f539ffee/src/app.ts +160 -0
  17. package/legacy/blank/a7e8f539ffee/src/routes.ts +75 -0
  18. package/legacy/blank/bdb9735e013b/src/app.ts +61 -0
  19. package/legacy/blank/c3be1d735b1a/src/app.ts +61 -0
  20. package/legacy/blank/c3be1d735b1a/src/routes.ts +18 -0
  21. package/legacy/blank/e04303a7f8dd/src/app.ts +61 -0
  22. package/legacy/chat/5120c4a9fa61/src/app.ts +157 -0
  23. package/legacy/chat/5120c4a9fa61/src/routes.ts +29 -0
  24. package/legacy/chat/d4464dfb3b04/src/app.ts +165 -0
  25. package/legacy/chat/d4464dfb3b04/src/routes.ts +29 -0
  26. package/legacy/frozen.json +7 -0
  27. package/legacy/layouts.json +135 -45
  28. package/legacy/nodejs/9d59115118c7/src/app.ts +150 -0
  29. package/legacy/nodejs/9d59115118c7/src/routes.ts +59 -0
  30. package/legacy/nodejs/a6a340b4d3a6/src/app.ts +158 -0
  31. package/legacy/nodejs/a6a340b4d3a6/src/routes.ts +59 -0
  32. package/legacy/notes/fb43a1c5f3b4/src/app.ts +165 -0
  33. package/legacy/notes/fb43a1c5f3b4/src/routes.ts +21 -0
  34. package/legacy/notes/fc3fe7c749d2/src/app.ts +157 -0
  35. package/legacy/notes/fc3fe7c749d2/src/routes.ts +21 -0
  36. package/legacy/todo/164274ffcf7f/src/app.ts +145 -0
  37. package/legacy/todo/164274ffcf7f/src/todo.ts +137 -0
  38. package/lib/cordis/door.d.ts +10 -1
  39. package/lib/cordis/door.js +11 -4
  40. package/package.json +1 -1
  41. package/plugins/acryl-door/src/host/door.ts +17 -5
  42. package/plugins/builder/index.ts +1 -1
  43. package/plugins/builder/plugin.json +1 -1
  44. package/plugins/extensions/index.ts +57 -2
  45. package/plugins/extensions/routes.ts +92 -0
  46. package/plugins/home/index.ts +3 -1
  47. package/plugins/plugin-share/README.md +16 -1
  48. package/plugins/plugin-share/index.ts +130 -16
  49. package/plugins/plugin-share/plugin.json +1 -1
  50. package/templates/agent/src/app.ts +2 -0
  51. package/templates/blank/blend.yaml +3 -0
  52. package/templates/blank/src/app.ts +8 -0
  53. package/templates/blank/template.json +1 -0
  54. package/templates/chat/blend.yaml +3 -0
  55. package/templates/chat/src/app.ts +8 -0
  56. package/templates/chat/template.json +1 -0
  57. package/templates/nodejs/blend.yaml +3 -0
  58. package/templates/nodejs/src/app.ts +8 -0
  59. package/templates/nodejs/template.json +1 -0
  60. package/templates/notes/blend.yaml +3 -0
  61. package/templates/notes/src/app.ts +8 -0
  62. package/templates/notes/template.json +1 -0
  63. /package/legacy/blank/{d6d371c9a65e → 2447ac6d5d24}/src/routes.ts +0 -0
  64. /package/legacy/blank/{5a91c558af22 → 387f7e25aaeb}/src/routes.ts +0 -0
  65. /package/legacy/blank/{b2cbb759c889 → 5b9f10e1ba5e}/src/routes.ts +0 -0
  66. /package/legacy/blank/{9c650cf52bf3 → bdb9735e013b}/src/routes.ts +0 -0
  67. /package/legacy/blank/{aea589283445 → e04303a7f8dd}/src/routes.ts +0 -0
  68. /package/plugins/{builder → plugin-share}/package.ts +0 -0
@@ -0,0 +1,152 @@
1
+ import { join } from 'node:path'
2
+ import { fileURLToPath } from 'node:url'
3
+ import { Context, type Fiber } from '@deepseek-ai/cordis'
4
+ import * as door from '../plugins/acryl-door/src/index.ts'
5
+ import * as nodeServer from '../plugins/acryl-node-server/src/index.ts'
6
+ import * as router from '../plugins/acryl-router/src/index.ts'
7
+ import { extensions } from '../plugins/extensions/index.ts'
8
+ import * as home from '../plugins/home/index.ts'
9
+ import { type AppInstance, instance } from '../plugins/instance/index.ts'
10
+ import {
11
+ appPluginNames,
12
+ blueprintsIn,
13
+ compose,
14
+ loadAppPlugins,
15
+ loadManifest,
16
+ type ParameterValue,
17
+ } from '../plugins/manifest/index.ts'
18
+ import { doorEnabled } from './door.ts'
19
+ import { FRAME_MOUNT_PREFIX, routes } from './routes.ts'
20
+
21
+ /** The plugins this app's code provides. `blend.yaml` chooses, orders and configures them, and adds the app's own plugins from `plugins/` by name. */
22
+ export const registry = {
23
+ 'acryl-router': router,
24
+ 'acryl-node-server': nodeServer,
25
+ 'acryl-door': door,
26
+ home,
27
+ extensions,
28
+ routes,
29
+ }
30
+
31
+ const projectRoot = fileURLToPath(new URL('..', import.meta.url))
32
+
33
+ /** The manifest next to this app's source. */
34
+ export const MANIFEST = join(projectRoot, 'blend.yaml')
35
+ /** The app's plugins: the library copies `registry` imports, and the app's own plugins (a feature each), which `blend.yaml` mounts by their folder name. */
36
+ const PLUGINS_DIR = join(projectRoot, 'plugins')
37
+
38
+ /**
39
+ * The app's manifest, resolved. A Blend finds its Blueprint in `blueprints/<id>.yaml`; an app that is itself a Blueprint never looks.
40
+ * `createApp` and the tests read it the same way.
41
+ */
42
+ export function readManifest(values?: Readonly<Record<string, ParameterValue>>) {
43
+ return loadManifest(MANIFEST, {
44
+ known: [...Object.keys(registry), ...appPluginNames(PLUGINS_DIR)],
45
+ getBlueprint: blueprintsIn(join(projectRoot, 'blueprints')),
46
+ ...(values ? { values } : {}),
47
+ })
48
+ }
49
+
50
+ /** The manifest without some rows: without its server (and so its door) the app is reached in process, through `root.router.request`; the door is also left out in production. */
51
+ function without<M extends { plugins: readonly { use: string }[] }>(
52
+ manifest: M,
53
+ ...uses: string[]
54
+ ): M {
55
+ return {
56
+ ...manifest,
57
+ plugins: manifest.plugins.map((row) =>
58
+ uses.includes(row.use) ? { ...row, disabled: true } : row,
59
+ ),
60
+ }
61
+ }
62
+
63
+ export interface App {
64
+ readonly root: Context
65
+ /** The address the server listens on; empty when the app was made with `listen: false`. */
66
+ readonly url: string
67
+ stop(): Promise<void>
68
+ }
69
+
70
+ export interface AppOptions {
71
+ readonly values?: Readonly<Record<string, ParameterValue>>
72
+ /** The path the app is mounted at; absent on its own server, where it keeps the root, and {@link FRAME_MOUNT_PREFIX} in the frame. */
73
+ readonly prefix?: string
74
+ /** Start the HTTP server (default). Tests pass `false` and call `app.root.router.request(path)`: it needs no port, so it also runs where a sandbox forbids listening. */
75
+ readonly listen?: boolean
76
+ }
77
+
78
+ /** The rows the frame host provides: the app contributes only the plugins that are its own. */
79
+ const HOST_ROWS = [
80
+ 'instance',
81
+ 'acryl-router',
82
+ 'acryl-node-server',
83
+ 'acryl-web-server',
84
+ 'acryl-page',
85
+ 'manifest',
86
+ 'save',
87
+ 'acryl-door',
88
+ ]
89
+
90
+ /**
91
+ * The app's rows, composed into `ctx`: the app's own server calls this from `createApp`, and the generated frame layer mounts it as one row, so the frame
92
+ * runs the app exactly as the app's own server does (same rows, same order, same config). `host: true` leaves the infrastructure rows to the frame host,
93
+ * which is where the door lives too, and mounts the app at {@link FRAME_MOUNT_PREFIX}.
94
+ */
95
+ export async function composeInto(
96
+ ctx: Context,
97
+ chosen: AppInstance,
98
+ options: AppOptions & { readonly host?: boolean } = {},
99
+ ): Promise<Fiber[]> {
100
+ const read = readManifest(options.values)
101
+ const own = options.host !== true && options.listen !== false
102
+ // The frame host mounts the app under its own prefix; the app's own server keeps the root.
103
+ const prefix = options.prefix ?? (options.host === true ? FRAME_MOUNT_PREFIX : undefined)
104
+ // Rows left out: the server (and the door, which needs it) when the app is reached in process or inside the frame host; the door when it is switched
105
+ // off.
106
+ const leaveOut = new Set<string>(options.host === true ? HOST_ROWS : [])
107
+ if (!own) leaveOut.add('acryl-node-server').add('acryl-door')
108
+ if (!doorEnabled()) leaveOut.add('acryl-door')
109
+ const manifest = without(read, ...leaveOut)
110
+ // The rows that name one of the app's own plugin folders (a feature: plugins/<name>/ and its row) rather than a registry import. Each one that runs
111
+ // is imported here; all of them, off or on, belong to their row, so the extensions row never starts them a second time.
112
+ const ownRows = [
113
+ ...new Set(read.plugins.map((row) => row.use).filter((use) => !Object.hasOwn(registry, use))),
114
+ ]
115
+ const ownPlugins = await loadAppPlugins(
116
+ PLUGINS_DIR,
117
+ ownRows.filter((use) => manifest.plugins.some((row) => row.use === use && !row.disabled)),
118
+ )
119
+ return compose(
120
+ ctx,
121
+ manifest,
122
+ { ...registry, ...ownPlugins },
123
+ {
124
+ // The routes row mounts the pages (and the client modules) at the prefix the frame host chose.
125
+ routes: { ...(prefix === undefined ? {} : { prefix }) },
126
+ // The app's own plugins live in plugins/, next to the plugins copied from the library (plugins/library.json lists those, so they are not installed twice).
127
+ // In production they start read-only from where they are deployed: the app keeps its features, and nothing can be installed while it runs.
128
+ extensions: {
129
+ ...(process.env.NODE_ENV === 'production' ? { readOnly: true } : {}),
130
+ sources: [{ dir: PLUGINS_DIR, trust: 'install' }],
131
+ rows: ownRows,
132
+ },
133
+ // Only the app's own server listens; the frame host owns the server and its port.
134
+ ...(own ? { server: { port: chosen.port.start, scan: chosen.port.scan ? 20 : 0 } } : {}),
135
+ },
136
+ )
137
+ }
138
+
139
+ /** The app: `instance` first (where it lives, chosen at run time), then the manifest's rows in order. */
140
+ export async function createApp(chosen: AppInstance, options: AppOptions = {}): Promise<App> {
141
+ const root = new Context()
142
+ const first = root.plugin(instance, chosen)
143
+ await first.await()
144
+ const fibers: Fiber[] = [first, ...(await composeInto(root, chosen, options))]
145
+ return {
146
+ root,
147
+ url: options.listen === false ? '' : root.nodeServer.url,
148
+ async stop() {
149
+ for (const fiber of [...fibers].reverse()) await fiber.dispose()
150
+ },
151
+ }
152
+ }
@@ -0,0 +1,75 @@
1
+ import type { Context } from '@deepseek-ai/cordis'
2
+ import { Acryl } from '../plugins/acryl-router/src/index.ts'
3
+ import { type Home, renderWidgets } from '../plugins/home/index.ts'
4
+ import { aboutPage } from './about.tsx'
5
+ import { FIRST_PAGE_MARKER } from './first-page.ts'
6
+
7
+ export const APP_NAME = '__APP_NAME__'
8
+
9
+ /**
10
+ * The only place the app's mount prefix is named. On its own server (production, `npm start`) the app mounts at the root and
11
+ * its public URLs are `/`, `/about`, `/health`; when the ACRYL frame hosts it (`npm run dev`) the routes mount here, and the
12
+ * frame opens its tile at `/app/`. Every page link and asset URL this template writes is derived from the prefix it is
13
+ * mounted at, so the same source serves both.
14
+ */
15
+ export const FRAME_MOUNT_PREFIX = '/app'
16
+
17
+ /** The scaffold's name comes from the folder, so the first screen escapes it like any other user text. */
18
+ const escapeHtml = (text: string): string =>
19
+ text
20
+ .replaceAll('&', '&amp;')
21
+ .replaceAll('<', '&lt;')
22
+ .replaceAll('>', '&gt;')
23
+ .replaceAll('"', '&quot;')
24
+
25
+ /**
26
+ * The first screen: the page a browser gets at the root, which is what the ACRYL frame's first tile shows. A blank app whose root answered JSON to
27
+ * every client gave the tile Chrome's JSON viewer, nearly invisible in the frame's dark surface (owner review, 2026-11-02); the root now answers a page
28
+ * to a browser and the JSON hello to everything else, the way the agent template does. The About link is relative, so it works under the frame's /app
29
+ * mount and on the app's own server alike.
30
+ */
31
+ const homePage = (name: string, widgets: string): string => `<!doctype html>
32
+ <html lang="en">
33
+ <head>
34
+ <meta charset="utf-8">
35
+ <meta name="viewport" content="width=device-width, initial-scale=1">
36
+ <title>${escapeHtml(name)}</title>
37
+ <style>:root{color-scheme:light dark;background:Canvas;color:CanvasText}body{margin:2rem auto;max-width:44rem;padding:0 1rem;font:15px/1.55 system-ui,-apple-system,"Segoe UI",sans-serif}h1{font-size:1.6rem;margin:0 0 .5rem}a{color:#5468ff}code{font:.9em ui-monospace,"SF Mono",Menlo,monospace}</style>
38
+ </head>
39
+ <body>
40
+ <main>
41
+ <h1>${escapeHtml(name)}</h1>
42
+ <p>Your app is running. ${FIRST_PAGE_MARKER}; edit <code>src/routes.ts</code> to change it.</p>
43
+ <p><a href="./about">About</a></p>
44
+ ${widgets}
45
+ </main>
46
+ </body>
47
+ </html>`
48
+
49
+ /**
50
+ * The app's own pages and routes, mountable at any prefix: the standalone server mounts it at the root, the frame host at {@link FRAME_MOUNT_PREFIX}.
51
+ * The first screen shows the widgets of the app's plugins (`ctx.home`), read at each request, so a plugin switched on or off shows at the next load.
52
+ */
53
+ export function makeApp(home: Home): Acryl {
54
+ return (
55
+ new Acryl()
56
+ // A browser gets the first screen; an API client gets the JSON hello.
57
+ .get('/', async (c) =>
58
+ (c.req.header('accept') ?? '').includes('text/html')
59
+ ? c.html(homePage(APP_NAME, await renderWidgets(home)))
60
+ : c.json({ app: APP_NAME, ok: true }),
61
+ )
62
+ .get('/health', (c) => c.json({ ok: true }))
63
+ .get('/about', (c) => c.html(aboutPage()))
64
+ )
65
+ }
66
+
67
+ /** The app's own routes: an `App` mounted on the router at `options.prefix` (empty or absent: the root). The mount is removed when this plugin is disposed. */
68
+ export const routes = {
69
+ name: 'routes',
70
+ inject: ['router', 'home'],
71
+ apply(ctx: Context, options: { readonly prefix?: string } = {}) {
72
+ const prefix = options.prefix ?? ''
73
+ ctx.router.route(prefix === '' ? '/' : prefix, makeApp(ctx.home))
74
+ },
75
+ }
@@ -0,0 +1,160 @@
1
+ import { join } from 'node:path'
2
+ import { fileURLToPath } from 'node:url'
3
+ import { Context, type Fiber } from '@deepseek-ai/cordis'
4
+ import * as door from '../plugins/acryl-door/src/index.ts'
5
+ import * as nodeServer from '../plugins/acryl-node-server/src/index.ts'
6
+ import * as router from '../plugins/acryl-router/src/index.ts'
7
+ import { extensions } from '../plugins/extensions/index.ts'
8
+ import * as home from '../plugins/home/index.ts'
9
+ import { type AppInstance, instance } from '../plugins/instance/index.ts'
10
+ import {
11
+ appPluginNames,
12
+ blueprintsIn,
13
+ compose,
14
+ loadAppPlugins,
15
+ loadManifest,
16
+ type ParameterValue,
17
+ } from '../plugins/manifest/index.ts'
18
+ import { pluginShare } from '../plugins/plugin-share/index.ts'
19
+ import { doorEnabled } from './door.ts'
20
+ import { FRAME_MOUNT_PREFIX, routes } from './routes.ts'
21
+
22
+ /** The plugins this app's code provides. `blend.yaml` chooses, orders and configures them, and adds the app's own plugins from `plugins/` by name. */
23
+ export const registry = {
24
+ 'acryl-router': router,
25
+ 'acryl-node-server': nodeServer,
26
+ 'acryl-door': door,
27
+ home,
28
+ extensions,
29
+ 'plugin-share': pluginShare,
30
+ routes,
31
+ }
32
+
33
+ const projectRoot = fileURLToPath(new URL('..', import.meta.url))
34
+
35
+ /** The manifest next to this app's source. */
36
+ export const MANIFEST = join(projectRoot, 'blend.yaml')
37
+ /** The app's plugins: the library copies `registry` imports, and the app's own plugins (a feature each), which `blend.yaml` mounts by their folder name. */
38
+ const PLUGINS_DIR = join(projectRoot, 'plugins')
39
+
40
+ /**
41
+ * The app's manifest, resolved. A Blend finds its Blueprint in `blueprints/<id>.yaml`; an app that is itself a Blueprint never looks.
42
+ * `createApp` and the tests read it the same way.
43
+ */
44
+ export function readManifest(values?: Readonly<Record<string, ParameterValue>>) {
45
+ return loadManifest(MANIFEST, {
46
+ known: [...Object.keys(registry), ...appPluginNames(PLUGINS_DIR)],
47
+ getBlueprint: blueprintsIn(join(projectRoot, 'blueprints')),
48
+ ...(values ? { values } : {}),
49
+ })
50
+ }
51
+
52
+ /** The manifest without some rows: without its server (and so its door) the app is reached in process, through `root.router.request`; the door is also left out in production. */
53
+ function without<M extends { plugins: readonly { use: string }[] }>(
54
+ manifest: M,
55
+ ...uses: string[]
56
+ ): M {
57
+ return {
58
+ ...manifest,
59
+ plugins: manifest.plugins.map((row) =>
60
+ uses.includes(row.use) ? { ...row, disabled: true } : row,
61
+ ),
62
+ }
63
+ }
64
+
65
+ export interface App {
66
+ readonly root: Context
67
+ /** The address the server listens on; empty when the app was made with `listen: false`. */
68
+ readonly url: string
69
+ stop(): Promise<void>
70
+ }
71
+
72
+ export interface AppOptions {
73
+ readonly values?: Readonly<Record<string, ParameterValue>>
74
+ /** The path the app is mounted at; absent on its own server, where it keeps the root, and {@link FRAME_MOUNT_PREFIX} in the frame. */
75
+ readonly prefix?: string
76
+ /** Start the HTTP server (default). Tests pass `false` and call `app.root.router.request(path)`: it needs no port, so it also runs where a sandbox forbids listening. */
77
+ readonly listen?: boolean
78
+ }
79
+
80
+ /** The rows the frame host provides: the app contributes only the plugins that are its own. */
81
+ const HOST_ROWS = [
82
+ 'instance',
83
+ 'acryl-router',
84
+ 'acryl-node-server',
85
+ 'acryl-web-server',
86
+ 'acryl-page',
87
+ 'manifest',
88
+ 'save',
89
+ 'acryl-door',
90
+ ]
91
+
92
+ /**
93
+ * The app's rows, composed into `ctx`: the app's own server calls this from `createApp`, and the generated frame layer mounts it as one row, so the frame
94
+ * runs the app exactly as the app's own server does (same rows, same order, same config). `host: true` leaves the infrastructure rows to the frame host,
95
+ * which is where the door lives too, and mounts the app at {@link FRAME_MOUNT_PREFIX}.
96
+ */
97
+ export async function composeInto(
98
+ ctx: Context,
99
+ chosen: AppInstance,
100
+ options: AppOptions & { readonly host?: boolean } = {},
101
+ ): Promise<Fiber[]> {
102
+ const read = readManifest(options.values)
103
+ const own = options.host !== true && options.listen !== false
104
+ // The frame host mounts the app under its own prefix; the app's own server keeps the root.
105
+ const prefix = options.prefix ?? (options.host === true ? FRAME_MOUNT_PREFIX : undefined)
106
+ // Rows left out: the server (and the door, which needs it) when the app is reached in process or inside the frame host; the door when it is switched
107
+ // off.
108
+ const leaveOut = new Set<string>(options.host === true ? HOST_ROWS : [])
109
+ if (!own) leaveOut.add('acryl-node-server').add('acryl-door')
110
+ if (!doorEnabled()) leaveOut.add('acryl-door')
111
+ // A pull runs a stranger's code and a publish leaves the machine: development only, like the door.
112
+ if (process.env.NODE_ENV === 'production') leaveOut.add('plugin-share')
113
+ const manifest = without(read, ...leaveOut)
114
+ // The rows that name one of the app's own plugin folders (a feature: plugins/<name>/ and its row) rather than a registry import. Each one that runs
115
+ // is imported here; all of them, off or on, belong to their row, so the extensions row never starts them a second time.
116
+ const ownRows = [
117
+ ...new Set(read.plugins.map((row) => row.use).filter((use) => !Object.hasOwn(registry, use))),
118
+ ]
119
+ const ownPlugins = await loadAppPlugins(
120
+ PLUGINS_DIR,
121
+ ownRows.filter((use) => manifest.plugins.some((row) => row.use === use && !row.disabled)),
122
+ )
123
+ return compose(
124
+ ctx,
125
+ manifest,
126
+ { ...registry, ...ownPlugins },
127
+ {
128
+ // The routes row mounts the pages (and the client modules) at the prefix the frame host chose.
129
+ routes: { ...(prefix === undefined ? {} : { prefix }) },
130
+ // The app's own plugins live in plugins/, next to the plugins copied from the library (plugins/library.json lists those, so they are not installed twice).
131
+ // In production they start read-only from where they are deployed: the app keeps its features, and nothing can be installed while it runs.
132
+ extensions: {
133
+ ...(process.env.NODE_ENV === 'production' ? { readOnly: true } : {}),
134
+ sources: [{ dir: PLUGINS_DIR, trust: 'install' }],
135
+ rows: ownRows,
136
+ // Messages name a route as the plugin wrote it, not under the frame's canvas prefix.
137
+ ...(prefix === undefined ? {} : { routePrefix: prefix }),
138
+ },
139
+ // Pulled plugins go where the extensions row installs from.
140
+ 'plugin-share': { dir: PLUGINS_DIR },
141
+ // Only the app's own server listens; the frame host owns the server and its port.
142
+ ...(own ? { server: { port: chosen.port.start, scan: chosen.port.scan ? 20 : 0 } } : {}),
143
+ },
144
+ )
145
+ }
146
+
147
+ /** The app: `instance` first (where it lives, chosen at run time), then the manifest's rows in order. */
148
+ export async function createApp(chosen: AppInstance, options: AppOptions = {}): Promise<App> {
149
+ const root = new Context()
150
+ const first = root.plugin(instance, chosen)
151
+ await first.await()
152
+ const fibers: Fiber[] = [first, ...(await composeInto(root, chosen, options))]
153
+ return {
154
+ root,
155
+ url: options.listen === false ? '' : root.nodeServer.url,
156
+ async stop() {
157
+ for (const fiber of [...fibers].reverse()) await fiber.dispose()
158
+ },
159
+ }
160
+ }
@@ -0,0 +1,75 @@
1
+ import type { Context } from '@deepseek-ai/cordis'
2
+ import { Acryl } from '../plugins/acryl-router/src/index.ts'
3
+ import { type Home, renderWidgets } from '../plugins/home/index.ts'
4
+ import { aboutPage } from './about.tsx'
5
+ import { FIRST_PAGE_MARKER } from './first-page.ts'
6
+
7
+ export const APP_NAME = '__APP_NAME__'
8
+
9
+ /**
10
+ * The only place the app's mount prefix is named. On its own server (production, `npm start`) the app mounts at the root and
11
+ * its public URLs are `/`, `/about`, `/health`; when the ACRYL frame hosts it (`npm run dev`) the routes mount here, and the
12
+ * frame opens its tile at `/app/`. Every page link and asset URL this template writes is derived from the prefix it is
13
+ * mounted at, so the same source serves both.
14
+ */
15
+ export const FRAME_MOUNT_PREFIX = '/app'
16
+
17
+ /** The scaffold's name comes from the folder, so the first screen escapes it like any other user text. */
18
+ const escapeHtml = (text: string): string =>
19
+ text
20
+ .replaceAll('&', '&amp;')
21
+ .replaceAll('<', '&lt;')
22
+ .replaceAll('>', '&gt;')
23
+ .replaceAll('"', '&quot;')
24
+
25
+ /**
26
+ * The first screen: the page a browser gets at the root, which is what the ACRYL frame's first tile shows. A blank app whose root answered JSON to
27
+ * every client gave the tile Chrome's JSON viewer, nearly invisible in the frame's dark surface (owner review, 2026-11-02); the root now answers a page
28
+ * to a browser and the JSON hello to everything else, the way the agent template does. The About link is relative, so it works under the frame's /app
29
+ * mount and on the app's own server alike.
30
+ */
31
+ const homePage = (name: string, widgets: string): string => `<!doctype html>
32
+ <html lang="en">
33
+ <head>
34
+ <meta charset="utf-8">
35
+ <meta name="viewport" content="width=device-width, initial-scale=1">
36
+ <title>${escapeHtml(name)}</title>
37
+ <style>:root{color-scheme:light dark;background:Canvas;color:CanvasText}body{margin:2rem auto;max-width:44rem;padding:0 1rem;font:15px/1.55 system-ui,-apple-system,"Segoe UI",sans-serif}h1{font-size:1.6rem;margin:0 0 .5rem}a{color:#5468ff}code{font:.9em ui-monospace,"SF Mono",Menlo,monospace}</style>
38
+ </head>
39
+ <body>
40
+ <main>
41
+ <h1>${escapeHtml(name)}</h1>
42
+ <p>Your app is running. ${FIRST_PAGE_MARKER}; edit <code>src/routes.ts</code> to change it.</p>
43
+ <p><a href="./about">About</a></p>
44
+ ${widgets}
45
+ </main>
46
+ </body>
47
+ </html>`
48
+
49
+ /**
50
+ * The app's own pages and routes, mountable at any prefix: the standalone server mounts it at the root, the frame host at {@link FRAME_MOUNT_PREFIX}.
51
+ * The first screen shows the widgets of the app's plugins (`ctx.home`), read at each request, so a plugin switched on or off shows at the next load.
52
+ */
53
+ export function makeApp(home: Home): Acryl {
54
+ return (
55
+ new Acryl()
56
+ // A browser gets the first screen; an API client gets the JSON hello.
57
+ .get('/', async (c) =>
58
+ (c.req.header('accept') ?? '').includes('text/html')
59
+ ? c.html(homePage(APP_NAME, await renderWidgets(home)))
60
+ : c.json({ app: APP_NAME, ok: true }),
61
+ )
62
+ .get('/health', (c) => c.json({ ok: true }))
63
+ .get('/about', (c) => c.html(aboutPage()))
64
+ )
65
+ }
66
+
67
+ /** The app's own routes: an `App` mounted on the router at `options.prefix` (empty or absent: the root). The mount is removed when this plugin is disposed. */
68
+ export const routes = {
69
+ name: 'routes',
70
+ inject: ['router', 'home'],
71
+ apply(ctx: Context, options: { readonly prefix?: string } = {}) {
72
+ const prefix = options.prefix ?? ''
73
+ ctx.router.route(prefix === '' ? '/' : prefix, makeApp(ctx.home))
74
+ },
75
+ }
@@ -0,0 +1,61 @@
1
+ import { join } from 'node:path'
2
+ import { fileURLToPath } from 'node:url'
3
+ import { Context, type Fiber } from '@deepseek-ai/cordis'
4
+ import * as nodeServer from './plugins/acryl-node-server/src/index.ts'
5
+ import * as router from './plugins/acryl-router/src/index.ts'
6
+ import { type AppInstance, instance } from './plugins/instance/index.ts'
7
+ import {
8
+ blueprintsIn,
9
+ compose,
10
+ loadManifest,
11
+ type ParameterValue,
12
+ } from './plugins/manifest/index.ts'
13
+ import { routes } from './routes.ts'
14
+
15
+ /** The plugins this app's code provides. `blend.yaml` chooses, orders and configures them. */
16
+ export const registry = { 'acryl-router': router, 'acryl-node-server': nodeServer, routes }
17
+
18
+ /** The manifest next to this app's source. */
19
+ export const MANIFEST = join(fileURLToPath(new URL('..', import.meta.url)), 'blend.yaml')
20
+
21
+ /**
22
+ * The app's manifest, resolved. A Blend finds its Blueprint in `blueprints/<id>.yaml`; an app that is itself a Blueprint never looks.
23
+ * `createApp` and the tests read it the same way.
24
+ */
25
+ export function readManifest(values?: Readonly<Record<string, ParameterValue>>) {
26
+ return loadManifest(MANIFEST, {
27
+ known: Object.keys(registry),
28
+ getBlueprint: blueprintsIn(join(fileURLToPath(new URL('..', import.meta.url)), 'blueprints')),
29
+ ...(values ? { values } : {}),
30
+ })
31
+ }
32
+
33
+ export interface App {
34
+ readonly root: Context
35
+ readonly url: string
36
+ stop(): Promise<void>
37
+ }
38
+
39
+ /** The app: `instance` first (where it lives, chosen at run time), then the manifest's rows in order. */
40
+ export async function createApp(
41
+ chosen: AppInstance,
42
+ options: { values?: Readonly<Record<string, ParameterValue>> } = {},
43
+ ): Promise<App> {
44
+ const manifest = readManifest(options.values)
45
+ const root = new Context()
46
+ const first = root.plugin(instance, chosen)
47
+ await first.await()
48
+ const fibers: Fiber[] = [
49
+ first,
50
+ ...(await compose(root, manifest, registry, {
51
+ server: { port: chosen.port.start, scan: chosen.port.scan ? 20 : 0 },
52
+ })),
53
+ ]
54
+ return {
55
+ root,
56
+ url: root.nodeServer.url,
57
+ async stop() {
58
+ for (const fiber of [...fibers].reverse()) await fiber.dispose()
59
+ },
60
+ }
61
+ }
@@ -0,0 +1,61 @@
1
+ import { join } from 'node:path'
2
+ import { fileURLToPath } from 'node:url'
3
+ import { Context, type Fiber } from '@deepseek-ai/cordis'
4
+ import * as nodeServer from '../plugins/acryl-node-server/src/index.ts'
5
+ import * as router from '../plugins/acryl-router/src/index.ts'
6
+ import { type AppInstance, instance } from '../plugins/instance/index.ts'
7
+ import {
8
+ blueprintsIn,
9
+ compose,
10
+ loadManifest,
11
+ type ParameterValue,
12
+ } from '../plugins/manifest/index.ts'
13
+ import { routes } from './routes.ts'
14
+
15
+ /** The plugins this app's code provides. `blend.yaml` chooses, orders and configures them. */
16
+ export const registry = { 'acryl-router': router, 'acryl-node-server': nodeServer, routes }
17
+
18
+ /** The manifest next to this app's source. */
19
+ export const MANIFEST = join(fileURLToPath(new URL('..', import.meta.url)), 'blend.yaml')
20
+
21
+ /**
22
+ * The app's manifest, resolved. A Blend finds its Blueprint in `blueprints/<id>.yaml`; an app that is itself a Blueprint never looks.
23
+ * `createApp` and the tests read it the same way.
24
+ */
25
+ export function readManifest(values?: Readonly<Record<string, ParameterValue>>) {
26
+ return loadManifest(MANIFEST, {
27
+ known: Object.keys(registry),
28
+ getBlueprint: blueprintsIn(join(fileURLToPath(new URL('..', import.meta.url)), 'blueprints')),
29
+ ...(values ? { values } : {}),
30
+ })
31
+ }
32
+
33
+ export interface App {
34
+ readonly root: Context
35
+ readonly url: string
36
+ stop(): Promise<void>
37
+ }
38
+
39
+ /** The app: `instance` first (where it lives, chosen at run time), then the manifest's rows in order. */
40
+ export async function createApp(
41
+ chosen: AppInstance,
42
+ options: { values?: Readonly<Record<string, ParameterValue>> } = {},
43
+ ): Promise<App> {
44
+ const manifest = readManifest(options.values)
45
+ const root = new Context()
46
+ const first = root.plugin(instance, chosen)
47
+ await first.await()
48
+ const fibers: Fiber[] = [
49
+ first,
50
+ ...(await compose(root, manifest, registry, {
51
+ server: { port: chosen.port.start, scan: chosen.port.scan ? 20 : 0 },
52
+ })),
53
+ ]
54
+ return {
55
+ root,
56
+ url: root.nodeServer.url,
57
+ async stop() {
58
+ for (const fiber of [...fibers].reverse()) await fiber.dispose()
59
+ },
60
+ }
61
+ }
@@ -0,0 +1,18 @@
1
+ import type { Context } from '@deepseek-ai/cordis'
2
+ import { Acryl } from '../plugins/acryl-router/src/index.ts'
3
+ import { aboutPage } from './about.tsx'
4
+
5
+ export const APP_NAME = '__APP_NAME__'
6
+
7
+ /** The app's own routes: an `App` mounted on the router. The mount is removed when this plugin is disposed. */
8
+ export const routes = {
9
+ name: 'routes',
10
+ inject: ['router'],
11
+ apply(ctx: Context) {
12
+ const app = new Acryl()
13
+ .get('/', (c) => c.json({ app: APP_NAME, ok: true }))
14
+ .get('/health', (c) => c.json({ ok: true }))
15
+ .get('/about', (c) => c.html(aboutPage()))
16
+ ctx.router.route('/', app)
17
+ },
18
+ }
@@ -0,0 +1,61 @@
1
+ import { join } from 'node:path'
2
+ import { fileURLToPath } from 'node:url'
3
+ import { Context, type Fiber } from '@deepseek-ai/cordis'
4
+ import * as nodeServer from './plugins/acryl-node-server/src/index.ts'
5
+ import * as router from './plugins/acryl-router/src/index.ts'
6
+ import { type AppInstance, instance } from './plugins/instance/index.ts'
7
+ import {
8
+ blueprintsIn,
9
+ compose,
10
+ loadManifest,
11
+ type ParameterValue,
12
+ } from './plugins/manifest/index.ts'
13
+ import { routes } from './routes.ts'
14
+
15
+ /** The plugins this app's code provides. `blend.yaml` chooses, orders and configures them. */
16
+ export const registry = { 'acryl-router': router, 'acryl-node-server': nodeServer, routes }
17
+
18
+ /** The manifest next to this app's source. */
19
+ export const MANIFEST = join(fileURLToPath(new URL('..', import.meta.url)), 'blend.yaml')
20
+
21
+ /**
22
+ * The app's manifest, resolved. A Blend finds its Blueprint in `blueprints/<id>.yaml`; an app that is itself a Blueprint never looks.
23
+ * `createApp` and the tests read it the same way.
24
+ */
25
+ export function readManifest(values?: Readonly<Record<string, ParameterValue>>) {
26
+ return loadManifest(MANIFEST, {
27
+ known: Object.keys(registry),
28
+ getBlueprint: blueprintsIn(join(fileURLToPath(new URL('..', import.meta.url)), 'blueprints')),
29
+ ...(values ? { values } : {}),
30
+ })
31
+ }
32
+
33
+ export interface App {
34
+ readonly root: Context
35
+ readonly url: string
36
+ stop(): Promise<void>
37
+ }
38
+
39
+ /** The app: `instance` first (where it lives, chosen at run time), then the manifest's rows in order. */
40
+ export async function createApp(
41
+ chosen: AppInstance,
42
+ options: { values?: Readonly<Record<string, ParameterValue>> } = {},
43
+ ): Promise<App> {
44
+ const manifest = readManifest(options.values)
45
+ const root = new Context()
46
+ const first = root.plugin(instance, chosen)
47
+ await first.await()
48
+ const fibers: Fiber[] = [
49
+ first,
50
+ ...(await compose(root, manifest, registry, {
51
+ server: { port: chosen.port.start, scan: chosen.port.scan ? 20 : 0 },
52
+ })),
53
+ ]
54
+ return {
55
+ root,
56
+ url: root.nodeServer.url,
57
+ async stop() {
58
+ for (const fiber of [...fibers].reverse()) await fiber.dispose()
59
+ },
60
+ }
61
+ }