@astera-app/plugin-sdk 0.1.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 CHANGED
@@ -3,6 +3,51 @@
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
+
29
+ ## 0.2.0
30
+
31
+ - `onEvent` on a plugin: the `event` capability, which hands the plugin each of Astera's events in order, from where
32
+ it left off, and tries an event again when the handler throws.
33
+ - `defineNotificationProvider` and its `send`: the `notification` capability, which hands the plugin each thing worth
34
+ telling a person (a question, a session waiting, a failed or finished Run, a usage limit), worded by Astera in the
35
+ person's language. `NOTIFICATION_KINDS` lists the kinds, for a provider's setting of the ones it leaves out.
36
+ - `defineJobSourceProvider` and its `listItems`, `getItem` and `buildJobContext`, with the types they answer
37
+ (`JobSourceItem`, `JobSourcePage`, `JobSourceItemDetail`, `JobSourceContext`): the `job-source` capability, from
38
+ which a person, the `astera sources` commands and MCP clients pick a ticket to make a Job from. The Job is named by
39
+ the first line of the context's `objective`, so a provider starts it with the item's title.
40
+ - `defineCompletionCheckProvider` and its `runCheck`, with the types it is asked with and answers
41
+ (`CompletionCheckInput`, `CompletionCheckResult`, `CompletionCheckDiagnostic`): the `completion-check` capability,
42
+ which a Task names among its checks as `plugin:<id>`. Its `failed` goes to the Task's repair loop with its findings
43
+ (Astera keeps the first 20; a check that found more sends 20 and its own `diagnosticsTotal`); its `error` is asked
44
+ once more, then put to a person.
45
+ - In a handler (`onEvent`, `send`, `listItems`, `getItem`, `buildJobContext`, `runCheck`), `ctx.signal` is that call's:
46
+ it also aborts when Astera stops waiting for the call, so a handler can stop the work it started.
47
+
48
+ All five need Astera 1.4.14 or later. The plugin SDK needs `@astera-app/client` 0.2.0 or later, whose events include the
49
+ session events.
50
+
6
51
  ## 0.1.0
7
52
 
8
53
  The first release on npm: `definePlugin` and the types of the plugin context, for Plugin API 1, which Astera 1.4.12
