@ampcode/plugin 0.0.0-20261109001254-g196b1f0 → 0.0.0-20261110001141-ga81a67d

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/package.json +3 -7
  2. package/omni.d.ts +0 -759
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampcode/plugin",
3
- "version": "0.0.0-20261109001254-g196b1f0",
3
+ "version": "0.0.0-20261110001141-ga81a67d",
4
4
  "description": "Amp Plugin API",
5
5
  "license": "Amp Commercial License",
6
6
  "homepage": "https://ampcode.com/docs/plugin-api",
@@ -18,14 +18,10 @@
18
18
  "exports": {
19
19
  ".": {
20
20
  "types": "./index.d.ts"
21
- },
22
- "./omni": {
23
- "types": "./omni.d.ts"
24
21
  }
25
22
  },
26
23
  "files": [
27
24
  "index.d.ts",
28
- "omni.d.ts",
29
25
  "README.md"
30
26
  ],
31
27
  "publishConfig": {
@@ -34,9 +30,9 @@
34
30
  "sideEffects": false,
35
31
  "scripts": {
36
32
  "build": "tsgo -b",
37
- "format:check": "bun fmt --check index.d.ts omni.d.ts",
33
+ "format:check": "bun fmt --check .",
38
34
  "test": "echo 'No tests'",
39
- "lint": "biome check --config-path=../.. index.d.ts omni.d.ts",
35
+ "lint": "biome check --config-path=../.. .",
40
36
  "typecheck": "tsgo -b"
41
37
  },
42
38
  "devDependencies": {
package/omni.d.ts DELETED
@@ -1,759 +0,0 @@
1
- declare module '@ampcode/plugin/omni' {
2
- import type {
3
- AgentEndEvent,
4
- AgentEndResult,
5
- AgentStartEvent,
6
- AgentStartResult,
7
- AppendUserMessageOptions,
8
- CustomAgentDefinition,
9
- defineAgent as defineAgentHelper,
10
- Observable,
11
- PluginAgentModeDefinition,
12
- PluginLogger,
13
- QuickActionArgs,
14
- QuickActionIcon,
15
- SessionStartEvent,
16
- Subscription,
17
- ThreadMessage,
18
- UserMessage,
19
- WebhookEvent,
20
- WebhookRegistration,
21
- } from '@ampcode/plugin'
22
-
23
- /**
24
- * # Amp Omni Plugin API
25
- *
26
- * An omni plugin runs on a user or workspace actor rather than on an executor, so
27
- * user and workspace plugins work before any thread exists. It is a plugin file
28
- * that starts with a `// @amp-omni-plugin` comment and exports a default function that
29
- * receives an {@link OmniPluginAPI}. Plugin hosts on executors skip these files; the Amp
30
- * service runs them instead.
31
- *
32
- * ```ts
33
- * // @amp-omni-plugin
34
- * import type { OmniPluginAPI } from '@ampcode/plugin/omni'
35
- *
36
- * export default function (amp: OmniPluginAPI) {
37
- * amp.registerCommand('acme.ship', {
38
- * title: 'Ship',
39
- * group: 'Git',
40
- * action: 'send-message',
41
- * args: { message: 'Ship this thread: commit, push, and report CI.' },
42
- * })
43
- * amp.ui.quickActions.addButton('acme.ship', { when: { working: false, hasChanges: true } })
44
- * }
45
- * ```
46
- *
47
- * Omni plugins are ordinary TypeScript or JavaScript ES modules, run in a sandboxed
48
- * JavaScript engine with no access to the network, the file system, or any executor:
49
- *
50
- * - Type annotations, `type`/`interface` declarations, `as`, and `import type` are erased;
51
- * TypeScript-only syntax that generates code (`enum`, `namespace`, parameter properties)
52
- * is rejected.
53
- * - Value imports are limited to `defineAgent` from `@ampcode/plugin`,
54
- * `@ampcode/plugin/omni`, and `@ampcode/sdk-next`.
55
- * Other dependencies must be included in the self-contained plugin file.
56
- * - Each synchronous slice of plugin execution has a short time limit and the plugin has a
57
- * fixed memory limit. A call that exceeds either fails and is logged; it does not block
58
- * Amp.
59
- *
60
- * This API is in development. Every member of `amp` not declared here throws when used, so a
61
- * plugin written against the executor `PluginAPI` fails fast rather than silently doing
62
- * nothing.
63
- */
64
-
65
- /**
66
- * The API object passed to an omni plugin's default export function.
67
- */
68
- export interface OmniPluginAPI {
69
- /** Logger scoped to this plugin. */
70
- logger: PluginLogger
71
-
72
- /** Owning actor, supplied by the host after authorization. Guest code cannot change it. */
73
- readonly actor: OmniPluginActor
74
-
75
- /** Declare an agent directory's config without resolving or invoking it. */
76
- defineAgent: typeof defineAgentHelper
77
-
78
- /** Registers a selectable mode using an agent definition. */
79
- registerAgentMode(
80
- definition: Omit<PluginAgentModeDefinition, 'agent'> & {
81
- agent: CustomAgentDefinition
82
- },
83
- ): Subscription
84
-
85
- /**
86
- * Registers a durable webhook on the Puck or Space thread that hosts this automation.
87
- * The private URL authenticates incoming POST requests; return it only to the authorized
88
- * registrant. Registration is explicit, not automatic on push. The host reloads this
89
- * plugin in a fresh sandbox for each delivery, so initialize handlers in the default
90
- * export and do not rely on captured state surviving between events. Registration keys
91
- * are scoped to the installation, host thread, and plugin name. Re-registering updates
92
- * future events without resuming a paused registration. Queued events retain their
93
- * admitted plugin source. Not available to interactive (user actor) plugin runs.
94
- *
95
- * Delivery is at least once. Use the event ID to deduplicate effects. Event bodies and
96
- * headers are untrusted input. This handler has no executor APIs, network, or filesystem.
97
- * Existing executor-hosted `PluginAPI.createWebhook` handlers are unchanged.
98
- * In an admitted Git-backed delivery, use `new Amp().threads.create(...)` from
99
- * `@ampcode/sdk-next` with `agentMode: 'agent:<key>'` to run a saved Git agent.
100
- * Resolution uses the caller's personal repository before the authorized workspace's,
101
- * with the same validation and feature checks as ordinary thread creation. The created
102
- * thread pins the definition and execution mode; retries reuse them instead of Git HEAD.
103
- * Pass `result: { callbackKey }` to that call and the thread may report one structured
104
- * result with its result tool; the host then delivers it to the handler registered under
105
- * `callbackKey` as a fresh event whose body is the JSON `{ kind: 'thread-result',
106
- * threadID, parentEventID, status, result?, error? }`, after this handler has exited.
107
- * A thread going idle is not a result; a missed deadline arrives as `deadline_exceeded`.
108
- * Await host operations. Each run allows 64 calls, 1 MiB of request data and at most four
109
- * concurrent calls; exceeding a limit fails the delivery rather than queueing more work.
110
- * Guest execution runs in isolated workers, with at most two active per runner and a
111
- * 30-second hard deadline. These limits also apply to interactive omni plugins, not to
112
- * executor-hosted plugins.
113
- */
114
- createWebhook(options: {
115
- key: string
116
- headers?: readonly string[]
117
- handler: (event: WebhookEvent, ctx: OmniPluginHandlerContext) => void | Promise<void>
118
- }): Promise<WebhookRegistration>
119
-
120
- /**
121
- * Provider events on the Puck or Space thread that hosts this automation. See
122
- * {@link OmniPluginEvents.subscribe}. Not available to interactive (user actor) runs.
123
- */
124
- events: OmniPluginEvents
125
-
126
- /** The host thread's tools, available to webhook and event handlers as `ctx.tools`. */
127
- tools: OmniPluginTools
128
-
129
- /**
130
- * The user's connected Amp clients ({@link OmniPluginClient}) and the windows each has
131
- * open. Subscribing emits the current list at once. The list is empty until a client
132
- * connects. User actors capture this read-only snapshot at execution time, not event
133
- * admission. Workspace client visibility is unsupported and always returns an empty list;
134
- * it does not expose the registering user's clients or aggregate member clients.
135
- *
136
- * There is no single "active thread": the user may have several windows open on several
137
- * devices, and each {@link OmniPluginWindow} has its own `activeThread`.
138
- *
139
- * @example
140
- * ```ts
141
- * const windowShowing = (threadID: string) =>
142
- * amp.clients.current
143
- * .flatMap((client) => client.windows)
144
- * .find((window) => window.visible && window.activeThread?.id === threadID)
145
- * ```
146
- */
147
- clients: Pick<Observable<OmniPluginClient[]>, 'subscribe'> & {
148
- readonly current: OmniPluginClient[]
149
- }
150
-
151
- /**
152
- * Adds a command to the command palette of every client the user is signed in to, on
153
- * every page, not only inside a thread. Users can bind a keyboard shortcut to it in
154
- * their keymap settings. To also show a button for it in a thread, place it with
155
- * {@link OmniPluginAPI.ui} after registering it.
156
- *
157
- * What picking the command does is its `action`. A declarative action (`'open-url'`,
158
- * `'send-message'`, `'copy'`, `'open-pane'`, `'open-portal'`) is performed by the client
159
- * itself, at once, with no round trip to the plugin: a link button is a real link that
160
- * ⌘-click opens in a new tab, and a right-click on a message button lists Send and Edit
161
- * Before Sending. With `action: 'call'`, picking the command calls `call` on the actor:
162
- * the actor runs this plugin's default export again in a fresh sandbox and then calls
163
- * `call`, as it does for webhook deliveries, so initialize in the default export and do
164
- * not rely on state captured between runs. The window the user picked it in is
165
- * `ctx.window`.
166
- *
167
- * A plugin may register at most 50 commands, and registering an ID that is still
168
- * registered throws.
169
- *
170
- * @param id - The command's ID, `namespace.name` as in VS Code: two or more
171
- * dot-separated segments of letters, digits, and hyphens, such as `'acme.ship'` or
172
- * `'acme.review.changes'`. The namespace is a name the plugin picks for itself, so its
173
- * commands read as a family in keymaps and logs; it need not match the plugin file or
174
- * workspace name. IDs are unique within this plugin.
175
- *
176
- * @example
177
- * ```ts
178
- * amp.registerCommand('acme.standup', {
179
- * title: 'Draft Standup',
180
- * group: 'Team',
181
- * action: 'call',
182
- * call: async (ctx) => {
183
- * if (!ctx.window) return
184
- * await ctx.window.insertPromptText('Draft my standup update from yesterday’s threads.')
185
- * await ctx.ui.notify('Standup prompt inserted')
186
- * },
187
- * })
188
- * amp.registerCommand('acme.dashboard', {
189
- * title: 'Open Dashboard',
190
- * icon: 'activity',
191
- * action: 'open-url',
192
- * args: { url: 'https://example.com/dashboard' },
193
- * })
194
- * amp.ui.threadMenu.addItem('acme.dashboard')
195
- * amp.ui.threadTitleBar.addButton('acme.dashboard', { title: 'Dashboard' })
196
- * ```
197
- */
198
- registerCommand(id: string, options: OmniPluginCommandOptions): OmniPluginSubscription
199
-
200
- /**
201
- * Subscribes a handler to an agent hook on every thread the user owns. The hook names,
202
- * event payloads, and handler results are the executor plugin API's (`amp.on()` in
203
- * `@ampcode/plugin`), so a handler written for an executor plugin runs unchanged here:
204
- * `session.start` once per thread, `agent.start` when a user message starts a turn, and
205
- * `agent.end` when the turn settles. An `agent.start` handler may return
206
- * `{ message }` to add context to the turn, and an `agent.end` handler may return
207
- * `{ action: 'continue', userMessage }` to start another turn.
208
- *
209
- * The thread runs these hooks itself, right after it ran the same hook of the executor
210
- * plugins, whether or not it has an executor. Each hook runs this plugin's default export
211
- * again in a fresh sandbox and then calls the handler, as commands do, so initialize in
212
- * the default export. Handlers get {@link OmniPluginEventContext}: the thread's
213
- * transcript and `ctx.ui` dialogs that show on the thread, in every window that has it
214
- * open, rather than in one window. Several subscribed plugins run one after the other;
215
- * the first `agent.end` handler that asks to continue wins, after the executor's. A
216
- * handler that throws is logged and does not affect the turn.
217
- *
218
- * @example
219
- * ```ts
220
- * amp.on('agent.end', async (event, ctx) => {
221
- * if (event.status !== 'error') return
222
- * const retry = await ctx.ui.confirm({ title: 'The turn failed. Retry it?' })
223
- * if (retry) return { action: 'continue', userMessage: 'Try again' }
224
- * })
225
- * ```
226
- */
227
- on<E extends keyof OmniPluginThreadEventMap>(
228
- event: E,
229
- handler: (
230
- event: OmniPluginThreadEventMap[E],
231
- ctx: OmniPluginEventContext,
232
- ) => OmniPluginThreadEventResultMap[E] | Promise<OmniPluginThreadEventResultMap[E]>,
233
- ): OmniPluginSubscription
234
-
235
- /**
236
- * Where a registered command can show a button besides the command palette. Each
237
- * surface has its own call, with the options that surface understands; a command may be
238
- * placed once on each. Every button shows the command's `icon` and, unless the
239
- * placement gives its own, its `title`; hovering names the plugin and shows
240
- * `description`. A button runs the command with its thread as `ctx.thread`: the thread
241
- * whose title bar, menu, or composer it is in, which need not be the page's.
242
- *
243
- * Place a command after registering it; placing an unregistered command throws, and
244
- * unregistering a command removes its placements. Each call returns a subscription that
245
- * removes only that placement.
246
- */
247
- ui: OmniPluginUI
248
- }
249
-
250
- /** The surfaces {@link OmniPluginAPI.ui} places commands on. */
251
- export interface OmniPluginUI {
252
- /** A button at the end of the thread's title bar, after Amp's own controls. */
253
- threadTitleBar: {
254
- addButton(command: string, options?: OmniPluginTitleBarButtonOptions): OmniPluginSubscription
255
- }
256
- /**
257
- * A row in every menu that acts on a thread: the title bar's `⋯` menu and the sidebar
258
- * row's right-click or long-press menu. One placement fills them all; a sidebar row's
259
- * item acts on that row's thread.
260
- */
261
- threadMenu: {
262
- addItem(command: string, options?: OmniPluginThreadMenuItemOptions): OmniPluginSubscription
263
- }
264
- /**
265
- * A capsule in the quick action row above the composer, after the executor plugins'
266
- * quick actions. `when` decides on which threads it shows.
267
- */
268
- quickActions: {
269
- addButton(command: string, options?: OmniPluginQuickActionOptions): OmniPluginSubscription
270
- }
271
- }
272
-
273
- /** Options for {@link OmniPluginUI.threadTitleBar}. */
274
- export interface OmniPluginTitleBarButtonOptions {
275
- /**
276
- * The button's text instead of the command's `title`, such as a shorter `'Dashboard'`
277
- * for `'Open Dashboard'`. The tooltip and the palette keep the command's `title`.
278
- */
279
- title?: string
280
- /** Show only the icon, and keep the title for the tooltip. */
281
- iconOnly?: boolean
282
- }
283
-
284
- /** Options for {@link OmniPluginUI.threadMenu}. */
285
- export interface OmniPluginThreadMenuItemOptions {
286
- /** The row's text instead of the command's `title`. */
287
- title?: string
288
- }
289
-
290
- /** Options for {@link OmniPluginUI.quickActions}. */
291
- export interface OmniPluginQuickActionOptions {
292
- /** The capsule's text instead of the command's `title`. */
293
- title?: string
294
- /**
295
- * What the thread must be for the capsule to show. Each key given must match; an
296
- * omitted key does not restrict. Without `when`, the capsule shows on every thread.
297
- */
298
- when?: OmniPluginQuickActionCriteria
299
- }
300
-
301
- /**
302
- * Facts about a thread a quick action placement can require
303
- * ({@link OmniPluginQuickActionOptions.when}). The web client evaluates them as the thread
304
- * changes, so a capsule appears and disappears with the thread's state.
305
- */
306
- export interface OmniPluginQuickActionCriteria {
307
- /** `true`: only while an agent turn is running; `false`: only while the agent is idle. */
308
- working?: boolean
309
- /**
310
- * `true`: only when the thread's workspace has uncommitted, unlanded, or unpushed
311
- * changes; `false`: only when it has none.
312
- */
313
- hasChanges?: boolean
314
- }
315
-
316
- /**
317
- * Options for {@link OmniPluginAPI.registerCommand}: how the command is listed, and what
318
- * picking it does ({@link OmniPluginCommandAction}).
319
- */
320
- export type OmniPluginCommandOptions = OmniPluginCommandListing & OmniPluginCommandAction
321
-
322
- /** How a command is listed in the palette and shown on the buttons placed for it. */
323
- export interface OmniPluginCommandListing {
324
- /**
325
- * The command's name everywhere it shows: the command palette, each button placed for
326
- * it, and the button's tooltip, such as `'Ship'`. A placement can show a different text
327
- * with its own `title` option.
328
- */
329
- title: string
330
-
331
- /**
332
- * The command palette group the command is listed under, such as `'Git'`. A group that
333
- * no other command uses is created for it, after Amp's own groups. Defaults to the
334
- * plugin name.
335
- */
336
- group?: string
337
-
338
- /** Human-readable description of what this command does */
339
- description?: string
340
-
341
- /**
342
- * The icon the buttons placed for the command show, named as in Lucide. Without one, the
343
- * button shows the action's icon, or for `open-pane`, the pane's icon.
344
- */
345
- icon?: QuickActionIcon
346
- }
347
-
348
- /**
349
- * The declarative actions a command can declare instead of running code. The client
350
- * performs each itself: see `QuickActionArgs` in `@ampcode/plugin` for what each does.
351
- * `send-message` needs a thread: from a placed button it is the button's thread, from the
352
- * palette the thread on screen; the CLI puts the message in the composer instead of sending
353
- * it. `open-pane` and `open-portal` need a thread page in the web or an app. Text is
354
- * limited to 10,000 characters.
355
- */
356
- export type OmniPluginCommandActionName =
357
- | 'send-message'
358
- | 'open-url'
359
- | 'copy'
360
- | 'open-pane'
361
- | 'open-portal'
362
-
363
- /**
364
- * What picking a command does: `call` calls a function on the actor, with
365
- * {@link OmniPluginCommandContext}; the others are declarative, and the client performs
366
- * them itself.
367
- */
368
- export type OmniPluginCommandAction =
369
- | {
370
- action: 'call'
371
- /** Called on the actor each time the user picks the command. */
372
- call: (ctx: OmniPluginCommandContext) => void | Promise<void>
373
- }
374
- | {
375
- [A in OmniPluginCommandActionName]: { action: A; args: QuickActionArgs[A] }
376
- }[OmniPluginCommandActionName]
377
-
378
- /**
379
- * Returned by {@link OmniPluginAPI.registerCommand} and the {@link OmniPluginAPI.ui} calls;
380
- * `unsubscribe()` removes the command or the placement.
381
- */
382
- export interface OmniPluginSubscription {
383
- unsubscribe(): void
384
- }
385
-
386
- /**
387
- * Context passed to an omni plugin command handler. Everything it can do is scoped to the
388
- * window the user ran the command in.
389
- */
390
- export interface OmniPluginCommandContext {
391
- /** Logger scoped to this plugin. */
392
- logger: PluginLogger
393
-
394
- /** UI of the window the user ran the command in. */
395
- ui: OmniPluginCommandUI
396
-
397
- /**
398
- * The window the user ran the command in, or `null` when the client did not report one.
399
- */
400
- window: OmniPluginCommandWindow | null
401
-
402
- /**
403
- * The thread `window` showed when the user picked the command, or `undefined` when it
404
- * showed another page or there is no window. Text the command inserts goes to that
405
- * thread's prompt editor; if the window has moved to another thread, the text is dropped.
406
- */
407
- thread?: OmniPluginCommandThread
408
- }
409
-
410
- /**
411
- * The agent hooks {@link OmniPluginAPI.on} delivers, by name, with the executor plugin
412
- * API's payloads (`PluginEventMap` in `@ampcode/plugin`).
413
- */
414
- export interface OmniPluginThreadEventMap {
415
- /** The thread's first turn is starting; fires once per thread. */
416
- 'session.start': SessionStartEvent
417
- /** A user message started a turn. */
418
- 'agent.start': AgentStartEvent
419
- /** The turn settled: `status` is `done`, `error`, or `cancelled`, with the turn's messages. */
420
- 'agent.end': AgentEndEvent
421
- }
422
-
423
- /**
424
- * What a handler may return for each hook, as the executor plugin API's
425
- * `PluginRequestResultMap`. Return nothing to leave the turn as it is. An `agent.start`
426
- * `message.content` is at most 16,000 characters and an `agent.end` `userMessage` at most
427
- * 16,000 characters; a result outside the shape is logged and dropped.
428
- */
429
- export interface OmniPluginThreadEventResultMap {
430
- 'session.start': void
431
- 'agent.start': AgentStartResult | void
432
- 'agent.end': AgentEndResult
433
- }
434
-
435
- /**
436
- * Context passed to an {@link OmniPluginAPI.on} handler. A hook runs on the thread, not in
437
- * a window, so there is no prompt editor to insert into and no page to show, and the
438
- * dialogs show on the thread.
439
- */
440
- export interface OmniPluginEventContext {
441
- /** Logger scoped to this plugin. */
442
- logger: PluginLogger
443
-
444
- /**
445
- * Dialogs shown on the thread, as an executor plugin's `ctx.ui` dialogs are: every
446
- * window with the thread open shows the question, the first answer settles it, and it
447
- * resolves as dismissed after 5 minutes without one. `notify` reaches every window the
448
- * user has open. `show` is only for commands and throws here.
449
- */
450
- ui: Omit<OmniPluginCommandUI, 'show'>
451
-
452
- /**
453
- * The thread the hook runs on. `messages()` reads the live transcript, including the
454
- * turn in progress, and `appendUserMessage()` is accepted by the thread directly; both
455
- * otherwise work as in {@link OmniPluginCommandThread}.
456
- */
457
- thread: Pick<OmniPluginCommandThread, 'id' | 'messages' | 'appendUserMessage'> & {
458
- /** The thread's title, or `null` when it has none yet. */
459
- title: string | null
460
- }
461
- }
462
-
463
- /** The thread a command ran on, with access to its transcript. */
464
- export interface OmniPluginCommandThread {
465
- id: string
466
-
467
- /**
468
- * Reads a page of this thread's stored messages in the same plugin-facing schema as
469
- * executor plugins' `amp.thread.messages()`. The read goes to the Amp service, so it is
470
- * always asynchronous and needs the user to still be able to view the thread.
471
- *
472
- * Defaults to `{ from: 'end', offset: 0, limit: 10 }`. `limit` is at most 20 and
473
- * `offset` at most 200; a page whose JSON exceeds 256,000 characters rejects instead of
474
- * truncating, so read smaller pages of threads with large tool results. Unlike the
475
- * executor API there is no `full` option: the read always covers the stored transcript,
476
- * and assistant messages never report `stopReason: 'end_turn'`.
477
- *
478
- * Known limitation: the read sees the thread as last synced to the Amp service, not the
479
- * live transcript. While a turn is running, the assistant message being streamed and the
480
- * tool call in progress are absent until that step finishes, and each finished step takes
481
- * up to about 10 more seconds to arrive. Between turns the stored transcript is complete.
482
- *
483
- * ```ts
484
- * const [last] = await ctx.thread.messages({ limit: 1 })
485
- * ```
486
- */
487
- messages(options?: OmniPluginThreadMessagesOptions): Promise<ThreadMessage[]>
488
-
489
- /**
490
- * Appends a user message to this thread, with the same arguments as executor plugins'
491
- * `amp.thread.appendUserMessage()`. The message starts a turn as if the user had sent it
492
- * and the transcript shows it as sent by this plugin. Only the thread's owner can send,
493
- * so this fails on a thread shared with the user. `content` is at most 16,000 characters.
494
- * Resolves once the thread has accepted the message, before the agent answers.
495
- *
496
- * When `steer` is true and the thread is busy, the message is queued as a steering
497
- * message and is preferred when the thread next dequeues work.
498
- *
499
- * A message sent from an `agent.end` handler starts another turn, which ends with another
500
- * `agent.end`; check the thread's last messages before sending so a plugin does not keep a
501
- * thread running on its own.
502
- *
503
- * ```ts
504
- * await ctx.thread.appendUserMessage({ type: 'user-message', content: 'Run the tests' })
505
- * ```
506
- */
507
- appendUserMessage(message: UserMessage, options?: AppendUserMessageOptions): Promise<void>
508
- }
509
-
510
- /** Options for {@link OmniPluginCommandThread.messages}. Unknown keys are rejected. */
511
- export interface OmniPluginThreadMessagesOptions {
512
- /** Which end of the transcript to page from. Defaults to `end`. */
513
- from?: 'start' | 'end'
514
- /** How many messages to skip from `from`, at most 200. Defaults to 0. */
515
- offset?: number
516
- /** How many messages to read, at most 20. Defaults to 10. */
517
- limit?: number
518
- }
519
-
520
- /**
521
- * UI calls available to an omni plugin command. The dialogs show in the window the user ran
522
- * the command in and resolve with the user's answer. The command's 30 s run limit pauses
523
- * while a dialog is open; one run may wait at most 5 minutes in total for answers, after
524
- * which the open dialog resolves as dismissed. Text in options is limited to 4000
525
- * characters and a select to 50 options; unknown option keys fail the call.
526
- *
527
- * ```ts
528
- * const target = await ctx.ui.select({ title: 'Deploy to', options: ['staging', 'prod'] })
529
- * if (target && (await ctx.ui.confirm({ title: `Deploy to ${target}?` }))) {
530
- * await ctx.window.insertPromptText(`Deploy to ${target}`)
531
- * }
532
- * ```
533
- */
534
- export interface OmniPluginCommandUI {
535
- /** Shows a short notification (a toast) in the window the user ran the command in. */
536
- notify(message: string): Promise<void>
537
- /** Asks the user for a line of text; `undefined` when they dismiss the dialog. */
538
- input(options?: OmniPluginInputOptions): Promise<string | undefined>
539
- /** Asks the user a yes-or-no question; `false` when they dismiss the dialog. */
540
- confirm(options: OmniPluginConfirmOptions): Promise<boolean>
541
- /** Asks the user to pick one option; `undefined` when they dismiss the dialog. */
542
- select(options: OmniPluginSelectOptions): Promise<string | undefined>
543
- /**
544
- * Shows Markdown or an embedded HTTPS page in a dialog titled `title`. Resolves
545
- * when the user closes it, with `undefined`, or when the embedded page posts a result
546
- * (see {@link OmniPluginShowOptions.url}), with that result. Clients that cannot embed a
547
- * page, such as the CLI, offer to open the URL in the browser and resolve `undefined`.
548
- *
549
- * @example
550
- * ```ts
551
- * const report = buildReport(await ctx.thread.messages({ limit: 20 }))
552
- * await ctx.ui.show({ title: 'Thread report', markdown: report })
553
- *
554
- * const picked = await ctx.ui.show({ title: 'Pick a ticket', url: 'https://tickets.example/pick' })
555
- * if (typeof picked === 'string') await ctx.window.insertPromptText(`Work on ${picked}`)
556
- * ```
557
- */
558
- show(options: OmniPluginShowOptions): Promise<unknown>
559
- }
560
-
561
- /**
562
- * Options for {@link OmniPluginCommandUI.show}. Give exactly one of `markdown` and `url`.
563
- */
564
- export interface OmniPluginShowOptions {
565
- title: string
566
- /** Markdown body, at most 16,000 characters. */
567
- markdown?: string
568
- /**
569
- * HTTPS page to embed in an iframe, at most 2,048 characters. The page runs with scripts,
570
- * forms, and its own origin's storage. To close the dialog with a result, it posts
571
- * `{ type: 'amp-plugin-dialog-result', value }` to `window.parent`, where `value` is any
572
- * JSON of at most 16,000 characters; a `null` value closes without a result. Only messages
573
- * from the page's own origin count. Pages that forbid framing (`X-Frame-Options`,
574
- * `frame-ancestors`) show blank.
575
- */
576
- url?: string
577
- }
578
-
579
- /** Options for {@link OmniPluginCommandUI.input}; the executor API's options minus thread-bound ones. */
580
- export interface OmniPluginInputOptions {
581
- title?: string
582
- /** Help text shown below the title. */
583
- helpText?: string
584
- /** Initial text in the field. Not allowed with `secret`. */
585
- initialValue?: string
586
- submitButtonText?: string
587
- placeholder?: string
588
- /** Clients mask or hide the text, and it is not logged. */
589
- secret?: boolean
590
- /** Stable field name password managers recognize, such as `OPENAI_API_KEY`. */
591
- fieldName?: string
592
- }
593
-
594
- /** Options for {@link OmniPluginCommandUI.confirm}. */
595
- export interface OmniPluginConfirmOptions {
596
- title: string
597
- /** Markdown shown below the title. */
598
- message?: string
599
- /** Text for the confirm button (default: "Yes"). */
600
- confirmButtonText?: string
601
- }
602
-
603
- /** Options for {@link OmniPluginCommandUI.select}. */
604
- export interface OmniPluginSelectOptions {
605
- title: string
606
- /** Markdown shown below the title. */
607
- message?: string
608
- /** The choices, at most 50. */
609
- options: string[]
610
- initialValue?: string
611
- /** Adds a free-text "Other" field whose trimmed value is returned like a choice. */
612
- allowOther?: boolean
613
- }
614
-
615
- /** The window a command runs in, with what the command can ask of it. */
616
- export interface OmniPluginCommandWindow extends OmniPluginWindow {
617
- /**
618
- * Inserts text at the cursor of the window's prompt editor without sending it. When the
619
- * window shows no prompt editor, the window tells the user and the text is dropped.
620
- */
621
- insertPromptText(text: string): Promise<void>
622
- }
623
-
624
- /** Runtime exports use the same host capabilities as the default function's API argument. */
625
- export const defineAgent: OmniPluginAPI['defineAgent']
626
- export const createWebhook: OmniPluginAPI['createWebhook']
627
- export const registerAgentMode: OmniPluginAPI['registerAgentMode']
628
- export const logger: OmniPluginAPI['logger']
629
- export const actor: OmniPluginAPI['actor']
630
- export const clients: OmniPluginAPI['clients']
631
- export const events: OmniPluginAPI['events']
632
- export const tools: OmniPluginAPI['tools']
633
- export const ui: OmniPluginAPI['ui']
634
-
635
- /** Context a webhook or event handler receives on its Puck or Space host. */
636
- export interface OmniPluginHandlerContext {
637
- actor: OmniPluginActor
638
- logger: PluginLogger
639
- tools: OmniPluginTools
640
- host: OmniPluginHost
641
- }
642
-
643
- /** The Puck or Space thread a handler runs on. */
644
- export interface OmniPluginHost {
645
- /**
646
- * Sends `text` (Markdown) to the host thread as a message from this plugin. The transcript
647
- * shows it as the provider event the handler is running for: `title` when given,
648
- * otherwise the provider and event name, with `url` linking to the event at its provider.
649
- * `icon` replaces the row's mark with one emoji (`'🚨'`) or a named icon: `slack`,
650
- * `linear`, `jira`, `github`, `gitlab`, `activity`, `alert`, `bell`, `bot`, `bug`,
651
- * `calendar`, `chart`, `check`, `clock`, `cloud`, `database`, `error`, `flag`, `flame`,
652
- * `globe`, `info`, `lock`, `mail`, `megaphone`, `message`, `package`, `rocket`, `server`,
653
- * `shield`, `star`, `ticket`, `wrench`, or `zap`.
654
- * By default the host's agent answers it like any other message; `wantsReply: false` only
655
- * records it, without waking the agent. Resolves once the thread accepted the message and
656
- * rejects with its reason when it refused.
657
- */
658
- message(
659
- text: string,
660
- options?: { title?: string; url?: string; icon?: string; wantsReply?: boolean },
661
- ): Promise<void>
662
- }
663
-
664
- export interface OmniPluginEvents {
665
- /**
666
- * Subscribes a handler to events an Amp integration already receives for the plugin's
667
- * user, such as Slack messages in a channel. The host checks the provider's own access
668
- * rules for that user when subscribing (for Slack: the user's Slack connection belongs to
669
- * a connected workspace and both the user and the Amp app are in the channel), and
670
- * stores the subscription under `key` like a webhook registration: scoped to the
671
- * installation, host thread and plugin name, re-registered on every run, and paused and
672
- * resumed with the plugin's other triggers. A key is either a webhook or a subscription.
673
- *
674
- * Delivery is at least once, in a fresh sandbox per event, with the same limits as
675
- * {@link OmniPluginAPI.createWebhook}. Events that arrive while the subscription is
676
- * paused are skipped, not replayed. The provider's own routing is unchanged: a Slack
677
- * message still reaches its listeners and threads as before.
678
- *
679
- * Without a `handler`, each event is sent to the host thread as a message from this
680
- * plugin ({@link OmniPluginHost.message} with the event's `text`), which the host's agent
681
- * answers like any other message. A handler replaces that: it decides what, if anything,
682
- * reaches the host.
683
- *
684
- * Providers and their selectors: `slack` `message` with `{ channel: '<Slack channel ID>' }`
685
- * delivers every message and thread reply in that channel as the Slack message payload
686
- * (`slackTeamID`, `slackChannelID`, `slackSenderID`, `messageTs`, `threadTs?`, `text`).
687
- */
688
- subscribe<P = unknown>(options: {
689
- key: string
690
- provider: string
691
- event: string
692
- selector?: Record<string, unknown>
693
- handler?: (event: OmniPluginEvent<P>, ctx: OmniPluginHandlerContext) => void | Promise<void>
694
- }): Promise<{ key: string }>
695
- }
696
-
697
- /** One provider event delivered to an {@link OmniPluginEvents.subscribe} handler. */
698
- export interface OmniPluginEvent<P = unknown> {
699
- /** The delivery's ID; stable across retries of the same event. */
700
- id: string
701
- provider: string
702
- event: string
703
- /** The provider's key for where the event happened, such as a Slack `team:channel`. */
704
- routeKey: string
705
- /** The provider's event payload, as its ingress built it. */
706
- payload: P
707
- /**
708
- * The provider's own text for the event, written for an agent: what happened, and how to
709
- * act on it with the provider's tools. What a subscription without a handler sends to
710
- * the host.
711
- */
712
- text: string
713
- /** When Amp received the event, as an ISO timestamp. */
714
- receivedAt: string
715
- }
716
-
717
- export interface OmniPluginTools {
718
- /**
719
- * Calls one of the host thread's tools as the thread's user: Amp's server tools such as
720
- * `slack_write` and `slack_read`, and tools on the user's connected MCP servers by
721
- * `<server>.<tool>`. The same enablement rules apply as for the thread's own agent.
722
- * Handlers run with no user present, so a tool that would ask the user for approval or
723
- * input is refused. Rejects with the tool's error message. Not available to interactive
724
- * (user actor) plugin runs.
725
- */
726
- call(name: string, input?: Record<string, unknown>): Promise<unknown>
727
- }
728
-
729
- export type OmniPluginActor =
730
- | { readonly type: 'user'; readonly id: string }
731
- | { readonly type: 'workspace'; readonly id: string }
732
-
733
- /** The kind of Amp client an {@link OmniPluginClient} is. */
734
- export type OmniPluginClientPlatform = 'web' | 'cli' | 'ios' | 'macos' | 'watchos'
735
-
736
- /**
737
- * One Amp client the user is signed in to: a browser profile, a CLI process, or a native app
738
- * installation. A client has one or more {@link OmniPluginWindow}s; a CLI has exactly one.
739
- */
740
- export interface OmniPluginClient {
741
- /** Stable per installation, so the same browser keeps its ID across reloads. */
742
- id: string
743
- platform: OmniPluginClientPlatform
744
- /** The client's open windows, in no particular order. */
745
- windows: OmniPluginWindow[]
746
- }
747
-
748
- /**
749
- * One window (browser tab, CLI terminal, or app window) of an {@link OmniPluginClient}.
750
- * Window IDs are unique across all of the user's clients.
751
- */
752
- export interface OmniPluginWindow {
753
- id: string
754
- /** The thread the window shows, or `null` when it shows another page. */
755
- activeThread: { id: string } | null
756
- /** Whether the user can see the window; hidden tabs and backgrounded apps are not visible. */
757
- visible: boolean
758
- }
759
- }