@astera-app/plugin-sdk 0.2.0 → 0.3.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/CHANGELOG.md +23 -0
- package/README.md +11 -1
- package/dist/cjs/index.d.ts +56 -12
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/panel.d.ts +129 -0
- package/dist/cjs/panel.js +87 -0
- package/dist/esm/index.d.ts +56 -12
- package/dist/esm/index.js +4 -2
- package/dist/esm/panel.d.ts +129 -0
- package/dist/esm/panel.js +84 -0
- package/package.json +11 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,29 @@
|
|
|
3
3
|
`@astera-app/plugin-sdk` is versioned apart from the Astera app. [docs/plugins.md](https://github.com/parsingk/Astera/blob/main/docs/plugins.md)
|
|
4
4
|
is the guide.
|
|
5
5
|
|
|
6
|
+
## 0.3.0
|
|
7
|
+
|
|
8
|
+
- `PLUGIN_API_VERSION` is `'2'`: Plugin API 2, panels and the other contributions of `astera.contributes`. A plugin
|
|
9
|
+
written for API 1 is typed the same.
|
|
10
|
+
- `ctx.panels`, whose `post(message, { panel? })` sends a message to the plugin's open panels, and `onPanelMessage`,
|
|
11
|
+
called as `onPanelMessage(message, { panel }, ctx)`, which answers what a panel sends with `window.astera.host.send`.
|
|
12
|
+
- `@astera-app/plugin-sdk/panel`, a second entry point for a panel's page: `AsteraPanelBridge`, the type of
|
|
13
|
+
`window.astera` (declared on `Window` once the page references the entry), with each method's arguments and answer;
|
|
14
|
+
`PANEL_METHODS`; and `PANEL_ERROR_CODES` with `PanelErrorCode`, every code a call can be refused with. A refused call
|
|
15
|
+
rejects with `CODE: sentence`. `secrets.list()` answers `{ secrets }`, as `secrets.request()` and
|
|
16
|
+
`secrets.delete()` do.
|
|
17
|
+
- Completion checks can answer `pending` (not ready yet: Astera asks again, with `previous`, within 30 minutes from
|
|
18
|
+
its first ask; `retryAfterSeconds` says when, `state` is handed back) and `unknown` (the check ran but cannot tell
|
|
19
|
+
whether this work passes: a person chooses). A result computed elsewhere names its commit as `revision`; a `passed`
|
|
20
|
+
or `failed` for another commit than `workspace.head`, or for a folder holding changes in no commit, counts as
|
|
21
|
+
`unknown`. `workspace.head` is now the folder's commit when Astera asked, read at each ask.
|
|
22
|
+
|
|
23
|
+
All of it needs an Astera newer than 1.5.6, from the release that ships the panel broker and these completion checks.
|
|
24
|
+
An older Astera answers no panel broker call and reads `pending` and `unknown` as an answer of the wrong shape, but it
|
|
25
|
+
ignores `revision`: a `passed` for another commit passes there. A check that sends `revision` sets
|
|
26
|
+
`astera.minAsteraVersion` to that release, so an older Astera does not run it and its check goes to a person as one that
|
|
27
|
+
could not be made.
|
|
28
|
+
|
|
6
29
|
## 0.2.0
|
|
7
30
|
|
|
8
31
|
- `onEvent` on a plugin: the `event` capability, which hands the plugin each of Astera's events in order, from where
|
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ export default definePlugin({
|
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
A plugin is a folder with a `package.json` whose `astera` field names its entry file, the Plugin API it is written for
|
|
28
|
-
(`"1"`) and the permissions it asks for. `ctx.astera` is a client from `@astera-app/client`, answered within the
|
|
28
|
+
(`"1"`, or `"2"` for panels and the other contributions) and the permissions it asks for. `ctx.astera` is a client from `@astera-app/client`, answered within the
|
|
29
29
|
permissions the person granted. A plugin that names the `event` capability gets each of Astera's events, in order, in
|
|
30
30
|
its `onEvent` ([event plugins](https://github.com/parsingk/Astera/blob/main/docs/plugins.md#event-plugins)), and one
|
|
31
31
|
that names the `notification` capability gets each notification, worded for a person, in its `send`
|
|
@@ -38,5 +38,15 @@ passes, in its `runCheck`
|
|
|
38
38
|
([completion check plugins](https://github.com/parsingk/Astera/blob/main/docs/plugins.md#completion-check-plugins)),
|
|
39
39
|
which `defineCompletionCheckProvider` types.
|
|
40
40
|
|
|
41
|
+
A panel's page, which runs in Astera apart from the plugin's Host code, reaches the network, files, secrets, a lasting
|
|
42
|
+
store and its Host code only through `window.astera`
|
|
43
|
+
([the panel broker](https://github.com/parsingk/Astera/blob/main/docs/plugins.md#the-panel-broker)). Its types come
|
|
44
|
+
from this package's second entry point; add this line to the page's code (with `moduleResolution` `NodeNext` or
|
|
45
|
+
`bundler`):
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
/// <reference types="@astera-app/plugin-sdk/panel" />
|
|
49
|
+
```
|
|
50
|
+
|
|
41
51
|
Plugins run trusted code on the person's machine: a plugin can do anything they can, and its permissions limit only
|
|
42
52
|
what it asks Astera for.
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { AsteraClient, AsteraEvent, EventGap } from '@astera-app/client';
|
|
2
|
-
/** The Plugin API this package
|
|
3
|
-
|
|
2
|
+
/** The Plugin API this package describes: the manifest's `astera.apiVersion` (spec §28). Plugin API 2 adds panels and
|
|
3
|
+
* the other contributions of `astera.contributes`; a plugin written for API 1 is typed the same. A panel page's
|
|
4
|
+
* `window.astera` is typed by `@astera-app/plugin-sdk/panel`. */
|
|
5
|
+
export declare const PLUGIN_API_VERSION = "2";
|
|
4
6
|
/** Lines to the plugin's log, which `astera plugins logs` reads. Anything the plugin prints goes there too. */
|
|
5
7
|
export interface PluginLog {
|
|
6
8
|
info(message: string): void;
|
|
@@ -31,6 +33,13 @@ export interface PluginContext {
|
|
|
31
33
|
/** The permissions the person granted, a subset of those the manifest asks for. */
|
|
32
34
|
permissions: readonly string[];
|
|
33
35
|
log: PluginLog;
|
|
36
|
+
/** The plugin's open panels: `post` sends a JSON message (at most 64 KiB, 20 a second) to each of them, or to one panel
|
|
37
|
+
* by its id; a panel takes it with `window.astera.host.onMessage`. A panel that is not open gets nothing. */
|
|
38
|
+
panels: {
|
|
39
|
+
post(message: unknown, options?: {
|
|
40
|
+
panel?: string;
|
|
41
|
+
}): Promise<void>;
|
|
42
|
+
};
|
|
34
43
|
/** Aborted when Astera stops the plugin: disabled, removed, updated, or the Host leaving. In a handler (`onEvent`,
|
|
35
44
|
* `send`, `listItems`, `getItem`, `buildJobContext`, `runCheck`) it is that call's: it also aborts when Astera stops
|
|
36
45
|
* waiting for the call (30 seconds for an event or a notification, 15 for a job source, 30 minutes for a check). */
|
|
@@ -49,6 +58,11 @@ export interface PluginDefinition {
|
|
|
49
58
|
* you have seen. A property rather than a method, so a handler that takes only `AsteraEvent` does not typecheck:
|
|
50
59
|
* it would throw on a gap. */
|
|
51
60
|
onEvent?: (event: AsteraEvent | EventGap, ctx: PluginContext) => void | Promise<void>;
|
|
61
|
+
/** A message one of the plugin's panels sent with `window.astera.host.send`, and which panel sent it. What it returns
|
|
62
|
+
* (JSON, at most 64 KiB) is the panel's answer; it must settle within 15 s. */
|
|
63
|
+
onPanelMessage?: (message: unknown, from: {
|
|
64
|
+
panel: string;
|
|
65
|
+
}, ctx: PluginContext) => unknown | Promise<unknown>;
|
|
52
66
|
}
|
|
53
67
|
/** The plugin an entry file exports as its default. */
|
|
54
68
|
export declare function definePlugin<T extends PluginDefinition>(definition: T): T;
|
|
@@ -143,10 +157,12 @@ export interface JobSourceProvider extends PluginDefinition {
|
|
|
143
157
|
/** The provider an entry file exports as its default. */
|
|
144
158
|
export declare function defineJobSourceProvider<T extends JobSourceProvider>(provider: T): T;
|
|
145
159
|
/** What a completion check is asked about: the Task and the folder its checks run in. `root` is the Task's worktree, or
|
|
146
|
-
* the project folder
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
160
|
+
* the project folder. `base` is the commit the Task's work started from, when Astera recorded it, so a check can look
|
|
161
|
+
* at what the Task changed. `head` is the folder's commit when Astera asked, read again at each ask, and absent when it
|
|
162
|
+
* could not be read (not a repository, git failed): a check that looks up a result computed elsewhere asks for this
|
|
163
|
+
* commit and names it as its answer's `revision`. `branch` is not sent by this Astera: a check that needs it asks git
|
|
164
|
+
* in `root`. A check configured per project reads the project's own files under `root`; the plugin's settings are the
|
|
165
|
+
* rest of its configuration. */
|
|
150
166
|
export interface CompletionCheckInput {
|
|
151
167
|
projectId?: string;
|
|
152
168
|
jobId: string;
|
|
@@ -161,6 +177,14 @@ export interface CompletionCheckInput {
|
|
|
161
177
|
head?: string;
|
|
162
178
|
branch?: string;
|
|
163
179
|
};
|
|
180
|
+
/** On an ask that follows a `pending` answer: how many times this check answered pending in this round, when the
|
|
181
|
+
* round's first ask of it was (ISO time), and the `state` of its latest `pending` answer (absent when that answer gave
|
|
182
|
+
* none). A Host restart starts the waiting over, and the first ask after it has no `previous`. */
|
|
183
|
+
previous?: {
|
|
184
|
+
pending: number;
|
|
185
|
+
since: string;
|
|
186
|
+
state?: string;
|
|
187
|
+
};
|
|
164
188
|
}
|
|
165
189
|
/** One finding. Astera keeps a `message` (required) of up to 1,000 characters, a `file` of up to 500, a `line` that is a
|
|
166
190
|
* positive integer and a `severity` that is one of the two, and drops what is not. */
|
|
@@ -173,21 +197,41 @@ export interface CompletionCheckDiagnostic {
|
|
|
173
197
|
/** A check's answer. `passed` lets the Task's next check run. `failed` is the code's fault: the Task's repair request
|
|
174
198
|
* carries your summary, your first 20 findings as `file:line message` and your link, and the Task fails where its Job
|
|
175
199
|
* repairs nothing. `error` says the check could not be made (a service down, a missing token): Astera asks once more,
|
|
176
|
-
* then puts it to a person, and no repair is spent on it. `
|
|
177
|
-
*
|
|
178
|
-
*
|
|
200
|
+
* then puts it to a person, and no repair is spent on it. `pending` says the result is not ready yet (an analysis or a
|
|
201
|
+
* CI run still going): Astera asks again later, with `previous`, until 30 minutes from its first ask of this check in
|
|
202
|
+
* this round have passed; still pending then, the check counts as unknown. `unknown` says the check ran but cannot
|
|
203
|
+
* tell whether this work passes: Astera puts it to a person, asks nothing again on its own, and spends no repair.
|
|
204
|
+
*
|
|
205
|
+
* `summary` is cut at 1,000 characters (the status word when there is none), `diagnostics` keep the first 20 (Astera
|
|
206
|
+
* counts the rest, and keeps none of a `passed` check's: give the whole report as `externalUrl`), and `externalUrl` is
|
|
207
|
+
* kept when it is http or https within 2,048. */
|
|
179
208
|
export interface CompletionCheckResult {
|
|
180
|
-
status: 'passed' | 'failed' | 'error';
|
|
209
|
+
status: 'passed' | 'failed' | 'error' | 'pending' | 'unknown';
|
|
181
210
|
summary?: string;
|
|
182
211
|
diagnostics?: CompletionCheckDiagnostic[];
|
|
183
212
|
/** How many findings there are, when you send fewer: send the first 20 and the count, not thousands to be cut. */
|
|
184
213
|
diagnosticsTotal?: number;
|
|
185
214
|
externalUrl?: string;
|
|
215
|
+
/** The commit this result is about, as hex (7 to 64 characters). A check that reads a result computed elsewhere (an
|
|
216
|
+
* analysis, a CI run, a test report) sends it, as `workspace.head` or a prefix of it; a check of the folder as it is
|
|
217
|
+
* leaves it out. A `passed` or `failed` naming another commit than `workspace.head`, or naming it while the folder
|
|
218
|
+
* holds changes that are in no commit, counts as unknown: a result for other code never lets a Task pass. Anything
|
|
219
|
+
* but 7 to 64 hex digits makes the answer the wrong shape. An Astera older than SDK 0.3 ignores `revision`, so a check
|
|
220
|
+
* that sends it sets `astera.minAsteraVersion` to the first Astera that judges it. */
|
|
221
|
+
revision?: string;
|
|
222
|
+
/** For `pending`: when to ask again, in seconds. Astera keeps it within 5 to 120; without it Astera waits 10 seconds,
|
|
223
|
+
* then twice as long each time, up to 60. A wait that would run past the 30 minutes is cut to them, and no ask follows
|
|
224
|
+
* it: the check counts as unknown. */
|
|
225
|
+
retryAfterSeconds?: number;
|
|
226
|
+
/** For `pending`: text of at most 2,000 characters handed back as `previous.state` on the next ask, never shown to
|
|
227
|
+
* anyone. A longer one makes the answer the wrong shape. */
|
|
228
|
+
state?: string;
|
|
186
229
|
}
|
|
187
230
|
/** A plugin of the `completion-check` capability (`astera.capabilities: ["completion-check"]`, with no permission):
|
|
188
231
|
* Astera asks it when a Task whose checks name `plugin:<its id>` is done, in the order the Task lists its checks. A
|
|
189
|
-
*
|
|
190
|
-
*
|
|
232
|
+
* check has 30 minutes in a round, whether it spends them in one call or in several `pending` answers: each call's
|
|
233
|
+
* `ctx.signal` aborts when what is left of them runs out. Throw or reject to say the check could not be made: it counts
|
|
234
|
+
* as `error`, with your message. A plugin missing `runCheck` does not start. */
|
|
191
235
|
export interface CompletionCheckProvider extends PluginDefinition {
|
|
192
236
|
runCheck: (input: CompletionCheckInput, ctx: PluginContext) => CompletionCheckResult | Promise<CompletionCheckResult>;
|
|
193
237
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -5,8 +5,10 @@ exports.definePlugin = definePlugin;
|
|
|
5
5
|
exports.defineNotificationProvider = defineNotificationProvider;
|
|
6
6
|
exports.defineJobSourceProvider = defineJobSourceProvider;
|
|
7
7
|
exports.defineCompletionCheckProvider = defineCompletionCheckProvider;
|
|
8
|
-
/** The Plugin API this package
|
|
9
|
-
|
|
8
|
+
/** The Plugin API this package describes: the manifest's `astera.apiVersion` (spec §28). Plugin API 2 adds panels and
|
|
9
|
+
* the other contributions of `astera.contributes`; a plugin written for API 1 is typed the same. A panel page's
|
|
10
|
+
* `window.astera` is typed by `@astera-app/plugin-sdk/panel`. */
|
|
11
|
+
exports.PLUGIN_API_VERSION = '2';
|
|
10
12
|
/** The plugin an entry file exports as its default. */
|
|
11
13
|
function definePlugin(definition) {
|
|
12
14
|
return definition;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/** The methods of `window.astera`, as Astera's bridge names them. Astera's own list is checked against this one. */
|
|
2
|
+
export declare const PANEL_METHODS: readonly ['context', 'net.request', 'net.cancel', 'secrets.list', 'secrets.request', 'secrets.delete', 'files.pick', 'files.read', 'files.create', 'files.save', 'files.onOpen', 'storage.get', 'storage.set', 'storage.delete', 'storage.keys', 'host.send', 'host.onMessage'];
|
|
3
|
+
export type PanelMethod = (typeof PANEL_METHODS)[number];
|
|
4
|
+
/** Every code a call can be refused with. A refused call rejects with an `Error` whose message is `CODE: sentence`,
|
|
5
|
+
* such as `NO_GESTURE: net.request needs a key press or click in the panel within the last 5 seconds`: read the code
|
|
6
|
+
* before the first `:`.
|
|
7
|
+
* The sentence is for a person, and may change. Astera's sources are checked against this list. */
|
|
8
|
+
export declare const PANEL_ERROR_CODES: readonly ['BAD_HANDLE', 'BAD_KEY', 'BAD_REQUEST', 'BAD_SECRET', 'BAD_VALUE', 'BLOCKED_ADDRESS', 'BUSY', 'CANCELLED', 'CONFLICT', 'ENCODING', 'EXISTS', 'FAILED', 'FORBIDDEN', 'HOST', 'INVALID_ARGUMENTS', 'NETWORK', 'NOT_ANSWERED', 'NOT_FOUND', 'NOT_GRANTED', 'NOT_INSTALLED', 'NOT_SUPPORTED', 'NO_GESTURE', 'NO_HOST_CODE', 'NO_PERMISSION', 'NO_PROJECT', 'OUTSIDE_PROJECT', 'PAYLOAD_NOT_JSON', 'PAYLOAD_TOO_LARGE', 'PLUGIN_FAILED', 'PLUGIN_NOT_RUNNING', 'PLUGIN_OFF', 'PRIVATE_ADDRESS', 'REDIRECT_LIMIT', 'REFUSED', 'REPLY_TOO_LARGE', 'SAFE_MODE', 'SAVE_FAILED', 'SECRET_NOT_BOUND', 'SECRET_UNKNOWN', 'STORAGE_FULL', 'TIMEOUT', 'TLS', 'TOO_LARGE', 'TOO_MANY_CALLS', 'TOO_MANY_REQUESTS', 'UNKNOWN_METHOD', 'UNSAVED_IN_EDITOR', 'WRONG_TYPE'];
|
|
9
|
+
export type PanelErrorCode = (typeof PANEL_ERROR_CODES)[number];
|
|
10
|
+
/** What the panel was opened as: its plugin's id, its panel's id, and the project its tab was opened in, when the
|
|
11
|
+
* plugin was granted `workspace.read`. */
|
|
12
|
+
export interface PanelContext {
|
|
13
|
+
plugin: string;
|
|
14
|
+
panel: string;
|
|
15
|
+
project?: {
|
|
16
|
+
root: string;
|
|
17
|
+
name: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** A request to the network. `body` is text, at most 10 MiB; `timeoutMs` up to 120,000 (30 seconds without it). A
|
|
21
|
+
* header value, a query value or the body may name a secret as `{{secret:<name>}}`. `id`, at most 64 characters, is
|
|
22
|
+
* what `net.cancel` takes; Astera makes one when it is left out. */
|
|
23
|
+
export interface PanelNetRequest {
|
|
24
|
+
method: string;
|
|
25
|
+
url: string;
|
|
26
|
+
headers?: Record<string, string>;
|
|
27
|
+
body?: string;
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
id?: string;
|
|
30
|
+
}
|
|
31
|
+
/** A response. A text body is `text`; anything else comes as `base64`. Past 20 MiB the body is cut and `truncated` is
|
|
32
|
+
* set. `redirectedTo` is the origin a redirect pointed at that the plugin may not reach: the request stopped there. */
|
|
33
|
+
export interface PanelNetResponse {
|
|
34
|
+
status: number;
|
|
35
|
+
headers: Record<string, string>;
|
|
36
|
+
body: string;
|
|
37
|
+
bodyEncoding: 'text' | 'base64';
|
|
38
|
+
ms: number;
|
|
39
|
+
truncated?: true;
|
|
40
|
+
redirectedTo?: string;
|
|
41
|
+
}
|
|
42
|
+
/** A secret entered for the plugin's panels, by name, with the origins it may be sent to. A panel never reads a value. */
|
|
43
|
+
export interface PanelSecretInfo {
|
|
44
|
+
name: string;
|
|
45
|
+
origins: string[];
|
|
46
|
+
}
|
|
47
|
+
/** A file the person picked, named or opened in the panel: a handle, never a path, and the file's name. */
|
|
48
|
+
export interface PanelFileHandle {
|
|
49
|
+
handle: string;
|
|
50
|
+
name: string;
|
|
51
|
+
}
|
|
52
|
+
/** A file's UTF-8 text, at most 5 MiB, and the revision `files.save` must be given next. */
|
|
53
|
+
export interface PanelFileText {
|
|
54
|
+
text: string;
|
|
55
|
+
revision: string;
|
|
56
|
+
}
|
|
57
|
+
/** `window.astera` in a plugin panel. Each method answers a promise that rejects with `CODE: sentence` when Astera
|
|
58
|
+
* refuses the call (see `PANEL_ERROR_CODES`). Methods marked "key press or click" need one in the panel within the
|
|
59
|
+
* last 5 seconds. */
|
|
60
|
+
export interface AsteraPanelBridge {
|
|
61
|
+
context(): Promise<PanelContext>;
|
|
62
|
+
net: {
|
|
63
|
+
/** Needs `network.request`; key press or click. The first request to an origin the plugin may not reach yet asks
|
|
64
|
+
* the person. */
|
|
65
|
+
request(req: PanelNetRequest): Promise<PanelNetResponse>;
|
|
66
|
+
/** Needs `network.request`. */
|
|
67
|
+
cancel(id: string): Promise<{
|
|
68
|
+
cancelled: boolean;
|
|
69
|
+
}>;
|
|
70
|
+
};
|
|
71
|
+
secrets: {
|
|
72
|
+
/** Needs `network.request`. */
|
|
73
|
+
list(): Promise<{
|
|
74
|
+
secrets: PanelSecretInfo[];
|
|
75
|
+
}>;
|
|
76
|
+
/** Needs `network.request`; key press or click. Asks the person to enter it, for origins the plugin already holds. */
|
|
77
|
+
request(name: string, label: string, options: {
|
|
78
|
+
origins: string[];
|
|
79
|
+
}): Promise<{
|
|
80
|
+
secrets: PanelSecretInfo[];
|
|
81
|
+
}>;
|
|
82
|
+
/** Needs `network.request`; key press or click. */
|
|
83
|
+
delete(name: string): Promise<{
|
|
84
|
+
secrets: PanelSecretInfo[];
|
|
85
|
+
}>;
|
|
86
|
+
};
|
|
87
|
+
files: {
|
|
88
|
+
/** Needs `files.read`; key press or click. Null when the person picked nothing. */
|
|
89
|
+
pick(options?: {
|
|
90
|
+
extensions?: string[];
|
|
91
|
+
}): Promise<PanelFileHandle | null>;
|
|
92
|
+
/** Needs `files.read`. */
|
|
93
|
+
read(handle: string): Promise<PanelFileText>;
|
|
94
|
+
/** Needs `files.write`; key press or click. Asks the person for a folder and a name in the project; null when they
|
|
95
|
+
* chose none. Its first save takes `revision: null`. */
|
|
96
|
+
create(options: {
|
|
97
|
+
suggestedName: string;
|
|
98
|
+
extensions?: string[];
|
|
99
|
+
}): Promise<PanelFileHandle | null>;
|
|
100
|
+
/** Needs `files.write`; key press or click. `revision` is the one last read or saved (`CONFLICT` otherwise). */
|
|
101
|
+
save(handle: string, text: string, options: {
|
|
102
|
+
revision: string | null;
|
|
103
|
+
}): Promise<{
|
|
104
|
+
revision: string;
|
|
105
|
+
}>;
|
|
106
|
+
/** Needs `files.read`. Called with each file the person opens in this panel; answers how to stop listening. */
|
|
107
|
+
onOpen(listener: (file: PanelFileHandle) => void): () => void;
|
|
108
|
+
};
|
|
109
|
+
storage: {
|
|
110
|
+
/** The value stored under `key`: `undefined` when there is none, `null` for a stored null. */
|
|
111
|
+
get(key: string): Promise<unknown>;
|
|
112
|
+
/** A JSON value; keys of at most 128 characters, at most 5 MiB a plugin. */
|
|
113
|
+
set(key: string, value: unknown): Promise<null>;
|
|
114
|
+
delete(key: string): Promise<null>;
|
|
115
|
+
keys(): Promise<string[]>;
|
|
116
|
+
};
|
|
117
|
+
host: {
|
|
118
|
+
/** For a plugin with Host code: reaches its `onPanelMessage`, whose answer is the reply. JSON, at most 64 KiB. */
|
|
119
|
+
send(message: unknown): Promise<unknown>;
|
|
120
|
+
/** For a plugin with Host code: called with each message its `ctx.panels.post` sends; answers how to stop
|
|
121
|
+
* listening. */
|
|
122
|
+
onMessage(listener: (message: unknown) => void): () => void;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
declare global {
|
|
126
|
+
interface Window {
|
|
127
|
+
astera: AsteraPanelBridge;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @astera-app/plugin-sdk/panel: what a plugin panel's page is written against (Plugin API 2, the panel broker of PE-B
|
|
3
|
+
// part 1). A panel runs as a web page in Astera, apart from the plugin's Host code, and reaches the network, files,
|
|
4
|
+
// secrets, a lasting store and its plugin's Host code only through `window.astera`, which Astera answers after checking
|
|
5
|
+
// the permission the person granted and, for some methods, a key press or click in the panel within the last 5 seconds.
|
|
6
|
+
//
|
|
7
|
+
// Reference it from the page's code to have `window.astera` typed:
|
|
8
|
+
// /// <reference types="@astera-app/plugin-sdk/panel" />
|
|
9
|
+
// or with a type import (`import type { AsteraPanelBridge } from '@astera-app/plugin-sdk/panel'`). The subpath needs
|
|
10
|
+
// `moduleResolution` `NodeNext` or `bundler`. At run time this entry holds only the two lists below; the bridge itself
|
|
11
|
+
// is Astera's.
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.PANEL_ERROR_CODES = exports.PANEL_METHODS = void 0;
|
|
14
|
+
/** The methods of `window.astera`, as Astera's bridge names them. Astera's own list is checked against this one. */
|
|
15
|
+
exports.PANEL_METHODS = [
|
|
16
|
+
'context',
|
|
17
|
+
'net.request',
|
|
18
|
+
'net.cancel',
|
|
19
|
+
'secrets.list',
|
|
20
|
+
'secrets.request',
|
|
21
|
+
'secrets.delete',
|
|
22
|
+
'files.pick',
|
|
23
|
+
'files.read',
|
|
24
|
+
'files.create',
|
|
25
|
+
'files.save',
|
|
26
|
+
'files.onOpen',
|
|
27
|
+
'storage.get',
|
|
28
|
+
'storage.set',
|
|
29
|
+
'storage.delete',
|
|
30
|
+
'storage.keys',
|
|
31
|
+
'host.send',
|
|
32
|
+
'host.onMessage'
|
|
33
|
+
];
|
|
34
|
+
/** Every code a call can be refused with. A refused call rejects with an `Error` whose message is `CODE: sentence`,
|
|
35
|
+
* such as `NO_GESTURE: net.request needs a key press or click in the panel within the last 5 seconds`: read the code
|
|
36
|
+
* before the first `:`.
|
|
37
|
+
* The sentence is for a person, and may change. Astera's sources are checked against this list. */
|
|
38
|
+
exports.PANEL_ERROR_CODES = [
|
|
39
|
+
'BAD_HANDLE',
|
|
40
|
+
'BAD_KEY',
|
|
41
|
+
'BAD_REQUEST',
|
|
42
|
+
'BAD_SECRET',
|
|
43
|
+
'BAD_VALUE',
|
|
44
|
+
'BLOCKED_ADDRESS',
|
|
45
|
+
'BUSY',
|
|
46
|
+
'CANCELLED',
|
|
47
|
+
'CONFLICT',
|
|
48
|
+
'ENCODING',
|
|
49
|
+
'EXISTS',
|
|
50
|
+
'FAILED',
|
|
51
|
+
'FORBIDDEN',
|
|
52
|
+
'HOST',
|
|
53
|
+
'INVALID_ARGUMENTS',
|
|
54
|
+
'NETWORK',
|
|
55
|
+
'NOT_ANSWERED',
|
|
56
|
+
'NOT_FOUND',
|
|
57
|
+
'NOT_GRANTED',
|
|
58
|
+
'NOT_INSTALLED',
|
|
59
|
+
'NOT_SUPPORTED',
|
|
60
|
+
'NO_GESTURE',
|
|
61
|
+
'NO_HOST_CODE',
|
|
62
|
+
'NO_PERMISSION',
|
|
63
|
+
'NO_PROJECT',
|
|
64
|
+
'OUTSIDE_PROJECT',
|
|
65
|
+
'PAYLOAD_NOT_JSON',
|
|
66
|
+
'PAYLOAD_TOO_LARGE',
|
|
67
|
+
'PLUGIN_FAILED',
|
|
68
|
+
'PLUGIN_NOT_RUNNING',
|
|
69
|
+
'PLUGIN_OFF',
|
|
70
|
+
'PRIVATE_ADDRESS',
|
|
71
|
+
'REDIRECT_LIMIT',
|
|
72
|
+
'REFUSED',
|
|
73
|
+
'REPLY_TOO_LARGE',
|
|
74
|
+
'SAFE_MODE',
|
|
75
|
+
'SAVE_FAILED',
|
|
76
|
+
'SECRET_NOT_BOUND',
|
|
77
|
+
'SECRET_UNKNOWN',
|
|
78
|
+
'STORAGE_FULL',
|
|
79
|
+
'TIMEOUT',
|
|
80
|
+
'TLS',
|
|
81
|
+
'TOO_LARGE',
|
|
82
|
+
'TOO_MANY_CALLS',
|
|
83
|
+
'TOO_MANY_REQUESTS',
|
|
84
|
+
'UNKNOWN_METHOD',
|
|
85
|
+
'UNSAVED_IN_EDITOR',
|
|
86
|
+
'WRONG_TYPE'
|
|
87
|
+
];
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { AsteraClient, AsteraEvent, EventGap } from '@astera-app/client';
|
|
2
|
-
/** The Plugin API this package
|
|
3
|
-
|
|
2
|
+
/** The Plugin API this package describes: the manifest's `astera.apiVersion` (spec §28). Plugin API 2 adds panels and
|
|
3
|
+
* the other contributions of `astera.contributes`; a plugin written for API 1 is typed the same. A panel page's
|
|
4
|
+
* `window.astera` is typed by `@astera-app/plugin-sdk/panel`. */
|
|
5
|
+
export declare const PLUGIN_API_VERSION = "2";
|
|
4
6
|
/** Lines to the plugin's log, which `astera plugins logs` reads. Anything the plugin prints goes there too. */
|
|
5
7
|
export interface PluginLog {
|
|
6
8
|
info(message: string): void;
|
|
@@ -31,6 +33,13 @@ export interface PluginContext {
|
|
|
31
33
|
/** The permissions the person granted, a subset of those the manifest asks for. */
|
|
32
34
|
permissions: readonly string[];
|
|
33
35
|
log: PluginLog;
|
|
36
|
+
/** The plugin's open panels: `post` sends a JSON message (at most 64 KiB, 20 a second) to each of them, or to one panel
|
|
37
|
+
* by its id; a panel takes it with `window.astera.host.onMessage`. A panel that is not open gets nothing. */
|
|
38
|
+
panels: {
|
|
39
|
+
post(message: unknown, options?: {
|
|
40
|
+
panel?: string;
|
|
41
|
+
}): Promise<void>;
|
|
42
|
+
};
|
|
34
43
|
/** Aborted when Astera stops the plugin: disabled, removed, updated, or the Host leaving. In a handler (`onEvent`,
|
|
35
44
|
* `send`, `listItems`, `getItem`, `buildJobContext`, `runCheck`) it is that call's: it also aborts when Astera stops
|
|
36
45
|
* waiting for the call (30 seconds for an event or a notification, 15 for a job source, 30 minutes for a check). */
|
|
@@ -49,6 +58,11 @@ export interface PluginDefinition {
|
|
|
49
58
|
* you have seen. A property rather than a method, so a handler that takes only `AsteraEvent` does not typecheck:
|
|
50
59
|
* it would throw on a gap. */
|
|
51
60
|
onEvent?: (event: AsteraEvent | EventGap, ctx: PluginContext) => void | Promise<void>;
|
|
61
|
+
/** A message one of the plugin's panels sent with `window.astera.host.send`, and which panel sent it. What it returns
|
|
62
|
+
* (JSON, at most 64 KiB) is the panel's answer; it must settle within 15 s. */
|
|
63
|
+
onPanelMessage?: (message: unknown, from: {
|
|
64
|
+
panel: string;
|
|
65
|
+
}, ctx: PluginContext) => unknown | Promise<unknown>;
|
|
52
66
|
}
|
|
53
67
|
/** The plugin an entry file exports as its default. */
|
|
54
68
|
export declare function definePlugin<T extends PluginDefinition>(definition: T): T;
|
|
@@ -143,10 +157,12 @@ export interface JobSourceProvider extends PluginDefinition {
|
|
|
143
157
|
/** The provider an entry file exports as its default. */
|
|
144
158
|
export declare function defineJobSourceProvider<T extends JobSourceProvider>(provider: T): T;
|
|
145
159
|
/** What a completion check is asked about: the Task and the folder its checks run in. `root` is the Task's worktree, or
|
|
146
|
-
* the project folder
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
160
|
+
* the project folder. `base` is the commit the Task's work started from, when Astera recorded it, so a check can look
|
|
161
|
+
* at what the Task changed. `head` is the folder's commit when Astera asked, read again at each ask, and absent when it
|
|
162
|
+
* could not be read (not a repository, git failed): a check that looks up a result computed elsewhere asks for this
|
|
163
|
+
* commit and names it as its answer's `revision`. `branch` is not sent by this Astera: a check that needs it asks git
|
|
164
|
+
* in `root`. A check configured per project reads the project's own files under `root`; the plugin's settings are the
|
|
165
|
+
* rest of its configuration. */
|
|
150
166
|
export interface CompletionCheckInput {
|
|
151
167
|
projectId?: string;
|
|
152
168
|
jobId: string;
|
|
@@ -161,6 +177,14 @@ export interface CompletionCheckInput {
|
|
|
161
177
|
head?: string;
|
|
162
178
|
branch?: string;
|
|
163
179
|
};
|
|
180
|
+
/** On an ask that follows a `pending` answer: how many times this check answered pending in this round, when the
|
|
181
|
+
* round's first ask of it was (ISO time), and the `state` of its latest `pending` answer (absent when that answer gave
|
|
182
|
+
* none). A Host restart starts the waiting over, and the first ask after it has no `previous`. */
|
|
183
|
+
previous?: {
|
|
184
|
+
pending: number;
|
|
185
|
+
since: string;
|
|
186
|
+
state?: string;
|
|
187
|
+
};
|
|
164
188
|
}
|
|
165
189
|
/** One finding. Astera keeps a `message` (required) of up to 1,000 characters, a `file` of up to 500, a `line` that is a
|
|
166
190
|
* positive integer and a `severity` that is one of the two, and drops what is not. */
|
|
@@ -173,21 +197,41 @@ export interface CompletionCheckDiagnostic {
|
|
|
173
197
|
/** A check's answer. `passed` lets the Task's next check run. `failed` is the code's fault: the Task's repair request
|
|
174
198
|
* carries your summary, your first 20 findings as `file:line message` and your link, and the Task fails where its Job
|
|
175
199
|
* repairs nothing. `error` says the check could not be made (a service down, a missing token): Astera asks once more,
|
|
176
|
-
* then puts it to a person, and no repair is spent on it. `
|
|
177
|
-
*
|
|
178
|
-
*
|
|
200
|
+
* then puts it to a person, and no repair is spent on it. `pending` says the result is not ready yet (an analysis or a
|
|
201
|
+
* CI run still going): Astera asks again later, with `previous`, until 30 minutes from its first ask of this check in
|
|
202
|
+
* this round have passed; still pending then, the check counts as unknown. `unknown` says the check ran but cannot
|
|
203
|
+
* tell whether this work passes: Astera puts it to a person, asks nothing again on its own, and spends no repair.
|
|
204
|
+
*
|
|
205
|
+
* `summary` is cut at 1,000 characters (the status word when there is none), `diagnostics` keep the first 20 (Astera
|
|
206
|
+
* counts the rest, and keeps none of a `passed` check's: give the whole report as `externalUrl`), and `externalUrl` is
|
|
207
|
+
* kept when it is http or https within 2,048. */
|
|
179
208
|
export interface CompletionCheckResult {
|
|
180
|
-
status: 'passed' | 'failed' | 'error';
|
|
209
|
+
status: 'passed' | 'failed' | 'error' | 'pending' | 'unknown';
|
|
181
210
|
summary?: string;
|
|
182
211
|
diagnostics?: CompletionCheckDiagnostic[];
|
|
183
212
|
/** How many findings there are, when you send fewer: send the first 20 and the count, not thousands to be cut. */
|
|
184
213
|
diagnosticsTotal?: number;
|
|
185
214
|
externalUrl?: string;
|
|
215
|
+
/** The commit this result is about, as hex (7 to 64 characters). A check that reads a result computed elsewhere (an
|
|
216
|
+
* analysis, a CI run, a test report) sends it, as `workspace.head` or a prefix of it; a check of the folder as it is
|
|
217
|
+
* leaves it out. A `passed` or `failed` naming another commit than `workspace.head`, or naming it while the folder
|
|
218
|
+
* holds changes that are in no commit, counts as unknown: a result for other code never lets a Task pass. Anything
|
|
219
|
+
* but 7 to 64 hex digits makes the answer the wrong shape. An Astera older than SDK 0.3 ignores `revision`, so a check
|
|
220
|
+
* that sends it sets `astera.minAsteraVersion` to the first Astera that judges it. */
|
|
221
|
+
revision?: string;
|
|
222
|
+
/** For `pending`: when to ask again, in seconds. Astera keeps it within 5 to 120; without it Astera waits 10 seconds,
|
|
223
|
+
* then twice as long each time, up to 60. A wait that would run past the 30 minutes is cut to them, and no ask follows
|
|
224
|
+
* it: the check counts as unknown. */
|
|
225
|
+
retryAfterSeconds?: number;
|
|
226
|
+
/** For `pending`: text of at most 2,000 characters handed back as `previous.state` on the next ask, never shown to
|
|
227
|
+
* anyone. A longer one makes the answer the wrong shape. */
|
|
228
|
+
state?: string;
|
|
186
229
|
}
|
|
187
230
|
/** A plugin of the `completion-check` capability (`astera.capabilities: ["completion-check"]`, with no permission):
|
|
188
231
|
* Astera asks it when a Task whose checks name `plugin:<its id>` is done, in the order the Task lists its checks. A
|
|
189
|
-
*
|
|
190
|
-
*
|
|
232
|
+
* check has 30 minutes in a round, whether it spends them in one call or in several `pending` answers: each call's
|
|
233
|
+
* `ctx.signal` aborts when what is left of them runs out. Throw or reject to say the check could not be made: it counts
|
|
234
|
+
* as `error`, with your message. A plugin missing `runCheck` does not start. */
|
|
191
235
|
export interface CompletionCheckProvider extends PluginDefinition {
|
|
192
236
|
runCheck: (input: CompletionCheckInput, ctx: PluginContext) => CompletionCheckResult | Promise<CompletionCheckResult>;
|
|
193
237
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
/** The Plugin API this package
|
|
2
|
-
|
|
1
|
+
/** The Plugin API this package describes: the manifest's `astera.apiVersion` (spec §28). Plugin API 2 adds panels and
|
|
2
|
+
* the other contributions of `astera.contributes`; a plugin written for API 1 is typed the same. A panel page's
|
|
3
|
+
* `window.astera` is typed by `@astera-app/plugin-sdk/panel`. */
|
|
4
|
+
export const PLUGIN_API_VERSION = '2';
|
|
3
5
|
/** The plugin an entry file exports as its default. */
|
|
4
6
|
export function definePlugin(definition) {
|
|
5
7
|
return definition;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/** The methods of `window.astera`, as Astera's bridge names them. Astera's own list is checked against this one. */
|
|
2
|
+
export declare const PANEL_METHODS: readonly ['context', 'net.request', 'net.cancel', 'secrets.list', 'secrets.request', 'secrets.delete', 'files.pick', 'files.read', 'files.create', 'files.save', 'files.onOpen', 'storage.get', 'storage.set', 'storage.delete', 'storage.keys', 'host.send', 'host.onMessage'];
|
|
3
|
+
export type PanelMethod = (typeof PANEL_METHODS)[number];
|
|
4
|
+
/** Every code a call can be refused with. A refused call rejects with an `Error` whose message is `CODE: sentence`,
|
|
5
|
+
* such as `NO_GESTURE: net.request needs a key press or click in the panel within the last 5 seconds`: read the code
|
|
6
|
+
* before the first `:`.
|
|
7
|
+
* The sentence is for a person, and may change. Astera's sources are checked against this list. */
|
|
8
|
+
export declare const PANEL_ERROR_CODES: readonly ['BAD_HANDLE', 'BAD_KEY', 'BAD_REQUEST', 'BAD_SECRET', 'BAD_VALUE', 'BLOCKED_ADDRESS', 'BUSY', 'CANCELLED', 'CONFLICT', 'ENCODING', 'EXISTS', 'FAILED', 'FORBIDDEN', 'HOST', 'INVALID_ARGUMENTS', 'NETWORK', 'NOT_ANSWERED', 'NOT_FOUND', 'NOT_GRANTED', 'NOT_INSTALLED', 'NOT_SUPPORTED', 'NO_GESTURE', 'NO_HOST_CODE', 'NO_PERMISSION', 'NO_PROJECT', 'OUTSIDE_PROJECT', 'PAYLOAD_NOT_JSON', 'PAYLOAD_TOO_LARGE', 'PLUGIN_FAILED', 'PLUGIN_NOT_RUNNING', 'PLUGIN_OFF', 'PRIVATE_ADDRESS', 'REDIRECT_LIMIT', 'REFUSED', 'REPLY_TOO_LARGE', 'SAFE_MODE', 'SAVE_FAILED', 'SECRET_NOT_BOUND', 'SECRET_UNKNOWN', 'STORAGE_FULL', 'TIMEOUT', 'TLS', 'TOO_LARGE', 'TOO_MANY_CALLS', 'TOO_MANY_REQUESTS', 'UNKNOWN_METHOD', 'UNSAVED_IN_EDITOR', 'WRONG_TYPE'];
|
|
9
|
+
export type PanelErrorCode = (typeof PANEL_ERROR_CODES)[number];
|
|
10
|
+
/** What the panel was opened as: its plugin's id, its panel's id, and the project its tab was opened in, when the
|
|
11
|
+
* plugin was granted `workspace.read`. */
|
|
12
|
+
export interface PanelContext {
|
|
13
|
+
plugin: string;
|
|
14
|
+
panel: string;
|
|
15
|
+
project?: {
|
|
16
|
+
root: string;
|
|
17
|
+
name: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** A request to the network. `body` is text, at most 10 MiB; `timeoutMs` up to 120,000 (30 seconds without it). A
|
|
21
|
+
* header value, a query value or the body may name a secret as `{{secret:<name>}}`. `id`, at most 64 characters, is
|
|
22
|
+
* what `net.cancel` takes; Astera makes one when it is left out. */
|
|
23
|
+
export interface PanelNetRequest {
|
|
24
|
+
method: string;
|
|
25
|
+
url: string;
|
|
26
|
+
headers?: Record<string, string>;
|
|
27
|
+
body?: string;
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
id?: string;
|
|
30
|
+
}
|
|
31
|
+
/** A response. A text body is `text`; anything else comes as `base64`. Past 20 MiB the body is cut and `truncated` is
|
|
32
|
+
* set. `redirectedTo` is the origin a redirect pointed at that the plugin may not reach: the request stopped there. */
|
|
33
|
+
export interface PanelNetResponse {
|
|
34
|
+
status: number;
|
|
35
|
+
headers: Record<string, string>;
|
|
36
|
+
body: string;
|
|
37
|
+
bodyEncoding: 'text' | 'base64';
|
|
38
|
+
ms: number;
|
|
39
|
+
truncated?: true;
|
|
40
|
+
redirectedTo?: string;
|
|
41
|
+
}
|
|
42
|
+
/** A secret entered for the plugin's panels, by name, with the origins it may be sent to. A panel never reads a value. */
|
|
43
|
+
export interface PanelSecretInfo {
|
|
44
|
+
name: string;
|
|
45
|
+
origins: string[];
|
|
46
|
+
}
|
|
47
|
+
/** A file the person picked, named or opened in the panel: a handle, never a path, and the file's name. */
|
|
48
|
+
export interface PanelFileHandle {
|
|
49
|
+
handle: string;
|
|
50
|
+
name: string;
|
|
51
|
+
}
|
|
52
|
+
/** A file's UTF-8 text, at most 5 MiB, and the revision `files.save` must be given next. */
|
|
53
|
+
export interface PanelFileText {
|
|
54
|
+
text: string;
|
|
55
|
+
revision: string;
|
|
56
|
+
}
|
|
57
|
+
/** `window.astera` in a plugin panel. Each method answers a promise that rejects with `CODE: sentence` when Astera
|
|
58
|
+
* refuses the call (see `PANEL_ERROR_CODES`). Methods marked "key press or click" need one in the panel within the
|
|
59
|
+
* last 5 seconds. */
|
|
60
|
+
export interface AsteraPanelBridge {
|
|
61
|
+
context(): Promise<PanelContext>;
|
|
62
|
+
net: {
|
|
63
|
+
/** Needs `network.request`; key press or click. The first request to an origin the plugin may not reach yet asks
|
|
64
|
+
* the person. */
|
|
65
|
+
request(req: PanelNetRequest): Promise<PanelNetResponse>;
|
|
66
|
+
/** Needs `network.request`. */
|
|
67
|
+
cancel(id: string): Promise<{
|
|
68
|
+
cancelled: boolean;
|
|
69
|
+
}>;
|
|
70
|
+
};
|
|
71
|
+
secrets: {
|
|
72
|
+
/** Needs `network.request`. */
|
|
73
|
+
list(): Promise<{
|
|
74
|
+
secrets: PanelSecretInfo[];
|
|
75
|
+
}>;
|
|
76
|
+
/** Needs `network.request`; key press or click. Asks the person to enter it, for origins the plugin already holds. */
|
|
77
|
+
request(name: string, label: string, options: {
|
|
78
|
+
origins: string[];
|
|
79
|
+
}): Promise<{
|
|
80
|
+
secrets: PanelSecretInfo[];
|
|
81
|
+
}>;
|
|
82
|
+
/** Needs `network.request`; key press or click. */
|
|
83
|
+
delete(name: string): Promise<{
|
|
84
|
+
secrets: PanelSecretInfo[];
|
|
85
|
+
}>;
|
|
86
|
+
};
|
|
87
|
+
files: {
|
|
88
|
+
/** Needs `files.read`; key press or click. Null when the person picked nothing. */
|
|
89
|
+
pick(options?: {
|
|
90
|
+
extensions?: string[];
|
|
91
|
+
}): Promise<PanelFileHandle | null>;
|
|
92
|
+
/** Needs `files.read`. */
|
|
93
|
+
read(handle: string): Promise<PanelFileText>;
|
|
94
|
+
/** Needs `files.write`; key press or click. Asks the person for a folder and a name in the project; null when they
|
|
95
|
+
* chose none. Its first save takes `revision: null`. */
|
|
96
|
+
create(options: {
|
|
97
|
+
suggestedName: string;
|
|
98
|
+
extensions?: string[];
|
|
99
|
+
}): Promise<PanelFileHandle | null>;
|
|
100
|
+
/** Needs `files.write`; key press or click. `revision` is the one last read or saved (`CONFLICT` otherwise). */
|
|
101
|
+
save(handle: string, text: string, options: {
|
|
102
|
+
revision: string | null;
|
|
103
|
+
}): Promise<{
|
|
104
|
+
revision: string;
|
|
105
|
+
}>;
|
|
106
|
+
/** Needs `files.read`. Called with each file the person opens in this panel; answers how to stop listening. */
|
|
107
|
+
onOpen(listener: (file: PanelFileHandle) => void): () => void;
|
|
108
|
+
};
|
|
109
|
+
storage: {
|
|
110
|
+
/** The value stored under `key`: `undefined` when there is none, `null` for a stored null. */
|
|
111
|
+
get(key: string): Promise<unknown>;
|
|
112
|
+
/** A JSON value; keys of at most 128 characters, at most 5 MiB a plugin. */
|
|
113
|
+
set(key: string, value: unknown): Promise<null>;
|
|
114
|
+
delete(key: string): Promise<null>;
|
|
115
|
+
keys(): Promise<string[]>;
|
|
116
|
+
};
|
|
117
|
+
host: {
|
|
118
|
+
/** For a plugin with Host code: reaches its `onPanelMessage`, whose answer is the reply. JSON, at most 64 KiB. */
|
|
119
|
+
send(message: unknown): Promise<unknown>;
|
|
120
|
+
/** For a plugin with Host code: called with each message its `ctx.panels.post` sends; answers how to stop
|
|
121
|
+
* listening. */
|
|
122
|
+
onMessage(listener: (message: unknown) => void): () => void;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
declare global {
|
|
126
|
+
interface Window {
|
|
127
|
+
astera: AsteraPanelBridge;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// @astera-app/plugin-sdk/panel: what a plugin panel's page is written against (Plugin API 2, the panel broker of PE-B
|
|
2
|
+
// part 1). A panel runs as a web page in Astera, apart from the plugin's Host code, and reaches the network, files,
|
|
3
|
+
// secrets, a lasting store and its plugin's Host code only through `window.astera`, which Astera answers after checking
|
|
4
|
+
// the permission the person granted and, for some methods, a key press or click in the panel within the last 5 seconds.
|
|
5
|
+
//
|
|
6
|
+
// Reference it from the page's code to have `window.astera` typed:
|
|
7
|
+
// /// <reference types="@astera-app/plugin-sdk/panel" />
|
|
8
|
+
// or with a type import (`import type { AsteraPanelBridge } from '@astera-app/plugin-sdk/panel'`). The subpath needs
|
|
9
|
+
// `moduleResolution` `NodeNext` or `bundler`. At run time this entry holds only the two lists below; the bridge itself
|
|
10
|
+
// is Astera's.
|
|
11
|
+
/** The methods of `window.astera`, as Astera's bridge names them. Astera's own list is checked against this one. */
|
|
12
|
+
export const PANEL_METHODS = [
|
|
13
|
+
'context',
|
|
14
|
+
'net.request',
|
|
15
|
+
'net.cancel',
|
|
16
|
+
'secrets.list',
|
|
17
|
+
'secrets.request',
|
|
18
|
+
'secrets.delete',
|
|
19
|
+
'files.pick',
|
|
20
|
+
'files.read',
|
|
21
|
+
'files.create',
|
|
22
|
+
'files.save',
|
|
23
|
+
'files.onOpen',
|
|
24
|
+
'storage.get',
|
|
25
|
+
'storage.set',
|
|
26
|
+
'storage.delete',
|
|
27
|
+
'storage.keys',
|
|
28
|
+
'host.send',
|
|
29
|
+
'host.onMessage'
|
|
30
|
+
];
|
|
31
|
+
/** Every code a call can be refused with. A refused call rejects with an `Error` whose message is `CODE: sentence`,
|
|
32
|
+
* such as `NO_GESTURE: net.request needs a key press or click in the panel within the last 5 seconds`: read the code
|
|
33
|
+
* before the first `:`.
|
|
34
|
+
* The sentence is for a person, and may change. Astera's sources are checked against this list. */
|
|
35
|
+
export const PANEL_ERROR_CODES = [
|
|
36
|
+
'BAD_HANDLE',
|
|
37
|
+
'BAD_KEY',
|
|
38
|
+
'BAD_REQUEST',
|
|
39
|
+
'BAD_SECRET',
|
|
40
|
+
'BAD_VALUE',
|
|
41
|
+
'BLOCKED_ADDRESS',
|
|
42
|
+
'BUSY',
|
|
43
|
+
'CANCELLED',
|
|
44
|
+
'CONFLICT',
|
|
45
|
+
'ENCODING',
|
|
46
|
+
'EXISTS',
|
|
47
|
+
'FAILED',
|
|
48
|
+
'FORBIDDEN',
|
|
49
|
+
'HOST',
|
|
50
|
+
'INVALID_ARGUMENTS',
|
|
51
|
+
'NETWORK',
|
|
52
|
+
'NOT_ANSWERED',
|
|
53
|
+
'NOT_FOUND',
|
|
54
|
+
'NOT_GRANTED',
|
|
55
|
+
'NOT_INSTALLED',
|
|
56
|
+
'NOT_SUPPORTED',
|
|
57
|
+
'NO_GESTURE',
|
|
58
|
+
'NO_HOST_CODE',
|
|
59
|
+
'NO_PERMISSION',
|
|
60
|
+
'NO_PROJECT',
|
|
61
|
+
'OUTSIDE_PROJECT',
|
|
62
|
+
'PAYLOAD_NOT_JSON',
|
|
63
|
+
'PAYLOAD_TOO_LARGE',
|
|
64
|
+
'PLUGIN_FAILED',
|
|
65
|
+
'PLUGIN_NOT_RUNNING',
|
|
66
|
+
'PLUGIN_OFF',
|
|
67
|
+
'PRIVATE_ADDRESS',
|
|
68
|
+
'REDIRECT_LIMIT',
|
|
69
|
+
'REFUSED',
|
|
70
|
+
'REPLY_TOO_LARGE',
|
|
71
|
+
'SAFE_MODE',
|
|
72
|
+
'SAVE_FAILED',
|
|
73
|
+
'SECRET_NOT_BOUND',
|
|
74
|
+
'SECRET_UNKNOWN',
|
|
75
|
+
'STORAGE_FULL',
|
|
76
|
+
'TIMEOUT',
|
|
77
|
+
'TLS',
|
|
78
|
+
'TOO_LARGE',
|
|
79
|
+
'TOO_MANY_CALLS',
|
|
80
|
+
'TOO_MANY_REQUESTS',
|
|
81
|
+
'UNKNOWN_METHOD',
|
|
82
|
+
'UNSAVED_IN_EDITOR',
|
|
83
|
+
'WRONG_TYPE'
|
|
84
|
+
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astera-app/plugin-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Write Astera plugins: definePlugin and the plugin context's types.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astera",
|
|
@@ -31,6 +31,16 @@
|
|
|
31
31
|
"default": "./dist/cjs/index.js"
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
|
+
"./panel": {
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./dist/esm/panel.d.ts",
|
|
37
|
+
"default": "./dist/esm/panel.js"
|
|
38
|
+
},
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./dist/cjs/panel.d.ts",
|
|
41
|
+
"default": "./dist/cjs/panel.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
34
44
|
"./package.json": "./package.json"
|
|
35
45
|
},
|
|
36
46
|
"files": [
|