@chainingintention/pi-web-cn 1.202606.5 → 1.202606.7
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/README.md +1 -1
- package/dist/client/assets/{CodeViewer-DRxmEzh1.js → CodeViewer-8znVN61S.js} +1 -1
- package/dist/client/assets/{TerminalPanel-BcGKwlLZ.js → TerminalPanel-DrdWnF1y.js} +1 -1
- package/dist/client/assets/index-BiGrW6IC.js +2169 -0
- package/dist/client/index.html +1 -1
- package/dist/plugin-api.d.ts +17 -11
- package/dist/server/app.js +7 -0
- package/dist/server/app.js.map +1 -1
- package/dist/server/machines/machinePluginProxyRoutes.js +179 -0
- package/dist/server/machines/machinePluginProxyRoutes.js.map +1 -0
- package/dist/server/machines/machineProxyRoutes.js +1 -0
- package/dist/server/machines/machineProxyRoutes.js.map +1 -1
- package/dist/server/managementEmbed.js +45 -15
- package/dist/server/managementEmbed.js.map +1 -1
- package/dist/server/sessions/piSessionService.js +19 -5
- package/dist/server/sessions/piSessionService.js.map +1 -1
- package/dist/server/sessions/sessionNameGenerator.js +2 -0
- package/dist/server/sessions/sessionNameGenerator.js.map +1 -1
- package/dist/server/sessions/sessionRoutes.js +1 -1
- package/dist/server/sessions/sessionRoutes.js.map +1 -1
- package/dist/server/terminalProxyRoutes.js +10 -0
- package/dist/server/terminalProxyRoutes.js.map +1 -1
- package/dist/server/terminals/terminalRoutes.js +11 -0
- package/dist/server/terminals/terminalRoutes.js.map +1 -1
- package/dist/server/terminals/terminalService.js +6 -0
- package/dist/server/terminals/terminalService.js.map +1 -1
- package/dist/server/workspaceExplorerRoutes.js +86 -0
- package/dist/server/workspaceExplorerRoutes.js.map +1 -1
- package/dist/server/workspaces/fileOperationService.js +95 -0
- package/dist/server/workspaces/fileOperationService.js.map +1 -0
- package/dist/server/workspaces/fileUploadService.js +23 -0
- package/dist/server/workspaces/fileUploadService.js.map +1 -0
- package/dist/server/workspaces/workspaceDeletionRoutes.js +127 -0
- package/dist/server/workspaces/workspaceDeletionRoutes.js.map +1 -0
- package/dist/shared/apiTypes.d.ts +12 -0
- package/dist/shared/federatedRoutes.js +9 -0
- package/dist/shared/federatedRoutes.js.map +1 -1
- package/dist/shared/machinePluginIds.js +41 -0
- package/dist/shared/machinePluginIds.js.map +1 -0
- package/dist/shared/workspaceDeletion.js +12 -0
- package/dist/shared/workspaceDeletion.js.map +1 -0
- package/docs/plugins.md +88 -12
- package/package.json +1 -1
- package/dist/client/assets/index-BZE2v69K.js +0 -2002
package/docs/plugins.md
CHANGED
|
@@ -22,7 +22,7 @@ Plugins run as JavaScript in the browser app. Treat them as trusted code:
|
|
|
22
22
|
- they can render arbitrary Lit templates/custom elements in plugin contribution areas;
|
|
23
23
|
- they should not be installed from untrusted sources.
|
|
24
24
|
|
|
25
|
-
PI WEB's `/api/...` HTTP and WebSocket endpoints are internal implementation details. Plugin code should
|
|
25
|
+
PI WEB's `/api/...` HTTP and WebSocket endpoints are internal implementation details. Plugin code should use the documented context helpers instead. Daring plugins can still reach private routes or runtime objects because they run in the browser, but those private surfaces are experimental: they may graduate into stable helpers, change shape, or disappear.
|
|
26
26
|
|
|
27
27
|
## What to ask AI to build
|
|
28
28
|
|
|
@@ -129,9 +129,30 @@ ln -s /path/to/plugin-folder ~/.pi-web/plugins/plugin-id
|
|
|
129
129
|
|
|
130
130
|
Reload the PI WEB browser tab. PI WEB serves plugin modules with an mtime-based `?v=` cache buster. After editing a plugin, hard reload the browser if you do not see changes.
|
|
131
131
|
|
|
132
|
+
## Remote machine plugins
|
|
133
|
+
|
|
134
|
+
When [machine federation](https://pi-web.dev/machines.html) is enabled, PI WEB also loads discovered plugins from the selected remote machine. Remote plugins are trusted browser-side code like local plugins, but their contributions are machine-scoped:
|
|
135
|
+
|
|
136
|
+
- actions, workspace panels, and workspace labels only appear while that machine is selected;
|
|
137
|
+
- plugin file and terminal helpers run against that machine;
|
|
138
|
+
- plugin code is loaded best-effort through the current gateway and cached for the browser page lifetime;
|
|
139
|
+
- if the gateway already has an enabled plugin with the same original id, the gateway plugin wins and the remote duplicate stays hidden;
|
|
140
|
+
- remote theme contributions are ignored for now because themes are app-wide;
|
|
141
|
+
- mixed PI WEB versions across federated machines are best-effort and not guaranteed compatible.
|
|
142
|
+
|
|
143
|
+
Remote plugin enablement is controlled by the remote machine's PI WEB plugin config. To edit or disable a remote machine plugin, open that machine directly or update its config file.
|
|
144
|
+
|
|
145
|
+
For portable plugin assets, prefer URLs relative to the plugin module, for example:
|
|
146
|
+
|
|
147
|
+
```js
|
|
148
|
+
const url = new URL("./asset.json", import.meta.url);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
If a remote plugin constructs absolute asset URLs, it should use the `pluginId` from `activate()` because PI WEB gives remote plugins a gateway-scoped runtime id. Hard-coded `/pi-web-plugins/<original-id>/...` URLs may point at the gateway instead of the remote machine.
|
|
152
|
+
|
|
132
153
|
## Manage plugins
|
|
133
154
|
|
|
134
|
-
Open **Settings → Plugins** to review discovered bundled, local, dev, and Pi package plugins. PI WEB can disable any discovered plugin before the browser imports it. Core app contributions such as the built-in command palette, base workspace tools, and themes are not managed through this plugin list.
|
|
155
|
+
Open **Settings → Plugins** to review discovered bundled, local, dev, and Pi package plugins for the PI WEB gateway you opened. PI WEB can disable any discovered gateway plugin before the browser imports it. Core app contributions such as the built-in command palette, base workspace tools, and themes are not managed through this plugin list.
|
|
135
156
|
|
|
136
157
|
Plugin preferences are stored under the top-level `plugins` config key in the PI WEB config file:
|
|
137
158
|
|
|
@@ -161,7 +182,7 @@ Built-in plugins can be managed from **Settings → Plugins** or with the top-le
|
|
|
161
182
|
|
|
162
183
|
### Updates
|
|
163
184
|
|
|
164
|
-
**Plugin id:** `updates`
|
|
185
|
+
**Plugin id:** `updates`
|
|
165
186
|
**What it does:** adds a conditional **Updates** workspace tab with PI WEB update, restart, and installed-service guidance.
|
|
166
187
|
|
|
167
188
|
Updates is enabled by default. To hide it, disable `updates` in **Settings → Plugins** or set:
|
|
@@ -176,8 +197,8 @@ Updates is enabled by default. To hide it, disable `updates` in **Settings → P
|
|
|
176
197
|
|
|
177
198
|
### Workspace Tasks
|
|
178
199
|
|
|
179
|
-
**Plugin id:** `workspace-tasks`
|
|
180
|
-
**Config file:** `.pi-web/tasks.json`
|
|
200
|
+
**Plugin id:** `workspace-tasks`
|
|
201
|
+
**Config file:** `.pi-web/tasks.json`
|
|
181
202
|
**What it does:** adds a **Tasks** workspace tab for running configured shell commands in dedicated PI WEB terminals.
|
|
182
203
|
|
|
183
204
|
Workspace Tasks is enabled by default. To hide it, disable `workspace-tasks` in **Settings → Plugins** or set:
|
|
@@ -231,7 +252,7 @@ Review task configs before running them, especially in shared projects. Workspac
|
|
|
231
252
|
|
|
232
253
|
## Discovery and packaging
|
|
233
254
|
|
|
234
|
-
PI WEB builds `/pi-web-plugins/manifest.json` from these sources:
|
|
255
|
+
PI WEB builds the gateway `/pi-web-plugins/manifest.json` from these sources:
|
|
235
256
|
|
|
236
257
|
1. Bundled plugins in the PI WEB package:
|
|
237
258
|
|
|
@@ -249,6 +270,8 @@ PI WEB builds `/pi-web-plugins/manifest.json` from these sources:
|
|
|
249
270
|
|
|
250
271
|
3. Installed Pi packages that expose PI WEB plugin metadata. Pi packages may be user or project scoped.
|
|
251
272
|
|
|
273
|
+
Remote machines expose their own manifests through the gateway at `/api/machines/<machine-id>/pi-web-plugins/manifest.json`. Those plugin modules are rewritten to gateway-scoped asset URLs and registered under machine-scoped runtime ids so duplicate plugin ids on different machines do not collide.
|
|
274
|
+
|
|
252
275
|
Plugin package directory names and plugin ids must be valid identifiers:
|
|
253
276
|
|
|
254
277
|
```text
|
|
@@ -428,7 +451,7 @@ Notes:
|
|
|
428
451
|
|
|
429
452
|
- `state` is a snapshot of current UI state when actions are built.
|
|
430
453
|
- The stable state fields are `state.selectedWorkspace`, `state.selectedSession`, and `state.piWebStatus`.
|
|
431
|
-
- Other `state` fields may exist at runtime, but they are PI WEB internals
|
|
454
|
+
- Other `state` fields may exist at runtime, but they are private PI WEB internals that may graduate into stable helpers, change shape, or disappear.
|
|
432
455
|
- `enabled` is evaluated when the action palette asks for actions.
|
|
433
456
|
- `selectWorkspaceTool()` expects a qualified panel id such as `my-plugin:workspace.info`.
|
|
434
457
|
- `openTerminal()` switches to the built-in terminal panel. Pass `{ terminalId }` to deep-link to a specific terminal.
|
|
@@ -511,6 +534,8 @@ interface WorkspacePanelContext {
|
|
|
511
534
|
|
|
512
535
|
`machine`, `workspace`, `files`, `terminal`, and `host` are documented as stable for panel callbacks. Use `terminal.open()` to switch to the built-in terminal panel; pass `{ terminalId }` to deep-link to a specific terminal. Call `host.requestRender()` when async plugin-owned state changes should make PI WEB re-evaluate panel callbacks such as `badge`, `visible`, or `render`.
|
|
513
536
|
|
|
537
|
+
For compatibility, PI WEB still provides the old `context.openTerminal()` workspace-panel helper at runtime. It is deprecated, intentionally omitted from the public TypeScript declarations, and planned for removal in v2. Existing JavaScript plugins keep working, while typed plugins should migrate to `context.terminal.open()`.
|
|
538
|
+
|
|
514
539
|
Useful workspace and machine shapes:
|
|
515
540
|
|
|
516
541
|
```ts
|
|
@@ -573,12 +598,18 @@ interface WorkspaceLabelContext {
|
|
|
573
598
|
machine: PluginMachine;
|
|
574
599
|
workspace: Workspace;
|
|
575
600
|
state?: PluginRuntimeState;
|
|
601
|
+
files: {
|
|
602
|
+
readFile(path: string): Promise<FileContentResponse>;
|
|
603
|
+
};
|
|
604
|
+
host: {
|
|
605
|
+
requestRender(): void;
|
|
606
|
+
};
|
|
576
607
|
}
|
|
577
608
|
```
|
|
578
609
|
|
|
579
|
-
`machine` and `
|
|
610
|
+
`machine`, `workspace`, `files`, and `host` are documented as stable for label callbacks. Include `machine.id` in any label caches that depend on workspace data. Call `host.requestRender()` when async plugin-owned state changes should make PI WEB re-evaluate label `visible` or `items` callbacks.
|
|
580
611
|
|
|
581
|
-
Items are sorted by `order` and then id. Return an empty array to render nothing.
|
|
612
|
+
Items are sorted by `order` and then id. Return an empty array to render nothing. Keep callbacks synchronous and lightweight; start async work from the callback, return cached items, then call `host.requestRender()` when the cache changes.
|
|
582
613
|
|
|
583
614
|
#### Text items
|
|
584
615
|
|
|
@@ -638,7 +669,7 @@ export default {
|
|
|
638
669
|
|
|
639
670
|
## Reading workspace files
|
|
640
671
|
|
|
641
|
-
Workspace panels can read files through the documented `files` helper. PI WEB binds this helper to the
|
|
672
|
+
Workspace panels and workspace labels can read files through the documented `files` helper. PI WEB binds this helper to the callback's machine and workspace, so it works the same for local and federated machines.
|
|
642
673
|
|
|
643
674
|
```js
|
|
644
675
|
workspacePanels: [
|
|
@@ -668,6 +699,51 @@ class MyEnvViewer extends HTMLElement {
|
|
|
668
699
|
}
|
|
669
700
|
```
|
|
670
701
|
|
|
702
|
+
Labels should use the same helper through a plugin-owned cache because `items()` itself must return synchronously:
|
|
703
|
+
|
|
704
|
+
```js
|
|
705
|
+
const envCache = new Map();
|
|
706
|
+
|
|
707
|
+
function envKey(machine, workspace) {
|
|
708
|
+
return `${machine.id}:${workspace.id}:docker/development.be-go.local.env`;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
function loadEnvLabel(context) {
|
|
712
|
+
const key = envKey(context.machine, context.workspace);
|
|
713
|
+
const cached = envCache.get(key);
|
|
714
|
+
if (cached !== undefined) return cached;
|
|
715
|
+
|
|
716
|
+
const pending = { status: "loading", label: undefined };
|
|
717
|
+
envCache.set(key, pending);
|
|
718
|
+
context.files.readFile("docker/development.be-go.local.env")
|
|
719
|
+
.then((file) => {
|
|
720
|
+
pending.status = "ready";
|
|
721
|
+
pending.label = file.content.match(/^DEV_URL=(.+)$/m)?.[1];
|
|
722
|
+
context.host.requestRender();
|
|
723
|
+
})
|
|
724
|
+
.catch(() => {
|
|
725
|
+
pending.status = "missing";
|
|
726
|
+
context.host.requestRender();
|
|
727
|
+
});
|
|
728
|
+
return pending;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
workspaceLabels: [
|
|
732
|
+
{
|
|
733
|
+
id: "dev-url",
|
|
734
|
+
items: (context) => {
|
|
735
|
+
const cached = loadEnvLabel(context);
|
|
736
|
+
return cached.label === undefined ? [] : [{
|
|
737
|
+
type: "link",
|
|
738
|
+
text: cached.label,
|
|
739
|
+
href: cached.label,
|
|
740
|
+
target: "_blank",
|
|
741
|
+
}];
|
|
742
|
+
},
|
|
743
|
+
},
|
|
744
|
+
]
|
|
745
|
+
```
|
|
746
|
+
|
|
671
747
|
The file response includes fields such as `path`, `content`, `truncated`, and `binary`. Be careful with sensitive files such as `.env`: plugins are trusted browser code, and file contents are exposed to the plugin.
|
|
672
748
|
|
|
673
749
|
## Running workspace terminal commands
|
|
@@ -687,9 +763,9 @@ render: ({ terminal }) => html`
|
|
|
687
763
|
|
|
688
764
|
Review command strings carefully. They are trusted shell commands executed in the workspace terminal.
|
|
689
765
|
|
|
690
|
-
##
|
|
766
|
+
## Private and experimental PI WEB APIs
|
|
691
767
|
|
|
692
|
-
PI WEB's `/api/...` HTTP and WebSocket routes are private implementation details.
|
|
768
|
+
PI WEB's `/api/...` HTTP and WebSocket routes and runtime-only fields are private implementation details. They exist because plugins are trusted browser code, and because some capabilities may be evaluated there before they are designed as stable helpers.
|
|
693
769
|
|
|
694
770
|
If a plugin author deliberately chooses to depend on an unstable runtime field while a public helper is still being designed, make that decision explicit in code with a type-only unstable import and a local type assertion:
|
|
695
771
|
|
package/package.json
CHANGED