@puredesktop/create-app 2.1.5 → 2.1.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/bin/create-puredesktop-app.mjs +319 -319
- package/package.json +1 -1
- package/template/README.md +52 -52
- package/template/agents.md +11 -11
- package/template/docs/README.md +30 -30
- package/template/docs/agent.md +58 -58
- package/template/docs/app-lifecycle.md +60 -60
- package/template/docs/bridge/README.md +84 -84
- package/template/docs/bridge/dialog.md +56 -56
- package/template/docs/bridge/fs.md +95 -95
- package/template/docs/bridge/network.md +38 -38
- package/template/docs/bridge/settings.md +63 -63
- package/template/docs/bridge/storage.md +48 -48
- package/template/docs/plugin-manifest.md +104 -104
- package/template/docs/theme-vars.md +79 -79
- package/template/docs/tool-handlers.md +122 -122
- package/template/docs/ui-and-components.md +57 -56
- package/template/package.json +10 -10
- package/template/plugin.json +20 -20
- package/template/src/App.tsx +4 -4
- package/template/src/bridge/platformBridge.ts +122 -122
- package/template/src/components/AppShell.tsx +9 -9
package/package.json
CHANGED
package/template/README.md
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
# {{APP_TITLE}}
|
|
2
|
-
|
|
3
|
-
Vite + React plugin app for **PureDesktop**, scaffolded with
|
|
4
|
-
`@puredesktop/create-app`.
|
|
5
|
-
|
|
6
|
-
## Start
|
|
7
|
-
|
|
8
|
-
```bash
|
|
9
|
-
npm install
|
|
10
|
-
npm run dev
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
The dev server runs at `http://localhost:{{APP_PORT}}`, matching
|
|
14
|
-
`plugin.json`.
|
|
15
|
-
|
|
16
|
-
In PureDesktop, register the app from **File -> Register App...** with the same
|
|
17
|
-
entrypoint URL.
|
|
18
|
-
|
|
19
|
-
## Build
|
|
20
|
-
|
|
21
|
-
```bash
|
|
1
|
+
# {{APP_TITLE}}
|
|
2
|
+
|
|
3
|
+
Vite + React plugin app for **PureDesktop**, scaffolded with
|
|
4
|
+
`@puredesktop/create-app`.
|
|
5
|
+
|
|
6
|
+
## Start
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install
|
|
10
|
+
npm run dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The dev server runs at `http://localhost:{{APP_PORT}}`, matching
|
|
14
|
+
`plugin.json`.
|
|
15
|
+
|
|
16
|
+
In PureDesktop, register the app from **File -> Register App...** with the same
|
|
17
|
+
entrypoint URL.
|
|
18
|
+
|
|
19
|
+
## Build
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
22
|
npm run typecheck
|
|
23
|
-
npm run build
|
|
24
|
-
npm run puredesktop:check
|
|
25
|
-
```
|
|
26
|
-
|
|
23
|
+
npm run build
|
|
24
|
+
npm run puredesktop:check
|
|
25
|
+
```
|
|
26
|
+
|
|
27
27
|
`puredesktop:check` verifies the package facts the shell needs before
|
|
28
28
|
registration: manifest shape, entrypoint, permissions, `agents.md`, build output,
|
|
29
29
|
and declared app agent tools.
|
|
30
|
-
|
|
31
|
-
## Project Layout
|
|
32
|
-
|
|
33
|
-
- `plugin.json`: app identity, permissions, entrypoint, routing, and agent tool
|
|
34
|
-
declarations.
|
|
35
|
-
- `agents.md`: app-scoped assistant prompt.
|
|
36
|
-
- `src/App.tsx`: bridge and boot gates wrapped in `AppFrame`.
|
|
37
|
-
- `src/bridge/platformBridge.ts`: local app bridge exports.
|
|
38
|
-
- `src/hooks/useAppBoot.ts`: boot data loading after bridge readiness.
|
|
39
|
-
- `src/components/AppShell.tsx`: first app-owned UI surface.
|
|
40
|
-
- `docs/`: builder-facing app, bridge, agent, and tool-handler docs.
|
|
41
|
-
|
|
42
|
-
## Builder Docs
|
|
43
|
-
|
|
44
|
-
Read [docs/README.md](./docs/README.md) before changing app structure.
|
|
45
|
-
|
|
46
|
-
Bridge helper docs live in [docs/bridge/README.md](./docs/bridge/README.md).
|
|
47
|
-
|
|
48
|
-
## Core Rules
|
|
49
|
-
|
|
50
|
-
- `plugin.json` `app.slug` matches `src/constants.ts` `APP_SLUG`.
|
|
51
|
-
- `plugin.json` `entrypoint.url` matches the Vite dev port.
|
|
52
|
-
- `app.usePureDesktopAiPanel` stays `true` for shell-owned agent UI.
|
|
53
|
-
- `agents.md` stays at the package root for app-scoped sessions.
|
|
54
|
-
- Bridge calls stay inside `src/bridge/platformBridge.ts` or files owned by
|
|
55
|
-
`src/bridge/`.
|
|
56
|
-
- `AppFrame` wraps every `src/App.tsx` return path.
|
|
30
|
+
|
|
31
|
+
## Project Layout
|
|
32
|
+
|
|
33
|
+
- `plugin.json`: app identity, permissions, entrypoint, routing, and agent tool
|
|
34
|
+
declarations.
|
|
35
|
+
- `agents.md`: app-scoped assistant prompt.
|
|
36
|
+
- `src/App.tsx`: bridge and boot gates wrapped in `AppFrame`.
|
|
37
|
+
- `src/bridge/platformBridge.ts`: local app bridge exports.
|
|
38
|
+
- `src/hooks/useAppBoot.ts`: boot data loading after bridge readiness.
|
|
39
|
+
- `src/components/AppShell.tsx`: first app-owned UI surface.
|
|
40
|
+
- `docs/`: builder-facing app, bridge, agent, and tool-handler docs.
|
|
41
|
+
|
|
42
|
+
## Builder Docs
|
|
43
|
+
|
|
44
|
+
Read [docs/README.md](./docs/README.md) before changing app structure.
|
|
45
|
+
|
|
46
|
+
Bridge helper docs live in [docs/bridge/README.md](./docs/bridge/README.md).
|
|
47
|
+
|
|
48
|
+
## Core Rules
|
|
49
|
+
|
|
50
|
+
- `plugin.json` `app.slug` matches `src/constants.ts` `APP_SLUG`.
|
|
51
|
+
- `plugin.json` `entrypoint.url` matches the Vite dev port.
|
|
52
|
+
- `app.usePureDesktopAiPanel` stays `true` for shell-owned agent UI.
|
|
53
|
+
- `agents.md` stays at the package root for app-scoped sessions.
|
|
54
|
+
- Bridge calls stay inside `src/bridge/platformBridge.ts` or files owned by
|
|
55
|
+
`src/bridge/`.
|
|
56
|
+
- `AppFrame` wraps every `src/App.tsx` return path.
|
package/template/agents.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# {{APP_TITLE}} Agent
|
|
2
|
-
|
|
3
|
-
You are the app-scoped assistant for {{APP_TITLE}}.
|
|
4
|
-
|
|
5
|
-
Help the user understand, review, and act on the work inside this app. Stay
|
|
6
|
-
grounded in the app UI and data. Prefer concise answers, concrete next actions,
|
|
7
|
-
and safe tool use.
|
|
8
|
-
|
|
9
|
-
When tools are available, use read-only tools before write tools. Ask for
|
|
10
|
-
confirmation before destructive or external-effect changes unless the tool
|
|
11
|
-
policy already requires approval.
|
|
1
|
+
# {{APP_TITLE}} Agent
|
|
2
|
+
|
|
3
|
+
You are the app-scoped assistant for {{APP_TITLE}}.
|
|
4
|
+
|
|
5
|
+
Help the user understand, review, and act on the work inside this app. Stay
|
|
6
|
+
grounded in the app UI and data. Prefer concise answers, concrete next actions,
|
|
7
|
+
and safe tool use.
|
|
8
|
+
|
|
9
|
+
When tools are available, use read-only tools before write tools. Ask for
|
|
10
|
+
confirmation before destructive or external-effect changes unless the tool
|
|
11
|
+
policy already requires approval.
|
package/template/docs/README.md
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
# PureDesktop App Builder Docs
|
|
2
|
-
|
|
3
|
-
This folder is the builder-facing contract for generated PureDesktop apps.
|
|
4
|
-
|
|
5
|
-
A generated app is a Vite + React application rendered by PureDesktop inside a
|
|
6
|
-
workspace iframe. The app owns its UI, state, domain logic, and optional tool
|
|
7
|
-
handlers. The shell owns discovery, tabs, bridge permissions, filesystem and OS
|
|
8
|
-
services, agent sessions, and app registration.
|
|
9
|
-
|
|
10
|
-
Read these in order when building or repairing an app:
|
|
11
|
-
|
|
12
|
-
1. [App lifecycle](./app-lifecycle.md)
|
|
13
|
-
2. [Plugin manifest](./plugin-manifest.md)
|
|
14
|
-
3. [Bridge helpers](./bridge/README.md)
|
|
15
|
-
4. [App agent](./agent.md)
|
|
16
|
-
5. [Tool handlers](./tool-handlers.md)
|
|
17
|
-
6. [UI and components](./ui-and-components.md)
|
|
18
|
-
7. [Theme CSS variables](./theme-vars.md)
|
|
19
|
-
|
|
20
|
-
Key files in this scaffold:
|
|
21
|
-
|
|
22
|
-
- `plugin.json`: app identity, entrypoint, permissions, file routing, and agent
|
|
23
|
-
tool declarations.
|
|
24
|
-
- `agents.md`: app-scoped assistant instructions used by shell agent sessions.
|
|
25
|
-
- `src/App.tsx`: bridge readiness, boot loading, and `AppFrame` wrapper.
|
|
26
|
-
- `src/bridge/platformBridge.ts`: local app bridge surface.
|
|
27
|
-
- `src/hooks/useAppBoot.ts`: app boot data loading after the bridge is ready.
|
|
28
|
-
- `src/components/AppShell.tsx`: first app-owned UI surface.
|
|
1
|
+
# PureDesktop App Builder Docs
|
|
2
|
+
|
|
3
|
+
This folder is the builder-facing contract for generated PureDesktop apps.
|
|
4
|
+
|
|
5
|
+
A generated app is a Vite + React application rendered by PureDesktop inside a
|
|
6
|
+
workspace iframe. The app owns its UI, state, domain logic, and optional tool
|
|
7
|
+
handlers. The shell owns discovery, tabs, bridge permissions, filesystem and OS
|
|
8
|
+
services, agent sessions, and app registration.
|
|
9
|
+
|
|
10
|
+
Read these in order when building or repairing an app:
|
|
11
|
+
|
|
12
|
+
1. [App lifecycle](./app-lifecycle.md)
|
|
13
|
+
2. [Plugin manifest](./plugin-manifest.md)
|
|
14
|
+
3. [Bridge helpers](./bridge/README.md)
|
|
15
|
+
4. [App agent](./agent.md)
|
|
16
|
+
5. [Tool handlers](./tool-handlers.md)
|
|
17
|
+
6. [UI and components](./ui-and-components.md)
|
|
18
|
+
7. [Theme CSS variables](./theme-vars.md)
|
|
19
|
+
|
|
20
|
+
Key files in this scaffold:
|
|
21
|
+
|
|
22
|
+
- `plugin.json`: app identity, entrypoint, permissions, file routing, and agent
|
|
23
|
+
tool declarations.
|
|
24
|
+
- `agents.md`: app-scoped assistant instructions used by shell agent sessions.
|
|
25
|
+
- `src/App.tsx`: bridge readiness, boot loading, and `AppFrame` wrapper.
|
|
26
|
+
- `src/bridge/platformBridge.ts`: local app bridge surface.
|
|
27
|
+
- `src/hooks/useAppBoot.ts`: app boot data loading after the bridge is ready.
|
|
28
|
+
- `src/components/AppShell.tsx`: first app-owned UI surface.
|
|
29
29
|
- `scripts/validate-puredesktop-app.mjs`: registration and tool scaffold check.
|
|
30
|
-
|
|
31
|
-
Use `npm run puredesktop:check` after `npm run build` before registration.
|
|
30
|
+
|
|
31
|
+
Use `npm run puredesktop:check` after `npm run build` before registration.
|
package/template/docs/agent.md
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
# App Agent
|
|
2
|
-
|
|
3
|
-
Every generated app has an app-scoped assistant that runs in the shell agent
|
|
4
|
-
drawer. The app does not render its own agent chat UI by default.
|
|
5
|
-
|
|
6
|
-
## Source Files
|
|
7
|
-
|
|
8
|
-
- `agents.md`: app-scoped assistant prompt.
|
|
9
|
-
- `plugin.json` `app.agents.tools`: tool schemas exposed to the agent.
|
|
10
|
-
- `src/agents/*`: generated app-owned tool catalog and handlers when tools
|
|
11
|
-
exist.
|
|
12
|
-
- `src/hooks/useAppAgentTools.ts`: generated runtime registration hook when
|
|
13
|
-
tools exist.
|
|
14
|
-
|
|
15
|
-
## How The Agent Uses App Tools
|
|
16
|
-
|
|
17
|
-
1. The shell reads `plugin.json` and includes declared app tools in the app
|
|
18
|
-
agent's available tools.
|
|
19
|
-
2. The app iframe loads and registers runtime handlers with
|
|
20
|
-
`usePlatformAgentTools`.
|
|
21
|
-
3. The agent calls a declared tool during a shell-managed session.
|
|
22
|
-
4. The shell routes the invocation to the app iframe.
|
|
23
|
-
5. The app handler returns compact text or JSON.
|
|
24
|
-
6. The bridge helper completes the tool call back to the shell.
|
|
25
|
-
7. The shell resumes the agent session.
|
|
26
|
-
|
|
27
|
-
The app owns the handler implementation. The shell owns session state,
|
|
28
|
-
approvals, routing, and completion.
|
|
29
|
-
|
|
30
|
-
When `plugin.json` contains `app.agents.tools`, the create-app generator writes
|
|
31
|
-
the initial catalog, handler map, and registration hook. The generated handlers
|
|
32
|
-
return explicit not-implemented tool errors until the app replaces them with real
|
|
33
|
-
domain behavior.
|
|
34
|
-
|
|
35
|
-
## agents.md
|
|
36
|
-
|
|
37
|
-
Keep `agents.md` grounded in the app's real UI and data. Mention the app's work
|
|
38
|
-
objects, read-first workflow, write safety rules, and expected concise output.
|
|
39
|
-
|
|
40
|
-
Example:
|
|
41
|
-
|
|
42
|
-
```md
|
|
43
|
-
# {{APP_TITLE}} Agent
|
|
44
|
-
|
|
45
|
-
You are the app-scoped assistant for {{APP_TITLE}}.
|
|
46
|
-
|
|
47
|
-
Help the user understand, review, and act on the work inside this app. Stay
|
|
48
|
-
grounded in the app UI and data. Prefer concise answers, concrete next actions,
|
|
49
|
-
and safe tool use.
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Approval Policy
|
|
53
|
-
|
|
54
|
-
Set `requiresApproval` on each manifest tool. Read-only inspection tools usually
|
|
55
|
-
set `false`. Destructive, external-effect, or broad write tools set `true`.
|
|
56
|
-
|
|
57
|
-
The shell drawer displays approvals and resumes the same session after the user
|
|
58
|
-
approves or rejects.
|
|
1
|
+
# App Agent
|
|
2
|
+
|
|
3
|
+
Every generated app has an app-scoped assistant that runs in the shell agent
|
|
4
|
+
drawer. The app does not render its own agent chat UI by default.
|
|
5
|
+
|
|
6
|
+
## Source Files
|
|
7
|
+
|
|
8
|
+
- `agents.md`: app-scoped assistant prompt.
|
|
9
|
+
- `plugin.json` `app.agents.tools`: tool schemas exposed to the agent.
|
|
10
|
+
- `src/agents/*`: generated app-owned tool catalog and handlers when tools
|
|
11
|
+
exist.
|
|
12
|
+
- `src/hooks/useAppAgentTools.ts`: generated runtime registration hook when
|
|
13
|
+
tools exist.
|
|
14
|
+
|
|
15
|
+
## How The Agent Uses App Tools
|
|
16
|
+
|
|
17
|
+
1. The shell reads `plugin.json` and includes declared app tools in the app
|
|
18
|
+
agent's available tools.
|
|
19
|
+
2. The app iframe loads and registers runtime handlers with
|
|
20
|
+
`usePlatformAgentTools`.
|
|
21
|
+
3. The agent calls a declared tool during a shell-managed session.
|
|
22
|
+
4. The shell routes the invocation to the app iframe.
|
|
23
|
+
5. The app handler returns compact text or JSON.
|
|
24
|
+
6. The bridge helper completes the tool call back to the shell.
|
|
25
|
+
7. The shell resumes the agent session.
|
|
26
|
+
|
|
27
|
+
The app owns the handler implementation. The shell owns session state,
|
|
28
|
+
approvals, routing, and completion.
|
|
29
|
+
|
|
30
|
+
When `plugin.json` contains `app.agents.tools`, the create-app generator writes
|
|
31
|
+
the initial catalog, handler map, and registration hook. The generated handlers
|
|
32
|
+
return explicit not-implemented tool errors until the app replaces them with real
|
|
33
|
+
domain behavior.
|
|
34
|
+
|
|
35
|
+
## agents.md
|
|
36
|
+
|
|
37
|
+
Keep `agents.md` grounded in the app's real UI and data. Mention the app's work
|
|
38
|
+
objects, read-first workflow, write safety rules, and expected concise output.
|
|
39
|
+
|
|
40
|
+
Example:
|
|
41
|
+
|
|
42
|
+
```md
|
|
43
|
+
# {{APP_TITLE}} Agent
|
|
44
|
+
|
|
45
|
+
You are the app-scoped assistant for {{APP_TITLE}}.
|
|
46
|
+
|
|
47
|
+
Help the user understand, review, and act on the work inside this app. Stay
|
|
48
|
+
grounded in the app UI and data. Prefer concise answers, concrete next actions,
|
|
49
|
+
and safe tool use.
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Approval Policy
|
|
53
|
+
|
|
54
|
+
Set `requiresApproval` on each manifest tool. Read-only inspection tools usually
|
|
55
|
+
set `false`. Destructive, external-effect, or broad write tools set `true`.
|
|
56
|
+
|
|
57
|
+
The shell drawer displays approvals and resumes the same session after the user
|
|
58
|
+
approves or rejects.
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
# App Lifecycle
|
|
2
|
-
|
|
3
|
-
A PureDesktop app is loaded into an iframe by the shell. The shell discovers the
|
|
4
|
-
app from `plugin.json`, opens a workspace tab, loads the entrypoint URL or built
|
|
5
|
-
static bundle, then establishes the bridge handshake with the iframe.
|
|
6
|
-
|
|
7
|
-
## Registration To Render
|
|
8
|
-
|
|
9
|
-
1. The shell scans installed app folders for `plugin.json`.
|
|
10
|
-
2. The catalog creates one app entry from `plugin.json` `app.slug`.
|
|
11
|
-
3. Opening the app creates a workspace tab.
|
|
12
|
-
4. The tab renders the app entrypoint in an iframe.
|
|
13
|
-
5. The iframe starts React from `src/main.tsx`.
|
|
14
|
-
6. `src/App.tsx` calls `usePlatformBridge()`.
|
|
15
|
-
7. The bridge client sends a handshake to the shell parent window.
|
|
16
|
-
8. The shell replies with `ready` metadata, including `pluginId`, `appSlug`,
|
|
17
|
-
allowed method names, theme CSS, and optional viewport resource.
|
|
18
|
-
9. The app boot hook loads app settings and other startup data.
|
|
19
|
-
10. The app renders inside `AppFrame`.
|
|
20
|
-
|
|
21
|
-
## App.tsx Contract
|
|
22
|
-
|
|
23
|
-
`src/App.tsx` is the orchestration boundary. Keep it thin:
|
|
24
|
-
|
|
25
|
-
- call `usePlatformBridge()`;
|
|
26
|
-
- allow standalone browser dev mode when needed;
|
|
27
|
-
- call the app boot hook after the bridge is ready;
|
|
28
|
-
- render loading and error states inside `AppFrame`;
|
|
29
|
-
- render the app shell inside `AppFrame` after boot succeeds.
|
|
30
|
-
|
|
31
|
-
The template already follows this shape.
|
|
32
|
-
|
|
33
|
-
## Viewport Resources
|
|
34
|
-
|
|
35
|
-
When the shell opens a file or app resource into a tab, the bridge ready metadata
|
|
36
|
-
can include:
|
|
37
|
-
|
|
38
|
-
```ts
|
|
39
|
-
{
|
|
40
|
-
viewport: {
|
|
41
|
-
tabId: string
|
|
42
|
-
resource: { path: string; name: string; kind: string } | null
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
File-centric apps use `usePlatformViewportResource(ready, meta)` from the bridge
|
|
48
|
-
React helpers. This handles cold opens and warm `resource.open` events without
|
|
49
|
-
duplicating event wiring in screens.
|
|
50
|
-
|
|
51
|
-
## Standalone Dev
|
|
52
|
-
|
|
53
|
-
The template supports browser-only development with:
|
|
54
|
-
|
|
55
|
-
```ts
|
|
56
|
-
window.parent === window
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
Standalone mode is for UI iteration. Production app behavior runs inside the
|
|
60
|
-
shell iframe and uses shell bridge permissions.
|
|
1
|
+
# App Lifecycle
|
|
2
|
+
|
|
3
|
+
A PureDesktop app is loaded into an iframe by the shell. The shell discovers the
|
|
4
|
+
app from `plugin.json`, opens a workspace tab, loads the entrypoint URL or built
|
|
5
|
+
static bundle, then establishes the bridge handshake with the iframe.
|
|
6
|
+
|
|
7
|
+
## Registration To Render
|
|
8
|
+
|
|
9
|
+
1. The shell scans installed app folders for `plugin.json`.
|
|
10
|
+
2. The catalog creates one app entry from `plugin.json` `app.slug`.
|
|
11
|
+
3. Opening the app creates a workspace tab.
|
|
12
|
+
4. The tab renders the app entrypoint in an iframe.
|
|
13
|
+
5. The iframe starts React from `src/main.tsx`.
|
|
14
|
+
6. `src/App.tsx` calls `usePlatformBridge()`.
|
|
15
|
+
7. The bridge client sends a handshake to the shell parent window.
|
|
16
|
+
8. The shell replies with `ready` metadata, including `pluginId`, `appSlug`,
|
|
17
|
+
allowed method names, theme CSS, and optional viewport resource.
|
|
18
|
+
9. The app boot hook loads app settings and other startup data.
|
|
19
|
+
10. The app renders inside `AppFrame`.
|
|
20
|
+
|
|
21
|
+
## App.tsx Contract
|
|
22
|
+
|
|
23
|
+
`src/App.tsx` is the orchestration boundary. Keep it thin:
|
|
24
|
+
|
|
25
|
+
- call `usePlatformBridge()`;
|
|
26
|
+
- allow standalone browser dev mode when needed;
|
|
27
|
+
- call the app boot hook after the bridge is ready;
|
|
28
|
+
- render loading and error states inside `AppFrame`;
|
|
29
|
+
- render the app shell inside `AppFrame` after boot succeeds.
|
|
30
|
+
|
|
31
|
+
The template already follows this shape.
|
|
32
|
+
|
|
33
|
+
## Viewport Resources
|
|
34
|
+
|
|
35
|
+
When the shell opens a file or app resource into a tab, the bridge ready metadata
|
|
36
|
+
can include:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
{
|
|
40
|
+
viewport: {
|
|
41
|
+
tabId: string
|
|
42
|
+
resource: { path: string; name: string; kind: string } | null
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
File-centric apps use `usePlatformViewportResource(ready, meta)` from the bridge
|
|
48
|
+
React helpers. This handles cold opens and warm `resource.open` events without
|
|
49
|
+
duplicating event wiring in screens.
|
|
50
|
+
|
|
51
|
+
## Standalone Dev
|
|
52
|
+
|
|
53
|
+
The template supports browser-only development with:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
window.parent === window
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Standalone mode is for UI iteration. Production app behavior runs inside the
|
|
60
|
+
shell iframe and uses shell bridge permissions.
|
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
# Platform Bridge Helpers
|
|
2
|
-
|
|
3
|
-
The bridge is the app iframe's RPC channel to the PureDesktop shell.
|
|
4
|
-
|
|
5
|
-
The generated app runs in an iframe. It cannot call shell internals directly.
|
|
6
|
-
Instead, app code imports helpers from `src/bridge/platformBridge.ts`. That
|
|
7
|
-
local bridge module wraps the package bridge client from
|
|
8
|
-
`@puredesktop/puredesktop-ui-bridge`.
|
|
9
|
-
|
|
10
|
-
## Runtime Boundary
|
|
11
|
-
|
|
12
|
-
```text
|
|
13
|
-
App iframe -> bridge helper -> postMessage -> shell renderer -> shell handler
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
The shell validates the app origin, method name, and `plugin.json` permissions
|
|
17
|
-
before running a handler.
|
|
18
|
-
|
|
19
|
-
## Ready Handshake
|
|
20
|
-
|
|
21
|
-
`src/App.tsx` uses `usePlatformBridge()` to wait for the shell:
|
|
22
|
-
|
|
23
|
-
```ts
|
|
24
|
-
const { ready, error, meta } = usePlatformBridge()
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
The shell ready payload includes:
|
|
28
|
-
|
|
29
|
-
- `pluginId`: plugin package identity.
|
|
30
|
-
- `appSlug`: app API scope.
|
|
31
|
-
- `methods`: bridge methods available in this shell.
|
|
32
|
-
- `theme`: injected theme CSS.
|
|
33
|
-
- `viewport`: optional tab resource opened into the app.
|
|
34
|
-
|
|
35
|
-
Call bridge helpers after `ready` is true. The template boot hook follows that
|
|
36
|
-
pattern.
|
|
37
|
-
|
|
38
|
-
## Local Bridge Module
|
|
39
|
-
|
|
40
|
-
`src/bridge/platformBridge.ts` is the app's bridge boundary. Components and
|
|
41
|
-
feature code import from that local file:
|
|
42
|
-
|
|
43
|
-
```ts
|
|
44
|
-
import { fetchAppSettings, networkFetch } from '../bridge/platformBridge'
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
Keep request-shape knowledge in this bridge folder. Component code calls
|
|
48
|
-
domain-named helpers.
|
|
49
|
-
|
|
50
|
-
`platformBridge.ts` is both the exported app bridge surface and the place for
|
|
51
|
-
app-owned bridge wrappers. Package bridge helpers are imported as local bindings
|
|
52
|
-
first, then re-exported for app code. App-specific wrappers in this file should
|
|
53
|
-
call those local bindings.
|
|
54
|
-
|
|
55
|
-
## Helper Domains
|
|
56
|
-
|
|
57
|
-
- [Dialog](./dialog.md)
|
|
58
|
-
- [Filesystem](./fs.md)
|
|
59
|
-
- [Network](./network.md)
|
|
60
|
-
- [Settings](./settings.md)
|
|
61
|
-
- [Storage](./storage.md)
|
|
62
|
-
|
|
63
|
-
## Permissions
|
|
64
|
-
|
|
65
|
-
Bridge calls are gated by top-level `plugin.json` `permissions`.
|
|
66
|
-
|
|
67
|
-
| Permission | Helper domains |
|
|
68
|
-
| --- | --- |
|
|
69
|
-
| `settings` | settings and preferences |
|
|
70
|
-
| `filesystem` | filesystem, dialogs, storage, file routing |
|
|
71
|
-
| `network` | network requests and OAuth-style flows |
|
|
72
|
-
| `render` | print and render helpers |
|
|
73
|
-
| `assets` | asset library helpers |
|
|
74
|
-
| `agents` | agent sessions, agent tools, credentials |
|
|
75
|
-
|
|
76
|
-
## Events
|
|
77
|
-
|
|
78
|
-
The bridge also delivers shell events into the iframe. Common app events include
|
|
79
|
-
theme changes, viewport resource opens, render progress, filesystem watch
|
|
80
|
-
changes, agent run events, and app tool invocations.
|
|
81
|
-
|
|
82
|
-
Use the package React hooks when they exist. For example,
|
|
83
|
-
`usePlatformViewportResource(ready, meta)` handles file opens without manual
|
|
84
|
-
event wiring.
|
|
1
|
+
# Platform Bridge Helpers
|
|
2
|
+
|
|
3
|
+
The bridge is the app iframe's RPC channel to the PureDesktop shell.
|
|
4
|
+
|
|
5
|
+
The generated app runs in an iframe. It cannot call shell internals directly.
|
|
6
|
+
Instead, app code imports helpers from `src/bridge/platformBridge.ts`. That
|
|
7
|
+
local bridge module wraps the package bridge client from
|
|
8
|
+
`@puredesktop/puredesktop-ui-bridge`.
|
|
9
|
+
|
|
10
|
+
## Runtime Boundary
|
|
11
|
+
|
|
12
|
+
```text
|
|
13
|
+
App iframe -> bridge helper -> postMessage -> shell renderer -> shell handler
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The shell validates the app origin, method name, and `plugin.json` permissions
|
|
17
|
+
before running a handler.
|
|
18
|
+
|
|
19
|
+
## Ready Handshake
|
|
20
|
+
|
|
21
|
+
`src/App.tsx` uses `usePlatformBridge()` to wait for the shell:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
const { ready, error, meta } = usePlatformBridge()
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The shell ready payload includes:
|
|
28
|
+
|
|
29
|
+
- `pluginId`: plugin package identity.
|
|
30
|
+
- `appSlug`: app API scope.
|
|
31
|
+
- `methods`: bridge methods available in this shell.
|
|
32
|
+
- `theme`: injected theme CSS.
|
|
33
|
+
- `viewport`: optional tab resource opened into the app.
|
|
34
|
+
|
|
35
|
+
Call bridge helpers after `ready` is true. The template boot hook follows that
|
|
36
|
+
pattern.
|
|
37
|
+
|
|
38
|
+
## Local Bridge Module
|
|
39
|
+
|
|
40
|
+
`src/bridge/platformBridge.ts` is the app's bridge boundary. Components and
|
|
41
|
+
feature code import from that local file:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { fetchAppSettings, networkFetch } from '../bridge/platformBridge'
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Keep request-shape knowledge in this bridge folder. Component code calls
|
|
48
|
+
domain-named helpers.
|
|
49
|
+
|
|
50
|
+
`platformBridge.ts` is both the exported app bridge surface and the place for
|
|
51
|
+
app-owned bridge wrappers. Package bridge helpers are imported as local bindings
|
|
52
|
+
first, then re-exported for app code. App-specific wrappers in this file should
|
|
53
|
+
call those local bindings.
|
|
54
|
+
|
|
55
|
+
## Helper Domains
|
|
56
|
+
|
|
57
|
+
- [Dialog](./dialog.md)
|
|
58
|
+
- [Filesystem](./fs.md)
|
|
59
|
+
- [Network](./network.md)
|
|
60
|
+
- [Settings](./settings.md)
|
|
61
|
+
- [Storage](./storage.md)
|
|
62
|
+
|
|
63
|
+
## Permissions
|
|
64
|
+
|
|
65
|
+
Bridge calls are gated by top-level `plugin.json` `permissions`.
|
|
66
|
+
|
|
67
|
+
| Permission | Helper domains |
|
|
68
|
+
| --- | --- |
|
|
69
|
+
| `settings` | settings and preferences |
|
|
70
|
+
| `filesystem` | filesystem, dialogs, storage, file routing |
|
|
71
|
+
| `network` | network requests and OAuth-style flows |
|
|
72
|
+
| `render` | print and render helpers |
|
|
73
|
+
| `assets` | asset library helpers |
|
|
74
|
+
| `agents` | agent sessions, agent tools, credentials |
|
|
75
|
+
|
|
76
|
+
## Events
|
|
77
|
+
|
|
78
|
+
The bridge also delivers shell events into the iframe. Common app events include
|
|
79
|
+
theme changes, viewport resource opens, render progress, filesystem watch
|
|
80
|
+
changes, agent run events, and app tool invocations.
|
|
81
|
+
|
|
82
|
+
Use the package React hooks when they exist. For example,
|
|
83
|
+
`usePlatformViewportResource(ready, meta)` handles file opens without manual
|
|
84
|
+
event wiring.
|