@ampcode/plugin 0.0.0-20261104001221-gc8c68be → 0.0.0-20261106001255-g161ec3f
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/index.d.ts +0 -7
- package/omni.d.ts +253 -0
- package/package.json +5 -1
package/index.d.ts
CHANGED
|
@@ -199,10 +199,6 @@ declare module '@ampcode/plugin' {
|
|
|
199
199
|
* at 5 minutes. Amp drops an event after 1 hour of handler failures, and later events
|
|
200
200
|
* can run while an earlier event is waiting to retry.
|
|
201
201
|
*
|
|
202
|
-
* For callbacks that do not require an executor, use `createWebhook` in an
|
|
203
|
-
* `@ampcode/plugin/omni` plugin installed on a thread, user, or workspace actor.
|
|
204
|
-
* User and workspace actor registrations do not depend on a thread staying alive.
|
|
205
|
-
*
|
|
206
202
|
* @example
|
|
207
203
|
* ```ts
|
|
208
204
|
* const { url } = await amp.createWebhook({
|
|
@@ -377,9 +373,6 @@ declare module '@ampcode/plugin' {
|
|
|
377
373
|
export interface CreateAgentConfig {
|
|
378
374
|
/**
|
|
379
375
|
* Defaults to the launching user. `user` uses the webhook's saved execution user.
|
|
380
|
-
* Service accounts are supported by workspace-owned omni webhook agents only. The server
|
|
381
|
-
* requires a current workspace admin and an enabled account in that workspace at launch
|
|
382
|
-
* and append. This selects existing account access and credentials, not a new secret grant.
|
|
383
376
|
*/
|
|
384
377
|
owner?: PluginAgentOwner
|
|
385
378
|
/**
|
package/omni.d.ts
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
declare module '@ampcode/plugin/omni' {
|
|
2
|
+
import type {
|
|
3
|
+
CustomAgentDefinition,
|
|
4
|
+
defineAgent as defineAgentHelper,
|
|
5
|
+
Observable,
|
|
6
|
+
PluginAgentModeDefinition,
|
|
7
|
+
PluginLogger,
|
|
8
|
+
Subscription,
|
|
9
|
+
WebhookEvent,
|
|
10
|
+
WebhookRegistration,
|
|
11
|
+
} from '@ampcode/plugin'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* # Amp Omni Plugin API
|
|
15
|
+
*
|
|
16
|
+
* An omni plugin runs on a user or workspace actor rather than on an executor, so
|
|
17
|
+
* user and workspace plugins work before any thread exists. It is a plugin file
|
|
18
|
+
* that starts with a `// @amp-omni-plugin` comment and exports a default function that
|
|
19
|
+
* receives an {@link OmniPluginAPI}. Plugin hosts on executors skip these files; the Amp
|
|
20
|
+
* service runs them instead.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* // @amp-omni-plugin
|
|
24
|
+
* import type { OmniPluginAPI } from '@ampcode/plugin/omni'
|
|
25
|
+
*
|
|
26
|
+
* export default function (amp: OmniPluginAPI) {
|
|
27
|
+
* amp.registerCommand('ship', { title: 'ship', category: 'git' }, async (ctx) => {
|
|
28
|
+
* if (!ctx.window) return
|
|
29
|
+
* await ctx.window.insertPromptText('Ship this thread: commit, push, and report CI.')
|
|
30
|
+
* })
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* Omni plugins are ordinary TypeScript or JavaScript ES modules, run in a sandboxed
|
|
35
|
+
* JavaScript engine with no access to the network, the file system, or any executor:
|
|
36
|
+
*
|
|
37
|
+
* - Type annotations, `type`/`interface` declarations, `as`, and `import type` are erased;
|
|
38
|
+
* TypeScript-only syntax that generates code (`enum`, `namespace`, parameter properties)
|
|
39
|
+
* is rejected.
|
|
40
|
+
* - Value imports are limited to `defineAgent` from `@ampcode/plugin`,
|
|
41
|
+
* `@ampcode/plugin/omni`, and `@ampcode/sdk-next`.
|
|
42
|
+
* Other dependencies must be included in the self-contained plugin file.
|
|
43
|
+
* - Each synchronous slice of plugin execution has a short time limit and the plugin has a
|
|
44
|
+
* fixed memory limit. A call that exceeds either fails and is logged; it does not block
|
|
45
|
+
* Amp.
|
|
46
|
+
*
|
|
47
|
+
* This API is in development. Every member of `amp` not declared here throws when used, so a
|
|
48
|
+
* plugin written against the executor `PluginAPI` fails fast rather than silently doing
|
|
49
|
+
* nothing.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The API object passed to an omni plugin's default export function.
|
|
54
|
+
*/
|
|
55
|
+
export interface OmniPluginAPI {
|
|
56
|
+
/** Logger scoped to this plugin. */
|
|
57
|
+
logger: PluginLogger
|
|
58
|
+
|
|
59
|
+
/** Owning actor, supplied by the host after authorization. Guest code cannot change it. */
|
|
60
|
+
readonly actor: OmniPluginActor
|
|
61
|
+
|
|
62
|
+
/** Declare an agent directory's config without resolving or invoking it. */
|
|
63
|
+
defineAgent: typeof defineAgentHelper
|
|
64
|
+
|
|
65
|
+
/** Registers a selectable mode using an agent definition. */
|
|
66
|
+
registerAgentMode(
|
|
67
|
+
definition: Omit<PluginAgentModeDefinition, 'agent'> & {
|
|
68
|
+
agent: CustomAgentDefinition
|
|
69
|
+
},
|
|
70
|
+
): Subscription
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Registers a durable webhook on the owning user or workspace actor. The private
|
|
74
|
+
* URL authenticates incoming POST requests; return it only to the authorized registrant.
|
|
75
|
+
* Registration is explicit, not automatic on push. The actor reloads this plugin
|
|
76
|
+
* in a fresh sandbox for each delivery, so initialize handlers in the default export and
|
|
77
|
+
* do not rely on captured state surviving between events. Registration keys are scoped
|
|
78
|
+
* to this actor and plugin name. Re-registering updates future events without resuming a
|
|
79
|
+
* paused registration. Queued events retain their admitted plugin source.
|
|
80
|
+
*
|
|
81
|
+
* Delivery is at least once. Use the event ID to deduplicate effects. Event bodies and
|
|
82
|
+
* headers are untrusted input. This handler has no executor APIs, network, or filesystem.
|
|
83
|
+
* Existing executor-hosted `PluginAPI.createWebhook` handlers are unchanged.
|
|
84
|
+
* In an admitted Git-backed delivery, use `new Amp().threads.create(...)` from
|
|
85
|
+
* `@ampcode/sdk-next` with `agentMode: 'agent:<key>'` to run a saved Git agent.
|
|
86
|
+
* Resolution uses the caller's personal repository before the authorized workspace's,
|
|
87
|
+
* with the same validation and feature checks as ordinary thread creation. The created
|
|
88
|
+
* thread pins the definition and execution mode; retries reuse them instead of Git HEAD.
|
|
89
|
+
* Await host operations. Each run allows 64 calls, 1 MiB of request data and at most four
|
|
90
|
+
* concurrent calls; exceeding a limit fails the delivery rather than queueing more work.
|
|
91
|
+
* Guest execution runs in isolated workers, with at most two active per runner and a
|
|
92
|
+
* 30-second hard deadline. These limits also apply to interactive omni plugins, not to
|
|
93
|
+
* executor-hosted plugins.
|
|
94
|
+
*/
|
|
95
|
+
createWebhook(options: {
|
|
96
|
+
key: string
|
|
97
|
+
headers?: readonly string[]
|
|
98
|
+
handler: (
|
|
99
|
+
event: WebhookEvent,
|
|
100
|
+
ctx: {
|
|
101
|
+
actor: OmniPluginActor
|
|
102
|
+
logger: PluginLogger
|
|
103
|
+
},
|
|
104
|
+
) => void | Promise<void>
|
|
105
|
+
}): Promise<WebhookRegistration>
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The user's connected Amp clients ({@link OmniPluginClient}) and the windows each has
|
|
109
|
+
* open. Subscribing emits the current list at once. The list is empty until a client
|
|
110
|
+
* connects. User actors capture this read-only snapshot at execution time, not event
|
|
111
|
+
* admission. Workspace client visibility is unsupported and always returns an empty list;
|
|
112
|
+
* it does not expose the registering user's clients or aggregate member clients.
|
|
113
|
+
*
|
|
114
|
+
* There is no single "active thread": the user may have several windows open on several
|
|
115
|
+
* devices, and each {@link OmniPluginWindow} has its own `activeThread`.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* const windowShowing = (threadID: string) =>
|
|
120
|
+
* amp.clients.current
|
|
121
|
+
* .flatMap((client) => client.windows)
|
|
122
|
+
* .find((window) => window.visible && window.activeThread?.id === threadID)
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
clients: Pick<Observable<OmniPluginClient[]>, 'subscribe'> & {
|
|
126
|
+
readonly current: OmniPluginClient[]
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Adds a command to the command palette of every client the user is signed in to, on
|
|
131
|
+
* every page, not only inside a thread. Users can bind a keyboard shortcut to it in their
|
|
132
|
+
* keymap settings. When the user picks the command, the actor runs this plugin's default
|
|
133
|
+
* export again in a fresh sandbox and then the handler, as it does for webhook
|
|
134
|
+
* deliveries, so initialize in the default export and do not rely on state captured
|
|
135
|
+
* between runs. The window they picked it in is `ctx.window`.
|
|
136
|
+
*
|
|
137
|
+
* The same shape as `PluginAPI.registerCommand`, with the options and context an omni
|
|
138
|
+
* plugin can use. A plugin may register at most 50 commands, and registering an ID that
|
|
139
|
+
* is still registered throws.
|
|
140
|
+
*
|
|
141
|
+
* @param id - Unique within this plugin, such as `'ship'`.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* amp.registerCommand('standup', { title: 'draft standup', category: 'team' }, async (ctx) => {
|
|
146
|
+
* if (!ctx.window) return
|
|
147
|
+
* await ctx.window.insertPromptText('Draft my standup update from yesterday’s threads.')
|
|
148
|
+
* await ctx.ui.notify('Standup prompt inserted')
|
|
149
|
+
* })
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
registerCommand(
|
|
153
|
+
id: string,
|
|
154
|
+
options: OmniPluginCommandOptions,
|
|
155
|
+
handler: (ctx: OmniPluginCommandContext) => void | Promise<void>,
|
|
156
|
+
): OmniPluginCommandSubscription
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Options for {@link OmniPluginAPI.registerCommand}. */
|
|
160
|
+
export interface OmniPluginCommandOptions {
|
|
161
|
+
/** The title shown after the colon in the command palette (e.g., "Greet" in "Hello: Greet") */
|
|
162
|
+
title: string
|
|
163
|
+
|
|
164
|
+
/** The category shown before the colon (e.g., "Hello" in "Hello: Greet"). Defaults to the plugin name. */
|
|
165
|
+
category?: string
|
|
166
|
+
|
|
167
|
+
/** Human-readable description of what this command does */
|
|
168
|
+
description?: string
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Returned by {@link OmniPluginAPI.registerCommand}; `unsubscribe()` removes the command. */
|
|
172
|
+
export interface OmniPluginCommandSubscription {
|
|
173
|
+
unsubscribe(): void
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Context passed to an omni plugin command handler. Everything it can do is scoped to the
|
|
178
|
+
* window the user ran the command in.
|
|
179
|
+
*/
|
|
180
|
+
export interface OmniPluginCommandContext {
|
|
181
|
+
/** Logger scoped to this plugin. */
|
|
182
|
+
logger: PluginLogger
|
|
183
|
+
|
|
184
|
+
/** UI of the window the user ran the command in. */
|
|
185
|
+
ui: OmniPluginCommandUI
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* The window the user ran the command in, or `null` when the client did not report one.
|
|
189
|
+
*/
|
|
190
|
+
window: OmniPluginCommandWindow | null
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* The thread `window` showed when the user picked the command, or `undefined` when it
|
|
194
|
+
* showed another page or there is no window. Text the command inserts goes to that
|
|
195
|
+
* thread's prompt editor; if the window has moved to another thread, the text is dropped.
|
|
196
|
+
*/
|
|
197
|
+
thread?: { id: string }
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** UI calls available to an omni plugin command. */
|
|
201
|
+
export interface OmniPluginCommandUI {
|
|
202
|
+
/** Shows a short notification (a toast) in the window the user ran the command in. */
|
|
203
|
+
notify(message: string): Promise<void>
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** The window a command runs in, with what the command can ask of it. */
|
|
207
|
+
export interface OmniPluginCommandWindow extends OmniPluginWindow {
|
|
208
|
+
/**
|
|
209
|
+
* Inserts text at the cursor of the window's prompt editor without sending it. When the
|
|
210
|
+
* window shows no prompt editor, the window tells the user and the text is dropped.
|
|
211
|
+
*/
|
|
212
|
+
insertPromptText(text: string): Promise<void>
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Runtime exports use the same host capabilities as the default function's API argument. */
|
|
216
|
+
export const defineAgent: OmniPluginAPI['defineAgent']
|
|
217
|
+
export const createWebhook: OmniPluginAPI['createWebhook']
|
|
218
|
+
export const registerAgentMode: OmniPluginAPI['registerAgentMode']
|
|
219
|
+
export const logger: OmniPluginAPI['logger']
|
|
220
|
+
export const actor: OmniPluginAPI['actor']
|
|
221
|
+
export const clients: OmniPluginAPI['clients']
|
|
222
|
+
|
|
223
|
+
export type OmniPluginActor =
|
|
224
|
+
| { readonly type: 'user'; readonly id: string }
|
|
225
|
+
| { readonly type: 'workspace'; readonly id: string }
|
|
226
|
+
|
|
227
|
+
/** The kind of Amp client an {@link OmniPluginClient} is. */
|
|
228
|
+
export type OmniPluginClientPlatform = 'web' | 'cli' | 'ios' | 'macos' | 'watchos'
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* One Amp client the user is signed in to: a browser profile, a CLI process, or a native app
|
|
232
|
+
* installation. A client has one or more {@link OmniPluginWindow}s; a CLI has exactly one.
|
|
233
|
+
*/
|
|
234
|
+
export interface OmniPluginClient {
|
|
235
|
+
/** Stable per installation, so the same browser keeps its ID across reloads. */
|
|
236
|
+
id: string
|
|
237
|
+
platform: OmniPluginClientPlatform
|
|
238
|
+
/** The client's open windows, in no particular order. */
|
|
239
|
+
windows: OmniPluginWindow[]
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* One window (browser tab, CLI terminal, or app window) of an {@link OmniPluginClient}.
|
|
244
|
+
* Window IDs are unique across all of the user's clients.
|
|
245
|
+
*/
|
|
246
|
+
export interface OmniPluginWindow {
|
|
247
|
+
id: string
|
|
248
|
+
/** The thread the window shows, or `null` when it shows another page. */
|
|
249
|
+
activeThread: { id: string } | null
|
|
250
|
+
/** Whether the user can see the window; hidden tabs and backgrounded apps are not visible. */
|
|
251
|
+
visible: boolean
|
|
252
|
+
}
|
|
253
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ampcode/plugin",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-20261106001255-g161ec3f",
|
|
4
4
|
"description": "Amp Plugin API",
|
|
5
5
|
"license": "Amp Commercial License",
|
|
6
6
|
"homepage": "https://ampcode.com/docs/plugin-api",
|
|
@@ -18,10 +18,14 @@
|
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
20
|
"types": "./index.d.ts"
|
|
21
|
+
},
|
|
22
|
+
"./omni": {
|
|
23
|
+
"types": "./omni.d.ts"
|
|
21
24
|
}
|
|
22
25
|
},
|
|
23
26
|
"files": [
|
|
24
27
|
"index.d.ts",
|
|
28
|
+
"omni.d.ts",
|
|
25
29
|
"README.md"
|
|
26
30
|
],
|
|
27
31
|
"publishConfig": {
|