@ampcode/plugin 0.0.0-20261106001255-g161ec3f → 0.0.0-20261107001010-g21afa79

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.
Files changed (2) hide show
  1. package/omni.d.ts +119 -14
  2. package/package.json +1 -1
package/omni.d.ts CHANGED
@@ -70,13 +70,14 @@ declare module '@ampcode/plugin/omni' {
70
70
  ): Subscription
71
71
 
72
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.
73
+ * Registers a durable webhook on the Puck or Space thread that hosts this automation.
74
+ * The private URL authenticates incoming POST requests; return it only to the authorized
75
+ * registrant. Registration is explicit, not automatic on push. The host reloads this
76
+ * plugin in a fresh sandbox for each delivery, so initialize handlers in the default
77
+ * export and do not rely on captured state surviving between events. Registration keys
78
+ * are scoped to the installation, host thread, and plugin name. Re-registering updates
79
+ * future events without resuming a paused registration. Queued events retain their
80
+ * admitted plugin source. Not available to interactive (user actor) plugin runs.
80
81
  *
81
82
  * Delivery is at least once. Use the event ID to deduplicate effects. Event bodies and
82
83
  * headers are untrusted input. This handler has no executor APIs, network, or filesystem.
@@ -86,6 +87,11 @@ declare module '@ampcode/plugin/omni' {
86
87
  * Resolution uses the caller's personal repository before the authorized workspace's,
87
88
  * with the same validation and feature checks as ordinary thread creation. The created
88
89
  * thread pins the definition and execution mode; retries reuse them instead of Git HEAD.
90
+ * Pass `result: { callbackKey }` to that call and the thread may report one structured
91
+ * result with its result tool; the host then delivers it to the handler registered under
92
+ * `callbackKey` as a fresh event whose body is the JSON `{ kind: 'thread-result',
93
+ * threadID, parentEventID, status, result?, error? }`, after this handler has exited.
94
+ * A thread going idle is not a result; a missed deadline arrives as `deadline_exceeded`.
89
95
  * Await host operations. Each run allows 64 calls, 1 MiB of request data and at most four
90
96
  * concurrent calls; exceeding a limit fails the delivery rather than queueing more work.
91
97
  * Guest execution runs in isolated workers, with at most two active per runner and a
@@ -95,15 +101,18 @@ declare module '@ampcode/plugin/omni' {
95
101
  createWebhook(options: {
96
102
  key: string
97
103
  headers?: readonly string[]
98
- handler: (
99
- event: WebhookEvent,
100
- ctx: {
101
- actor: OmniPluginActor
102
- logger: PluginLogger
103
- },
104
- ) => void | Promise<void>
104
+ handler: (event: WebhookEvent, ctx: OmniPluginHandlerContext) => void | Promise<void>
105
105
  }): Promise<WebhookRegistration>
106
106
 
107
+ /**
108
+ * Provider events on the Puck or Space thread that hosts this automation. See
109
+ * {@link OmniPluginEvents.subscribe}. Not available to interactive (user actor) runs.
110
+ */
111
+ events: OmniPluginEvents
112
+
113
+ /** The host thread's tools, available to webhook and event handlers as `ctx.tools`. */
114
+ tools: OmniPluginTools
115
+
107
116
  /**
108
117
  * The user's connected Amp clients ({@link OmniPluginClient}) and the windows each has
109
118
  * open. Subscribing emits the current list at once. The list is empty until a client
@@ -219,6 +228,102 @@ declare module '@ampcode/plugin/omni' {
219
228
  export const logger: OmniPluginAPI['logger']
220
229
  export const actor: OmniPluginAPI['actor']
221
230
  export const clients: OmniPluginAPI['clients']
231
+ export const events: OmniPluginAPI['events']
232
+ export const tools: OmniPluginAPI['tools']
233
+
234
+ /** Context a webhook or event handler receives on its Puck or Space host. */
235
+ export interface OmniPluginHandlerContext {
236
+ actor: OmniPluginActor
237
+ logger: PluginLogger
238
+ tools: OmniPluginTools
239
+ host: OmniPluginHost
240
+ }
241
+
242
+ /** The Puck or Space thread a handler runs on. */
243
+ export interface OmniPluginHost {
244
+ /**
245
+ * Sends `text` (Markdown) to the host thread as a message from this plugin. The transcript
246
+ * shows it as the provider event the handler is running for: `title` when given,
247
+ * otherwise the provider and event name, with `url` linking to the event at its provider.
248
+ * `icon` replaces the row's mark with one emoji (`'🚨'`) or a named icon: `slack`,
249
+ * `linear`, `jira`, `github`, `gitlab`, `activity`, `alert`, `bell`, `bot`, `bug`,
250
+ * `calendar`, `chart`, `check`, `clock`, `cloud`, `database`, `error`, `flag`, `flame`,
251
+ * `globe`, `info`, `lock`, `mail`, `megaphone`, `message`, `package`, `rocket`, `server`,
252
+ * `shield`, `star`, `ticket`, `wrench`, or `zap`.
253
+ * By default the host's agent answers it like any other message; `wantsReply: false` only
254
+ * records it, without waking the agent. Resolves once the thread accepted the message and
255
+ * rejects with its reason when it refused.
256
+ */
257
+ message(
258
+ text: string,
259
+ options?: { title?: string; url?: string; icon?: string; wantsReply?: boolean },
260
+ ): Promise<void>
261
+ }
262
+
263
+ export interface OmniPluginEvents {
264
+ /**
265
+ * Subscribes a handler to events an Amp integration already receives for the plugin's
266
+ * user, such as Slack messages in a channel. The host checks the provider's own access
267
+ * rules for that user when subscribing (for Slack: the user's Slack connection belongs to
268
+ * a connected workspace and both the user and the Amp app are in the channel), and
269
+ * stores the subscription under `key` like a webhook registration: scoped to the
270
+ * installation, host thread and plugin name, re-registered on every run, and paused and
271
+ * resumed with the plugin's other triggers. A key is either a webhook or a subscription.
272
+ *
273
+ * Delivery is at least once, in a fresh sandbox per event, with the same limits as
274
+ * {@link OmniPluginAPI.createWebhook}. Events that arrive while the subscription is
275
+ * paused are skipped, not replayed. The provider's own routing is unchanged: a Slack
276
+ * message still reaches its listeners and threads as before.
277
+ *
278
+ * Without a `handler`, each event is sent to the host thread as a message from this
279
+ * plugin ({@link OmniPluginHost.message} with the event's `text`), which the host's agent
280
+ * answers like any other message. A handler replaces that: it decides what, if anything,
281
+ * reaches the host.
282
+ *
283
+ * Providers and their selectors: `slack` `message` with `{ channel: '<Slack channel ID>' }`
284
+ * delivers every message and thread reply in that channel as the Slack message payload
285
+ * (`slackTeamID`, `slackChannelID`, `slackSenderID`, `messageTs`, `threadTs?`, `text`).
286
+ */
287
+ subscribe<P = unknown>(options: {
288
+ key: string
289
+ provider: string
290
+ event: string
291
+ selector?: Record<string, unknown>
292
+ handler?: (event: OmniPluginEvent<P>, ctx: OmniPluginHandlerContext) => void | Promise<void>
293
+ }): Promise<{ key: string }>
294
+ }
295
+
296
+ /** One provider event delivered to an {@link OmniPluginEvents.subscribe} handler. */
297
+ export interface OmniPluginEvent<P = unknown> {
298
+ /** The delivery's ID; stable across retries of the same event. */
299
+ id: string
300
+ provider: string
301
+ event: string
302
+ /** The provider's key for where the event happened, such as a Slack `team:channel`. */
303
+ routeKey: string
304
+ /** The provider's event payload, as its ingress built it. */
305
+ payload: P
306
+ /**
307
+ * The provider's own text for the event, written for an agent: what happened, and how to
308
+ * act on it with the provider's tools. What a subscription without a handler sends to
309
+ * the host.
310
+ */
311
+ text: string
312
+ /** When Amp received the event, as an ISO timestamp. */
313
+ receivedAt: string
314
+ }
315
+
316
+ export interface OmniPluginTools {
317
+ /**
318
+ * Calls one of the host thread's tools as the thread's user: Amp's server tools such as
319
+ * `slack_write` and `slack_read`, and tools on the user's connected MCP servers by
320
+ * `<server>.<tool>`. The same enablement rules apply as for the thread's own agent.
321
+ * Handlers run with no user present, so a tool that would ask the user for approval or
322
+ * input is refused. Rejects with the tool's error message. Not available to interactive
323
+ * (user actor) plugin runs.
324
+ */
325
+ call(name: string, input?: Record<string, unknown>): Promise<unknown>
326
+ }
222
327
 
223
328
  export type OmniPluginActor =
224
329
  | { readonly type: 'user'; readonly id: string }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampcode/plugin",
3
- "version": "0.0.0-20261106001255-g161ec3f",
3
+ "version": "0.0.0-20261107001010-g21afa79",
4
4
  "description": "Amp Plugin API",
5
5
  "license": "Amp Commercial License",
6
6
  "homepage": "https://ampcode.com/docs/plugin-api",