@astera-app/plugin-sdk 0.3.0 → 0.3.1

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 CHANGED
@@ -3,6 +3,15 @@
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.1
7
+
8
+ - `@astera-app/plugin-sdk/manifest.schema.json`, a JSON Schema of a plugin's `package.json`, for an editor: point
9
+ VS Code's `json.schemas` at `./node_modules/@astera-app/plugin-sdk/manifest.schema.json` for `package.json`.
10
+ `astera plugins validate` stays the authority, and checks rules a schema cannot hold.
11
+ - `dist/plugin-api.md`, the API reference of this SDK: every export, member, panel method and error code.
12
+
13
+ No API change: it needs the same Astera as 0.3.0.
14
+
6
15
  ## 0.3.0
7
16
 
8
17
  - `PLUGIN_API_VERSION` is `'2'`: Plugin API 2, panels and the other contributions of `astera.contributes`. A plugin
package/README.md CHANGED
@@ -3,6 +3,10 @@
3
3
  Write [Astera](https://github.com/parsingk/Astera) plugins.
4
4
 
5
5
  The guide, with a quick start and a sample plugin: [docs/plugins.md](https://github.com/parsingk/Astera/blob/main/docs/plugins.md).
6
+ Every export, member and error code: [docs/plugin-api.md](https://github.com/parsingk/Astera/blob/main/docs/plugin-api.md),
7
+ which this package carries as `dist/plugin-api.md`. It also carries `manifest.schema.json`, a JSON Schema of a plugin's
8
+ `package.json` for an editor
9
+ ([how to use it](https://github.com/parsingk/Astera/blob/main/docs/plugins.md#the-manifest)).
6
10
 
7
11
  ```bash
8
12
  npm install @astera-app/plugin-sdk
@@ -0,0 +1,504 @@
1
+ # Plugin SDK API reference
2
+
3
+ Every export of `@astera-app/plugin-sdk`, what it does, its limits, what it needs and how it fails. The guide to
4
+ writing a plugin is [docs/plugins.md](plugins.md): this page is the reference beside it. Each signature is the one the
5
+ SDK declares; the SDK's own `.d.ts` files say the same.
6
+
7
+ An Astera you have installed prints this page as it shipped with it: `astera plugins guide --api`. A plugin folder with
8
+ the SDK installed has it as `node_modules/@astera-app/plugin-sdk/dist/plugin-api.md` (from 0.3.1). Those copies do not
9
+ carry the pages this one links, which are in the Astera repository's docs folder:
10
+ https://github.com/parsingk/Astera/tree/main/docs.
11
+
12
+ The package has two entry points:
13
+
14
+ - [`@astera-app/plugin-sdk`](#astera-appplugin-sdk), for a plugin's Host code: the entry file Astera starts.
15
+ - [`@astera-app/plugin-sdk/panel`](#astera-appplugin-sdkpanel), for a panel's page: the types of `window.astera`.
16
+
17
+ ## Supported versions
18
+
19
+ | SDK | Astera it needs | Plugin API |
20
+ |---|---|---|
21
+ | 0.1 | 1.4.12 or later | 1 |
22
+ | 0.2 | 1.4.14 or later | 1 |
23
+ | 0.3 | newer than 1.5.6 (the release with the panel broker) | 1 and 2 |
24
+
25
+ A plugin can name the oldest Astera it runs on with `astera.minAsteraVersion`, and with Plugin API 2 a range with
26
+ `engines.astera`. [The migration guide](plugin-migration.md) says what changed at each step.
27
+
28
+ ## @astera-app/plugin-sdk
29
+
30
+ The entry file exports its plugin as its default, built with one of the `define…` functions below. Each of them returns
31
+ what it is given: it is there for the types.
32
+
33
+ ### `PLUGIN_API_VERSION`
34
+
35
+ ```typescript
36
+ const PLUGIN_API_VERSION = '2'
37
+ ```
38
+
39
+ The Plugin API this SDK describes, the manifest's `astera.apiVersion`. Plugin API 2 adds panels and the other
40
+ contributions of `astera.contributes`. A plugin written for API 1 is typed the same.
41
+
42
+ ### `definePlugin`
43
+
44
+ ```typescript
45
+ function definePlugin<T extends PluginDefinition>(definition: T): T
46
+ ```
47
+
48
+ The plugin an entry file exports as its default.
49
+
50
+ ```ts
51
+ import { definePlugin } from '@astera-app/plugin-sdk'
52
+
53
+ export default definePlugin({
54
+ async activate(ctx) {
55
+ const { items } = await ctx.astera.projects.list()
56
+ ctx.log.info(`${items.length} projects`)
57
+ }
58
+ })
59
+ ```
60
+
61
+ ### `PluginDefinition`
62
+
63
+ What a plugin may implement. Every member is optional.
64
+
65
+ | Member | Called | Limit |
66
+ |---|---|---|
67
+ | `activate(ctx)` | once the plugin is loaded; the plugin counts as running when it resolves | 30 s; past that, or a throw, is a crash |
68
+ | `deactivate()` | before the plugin is stopped, after `ctx.signal` aborts | 5 s, then Astera ends the process |
69
+ | `onEvent(event, ctx)` | the `event` capability: each of Astera's events, in order, one at a time, from where the plugin left off | 30 s a call |
70
+ | `onPanelMessage(message, from, ctx)` | a message one of the plugin's panels sent with `window.astera.host.send`, with `from.panel`; what it returns is the panel's answer | 15 s, JSON of at most 64 KiB |
71
+
72
+ `onEvent` takes `AsteraEvent | EventGap`: a `{ type: 'gap' }` means events were lost before the next one. Throw or
73
+ reject to have the same event handed over again (after 1 s, doubling to 5 minutes, for an hour). An event can come
74
+ twice: `event.id` never repeats, so drop one you have seen. It needs `astera.capabilities: ["event"]` and the
75
+ `events.subscribe` permission ([event plugins](plugins.md#event-plugins)).
76
+
77
+ A crash (an uncaught exception, an unhandled rejection, `process.exit()`) restarts the plugin after 1, then 2 seconds;
78
+ the third without 30 seconds of steady running marks it `failed` ([lifecycle](plugins.md#lifecycle)).
79
+
80
+ ### `PluginContext`
81
+
82
+ What `activate` and every handler are given.
83
+
84
+ | Member | What it is |
85
+ |---|---|
86
+ | `ctx.astera` | A client of the Host (`AsteraClient` from `@astera-app/client`), answered within the permissions the plugin was granted. See [`ctx.astera`](#ctxastera). |
87
+ | `ctx.settings` | The settings a person set (`astera plugins configure`), with the manifest's defaults, secret ones included. Read when the plugin starts; a change restarts it. |
88
+ | `ctx.secrets` | The plugin's own secret store: [`PluginSecrets`](#pluginsecrets). |
89
+ | `ctx.plugin` | This plugin as installed: `ctx.plugin.id` (the package name), `ctx.plugin.version` and `ctx.plugin.dir`, the folder it runs from. |
90
+ | `ctx.permissions` | The permissions the person granted, a subset of those the manifest asks for. |
91
+ | `ctx.log` | Lines to the plugin's log: [`PluginLog`](#pluginlog). |
92
+ | `ctx.panels` | `ctx.panels.post(message, { panel? })` sends a JSON message (at most 64 KiB, 20 a second) to each open panel of the plugin, or to one by its id; a panel takes it with `window.astera.host.onMessage`. A panel that is not open gets nothing. |
93
+ | `ctx.signal` | An `AbortSignal` aborted when Astera stops the plugin. In a handler it is that call's: it also aborts when Astera stops waiting (30 s for an event or a notification, 15 s for a job source, 30 minutes for a check). |
94
+
95
+ #### `ctx.astera`
96
+
97
+ `ctx.astera` is the client of [the Astera SDK](sdk.md), whose guide covers its arguments, answers, errors and paging.
98
+ A plugin may call the methods below, each with the permission it needs; a call without it is refused with
99
+ `PERMISSION_DENIED` ([permissions](plugins.md#permissions)). `ctx.astera.agentProfiles` is closed to plugins.
100
+
101
+ | Method | Permission |
102
+ |---|---|
103
+ | `ctx.astera.projects.list()` | `projects.read` |
104
+ | `ctx.astera.projects.get()` | `projects.read` |
105
+ | `ctx.astera.jobs.list()` | `jobs.read` |
106
+ | `ctx.astera.jobs.get()` | `jobs.read` |
107
+ | `ctx.astera.jobs.wait()` | `jobs.read` |
108
+ | `ctx.astera.jobs.create()` | `jobs.create` |
109
+ | `ctx.astera.jobs.run()` | `jobs.run` |
110
+ | `ctx.astera.runs.list()` | `runs.read` |
111
+ | `ctx.astera.runs.get()` | `runs.read` |
112
+ | `ctx.astera.runs.wait()` | `runs.read` |
113
+ | `ctx.astera.runs.follow()` | `runs.read` |
114
+ | `ctx.astera.runs.stop()` | `runs.control` |
115
+ | `ctx.astera.runs.resume()` | `runs.control` |
116
+ | `ctx.astera.tasks.list()` | `tasks.read` |
117
+ | `ctx.astera.tasks.get()` | `tasks.read` |
118
+ | `ctx.astera.tasks.create()` | `tasks.write` |
119
+ | `ctx.astera.questions.list()` | `questions.read` |
120
+ | `ctx.astera.questions.get()` | `questions.read` |
121
+ | `ctx.astera.questions.answer()` | `questions.answer` |
122
+ | `ctx.astera.completion.get()` | `completion.read` |
123
+ | `ctx.astera.events.list()` | `events.subscribe` |
124
+ | `ctx.astera.events.cursor()` | `events.subscribe` |
125
+ | `ctx.astera.events.subscribe()` | `events.subscribe` |
126
+
127
+ ### `PluginLog`
128
+
129
+ | Member | What it does |
130
+ |---|---|
131
+ | `ctx.log.info(message)` | A line to the plugin's log, which `astera plugins logs` reads. |
132
+ | `ctx.log.warn(message)` | The same, as a warning. |
133
+ | `ctx.log.error(message)` | The same, as an error. |
134
+
135
+ Anything the plugin prints goes to the log too. Astera hides its secret values there ([logs](plugins.md#logs)).
136
+
137
+ ### `PluginSecrets`
138
+
139
+ | Member | What it does |
140
+ |---|---|
141
+ | `ctx.secrets.get(name)` | The value, or `undefined` when there is none. |
142
+ | `ctx.secrets.set(name, value)` | Keeps it in Astera's store for this plugin alone, never shown to anyone. |
143
+ | `ctx.secrets.delete(name)` | Removes it. |
144
+
145
+ A name is letters, digits, `_`, `-` and `.`, at most 73, not starting or ending with `.`; `Token` is the same name as
146
+ `token`. A value is text of at most 65,536 characters. A name or value out of those rejects the call
147
+ ([settings and secrets](plugins.md#settings-and-secrets)).
148
+
149
+ ### `NOTIFICATION_KINDS`
150
+
151
+ ```typescript
152
+ const NOTIFICATION_KINDS = ['question.created', 'session.input_needed', 'run.failed', 'completion.exhausted', 'session.limit_waiting', 'run.completed', 'session.account_switched'] as const
153
+ ```
154
+
155
+ The kinds of notification Astera sends a notification plugin, most pressing first. A provider offers a setting for the
156
+ ones it leaves out; Astera sends all of them.
157
+
158
+ ### `NotificationKind`
159
+
160
+ One of `NOTIFICATION_KINDS`.
161
+
162
+ ### `NotificationLevel`
163
+
164
+ `'action' | 'error' | 'warning' | 'info'`: `action` waits on the person, `error` failed, `warning` stopped for now,
165
+ `info` went on.
166
+
167
+ ### `AsteraNotification`
168
+
169
+ Something worth telling a person, worded by Astera in the app's language: post `title` and `body` as they are.
170
+ `id` (the event's id; a notification can come twice, so drop one you have seen), `kind` (a later Astera may send a kind
171
+ the list does not name: post it by its title and body), `level` (a later level: post it as the nearest one you know),
172
+ `title` (a Job's objective or a session's title), `body` (one sentence), `occurredAt`, and `event` (the whole event).
173
+
174
+ ### `NotificationProvider`
175
+
176
+ A `PluginDefinition` with `send`. It needs `astera.capabilities: ["notification"]` and the `events.subscribe`
177
+ permission ([notification plugins](plugins.md#notification-plugins)).
178
+
179
+ | Member | Called | Limit |
180
+ |---|---|---|
181
+ | `send(notification, ctx)` | each notification, in order, one at a time, once `activate` has resolved | 30 s; throw or reject to have it sent again (after 1 s, doubling to 5 minutes, for an hour); one older than an hour when its turn comes is not sent |
182
+
183
+ ### `defineNotificationProvider`
184
+
185
+ ```typescript
186
+ function defineNotificationProvider<T extends NotificationProvider>(provider: T): T
187
+ ```
188
+
189
+ The notification provider an entry file exports as its default.
190
+
191
+ ```ts
192
+ import { defineNotificationProvider } from '@astera-app/plugin-sdk'
193
+
194
+ export default defineNotificationProvider({
195
+ async send(n, ctx) {
196
+ ctx.log.info(`${n.level}: ${n.title}: ${n.body}`)
197
+ }
198
+ })
199
+ ```
200
+
201
+ ### `JobSourceQuery`
202
+
203
+ What `listItems` is asked: `query` (the person's search) and `cursor` (the page before's `nextCursor`), both optional.
204
+
205
+ ### `JobSourceItem`
206
+
207
+ One ticket or issue: `id` (your own opaque id, 1 to 200 characters with no control characters, or the item is
208
+ refused), `title` (cut at 300), and optional `status` (cut at 100), `url` (kept when http or https) and `summary` (cut
209
+ at 1,000).
210
+
211
+ ### `JobSourcePage`
212
+
213
+ `items` (at most 100 are kept) and `nextCursor` (at most 2,000 characters), handed back for the next page; none means
214
+ the last page.
215
+
216
+ ### `JobSourceItemDetail`
217
+
218
+ A `JobSourceItem` read whole: `body` (cut at 20,000) and `fields`, at most 50 pairs of short text (100 characters a
219
+ name, 1,000 a value).
220
+
221
+ ### `JobSourceContext`
222
+
223
+ What a Job made from an item is to do: `objective` (at most 20,000; its first line, at most 300, names the Job, so
224
+ start it with the item's title), `sourceLabel` (such as `Linear ENG-123`, at most 200), and optional `sourceUrl`,
225
+ `evidence` (at most 20 `{ label, content }`, 20,000 characters each and 100,000 in all) and `metadata` (at most 50
226
+ pairs). Astera writes the Job's objective itself and quotes your text as data the Job's agent takes no orders from.
227
+
228
+ ### `JobSourceProvider`
229
+
230
+ A `PluginDefinition` with three methods; a plugin missing any of them does not start. It needs
231
+ `astera.capabilities: ["job-source"]` and no permission. Each call has 15 seconds. Throw or reject to say why there is
232
+ no answer: the person reads that sentence, and Astera tries nothing again
233
+ ([job source plugins](plugins.md#job-source-plugins)).
234
+
235
+ | Member | Answers |
236
+ |---|---|
237
+ | `listItems(input, ctx)` | a `JobSourcePage`, searched with `input.query`, from `input.cursor` on |
238
+ | `getItem(id, ctx)` | a `JobSourceItemDetail` for an id `listItems` gave; throw for one you do not know |
239
+ | `buildJobContext(id, ctx)` | the `JobSourceContext` of a Job made from that item |
240
+
241
+ ### `defineJobSourceProvider`
242
+
243
+ ```typescript
244
+ function defineJobSourceProvider<T extends JobSourceProvider>(provider: T): T
245
+ ```
246
+
247
+ The job source an entry file exports as its default.
248
+
249
+ ```ts
250
+ import { defineJobSourceProvider } from '@astera-app/plugin-sdk'
251
+
252
+ const ITEMS = [{ id: 'T-1', title: 'Fix the login page' }]
253
+
254
+ export default defineJobSourceProvider({
255
+ listItems: () => ({ items: ITEMS }),
256
+ getItem: (id) => {
257
+ const item = ITEMS.find((i) => i.id === id)
258
+ if (!item) throw new Error(`no item ${id}`)
259
+ return item
260
+ },
261
+ buildJobContext: (id) => ({ objective: `${ITEMS.find((i) => i.id === id)?.title ?? id}\n\nDo the work.`, sourceLabel: `Tickets ${id}` })
262
+ })
263
+ ```
264
+
265
+ ### `CompletionCheckInput`
266
+
267
+ What a completion check is asked about: `jobId`, `runId`, `taskId`, `task.title`, optional `projectId`, and
268
+ `workspace`: `root` (the Task's worktree, or the project folder), `base` (the commit the work started from, when
269
+ recorded), `head` (the folder's commit when Astera asked, read again at each ask; absent when it could not be read) and
270
+ `branch` (not sent by this Astera: ask git in `root`). `previous` is there on an ask that follows a `pending` answer:
271
+ `pending` (how many times), `since` (the round's first ask) and `state` (your latest `pending` answer's).
272
+
273
+ ### `CompletionCheckDiagnostic`
274
+
275
+ One finding: `message` (required, up to 1,000 characters), and optional `file` (up to 500), `line` (a positive
276
+ integer) and `severity` (`error` or `warning`). What is not that is dropped.
277
+
278
+ ### `CompletionCheckResult`
279
+
280
+ | `status` | Means | What Astera does |
281
+ |---|---|---|
282
+ | `passed` | the work passes | the Task's next check runs |
283
+ | `failed` | the code's fault | the Task's repair carries your summary, first 20 findings and link; the Task fails where its Job repairs nothing |
284
+ | `error` | the check could not be made | asks once more, then puts it to a person; no repair is spent |
285
+ | `pending` | the result is not ready yet | asks again with `previous`, within 30 minutes from its first ask; still pending then, it counts as unknown |
286
+ | `unknown` | the check ran but cannot tell | puts it to a person and asks nothing again |
287
+
288
+ The other fields: `summary` (cut at 1,000), `diagnostics` (the first 20 are kept, none of a `passed` check's),
289
+ `diagnosticsTotal` (the count, when you send fewer), `externalUrl` (http or https within 2,048), `revision` (the commit
290
+ the result is about, 7 to 64 hex digits; a `passed` or `failed` for another commit than `workspace.head`, or for a
291
+ folder holding changes in no commit, counts as unknown), `retryAfterSeconds` (for `pending`, kept within 5 to 120;
292
+ without it Astera waits 10 seconds, doubling up to 60) and `state` (for `pending`, at most 2,000 characters, handed back
293
+ as `previous.state`). A `revision` or `state` out of those makes the answer the wrong shape. An Astera older than SDK 0.3
294
+ ignores `revision`, so a check that sends it sets `astera.minAsteraVersion`.
295
+
296
+ ### `CompletionCheckProvider`
297
+
298
+ A `PluginDefinition` with `runCheck`; a plugin missing it does not start. It needs
299
+ `astera.capabilities: ["completion-check"]` and no permission. Astera asks it when a Task whose checks name
300
+ `plugin:<its id>` is done. A check has 30 minutes in a round, in one call or across `pending` answers: each call's
301
+ `ctx.signal` aborts when they run out. Throw or reject to say the check could not be made: it counts as `error`, with
302
+ your message ([completion check plugins](plugins.md#completion-check-plugins)).
303
+
304
+ | Member | Answers |
305
+ |---|---|
306
+ | `runCheck(input, ctx)` | a `CompletionCheckResult` |
307
+
308
+ ### `defineCompletionCheckProvider`
309
+
310
+ ```typescript
311
+ function defineCompletionCheckProvider<T extends CompletionCheckProvider>(provider: T): T
312
+ ```
313
+
314
+ The completion check an entry file exports as its default.
315
+
316
+ ```ts
317
+ import { defineCompletionCheckProvider } from '@astera-app/plugin-sdk'
318
+ import { existsSync } from 'node:fs'
319
+ import path from 'node:path'
320
+
321
+ export default defineCompletionCheckProvider({
322
+ runCheck: ({ workspace }) =>
323
+ existsSync(path.join(workspace.root, 'CHANGELOG.md'))
324
+ ? { status: 'passed' }
325
+ : { status: 'failed', summary: 'CHANGELOG.md is missing', diagnostics: [{ file: 'CHANGELOG.md', message: 'add a changelog' }] }
326
+ })
327
+ ```
328
+
329
+ ## @astera-app/plugin-sdk/panel
330
+
331
+ A panel's page runs in a sandboxed guest of its own: no Node and no network of its own. It reaches the network, files,
332
+ secrets, a lasting store and its plugin's Host code only through `window.astera`, which Astera answers after checking
333
+ the permission the person granted and, for some methods, a key press or click in the panel within the last 5 seconds
334
+ ([the panel broker](plugins.md#the-panel-broker)). Add this line to the page's code for the types (with
335
+ `moduleResolution` `NodeNext` or `bundler`):
336
+
337
+ ```js
338
+ /// <reference types="@astera-app/plugin-sdk/panel" />
339
+ ```
340
+
341
+ At run time this entry holds only `PANEL_METHODS` and `PANEL_ERROR_CODES`; the bridge itself is Astera's. It answers at
342
+ most 20 calls a second.
343
+
344
+ ### `AsteraPanelBridge`
345
+
346
+ The type of `window.astera`. Each method answers a promise that rejects with an `Error` whose message is
347
+ `CODE: sentence` when Astera refuses the call: read the code before the first `:`. "Gesture" means a key press or click
348
+ in the panel within the last 5 seconds.
349
+
350
+ | Method | Needs | Gesture | Answers |
351
+ |---|---|---|---|
352
+ | `window.astera.context()` | nothing | no | a [`PanelContext`](#panelcontext) |
353
+ | `window.astera.net.request(req)` | `network.request` | yes | a [`PanelNetResponse`](#panelnetresponse); the first request to an origin the plugin may not reach yet asks the person |
354
+ | `window.astera.net.cancel(id)` | `network.request` | no | `{ cancelled }` |
355
+ | `window.astera.secrets.list()` | `network.request` | no | `{ secrets }`, each a [`PanelSecretInfo`](#panelsecretinfo) |
356
+ | `window.astera.secrets.request(name, label, { origins })` | `network.request` | yes | `{ secrets }`; asks the person to enter it, for origins the plugin already holds |
357
+ | `window.astera.secrets.delete(name)` | `network.request` | yes | `{ secrets }` |
358
+ | `window.astera.files.pick({ extensions? })` | `files.read` | yes | a [`PanelFileHandle`](#panelfilehandle), or null when the person picked nothing |
359
+ | `window.astera.files.read(handle)` | `files.read` | no | a [`PanelFileText`](#panelfiletext) |
360
+ | `window.astera.files.create({ suggestedName, extensions? })` | `files.write` | yes | a `PanelFileHandle` for a folder and name the person chose in the project, or null; its first save takes `revision: null` |
361
+ | `window.astera.files.save(handle, text, { revision })` | `files.write` | yes | `{ revision }`; `revision` is the one last read or saved (`CONFLICT` otherwise) |
362
+ | `window.astera.files.onOpen(listener)` | `files.read` | no | a function that stops listening; the listener gets each file the person opens in this panel |
363
+ | `window.astera.storage.get(key)` | nothing | no | the value, `undefined` when there is none, `null` for a stored null |
364
+ | `window.astera.storage.set(key, value)` | nothing | no | `null`; a JSON value (the call at most 64 KiB), keys of at most 128 characters, at most 5 MiB a plugin |
365
+ | `window.astera.storage.delete(key)` | nothing | no | `null` |
366
+ | `window.astera.storage.keys()` | nothing | no | the keys |
367
+ | `window.astera.host.send(message)` | Host code | no | the plugin's `onPanelMessage` answer; JSON, at most 64 KiB |
368
+ | `window.astera.host.onMessage(listener)` | Host code | no | a function that stops listening; the listener gets each `ctx.panels.post` message |
369
+
370
+ A call's arguments travel as JSON, at most 64 KiB, or 10 MiB for `window.astera.net.request` and
371
+ `window.astera.files.save`; a larger call is refused with `PAYLOAD_TOO_LARGE` before Astera reads it.
372
+ `context()` names the project only when the plugin has `workspace.read`. A network request waits 30 seconds, or its
373
+ `timeoutMs` up to 120,000; at most 6 run at once for a plugin; Astera follows at most 5 redirects, each to an origin the
374
+ plugin holds. A plugin has one prompt or picker open at a time.
375
+
376
+ ```js
377
+ const button = document.querySelector('#refresh')
378
+ button.addEventListener('click', async () => {
379
+ try {
380
+ const res = await window.astera.net.request({ method: 'GET', url: 'https://api.example.com/status' })
381
+ document.querySelector('#out').textContent = res.body
382
+ } catch (e) {
383
+ document.querySelector('#out').textContent = String(e.message).split(':')[0]
384
+ }
385
+ })
386
+ ```
387
+
388
+ ### `PANEL_METHODS`
389
+
390
+ ```typescript
391
+ const PANEL_METHODS = ['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'] as const
392
+ ```
393
+
394
+ The methods of `window.astera`, as Astera's bridge names them.
395
+
396
+ ### `PanelMethod`
397
+
398
+ One of `PANEL_METHODS`.
399
+
400
+ ### `PANEL_ERROR_CODES`
401
+
402
+ Every code a call can be refused with. The sentence after the code is for a person and may change; the code does not.
403
+
404
+ | Code | Means |
405
+ |---|---|
406
+ | `BAD_HANDLE` | the handle is not a file this panel was given |
407
+ | `BAD_KEY` | a storage key is not text of 1 to 128 characters |
408
+ | `BAD_REQUEST` | the request is not one Astera can make (a missing name, value or origin, a malformed address) |
409
+ | `BAD_SECRET` | the secret's name or value is not one the store keeps |
410
+ | `BAD_VALUE` | the value to store is not JSON |
411
+ | `BLOCKED_ADDRESS` | the address is one no panel may reach (link-local, cloud metadata) |
412
+ | `BUSY` | the plugin already has a prompt or picker open |
413
+ | `CANCELLED` | `net.cancel` stopped the request |
414
+ | `CONFLICT` | the file changed, appeared or went since the panel read it |
415
+ | `ENCODING` | an answer to a request carrying a secret came in an encoding Astera cannot check for the secret |
416
+ | `EXISTS` | a file is already where the person named a new one |
417
+ | `FAILED` | the call failed for a reason with no code of its own |
418
+ | `FORBIDDEN` | the Host refused the call |
419
+ | `HOST` | the Host cannot be asked: not running, or gone |
420
+ | `INVALID_ARGUMENTS` | the call's arguments are not what the method takes |
421
+ | `NETWORK` | the address could not be resolved or reached |
422
+ | `NOT_ANSWERED` | the person closed the prompt without answering; the next call asks again |
423
+ | `NOT_FOUND` | the file is not there, is not a file, or has not been saved yet |
424
+ | `NOT_GRANTED` | the plugin may not reach that origin, or not for that method |
425
+ | `NOT_INSTALLED` | the plugin is not installed |
426
+ | `NOT_SUPPORTED` | this Host runs no plugin code |
427
+ | `NO_GESTURE` | the method needs a key press or click in the panel within the last 5 seconds |
428
+ | `NO_HOST_CODE` | `host.send` or `host.onMessage` in a plugin with no Host code |
429
+ | `NO_PERMISSION` | the plugin was not granted the permission the method needs |
430
+ | `NO_PROJECT` | the panel was opened with no project open, or its project is no longer open |
431
+ | `OUTSIDE_PROJECT` | the file is not in the panel's project, or now points outside it |
432
+ | `PAYLOAD_NOT_JSON` | the message cannot be sent as JSON |
433
+ | `PAYLOAD_TOO_LARGE` | the call's arguments, as JSON, pass 64 KiB (10 MiB for `net.request` and `files.save`) |
434
+ | `PLUGIN_FAILED` | the plugin's `onPanelMessage` threw |
435
+ | `PLUGIN_NOT_RUNNING` | the plugin's Host code is not running |
436
+ | `PLUGIN_OFF` | the plugin is turned off |
437
+ | `PRIVATE_ADDRESS` | the address is this computer or the local network, which the person has not allowed for that origin |
438
+ | `REDIRECT_LIMIT` | more than 5 redirects |
439
+ | `REFUSED` | the person refused: the origin, or entering the secret |
440
+ | `REPLY_TOO_LARGE` | the plugin's answer is larger than 64 KiB |
441
+ | `SAFE_MODE` | Safe Mode is on: no plugin runs |
442
+ | `SAVE_FAILED` | the file could not be written, or the editor holding it could not save it |
443
+ | `SECRET_NOT_BOUND` | the request names a secret at an origin it may not be sent to |
444
+ | `SECRET_UNKNOWN` | the request names a secret the panel does not have: ask for it with `secrets.request` |
445
+ | `STORAGE_FULL` | the plugin's store would pass 5 MiB |
446
+ | `TIMEOUT` | the request, or the plugin's answer, took too long |
447
+ | `TLS` | the server's certificate was refused |
448
+ | `TOO_LARGE` | a message to the plugin's Host code passes 64 KiB, or a file to read passes 5 MiB |
449
+ | `TOO_MANY_CALLS` | more than 20 calls in a second |
450
+ | `TOO_MANY_REQUESTS` | more than 6 network requests at once |
451
+ | `UNKNOWN_METHOD` | no such method |
452
+ | `UNSAVED_IN_EDITOR` | the file has unsaved changes in an editor tab |
453
+ | `WRONG_TYPE` | the file's extension is not one the panel takes |
454
+
455
+ ### `PanelErrorCode`
456
+
457
+ One of `PANEL_ERROR_CODES`.
458
+
459
+ ### `PanelContext`
460
+
461
+ What `context()` answers: `plugin` (its id), `panel` (the panel's id) and `project` (`project.root` and
462
+ `project.name`, only with `workspace.read` and a project open when the panel opened).
463
+
464
+ ### `PanelNetRequest`
465
+
466
+ `method`, `url`, and optional `headers`, `body` (text, at most 10 MiB), `timeoutMs` (up to 120,000; 30,000 without it)
467
+ and `id` (at most 64 characters, what `net.cancel` takes; Astera makes one when it is left out). A header value, a query
468
+ value or the body may name a secret as `{{secret:<name>}}`, which Astera fills in just before sending, and only to an
469
+ origin the secret is bound to.
470
+
471
+ ### `PanelNetResponse`
472
+
473
+ `status`, `headers`, `body`, `bodyEncoding` (`text`, or `base64` for anything else), `ms`, and `truncated` (the body
474
+ passed 20 MiB and was cut) and `redirectedTo` (the origin a redirect pointed at that the plugin may not reach: the
475
+ request stopped there) when they apply. Every secret of the plugin in it reads `[redacted]`.
476
+
477
+ ### `PanelSecretInfo`
478
+
479
+ A secret entered for the plugin's panels: `name` and the `origins` it may be sent to. A panel never reads a value.
480
+
481
+ ### `PanelFileHandle`
482
+
483
+ A file the person picked, named or opened in the panel: `handle` (never a path) and `name`.
484
+
485
+ ### `PanelFileText`
486
+
487
+ A file's UTF-8 text (`text`, at most 5 MiB) and the `revision` `files.save` must be given next.
488
+
489
+ ## Not in the SDK
490
+
491
+ What agents and authors often reach for, and what to use instead:
492
+
493
+ - **A panel's own network.** A page cannot fetch or open a socket: its Content-Security-Policy refuses every request.
494
+ Use `window.astera.net.request`, with the `network.request` permission.
495
+ - **Node in a page.** A page has no `require`, no `process` and no file system. Read and save the person's files with
496
+ `window.astera.files`, keep data with `window.astera.storage`, and do the rest in Host code reached with
497
+ `window.astera.host.send`.
498
+ - **A data folder.** Astera gives a plugin none yet. Its installed copy, `ctx.plugin.dir`, is replaced on every install
499
+ and update (and on each change under `astera plugins dev`), so nothing written there lasts. Keep secrets in
500
+ `ctx.secrets`, settings in `astera.settingsSchema`, a panel's state in `window.astera.storage`, and anything else in a
501
+ folder of the plugin's own outside the installed copy. Host code is trusted code and could write anywhere the person
502
+ can: it must not write outside what it owns.
503
+ - **A method the tables above do not list.** There is none: if you need one, say so rather than calling a name that is
504
+ not here.
@@ -0,0 +1,245 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "Astera plugin package.json",
4
+ "description": "The structure of an Astera plugin's package.json, for an editor. `astera plugins validate` is the authority: it checks rules a schema cannot hold (a command naming a declared panel, a theme's contrast, files in the folder), and a manifest this schema passes can still fail there.",
5
+ "type": "object",
6
+ "required": ["name", "version", "astera"],
7
+ "properties": {
8
+ "name": {
9
+ "description": "The npm package name, which is also the plugin's id.",
10
+ "type": "string",
11
+ "maxLength": 214,
12
+ "pattern": "^(?:@[a-z0-9-][a-z0-9-._]*\\/)?[a-z0-9-][a-z0-9-._]*$"
13
+ },
14
+ "version": {
15
+ "description": "A semver version.",
16
+ "type": "string",
17
+ "pattern": "^(\\d+)\\.(\\d+)\\.(\\d+)(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$"
18
+ },
19
+ "displayName": {
20
+ "description": "The name Astera shows; the package name when absent.",
21
+ "type": "string",
22
+ "minLength": 1,
23
+ "maxLength": 64
24
+ },
25
+ "description": {
26
+ "description": "One or two sentences Astera shows beside the plugin.",
27
+ "type": "string"
28
+ },
29
+ "license": {
30
+ "description": "An SPDX license id, or SEE LICENSE IN <file>. validate warns when it is missing or not one it knows.",
31
+ "type": "string"
32
+ },
33
+ "engines": {
34
+ "properties": {
35
+ "astera": {
36
+ "description": "Plugin API 2: the Astera versions the plugin runs on, as comparators all of which must hold, such as \">=1.7.0 <2.0.0\".",
37
+ "type": "string"
38
+ }
39
+ }
40
+ },
41
+ "astera": {
42
+ "description": "What Astera reads: the Plugin API, what the plugin runs and shows, and what it asks for.",
43
+ "type": "object",
44
+ "required": ["apiVersion"],
45
+ "properties": {
46
+ "apiVersion": {
47
+ "description": "The Plugin API the plugin is written for. \"2\" adds a ui page, contributions and themes.",
48
+ "type": "string",
49
+ "enum": ["1", "2"]
50
+ },
51
+ "entry": {
52
+ "description": "The Node file Astera starts, relative to the plugin's folder: trusted code with the person's rights. Required by Plugin API 1.",
53
+ "type": "string",
54
+ "minLength": 1
55
+ },
56
+ "ui": { "description": "Plugin API 2: the .html page the plugin's panels show, relative to its folder. Plugin API 1 ignores it." },
57
+ "capabilities": {
58
+ "description": "What the plugin's Host code serves; each needs an entry.",
59
+ "type": "array",
60
+ "uniqueItems": true,
61
+ "items": { "enum": ["event", "job-source", "completion-check", "notification"] }
62
+ },
63
+ "permissions": {
64
+ "description": "What the plugin asks Astera for. The first group opens Host commands to an entry; the second is the UI's (Plugin API 2).",
65
+ "type": "array",
66
+ "uniqueItems": true,
67
+ "items": {
68
+ "enum": [
69
+ "projects.read",
70
+ "jobs.read",
71
+ "jobs.create",
72
+ "jobs.run",
73
+ "runs.read",
74
+ "runs.control",
75
+ "tasks.read",
76
+ "tasks.write",
77
+ "questions.read",
78
+ "questions.answer",
79
+ "completion.read",
80
+ "events.subscribe",
81
+ "github.read",
82
+ "github.write",
83
+ "how-it-works.read",
84
+ "commands.register",
85
+ "panels.register",
86
+ "workspace.read",
87
+ "themes.register",
88
+ "network.request",
89
+ "files.read",
90
+ "files.write"
91
+ ]
92
+ }
93
+ },
94
+ "minAsteraVersion": {
95
+ "description": "The oldest Astera that runs the plugin.",
96
+ "type": "string",
97
+ "pattern": "^(\\d+)\\.(\\d+)\\.(\\d+)(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$"
98
+ },
99
+ "settingsSchema": { "$ref": "#/$defs/settingsSchema" },
100
+ "network": {
101
+ "description": "Plugin API 2: the origins the plugin always needs, granted with the install. Needs network.request.",
102
+ "type": "object",
103
+ "properties": {
104
+ "origins": {
105
+ "type": "array",
106
+ "maxItems": 20,
107
+ "items": {
108
+ "type": "object",
109
+ "required": ["origin", "access"],
110
+ "properties": {
111
+ "origin": { "description": "https:// or http://, a host and an optional port, no path.", "type": "string" },
112
+ "access": { "description": "read sends no body; send may.", "enum": ["read", "send"] }
113
+ }
114
+ }
115
+ }
116
+ }
117
+ },
118
+ "contributes": { "description": "Plugin API 2: what the plugin adds to Astera's interface. Plugin API 1 ignores it." }
119
+ },
120
+ "if": { "required": ["apiVersion"], "properties": { "apiVersion": { "const": "2" } } },
121
+ "then": {
122
+ "properties": {
123
+ "ui": { "type": "string", "pattern": "\\.[Hh][Tt][Mm][Ll]$" },
124
+ "contributes": {
125
+ "type": "object",
126
+ "properties": {
127
+ "commands": { "description": "Each opens one of the plugin's panels.", "type": "array", "maxItems": 50, "items": { "$ref": "#/$defs/command" } },
128
+ "panels": { "description": "Panels showing the plugin's ui page.", "type": "array", "maxItems": 20, "items": { "$ref": "#/$defs/panel" } },
129
+ "sidebar": { "description": "A panel shown in the sidebar from a rail button.", "type": "array", "maxItems": 2, "items": { "$ref": "#/$defs/sidebarView" } },
130
+ "statusBar": { "description": "A short text in the status bar that runs one of the plugin's commands.", "type": "array", "maxItems": 2, "items": { "$ref": "#/$defs/statusItem" } },
131
+ "themes": { "description": "Colour themes over a built-in base.", "type": "array", "maxItems": 4, "items": { "$ref": "#/$defs/theme" } }
132
+ }
133
+ }
134
+ }
135
+ }
136
+ }
137
+ },
138
+ "$defs": {
139
+ "contributionId": {
140
+ "description": "Lower-case letters, digits and . _ -, starting with a letter or digit.",
141
+ "type": "string",
142
+ "pattern": "^[a-z0-9][a-z0-9._-]{0,63}$"
143
+ },
144
+ "title": { "type": "string", "minLength": 1, "maxLength": 64 },
145
+ "command": {
146
+ "type": "object",
147
+ "required": ["id", "title", "panel"],
148
+ "properties": {
149
+ "id": { "$ref": "#/$defs/contributionId" },
150
+ "title": { "$ref": "#/$defs/title" },
151
+ "panel": { "description": "The id of a panel the plugin contributes.", "type": "string", "minLength": 1 }
152
+ }
153
+ },
154
+ "panel": {
155
+ "type": "object",
156
+ "required": ["id", "title"],
157
+ "properties": {
158
+ "id": { "$ref": "#/$defs/contributionId" },
159
+ "title": { "$ref": "#/$defs/title" },
160
+ "fileTypes": {
161
+ "description": "Extensions, lower case and without a dot, whose files Astera offers to open in this panel. Needs files.read.",
162
+ "type": "array",
163
+ "maxItems": 20,
164
+ "items": { "type": "string", "pattern": "^[a-z0-9][a-z0-9+_-]{0,15}$" }
165
+ }
166
+ }
167
+ },
168
+ "sidebarView": {
169
+ "type": "object",
170
+ "required": ["id", "title", "panel"],
171
+ "properties": {
172
+ "id": { "$ref": "#/$defs/contributionId" },
173
+ "title": { "$ref": "#/$defs/title" },
174
+ "panel": { "description": "The id of a panel the plugin contributes.", "type": "string" }
175
+ }
176
+ },
177
+ "statusItem": {
178
+ "type": "object",
179
+ "required": ["id", "text", "command"],
180
+ "properties": {
181
+ "id": { "$ref": "#/$defs/contributionId" },
182
+ "text": { "type": "string", "minLength": 1, "maxLength": 24 },
183
+ "command": { "description": "The id of a command the plugin contributes.", "type": "string" }
184
+ }
185
+ },
186
+ "hex": { "description": "A #rrggbb colour.", "type": "string", "pattern": "^#[0-9a-fA-F]{6}$" },
187
+ "theme": {
188
+ "description": "Colours over a built-in base; validate checks that text keeps its contrast and surfaces stay dark.",
189
+ "type": "object",
190
+ "required": ["id", "title", "base", "colors"],
191
+ "properties": {
192
+ "id": { "$ref": "#/$defs/contributionId" },
193
+ "title": { "$ref": "#/$defs/title" },
194
+ "base": { "enum": ["vega", "orion", "umbra", "aurora", "antares", "quasar", "sirius"] },
195
+ "colors": {
196
+ "type": "object",
197
+ "additionalProperties": false,
198
+ "properties": {
199
+ "bg": { "$ref": "#/$defs/hex" },
200
+ "rail": { "$ref": "#/$defs/hex" },
201
+ "panel": { "$ref": "#/$defs/hex" },
202
+ "elevated": { "$ref": "#/$defs/hex" },
203
+ "surfaceHover": { "$ref": "#/$defs/hex" },
204
+ "termBg": { "$ref": "#/$defs/hex" },
205
+ "line": { "$ref": "#/$defs/hex" },
206
+ "lineSoft": { "$ref": "#/$defs/hex" },
207
+ "text": { "$ref": "#/$defs/hex" },
208
+ "textDim": { "$ref": "#/$defs/hex" },
209
+ "textFaint": { "$ref": "#/$defs/hex" },
210
+ "railIcon": { "$ref": "#/$defs/hex" },
211
+ "accent": { "$ref": "#/$defs/hex" },
212
+ "accentInk": { "$ref": "#/$defs/hex" },
213
+ "statusBg": { "$ref": "#/$defs/hex" },
214
+ "statusInk": { "$ref": "#/$defs/hex" },
215
+ "mdLink": { "$ref": "#/$defs/hex" }
216
+ }
217
+ }
218
+ }
219
+ },
220
+ "settingsSchema": {
221
+ "description": "The settings a person sets with astera plugins configure; needs an entry.",
222
+ "type": "object",
223
+ "required": ["type", "properties"],
224
+ "additionalProperties": false,
225
+ "properties": {
226
+ "type": { "const": "object" },
227
+ "properties": { "type": "object", "maxProperties": 50, "additionalProperties": { "$ref": "#/$defs/setting" } },
228
+ "required": { "type": "array", "items": { "type": "string" } }
229
+ }
230
+ },
231
+ "setting": {
232
+ "type": "object",
233
+ "required": ["type"],
234
+ "additionalProperties": false,
235
+ "properties": {
236
+ "type": { "enum": ["string", "number", "integer", "boolean"] },
237
+ "title": { "type": "string", "maxLength": 64 },
238
+ "description": { "type": "string", "maxLength": 500 },
239
+ "default": { "type": ["string", "number", "boolean"] },
240
+ "enum": { "type": "array", "maxItems": 50 },
241
+ "secret": { "description": "A string kept in Astera's secret store and never shown.", "const": true }
242
+ }
243
+ }
244
+ }
245
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astera-app/plugin-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Write Astera plugins: definePlugin and the plugin context's types.",
5
5
  "keywords": [
6
6
  "astera",
@@ -41,10 +41,12 @@
41
41
  "default": "./dist/cjs/panel.js"
42
42
  }
43
43
  },
44
+ "./manifest.schema.json": "./manifest.schema.json",
44
45
  "./package.json": "./package.json"
45
46
  },
46
47
  "files": [
47
48
  "dist",
49
+ "manifest.schema.json",
48
50
  "README.md",
49
51
  "LICENSE",
50
52
  "CHANGELOG.md"