@acryldev/showcase 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/cards.ts +162 -0
- package/index.ts +117 -0
- package/lib/index.js +177 -0
- package/lib/index.js.map +1 -0
- package/lib/types/cards.d.ts +38 -0
- package/lib/types/index.d.ts +14 -0
- package/lib/types/tsdown.config.d.ts +2 -0
- package/package.json +46 -3
- package/plugin.json +14 -0
- package/test/showcase.test.ts +280 -0
- package/tsconfig.json +21 -0
- package/tsdown.config.ts +23 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 acrylblends
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/cards.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The showcase's cards: what each plugin in the app is, who made it and where to find what it adds. Pure, so the page, the stream and the tests
|
|
3
|
+
* render the same thing.
|
|
4
|
+
*/
|
|
5
|
+
import type { SharedPluginInfo } from '@acryldev/plugin-share'
|
|
6
|
+
|
|
7
|
+
/** One plugin as the showcase shows it. */
|
|
8
|
+
export interface ShowcaseCard {
|
|
9
|
+
readonly name: string
|
|
10
|
+
/** The release's version, or the installed content's short digest for a plugin without one. */
|
|
11
|
+
readonly version: string
|
|
12
|
+
readonly state: string
|
|
13
|
+
/** The GitHub login of whoever released it; absent for a plugin made in this app or pulled from a local file. */
|
|
14
|
+
readonly author?: string
|
|
15
|
+
/** Where it came from: the pulled source, or `this app`. */
|
|
16
|
+
readonly source: string
|
|
17
|
+
/** The pages it serves (`GET` routes without parameters), as the plugin wrote them. */
|
|
18
|
+
readonly pages: readonly string[]
|
|
19
|
+
/** It has a widget on the home page. */
|
|
20
|
+
readonly widget: boolean
|
|
21
|
+
/** The tool of its name, when it registered one. */
|
|
22
|
+
readonly tool?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** What else the app knows about its plugins: the tools registered and the home page's widgets, by name. */
|
|
26
|
+
export interface Offered {
|
|
27
|
+
readonly tools: readonly string[]
|
|
28
|
+
readonly widgets: readonly string[]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A GitHub login: what `author` must look like before the page links to github.com. */
|
|
32
|
+
const LOGIN = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})$/u
|
|
33
|
+
|
|
34
|
+
/** A path a person can open: no `:param`, no wildcard. */
|
|
35
|
+
const PAGE = /^\/[^:*]*$/u
|
|
36
|
+
|
|
37
|
+
/** The cards, one per plugin, in the order the app lists them. */
|
|
38
|
+
export function showcaseCards(
|
|
39
|
+
plugins: readonly SharedPluginInfo[],
|
|
40
|
+
offered: Offered,
|
|
41
|
+
): ShowcaseCard[] {
|
|
42
|
+
return plugins.map((plugin) => {
|
|
43
|
+
const pages = [
|
|
44
|
+
...new Set(
|
|
45
|
+
plugin.routes
|
|
46
|
+
.filter((route) => route.method === 'GET' && PAGE.test(route.path))
|
|
47
|
+
.map((route) => route.path),
|
|
48
|
+
),
|
|
49
|
+
]
|
|
50
|
+
return {
|
|
51
|
+
name: plugin.name,
|
|
52
|
+
version: plugin.release ?? plugin.version,
|
|
53
|
+
state: plugin.state,
|
|
54
|
+
...(plugin.author !== undefined && LOGIN.test(plugin.author)
|
|
55
|
+
? { author: plugin.author }
|
|
56
|
+
: {}),
|
|
57
|
+
source: plugin.pulledFrom ?? 'this app',
|
|
58
|
+
pages,
|
|
59
|
+
widget: offered.widgets.includes(plugin.name),
|
|
60
|
+
...(offered.tools.includes(plugin.name) ? { tool: plugin.name } : {}),
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const escapeHtml = (text: string): string =>
|
|
66
|
+
text
|
|
67
|
+
.replaceAll('&', '&')
|
|
68
|
+
.replaceAll('<', '<')
|
|
69
|
+
.replaceAll('>', '>')
|
|
70
|
+
.replaceAll('"', '"')
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The path the app is served at, read from the showcase's own request path: `''` on the app's own server, `/app` in the frame. Links are built from it,
|
|
74
|
+
* because a relative link cannot name the app's root (`./` from `/app/showcase` is `/app/`, which the app does not serve).
|
|
75
|
+
*/
|
|
76
|
+
export function appBase(requestPath: string): string {
|
|
77
|
+
const at = requestPath.lastIndexOf('/showcase')
|
|
78
|
+
return at <= 0 ? '' : requestPath.slice(0, at)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** A path of the app as the browser asks for it: under `base`, and the root as `base` itself (or `/`). */
|
|
82
|
+
const inApp = (base: string, path: string): string =>
|
|
83
|
+
path === '/' ? base || '/' : `${base}${path}`
|
|
84
|
+
|
|
85
|
+
/** The cards as HTML: the list the page shows, and what the stream sends on each change. Every value is escaped. */
|
|
86
|
+
export function renderCards(cards: readonly ShowcaseCard[], base = ''): string {
|
|
87
|
+
if (cards.length === 0)
|
|
88
|
+
return '<p class="empty">No plugins yet. Pull one: <code>npm run acryl -- plugin pull github:<owner>/<repo></code>, or a group\'s list with <code>--from group.txt</code>.</p>'
|
|
89
|
+
return cards
|
|
90
|
+
.map((card) => {
|
|
91
|
+
const author =
|
|
92
|
+
card.author === undefined
|
|
93
|
+
? '<span class="dim">made here</span>'
|
|
94
|
+
: `<a href="https://github.com/${escapeHtml(card.author)}" target="_blank" rel="noopener">@${escapeHtml(card.author)}</a>`
|
|
95
|
+
const links = [
|
|
96
|
+
...card.pages.map(
|
|
97
|
+
(page) => `<a href="${escapeHtml(inApp(base, page))}">${escapeHtml(page)}</a>`,
|
|
98
|
+
),
|
|
99
|
+
...(card.widget ? [`<a href="${escapeHtml(inApp(base, '/'))}">home widget</a>`] : []),
|
|
100
|
+
...(card.tool === undefined
|
|
101
|
+
? []
|
|
102
|
+
: [
|
|
103
|
+
`<span title="the app's agent can call it">tool <code>${escapeHtml(card.tool)}</code></span>`,
|
|
104
|
+
]),
|
|
105
|
+
]
|
|
106
|
+
return [
|
|
107
|
+
`<article class="card" data-plugin="${escapeHtml(card.name)}" data-state="${escapeHtml(card.state)}">`,
|
|
108
|
+
`<header><h2>${escapeHtml(card.name)}</h2><p class="meta"><span class="version">${escapeHtml(card.version)}</span><span class="state state-${escapeHtml(card.state)}">${escapeHtml(card.state)}</span></p></header>`,
|
|
109
|
+
`<p class="author">${author}</p>`,
|
|
110
|
+
`<p class="source"><code>${escapeHtml(card.source)}</code></p>`,
|
|
111
|
+
links.length === 0
|
|
112
|
+
? '<p class="dim">no page of its own</p>'
|
|
113
|
+
: `<p class="links">${links.join(' ')}</p>`,
|
|
114
|
+
'</article>',
|
|
115
|
+
].join('')
|
|
116
|
+
})
|
|
117
|
+
.join('\n')
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const STYLES = `:root{--bg:#fff;--surface:#f7f7f9;--border:#e2e2e8;--text:#18181b;--dim:#6b6b75;--accent:#5468ff;--ok:#2f9e44;--warn:#d9480f;color-scheme:light}
|
|
121
|
+
@media (prefers-color-scheme:dark){:root{--bg:#0b0b0d;--surface:#18181b;--border:#2a2a2f;--text:#e8e8ea;--dim:#8b8b93;color-scheme:dark}}
|
|
122
|
+
*{box-sizing:border-box}
|
|
123
|
+
body{margin:0;padding:24px 16px;background:var(--bg);color:var(--text);font:14px/1.5 system-ui,-apple-system,"Segoe UI",sans-serif}
|
|
124
|
+
main{max-width:1080px;margin:0 auto}
|
|
125
|
+
h1{margin:0 0 4px;font-size:20px}
|
|
126
|
+
.lead{margin:0 0 20px;color:var(--dim)}
|
|
127
|
+
#cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(260px,1fr));gap:12px}
|
|
128
|
+
.card{padding:14px 16px;border:1px solid var(--border);border-radius:12px;background:var(--surface);min-width:0}
|
|
129
|
+
.card header{margin-bottom:8px}
|
|
130
|
+
.card h2{margin:0 0 4px;font-size:15px;font-weight:600;overflow-wrap:anywhere}
|
|
131
|
+
.card .meta{display:flex;align-items:center;gap:8px;margin:0}
|
|
132
|
+
.version{color:var(--dim);font-variant-numeric:tabular-nums}
|
|
133
|
+
.state{padding:1px 8px;border-radius:999px;border:1px solid var(--border);font-size:12px;color:var(--dim)}
|
|
134
|
+
.state-active{color:var(--ok);border-color:currentColor}
|
|
135
|
+
.state-failed,.state-pending{color:var(--warn);border-color:currentColor}
|
|
136
|
+
.card p{margin:4px 0}
|
|
137
|
+
.source code{font-size:12px;color:var(--dim);overflow-wrap:anywhere}
|
|
138
|
+
.links{display:flex;flex-wrap:wrap;gap:6px 12px}
|
|
139
|
+
a{color:var(--accent);text-decoration:none}
|
|
140
|
+
a:hover{text-decoration:underline}
|
|
141
|
+
.dim,.empty{color:var(--dim)}
|
|
142
|
+
#live{font-size:12px;color:var(--dim)}`
|
|
143
|
+
|
|
144
|
+
/** The whole page; the script follows the stream and replaces the cards on each change. */
|
|
145
|
+
export function renderPage(cards: readonly ShowcaseCard[], base = ''): string {
|
|
146
|
+
return `<!doctype html>
|
|
147
|
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
148
|
+
<title>Showcase</title><style>${STYLES}</style></head>
|
|
149
|
+
<body><main>
|
|
150
|
+
<h1>Showcase</h1>
|
|
151
|
+
<p class="lead">Every plugin in this app, who made it and where it came from. <span id="live" role="status"></span></p>
|
|
152
|
+
<section id="cards" aria-live="polite">${renderCards(cards, base)}</section>
|
|
153
|
+
</main>
|
|
154
|
+
<script type="module">
|
|
155
|
+
const cards = document.getElementById('cards')
|
|
156
|
+
const live = document.getElementById('live')
|
|
157
|
+
const events = new EventSource(${JSON.stringify(`${base}/showcase/events`).replaceAll('<', '\\u003c')})
|
|
158
|
+
events.addEventListener('cards', (event) => { cards.innerHTML = event.data; live.textContent = 'live' })
|
|
159
|
+
events.onerror = () => { live.textContent = 'reconnecting...' }
|
|
160
|
+
</script>
|
|
161
|
+
</body></html>`
|
|
162
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The collective app's showcase: every plugin in the app as a card (name, author, version, source, state, links to what it adds) at `/showcase`,
|
|
3
|
+
* updated live as plugins are pulled and removed.
|
|
4
|
+
*
|
|
5
|
+
* A group pulls its members' plugins into one app (`plugin pull --from group.txt`); this page is where they see what the group made. It reads the
|
|
6
|
+
* app's plugins through `pluginShare` (which knows where each pulled one came from), and follows `extensions/changed`: every install, update,
|
|
7
|
+
* restore and removal goes through extensions, so one event covers them all. The stream's open connections end with the plugin.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {} from '@acryldev/extensions'
|
|
11
|
+
import type {} from '@acryldev/plugin-share'
|
|
12
|
+
import { Acryl } from '@acryldev/router'
|
|
13
|
+
import { streamSSE } from '@acryldev/router/helpers'
|
|
14
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
15
|
+
import {
|
|
16
|
+
appBase,
|
|
17
|
+
type Offered,
|
|
18
|
+
renderCards,
|
|
19
|
+
renderPage,
|
|
20
|
+
type ShowcaseCard,
|
|
21
|
+
showcaseCards,
|
|
22
|
+
} from './cards.ts'
|
|
23
|
+
|
|
24
|
+
export type { ShowcaseCard } from './cards.ts'
|
|
25
|
+
export { appBase, renderCards, showcaseCards } from './cards.ts'
|
|
26
|
+
|
|
27
|
+
export const name = 'showcase'
|
|
28
|
+
export const inject = ['router', 'pluginShare']
|
|
29
|
+
|
|
30
|
+
/** A comment line this often keeps an idle stream open through proxies and browsers. */
|
|
31
|
+
const KEEP_ALIVE_MS = 15_000
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The names an optional service lists, or none when it is absent or is not the service the showcase knows. A name can be someone else's: in the
|
|
35
|
+
* frame `tools` is the host's (the DSH harness's tool registry, with another shape), not the app's agent tools, so the shape is checked, not assumed.
|
|
36
|
+
*/
|
|
37
|
+
function namesOf(service: unknown, method: string, key: string): string[] {
|
|
38
|
+
const list = (service as Record<string, unknown> | undefined)?.[method]
|
|
39
|
+
if (typeof list !== 'function') return []
|
|
40
|
+
let entries: unknown
|
|
41
|
+
try {
|
|
42
|
+
entries = (list as () => unknown).call(service)
|
|
43
|
+
} catch {
|
|
44
|
+
return []
|
|
45
|
+
}
|
|
46
|
+
if (!Array.isArray(entries)) return []
|
|
47
|
+
return entries.flatMap((entry) => {
|
|
48
|
+
const value = (entry as Record<string, unknown> | null)?.[key]
|
|
49
|
+
return typeof value === 'string' ? [value] : []
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The optional services the cards link to, read where they are now: an app without an agent has no tools, one without a home page no widgets. */
|
|
54
|
+
function offered(ctx: Context): Offered {
|
|
55
|
+
const get = ctx.get as (service: string) => unknown
|
|
56
|
+
return {
|
|
57
|
+
tools: namesOf(get('tools'), 'list', 'name'),
|
|
58
|
+
widgets: namesOf(get('home'), 'widgets', 'id'),
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function apply(ctx: Context): void {
|
|
63
|
+
const cards = (): ShowcaseCard[] => showcaseCards(ctx.pluginShare.list(), offered(ctx))
|
|
64
|
+
|
|
65
|
+
// The pages that follow the stream; each gets the cards again after every change, rendered for the path it is served at.
|
|
66
|
+
const listeners = new Set<(now: readonly ShowcaseCard[]) => void>()
|
|
67
|
+
const ends = new Set<() => void>()
|
|
68
|
+
ctx.on('extensions/changed', () => {
|
|
69
|
+
if (listeners.size === 0) return
|
|
70
|
+
const now = cards()
|
|
71
|
+
for (const listener of listeners) listener(now)
|
|
72
|
+
})
|
|
73
|
+
ctx.effect(
|
|
74
|
+
() => () => {
|
|
75
|
+
for (const end of ends) end()
|
|
76
|
+
},
|
|
77
|
+
'showcase: end the open streams',
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
const app = new Acryl()
|
|
81
|
+
.get('/showcase', (c) =>
|
|
82
|
+
c.html(renderPage(cards(), appBase(c.req.path)), 200, { 'cache-control': 'no-store' }),
|
|
83
|
+
)
|
|
84
|
+
.get('/showcase/plugins', (c) => c.json(cards(), 200, { 'cache-control': 'no-store' }))
|
|
85
|
+
.get('/showcase/events', (c) =>
|
|
86
|
+
streamSSE(c, async (stream) => {
|
|
87
|
+
const base = appBase(c.req.path)
|
|
88
|
+
let queue: Promise<unknown> = Promise.resolve()
|
|
89
|
+
const send = (now: readonly ShowcaseCard[]): void => {
|
|
90
|
+
queue = queue
|
|
91
|
+
.then(() => stream.writeSSE({ event: 'cards', data: renderCards(now, base) }))
|
|
92
|
+
.catch(() => undefined)
|
|
93
|
+
}
|
|
94
|
+
let finish = (): void => undefined
|
|
95
|
+
const ended = new Promise<void>((resolve) => {
|
|
96
|
+
finish = resolve
|
|
97
|
+
stream.onAbort(resolve)
|
|
98
|
+
})
|
|
99
|
+
ends.add(finish)
|
|
100
|
+
listeners.add(send)
|
|
101
|
+
send(cards())
|
|
102
|
+
const keepAlive = setInterval(() => {
|
|
103
|
+
queue = queue.then(() => stream.write(': keepalive\n\n')).catch(() => undefined)
|
|
104
|
+
}, KEEP_ALIVE_MS)
|
|
105
|
+
keepAlive.unref()
|
|
106
|
+
try {
|
|
107
|
+
await ended
|
|
108
|
+
} finally {
|
|
109
|
+
clearInterval(keepAlive)
|
|
110
|
+
listeners.delete(send)
|
|
111
|
+
ends.delete(finish)
|
|
112
|
+
await queue
|
|
113
|
+
}
|
|
114
|
+
}),
|
|
115
|
+
)
|
|
116
|
+
ctx.router.route('/', app)
|
|
117
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { Acryl } from "@acryldev/router";
|
|
2
|
+
import { streamSSE } from "@acryldev/router/helpers";
|
|
3
|
+
//#region cards.ts
|
|
4
|
+
/** A GitHub login: what `author` must look like before the page links to github.com. */
|
|
5
|
+
const LOGIN = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})$/u;
|
|
6
|
+
/** A path a person can open: no `:param`, no wildcard. */
|
|
7
|
+
const PAGE = /^\/[^:*]*$/u;
|
|
8
|
+
/** The cards, one per plugin, in the order the app lists them. */
|
|
9
|
+
function showcaseCards(plugins, offered) {
|
|
10
|
+
return plugins.map((plugin) => {
|
|
11
|
+
const pages = [...new Set(plugin.routes.filter((route) => route.method === "GET" && PAGE.test(route.path)).map((route) => route.path))];
|
|
12
|
+
return {
|
|
13
|
+
name: plugin.name,
|
|
14
|
+
version: plugin.release ?? plugin.version,
|
|
15
|
+
state: plugin.state,
|
|
16
|
+
...plugin.author !== void 0 && LOGIN.test(plugin.author) ? { author: plugin.author } : {},
|
|
17
|
+
source: plugin.pulledFrom ?? "this app",
|
|
18
|
+
pages,
|
|
19
|
+
widget: offered.widgets.includes(plugin.name),
|
|
20
|
+
...offered.tools.includes(plugin.name) ? { tool: plugin.name } : {}
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const escapeHtml = (text) => text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """);
|
|
25
|
+
/**
|
|
26
|
+
* The path the app is served at, read from the showcase's own request path: `''` on the app's own server, `/app` in the frame. Links are built from it,
|
|
27
|
+
* because a relative link cannot name the app's root (`./` from `/app/showcase` is `/app/`, which the app does not serve).
|
|
28
|
+
*/
|
|
29
|
+
function appBase(requestPath) {
|
|
30
|
+
const at = requestPath.lastIndexOf("/showcase");
|
|
31
|
+
return at <= 0 ? "" : requestPath.slice(0, at);
|
|
32
|
+
}
|
|
33
|
+
/** A path of the app as the browser asks for it: under `base`, and the root as `base` itself (or `/`). */
|
|
34
|
+
const inApp = (base, path) => path === "/" ? base || "/" : `${base}${path}`;
|
|
35
|
+
/** The cards as HTML: the list the page shows, and what the stream sends on each change. Every value is escaped. */
|
|
36
|
+
function renderCards(cards, base = "") {
|
|
37
|
+
if (cards.length === 0) return "<p class=\"empty\">No plugins yet. Pull one: <code>npm run acryl -- plugin pull github:<owner>/<repo></code>, or a group's list with <code>--from group.txt</code>.</p>";
|
|
38
|
+
return cards.map((card) => {
|
|
39
|
+
const author = card.author === void 0 ? "<span class=\"dim\">made here</span>" : `<a href="https://github.com/${escapeHtml(card.author)}" target="_blank" rel="noopener">@${escapeHtml(card.author)}</a>`;
|
|
40
|
+
const links = [
|
|
41
|
+
...card.pages.map((page) => `<a href="${escapeHtml(inApp(base, page))}">${escapeHtml(page)}</a>`),
|
|
42
|
+
...card.widget ? [`<a href="${escapeHtml(inApp(base, "/"))}">home widget</a>`] : [],
|
|
43
|
+
...card.tool === void 0 ? [] : [`<span title="the app's agent can call it">tool <code>${escapeHtml(card.tool)}</code></span>`]
|
|
44
|
+
];
|
|
45
|
+
return [
|
|
46
|
+
`<article class="card" data-plugin="${escapeHtml(card.name)}" data-state="${escapeHtml(card.state)}">`,
|
|
47
|
+
`<header><h2>${escapeHtml(card.name)}</h2><p class="meta"><span class="version">${escapeHtml(card.version)}</span><span class="state state-${escapeHtml(card.state)}">${escapeHtml(card.state)}</span></p></header>`,
|
|
48
|
+
`<p class="author">${author}</p>`,
|
|
49
|
+
`<p class="source"><code>${escapeHtml(card.source)}</code></p>`,
|
|
50
|
+
links.length === 0 ? "<p class=\"dim\">no page of its own</p>" : `<p class="links">${links.join(" ")}</p>`,
|
|
51
|
+
"</article>"
|
|
52
|
+
].join("");
|
|
53
|
+
}).join("\n");
|
|
54
|
+
}
|
|
55
|
+
const STYLES = `:root{--bg:#fff;--surface:#f7f7f9;--border:#e2e2e8;--text:#18181b;--dim:#6b6b75;--accent:#5468ff;--ok:#2f9e44;--warn:#d9480f;color-scheme:light}
|
|
56
|
+
@media (prefers-color-scheme:dark){:root{--bg:#0b0b0d;--surface:#18181b;--border:#2a2a2f;--text:#e8e8ea;--dim:#8b8b93;color-scheme:dark}}
|
|
57
|
+
*{box-sizing:border-box}
|
|
58
|
+
body{margin:0;padding:24px 16px;background:var(--bg);color:var(--text);font:14px/1.5 system-ui,-apple-system,"Segoe UI",sans-serif}
|
|
59
|
+
main{max-width:1080px;margin:0 auto}
|
|
60
|
+
h1{margin:0 0 4px;font-size:20px}
|
|
61
|
+
.lead{margin:0 0 20px;color:var(--dim)}
|
|
62
|
+
#cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(260px,1fr));gap:12px}
|
|
63
|
+
.card{padding:14px 16px;border:1px solid var(--border);border-radius:12px;background:var(--surface);min-width:0}
|
|
64
|
+
.card header{margin-bottom:8px}
|
|
65
|
+
.card h2{margin:0 0 4px;font-size:15px;font-weight:600;overflow-wrap:anywhere}
|
|
66
|
+
.card .meta{display:flex;align-items:center;gap:8px;margin:0}
|
|
67
|
+
.version{color:var(--dim);font-variant-numeric:tabular-nums}
|
|
68
|
+
.state{padding:1px 8px;border-radius:999px;border:1px solid var(--border);font-size:12px;color:var(--dim)}
|
|
69
|
+
.state-active{color:var(--ok);border-color:currentColor}
|
|
70
|
+
.state-failed,.state-pending{color:var(--warn);border-color:currentColor}
|
|
71
|
+
.card p{margin:4px 0}
|
|
72
|
+
.source code{font-size:12px;color:var(--dim);overflow-wrap:anywhere}
|
|
73
|
+
.links{display:flex;flex-wrap:wrap;gap:6px 12px}
|
|
74
|
+
a{color:var(--accent);text-decoration:none}
|
|
75
|
+
a:hover{text-decoration:underline}
|
|
76
|
+
.dim,.empty{color:var(--dim)}
|
|
77
|
+
#live{font-size:12px;color:var(--dim)}`;
|
|
78
|
+
/** The whole page; the script follows the stream and replaces the cards on each change. */
|
|
79
|
+
function renderPage(cards, base = "") {
|
|
80
|
+
return `<!doctype html>
|
|
81
|
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
82
|
+
<title>Showcase</title><style>${STYLES}</style></head>
|
|
83
|
+
<body><main>
|
|
84
|
+
<h1>Showcase</h1>
|
|
85
|
+
<p class="lead">Every plugin in this app, who made it and where it came from. <span id="live" role="status"></span></p>
|
|
86
|
+
<section id="cards" aria-live="polite">${renderCards(cards, base)}</section>
|
|
87
|
+
</main>
|
|
88
|
+
<script type="module">
|
|
89
|
+
const cards = document.getElementById('cards')
|
|
90
|
+
const live = document.getElementById('live')
|
|
91
|
+
const events = new EventSource(${JSON.stringify(`${base}/showcase/events`).replaceAll("<", "\\u003c")})
|
|
92
|
+
events.addEventListener('cards', (event) => { cards.innerHTML = event.data; live.textContent = 'live' })
|
|
93
|
+
events.onerror = () => { live.textContent = 'reconnecting...' }
|
|
94
|
+
<\/script>
|
|
95
|
+
</body></html>`;
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region index.ts
|
|
99
|
+
const name = "showcase";
|
|
100
|
+
const inject = ["router", "pluginShare"];
|
|
101
|
+
/** A comment line this often keeps an idle stream open through proxies and browsers. */
|
|
102
|
+
const KEEP_ALIVE_MS = 15e3;
|
|
103
|
+
/**
|
|
104
|
+
* The names an optional service lists, or none when it is absent or is not the service the showcase knows. A name can be someone else's: in the
|
|
105
|
+
* frame `tools` is the host's (the DSH harness's tool registry, with another shape), not the app's agent tools, so the shape is checked, not assumed.
|
|
106
|
+
*/
|
|
107
|
+
function namesOf(service, method, key) {
|
|
108
|
+
const list = service?.[method];
|
|
109
|
+
if (typeof list !== "function") return [];
|
|
110
|
+
let entries;
|
|
111
|
+
try {
|
|
112
|
+
entries = list.call(service);
|
|
113
|
+
} catch {
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
if (!Array.isArray(entries)) return [];
|
|
117
|
+
return entries.flatMap((entry) => {
|
|
118
|
+
const value = entry?.[key];
|
|
119
|
+
return typeof value === "string" ? [value] : [];
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/** The optional services the cards link to, read where they are now: an app without an agent has no tools, one without a home page no widgets. */
|
|
123
|
+
function offered(ctx) {
|
|
124
|
+
const get = ctx.get;
|
|
125
|
+
return {
|
|
126
|
+
tools: namesOf(get("tools"), "list", "name"),
|
|
127
|
+
widgets: namesOf(get("home"), "widgets", "id")
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function apply(ctx) {
|
|
131
|
+
const cards = () => showcaseCards(ctx.pluginShare.list(), offered(ctx));
|
|
132
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
133
|
+
const ends = /* @__PURE__ */ new Set();
|
|
134
|
+
ctx.on("extensions/changed", () => {
|
|
135
|
+
if (listeners.size === 0) return;
|
|
136
|
+
const now = cards();
|
|
137
|
+
for (const listener of listeners) listener(now);
|
|
138
|
+
});
|
|
139
|
+
ctx.effect(() => () => {
|
|
140
|
+
for (const end of ends) end();
|
|
141
|
+
}, "showcase: end the open streams");
|
|
142
|
+
const app = new Acryl().get("/showcase", (c) => c.html(renderPage(cards(), appBase(c.req.path)), 200, { "cache-control": "no-store" })).get("/showcase/plugins", (c) => c.json(cards(), 200, { "cache-control": "no-store" })).get("/showcase/events", (c) => streamSSE(c, async (stream) => {
|
|
143
|
+
const base = appBase(c.req.path);
|
|
144
|
+
let queue = Promise.resolve();
|
|
145
|
+
const send = (now) => {
|
|
146
|
+
queue = queue.then(() => stream.writeSSE({
|
|
147
|
+
event: "cards",
|
|
148
|
+
data: renderCards(now, base)
|
|
149
|
+
})).catch(() => void 0);
|
|
150
|
+
};
|
|
151
|
+
let finish = () => void 0;
|
|
152
|
+
const ended = new Promise((resolve) => {
|
|
153
|
+
finish = resolve;
|
|
154
|
+
stream.onAbort(resolve);
|
|
155
|
+
});
|
|
156
|
+
ends.add(finish);
|
|
157
|
+
listeners.add(send);
|
|
158
|
+
send(cards());
|
|
159
|
+
const keepAlive = setInterval(() => {
|
|
160
|
+
queue = queue.then(() => stream.write(": keepalive\n\n")).catch(() => void 0);
|
|
161
|
+
}, KEEP_ALIVE_MS);
|
|
162
|
+
keepAlive.unref();
|
|
163
|
+
try {
|
|
164
|
+
await ended;
|
|
165
|
+
} finally {
|
|
166
|
+
clearInterval(keepAlive);
|
|
167
|
+
listeners.delete(send);
|
|
168
|
+
ends.delete(finish);
|
|
169
|
+
await queue;
|
|
170
|
+
}
|
|
171
|
+
}));
|
|
172
|
+
ctx.router.route("/", app);
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
export { appBase, apply, inject, name, renderCards, showcaseCards };
|
|
176
|
+
|
|
177
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../cards.ts","../index.ts"],"sourcesContent":["/**\n * The showcase's cards: what each plugin in the app is, who made it and where to find what it adds. Pure, so the page, the stream and the tests\n * render the same thing.\n */\nimport type { SharedPluginInfo } from '@acryldev/plugin-share'\n\n/** One plugin as the showcase shows it. */\nexport interface ShowcaseCard {\n readonly name: string\n /** The release's version, or the installed content's short digest for a plugin without one. */\n readonly version: string\n readonly state: string\n /** The GitHub login of whoever released it; absent for a plugin made in this app or pulled from a local file. */\n readonly author?: string\n /** Where it came from: the pulled source, or `this app`. */\n readonly source: string\n /** The pages it serves (`GET` routes without parameters), as the plugin wrote them. */\n readonly pages: readonly string[]\n /** It has a widget on the home page. */\n readonly widget: boolean\n /** The tool of its name, when it registered one. */\n readonly tool?: string\n}\n\n/** What else the app knows about its plugins: the tools registered and the home page's widgets, by name. */\nexport interface Offered {\n readonly tools: readonly string[]\n readonly widgets: readonly string[]\n}\n\n/** A GitHub login: what `author` must look like before the page links to github.com. */\nconst LOGIN = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})$/u\n\n/** A path a person can open: no `:param`, no wildcard. */\nconst PAGE = /^\\/[^:*]*$/u\n\n/** The cards, one per plugin, in the order the app lists them. */\nexport function showcaseCards(\n plugins: readonly SharedPluginInfo[],\n offered: Offered,\n): ShowcaseCard[] {\n return plugins.map((plugin) => {\n const pages = [\n ...new Set(\n plugin.routes\n .filter((route) => route.method === 'GET' && PAGE.test(route.path))\n .map((route) => route.path),\n ),\n ]\n return {\n name: plugin.name,\n version: plugin.release ?? plugin.version,\n state: plugin.state,\n ...(plugin.author !== undefined && LOGIN.test(plugin.author)\n ? { author: plugin.author }\n : {}),\n source: plugin.pulledFrom ?? 'this app',\n pages,\n widget: offered.widgets.includes(plugin.name),\n ...(offered.tools.includes(plugin.name) ? { tool: plugin.name } : {}),\n }\n })\n}\n\nconst escapeHtml = (text: string): string =>\n text\n .replaceAll('&', '&')\n .replaceAll('<', '<')\n .replaceAll('>', '>')\n .replaceAll('\"', '"')\n\n/**\n * The path the app is served at, read from the showcase's own request path: `''` on the app's own server, `/app` in the frame. Links are built from it,\n * because a relative link cannot name the app's root (`./` from `/app/showcase` is `/app/`, which the app does not serve).\n */\nexport function appBase(requestPath: string): string {\n const at = requestPath.lastIndexOf('/showcase')\n return at <= 0 ? '' : requestPath.slice(0, at)\n}\n\n/** A path of the app as the browser asks for it: under `base`, and the root as `base` itself (or `/`). */\nconst inApp = (base: string, path: string): string =>\n path === '/' ? base || '/' : `${base}${path}`\n\n/** The cards as HTML: the list the page shows, and what the stream sends on each change. Every value is escaped. */\nexport function renderCards(cards: readonly ShowcaseCard[], base = ''): string {\n if (cards.length === 0)\n return '<p class=\"empty\">No plugins yet. Pull one: <code>npm run acryl -- plugin pull github:<owner>/<repo></code>, or a group\\'s list with <code>--from group.txt</code>.</p>'\n return cards\n .map((card) => {\n const author =\n card.author === undefined\n ? '<span class=\"dim\">made here</span>'\n : `<a href=\"https://github.com/${escapeHtml(card.author)}\" target=\"_blank\" rel=\"noopener\">@${escapeHtml(card.author)}</a>`\n const links = [\n ...card.pages.map(\n (page) => `<a href=\"${escapeHtml(inApp(base, page))}\">${escapeHtml(page)}</a>`,\n ),\n ...(card.widget ? [`<a href=\"${escapeHtml(inApp(base, '/'))}\">home widget</a>`] : []),\n ...(card.tool === undefined\n ? []\n : [\n `<span title=\"the app's agent can call it\">tool <code>${escapeHtml(card.tool)}</code></span>`,\n ]),\n ]\n return [\n `<article class=\"card\" data-plugin=\"${escapeHtml(card.name)}\" data-state=\"${escapeHtml(card.state)}\">`,\n `<header><h2>${escapeHtml(card.name)}</h2><p class=\"meta\"><span class=\"version\">${escapeHtml(card.version)}</span><span class=\"state state-${escapeHtml(card.state)}\">${escapeHtml(card.state)}</span></p></header>`,\n `<p class=\"author\">${author}</p>`,\n `<p class=\"source\"><code>${escapeHtml(card.source)}</code></p>`,\n links.length === 0\n ? '<p class=\"dim\">no page of its own</p>'\n : `<p class=\"links\">${links.join(' ')}</p>`,\n '</article>',\n ].join('')\n })\n .join('\\n')\n}\n\nconst STYLES = `:root{--bg:#fff;--surface:#f7f7f9;--border:#e2e2e8;--text:#18181b;--dim:#6b6b75;--accent:#5468ff;--ok:#2f9e44;--warn:#d9480f;color-scheme:light}\n@media (prefers-color-scheme:dark){:root{--bg:#0b0b0d;--surface:#18181b;--border:#2a2a2f;--text:#e8e8ea;--dim:#8b8b93;color-scheme:dark}}\n*{box-sizing:border-box}\nbody{margin:0;padding:24px 16px;background:var(--bg);color:var(--text);font:14px/1.5 system-ui,-apple-system,\"Segoe UI\",sans-serif}\nmain{max-width:1080px;margin:0 auto}\nh1{margin:0 0 4px;font-size:20px}\n.lead{margin:0 0 20px;color:var(--dim)}\n#cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(260px,1fr));gap:12px}\n.card{padding:14px 16px;border:1px solid var(--border);border-radius:12px;background:var(--surface);min-width:0}\n.card header{margin-bottom:8px}\n.card h2{margin:0 0 4px;font-size:15px;font-weight:600;overflow-wrap:anywhere}\n.card .meta{display:flex;align-items:center;gap:8px;margin:0}\n.version{color:var(--dim);font-variant-numeric:tabular-nums}\n.state{padding:1px 8px;border-radius:999px;border:1px solid var(--border);font-size:12px;color:var(--dim)}\n.state-active{color:var(--ok);border-color:currentColor}\n.state-failed,.state-pending{color:var(--warn);border-color:currentColor}\n.card p{margin:4px 0}\n.source code{font-size:12px;color:var(--dim);overflow-wrap:anywhere}\n.links{display:flex;flex-wrap:wrap;gap:6px 12px}\na{color:var(--accent);text-decoration:none}\na:hover{text-decoration:underline}\n.dim,.empty{color:var(--dim)}\n#live{font-size:12px;color:var(--dim)}`\n\n/** The whole page; the script follows the stream and replaces the cards on each change. */\nexport function renderPage(cards: readonly ShowcaseCard[], base = ''): string {\n return `<!doctype html>\n<html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n<title>Showcase</title><style>${STYLES}</style></head>\n<body><main>\n<h1>Showcase</h1>\n<p class=\"lead\">Every plugin in this app, who made it and where it came from. <span id=\"live\" role=\"status\"></span></p>\n<section id=\"cards\" aria-live=\"polite\">${renderCards(cards, base)}</section>\n</main>\n<script type=\"module\">\nconst cards = document.getElementById('cards')\nconst live = document.getElementById('live')\nconst events = new EventSource(${JSON.stringify(`${base}/showcase/events`).replaceAll('<', '\\\\u003c')})\nevents.addEventListener('cards', (event) => { cards.innerHTML = event.data; live.textContent = 'live' })\nevents.onerror = () => { live.textContent = 'reconnecting...' }\n</script>\n</body></html>`\n}\n","/**\n * The collective app's showcase: every plugin in the app as a card (name, author, version, source, state, links to what it adds) at `/showcase`,\n * updated live as plugins are pulled and removed.\n *\n * A group pulls its members' plugins into one app (`plugin pull --from group.txt`); this page is where they see what the group made. It reads the\n * app's plugins through `pluginShare` (which knows where each pulled one came from), and follows `extensions/changed`: every install, update,\n * restore and removal goes through extensions, so one event covers them all. The stream's open connections end with the plugin.\n */\n\nimport type {} from '@acryldev/extensions'\nimport type {} from '@acryldev/plugin-share'\nimport { Acryl } from '@acryldev/router'\nimport { streamSSE } from '@acryldev/router/helpers'\nimport type { Context } from '@deepseek-ai/cordis'\nimport {\n appBase,\n type Offered,\n renderCards,\n renderPage,\n type ShowcaseCard,\n showcaseCards,\n} from './cards.ts'\n\nexport type { ShowcaseCard } from './cards.ts'\nexport { appBase, renderCards, showcaseCards } from './cards.ts'\n\nexport const name = 'showcase'\nexport const inject = ['router', 'pluginShare']\n\n/** A comment line this often keeps an idle stream open through proxies and browsers. */\nconst KEEP_ALIVE_MS = 15_000\n\n/**\n * The names an optional service lists, or none when it is absent or is not the service the showcase knows. A name can be someone else's: in the\n * frame `tools` is the host's (the DSH harness's tool registry, with another shape), not the app's agent tools, so the shape is checked, not assumed.\n */\nfunction namesOf(service: unknown, method: string, key: string): string[] {\n const list = (service as Record<string, unknown> | undefined)?.[method]\n if (typeof list !== 'function') return []\n let entries: unknown\n try {\n entries = (list as () => unknown).call(service)\n } catch {\n return []\n }\n if (!Array.isArray(entries)) return []\n return entries.flatMap((entry) => {\n const value = (entry as Record<string, unknown> | null)?.[key]\n return typeof value === 'string' ? [value] : []\n })\n}\n\n/** The optional services the cards link to, read where they are now: an app without an agent has no tools, one without a home page no widgets. */\nfunction offered(ctx: Context): Offered {\n const get = ctx.get as (service: string) => unknown\n return {\n tools: namesOf(get('tools'), 'list', 'name'),\n widgets: namesOf(get('home'), 'widgets', 'id'),\n }\n}\n\nexport function apply(ctx: Context): void {\n const cards = (): ShowcaseCard[] => showcaseCards(ctx.pluginShare.list(), offered(ctx))\n\n // The pages that follow the stream; each gets the cards again after every change, rendered for the path it is served at.\n const listeners = new Set<(now: readonly ShowcaseCard[]) => void>()\n const ends = new Set<() => void>()\n ctx.on('extensions/changed', () => {\n if (listeners.size === 0) return\n const now = cards()\n for (const listener of listeners) listener(now)\n })\n ctx.effect(\n () => () => {\n for (const end of ends) end()\n },\n 'showcase: end the open streams',\n )\n\n const app = new Acryl()\n .get('/showcase', (c) =>\n c.html(renderPage(cards(), appBase(c.req.path)), 200, { 'cache-control': 'no-store' }),\n )\n .get('/showcase/plugins', (c) => c.json(cards(), 200, { 'cache-control': 'no-store' }))\n .get('/showcase/events', (c) =>\n streamSSE(c, async (stream) => {\n const base = appBase(c.req.path)\n let queue: Promise<unknown> = Promise.resolve()\n const send = (now: readonly ShowcaseCard[]): void => {\n queue = queue\n .then(() => stream.writeSSE({ event: 'cards', data: renderCards(now, base) }))\n .catch(() => undefined)\n }\n let finish = (): void => undefined\n const ended = new Promise<void>((resolve) => {\n finish = resolve\n stream.onAbort(resolve)\n })\n ends.add(finish)\n listeners.add(send)\n send(cards())\n const keepAlive = setInterval(() => {\n queue = queue.then(() => stream.write(': keepalive\\n\\n')).catch(() => undefined)\n }, KEEP_ALIVE_MS)\n keepAlive.unref()\n try {\n await ended\n } finally {\n clearInterval(keepAlive)\n listeners.delete(send)\n ends.delete(finish)\n await queue\n }\n }),\n )\n ctx.router.route('/', app)\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The showcase's cards: what each plugin in the app is, who made it and where to find what it adds. Pure, so the page, the stream and the tests
|
|
3
|
+
* render the same thing.
|
|
4
|
+
*/
|
|
5
|
+
import type { SharedPluginInfo } from '@acryldev/plugin-share';
|
|
6
|
+
/** One plugin as the showcase shows it. */
|
|
7
|
+
export interface ShowcaseCard {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
/** The release's version, or the installed content's short digest for a plugin without one. */
|
|
10
|
+
readonly version: string;
|
|
11
|
+
readonly state: string;
|
|
12
|
+
/** The GitHub login of whoever released it; absent for a plugin made in this app or pulled from a local file. */
|
|
13
|
+
readonly author?: string;
|
|
14
|
+
/** Where it came from: the pulled source, or `this app`. */
|
|
15
|
+
readonly source: string;
|
|
16
|
+
/** The pages it serves (`GET` routes without parameters), as the plugin wrote them. */
|
|
17
|
+
readonly pages: readonly string[];
|
|
18
|
+
/** It has a widget on the home page. */
|
|
19
|
+
readonly widget: boolean;
|
|
20
|
+
/** The tool of its name, when it registered one. */
|
|
21
|
+
readonly tool?: string;
|
|
22
|
+
}
|
|
23
|
+
/** What else the app knows about its plugins: the tools registered and the home page's widgets, by name. */
|
|
24
|
+
export interface Offered {
|
|
25
|
+
readonly tools: readonly string[];
|
|
26
|
+
readonly widgets: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
/** The cards, one per plugin, in the order the app lists them. */
|
|
29
|
+
export declare function showcaseCards(plugins: readonly SharedPluginInfo[], offered: Offered): ShowcaseCard[];
|
|
30
|
+
/**
|
|
31
|
+
* The path the app is served at, read from the showcase's own request path: `''` on the app's own server, `/app` in the frame. Links are built from it,
|
|
32
|
+
* because a relative link cannot name the app's root (`./` from `/app/showcase` is `/app/`, which the app does not serve).
|
|
33
|
+
*/
|
|
34
|
+
export declare function appBase(requestPath: string): string;
|
|
35
|
+
/** The cards as HTML: the list the page shows, and what the stream sends on each change. Every value is escaped. */
|
|
36
|
+
export declare function renderCards(cards: readonly ShowcaseCard[], base?: string): string;
|
|
37
|
+
/** The whole page; the script follows the stream and replaces the cards on each change. */
|
|
38
|
+
export declare function renderPage(cards: readonly ShowcaseCard[], base?: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The collective app's showcase: every plugin in the app as a card (name, author, version, source, state, links to what it adds) at `/showcase`,
|
|
3
|
+
* updated live as plugins are pulled and removed.
|
|
4
|
+
*
|
|
5
|
+
* A group pulls its members' plugins into one app (`plugin pull --from group.txt`); this page is where they see what the group made. It reads the
|
|
6
|
+
* app's plugins through `pluginShare` (which knows where each pulled one came from), and follows `extensions/changed`: every install, update,
|
|
7
|
+
* restore and removal goes through extensions, so one event covers them all. The stream's open connections end with the plugin.
|
|
8
|
+
*/
|
|
9
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
10
|
+
export type { ShowcaseCard } from './cards.ts';
|
|
11
|
+
export { appBase, renderCards, showcaseCards } from './cards.ts';
|
|
12
|
+
export declare const name = "showcase";
|
|
13
|
+
export declare const inject: string[];
|
|
14
|
+
export declare function apply(ctx: Context): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acryldev/showcase",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The collective app's showcase: a page at /showcase with a card for every plugin in the app (name, author, version, where it came from, its state, and links to its pages, its home widget and its tool), updated live as plugins are pulled and removed.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/acryldev/acryl.git",
|
|
9
|
+
"directory": "plugins/showcase"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/acryldev/acryl/tree/main/plugins/showcase#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/acryldev/acryl/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": "^22.19.0 || >=24.0.0"
|
|
18
|
+
},
|
|
19
|
+
"main": "./lib/index.js",
|
|
20
|
+
"types": "./lib/types/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./lib/types/index.d.ts",
|
|
24
|
+
"default": "./lib/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@acryldev/extensions": "0.1.0",
|
|
30
|
+
"@acryldev/plugin-share": "0.1.0",
|
|
31
|
+
"@acryldev/router": "0.1.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@deepseek-ai/cordis": "^4.0.2"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@deepseek-ai/cordis": "4.0.4",
|
|
38
|
+
"@types/node": "^22.20.0",
|
|
39
|
+
"@acryldev/builder": "0.1.0",
|
|
40
|
+
"@acryldev/home": "0.1.0",
|
|
41
|
+
"@acryldev/instance": "0.1.1",
|
|
42
|
+
"@acryldev/plugin-hub-core": "^0.2.2",
|
|
43
|
+
"tsdown": "0.22.2",
|
|
44
|
+
"typescript": "6.0.3"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsdown && tsc -p tsconfig.json --emitDeclarationOnly"
|
|
48
|
+
}
|
|
6
49
|
}
|
package/plugin.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "showcase",
|
|
3
|
+
"description": "The collective app's showcase: a page at /showcase with a card for every plugin in the app (name, author, version, where it came from, its state, and links to its pages, its home widget and its tool), updated live as plugins are pulled and removed.",
|
|
4
|
+
"requires": ["router", "plugin-share", "extensions"],
|
|
5
|
+
"inject": ["router", "pluginShare"],
|
|
6
|
+
"provides": [],
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@deepseek-ai/cordis": "4.0.4"
|
|
9
|
+
},
|
|
10
|
+
"mount": "a row `- id: showcase` / `name: showcase` after the plugin-share row in blend.yaml, and 'showcase': showcase in the registry of src/app.ts (acrylblends add showcase does both)",
|
|
11
|
+
"entries": {
|
|
12
|
+
"": "index.ts"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { afterEach, test } from 'node:test'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
import { routeSource } from '@acryldev/builder/script'
|
|
8
|
+
import { extensions } from '@acryldev/extensions'
|
|
9
|
+
import * as home from '@acryldev/home'
|
|
10
|
+
import { instance, pinnedInstance } from '@acryldev/instance'
|
|
11
|
+
import { packFolder, type ReleasePort } from '@acryldev/plugin-hub-core'
|
|
12
|
+
import { type PullResult, pluginShare, type SharedPluginInfo } from '@acryldev/plugin-share'
|
|
13
|
+
import * as router from '@acryldev/router'
|
|
14
|
+
import { Context } from '@deepseek-ai/cordis'
|
|
15
|
+
import * as showcase from '../index.ts'
|
|
16
|
+
|
|
17
|
+
const cleanup: Array<() => Promise<void> | void> = []
|
|
18
|
+
afterEach(async () => {
|
|
19
|
+
for (const step of cleanup.splice(0)) await step()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const scratch = (prefix: string): string => {
|
|
23
|
+
const dir = mkdtempSync(join(tmpdir(), prefix))
|
|
24
|
+
cleanup.push(() => rmSync(dir, { recursive: true, force: true }))
|
|
25
|
+
return dir
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A released plugin's tarball, packed the way `package_plugin` packs it. */
|
|
29
|
+
function release(name: string, files: Record<string, string>): Uint8Array {
|
|
30
|
+
const dir = scratch('showcase-source-')
|
|
31
|
+
const all = {
|
|
32
|
+
'package.json': `${JSON.stringify({ name, version: '1.0.0', type: 'module', keywords: ['cordis-plugin', 'acrylblends'] }, null, 2)}\n`,
|
|
33
|
+
...files,
|
|
34
|
+
}
|
|
35
|
+
for (const [path, content] of Object.entries(all)) {
|
|
36
|
+
mkdirSync(join(dir, path, '..'), { recursive: true })
|
|
37
|
+
writeFileSync(join(dir, path), content)
|
|
38
|
+
}
|
|
39
|
+
return packFolder(dir).tarball
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** A plugin that puts a widget on the home page and serves nothing of its own. */
|
|
43
|
+
const WIDGET = `export const name = 'board'
|
|
44
|
+
export const inject = ['home']
|
|
45
|
+
export function apply(ctx) {
|
|
46
|
+
ctx.effect(() => ctx.home.widget({ id: 'board', title: 'Board', render: () => '<p>board</p>' }))
|
|
47
|
+
}
|
|
48
|
+
`
|
|
49
|
+
|
|
50
|
+
async function boot(releases: ReleasePort, before?: (ctx: Context) => void) {
|
|
51
|
+
const root = scratch('showcase-root-')
|
|
52
|
+
// The app's own framework copy, as every real app has installed (the scaffold's package.json depends on it).
|
|
53
|
+
mkdirSync(join(root, 'node_modules', '@acryldev'), { recursive: true })
|
|
54
|
+
symlinkSync(
|
|
55
|
+
fileURLToPath(new URL('../../../framework/packages/framework', import.meta.url)),
|
|
56
|
+
join(root, 'node_modules', '@acryldev', 'blends'),
|
|
57
|
+
'dir',
|
|
58
|
+
)
|
|
59
|
+
// The app's definition, where a pull records where each plugin came from.
|
|
60
|
+
writeFileSync(
|
|
61
|
+
join(root, 'blend.yaml'),
|
|
62
|
+
'apiVersion: blends.acryl.dev/v1alpha1\nkind: Blueprint\nmetadata: { id: group.collective, name: collective, version: 0.1.0 }\nspec:\n runtime: cordis\n rows:\n - id: router\n name: "@acryldev/router"\n - id: extensions\n name: extensions\n - id: plugin-share\n name: plugin-share\n - id: showcase\n name: showcase\n',
|
|
63
|
+
)
|
|
64
|
+
const app = new Context()
|
|
65
|
+
const fibers = [
|
|
66
|
+
app.plugin(instance, pinnedInstance(join(root, '.acrylblends'), { root })),
|
|
67
|
+
app.plugin(router),
|
|
68
|
+
...(before === undefined ? [app.plugin(home)] : []),
|
|
69
|
+
app.plugin(extensions, { sources: [{ dir: join(root, 'plugins'), trust: 'install' }] }),
|
|
70
|
+
app.plugin(pluginShare, { releases }),
|
|
71
|
+
]
|
|
72
|
+
for (const fiber of fibers) await fiber.await()
|
|
73
|
+
before?.(app)
|
|
74
|
+
const shown = app.plugin(showcase)
|
|
75
|
+
await shown.await()
|
|
76
|
+
fibers.push(shown)
|
|
77
|
+
cleanup.push(async () => {
|
|
78
|
+
for (const fiber of [...fibers].reverse()) await fiber.dispose()
|
|
79
|
+
})
|
|
80
|
+
const share = (
|
|
81
|
+
app as unknown as {
|
|
82
|
+
pluginShare: {
|
|
83
|
+
pull(source: string): Promise<PullResult>
|
|
84
|
+
remove(name: string): Promise<unknown>
|
|
85
|
+
list(): SharedPluginInfo[]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
).pluginShare
|
|
89
|
+
const request = (path: string) =>
|
|
90
|
+
(app as unknown as { router: { request(path: string): Promise<Response> } }).router.request(
|
|
91
|
+
path,
|
|
92
|
+
)
|
|
93
|
+
return { root, share, request, shown, app }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Reads a server-sent event stream one `cards` event at a time. */
|
|
97
|
+
function events(response: Response) {
|
|
98
|
+
const reader = (response.body as ReadableStream<Uint8Array>).getReader()
|
|
99
|
+
const decoder = new TextDecoder()
|
|
100
|
+
let buffer = ''
|
|
101
|
+
return {
|
|
102
|
+
async next(): Promise<string | undefined> {
|
|
103
|
+
for (;;) {
|
|
104
|
+
const end = buffer.indexOf('\n\n')
|
|
105
|
+
if (end !== -1) {
|
|
106
|
+
const block = buffer.slice(0, end)
|
|
107
|
+
buffer = buffer.slice(end + 2)
|
|
108
|
+
if (!block.startsWith('event: cards')) continue
|
|
109
|
+
return block
|
|
110
|
+
.split('\n')
|
|
111
|
+
.filter((line) => line.startsWith('data:'))
|
|
112
|
+
.map((line) => line.slice(5).replace(/^ /u, ''))
|
|
113
|
+
.join('\n')
|
|
114
|
+
}
|
|
115
|
+
const { value, done } = await reader.read()
|
|
116
|
+
if (done) return undefined
|
|
117
|
+
buffer += decoder.decode(value, { stream: true })
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
cancel: () => reader.cancel(),
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
test('a card names the plugin, its author, version, source and state, and links only to what a person can open', () => {
|
|
125
|
+
const info = (over: Partial<SharedPluginInfo>): SharedPluginInfo => ({
|
|
126
|
+
name: 'hello',
|
|
127
|
+
source: '/app/plugins/hello',
|
|
128
|
+
version: '1.0.0',
|
|
129
|
+
state: 'active',
|
|
130
|
+
missing: [],
|
|
131
|
+
stale: false,
|
|
132
|
+
routes: [],
|
|
133
|
+
...over,
|
|
134
|
+
})
|
|
135
|
+
const cards = showcase.showcaseCards(
|
|
136
|
+
[
|
|
137
|
+
info({
|
|
138
|
+
pulledFrom: 'github:inboxxobni/hello@1.0.0',
|
|
139
|
+
author: 'inboxxobni',
|
|
140
|
+
release: '1.0.0',
|
|
141
|
+
version: 'fcea2718d21e',
|
|
142
|
+
routes: [
|
|
143
|
+
{ method: 'GET', path: '/hello' },
|
|
144
|
+
{ method: 'POST', path: '/hello' },
|
|
145
|
+
{ method: 'GET', path: '/hello/:id' },
|
|
146
|
+
{ method: 'GET', path: '/hello' },
|
|
147
|
+
],
|
|
148
|
+
}),
|
|
149
|
+
info({ name: 'adder', routes: [] }),
|
|
150
|
+
info({ name: 'x<y', author: 'not a login/..', pulledFrom: 'https://example.test/<x>.tgz' }),
|
|
151
|
+
],
|
|
152
|
+
{ tools: ['adder'], widgets: ['hello'] },
|
|
153
|
+
)
|
|
154
|
+
assert.deepEqual(cards, [
|
|
155
|
+
{
|
|
156
|
+
name: 'hello',
|
|
157
|
+
version: '1.0.0',
|
|
158
|
+
state: 'active',
|
|
159
|
+
author: 'inboxxobni',
|
|
160
|
+
source: 'github:inboxxobni/hello@1.0.0',
|
|
161
|
+
pages: ['/hello'],
|
|
162
|
+
widget: true,
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
name: 'adder',
|
|
166
|
+
version: '1.0.0',
|
|
167
|
+
state: 'active',
|
|
168
|
+
source: 'this app',
|
|
169
|
+
pages: [],
|
|
170
|
+
widget: false,
|
|
171
|
+
tool: 'adder',
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: 'x<y',
|
|
175
|
+
version: '1.0.0',
|
|
176
|
+
state: 'active',
|
|
177
|
+
source: 'https://example.test/<x>.tgz',
|
|
178
|
+
pages: [],
|
|
179
|
+
widget: false,
|
|
180
|
+
},
|
|
181
|
+
])
|
|
182
|
+
const html = showcase.renderCards(cards)
|
|
183
|
+
assert.match(html, /<a href="\/hello">\/hello<\/a> <a href="\/">home widget<\/a>/u)
|
|
184
|
+
// In the frame the app is served at /app: its root is /app itself (the app does not serve /app/), its pages are under it.
|
|
185
|
+
assert.match(
|
|
186
|
+
showcase.renderCards(cards, '/app'),
|
|
187
|
+
/<a href="\/app\/hello">\/hello<\/a> <a href="\/app">home widget<\/a>/u,
|
|
188
|
+
)
|
|
189
|
+
assert.equal(showcase.appBase('/showcase'), '')
|
|
190
|
+
assert.equal(showcase.appBase('/showcase/events'), '')
|
|
191
|
+
assert.equal(showcase.appBase('/app/showcase'), '/app')
|
|
192
|
+
assert.equal(showcase.appBase('/app/showcase/events'), '/app')
|
|
193
|
+
assert.match(
|
|
194
|
+
html,
|
|
195
|
+
/<a href="https:\/\/github\.com\/inboxxobni" target="_blank" rel="noopener">@inboxxobni<\/a>/u,
|
|
196
|
+
)
|
|
197
|
+
assert.match(html, /tool <code>adder<\/code>/u)
|
|
198
|
+
assert.match(html, /<h2>x<y<\/h2>/u)
|
|
199
|
+
assert.match(html, /https:\/\/example\.test\/<x>\.tgz/u)
|
|
200
|
+
assert.doesNotMatch(html, /<x>|x<y/u)
|
|
201
|
+
assert.match(showcase.renderCards([]), /No plugins yet/u)
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
test('the page and its stream follow every pull and removal, and the streams end with the plugin', async () => {
|
|
205
|
+
const tarballs: Record<string, Uint8Array> = {
|
|
206
|
+
hello: release('hello', { 'index.ts': routeSource('hello', '/hello', 'Hello') }),
|
|
207
|
+
board: release('board', { 'index.ts': WIDGET }),
|
|
208
|
+
}
|
|
209
|
+
const { share, request, shown } = await boot({
|
|
210
|
+
release: async (_owner, repo) => ({
|
|
211
|
+
tag: 'v1.0.0',
|
|
212
|
+
assets: [{ name: `${repo}-1.0.0.tgz`, url: repo }],
|
|
213
|
+
}),
|
|
214
|
+
download: async (url) => tarballs[url] as Uint8Array,
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
const page = await request('/showcase')
|
|
218
|
+
assert.equal(page.status, 200)
|
|
219
|
+
const text = await page.text()
|
|
220
|
+
assert.match(text, /<title>Showcase<\/title>/u)
|
|
221
|
+
assert.match(text, /No plugins yet/u)
|
|
222
|
+
assert.match(text, /new EventSource\("\/showcase\/events"\)/u)
|
|
223
|
+
|
|
224
|
+
const stream = events(await request('/showcase/events'))
|
|
225
|
+
assert.match((await stream.next()) ?? '', /No plugins yet/u)
|
|
226
|
+
|
|
227
|
+
const pulled = await share.pull('github:inboxxobni/hello@1.0.0')
|
|
228
|
+
assert.ok(pulled.ok, JSON.stringify(pulled))
|
|
229
|
+
const afterHello = (await stream.next()) ?? ''
|
|
230
|
+
assert.match(afterHello, /data-plugin="hello" data-state="active"/u)
|
|
231
|
+
assert.match(afterHello, /<span class="version">1\.0\.0<\/span>/u)
|
|
232
|
+
assert.match(afterHello, /@inboxxobni/u)
|
|
233
|
+
assert.match(afterHello, /<a href="\/hello">\/hello<\/a>/u)
|
|
234
|
+
|
|
235
|
+
const board = await share.pull('github:someone-else/board@1.0.0')
|
|
236
|
+
assert.ok(board.ok, JSON.stringify(board))
|
|
237
|
+
const afterBoard = (await stream.next()) ?? ''
|
|
238
|
+
assert.match(afterBoard, /data-plugin="board"[\s\S]*@someone-else[\s\S]*home widget/u)
|
|
239
|
+
|
|
240
|
+
assert.deepEqual(
|
|
241
|
+
((await (await request('/showcase/plugins')).json()) as showcase.ShowcaseCard[]).map((card) => [
|
|
242
|
+
card.name,
|
|
243
|
+
card.author,
|
|
244
|
+
card.pages,
|
|
245
|
+
card.widget,
|
|
246
|
+
]),
|
|
247
|
+
[
|
|
248
|
+
['board', 'someone-else', [], true],
|
|
249
|
+
['hello', 'inboxxobni', ['/hello'], false],
|
|
250
|
+
],
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
await share.remove('hello')
|
|
254
|
+
const afterRemove = (await stream.next()) ?? ''
|
|
255
|
+
assert.doesNotMatch(afterRemove, /data-plugin="hello"/u)
|
|
256
|
+
assert.match(afterRemove, /data-plugin="board"/u)
|
|
257
|
+
|
|
258
|
+
// Switched off, the plugin ends the open streams and its routes go.
|
|
259
|
+
await shown.dispose()
|
|
260
|
+
assert.equal(await stream.next(), undefined)
|
|
261
|
+
assert.equal((await request('/showcase')).status, 404)
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
test("a service of the same name with another shape (the frame host's tools) leaves the cards answering", async () => {
|
|
265
|
+
const { request } = await boot(
|
|
266
|
+
{ release: async () => undefined, download: async () => new Uint8Array() },
|
|
267
|
+
(ctx) => {
|
|
268
|
+
// As the DSH harness's tool registry is in the frame: `tools` with no list(); and a `home` whose widgets() throws.
|
|
269
|
+
ctx.provide('tools', { register: () => () => undefined })
|
|
270
|
+
ctx.provide('home', {
|
|
271
|
+
widgets: () => {
|
|
272
|
+
throw new Error('not this home')
|
|
273
|
+
},
|
|
274
|
+
})
|
|
275
|
+
},
|
|
276
|
+
)
|
|
277
|
+
const answered = await request('/showcase/plugins')
|
|
278
|
+
assert.equal(answered.status, 200)
|
|
279
|
+
assert.deepEqual(await answered.json(), [])
|
|
280
|
+
})
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2024",
|
|
4
|
+
"lib": ["ES2024", "DOM", "DOM.Iterable"],
|
|
5
|
+
"module": "NodeNext",
|
|
6
|
+
"moduleResolution": "NodeNext",
|
|
7
|
+
"allowImportingTsExtensions": true,
|
|
8
|
+
"erasableSyntaxOnly": true,
|
|
9
|
+
"rootDir": ".",
|
|
10
|
+
"outDir": "lib",
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"declarationDir": "lib/types",
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"strict": true,
|
|
15
|
+
"noImplicitOverride": true,
|
|
16
|
+
"verbatimModuleSyntax": true,
|
|
17
|
+
"skipLibCheck": true,
|
|
18
|
+
"types": ["node"]
|
|
19
|
+
},
|
|
20
|
+
"include": ["*.ts"]
|
|
21
|
+
}
|
package/tsdown.config.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { defineConfig } from 'tsdown'
|
|
3
|
+
|
|
4
|
+
/** The package's importable files, exactly as `plugin.json`'s `entries` names them (the copy path uses the same table). */
|
|
5
|
+
const { entries } = JSON.parse(readFileSync(new URL('./plugin.json', import.meta.url), 'utf8')) as {
|
|
6
|
+
entries: Record<string, string>
|
|
7
|
+
}
|
|
8
|
+
const entry = Object.fromEntries(
|
|
9
|
+
Object.entries(entries).map(([, file]) => [file.replace(/.ts$/, ''), file]),
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
export default defineConfig({
|
|
13
|
+
name: '@acryldev/showcase',
|
|
14
|
+
entry,
|
|
15
|
+
outDir: 'lib',
|
|
16
|
+
format: 'esm',
|
|
17
|
+
platform: 'node',
|
|
18
|
+
target: 'es2024',
|
|
19
|
+
fixedExtension: false,
|
|
20
|
+
dts: false,
|
|
21
|
+
clean: true,
|
|
22
|
+
sourcemap: true,
|
|
23
|
+
})
|
package/README.md
DELETED