package/README.md CHANGED
@@ -25,8 +25,28 @@ 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
29
- permissions the person granted.
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
+ permissions the person granted. A plugin that names the `event` capability gets each of Astera's events, in order, in
30
+ its `onEvent` ([event plugins](https://github.com/parsingk/Astera/blob/main/docs/plugins.md#event-plugins)), and one
31
+ that names the `notification` capability gets each notification, worded for a person, in its `send`
32
+ ([notification plugins](https://github.com/parsingk/Astera/blob/main/docs/plugins.md#notification-plugins)), which
33
+ `defineNotificationProvider` types. One that names the `job-source` capability is asked for tickets a Job can be made
34
+ from, in its `listItems`, `getItem` and `buildJobContext`
35
+ ([job source plugins](https://github.com/parsingk/Astera/blob/main/docs/plugins.md#job-source-plugins)), which
36
+ `defineJobSourceProvider` types. One that names the `completion-check` capability is asked whether a Task's work
37
+ passes, in its `runCheck`
38
+ ([completion check plugins](https://github.com/parsingk/Astera/blob/main/docs/plugins.md#completion-check-plugins)),
39
+ which `defineCompletionCheckProvider` types.
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
+ ```
30
50
 
31
51
  Plugins run trusted code on the person's machine: a plugin can do anything they can, and its permissions limit only
32
52
  what it asks Astera for.
@@ -1,6 +1,8 @@
1
- import type { AsteraClient } from '@astera-app/client';
2
- /** The Plugin API this package is written for: the manifest's `astera.apiVersion` (spec §28). */
3
- export declare const PLUGIN_API_VERSION = "1";
1
+ import type { AsteraClient, AsteraEvent, EventGap } from '@astera-app/client';
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,7 +33,16 @@ 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;
34
- /** Aborted when Astera stops the plugin: disabled, removed, updated, or the Host leaving. */
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
+ };
43
+ /** Aborted when Astera stops the plugin: disabled, removed, updated, or the Host leaving. In a handler (`onEvent`,
44
+ * `send`, `listItems`, `getItem`, `buildJobContext`, `runCheck`) it is that call's: it also aborts when Astera stops
45
+ * waiting for the call (30 seconds for an event or a notification, 15 for a job source, 30 minutes for a check). */
35
46
  signal: AbortSignal;
36
47
  }
37
48
  export interface PluginDefinition {
@@ -39,6 +50,190 @@ export interface PluginDefinition {
39
50
  activate?(ctx: PluginContext): void | Promise<void>;
40
51
  /** Called before the plugin is stopped, with a few seconds to finish. */
41
52
  deactivate?(): void | Promise<void>;
53
+ /** The `event` capability (`astera.capabilities: ["event"]`, with the `events.subscribe` permission): each of
54
+ * Astera's events, in order, one at a time, from where this plugin left off, once `activate` has resolved. A
55
+ * `{ type: 'gap' }` first means events were lost before the next one. Throw or reject to have the same event handed
56
+ * over again (after 1 s, doubling to 5 min, for an hour). It must settle within 30 s: past that the call's
57
+ * `ctx.signal` aborts, and a handler that does not stop runs beside the event's next try. An event can come twice: `event.id` never repeats, so drop one
58
+ * you have seen. A property rather than a method, so a handler that takes only `AsteraEvent` does not typecheck:
59
+ * it would throw on a gap. */
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>;
42
66
  }
43
67
  /** The plugin an entry file exports as its default. */
44
68
  export declare function definePlugin<T extends PluginDefinition>(definition: T): T;
69
+ /** The kinds of notification Astera sends a `notification` plugin, most pressing first. A provider offers a setting
70
+ * for the ones it leaves out; Astera sends all of them. Astera's own copy of this list is checked against this one. */
71
+ export declare const NOTIFICATION_KINDS: readonly ['question.created', 'session.input_needed', 'run.failed', 'completion.exhausted', 'session.limit_waiting', 'run.completed', 'session.account_switched'];
72
+ export type NotificationKind = (typeof NOTIFICATION_KINDS)[number];
73
+ /** How much it matters: `action` waits on the person, `error` failed, `warning` stopped for now, `info` went on. */
74
+ export type NotificationLevel = 'action' | 'error' | 'warning' | 'info';
75
+ /** Something worth telling a person, already worded by Astera in the language the app is set to: post `title` and
76
+ * `body` as they are. */
77
+ export interface AsteraNotification {
78
+ /** The event's id: a notification can come twice, so drop one you have seen. */
79
+ readonly id: string;
80
+ /** The event's type. A later Astera may send a kind this list does not name yet: post it by its title and body. */
81
+ readonly kind: NotificationKind | (string & {});
82
+ /** How much it matters. A later Astera may add a level: post it as the nearest one you know. */
83
+ readonly level: NotificationLevel | (string & {});
84
+ /** What it is about: a Job's objective, or a session's title. */
85
+ readonly title: string;
86
+ /** One sentence. */
87
+ readonly body: string;
88
+ readonly occurredAt: string;
89
+ /** The whole event, for its ids and detail. */
90
+ readonly event: AsteraEvent;
91
+ }
92
+ /** A plugin of the `notification` capability (`astera.capabilities: ["notification"]`, with the `events.subscribe`
93
+ * permission). */
94
+ export interface NotificationProvider extends PluginDefinition {
95
+ /** Each notification, in order, one at a time, once `activate` has resolved. Throw or reject to have it sent again
96
+ * (after 1 s, doubling to 5 min, for an hour); it must settle within 30 s. A notification older than an hour when
97
+ * its turn comes is not sent. */
98
+ send: (notification: AsteraNotification, ctx: PluginContext) => void | Promise<void>;
99
+ }
100
+ /** The provider an entry file exports as its default. */
101
+ export declare function defineNotificationProvider<T extends NotificationProvider>(provider: T): T;
102
+ /** What `listItems` is asked: the person's search, and the cursor of the page before when there is one. */
103
+ export interface JobSourceQuery {
104
+ query?: string;
105
+ cursor?: string;
106
+ }
107
+ /** One item of a job source: a ticket, an issue. Astera refuses an item whose `id` is not 1 to 200 characters with no
108
+ * control characters (it is your own, opaque id, `ENG-123` say), cuts `title` at 300 characters, `status` at 100 and
109
+ * `summary` at 1,000, and keeps `url` only when it is http or https. */
110
+ export interface JobSourceItem {
111
+ id: string;
112
+ title: string;
113
+ status?: string;
114
+ url?: string;
115
+ summary?: string;
116
+ }
117
+ /** A page of items: at most 100 are kept, and `nextCursor` (at most 2,000 characters) is handed back to `listItems`
118
+ * for the next page. No `nextCursor` means this is the last page. */
119
+ export interface JobSourcePage {
120
+ items: JobSourceItem[];
121
+ nextCursor?: string;
122
+ }
123
+ /** One item read whole: `body` cut at 20,000 characters, and at most 50 `fields` of short text (100 characters a name,
124
+ * 1,000 a value), shown beside it. */
125
+ export interface JobSourceItemDetail extends JobSourceItem {
126
+ body?: string;
127
+ fields?: Record<string, string>;
128
+ }
129
+ /** What a Job made from an item is to do. Astera writes the Job's objective itself: a first line naming
130
+ * `sourceLabel` (`Linear ENG-123`, at most 200 characters) and `sourceUrl`, then your `objective` (at most 20,000), each
131
+ * `evidence` entry under its label (at most 20 entries, 20,000 characters each and 100,000 in all) and the `metadata`
132
+ * (at most 50 pairs), quoted as data the Job's agent does not take orders from. The Job keeps the item as its source,
133
+ * and is named, in the app, the CLI and notifications, by the first line of your `objective` (at most 300 characters):
134
+ * start it with the item's title. */
135
+ export interface JobSourceContext {
136
+ objective: string;
137
+ sourceLabel: string;
138
+ sourceUrl?: string;
139
+ evidence?: Array<{
140
+ label: string;
141
+ content: string;
142
+ }>;
143
+ metadata?: Record<string, string>;
144
+ }
145
+ /** A plugin of the `job-source` capability (`astera.capabilities: ["job-source"]`, with no permission): Astera asks it
146
+ * for items when a person, the `astera sources` commands or an MCP client looks for a ticket to make a Job from. Each
147
+ * call has 15 seconds. Throw or reject to say why there is no answer ("401 Unauthorized"): the person reads that
148
+ * sentence, and Astera tries nothing again. A plugin missing any of the three does not start. */
149
+ export interface JobSourceProvider extends PluginDefinition {
150
+ /** A page of items, searched with `input.query`, from `input.cursor` on. */
151
+ listItems: (input: JobSourceQuery, ctx: PluginContext) => JobSourcePage | Promise<JobSourcePage>;
152
+ /** One item read whole, by the id `listItems` gave it. Throw for an id you do not know. */
153
+ getItem: (id: string, ctx: PluginContext) => JobSourceItemDetail | Promise<JobSourceItemDetail>;
154
+ /** What a Job made from the item is to do, by the id `listItems` gave it. */
155
+ buildJobContext: (id: string, ctx: PluginContext) => JobSourceContext | Promise<JobSourceContext>;
156
+ }
157
+ /** The provider an entry file exports as its default. */
158
+ export declare function defineJobSourceProvider<T extends JobSourceProvider>(provider: T): T;
159
+ /** What a completion check is asked about: the Task and the folder its checks run in. `root` is the Task's worktree, or
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. */
166
+ export interface CompletionCheckInput {
167
+ projectId?: string;
168
+ jobId: string;
169
+ runId: string;
170
+ taskId: string;
171
+ task: {
172
+ title: string;
173
+ };
174
+ workspace: {
175
+ root: string;
176
+ base?: string;
177
+ head?: string;
178
+ branch?: string;
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
+ };
188
+ }
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
190
+ * positive integer and a `severity` that is one of the two, and drops what is not. */
191
+ export interface CompletionCheckDiagnostic {
192
+ file?: string;
193
+ line?: number;
194
+ message: string;
195
+ severity?: 'error' | 'warning';
196
+ }
197
+ /** A check's answer. `passed` lets the Task's next check run. `failed` is the code's fault: the Task's repair request
198
+ * carries your summary, your first 20 findings as `file:line message` and your link, and the Task fails where its Job
199
+ * repairs nothing. `error` says the check could not be made (a service down, a missing token): Astera asks once more,
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. */
208
+ export interface CompletionCheckResult {
209
+ status: 'passed' | 'failed' | 'error' | 'pending' | 'unknown';
210
+ summary?: string;
211
+ diagnostics?: CompletionCheckDiagnostic[];
212
+ /** How many findings there are, when you send fewer: send the first 20 and the count, not thousands to be cut. */
213
+ diagnosticsTotal?: number;
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;
229
+ }
230
+ /** A plugin of the `completion-check` capability (`astera.capabilities: ["completion-check"]`, with no permission):
231
+ * Astera asks it when a Task whose checks name `plugin:<its id>` is done, in the order the Task lists its checks. A
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. */
235
+ export interface CompletionCheckProvider extends PluginDefinition {
236
+ runCheck: (input: CompletionCheckInput, ctx: PluginContext) => CompletionCheckResult | Promise<CompletionCheckResult>;
237
+ }
238
+ /** The provider an entry file exports as its default. */
239
+ export declare function defineCompletionCheckProvider<T extends CompletionCheckProvider>(provider: T): T;
package/dist/cjs/index.js CHANGED
@@ -1,10 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PLUGIN_API_VERSION = void 0;
3
+ exports.NOTIFICATION_KINDS = exports.PLUGIN_API_VERSION = void 0;
4
4
  exports.definePlugin = definePlugin;
5
- /** The Plugin API this package is written for: the manifest's `astera.apiVersion` (spec §28). */
6
- exports.PLUGIN_API_VERSION = '1';
5
+ exports.defineNotificationProvider = defineNotificationProvider;
6
+ exports.defineJobSourceProvider = defineJobSourceProvider;
7
+ exports.defineCompletionCheckProvider = defineCompletionCheckProvider;
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';
7
12
  /** The plugin an entry file exports as its default. */
8
13
  function definePlugin(definition) {
9
14
  return definition;
10
15
  }
16
+ /** The kinds of notification Astera sends a `notification` plugin, most pressing first. A provider offers a setting
17
+ * for the ones it leaves out; Astera sends all of them. Astera's own copy of this list is checked against this one. */
18
+ exports.NOTIFICATION_KINDS = [
19
+ 'question.created',
20
+ 'session.input_needed',
21
+ 'run.failed',
22
+ 'completion.exhausted',
23
+ 'session.limit_waiting',
24
+ 'run.completed',
25
+ 'session.account_switched'
26
+ ];
27
+ /** The provider an entry file exports as its default. */
28
+ function defineNotificationProvider(provider) {
29
+ return provider;
30
+ }
31
+ /** The provider an entry file exports as its default. */
32
+ function defineJobSourceProvider(provider) {
33
+ return provider;
34
+ }
35
+ /** The provider an entry file exports as its default. */
36
+ function defineCompletionCheckProvider(provider) {
37
+ return provider;
38
+ }
@@ -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
+ ];
@@ -1,6 +1,8 @@
1
- import type { AsteraClient } from '@astera-app/client';
2
- /** The Plugin API this package is written for: the manifest's `astera.apiVersion` (spec §28). */
3
- export declare const PLUGIN_API_VERSION = "1";
1
+ import type { AsteraClient, AsteraEvent, EventGap } from '@astera-app/client';
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,7 +33,16 @@ 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;
34
- /** Aborted when Astera stops the plugin: disabled, removed, updated, or the Host leaving. */
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
+ };
43
+ /** Aborted when Astera stops the plugin: disabled, removed, updated, or the Host leaving. In a handler (`onEvent`,
44
+ * `send`, `listItems`, `getItem`, `buildJobContext`, `runCheck`) it is that call's: it also aborts when Astera stops
45
+ * waiting for the call (30 seconds for an event or a notification, 15 for a job source, 30 minutes for a check). */
35
46
  signal: AbortSignal;
36
47
  }
37
48
  export interface PluginDefinition {
@@ -39,6 +50,190 @@ export interface PluginDefinition {
39
50
  activate?(ctx: PluginContext): void | Promise<void>;
40
51
  /** Called before the plugin is stopped, with a few seconds to finish. */
41
52
  deactivate?(): void | Promise<void>;
53
+ /** The `event` capability (`astera.capabilities: ["event"]`, with the `events.subscribe` permission): each of
54
+ * Astera's events, in order, one at a time, from where this plugin left off, once `activate` has resolved. A
55
+ * `{ type: 'gap' }` first means events were lost before the next one. Throw or reject to have the same event handed
56
+ * over again (after 1 s, doubling to 5 min, for an hour). It must settle within 30 s: past that the call's
57
+ * `ctx.signal` aborts, and a handler that does not stop runs beside the event's next try. An event can come twice: `event.id` never repeats, so drop one
58
+ * you have seen. A property rather than a method, so a handler that takes only `AsteraEvent` does not typecheck:
59
+ * it would throw on a gap. */
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>;
42
66
  }
43
67
  /** The plugin an entry file exports as its default. */
44
68
  export declare function definePlugin<T extends PluginDefinition>(definition: T): T;
69
+ /** The kinds of notification Astera sends a `notification` plugin, most pressing first. A provider offers a setting
70
+ * for the ones it leaves out; Astera sends all of them. Astera's own copy of this list is checked against this one. */
71
+ export declare const NOTIFICATION_KINDS: readonly ['question.created', 'session.input_needed', 'run.failed', 'completion.exhausted', 'session.limit_waiting', 'run.completed', 'session.account_switched'];
72
+ export type NotificationKind = (typeof NOTIFICATION_KINDS)[number];
73
+ /** How much it matters: `action` waits on the person, `error` failed, `warning` stopped for now, `info` went on. */
74
+ export type NotificationLevel = 'action' | 'error' | 'warning' | 'info';
75
+ /** Something worth telling a person, already worded by Astera in the language the app is set to: post `title` and
76
+ * `body` as they are. */
77
+ export interface AsteraNotification {
78
+ /** The event's id: a notification can come twice, so drop one you have seen. */
79
+ readonly id: string;
80
+ /** The event's type. A later Astera may send a kind this list does not name yet: post it by its title and body. */
81
+ readonly kind: NotificationKind | (string & {});
82
+ /** How much it matters. A later Astera may add a level: post it as the nearest one you know. */
83
+ readonly level: NotificationLevel | (string & {});
84
+ /** What it is about: a Job's objective, or a session's title. */
85
+ readonly title: string;
86
+ /** One sentence. */
87
+ readonly body: string;
88
+ readonly occurredAt: string;
89
+ /** The whole event, for its ids and detail. */
90
+ readonly event: AsteraEvent;
91
+ }
92
+ /** A plugin of the `notification` capability (`astera.capabilities: ["notification"]`, with the `events.subscribe`
93
+ * permission). */
94
+ export interface NotificationProvider extends PluginDefinition {
95
+ /** Each notification, in order, one at a time, once `activate` has resolved. Throw or reject to have it sent again
96
+ * (after 1 s, doubling to 5 min, for an hour); it must settle within 30 s. A notification older than an hour when
97
+ * its turn comes is not sent. */
98
+ send: (notification: AsteraNotification, ctx: PluginContext) => void | Promise<void>;
99
+ }
100
+ /** The provider an entry file exports as its default. */
101
+ export declare function defineNotificationProvider<T extends NotificationProvider>(provider: T): T;
102
+ /** What `listItems` is asked: the person's search, and the cursor of the page before when there is one. */
103
+ export interface JobSourceQuery {
104
+ query?: string;
105
+ cursor?: string;
106
+ }
107
+ /** One item of a job source: a ticket, an issue. Astera refuses an item whose `id` is not 1 to 200 characters with no
108
+ * control characters (it is your own, opaque id, `ENG-123` say), cuts `title` at 300 characters, `status` at 100 and
109
+ * `summary` at 1,000, and keeps `url` only when it is http or https. */
110
+ export interface JobSourceItem {
111
+ id: string;
112
+ title: string;
113
+ status?: string;
114
+ url?: string;
115
+ summary?: string;
116
+ }
117
+ /** A page of items: at most 100 are kept, and `nextCursor` (at most 2,000 characters) is handed back to `listItems`
118
+ * for the next page. No `nextCursor` means this is the last page. */
119
+ export interface JobSourcePage {
120
+ items: JobSourceItem[];
121
+ nextCursor?: string;
122
+ }
123
+ /** One item read whole: `body` cut at 20,000 characters, and at most 50 `fields` of short text (100 characters a name,
124
+ * 1,000 a value), shown beside it. */
125
+ export interface JobSourceItemDetail extends JobSourceItem {
126
+ body?: string;
127
+ fields?: Record<string, string>;
128
+ }
129
+ /** What a Job made from an item is to do. Astera writes the Job's objective itself: a first line naming
130
+ * `sourceLabel` (`Linear ENG-123`, at most 200 characters) and `sourceUrl`, then your `objective` (at most 20,000), each
131
+ * `evidence` entry under its label (at most 20 entries, 20,000 characters each and 100,000 in all) and the `metadata`
132
+ * (at most 50 pairs), quoted as data the Job's agent does not take orders from. The Job keeps the item as its source,
133
+ * and is named, in the app, the CLI and notifications, by the first line of your `objective` (at most 300 characters):
134
+ * start it with the item's title. */
135
+ export interface JobSourceContext {
136
+ objective: string;
137
+ sourceLabel: string;
138
+ sourceUrl?: string;
139
+ evidence?: Array<{
140
+ label: string;
141
+ content: string;
142
+ }>;
143
+ metadata?: Record<string, string>;
144
+ }
145
+ /** A plugin of the `job-source` capability (`astera.capabilities: ["job-source"]`, with no permission): Astera asks it
146
+ * for items when a person, the `astera sources` commands or an MCP client looks for a ticket to make a Job from. Each
147
+ * call has 15 seconds. Throw or reject to say why there is no answer ("401 Unauthorized"): the person reads that
148
+ * sentence, and Astera tries nothing again. A plugin missing any of the three does not start. */
149
+ export interface JobSourceProvider extends PluginDefinition {
150
+ /** A page of items, searched with `input.query`, from `input.cursor` on. */
151
+ listItems: (input: JobSourceQuery, ctx: PluginContext) => JobSourcePage | Promise<JobSourcePage>;
152
+ /** One item read whole, by the id `listItems` gave it. Throw for an id you do not know. */
153
+ getItem: (id: string, ctx: PluginContext) => JobSourceItemDetail | Promise<JobSourceItemDetail>;
154
+ /** What a Job made from the item is to do, by the id `listItems` gave it. */
155
+ buildJobContext: (id: string, ctx: PluginContext) => JobSourceContext | Promise<JobSourceContext>;
156
+ }
157
+ /** The provider an entry file exports as its default. */
158
+ export declare function defineJobSourceProvider<T extends JobSourceProvider>(provider: T): T;
159
+ /** What a completion check is asked about: the Task and the folder its checks run in. `root` is the Task's worktree, or
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. */
166
+ export interface CompletionCheckInput {
167
+ projectId?: string;
168
+ jobId: string;
169
+ runId: string;
170
+ taskId: string;
171
+ task: {
172
+ title: string;
173
+ };
174
+ workspace: {
175
+ root: string;
176
+ base?: string;
177
+ head?: string;
178
+ branch?: string;
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
+ };
188
+ }
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
190
+ * positive integer and a `severity` that is one of the two, and drops what is not. */
191
+ export interface CompletionCheckDiagnostic {
192
+ file?: string;
193
+ line?: number;
194
+ message: string;
195
+ severity?: 'error' | 'warning';
196
+ }
197
+ /** A check's answer. `passed` lets the Task's next check run. `failed` is the code's fault: the Task's repair request
198
+ * carries your summary, your first 20 findings as `file:line message` and your link, and the Task fails where its Job
199
+ * repairs nothing. `error` says the check could not be made (a service down, a missing token): Astera asks once more,
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. */
208
+ export interface CompletionCheckResult {
209
+ status: 'passed' | 'failed' | 'error' | 'pending' | 'unknown';
210
+ summary?: string;
211
+ diagnostics?: CompletionCheckDiagnostic[];
212
+ /** How many findings there are, when you send fewer: send the first 20 and the count, not thousands to be cut. */
213
+ diagnosticsTotal?: number;
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;
229
+ }
230
+ /** A plugin of the `completion-check` capability (`astera.capabilities: ["completion-check"]`, with no permission):
231
+ * Astera asks it when a Task whose checks name `plugin:<its id>` is done, in the order the Task lists its checks. A
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. */
235
+ export interface CompletionCheckProvider extends PluginDefinition {
236
+ runCheck: (input: CompletionCheckInput, ctx: PluginContext) => CompletionCheckResult | Promise<CompletionCheckResult>;
237
+ }
238
+ /** The provider an entry file exports as its default. */
239
+ export declare function defineCompletionCheckProvider<T extends CompletionCheckProvider>(provider: T): T;
package/dist/esm/index.js CHANGED
@@ -1,6 +1,31 @@
1
- /** The Plugin API this package is written for: the manifest's `astera.apiVersion` (spec §28). */
2
- export const PLUGIN_API_VERSION = '1';
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;
6
8
  }
9
+ /** The kinds of notification Astera sends a `notification` plugin, most pressing first. A provider offers a setting
10
+ * for the ones it leaves out; Astera sends all of them. Astera's own copy of this list is checked against this one. */
11
+ export const NOTIFICATION_KINDS = [
12
+ 'question.created',
13
+ 'session.input_needed',
14
+ 'run.failed',
15
+ 'completion.exhausted',
16
+ 'session.limit_waiting',
17
+ 'run.completed',
18
+ 'session.account_switched'
19
+ ];
20
+ /** The provider an entry file exports as its default. */
21
+ export function defineNotificationProvider(provider) {
22
+ return provider;
23
+ }
24
+ /** The provider an entry file exports as its default. */
25
+ export function defineJobSourceProvider(provider) {
26
+ return provider;
27
+ }
28
+ /** The provider an entry file exports as its default. */
29
+ export function defineCompletionCheckProvider(provider) {
30
+ return provider;
31
+ }
@@ -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.1.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": [
@@ -43,7 +53,7 @@
43
53
  "prepublishOnly": "node ../../scripts/build-packages.mjs"
44
54
  },
45
55
  "peerDependencies": {
46
- "@astera-app/client": ">=0.1.0"
56
+ "@astera-app/client": ">=0.2.0 <1"
47
57
  },
48
58
  "publishConfig": {
49
59
  "access": "public"