@acryldev/blends 1.7.0 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/docs/framework/LICENSE +0 -23
- package/docs/framework/README.md +0 -70
- package/docs/framework/agents/index.md +0 -59
- package/docs/framework/api/acryl.md +0 -247
- package/docs/framework/api/context.md +0 -478
- package/docs/framework/api/exception.md +0 -80
- package/docs/framework/api/index.md +0 -12
- package/docs/framework/api/presets.md +0 -62
- package/docs/framework/api/request.md +0 -396
- package/docs/framework/api/routing.md +0 -303
- package/docs/framework/api/summary.md +0 -143
- package/docs/framework/concepts/benchmarks.md +0 -26
- package/docs/framework/concepts/developer-experience.md +0 -5
- package/docs/framework/concepts/middleware.md +0 -21
- package/docs/framework/concepts/motivation.md +0 -14
- package/docs/framework/concepts/routers.md +0 -63
- package/docs/framework/concepts/stacks.md +0 -235
- package/docs/framework/concepts/web-standard.md +0 -27
- package/docs/framework/cordis/acryl-in-a-cordis-app.md +0 -160
- package/docs/framework/cordis/concepts.md +0 -105
- package/docs/framework/cordis/middleware.md +0 -8
- package/docs/framework/cordis/migration-from-0-3.md +0 -111
- package/docs/framework/cordis/migration-from-0-4.md +0 -14
- package/docs/framework/cordis/migration-from-dsh-webserver.md +0 -109
- package/docs/framework/cordis/migration-to-1-0.md +0 -46
- package/docs/framework/cordis/mounting.md +0 -85
- package/docs/framework/cordis/node-server.md +0 -100
- package/docs/framework/cordis/plugin-lifecycle.md +0 -111
- package/docs/framework/cordis/surfaces.md +0 -71
- package/docs/framework/cordis/transport-and-cancellation.md +0 -57
- package/docs/framework/cordis/validation.md +0 -135
- package/docs/framework/getting-started/basic.md +0 -201
- package/docs/framework/getting-started/bun.md +0 -219
- package/docs/framework/getting-started/deploy.md +0 -133
- package/docs/framework/getting-started/desktop.md +0 -80
- package/docs/framework/getting-started/nodejs.md +0 -365
- package/docs/framework/getting-started/other-runtimes.md +0 -30
- package/docs/framework/guides/best-practices.md +0 -231
- package/docs/framework/guides/bring-your-own-tool.md +0 -218
- package/docs/framework/guides/client-modules.md +0 -210
- package/docs/framework/guides/create-acrylblends.md +0 -143
- package/docs/framework/guides/data.md +0 -314
- package/docs/framework/guides/examples.md +0 -3
- package/docs/framework/guides/faq.md +0 -19
- package/docs/framework/guides/forms-and-sessions.md +0 -235
- package/docs/framework/guides/helpers.md +0 -33
- package/docs/framework/guides/jsx-dom.md +0 -301
- package/docs/framework/guides/jsx.md +0 -487
- package/docs/framework/guides/middleware.md +0 -253
- package/docs/framework/guides/production.md +0 -80
- package/docs/framework/guides/rpc.md +0 -878
- package/docs/framework/guides/testing.md +0 -133
- package/docs/framework/guides/validation.md +0 -470
- package/docs/framework/helpers/accepts.md +0 -60
- package/docs/framework/helpers/adapter.md +0 -57
- package/docs/framework/helpers/conninfo.md +0 -77
- package/docs/framework/helpers/cookie.md +0 -232
- package/docs/framework/helpers/css.md +0 -282
- package/docs/framework/helpers/dev.md +0 -64
- package/docs/framework/helpers/factory.md +0 -180
- package/docs/framework/helpers/html.md +0 -123
- package/docs/framework/helpers/jwt.md +0 -184
- package/docs/framework/helpers/proxy.md +0 -115
- package/docs/framework/helpers/route.md +0 -143
- package/docs/framework/helpers/ssg.md +0 -390
- package/docs/framework/helpers/streaming.md +0 -224
- package/docs/framework/helpers/testing.md +0 -118
- package/docs/framework/helpers/websocket.md +0 -208
- package/docs/framework/middleware/builtin/basic-auth.md +0 -165
- package/docs/framework/middleware/builtin/bearer-auth.md +0 -138
- package/docs/framework/middleware/builtin/body-limit.md +0 -71
- package/docs/framework/middleware/builtin/cache.md +0 -99
- package/docs/framework/middleware/builtin/combine.md +0 -94
- package/docs/framework/middleware/builtin/compress.md +0 -59
- package/docs/framework/middleware/builtin/context-storage.md +0 -74
- package/docs/framework/middleware/builtin/cors.md +0 -134
- package/docs/framework/middleware/builtin/csrf.md +0 -105
- package/docs/framework/middleware/builtin/etag.md +0 -54
- package/docs/framework/middleware/builtin/ip-restriction.md +0 -69
- package/docs/framework/middleware/builtin/jsx-renderer.md +0 -283
- package/docs/framework/middleware/builtin/jwk.md +0 -192
- package/docs/framework/middleware/builtin/jwt.md +0 -145
- package/docs/framework/middleware/builtin/language.md +0 -232
- package/docs/framework/middleware/builtin/logger.md +0 -74
- package/docs/framework/middleware/builtin/loopback-only.md +0 -31
- package/docs/framework/middleware/builtin/method-not-allowed.md +0 -48
- package/docs/framework/middleware/builtin/method-override.md +0 -80
- package/docs/framework/middleware/builtin/mount.md +0 -103
- package/docs/framework/middleware/builtin/pretty-json.md +0 -53
- package/docs/framework/middleware/builtin/request-id.md +0 -87
- package/docs/framework/middleware/builtin/secure-headers.md +0 -247
- package/docs/framework/middleware/builtin/timeout.md +0 -98
- package/docs/framework/middleware/builtin/timing.md +0 -100
- package/docs/framework/middleware/builtin/trailing-slash.md +0 -74
- package/docs/framework/middleware/third-party.md +0 -4
- package/docs/framework/workshop/README.md +0 -294
- package/docs/framework/workshop/facilitator.md +0 -101
- package/plugins/agent/LICENSE +0 -21
- package/plugins/agent/agent.ts +0 -229
- package/plugins/agent/index.ts +0 -20
- package/plugins/agent/memory.ts +0 -24
- package/plugins/agent/model.ts +0 -94
- package/plugins/agent/package.json +0 -41
- package/plugins/agent/plugin.json +0 -13
- package/plugins/agent/tools.ts +0 -67
- package/plugins/agent-panel/LICENSE +0 -21
- package/plugins/agent-panel/client/describe.ts +0 -101
- package/plugins/agent-panel/client/driver-pick.ts +0 -22
- package/plugins/agent-panel/client/frame.ts +0 -51
- package/plugins/agent-panel/client/main.ts +0 -707
- package/plugins/agent-panel/client/markdown.ts +0 -219
- package/plugins/agent-panel/headless.ts +0 -220
- package/plugins/agent-panel/index.ts +0 -523
- package/plugins/agent-panel/launch.ts +0 -67
- package/plugins/agent-panel/mount.ts +0 -27
- package/plugins/agent-panel/package.json +0 -69
- package/plugins/agent-panel/plugin.json +0 -28
- package/plugins/agent-panel/registry.ts +0 -17
- package/plugins/agent-panel/visitors.ts +0 -231
- package/plugins/app-settings/LICENSE +0 -21
- package/plugins/app-settings/index.ts +0 -270
- package/plugins/app-settings/merge.ts +0 -79
- package/plugins/app-settings/package.json +0 -45
- package/plugins/app-settings/plugin.json +0 -16
- package/plugins/builder/LICENSE +0 -21
- package/plugins/builder/index.ts +0 -171
- package/plugins/builder/package.json +0 -52
- package/plugins/builder/plugin.json +0 -17
- package/plugins/builder/script.ts +0 -158
- package/plugins/db/LICENSE +0 -47
- package/plugins/db/package.json +0 -67
- package/plugins/db/plugin.json +0 -25
- package/plugins/db/src/conformance.ts +0 -224
- package/plugins/db/src/cordis.ts +0 -13
- package/plugins/db/src/facade/database.ts +0 -41
- package/plugins/db/src/facade/migrations.ts +0 -50
- package/plugins/db/src/facade/schema.ts +0 -9
- package/plugins/db/src/index.ts +0 -19
- package/plugins/db/src/migration-files.ts +0 -31
- package/plugins/db-sqlite/LICENSE +0 -47
- package/plugins/db-sqlite/package.json +0 -89
- package/plugins/db-sqlite/plugin.json +0 -29
- package/plugins/db-sqlite/src/facade/node.ts +0 -199
- package/plugins/db-sqlite/src/index.ts +0 -95
- package/plugins/db-sqlite/src/open.ts +0 -61
- package/plugins/desktop-shell/LICENSE +0 -21
- package/plugins/desktop-shell/app-page.ts +0 -151
- package/plugins/desktop-shell/app-root.ts +0 -19
- package/plugins/desktop-shell/assets/acrylblends-logo.png +0 -0
- package/plugins/desktop-shell/attach.ts +0 -72
- package/plugins/desktop-shell/bin.ts +0 -5
- package/plugins/desktop-shell/brand.ts +0 -166
- package/plugins/desktop-shell/door-shell.ts +0 -385
- package/plugins/desktop-shell/frame.ts +0 -317
- package/plugins/desktop-shell/git.ts +0 -44
- package/plugins/desktop-shell/host-supervisor.ts +0 -63
- package/plugins/desktop-shell/launch.ts +0 -106
- package/plugins/desktop-shell/main.ts +0 -545
- package/plugins/desktop-shell/menu.ts +0 -60
- package/plugins/desktop-shell/package.json +0 -58
- package/plugins/desktop-shell/plugin.json +0 -20
- package/plugins/desktop-shell/preload.cjs +0 -8
- package/plugins/desktop-shell/product.ts +0 -164
- package/plugins/desktop-shell/shutdown.ts +0 -177
- package/plugins/desktop-shell/update-menu.ts +0 -126
- package/plugins/desktop-shell/updater.ts +0 -228
- package/plugins/desktop-shell/user-data.ts +0 -38
- package/plugins/desktop-shell/watch-host.d.mts +0 -10
- package/plugins/desktop-shell/watch-host.mjs +0 -130
- package/plugins/desktop-shell/window.ts +0 -119
- package/plugins/desktop-web/LICENSE +0 -21
- package/plugins/desktop-web/app-root.ts +0 -12
- package/plugins/desktop-web/launch.ts +0 -54
- package/plugins/desktop-web/main.ts +0 -108
- package/plugins/desktop-web/package.json +0 -49
- package/plugins/desktop-web/plugin.json +0 -21
- package/plugins/desktop-web/shutdown.ts +0 -177
- package/plugins/desktop-web/user-data.ts +0 -38
- package/plugins/desktop-web/window.ts +0 -29
- package/plugins/door/LICENSE +0 -47
- package/plugins/door/package.json +0 -116
- package/plugins/door/plugin.json +0 -39
- package/plugins/door/src/cli/acryl.ts +0 -335
- package/plugins/door/src/host/api.ts +0 -9
- package/plugins/door/src/host/audit.ts +0 -64
- package/plugins/door/src/host/channel.ts +0 -407
- package/plugins/door/src/host/chat-tools.ts +0 -76
- package/plugins/door/src/host/door-file.ts +0 -99
- package/plugins/door/src/host/door.ts +0 -492
- package/plugins/door/src/host/http.ts +0 -80
- package/plugins/door/src/host/mcp-routes.ts +0 -83
- package/plugins/door/src/host/operator-routes.ts +0 -58
- package/plugins/door/src/host/page-routes.ts +0 -69
- package/plugins/door/src/host/page-socket.ts +0 -88
- package/plugins/door/src/host/shell.ts +0 -147
- package/plugins/door/src/host/shim.ts +0 -125
- package/plugins/door/src/host/verbs.ts +0 -160
- package/plugins/door/src/index.ts +0 -337
- package/plugins/door/src/page/api.ts +0 -9
- package/plugins/door/src/page/base.ts +0 -32
- package/plugins/door/src/page/channel.ts +0 -209
- package/plugins/door/src/page/driver/accessibility.ts +0 -177
- package/plugins/door/src/page/driver/actions.ts +0 -207
- package/plugins/door/src/page/driver/driver.ts +0 -216
- package/plugins/door/src/page/driver/ref-table.ts +0 -78
- package/plugins/door/src/page/driver/sensitivity.ts +0 -85
- package/plugins/door/src/page/driver/snapshot.ts +0 -135
- package/plugins/door/src/page/index.ts +0 -100
- package/plugins/door/src/page/indicator.ts +0 -80
- package/plugins/door/src/page/main.ts +0 -7
- package/plugins/door/src/page/outline.ts +0 -56
- package/plugins/door/src/page/protocol.ts +0 -233
- package/plugins/door/src/page/snapshot-text.ts +0 -19
- package/plugins/door/src/page/socket-source.ts +0 -75
- package/plugins/door/src/page/user-input.ts +0 -24
- package/plugins/door/src/shell/protocol.ts +0 -133
- package/plugins/driver-acp/LICENSE +0 -21
- package/plugins/driver-acp/README.md +0 -53
- package/plugins/driver-acp/chat.ts +0 -258
- package/plugins/driver-acp/connection.ts +0 -239
- package/plugins/driver-acp/index.ts +0 -67
- package/plugins/driver-acp/package.json +0 -52
- package/plugins/driver-acp/plugin.json +0 -15
- package/plugins/driver-acp/provenance.json +0 -20
- package/plugins/driver-pty/LICENSE +0 -21
- package/plugins/driver-pty/client/terminal.ts +0 -191
- package/plugins/driver-pty/client/vendor/LICENSE +0 -21
- package/plugins/driver-pty/client/vendor/LICENSE-addon-fit +0 -19
- package/plugins/driver-pty/client/vendor/VERSION +0 -4
- package/plugins/driver-pty/client/vendor/addon-fit.d.mts +0 -6
- package/plugins/driver-pty/client/vendor/addon-fit.mjs +0 -18
- package/plugins/driver-pty/client/vendor/xterm-css.d.mts +0 -2
- package/plugins/driver-pty/client/vendor/xterm-css.mjs +0 -2
- package/plugins/driver-pty/client/vendor/xterm.d.mts +0 -17
- package/plugins/driver-pty/client/vendor/xterm.mjs +0 -53
- package/plugins/driver-pty/index.ts +0 -280
- package/plugins/driver-pty/package.json +0 -55
- package/plugins/driver-pty/plugin.json +0 -16
- package/plugins/driver-pty/spawn.ts +0 -74
- package/plugins/driver-pty/terminal.ts +0 -86
- package/plugins/drivers/LICENSE +0 -21
- package/plugins/drivers/index.ts +0 -75
- package/plugins/drivers/package.json +0 -37
- package/plugins/drivers/plugin.json +0 -11
- package/plugins/extensions/LICENSE +0 -21
- package/plugins/extensions/browser.ts +0 -100
- package/plugins/extensions/index.ts +0 -991
- package/plugins/extensions/ledger.ts +0 -39
- package/plugins/extensions/package.json +0 -48
- package/plugins/extensions/plugin-store.ts +0 -27
- package/plugins/extensions/plugin.json +0 -15
- package/plugins/extensions/resolve.ts +0 -169
- package/plugins/extensions/routes.ts +0 -92
- package/plugins/extensions/stage.ts +0 -82
- package/plugins/feedback/LICENSE +0 -21
- package/plugins/feedback/client.d.ts +0 -22
- package/plugins/feedback/client.js +0 -471
- package/plugins/feedback/index.ts +0 -143
- package/plugins/feedback/package.json +0 -44
- package/plugins/feedback/plugin.json +0 -14
- package/plugins/feedback/store.ts +0 -307
- package/plugins/home/LICENSE +0 -21
- package/plugins/home/index.ts +0 -124
- package/plugins/home/package.json +0 -41
- package/plugins/home/plugin.json +0 -14
- package/plugins/inspect/LICENSE +0 -21
- package/plugins/inspect/package.json +0 -84
- package/plugins/inspect/plugin.json +0 -24
- package/plugins/inspect/src/index.ts +0 -3
- package/plugins/inspect/src/report.ts +0 -131
- package/plugins/inspect/src/service.ts +0 -68
- package/plugins/instance/LICENSE +0 -21
- package/plugins/instance/archive.ts +0 -395
- package/plugins/instance/bundle-overlay.ts +0 -10
- package/plugins/instance/bundle.ts +0 -230
- package/plugins/instance/home.ts +0 -395
- package/plugins/instance/index.ts +0 -284
- package/plugins/instance/package.json +0 -61
- package/plugins/instance/plugin.json +0 -16
- package/plugins/instance/storage.ts +0 -463
- package/plugins/kv/LICENSE +0 -47
- package/plugins/kv/package.json +0 -67
- package/plugins/kv/plugin.json +0 -26
- package/plugins/kv/src/check.ts +0 -58
- package/plugins/kv/src/conformance.ts +0 -226
- package/plugins/kv/src/copy.ts +0 -39
- package/plugins/kv/src/cordis.ts +0 -13
- package/plugins/kv/src/index.ts +0 -14
- package/plugins/kv/src/kv.ts +0 -37
- package/plugins/kv-db/LICENSE +0 -47
- package/plugins/kv-db/package.json +0 -91
- package/plugins/kv-db/plugin.json +0 -31
- package/plugins/kv-db/src/index.ts +0 -37
- package/plugins/kv-db/src/open.ts +0 -80
- package/plugins/kv-json/LICENSE +0 -47
- package/plugins/kv-json/package.json +0 -89
- package/plugins/kv-json/plugin.json +0 -29
- package/plugins/kv-json/src/index.ts +0 -78
- package/plugins/kv-json/src/open.ts +0 -249
- package/plugins/manifest/LICENSE +0 -21
- package/plugins/manifest/app-plugins.ts +0 -86
- package/plugins/manifest/index.ts +0 -645
- package/plugins/manifest/lock.ts +0 -115
- package/plugins/manifest/package.json +0 -57
- package/plugins/manifest/plugin.json +0 -19
- package/plugins/manifest/snapshot.ts +0 -275
- package/plugins/manifest/upgrade-cli.ts +0 -70
- package/plugins/manifest/upgrade.ts +0 -97
- package/plugins/node-server/LICENSE +0 -47
- package/plugins/node-server/package.json +0 -94
- package/plugins/node-server/plugin.json +0 -32
- package/plugins/node-server/src/adapter/conninfo.ts +0 -23
- package/plugins/node-server/src/adapter/early-hints.ts +0 -55
- package/plugins/node-server/src/adapter/error.ts +0 -11
- package/plugins/node-server/src/adapter/headers.ts +0 -249
- package/plugins/node-server/src/adapter/index.ts +0 -6
- package/plugins/node-server/src/adapter/listener.ts +0 -549
- package/plugins/node-server/src/adapter/raw.ts +0 -18
- package/plugins/node-server/src/adapter/request.ts +0 -798
- package/plugins/node-server/src/adapter/response.ts +0 -186
- package/plugins/node-server/src/adapter/serve-static.ts +0 -238
- package/plugins/node-server/src/adapter/server.ts +0 -59
- package/plugins/node-server/src/adapter/types.ts +0 -94
- package/plugins/node-server/src/adapter/url.ts +0 -42
- package/plugins/node-server/src/adapter/utils/response/constants.ts +0 -1
- package/plugins/node-server/src/adapter/utils/response.ts +0 -4
- package/plugins/node-server/src/adapter/utils/stream.ts +0 -88
- package/plugins/node-server/src/adapter/utils.ts +0 -96
- package/plugins/node-server/src/adapter/websocket-types.ts +0 -49
- package/plugins/node-server/src/adapter/websocket.ts +0 -409
- package/plugins/node-server/src/client-modules.ts +0 -300
- package/plugins/node-server/src/index.ts +0 -440
- package/plugins/node-server/src/register.ts +0 -65
- package/plugins/node-server/src/test-websocket.ts +0 -110
- package/plugins/node-server/src/transpile.ts +0 -139
- package/plugins/node-server/src/upgrade-hub.ts +0 -152
- package/plugins/openai/LICENSE +0 -21
- package/plugins/openai/index.ts +0 -218
- package/plugins/openai/package.json +0 -43
- package/plugins/openai/plugin.json +0 -14
- package/plugins/openai/prompt.ts +0 -60
- package/plugins/page/package.json +0 -51
- package/plugins/page/plugin.json +0 -16
- package/plugins/page/src/favicon.ts +0 -19
- package/plugins/page/src/index.ts +0 -168
- package/plugins/plugin-share/LICENSE +0 -21
- package/plugins/plugin-share/README.md +0 -86
- package/plugins/plugin-share/index.ts +0 -791
- package/plugins/plugin-share/native.ts +0 -290
- package/plugins/plugin-share/package.json +0 -54
- package/plugins/plugin-share/package.ts +0 -186
- package/plugins/plugin-share/plugin.json +0 -19
- package/plugins/plugin-share/publish.ts +0 -79
- package/plugins/plugin-share/pull-check.ts +0 -142
- package/plugins/plugin-share/pull-list.ts +0 -71
- package/plugins/plugin-share/pulled-records.ts +0 -70
- package/plugins/router/LICENSE +0 -47
- package/plugins/router/package.json +0 -118
- package/plugins/router/plugin.json +0 -31
- package/plugins/router/src/browser/client.ts +0 -3
- package/plugins/router/src/browser/jsx-dom.ts +0 -9
- package/plugins/router/src/browser/read-sse.ts +0 -3
- package/plugins/router/src/client.ts +0 -2
- package/plugins/router/src/connection.ts +0 -42
- package/plugins/router/src/core/adapter/aws-lambda/conninfo.ts +0 -73
- package/plugins/router/src/core/adapter/aws-lambda/handler.ts +0 -682
- package/plugins/router/src/core/adapter/aws-lambda/index.ts +0 -14
- package/plugins/router/src/core/adapter/aws-lambda/types.ts +0 -173
- package/plugins/router/src/core/adapter/bun/conninfo.ts +0 -43
- package/plugins/router/src/core/adapter/bun/index.ts +0 -11
- package/plugins/router/src/core/adapter/bun/serve-static.ts +0 -32
- package/plugins/router/src/core/adapter/bun/server.ts +0 -14
- package/plugins/router/src/core/adapter/bun/ssg.ts +0 -26
- package/plugins/router/src/core/adapter/bun/websocket.ts +0 -113
- package/plugins/router/src/core/adapter/cloudflare-pages/conninfo.ts +0 -26
- package/plugins/router/src/core/adapter/cloudflare-pages/handler.ts +0 -122
- package/plugins/router/src/core/adapter/cloudflare-pages/index.ts +0 -11
- package/plugins/router/src/core/adapter/cloudflare-workers/conninfo.ts +0 -7
- package/plugins/router/src/core/adapter/cloudflare-workers/index.ts +0 -8
- package/plugins/router/src/core/adapter/cloudflare-workers/serve-static-module.ts +0 -12
- package/plugins/router/src/core/adapter/cloudflare-workers/serve-static.ts +0 -41
- package/plugins/router/src/core/adapter/cloudflare-workers/utils.ts +0 -50
- package/plugins/router/src/core/adapter/cloudflare-workers/websocket.ts +0 -52
- package/plugins/router/src/core/adapter/lambda-edge/conninfo.ts +0 -15
- package/plugins/router/src/core/adapter/lambda-edge/handler.ts +0 -239
- package/plugins/router/src/core/adapter/lambda-edge/index.ts +0 -14
- package/plugins/router/src/core/adapter/netlify/conninfo.ts +0 -57
- package/plugins/router/src/core/adapter/netlify/handler.ts +0 -10
- package/plugins/router/src/core/adapter/netlify/index.ts +0 -6
- package/plugins/router/src/core/adapter/netlify/mod.ts +0 -2
- package/plugins/router/src/core/adapter/service-worker/handler.ts +0 -37
- package/plugins/router/src/core/adapter/service-worker/index.ts +0 -36
- package/plugins/router/src/core/adapter/service-worker/types.ts +0 -14
- package/plugins/router/src/core/adapter/vercel/conninfo.ts +0 -8
- package/plugins/router/src/core/adapter/vercel/handler.ts +0 -8
- package/plugins/router/src/core/adapter/vercel/index.ts +0 -7
- package/plugins/router/src/core/app-base.ts +0 -544
- package/plugins/router/src/core/app.ts +0 -34
- package/plugins/router/src/core/client/client.ts +0 -249
- package/plugins/router/src/core/client/fetch-result-please.ts +0 -95
- package/plugins/router/src/core/client/index.ts +0 -17
- package/plugins/router/src/core/client/types.ts +0 -393
- package/plugins/router/src/core/client/utils.ts +0 -117
- package/plugins/router/src/core/compose.ts +0 -73
- package/plugins/router/src/core/context.ts +0 -781
- package/plugins/router/src/core/helper/accepts/accepts.ts +0 -96
- package/plugins/router/src/core/helper/accepts/index.ts +0 -6
- package/plugins/router/src/core/helper/adapter/index.ts +0 -90
- package/plugins/router/src/core/helper/conninfo/index.ts +0 -6
- package/plugins/router/src/core/helper/conninfo/types.ts +0 -45
- package/plugins/router/src/core/helper/cookie/index.ts +0 -146
- package/plugins/router/src/core/helper/css/common.ts +0 -337
- package/plugins/router/src/core/helper/css/index.ts +0 -262
- package/plugins/router/src/core/helper/dev/index.ts +0 -79
- package/plugins/router/src/core/helper/factory/index.ts +0 -375
- package/plugins/router/src/core/helper/html/index.ts +0 -57
- package/plugins/router/src/core/helper/proxy/index.ts +0 -203
- package/plugins/router/src/core/helper/route/index.ts +0 -144
- package/plugins/router/src/core/helper/ssg/index.ts +0 -14
- package/plugins/router/src/core/helper/ssg/middleware.ts +0 -83
- package/plugins/router/src/core/helper/ssg/plugins.ts +0 -72
- package/plugins/router/src/core/helper/ssg/ssg.ts +0 -471
- package/plugins/router/src/core/helper/ssg/utils.ts +0 -118
- package/plugins/router/src/core/helper/streaming/index.ts +0 -9
- package/plugins/router/src/core/helper/streaming/sse.ts +0 -101
- package/plugins/router/src/core/helper/streaming/stream.ts +0 -45
- package/plugins/router/src/core/helper/streaming/text.ts +0 -15
- package/plugins/router/src/core/helper/streaming/utils.ts +0 -11
- package/plugins/router/src/core/helper/testing/index.ts +0 -28
- package/plugins/router/src/core/helper/websocket/index.ts +0 -146
- package/plugins/router/src/core/http-exception.ts +0 -77
- package/plugins/router/src/core/index.ts +0 -53
- package/plugins/router/src/core/jsx/base.ts +0 -490
- package/plugins/router/src/core/jsx/children.ts +0 -20
- package/plugins/router/src/core/jsx/components.ts +0 -257
- package/plugins/router/src/core/jsx/constants.ts +0 -6
- package/plugins/router/src/core/jsx/context.ts +0 -266
- package/plugins/router/src/core/jsx/dom/client.ts +0 -89
- package/plugins/router/src/core/jsx/dom/components.ts +0 -39
- package/plugins/router/src/core/jsx/dom/context.ts +0 -52
- package/plugins/router/src/core/jsx/dom/css.ts +0 -263
- package/plugins/router/src/core/jsx/dom/hooks/index.ts +0 -91
- package/plugins/router/src/core/jsx/dom/index.ts +0 -170
- package/plugins/router/src/core/jsx/dom/intrinsic-element/components.ts +0 -438
- package/plugins/router/src/core/jsx/dom/jsx-dev-runtime.ts +0 -23
- package/plugins/router/src/core/jsx/dom/jsx-runtime.ts +0 -8
- package/plugins/router/src/core/jsx/dom/render.ts +0 -879
- package/plugins/router/src/core/jsx/dom/server.ts +0 -76
- package/plugins/router/src/core/jsx/dom/utils.ts +0 -7
- package/plugins/router/src/core/jsx/hooks/index.ts +0 -437
- package/plugins/router/src/core/jsx/index.ts +0 -115
- package/plugins/router/src/core/jsx/intrinsic-element/common.ts +0 -23
- package/plugins/router/src/core/jsx/intrinsic-element/components.ts +0 -210
- package/plugins/router/src/core/jsx/intrinsic-elements.ts +0 -938
- package/plugins/router/src/core/jsx/jsx-dev-runtime.ts +0 -26
- package/plugins/router/src/core/jsx/jsx-runtime.ts +0 -51
- package/plugins/router/src/core/jsx/streaming.ts +0 -231
- package/plugins/router/src/core/jsx/types.ts +0 -41
- package/plugins/router/src/core/jsx/utils.ts +0 -202
- package/plugins/router/src/core/middleware/basic-auth/index.ts +0 -152
- package/plugins/router/src/core/middleware/bearer-auth/index.ts +0 -220
- package/plugins/router/src/core/middleware/body-limit/index.ts +0 -110
- package/plugins/router/src/core/middleware/cache/index.ts +0 -323
- package/plugins/router/src/core/middleware/combine/index.ts +0 -171
- package/plugins/router/src/core/middleware/compress/index.ts +0 -142
- package/plugins/router/src/core/middleware/context-storage/index.ts +0 -58
- package/plugins/router/src/core/middleware/cors/index.ts +0 -163
- package/plugins/router/src/core/middleware/csrf/index.ts +0 -150
- package/plugins/router/src/core/middleware/etag/digest.ts +0 -95
- package/plugins/router/src/core/middleware/etag/index.ts +0 -135
- package/plugins/router/src/core/middleware/ip-restriction/index.ts +0 -278
- package/plugins/router/src/core/middleware/jsx-renderer/index.ts +0 -162
- package/plugins/router/src/core/middleware/jwk/index.ts +0 -1
- package/plugins/router/src/core/middleware/jwk/jwk.ts +0 -196
- package/plugins/router/src/core/middleware/jwt/index.ts +0 -9
- package/plugins/router/src/core/middleware/jwt/jwt.ts +0 -190
- package/plugins/router/src/core/middleware/language/index.ts +0 -12
- package/plugins/router/src/core/middleware/language/language.ts +0 -314
- package/plugins/router/src/core/middleware/logger/index.ts +0 -95
- package/plugins/router/src/core/middleware/method-not-allowed/index.ts +0 -141
- package/plugins/router/src/core/middleware/method-override/index.ts +0 -147
- package/plugins/router/src/core/middleware/mount/index.ts +0 -108
- package/plugins/router/src/core/middleware/powered-by/index.ts +0 -35
- package/plugins/router/src/core/middleware/pretty-json/index.ts +0 -67
- package/plugins/router/src/core/middleware/request-id/index.ts +0 -7
- package/plugins/router/src/core/middleware/request-id/request-id.ts +0 -59
- package/plugins/router/src/core/middleware/secure-headers/index.ts +0 -8
- package/plugins/router/src/core/middleware/secure-headers/permissions-policy.ts +0 -101
- package/plugins/router/src/core/middleware/secure-headers/secure-headers.ts +0 -340
- package/plugins/router/src/core/middleware/serve-static/index.ts +0 -135
- package/plugins/router/src/core/middleware/serve-static/path.ts +0 -25
- package/plugins/router/src/core/middleware/timeout/index.ts +0 -58
- package/plugins/router/src/core/middleware/timing/index.ts +0 -8
- package/plugins/router/src/core/middleware/timing/timing.ts +0 -256
- package/plugins/router/src/core/middleware/trailing-slash/index.ts +0 -156
- package/plugins/router/src/core/preset/quick.ts +0 -24
- package/plugins/router/src/core/preset/tiny.ts +0 -20
- package/plugins/router/src/core/request/constants.ts +0 -1
- package/plugins/router/src/core/request.ts +0 -502
- package/plugins/router/src/core/router/linear-router/index.ts +0 -6
- package/plugins/router/src/core/router/linear-router/router.ts +0 -152
- package/plugins/router/src/core/router/pattern-router/index.ts +0 -6
- package/plugins/router/src/core/router/pattern-router/router.ts +0 -54
- package/plugins/router/src/core/router/reg-exp-router/index.ts +0 -7
- package/plugins/router/src/core/router/reg-exp-router/matcher.ts +0 -33
- package/plugins/router/src/core/router/reg-exp-router/node.ts +0 -170
- package/plugins/router/src/core/router/reg-exp-router/prepared-router.ts +0 -165
- package/plugins/router/src/core/router/reg-exp-router/router.ts +0 -174
- package/plugins/router/src/core/router/reg-exp-router/trie.ts +0 -84
- package/plugins/router/src/core/router/smart-router/index.ts +0 -6
- package/plugins/router/src/core/router/smart-router/router.ts +0 -70
- package/plugins/router/src/core/router/trie-router/index.ts +0 -6
- package/plugins/router/src/core/router/trie-router/node.ts +0 -221
- package/plugins/router/src/core/router/trie-router/router.ts +0 -18
- package/plugins/router/src/core/router/utils.ts +0 -1
- package/plugins/router/src/core/router.ts +0 -103
- package/plugins/router/src/core/types.ts +0 -2782
- package/plugins/router/src/core/utils/accept.ts +0 -268
- package/plugins/router/src/core/utils/basic-auth.ts +0 -26
- package/plugins/router/src/core/utils/body.ts +0 -263
- package/plugins/router/src/core/utils/buffer.ts +0 -117
- package/plugins/router/src/core/utils/color.ts +0 -56
- package/plugins/router/src/core/utils/compress.ts +0 -10
- package/plugins/router/src/core/utils/concurrent.ts +0 -55
- package/plugins/router/src/core/utils/constants.ts +0 -4
- package/plugins/router/src/core/utils/cookie.ts +0 -281
- package/plugins/router/src/core/utils/crypto.ts +0 -58
- package/plugins/router/src/core/utils/encode.ts +0 -34
- package/plugins/router/src/core/utils/filepath.ts +0 -60
- package/plugins/router/src/core/utils/handler.ts +0 -15
- package/plugins/router/src/core/utils/headers.ts +0 -355
- package/plugins/router/src/core/utils/html.ts +0 -182
- package/plugins/router/src/core/utils/http-status.ts +0 -72
- package/plugins/router/src/core/utils/ipaddr.ts +0 -374
- package/plugins/router/src/core/utils/jwt/index.ts +0 -7
- package/plugins/router/src/core/utils/jwt/jwa.ts +0 -38
- package/plugins/router/src/core/utils/jwt/jws.ts +0 -235
- package/plugins/router/src/core/utils/jwt/jwt.ts +0 -292
- package/plugins/router/src/core/utils/jwt/types.ts +0 -157
- package/plugins/router/src/core/utils/jwt/utf8.ts +0 -7
- package/plugins/router/src/core/utils/mime.ts +0 -94
- package/plugins/router/src/core/utils/stream.ts +0 -107
- package/plugins/router/src/core/utils/types.ts +0 -174
- package/plugins/router/src/core/utils/url.ts +0 -337
- package/plugins/router/src/core/validator/index.ts +0 -8
- package/plugins/router/src/core/validator/utils.ts +0 -69
- package/plugins/router/src/core/validator/validator.ts +0 -185
- package/plugins/router/src/helpers/index.ts +0 -17
- package/plugins/router/src/helpers/read-sse.ts +0 -111
- package/plugins/router/src/helpers/schema-validator.ts +0 -62
- package/plugins/router/src/index.ts +0 -6
- package/plugins/router/src/middleware/index.ts +0 -28
- package/plugins/router/src/middleware/loopback-only.ts +0 -183
- package/plugins/router/src/service.ts +0 -477
- package/plugins/router-http/LICENSE +0 -21
- package/plugins/router-http/package.json +0 -87
- package/plugins/router-http/plugin.json +0 -23
- package/plugins/router-http/src/bridge.ts +0 -54
- package/plugins/router-http/src/index.ts +0 -141
- package/plugins/router-http/src/serve.ts +0 -55
- package/plugins/sandbox/LICENSE +0 -21
- package/plugins/sandbox/index.ts +0 -150
- package/plugins/sandbox/package.json +0 -41
- package/plugins/sandbox/plugin.json +0 -13
- package/plugins/sandbox/runner.mjs +0 -18
- package/plugins/save/LICENSE +0 -21
- package/plugins/save/cli.ts +0 -19
- package/plugins/save/index.ts +0 -55
- package/plugins/save/package.json +0 -43
- package/plugins/save/plugin.json +0 -15
- package/plugins/save/share-cli.ts +0 -95
- package/plugins/save/share.ts +0 -193
- package/plugins/showcase/LICENSE +0 -21
- package/plugins/showcase/cards.ts +0 -162
- package/plugins/showcase/index.ts +0 -117
- package/plugins/showcase/package.json +0 -49
- package/plugins/showcase/plugin.json +0 -14
- package/plugins/state/LICENSE +0 -21
- package/plugins/state/package.json +0 -104
- package/plugins/state/plugin.json +0 -27
- package/plugins/state/src/cell.ts +0 -67
- package/plugins/state/src/client-source.ts +0 -244
- package/plugins/state/src/index.ts +0 -3
- package/plugins/state/src/service.ts +0 -146
- package/plugins/state/src/socket.ts +0 -96
- package/plugins/tasks/LICENSE +0 -21
- package/plugins/tasks/index.ts +0 -246
- package/plugins/tasks/package.json +0 -45
- package/plugins/tasks/plugin.json +0 -14
- package/plugins/tasks/store.ts +0 -86
- package/plugins/web-server/package.json +0 -52
- package/plugins/web-server/plugin.json +0 -20
- package/plugins/web-server/src/index.ts +0 -164
|
@@ -1,991 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The extensions service (`ctx.extensions`): install, update, remove and reload Cordis plugins while the app runs.
|
|
3
|
-
*
|
|
4
|
-
* Extracted from ACRYL (`the old acryl-extension-context copy's lib/install.js`, `stage.js`, `reconcile.js`), where an agent-written plugin
|
|
5
|
-
* installs, runs, updates and is removed live in the packaged app on macOS, Windows and Linux. ACRYL goes through pnpm and the Harness
|
|
6
|
-
* Loader; here an extension is a folder with an `index.ts` (or `.js`) that exports a Cordis plugin, mounted as a child fiber of this
|
|
7
|
-
* plugin. The rules carried over:
|
|
8
|
-
*
|
|
9
|
-
* - Check before changing anything; every answer is a structured result the agent can act on (`ok`, `stage`, `errors`, `next`).
|
|
10
|
-
* - Stage a content-hashed copy and import it fresh, so an update runs new code without a restart (`stage.ts`).
|
|
11
|
-
* - Import the new version while the old one still runs; dispose the old one only then. If the new one fails to start, mount the old
|
|
12
|
-
* one again (`restoredPrevious`), so a broken update never leaves the app without the version that worked.
|
|
13
|
-
* - Report the real fiber state: `active`, `pending` (with the services it waits for) or `failed` (with the real error).
|
|
14
|
-
* - One operation at a time, in order. A ledger line for every change (`ledger.ts`).
|
|
15
|
-
* - At startup, reinstall what was installed; install new folders only from sources trusted to `install`, and only list the rest
|
|
16
|
-
* (ACRYL's trust rule: code that arrived through a `git pull` must not run until someone asks for it).
|
|
17
|
-
*/
|
|
18
|
-
import {
|
|
19
|
-
existsSync,
|
|
20
|
-
mkdirSync,
|
|
21
|
-
readdirSync,
|
|
22
|
-
readFileSync,
|
|
23
|
-
renameSync,
|
|
24
|
-
statSync,
|
|
25
|
-
writeFileSync,
|
|
26
|
-
} from 'node:fs'
|
|
27
|
-
import { basename, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
28
|
-
import { pathToFileURL } from 'node:url'
|
|
29
|
-
import { isDeepStrictEqual } from 'node:util'
|
|
30
|
-
import type {} from '@acryldev/instance'
|
|
31
|
-
import type { Sandbox } from '@acryldev/sandbox'
|
|
32
|
-
import { type Context, type Fiber, Service } from '@deepseek-ai/cordis'
|
|
33
|
-
import { attachBrowserHalf } from './browser.ts'
|
|
34
|
-
import { appendLedger, type LedgerEntry, readLedger } from './ledger.ts'
|
|
35
|
-
import { type PluginStore, pluginVersion } from './plugin-store.ts'
|
|
36
|
-
import {
|
|
37
|
-
addedRoutes,
|
|
38
|
-
type FiberRoutesView,
|
|
39
|
-
routeClash,
|
|
40
|
-
type ServedRoute,
|
|
41
|
-
servedRoutes,
|
|
42
|
-
} from './routes.ts'
|
|
43
|
-
import { folderPluginStore } from './stage.ts'
|
|
44
|
-
|
|
45
|
-
/** A fiber's lifecycle state, by name (Cordis's own enum is a `const enum`, which does not exist at run time). */
|
|
46
|
-
export type ExtensionState = 'pending' | 'loading' | 'active' | 'failed' | 'disposed' | 'unloading'
|
|
47
|
-
const STATES: readonly ExtensionState[] = [
|
|
48
|
-
'pending',
|
|
49
|
-
'loading',
|
|
50
|
-
'active',
|
|
51
|
-
'failed',
|
|
52
|
-
'disposed',
|
|
53
|
-
'unloading',
|
|
54
|
-
]
|
|
55
|
-
|
|
56
|
-
/** Whether new folders found in a source are installed at startup, or only listed until someone installs them. */
|
|
57
|
-
/** `install`: installed at start; `list`: only reported; `ask`: an install waits for an explicit approve (or deny), recorded in the ledger. */
|
|
58
|
-
export type Trust = 'install' | 'list' | 'ask'
|
|
59
|
-
|
|
60
|
-
export interface ExtensionSource {
|
|
61
|
-
readonly dir: string
|
|
62
|
-
readonly trust: Trust
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** The library copies a plugins folder holds (`library.json`, written by `acrylblends add`): the app mounts them itself, so they are not extensions. */
|
|
66
|
-
function libraryCopies(dir: string): ReadonlySet<string> {
|
|
67
|
-
try {
|
|
68
|
-
const listed = (
|
|
69
|
-
JSON.parse(readFileSync(join(dir, 'library.json'), 'utf8')) as { plugins?: unknown }
|
|
70
|
-
).plugins
|
|
71
|
-
return new Set(
|
|
72
|
-
Array.isArray(listed)
|
|
73
|
-
? listed.filter((name): name is string => typeof name === 'string')
|
|
74
|
-
: [],
|
|
75
|
-
)
|
|
76
|
-
} catch {
|
|
77
|
-
return new Set()
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export interface ExtensionsConfig {
|
|
82
|
-
/** Where extension folders may come from. An app passes its `plugins/` folder (library copies listed in its `library.json` are skipped). Defaults to `<app home>/extensions`, trusted to install, for a service used without an app folder. */
|
|
83
|
-
sources?: readonly ExtensionSource[]
|
|
84
|
-
/** When true, every source that would install by itself asks for approval instead (`ask`). */
|
|
85
|
-
approval?: boolean
|
|
86
|
-
/**
|
|
87
|
-
* Production: the extension folders of the sources that install by themselves are started straight from where they are, once, and nothing can be installed, updated or
|
|
88
|
-
* removed afterwards (those calls are refused). No staging, no state file, no ledger, no approval queue are written or asked: the code that runs is the code in the folder,
|
|
89
|
-
* as it is deployed. One line says what was started, and a recorded extension whose folder is missing is a warning.
|
|
90
|
-
*/
|
|
91
|
-
readOnly?: boolean
|
|
92
|
-
/** Where the read-only start says what it did (the console by default). */
|
|
93
|
-
log?: (line: string) => void
|
|
94
|
-
/**
|
|
95
|
-
* Plugins of the sources that are switched off (Settings → Plugins writes this list into `blend.yaml`): they are not started, in development or
|
|
96
|
-
* production, until taken off the list. Their folders stay as they are.
|
|
97
|
-
*/
|
|
98
|
-
off?: readonly string[]
|
|
99
|
-
/**
|
|
100
|
-
* Plugins of the sources that `blend.yaml` mounts as rows of their own (the app composes them in its row order, with their row's config): they
|
|
101
|
-
* are not extensions, so they are neither found nor started here, and installing one is refused with that reason.
|
|
102
|
-
*/
|
|
103
|
-
rows?: readonly string[]
|
|
104
|
-
/** The path the app is mounted under (the frame's canvas, `/app`): a message names a route as the plugin wrote it, without it. */
|
|
105
|
-
routePrefix?: string
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const READ_ONLY =
|
|
109
|
-
'the extensions of this app are read-only here (production): nothing can be installed, updated, removed or approved while it runs'
|
|
110
|
-
|
|
111
|
-
export interface ExtensionInfo {
|
|
112
|
-
readonly name: string
|
|
113
|
-
readonly source: string
|
|
114
|
-
readonly version: string
|
|
115
|
-
readonly state: ExtensionState
|
|
116
|
-
/** Services an extension waits for, when it is pending. */
|
|
117
|
-
readonly missing: readonly string[]
|
|
118
|
-
/** The source folder no longer exists; the last installed version still runs. */
|
|
119
|
-
readonly stale: boolean
|
|
120
|
-
/** The routes its mount added, as the plugin wrote them (without the frame's prefix), so a surface can link to its pages. */
|
|
121
|
-
readonly routes: readonly { readonly method: string; readonly path: string }[]
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export type InstallResult =
|
|
125
|
-
| {
|
|
126
|
-
readonly ok: true
|
|
127
|
-
readonly name: string
|
|
128
|
-
readonly action: 'installed' | 'updated' | 'unchanged'
|
|
129
|
-
readonly state: ExtensionState
|
|
130
|
-
readonly missing: readonly string[]
|
|
131
|
-
readonly version: string
|
|
132
|
-
}
|
|
133
|
-
| {
|
|
134
|
-
readonly ok: false
|
|
135
|
-
/** check: before anything changed; import: loading the code; activate: starting it; verify: its own `check` failed. */
|
|
136
|
-
readonly stage: 'check' | 'import' | 'activate' | 'conflict' | 'verify' | 'approval'
|
|
137
|
-
readonly name?: string
|
|
138
|
-
readonly errors: readonly string[]
|
|
139
|
-
/** Present for an update: whether the version that was running is running again. */
|
|
140
|
-
readonly restoredPrevious?: boolean
|
|
141
|
-
readonly next: string
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export type RemoveResult =
|
|
145
|
-
| { readonly ok: true; readonly name: string }
|
|
146
|
-
| { readonly ok: false; readonly name: string; readonly errors: readonly string[] }
|
|
147
|
-
|
|
148
|
-
export interface StartupSummary {
|
|
149
|
-
readonly installed: string[]
|
|
150
|
-
readonly pending: string[]
|
|
151
|
-
readonly stale: string[]
|
|
152
|
-
readonly failed: Array<{ name: string; error: string }>
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/** A Cordis plugin module as an extension exports it. */
|
|
156
|
-
interface PluginModule {
|
|
157
|
-
readonly name?: unknown
|
|
158
|
-
readonly inject?: unknown
|
|
159
|
-
readonly apply: (...args: unknown[]) => unknown
|
|
160
|
-
/** Optional self-check, run after the plugin starts with the plugin's own context (so `ctx.router` reads as in `apply`): it throws (or rejects) when the plugin does not work. */
|
|
161
|
-
readonly check?: (ctx: Context) => unknown
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
interface Installed {
|
|
165
|
-
readonly name: string
|
|
166
|
-
readonly source: string
|
|
167
|
-
readonly version: string
|
|
168
|
-
/** The staged copy that is mounted. */
|
|
169
|
-
readonly dir: string
|
|
170
|
-
readonly module: PluginModule
|
|
171
|
-
fiber: Fiber
|
|
172
|
-
/** The routes its mount added, so a later plugin whose route is taken is told whose it is. */
|
|
173
|
-
readonly routes: readonly ServedRoute[]
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
interface Record_ {
|
|
177
|
-
readonly source: string
|
|
178
|
-
readonly version: string
|
|
179
|
-
readonly dir: string
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
declare module '@deepseek-ai/cordis' {
|
|
183
|
-
interface Context {
|
|
184
|
-
extensions: Extensions
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
interface Events {
|
|
188
|
-
/** An extension was installed, updated, restored or removed. */
|
|
189
|
-
'extensions/changed'(
|
|
190
|
-
name: string,
|
|
191
|
-
action:
|
|
192
|
-
| 'installed'
|
|
193
|
-
| 'updated'
|
|
194
|
-
| 'restored'
|
|
195
|
-
| 'removed'
|
|
196
|
-
| 'requested'
|
|
197
|
-
| 'approved'
|
|
198
|
-
| 'denied',
|
|
199
|
-
): void
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export const NAME = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/
|
|
204
|
-
const CHECK_TIMEOUT_MS = 10_000
|
|
205
|
-
const ENTRIES = ['index.ts', 'index.js', 'index.mjs']
|
|
206
|
-
const KEPT =
|
|
207
|
-
'The version that was running is still running. Fix the error above, then install again.'
|
|
208
|
-
const RESTORED =
|
|
209
|
-
'The version that was running is running again. Fix the error above, then install again.'
|
|
210
|
-
const NOTHING = 'Nothing was installed. Fix the error above, then install again.'
|
|
211
|
-
const WAITING =
|
|
212
|
-
'Nothing was installed. The owner must approve this version (approve) or refuse it (deny); then it installs.'
|
|
213
|
-
|
|
214
|
-
const message = (error: unknown) => (error instanceof Error ? error.message : String(error))
|
|
215
|
-
const inside = (path: string, folder: string) => {
|
|
216
|
-
const rel = relative(resolve(folder), resolve(path))
|
|
217
|
-
return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel)
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* A path as `extensions.json` stores it: relative to `base` (with `/`) when it is inside it, so the record survives a moved app folder (`base` the app's
|
|
222
|
-
* folder for a source, the app's data home for a staged copy); an absolute path stays absolute.
|
|
223
|
-
*/
|
|
224
|
-
export function storedPath(path: string, base: string): string {
|
|
225
|
-
const relativePath = relative(base, path)
|
|
226
|
-
return relativePath !== '' && !relativePath.startsWith('..') && !isAbsolute(relativePath)
|
|
227
|
-
? relativePath.split(sep).join('/')
|
|
228
|
-
: path
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/** The inverse of {@link storedPath}: a relative path is read from `base`. */
|
|
232
|
-
export function restoredPath(stored: string, base: string): string {
|
|
233
|
-
return isAbsolute(stored) ? stored : resolve(base, stored)
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
function injected(module: PluginModule): string[] {
|
|
237
|
-
const inject = module.inject
|
|
238
|
-
if (Array.isArray(inject))
|
|
239
|
-
return inject.filter((name): name is string => typeof name === 'string')
|
|
240
|
-
if (inject && typeof inject === 'object') {
|
|
241
|
-
const required = (inject as { required?: unknown }).required
|
|
242
|
-
if (Array.isArray(required))
|
|
243
|
-
return required.filter((name): name is string => typeof name === 'string')
|
|
244
|
-
return Object.keys(inject)
|
|
245
|
-
}
|
|
246
|
-
return []
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/** The service. One instance serves one app home. */
|
|
250
|
-
/** The slice of the state service this plugin uses, by name, so it imports nothing from @acryldev/state. */
|
|
251
|
-
interface StateService {
|
|
252
|
-
cell<T>(key: string, initial: T): { set(value: T): void }
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
export class Extensions extends Service {
|
|
256
|
-
readonly sources: readonly ExtensionSource[]
|
|
257
|
-
readonly stateFile: string
|
|
258
|
-
readonly ledgerFile: string
|
|
259
|
-
/** Settles when the startup pass is done. */
|
|
260
|
-
readonly ready: Promise<StartupSummary>
|
|
261
|
-
private readonly installed = new Map<string, Installed>()
|
|
262
|
-
private readonly stale = new Set<string>()
|
|
263
|
-
/** The version approved for each name in an `ask` source, and installs still waiting for a decision. */
|
|
264
|
-
private readonly approved = new Map<string, string>()
|
|
265
|
-
private readonly requests = new Map<string, { dir: string; version: string }>()
|
|
266
|
-
private tail: Promise<unknown> = Promise.resolve()
|
|
267
|
-
private disposed = false
|
|
268
|
-
private readonly readOnly: boolean
|
|
269
|
-
private readonly off: ReadonlySet<string>
|
|
270
|
-
private readonly rows: ReadonlySet<string>
|
|
271
|
-
private readonly say: (line: string) => void
|
|
272
|
-
/**
|
|
273
|
-
* The context the service was constructed with. Inside a service method `this.ctx` is Cordis's shadow context, which resolves services as the
|
|
274
|
-
* service's own fiber, so a plugin mounted from it would read `ctx.router` from the installer's fiber and fail. Extensions mount from this one.
|
|
275
|
-
*/
|
|
276
|
-
private readonly owner: Context
|
|
277
|
-
private readonly store: PluginStore
|
|
278
|
-
private readonly routePrefix: string
|
|
279
|
-
/** The app's folder and its data home: what the record's relative paths are read from. */
|
|
280
|
-
private readonly appRoot: string
|
|
281
|
-
private readonly dataHome: string
|
|
282
|
-
|
|
283
|
-
constructor(ctx: Context, config: ExtensionsConfig, store: PluginStore) {
|
|
284
|
-
super(ctx, 'extensions')
|
|
285
|
-
this.owner = ctx
|
|
286
|
-
this.store = store
|
|
287
|
-
this.routePrefix = (config.routePrefix ?? '').replace(/\/+$/u, '')
|
|
288
|
-
this.readOnly = config.readOnly === true
|
|
289
|
-
this.off = new Set(config.off ?? [])
|
|
290
|
-
this.rows = new Set(config.rows ?? [])
|
|
291
|
-
this.say = config.log ?? ((line) => console.log(line))
|
|
292
|
-
const { home, root } = ctx.appInstance
|
|
293
|
-
this.appRoot = root
|
|
294
|
-
this.dataHome = home
|
|
295
|
-
this.sources = (config.sources ?? [{ dir: join(home, 'extensions'), trust: 'install' }]).map(
|
|
296
|
-
(source) => ({
|
|
297
|
-
dir: resolve(source.dir),
|
|
298
|
-
trust: config.approval === true && source.trust === 'install' ? 'ask' : source.trust,
|
|
299
|
-
}),
|
|
300
|
-
)
|
|
301
|
-
this.stateFile = join(home, 'extensions.json')
|
|
302
|
-
this.ledgerFile = join(home, 'extensions-ledger.jsonl')
|
|
303
|
-
// Effects run their disposers newest first: settle pending operations, then dispose every mounted extension, then drop the hook.
|
|
304
|
-
// Staged copies live in the app's home, outside the app: their bare imports are resolved from the app. A read-only start imports the folders where they are (inside the app).
|
|
305
|
-
if (!this.readOnly)
|
|
306
|
-
ctx.effect(
|
|
307
|
-
() => this.store.resolveImportsFrom(root),
|
|
308
|
-
'extensions: resolve staged imports from the app',
|
|
309
|
-
)
|
|
310
|
-
ctx.effect(
|
|
311
|
-
() => async () => {
|
|
312
|
-
// A fiber already being disposed (an app reload) can return nothing here, not a promise.
|
|
313
|
-
for (const entry of [...this.installed.values()].reverse())
|
|
314
|
-
await Promise.resolve(entry.fiber.dispose()).catch(() => undefined)
|
|
315
|
-
this.installed.clear()
|
|
316
|
-
},
|
|
317
|
-
'extensions: dispose mounted extensions',
|
|
318
|
-
)
|
|
319
|
-
ctx.effect(
|
|
320
|
-
() => async () => {
|
|
321
|
-
this.disposed = true
|
|
322
|
-
await this.tail.catch(() => undefined)
|
|
323
|
-
},
|
|
324
|
-
'extensions: settle pending operations',
|
|
325
|
-
)
|
|
326
|
-
// With the state service mounted, what is installed is also a cell: any surface reads it as JSON or streams its changes (`/api/state/extensions`).
|
|
327
|
-
ctx.inject(['state'], (inner) => {
|
|
328
|
-
const state = (inner as unknown as { state: StateService }).state
|
|
329
|
-
const cell = state.cell('extensions', this.list())
|
|
330
|
-
inner.on('extensions/changed', () => cell.set(this.list()))
|
|
331
|
-
})
|
|
332
|
-
this.ready = this.serial(() => this.startup())
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/** Install a folder, or update the installed extension of the same name. The folder must be inside one of the sources. */
|
|
336
|
-
install(source: string): Promise<InstallResult> {
|
|
337
|
-
if (this.readOnly) return Promise.reject(new Error(READ_ONLY))
|
|
338
|
-
return this.serial(() => this.installNow(source))
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/** Remove an installed extension: dispose it, forget it, delete its staged copies. Its source folder is left alone. */
|
|
342
|
-
remove(name: string): Promise<RemoveResult> {
|
|
343
|
-
if (this.readOnly) return Promise.reject(new Error(READ_ONLY))
|
|
344
|
-
return this.serial(() => this.removeNow(name))
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/** Bring every installed extension in line with its source, and install new folders from sources trusted to install. */
|
|
348
|
-
reload(): Promise<InstallResult[]> {
|
|
349
|
-
if (this.readOnly) return Promise.reject(new Error(READ_ONLY))
|
|
350
|
-
return this.serial(async () => {
|
|
351
|
-
const results: InstallResult[] = []
|
|
352
|
-
for (const entry of [...this.installed.values()]) {
|
|
353
|
-
if (!existsSync(entry.source)) {
|
|
354
|
-
this.stale.add(entry.name)
|
|
355
|
-
continue
|
|
356
|
-
}
|
|
357
|
-
if (pluginVersion(entry.source) !== entry.version)
|
|
358
|
-
results.push(await this.installNow(entry.source))
|
|
359
|
-
}
|
|
360
|
-
for (const found of this.discover()) {
|
|
361
|
-
if (found.trust === 'install' && !this.installed.has(found.name))
|
|
362
|
-
results.push(await this.installNow(found.dir))
|
|
363
|
-
}
|
|
364
|
-
return results
|
|
365
|
-
})
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
/** What is installed, with each extension's live state. */
|
|
369
|
-
list(): ExtensionInfo[] {
|
|
370
|
-
return [...this.installed.values()]
|
|
371
|
-
.map((entry) => {
|
|
372
|
-
const state = STATES[entry.fiber.state] ?? 'failed'
|
|
373
|
-
return {
|
|
374
|
-
name: entry.name,
|
|
375
|
-
source: entry.source,
|
|
376
|
-
version: entry.version,
|
|
377
|
-
state,
|
|
378
|
-
missing: state === 'pending' ? this.missing(entry.module) : [],
|
|
379
|
-
stale: this.stale.has(entry.name),
|
|
380
|
-
routes: entry.routes.map(({ method, path }) => ({ method, path: this.written(path) })),
|
|
381
|
-
}
|
|
382
|
-
})
|
|
383
|
-
.sort((a, b) => a.name.localeCompare(b.name))
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/** Installs waiting for an owner's decision. */
|
|
387
|
-
approvals(): Array<{ name: string; version: string; dir: string }> {
|
|
388
|
-
return [...this.requests.entries()].map(([name, request]) => ({ name, ...request }))
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
/** Approve the version that is waiting, then install it. Refused when the source changed since it was requested. */
|
|
392
|
-
approve(name: string): Promise<InstallResult> {
|
|
393
|
-
if (this.readOnly) return Promise.reject(new Error(READ_ONLY))
|
|
394
|
-
return this.serial(async (): Promise<InstallResult> => {
|
|
395
|
-
const request = this.requests.get(name)
|
|
396
|
-
if (!request) {
|
|
397
|
-
return {
|
|
398
|
-
ok: false,
|
|
399
|
-
stage: 'approval',
|
|
400
|
-
name,
|
|
401
|
-
errors: [`nothing is waiting for approval for "${name}"`],
|
|
402
|
-
next: NOTHING,
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
this.requests.delete(name)
|
|
406
|
-
if (!existsSync(request.dir) || pluginVersion(request.dir) !== request.version) {
|
|
407
|
-
return {
|
|
408
|
-
ok: false,
|
|
409
|
-
stage: 'approval',
|
|
410
|
-
name,
|
|
411
|
-
errors: [
|
|
412
|
-
'the source changed after it was requested; the new version needs its own request',
|
|
413
|
-
],
|
|
414
|
-
next: NOTHING,
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
this.approved.set(name, request.version)
|
|
418
|
-
this.record({ kind: 'approved', name, version: request.version })
|
|
419
|
-
this.ctx.emit('extensions/changed', name, 'approved')
|
|
420
|
-
return this.installNow(request.dir)
|
|
421
|
-
})
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
/** Refuse the version that is waiting. Nothing changes except the ledger. */
|
|
425
|
-
deny(name: string): Promise<RemoveResult> {
|
|
426
|
-
if (this.readOnly) return Promise.reject(new Error(READ_ONLY))
|
|
427
|
-
return this.serial(async (): Promise<RemoveResult> => {
|
|
428
|
-
const request = this.requests.get(name)
|
|
429
|
-
if (!request)
|
|
430
|
-
return { ok: false, name, errors: [`nothing is waiting for approval for "${name}"`] }
|
|
431
|
-
this.requests.delete(name)
|
|
432
|
-
this.record({ kind: 'denied', name, version: request.version })
|
|
433
|
-
this.ctx.emit('extensions/changed', name, 'denied')
|
|
434
|
-
return { ok: true, name }
|
|
435
|
-
})
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
private trustOf(dir: string): Trust {
|
|
439
|
-
return this.sources.find((source) => inside(dir, source.dir))?.trust ?? 'list'
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
/** Extension folders in the sources that are not installed. */
|
|
443
|
-
pending(): Array<{ name: string; dir: string; trust: Trust }> {
|
|
444
|
-
return this.discover().filter((found) => !this.installed.has(found.name))
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/** Every change so far, oldest first. */
|
|
448
|
-
ledger(): LedgerEntry[] {
|
|
449
|
-
return readLedger(this.ledgerFile)
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
private serial<T>(run: () => Promise<T>): Promise<T> {
|
|
453
|
-
const guarded = () => {
|
|
454
|
-
if (this.disposed) return Promise.reject(new Error('extensions: the service is disposed'))
|
|
455
|
-
return run()
|
|
456
|
-
}
|
|
457
|
-
const result = this.tail.then(guarded, guarded)
|
|
458
|
-
this.tail = result.catch(() => undefined)
|
|
459
|
-
return result
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
private discover(): Array<{ name: string; dir: string; trust: Trust }> {
|
|
463
|
-
const found: Array<{ name: string; dir: string; trust: Trust }> = []
|
|
464
|
-
for (const source of this.sources) {
|
|
465
|
-
if (!existsSync(source.dir)) continue
|
|
466
|
-
const library = libraryCopies(source.dir)
|
|
467
|
-
for (const entry of readdirSync(source.dir, { withFileTypes: true })) {
|
|
468
|
-
const dir = join(source.dir, entry.name)
|
|
469
|
-
if (
|
|
470
|
-
entry.isDirectory() &&
|
|
471
|
-
NAME.test(entry.name) &&
|
|
472
|
-
!library.has(entry.name) &&
|
|
473
|
-
!this.off.has(entry.name) &&
|
|
474
|
-
!this.rows.has(entry.name) &&
|
|
475
|
-
ENTRIES.some((file) => existsSync(join(dir, file)))
|
|
476
|
-
) {
|
|
477
|
-
if (!found.some((other) => other.name === entry.name))
|
|
478
|
-
found.push({ name: entry.name, dir, trust: source.trust })
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
return found
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
/** The checks that need no code to run. */
|
|
486
|
-
private check(source: string): { name: string; dir: string; errors: string[] } {
|
|
487
|
-
const dir = resolve(source)
|
|
488
|
-
const name = basename(dir)
|
|
489
|
-
const errors: string[] = []
|
|
490
|
-
if (!isAbsolute(source)) errors.push(`the path must be absolute, got "${source}"`)
|
|
491
|
-
if (!this.sources.some((allowed) => inside(dir, allowed.dir))) {
|
|
492
|
-
errors.push(
|
|
493
|
-
`"${dir}" is not inside an extension source (${this.sources.map((allowed) => allowed.dir).join(', ')})`,
|
|
494
|
-
)
|
|
495
|
-
}
|
|
496
|
-
if (!NAME.test(name))
|
|
497
|
-
errors.push(
|
|
498
|
-
`the folder name "${name}" must be lowercase letters, digits and dashes; it is the extension's name`,
|
|
499
|
-
)
|
|
500
|
-
if (this.rows.has(name))
|
|
501
|
-
errors.push(
|
|
502
|
-
`"${name}" is a row of blend.yaml, so the app starts it, in its row order and with its row's config; it is not installed here. Change its folder and the running app loads it again (npm run dev); npm test checks it`,
|
|
503
|
-
)
|
|
504
|
-
if (!existsSync(dir) || !statSync(dir).isDirectory()) errors.push(`"${dir}" is not a folder`)
|
|
505
|
-
else if (!ENTRIES.some((file) => existsSync(join(dir, file))))
|
|
506
|
-
errors.push(`"${dir}" has no ${ENTRIES.join(', ')}`)
|
|
507
|
-
return { name, dir, errors }
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
/**
|
|
511
|
-
* A tool folder (`tool.json` next to an `index.ts` that exports `run(input)`) is code we do not trust, so it is never imported
|
|
512
|
-
* here. It becomes a generated plugin that registers a tool whose every call runs in the sandbox, and whose examples run in the
|
|
513
|
-
* sandbox as the install's self-check. `tool.json`: `{ "description": "...", "examples": [{ "input": ..., "output": ... }] }`.
|
|
514
|
-
*/
|
|
515
|
-
private toolModule(dir: string, name: string): PluginModule | undefined {
|
|
516
|
-
const file = join(dir, 'tool.json')
|
|
517
|
-
if (!existsSync(file)) return undefined
|
|
518
|
-
let spec: { description?: unknown; examples?: unknown; timeoutMs?: unknown }
|
|
519
|
-
try {
|
|
520
|
-
spec = JSON.parse(readFileSync(file, 'utf8'))
|
|
521
|
-
} catch (error) {
|
|
522
|
-
throw new Error(`tool.json is not valid JSON: ${message(error)}`)
|
|
523
|
-
}
|
|
524
|
-
if (typeof spec.description !== 'string' || spec.description.trim() === '')
|
|
525
|
-
throw new Error('tool.json needs a "description"')
|
|
526
|
-
const examples = spec.examples
|
|
527
|
-
if (
|
|
528
|
-
!Array.isArray(examples) ||
|
|
529
|
-
examples.length === 0 ||
|
|
530
|
-
!examples.every(
|
|
531
|
-
(example) =>
|
|
532
|
-
example && typeof example === 'object' && 'input' in example && 'output' in example,
|
|
533
|
-
)
|
|
534
|
-
) {
|
|
535
|
-
throw new Error(
|
|
536
|
-
'tool.json needs "examples": a non-empty list of { "input": ..., "output": ... }; they are run in the sandbox when the tool is installed',
|
|
537
|
-
)
|
|
538
|
-
}
|
|
539
|
-
const timeoutMs =
|
|
540
|
-
typeof spec.timeoutMs === 'number' ? Math.min(Math.max(spec.timeoutMs, 100), 30_000) : 5000
|
|
541
|
-
const entry = ENTRIES.map((candidate) => join(dir, candidate)).find((path) =>
|
|
542
|
-
existsSync(path),
|
|
543
|
-
) as string
|
|
544
|
-
const description = spec.description
|
|
545
|
-
const run = (ctx: Context, input: unknown) =>
|
|
546
|
-
// `get`, not `ctx.sandbox`: the self-check runs from the service's own context, which does not declare the dependency.
|
|
547
|
-
((ctx.get as (service: string) => unknown)('sandbox') as Sandbox)
|
|
548
|
-
.run(entry, input, { timeoutMs })
|
|
549
|
-
.then((result) => {
|
|
550
|
-
if (!result.ok) throw new Error(`${result.kind}: ${result.error}`)
|
|
551
|
-
return result.output
|
|
552
|
-
})
|
|
553
|
-
return {
|
|
554
|
-
name,
|
|
555
|
-
inject: ['tools', 'sandbox'],
|
|
556
|
-
apply: ((ctx: Context) => {
|
|
557
|
-
const tools = (ctx.get as (service: string) => unknown)('tools') as {
|
|
558
|
-
register(
|
|
559
|
-
tool: string,
|
|
560
|
-
definition: { description: string; run(input: unknown): unknown },
|
|
561
|
-
): () => void
|
|
562
|
-
}
|
|
563
|
-
ctx.effect(() => tools.register(name, { description, run: (input) => run(ctx, input) }))
|
|
564
|
-
}) as PluginModule['apply'],
|
|
565
|
-
check: async (ctx: Context) => {
|
|
566
|
-
for (const [index, example] of (
|
|
567
|
-
examples as Array<{ input: unknown; output: unknown }>
|
|
568
|
-
).entries()) {
|
|
569
|
-
const actual = await run(ctx, example.input)
|
|
570
|
-
if (!isDeepStrictEqual(actual, example.output)) {
|
|
571
|
-
throw new Error(
|
|
572
|
-
`example ${index + 1} expected ${JSON.stringify(example.output)} but the tool returned ${JSON.stringify(actual)}`,
|
|
573
|
-
)
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
},
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
private async load(dir: string, name: string): Promise<PluginModule> {
|
|
581
|
-
const tool = this.toolModule(dir, name)
|
|
582
|
-
if (tool) return tool
|
|
583
|
-
const entry = ENTRIES.map((file) => join(dir, file)).find((path) => existsSync(path)) as string
|
|
584
|
-
const module = (await import(pathToFileURL(entry).href)) as Partial<PluginModule> & {
|
|
585
|
-
default?: Partial<PluginModule>
|
|
586
|
-
}
|
|
587
|
-
const plugin = typeof module.apply === 'function' ? module : module.default
|
|
588
|
-
if (!plugin || typeof plugin.apply !== 'function') {
|
|
589
|
-
throw new Error(
|
|
590
|
-
`${basename(entry)} must export a Cordis plugin: "export const name = '${name}'" and "export function apply(ctx) { ... }"`,
|
|
591
|
-
)
|
|
592
|
-
}
|
|
593
|
-
if (plugin.name !== undefined && plugin.name !== name) {
|
|
594
|
-
throw new Error(
|
|
595
|
-
`the plugin is named "${String(plugin.name)}" but its folder is "${name}"; they must match`,
|
|
596
|
-
)
|
|
597
|
-
}
|
|
598
|
-
return { ...plugin, name } as PluginModule
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
private missing(module: PluginModule): string[] {
|
|
602
|
-
return injected(module).filter((service) => this.ctx.get(service) === undefined)
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
/** Run the extension's own `check`, if it has one, with a time limit. Returns the failure, or `undefined` when it passes. */
|
|
606
|
-
private async verify(
|
|
607
|
-
module: PluginModule,
|
|
608
|
-
ctx: Context,
|
|
609
|
-
): Promise<{ stage: 'verify'; error: string } | undefined> {
|
|
610
|
-
if (typeof module.check !== 'function') return undefined
|
|
611
|
-
let timer: ReturnType<typeof setTimeout> | undefined
|
|
612
|
-
try {
|
|
613
|
-
const limit = new Promise<never>((_, reject) => {
|
|
614
|
-
timer = setTimeout(
|
|
615
|
-
() => reject(new Error(`its check did not finish within ${CHECK_TIMEOUT_MS} ms`)),
|
|
616
|
-
CHECK_TIMEOUT_MS,
|
|
617
|
-
)
|
|
618
|
-
})
|
|
619
|
-
await Promise.race([Promise.resolve(module.check(ctx)), limit])
|
|
620
|
-
return undefined
|
|
621
|
-
} catch (error) {
|
|
622
|
-
return { stage: 'verify', error: `its check failed: ${message(error)}` }
|
|
623
|
-
} finally {
|
|
624
|
-
clearTimeout(timer)
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
/** Mount a module as a child fiber and wait until it settles. */
|
|
629
|
-
/** Every route the app serves now, read from the router's labels on every running fiber. */
|
|
630
|
-
private served(): ServedRoute[] {
|
|
631
|
-
const fibers = [...this.ctx.registry.values()].flatMap(
|
|
632
|
-
(runtime) => [...runtime.fibers] as unknown as FiberRoutesView[],
|
|
633
|
-
)
|
|
634
|
-
return servedRoutes(fibers)
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
/** A served path as the plugin wrote it: without the frame's canvas prefix. */
|
|
638
|
-
private written(path: string): string {
|
|
639
|
-
return this.routePrefix !== '' && path.startsWith(`${this.routePrefix}/`)
|
|
640
|
-
? path.slice(this.routePrefix.length)
|
|
641
|
-
: path
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
/**
|
|
645
|
-
* A route the new plugin added that another plugin already serves: the router would answer with the other one, so the new route would never be
|
|
646
|
-
* reached. Refused before the plugin's own check, which the other plugin's answer would pass.
|
|
647
|
-
*/
|
|
648
|
-
private conflict(
|
|
649
|
-
added: readonly ServedRoute[],
|
|
650
|
-
before: readonly ServedRoute[],
|
|
651
|
-
): { stage: 'conflict'; error: string } | undefined {
|
|
652
|
-
const clash = routeClash(added, before)
|
|
653
|
-
if (clash === undefined) return undefined
|
|
654
|
-
const { route, taken } = clash
|
|
655
|
-
const owner =
|
|
656
|
-
[...this.installed.values()].find((entry) =>
|
|
657
|
-
entry.routes.some((own) => own.method === taken.method && own.path === taken.path),
|
|
658
|
-
)?.name ?? (taken.owner === '' ? 'the app' : taken.owner)
|
|
659
|
-
const same =
|
|
660
|
-
taken.path === route.path ? '' : ` (it serves ${taken.method} ${this.written(taken.path)})`
|
|
661
|
-
return {
|
|
662
|
-
stage: 'conflict',
|
|
663
|
-
error: `${route.method} ${this.written(route.path)} is already served by ${owner}${same}; rename this plugin's route, or remove ${owner} first`,
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
private async mount(
|
|
668
|
-
module: PluginModule,
|
|
669
|
-
dir: string,
|
|
670
|
-
version: string,
|
|
671
|
-
): Promise<{ fiber: Fiber; error?: unknown }> {
|
|
672
|
-
// An extension is a plugin module whose config, if any, comes from its own defaults.
|
|
673
|
-
const fiber = this.owner.plugin(module as unknown as Parameters<Context['plugin']>[0])
|
|
674
|
-
attachBrowserHalf(fiber.ctx, this.dataHome, String(module.name ?? basename(dir)), version, dir)
|
|
675
|
-
try {
|
|
676
|
-
await fiber.await()
|
|
677
|
-
return { fiber }
|
|
678
|
-
} catch (error) {
|
|
679
|
-
return { fiber, error }
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
private record(entry: Omit<LedgerEntry, 'at'>): void {
|
|
684
|
-
appendLedger(this.ledgerFile, entry)
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
private saveState(): void {
|
|
688
|
-
const records: Record<string, Record_> = {}
|
|
689
|
-
for (const entry of this.installed.values())
|
|
690
|
-
records[entry.name] = {
|
|
691
|
-
source: storedPath(entry.source, this.appRoot),
|
|
692
|
-
version: entry.version,
|
|
693
|
-
dir: storedPath(entry.dir, this.dataHome),
|
|
694
|
-
}
|
|
695
|
-
mkdirSync(join(this.stateFile, '..'), { recursive: true })
|
|
696
|
-
const temporary = `${this.stateFile}.${String(process.pid)}.tmp`
|
|
697
|
-
writeFileSync(temporary, `${JSON.stringify(records, null, 2)}\n`)
|
|
698
|
-
renameSync(temporary, this.stateFile)
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
private async installNow(source: string): Promise<InstallResult> {
|
|
702
|
-
const { name, dir, errors } = this.check(source)
|
|
703
|
-
if (errors.length > 0) return { ok: false, stage: 'check', name, errors, next: NOTHING }
|
|
704
|
-
const previous = this.installed.get(name)
|
|
705
|
-
const version = pluginVersion(dir)
|
|
706
|
-
const running =
|
|
707
|
-
previous && previous.version === version && STATES[previous.fiber.state] !== 'failed'
|
|
708
|
-
// A source that asks: this exact version must have been approved. Anything else waits, and the ledger says so.
|
|
709
|
-
if (!running && this.trustOf(dir) === 'ask' && this.approved.get(name) !== version) {
|
|
710
|
-
if (this.requests.get(name)?.version !== version) {
|
|
711
|
-
this.requests.set(name, { dir, version })
|
|
712
|
-
this.record({ kind: 'requested', name, version })
|
|
713
|
-
this.ctx.emit('extensions/changed', name, 'requested')
|
|
714
|
-
}
|
|
715
|
-
return {
|
|
716
|
-
ok: false,
|
|
717
|
-
stage: 'approval',
|
|
718
|
-
name,
|
|
719
|
-
errors: [`version ${version} is waiting for approval`],
|
|
720
|
-
next: WAITING,
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
if (previous && previous.version === version && STATES[previous.fiber.state] !== 'failed') {
|
|
724
|
-
const state = STATES[previous.fiber.state] ?? 'failed'
|
|
725
|
-
return {
|
|
726
|
-
ok: true,
|
|
727
|
-
name,
|
|
728
|
-
action: 'unchanged',
|
|
729
|
-
state,
|
|
730
|
-
missing: state === 'pending' ? this.missing(previous.module) : [],
|
|
731
|
-
version,
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
// Import the new version while the old one keeps running: a syntax error or a missing export changes nothing.
|
|
736
|
-
const staged = this.store.put(name, dir)
|
|
737
|
-
let module: PluginModule
|
|
738
|
-
try {
|
|
739
|
-
module = await this.load(staged.dir, name)
|
|
740
|
-
} catch (error) {
|
|
741
|
-
this.store.discard(staged)
|
|
742
|
-
this.record({ kind: 'refused', name, version: staged.version, error: message(error) })
|
|
743
|
-
return {
|
|
744
|
-
ok: false,
|
|
745
|
-
stage: 'import',
|
|
746
|
-
name,
|
|
747
|
-
errors: [message(error)],
|
|
748
|
-
...(previous ? { restoredPrevious: true } : {}),
|
|
749
|
-
next: previous ? KEPT : NOTHING,
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
if (previous) await previous.fiber.dispose()
|
|
754
|
-
const before = this.served()
|
|
755
|
-
const mounted = await this.mount(module, staged.dir, staged.version)
|
|
756
|
-
const state = STATES[mounted.fiber.state] ?? 'failed'
|
|
757
|
-
const added = state === 'active' ? addedRoutes(before, this.served()) : []
|
|
758
|
-
// Commit before "done": a plugin that started still has to pass its own check before the install counts.
|
|
759
|
-
const failure =
|
|
760
|
-
mounted.error !== undefined || state === 'failed'
|
|
761
|
-
? {
|
|
762
|
-
stage: 'activate' as const,
|
|
763
|
-
error: message(mounted.error ?? 'the plugin failed to start'),
|
|
764
|
-
}
|
|
765
|
-
: state === 'active'
|
|
766
|
-
? (this.conflict(added, before) ?? (await this.verify(module, mounted.fiber.ctx)))
|
|
767
|
-
: undefined
|
|
768
|
-
if (failure) {
|
|
769
|
-
await mounted.fiber.dispose().catch(() => undefined)
|
|
770
|
-
this.store.discard(staged)
|
|
771
|
-
const error = failure.error
|
|
772
|
-
this.record({ kind: 'refused', name, version: staged.version, error })
|
|
773
|
-
let restored = false
|
|
774
|
-
if (previous) {
|
|
775
|
-
const again = await this.mount(previous.module, previous.dir, previous.version)
|
|
776
|
-
restored = again.error === undefined && STATES[again.fiber.state] !== 'failed'
|
|
777
|
-
previous.fiber = again.fiber
|
|
778
|
-
if (restored) {
|
|
779
|
-
this.record({ kind: 'restored', name, version: previous.version })
|
|
780
|
-
this.ctx.emit('extensions/changed', name, 'restored')
|
|
781
|
-
} else {
|
|
782
|
-
this.installed.delete(name)
|
|
783
|
-
this.saveState()
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
return {
|
|
787
|
-
ok: false,
|
|
788
|
-
stage: failure.stage,
|
|
789
|
-
name,
|
|
790
|
-
errors: [error],
|
|
791
|
-
...(previous ? { restoredPrevious: restored } : {}),
|
|
792
|
-
next: restored ? RESTORED : NOTHING,
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
const action = previous ? 'updated' : 'installed'
|
|
797
|
-
this.installed.set(name, {
|
|
798
|
-
name,
|
|
799
|
-
source: dir,
|
|
800
|
-
version: staged.version,
|
|
801
|
-
dir: staged.dir,
|
|
802
|
-
module,
|
|
803
|
-
fiber: mounted.fiber,
|
|
804
|
-
routes: added,
|
|
805
|
-
})
|
|
806
|
-
this.stale.delete(name)
|
|
807
|
-
this.saveState()
|
|
808
|
-
this.store.keepOnly(name, staged)
|
|
809
|
-
this.record({ kind: action, name, version: staged.version })
|
|
810
|
-
this.ctx.emit('extensions/changed', name, action)
|
|
811
|
-
return {
|
|
812
|
-
ok: true,
|
|
813
|
-
name,
|
|
814
|
-
action,
|
|
815
|
-
state,
|
|
816
|
-
missing: state === 'pending' ? this.missing(module) : [],
|
|
817
|
-
version: staged.version,
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
private async removeNow(name: string): Promise<RemoveResult> {
|
|
822
|
-
const entry = this.installed.get(name)
|
|
823
|
-
if (!entry) return { ok: false, name, errors: [`"${name}" is not installed`] }
|
|
824
|
-
await entry.fiber.dispose()
|
|
825
|
-
this.installed.delete(name)
|
|
826
|
-
this.stale.delete(name)
|
|
827
|
-
this.saveState()
|
|
828
|
-
this.store.keepOnly(name)
|
|
829
|
-
this.record({ kind: 'removed', name, version: entry.version })
|
|
830
|
-
this.ctx.emit('extensions/changed', name, 'removed')
|
|
831
|
-
return { ok: true, name }
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
/** Never throws: one extension's failure is recorded and the others still start. */
|
|
835
|
-
/**
|
|
836
|
-
* The production start: every folder of a source that installs by itself is loaded from where it is and mounted; the line says which. An extension that the app's own record
|
|
837
|
-
* (`extensions.json`, written by dev) names while its folder is gone is named in a warning, because it is not started.
|
|
838
|
-
*/
|
|
839
|
-
private async startupReadOnly(): Promise<StartupSummary> {
|
|
840
|
-
const summary: StartupSummary = { installed: [], pending: [], stale: [], failed: [] }
|
|
841
|
-
const found = this.discover()
|
|
842
|
-
for (const folder of found) {
|
|
843
|
-
if (folder.trust !== 'install') {
|
|
844
|
-
summary.pending.push(folder.name)
|
|
845
|
-
continue
|
|
846
|
-
}
|
|
847
|
-
try {
|
|
848
|
-
const module = await this.load(folder.dir, folder.name)
|
|
849
|
-
const before = this.served()
|
|
850
|
-
const mounted = await this.mount(module, folder.dir, pluginVersion(folder.dir))
|
|
851
|
-
this.installed.set(folder.name, {
|
|
852
|
-
name: folder.name,
|
|
853
|
-
source: folder.dir,
|
|
854
|
-
version: pluginVersion(folder.dir),
|
|
855
|
-
dir: folder.dir,
|
|
856
|
-
module,
|
|
857
|
-
fiber: mounted.fiber,
|
|
858
|
-
routes: addedRoutes(before, this.served()),
|
|
859
|
-
})
|
|
860
|
-
if (mounted.error !== undefined)
|
|
861
|
-
summary.failed.push({ name: folder.name, error: message(mounted.error) })
|
|
862
|
-
else summary.installed.push(folder.name)
|
|
863
|
-
} catch (error) {
|
|
864
|
-
summary.failed.push({ name: folder.name, error: message(error) })
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
this.say(
|
|
868
|
-
summary.installed.length === 0
|
|
869
|
-
? `extensions: none found in ${this.sources.map((source) => basename(source.dir)).join(', ')}/`
|
|
870
|
-
: `extensions (read-only): ${summary.installed.join(', ')}`,
|
|
871
|
-
)
|
|
872
|
-
for (const failure of summary.failed)
|
|
873
|
-
this.say(`WARNING: extension "${failure.name}" did not start: ${failure.error}`)
|
|
874
|
-
try {
|
|
875
|
-
if (existsSync(this.stateFile)) {
|
|
876
|
-
for (const recorded of Object.keys(
|
|
877
|
-
JSON.parse(readFileSync(this.stateFile, 'utf8')) as Record<string, unknown>,
|
|
878
|
-
)) {
|
|
879
|
-
if (!found.some((folder) => folder.name === recorded))
|
|
880
|
-
this.say(
|
|
881
|
-
`WARNING: ${basename(this.stateFile)} records the extension "${recorded}", but ${this.sources.map((source) => basename(source.dir)).join(', ')}/ has no folder for it: it is not started in production. Commit its folder, or run the app in development and install it again`,
|
|
882
|
-
)
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
} catch {
|
|
886
|
-
// A record that cannot be read says nothing about what to start.
|
|
887
|
-
}
|
|
888
|
-
return summary
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
/**
|
|
892
|
-
* A record with its paths made absolute: relative ones are read from this app's folder and data home, so a moved app finds its plugins. A record an older
|
|
893
|
-
* version wrote with an absolute source that is gone (the app was moved) finds the folder of the same name in one of the sources.
|
|
894
|
-
*/
|
|
895
|
-
private resolved(name: string, stored: Record_): Record_ {
|
|
896
|
-
let source = restoredPath(stored.source, this.appRoot)
|
|
897
|
-
if (!existsSync(source)) {
|
|
898
|
-
const moved = this.sources
|
|
899
|
-
.map((entry) => join(entry.dir, name))
|
|
900
|
-
.find((path) => existsSync(path))
|
|
901
|
-
if (moved !== undefined) source = moved
|
|
902
|
-
}
|
|
903
|
-
return { source, version: stored.version, dir: restoredPath(stored.dir, this.dataHome) }
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
private async startup(): Promise<StartupSummary> {
|
|
907
|
-
if (this.readOnly) return this.startupReadOnly()
|
|
908
|
-
const summary: StartupSummary = { installed: [], pending: [], stale: [], failed: [] }
|
|
909
|
-
let records: Record<string, Record_> = {}
|
|
910
|
-
try {
|
|
911
|
-
if (existsSync(this.stateFile))
|
|
912
|
-
records = JSON.parse(readFileSync(this.stateFile, 'utf8')) as Record<string, Record_>
|
|
913
|
-
} catch (error) {
|
|
914
|
-
summary.failed.push({ name: 'extensions.json', error: message(error) })
|
|
915
|
-
}
|
|
916
|
-
for (const [name, stored] of Object.entries(records)) {
|
|
917
|
-
// Switched off: not started, and dropped from the record; switched on again, its folder is found and installed as new.
|
|
918
|
-
if (this.off.has(name)) continue
|
|
919
|
-
// Now a row of blend.yaml: the app starts it, and the record of its install is dropped.
|
|
920
|
-
if (this.rows.has(name)) continue
|
|
921
|
-
const record = this.resolved(name, stored)
|
|
922
|
-
try {
|
|
923
|
-
// What was installed before was approved then: an unchanged source starts again without asking.
|
|
924
|
-
this.approved.set(name, record.version)
|
|
925
|
-
if (existsSync(record.source)) {
|
|
926
|
-
const result = await this.installNow(record.source)
|
|
927
|
-
if (result.ok) {
|
|
928
|
-
summary.installed.push(name)
|
|
929
|
-
continue
|
|
930
|
-
}
|
|
931
|
-
summary.failed.push({ name, error: result.errors.join('; ') })
|
|
932
|
-
// A source changed into one that does not start (a refused update leaves it on disk): the version that worked runs from its staged copy.
|
|
933
|
-
if (!existsSync(record.dir)) continue
|
|
934
|
-
}
|
|
935
|
-
// The source is gone or broken: the last installed version still runs, and is reported as stale.
|
|
936
|
-
summary.stale.push(name)
|
|
937
|
-
this.stale.add(name)
|
|
938
|
-
if (!this.store.holds(record)) {
|
|
939
|
-
summary.failed.push({ name, error: 'neither the source nor the staged copy exists' })
|
|
940
|
-
continue
|
|
941
|
-
}
|
|
942
|
-
const module = await this.load(record.dir, name)
|
|
943
|
-
const before = this.served()
|
|
944
|
-
const mounted = await this.mount(module, record.dir, record.version)
|
|
945
|
-
if (mounted.error !== undefined)
|
|
946
|
-
summary.failed.push({ name, error: message(mounted.error) })
|
|
947
|
-
this.installed.set(name, {
|
|
948
|
-
name,
|
|
949
|
-
source: record.source,
|
|
950
|
-
version: record.version,
|
|
951
|
-
dir: record.dir,
|
|
952
|
-
module,
|
|
953
|
-
fiber: mounted.fiber,
|
|
954
|
-
routes: addedRoutes(before, this.served()),
|
|
955
|
-
})
|
|
956
|
-
} catch (error) {
|
|
957
|
-
summary.failed.push({ name, error: message(error) })
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
for (const found of this.discover()) {
|
|
961
|
-
if (this.installed.has(found.name)) continue
|
|
962
|
-
if (found.trust !== 'install') {
|
|
963
|
-
summary.pending.push(found.name)
|
|
964
|
-
continue
|
|
965
|
-
}
|
|
966
|
-
try {
|
|
967
|
-
const result = await this.installNow(found.dir)
|
|
968
|
-
if (result.ok) summary.installed.push(found.name)
|
|
969
|
-
else summary.failed.push({ name: found.name, error: result.errors.join('; ') })
|
|
970
|
-
} catch (error) {
|
|
971
|
-
summary.failed.push({ name: found.name, error: message(error) })
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
if (Object.keys(records).length > 0 || summary.installed.length > 0) this.saveState()
|
|
975
|
-
return summary
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
/** The plugin: mount it after `instance`. Installed extensions mount as its children and leave with it. */
|
|
980
|
-
export const extensions = {
|
|
981
|
-
name: 'extensions',
|
|
982
|
-
inject: ['appInstance'],
|
|
983
|
-
async apply(ctx: Context, config: ExtensionsConfig) {
|
|
984
|
-
const service = new Extensions(
|
|
985
|
-
ctx,
|
|
986
|
-
config ?? {},
|
|
987
|
-
folderPluginStore(join(ctx.appInstance.home, 'extensions-staged')),
|
|
988
|
-
)
|
|
989
|
-
await service.ready
|
|
990
|
-
},
|
|
991
|
-
}
|