@opencode/plugin 0.0.0-dev-55 → 0.0.0-dev-56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gui/browser.d.ts +36 -0
- package/dist/gui/browser.js +3 -0
- package/dist/gui/context.d.ts +223 -0
- package/dist/gui/context.js +0 -0
- package/dist/gui/core.d.ts +560 -0
- package/dist/gui/core.js +86 -0
- package/dist/gui/declarations.d.ts +24 -0
- package/dist/gui/declarations.js +0 -0
- package/dist/gui/file.d.ts +122 -0
- package/dist/gui/file.js +7 -0
- package/dist/gui/host-apis.d.ts +1109 -0
- package/dist/gui/host-apis.js +0 -0
- package/dist/gui/icon-name.d.ts +2 -0
- package/dist/gui/icon-name.js +1 -0
- package/dist/gui/index.d.ts +7 -0
- package/dist/gui/index.js +6 -0
- package/dist/gui/internal.d.ts +44 -0
- package/dist/gui/internal.js +33 -0
- package/dist/gui/main.d.ts +279 -0
- package/dist/gui/main.js +20 -0
- package/dist/gui/modules.d.ts +15 -0
- package/dist/gui/modules.js +30 -0
- package/dist/gui/plugin.d.ts +86 -0
- package/dist/gui/plugin.js +9 -0
- package/dist/gui/reactive.d.ts +93 -0
- package/dist/gui/reactive.js +130 -0
- package/dist/gui/registries.d.ts +770 -0
- package/dist/gui/registries.js +110 -0
- package/dist/gui/review.d.ts +73 -0
- package/dist/gui/review.js +3 -0
- package/dist/gui/scope.d.ts +64 -0
- package/dist/gui/scope.js +85 -0
- package/dist/gui/solid.d.ts +99 -0
- package/dist/gui/solid.js +74 -0
- package/dist/gui/vite.d.ts +24 -0
- package/dist/gui/vite.js +49 -0
- package/dist/host.d.ts +12 -1
- package/dist/host.js +34 -2
- package/dist/runtime-modules.js +3 -1
- package/package.json +54 -10
|
File without changes
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** An icon from the app's catalog, for SDK fields such as `SessionPanelMenuItem.icon`. */
|
|
2
|
+
export type IconName = "align-right" | "appearance" | "archive" | "arrow-down-to-line" | "arrow-left" | "arrow-right" | "arrow-undo-down" | "arrow-up" | "arrow-up-right" | "brain" | "branch" | "branch-out" | "bubble-5" | "bullet-list" | "check" | "check-small" | "checklist" | "chevron-double-right" | "chevron-down" | "chevron-grabber-vertical" | "chevron-left" | "chevron-right" | "circle-ban-sign" | "circle-check" | "circle-exclamation" | "circle-x" | "circle-xmark" | "close" | "close-small" | "cloud-upload" | "code" | "code-lines" | "code-slash" | "collapse" | "comment" | "console" | "copy" | "cube" | "dash" | "discord" | "dot-grid" | "download" | "edit" | "edit-small-2" | "enter" | "expand" | "extensions" | "eye" | "file-document" | "file-tree" | "file-tree-active" | "filetree" | "fill-triangle-down" | "flask" | "folder" | "folder-add-left" | "fork" | "github" | "glasses" | "globe" | "graduation-cap" | "grid-plus" | "help" | "info" | "keyboard" | "layout-bottom" | "layout-bottom-full" | "layout-bottom-partial" | "layout-left" | "layout-left-full" | "layout-left-partial" | "layout-right" | "layout-right-full" | "layout-right-partial" | "link" | "lock" | "magnifying-glass" | "magnifying-glass-menu" | "mcp" | "menu" | "minus" | "models" | "monitor" | "new-session" | "new-session-active" | "notifications" | "open-file" | "outline-arrow-left" | "outline-arrow-right" | "outline-arrow-to-corner-top-right" | "outline-arrow-up-right" | "outline-audio" | "outline-brain" | "outline-browser-annotate" | "outline-chevron-down" | "outline-chevron-right" | "outline-console" | "outline-cookie" | "outline-copy" | "outline-dots" | "outline-eye" | "outline-eye-slash" | "outline-globe" | "outline-globe-plus" | "outline-hexagonal-warning" | "outline-photo" | "outline-quote" | "outline-reset" | "outline-rotate-clockwise" | "outline-share" | "outline-sliders" | "outline-square-arrow" | "outline-steer" | "outline-text" | "outline-trash" | "outline-undo" | "outline-video" | "outline-wave-audio" | "outline-worktree" | "outline-xmark" | "pencil-line" | "photo" | "plus" | "plus-small" | "post-skill" | "prompt" | "providers" | "refresh" | "reset" | "review" | "review-active" | "select-element" | "selector" | "server" | "settings-gear" | "share" | "shield" | "sidebar" | "sidebar-active" | "sliders" | "speech-bubble" | "split" | "square-arrow-top-right" | "status" | "status-active" | "stop" | "task" | "terminal" | "terminal-active" | "trash" | "unified" | "warning" | "waveform" | "window-analytics" | "window-cursor" | "workspace" | "workspace-isolated" | "workspace-new" | "xmark-small";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Generated by `bun run generate` (script/icon-name.ts) from the app's icon catalog. Do not edit.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Accessor, type JSX } from "solid-js";
|
|
2
|
+
import type { Context } from "./context.js";
|
|
3
|
+
import type { Live } from "./core.js";
|
|
4
|
+
import type { PanelFrame } from "./solid.js";
|
|
5
|
+
/** The host provides this around every contribution it renders and in the plugin's setup. `usePlugin` reads it. */
|
|
6
|
+
export declare const PluginContext: import("solid-js").Context<Context | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* Marks a scope that ends before the plugin does, such as a `createKeyed` run. The host disposes at once a
|
|
9
|
+
* registration made in a scope that already ended.
|
|
10
|
+
*/
|
|
11
|
+
export declare const LifetimeContext: import("solid-js").Context<{
|
|
12
|
+
/** The scope has ended. */
|
|
13
|
+
readonly ended: boolean;
|
|
14
|
+
} | undefined>;
|
|
15
|
+
/** The host provides this around panel renders. `usePanel` reads it. */
|
|
16
|
+
export declare const PanelContext: import("solid-js").Context<PanelFrame | undefined>;
|
|
17
|
+
/** The host provides this around a panel it shows in a narrow-screen drawer (`MobileView.kind` `"drawer"`). */
|
|
18
|
+
export declare const DrawerContext: import("solid-js").Context<{
|
|
19
|
+
/** Closes the drawer. */
|
|
20
|
+
readonly close: () => void;
|
|
21
|
+
/** Shows content in place of the drawer's view, with a back control. */
|
|
22
|
+
readonly open: (view: {
|
|
23
|
+
/** The drawer's title while the content shows. */
|
|
24
|
+
readonly title: string;
|
|
25
|
+
/** The content to show. */
|
|
26
|
+
readonly content: JSX.Element;
|
|
27
|
+
/** The element that receives focus when the back control returns to the drawer's view. */
|
|
28
|
+
readonly trigger: HTMLElement;
|
|
29
|
+
}) => void;
|
|
30
|
+
} | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* Marks an accessor `ctx.use` returns, so `createKeyed` follows its generations.
|
|
33
|
+
*
|
|
34
|
+
* @param read - Returns the provider's current `Live` value, one object per transition.
|
|
35
|
+
* @returns The same function, marked.
|
|
36
|
+
*/
|
|
37
|
+
export declare function liveAccessor<T>(read: () => Live<T>): Accessor<Live<T>>;
|
|
38
|
+
/**
|
|
39
|
+
* Whether the host marked the accessor with `liveAccessor`.
|
|
40
|
+
*
|
|
41
|
+
* @param source - Any accessor.
|
|
42
|
+
* @returns True for the accessors `ctx.use` returns.
|
|
43
|
+
*/
|
|
44
|
+
export declare function isLiveAccessor(source: Accessor<unknown>): source is Accessor<Live<unknown>>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// The window host's internals that the public SDK's helpers read. `gui/host` re-exports them for the hosts; the
|
|
2
|
+
// public `@opencode/plugin/gui` does not.
|
|
3
|
+
import { createContext } from "solid-js";
|
|
4
|
+
/** The host provides this around every contribution it renders and in the plugin's setup. `usePlugin` reads it. */
|
|
5
|
+
export const PluginContext = createContext();
|
|
6
|
+
/**
|
|
7
|
+
* Marks a scope that ends before the plugin does, such as a `createKeyed` run. The host disposes at once a
|
|
8
|
+
* registration made in a scope that already ended.
|
|
9
|
+
*/
|
|
10
|
+
export const LifetimeContext = createContext();
|
|
11
|
+
/** The host provides this around panel renders. `usePanel` reads it. */
|
|
12
|
+
export const PanelContext = createContext();
|
|
13
|
+
/** The host provides this around a panel it shows in a narrow-screen drawer (`MobileView.kind` `"drawer"`). */
|
|
14
|
+
export const DrawerContext = createContext();
|
|
15
|
+
const live = Symbol.for("opencode.plugin.live");
|
|
16
|
+
/**
|
|
17
|
+
* Marks an accessor `ctx.use` returns, so `createKeyed` follows its generations.
|
|
18
|
+
*
|
|
19
|
+
* @param read - Returns the provider's current `Live` value, one object per transition.
|
|
20
|
+
* @returns The same function, marked.
|
|
21
|
+
*/
|
|
22
|
+
export function liveAccessor(read) {
|
|
23
|
+
return Object.assign(read, { [live]: true });
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Whether the host marked the accessor with `liveAccessor`.
|
|
27
|
+
*
|
|
28
|
+
* @param source - Any accessor.
|
|
29
|
+
* @returns True for the accessors `ctx.use` returns.
|
|
30
|
+
*/
|
|
31
|
+
export function isLiveAccessor(source) {
|
|
32
|
+
return live in source;
|
|
33
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import type { BrowserWindow, NativeImage, WebContentsView } from "electron";
|
|
2
|
+
import type { Schema } from "effect";
|
|
3
|
+
import { Registry, type BaseContext, type App, type Cleanup, type Ipc, type IpcImpl, type IpcProvider, type IpcSpec, type Persisted } from "./core.js";
|
|
4
|
+
export * from "./core.js";
|
|
5
|
+
export * as Plugin from "./plugin.js";
|
|
6
|
+
/** The app's main windows. */
|
|
7
|
+
export interface Windows {
|
|
8
|
+
/**
|
|
9
|
+
* A main window by id.
|
|
10
|
+
*
|
|
11
|
+
* @param id - The window's id, e.g. `Caller.window`.
|
|
12
|
+
*/
|
|
13
|
+
get(id: number): BrowserWindow | undefined;
|
|
14
|
+
/** Every open main window. */
|
|
15
|
+
list(): readonly BrowserWindow[];
|
|
16
|
+
/** The main window that had focus last. */
|
|
17
|
+
focused(): BrowserWindow | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Listens to windows opening or closing. The listener is removed when the instance goes away.
|
|
20
|
+
*
|
|
21
|
+
* @param event - `open`: a main window opened; `close`: one closed.
|
|
22
|
+
* @param handler - Receives the window.
|
|
23
|
+
* @returns Removes the listener early.
|
|
24
|
+
*/
|
|
25
|
+
on(event: "open" | "close", handler: (window: BrowserWindow) => void): Cleanup;
|
|
26
|
+
}
|
|
27
|
+
/** A web page placed in a window's layout. The window shows it with `Embeds.View`. */
|
|
28
|
+
export interface Embed {
|
|
29
|
+
/** The id a window passes to `Embeds.View` and `Embeds.capture`. */
|
|
30
|
+
readonly id: string;
|
|
31
|
+
/**
|
|
32
|
+
* Page-side gate. The view shows only while the renderer lays it out AND show(true).
|
|
33
|
+
*
|
|
34
|
+
* @param visible - Whether the page may show.
|
|
35
|
+
*/
|
|
36
|
+
show(visible: boolean): void;
|
|
37
|
+
/**
|
|
38
|
+
* Runs when the view goes on or off screen, including when the renderer paints a still in its place.
|
|
39
|
+
*
|
|
40
|
+
* @param event - `visible`.
|
|
41
|
+
* @param handler - Receives whether the view is on screen.
|
|
42
|
+
* @returns Removes the listener.
|
|
43
|
+
*/
|
|
44
|
+
on(event: "visible", handler: (visible: boolean) => void): Cleanup;
|
|
45
|
+
/** A still of the page; undefined while it is not shown. */
|
|
46
|
+
capture(): Promise<NativeImage | undefined>;
|
|
47
|
+
/** Removes the view from the window. The host also disposes it when the instance goes away. */
|
|
48
|
+
dispose(): void;
|
|
49
|
+
}
|
|
50
|
+
/** Places web pages (Electron WebContentsViews) in a window's layout. */
|
|
51
|
+
export interface Embeds {
|
|
52
|
+
/**
|
|
53
|
+
* A window shows it with the window SDK's `Embeds.View`; the host owns bounds, zoom, corners, and occlusion.
|
|
54
|
+
* Created after the instance went away, it is disposed at once.
|
|
55
|
+
*
|
|
56
|
+
* @param view - The page's view.
|
|
57
|
+
* @param window - The window it belongs to.
|
|
58
|
+
*/
|
|
59
|
+
create(view: WebContentsView, window: BrowserWindow): Embed;
|
|
60
|
+
}
|
|
61
|
+
/** Main-process storage, in the plugin's namespace (`plugin.<id>`), shared by every window. */
|
|
62
|
+
export interface Storage {
|
|
63
|
+
/**
|
|
64
|
+
* The window's `Persisted` shape, read and written synchronously: `value` is always defined and `ready()` always
|
|
65
|
+
* true. Values are stored as the schema's canonical JSON; the schema must not need services. A stored value that
|
|
66
|
+
* fails to decode reads as `initial`. Each write reaches the database before it returns. `update` changes a copy of
|
|
67
|
+
* the value through a deep-mutable draft; `set` replaces it, including a number, `null` or a new list.
|
|
68
|
+
*
|
|
69
|
+
* @param key - The store's key in your namespace.
|
|
70
|
+
* @param options - The store's options.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* const tabs = ctx.storage.store(`restore:${session}`, { schema: Tabs, initial: [] })
|
|
75
|
+
* tabs.set(next)
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
store<S extends Schema.ConstraintCodec<unknown, unknown>>(key: string, options: {
|
|
79
|
+
/** Decodes the stored JSON; any schema. */
|
|
80
|
+
readonly schema: S;
|
|
81
|
+
/** The value before anything is stored, and after `remove`. */
|
|
82
|
+
readonly initial: S["Type"];
|
|
83
|
+
}): Persisted<S["Type"], S["Type"]>;
|
|
84
|
+
/**
|
|
85
|
+
* Deletes the value, so opening the key again reads its `initial`.
|
|
86
|
+
*
|
|
87
|
+
* @param key - The store's key in your namespace.
|
|
88
|
+
*/
|
|
89
|
+
remove(key: string): void;
|
|
90
|
+
}
|
|
91
|
+
/** A server endpoint main can call, with its credentials. */
|
|
92
|
+
export interface ServerEndpoint {
|
|
93
|
+
/** The server's id, as the window's `ServerRef.id`. */
|
|
94
|
+
readonly id: string;
|
|
95
|
+
/** The base URL. */
|
|
96
|
+
readonly url: string;
|
|
97
|
+
/** Headers to send, with the `authorization` the server needs. */
|
|
98
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
99
|
+
/**
|
|
100
|
+
* The endpoint is this app's own server, so its paths are this machine's paths. Other servers on this machine, such
|
|
101
|
+
* as one in WSL or on another local port, report false.
|
|
102
|
+
*/
|
|
103
|
+
readonly sameMachine: boolean;
|
|
104
|
+
/** The password a window configured for the server; `headers` already carries it. None for the app's own server. */
|
|
105
|
+
readonly password?: string;
|
|
106
|
+
}
|
|
107
|
+
/** The opencode CLI the desktop app runs. */
|
|
108
|
+
export interface Cli {
|
|
109
|
+
/** The CLI's version. */
|
|
110
|
+
readonly version: string;
|
|
111
|
+
/** The argv that runs it: the executable, or a development command such as `bun run … src/index.ts`. */
|
|
112
|
+
readonly command: readonly string[];
|
|
113
|
+
/** The executable's path; undefined when it runs from source. */
|
|
114
|
+
readonly binary?: string;
|
|
115
|
+
/** An unpackaged app running the CLI from source. */
|
|
116
|
+
readonly development: boolean;
|
|
117
|
+
}
|
|
118
|
+
/** The server endpoints the app's windows use. */
|
|
119
|
+
export interface ServerEndpoints {
|
|
120
|
+
/**
|
|
121
|
+
* An endpoint by server id: "sidecar" for the app's own server, else a server a window lists. Undefined until that
|
|
122
|
+
* server is known (the sidecar is running, or a window reported the server).
|
|
123
|
+
*
|
|
124
|
+
* @param id - The server's id, as the window's `ServerRef.id`.
|
|
125
|
+
*/
|
|
126
|
+
get(id: string): ServerEndpoint | undefined;
|
|
127
|
+
}
|
|
128
|
+
/** The desktop log file. */
|
|
129
|
+
export interface Log {
|
|
130
|
+
/**
|
|
131
|
+
* Writes to the desktop log file (included in exported debug logs); each field of `data` is serialized as it is.
|
|
132
|
+
*
|
|
133
|
+
* @param level - `debug`, `info`, `warn` or `error`.
|
|
134
|
+
* @param message - A fixed message; put variable parts in `data`.
|
|
135
|
+
* @param data - Structured fields.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* ctx.log.write("warn", "update check failed", { error: String(cause) })
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
write<Data extends Readonly<Record<string, unknown>>>(level: "debug" | "info" | "warn" | "error", message: string, data?: Data): void;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The setup context in the main process. The APIs the host always provides are properties, each created on first
|
|
146
|
+
* read. Every main plugin is one instance for the whole app, shared by all windows.
|
|
147
|
+
*/
|
|
148
|
+
export interface MainContext extends BaseContext {
|
|
149
|
+
/**
|
|
150
|
+
* Runs `fn` when the plugin goes away, last registered first; at once when it is already gone. A setup may also
|
|
151
|
+
* return its cleanup.
|
|
152
|
+
*
|
|
153
|
+
* @param fn - The teardown; an async one delays quitting until it settles, for at most 3 seconds.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* ctx.onCleanup(() => watcher.close())
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
onCleanup(fn: Cleanup): void;
|
|
161
|
+
/**
|
|
162
|
+
* Synchronous storage in the plugin's namespace: `value` is always defined.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* const tabs = ctx.storage.store(`restore:${session}`, { schema: Tabs, initial: [] })
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
readonly storage: Storage;
|
|
170
|
+
/**
|
|
171
|
+
* The desktop log file.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* ctx.log.write("info", "tunnel opened", { host })
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
readonly log: Log;
|
|
179
|
+
/**
|
|
180
|
+
* The running app, as `ctx.app` in server and TUI plugins; `platform` is always "desktop".
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* if (!ctx.app.packaged) return
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
readonly app: App;
|
|
188
|
+
/**
|
|
189
|
+
* The server endpoints the app's windows use.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* const server = ctx.serverEndpoints.get("sidecar")
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
readonly serverEndpoints: ServerEndpoints;
|
|
197
|
+
/**
|
|
198
|
+
* The app's main windows.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* ctx.windows.on("close", (window) => forget(window.id))
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
readonly windows: Windows;
|
|
206
|
+
/**
|
|
207
|
+
* Places web pages in a window's layout.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* const embed = ctx.embeds.create(new WebContentsView(), window)
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
readonly embeds: Embeds;
|
|
215
|
+
/**
|
|
216
|
+
* The opencode CLI the app runs.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* spawn(ctx.cli.command[0], [...ctx.cli.command.slice(1), "serve"])
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
readonly cli: Cli;
|
|
224
|
+
/**
|
|
225
|
+
* Provides an Ipc for the plugin's windows (`ctx.main`) and other plugins (`ctx.use`). Withdrawn when the instance
|
|
226
|
+
* goes away. Throws for an Ipc whose id is not your plugin's id or under it (`<id>.<name>`), for a Contract token,
|
|
227
|
+
* or for an `impl` missing a method.
|
|
228
|
+
*
|
|
229
|
+
* @param token - The Ipc.
|
|
230
|
+
* @param impl - Its methods, and `state` when the spec has one.
|
|
231
|
+
* @returns Pushes state and events, or withdraws the Ipc early.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* const provider = ctx.provide(Downloads, { state: () => downloads.state(), start, cancel })
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
provide<S extends IpcSpec>(token: Ipc<S>, impl: IpcImpl<S>): IpcProvider<S>;
|
|
239
|
+
}
|
|
240
|
+
/** An item of the native app menu. */
|
|
241
|
+
export interface MenubarItem {
|
|
242
|
+
/**
|
|
243
|
+
* The native menu the item goes in.
|
|
244
|
+
* - `app`: the app menu (macOS).
|
|
245
|
+
* - `file`, `edit`, `view`, `go`, `window`, `help`: the menu of that name.
|
|
246
|
+
*/
|
|
247
|
+
readonly menu: "app" | "file" | "edit" | "view" | "go" | "window" | "help";
|
|
248
|
+
/** The item's local id; the host publishes `${plugin}.${id}`. */
|
|
249
|
+
readonly id: string;
|
|
250
|
+
/** The item's label. Read it from a getter with `ctx.t` so it follows the locale. */
|
|
251
|
+
readonly label: string;
|
|
252
|
+
/** Places the item after a sibling: your item's local id, or a built-in item's id. */
|
|
253
|
+
readonly after?: string;
|
|
254
|
+
/** Shown disabled while it returns false; read each time the menu is built. Defaults to enabled. */
|
|
255
|
+
readonly enabled?: () => boolean;
|
|
256
|
+
/**
|
|
257
|
+
* Runs the item.
|
|
258
|
+
*
|
|
259
|
+
* @param window - The main window that had focus last.
|
|
260
|
+
*/
|
|
261
|
+
run(window: BrowserWindow | undefined): void;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* The registry of native app menu items, contributed from main entries. Windows without a native menubar show them
|
|
265
|
+
* in the in-app menu.
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* ctx.add(MenubarItem, {
|
|
270
|
+
* menu: "help",
|
|
271
|
+
* id: "check",
|
|
272
|
+
* get label() {
|
|
273
|
+
* return ctx.t("menu.check")
|
|
274
|
+
* },
|
|
275
|
+
* run: () => void check(),
|
|
276
|
+
* })
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
export declare const MenubarItem: Registry<MenubarItem>;
|
package/dist/gui/main.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Registry, } from "./core.js";
|
|
2
|
+
export * from "./core.js";
|
|
3
|
+
export * as Plugin from "./plugin.js";
|
|
4
|
+
/**
|
|
5
|
+
* The registry of native app menu items, contributed from main entries. Windows without a native menubar show them
|
|
6
|
+
* in the in-app menu.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* ctx.add(MenubarItem, {
|
|
11
|
+
* menu: "help",
|
|
12
|
+
* id: "check",
|
|
13
|
+
* get label() {
|
|
14
|
+
* return ctx.t("menu.check")
|
|
15
|
+
* },
|
|
16
|
+
* run: () => void check(),
|
|
17
|
+
* })
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const MenubarItem = Registry.define("menubar-item");
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The modules a plugin's `./gui-experimental` bundle may require that both processes provide, each its own instance.
|
|
3
|
+
* Main maps `@opencode/plugin/gui` to the main SDK and a window maps `@opencode/plugin/gui/main` to the window SDK:
|
|
4
|
+
* both export the same `Plugin`, `Store`, `Ipc`, `Contract` and `Registry`, so one definition and contract serve both
|
|
5
|
+
* processes. `@opencode/plugin/rpc` is here because a plugin's `./rpc` contract imports it, and its GUI imports that
|
|
6
|
+
* contract.
|
|
7
|
+
*/
|
|
8
|
+
export declare const pluginSharedModules: readonly ["effect", "@opencode/plugin/gui", "@opencode/plugin/gui/main", "@opencode/plugin/rpc", "@opencode/schema/rpc", "@opencode/client", "@opencode/client/effect"];
|
|
9
|
+
/**
|
|
10
|
+
* The modules only a window provides to a plugin's `./gui-experimental` bundle; main gives the bundle an inert
|
|
11
|
+
* placeholder.
|
|
12
|
+
*/
|
|
13
|
+
export declare const pluginWindowModules: readonly ["solid-js", "solid-js/web", "solid-js/store", "@opencode/plugin/gui/file", "@opencode/plugin/gui/review", "@opencode/plugin/gui/browser", "@opencode/client/solid"];
|
|
14
|
+
/** A module name in `pluginSharedModules` or `pluginWindowModules`. */
|
|
15
|
+
export type PluginModule = (typeof pluginSharedModules)[number] | (typeof pluginWindowModules)[number];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// The module lists only: `gui()` reads them at build time, so this file imports nothing.
|
|
2
|
+
/**
|
|
3
|
+
* The modules a plugin's `./gui-experimental` bundle may require that both processes provide, each its own instance.
|
|
4
|
+
* Main maps `@opencode/plugin/gui` to the main SDK and a window maps `@opencode/plugin/gui/main` to the window SDK:
|
|
5
|
+
* both export the same `Plugin`, `Store`, `Ipc`, `Contract` and `Registry`, so one definition and contract serve both
|
|
6
|
+
* processes. `@opencode/plugin/rpc` is here because a plugin's `./rpc` contract imports it, and its GUI imports that
|
|
7
|
+
* contract.
|
|
8
|
+
*/
|
|
9
|
+
export const pluginSharedModules = [
|
|
10
|
+
"effect",
|
|
11
|
+
"@opencode/plugin/gui",
|
|
12
|
+
"@opencode/plugin/gui/main",
|
|
13
|
+
"@opencode/plugin/rpc",
|
|
14
|
+
"@opencode/schema/rpc",
|
|
15
|
+
"@opencode/client",
|
|
16
|
+
"@opencode/client/effect",
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* The modules only a window provides to a plugin's `./gui-experimental` bundle; main gives the bundle an inert
|
|
20
|
+
* placeholder.
|
|
21
|
+
*/
|
|
22
|
+
export const pluginWindowModules = [
|
|
23
|
+
"solid-js",
|
|
24
|
+
"solid-js/web",
|
|
25
|
+
"solid-js/store",
|
|
26
|
+
"@opencode/plugin/gui/file",
|
|
27
|
+
"@opencode/plugin/gui/review",
|
|
28
|
+
"@opencode/plugin/gui/browser",
|
|
29
|
+
"@opencode/client/solid",
|
|
30
|
+
];
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { SetupContext } from "./context.js";
|
|
2
|
+
import type { Cleanup } from "./core.js";
|
|
3
|
+
import type { Declarations, Stores } from "./declarations.js";
|
|
4
|
+
import type { MainContext } from "./main.js";
|
|
5
|
+
export type { Cleanup, Declarations };
|
|
6
|
+
/**
|
|
7
|
+
* A window setup: the `setup` of `Plugin.define`. `Plugin.Setup<typeof definition>` types one written apart from
|
|
8
|
+
* its declarations, with `ctx.stores` from the declared stores. Runs synchronously under the plugin's Solid owner;
|
|
9
|
+
* return nothing, or a cleanup that runs when the plugin goes away. Put async work in `createKeyed` or
|
|
10
|
+
* `createLatest`, and pass `ctx.signal` or a signal derived from it. The return type rejects async functions and
|
|
11
|
+
* replacement values; the host also rejects thenables from JavaScript bundles.
|
|
12
|
+
*
|
|
13
|
+
* @param ctx - The plugin's context, under its Solid owner.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* export default Plugin.define({
|
|
18
|
+
* setup(ctx) {
|
|
19
|
+
* ctx.add(Command, () => ({ id: "settings", title: ctx.t("settings"), run: () => ctx.layout.settings(ctx.id) }))
|
|
20
|
+
* },
|
|
21
|
+
* })
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export type Setup<D extends Declarations = Declarations<{}>> = (ctx: SetupContext<D>) => Cleanup | void;
|
|
25
|
+
/**
|
|
26
|
+
* A main-process setup: the `main` of `Plugin.define`. It may be async; return nothing, or a cleanup that runs when
|
|
27
|
+
* the plugin goes away.
|
|
28
|
+
*
|
|
29
|
+
* @param ctx - The plugin's main-process context.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* export default Plugin.define({
|
|
34
|
+
* main(ctx) {
|
|
35
|
+
* const awake = ctx.storage.store("awake", { schema: Schema.Boolean, initial: false })
|
|
36
|
+
* ctx.provide(KeepAwake, { get: () => awake.value, set: (enabled) => awake.set(enabled) })
|
|
37
|
+
* },
|
|
38
|
+
* })
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export type MainSetup = (ctx: MainContext) => Cleanup | void | Promise<Cleanup | void>;
|
|
42
|
+
/**
|
|
43
|
+
* A plugin's GUI: the default export of its `./gui-experimental` bundle. Its `Declarations`, then a window setup, a
|
|
44
|
+
* main-process setup, or both. The app's built-in plugins declare with it too.
|
|
45
|
+
*/
|
|
46
|
+
export type Definition<S extends Stores = Stores> = Declarations<S> & {
|
|
47
|
+
/** Runs in every desktop app window. See `Setup`. */
|
|
48
|
+
readonly setup?: Setup<NoInfer<Declarations<S>>>;
|
|
49
|
+
/** Runs once in the desktop app's main process. See `MainSetup`. */
|
|
50
|
+
readonly main?: MainSetup;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Defines a plugin's GUI, the default export of its `./gui-experimental` bundle, as `Plugin.define` from
|
|
54
|
+
* `@opencode/plugin` and `@opencode/plugin/tui` define its server and terminal halves. It declares no id: the host
|
|
55
|
+
* assigns the server plugin's (`ctx.id`). The window setup's `ctx.stores` is typed from the declared stores.
|
|
56
|
+
*
|
|
57
|
+
* @param plugin - The declarations and at least one setup.
|
|
58
|
+
* @returns The same object.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```tsx
|
|
62
|
+
* export default Plugin.define({
|
|
63
|
+
* setup(ctx) {
|
|
64
|
+
* ctx.add(Command, () => ({ id: "open", title: ctx.t("open"), run: () => void ctx.main(Acme).ping() }))
|
|
65
|
+
* },
|
|
66
|
+
* main(ctx) {
|
|
67
|
+
* ctx.provide(Acme, { ping: () => "pong" })
|
|
68
|
+
* },
|
|
69
|
+
* })
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare function define<const S extends Stores = {}>(plugin: Definition<S> & WithSetup): Definition<S>;
|
|
73
|
+
/**
|
|
74
|
+
* Declares a plugin's GUI without setups, so setups written in other files are typed from it
|
|
75
|
+
* (`Plugin.Setup<typeof definition>`) and the app's host lists can attach their own entries. Returns only the
|
|
76
|
+
* declarations.
|
|
77
|
+
*
|
|
78
|
+
* @param plugin - The declarations.
|
|
79
|
+
* @returns The same object.
|
|
80
|
+
*/
|
|
81
|
+
export declare function define<const S extends Stores = {}>(plugin: Declarations<S>): Declarations<S>;
|
|
82
|
+
type WithSetup = {
|
|
83
|
+
readonly setup: unknown;
|
|
84
|
+
} | {
|
|
85
|
+
readonly main: unknown;
|
|
86
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type Accessor } from "solid-js";
|
|
2
|
+
import type { Live } from "./core.js";
|
|
3
|
+
type Falsy = undefined | null | false;
|
|
4
|
+
/**
|
|
5
|
+
* What `createKeyed` and `createLatest` follow: a `Live` accessor from `ctx.use(token)`, followed through its
|
|
6
|
+
* generations, or any accessor, followed by the identity of its value.
|
|
7
|
+
*/
|
|
8
|
+
export type KeyedSource = Accessor<unknown>;
|
|
9
|
+
/**
|
|
10
|
+
* What a source gives while it is active: the provider's value for a `Live` accessor; for a plain accessor, its value,
|
|
11
|
+
* which is active while it is not undefined, null or false.
|
|
12
|
+
*/
|
|
13
|
+
export type KeyedValue<S> = S extends Accessor<Live<infer T>> ? T : S extends Accessor<infer T> ? Exclude<T, Falsy> : never;
|
|
14
|
+
/**
|
|
15
|
+
* Runs `fn` once per key, like `<Show keyed>`: each active generation of a `Live` accessor, or each identity of a plain
|
|
16
|
+
* accessor's value. Each run, and each run of `otherwise` while there is no key, has its own owner: its
|
|
17
|
+
* `onCleanup` and its registrations end with it. This is the way plugin code runs side effects reactively; use it
|
|
18
|
+
* only to sync with something outside Solid (the DOM, a widget, an Ipc subscription), never to set state from state.
|
|
19
|
+
* Call it under an owner: in setup, or in a component.
|
|
20
|
+
*
|
|
21
|
+
* A plain accessor that builds an object, such as `{ directory, tab }`, gives a new key each time it reads, even when
|
|
22
|
+
* every field is unchanged; pass `equals` to compare the fields that matter instead.
|
|
23
|
+
*
|
|
24
|
+
* @param source - A `Live` accessor from `ctx.use(token)`, or any accessor.
|
|
25
|
+
* @param fn - Runs once per key with the source's value. It runs untracked.
|
|
26
|
+
* @param options - What runs while there is no key, and when a plain accessor's new value is the same key.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // Each provider generation: listen to its events; the listener ends with the generation.
|
|
31
|
+
* createKeyed(ctx.use(Changes), (changes) => changes.watch(screen, "files"))
|
|
32
|
+
* // A plain accessor: the picker runs while the tab is visible, and `otherwise` while it is not.
|
|
33
|
+
* createKeyed(visible, startPicker, { otherwise: endPicker })
|
|
34
|
+
* // An object source: lists again only when the directory or the tab changes.
|
|
35
|
+
* createKeyed(() => ({ directory: file.root, tab: tab() }), (key) => void list(key), {
|
|
36
|
+
* equals: (previous, next) => previous.directory === next.directory && previous.tab === next.tab,
|
|
37
|
+
* })
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function createKeyed<S extends KeyedSource>(source: S, fn: (value: KeyedValue<S>) => void, options?: {
|
|
41
|
+
/**
|
|
42
|
+
* Runs while the source has no key: a `Live` accessor that is pending or inactive, or a plain accessor whose value
|
|
43
|
+
* is undefined, null or false. Its own owner ends when a key arrives.
|
|
44
|
+
*/
|
|
45
|
+
readonly otherwise?: () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Whether a plain accessor's new value is the same key as the one `fn` last ran with, so the run stays and `fn`
|
|
48
|
+
* does not run again. Use it when the source builds an object each time it reads. Defaults to identity (`===`).
|
|
49
|
+
* A `Live` accessor always keys by generation and ignores it.
|
|
50
|
+
*/
|
|
51
|
+
readonly equals?: (previous: KeyedValue<S>, next: KeyedValue<S>) => boolean;
|
|
52
|
+
}): void;
|
|
53
|
+
/**
|
|
54
|
+
* The latest result of `fetch` for the source's current value. Never suspends. A new value aborts the previous request
|
|
55
|
+
* through its signal and drops its reply; so does the owner going away. `latest` keeps the last result meanwhile.
|
|
56
|
+
* Call it under an owner: in setup, or in a component.
|
|
57
|
+
*
|
|
58
|
+
* @param source - What to fetch for: a `Live` accessor from `ctx.use(token)`, or any accessor (see `KeyedValue`).
|
|
59
|
+
* @param fetch - Fetches for one value. Pass `signal` on to the request.
|
|
60
|
+
* @returns A store; read its fields in render or in a memo.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const active = createLatest(ctx.use(Pairing), (pairing, signal) => pairing.screenActive({ signal }))
|
|
65
|
+
* const awake = () => active.latest ?? false
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function createLatest<S extends KeyedSource, T>(source: S, fetch: (value: KeyedValue<S>, signal: AbortSignal) => Promise<T>): {
|
|
69
|
+
/** The last result; kept while a newer request runs and while the source has no value. Undefined before the first. */
|
|
70
|
+
readonly latest: T | undefined;
|
|
71
|
+
/** A request for the current value is in flight. */
|
|
72
|
+
readonly loading: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* The current request's rejection. Undefined while a request runs, after a result, and while the source has no
|
|
75
|
+
* value, so it never describes an earlier value's request.
|
|
76
|
+
*/
|
|
77
|
+
readonly error: unknown;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* State that returns to `initial` on every routing visit of the current session (`MountedSession.visit`), e.g. a
|
|
81
|
+
* selection to forget when the user goes Home and back. Call it inside a contribution or setup: it reads
|
|
82
|
+
* `usePlugin()`.
|
|
83
|
+
*
|
|
84
|
+
* @param initial - The value at the start of every visit.
|
|
85
|
+
* @returns The value accessor and its setter, like `createSignal`.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const [expanded, setExpanded] = createVisitState(false)
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function createVisitState<T>(initial: T): readonly [() => T, (next: T) => undefined];
|
|
93
|
+
export {};
|