@ampcode/plugin 0.0.0-20260511003151-g13ad60d → 0.0.0-20260513003404-g32e421b

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 (3) hide show
  1. package/README.md +6 -2
  2. package/index.d.ts +88 -17
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -26,12 +26,16 @@ Amp loads plugins from three locations:
26
26
  import type { PluginAPI } from '@ampcode/plugin'
27
27
 
28
28
  export default function (amp: PluginAPI) {
29
- amp.on('session.start', async (_event, ctx) => {
30
- await ctx.ui.notify('Plugin loaded.')
29
+ amp.logger.log('Plugin initialized')
30
+
31
+ amp.on('session.start', async (event, ctx) => {
32
+ await ctx.ui.notify(`Thread ${event.thread.id} started.`)
31
33
  })
32
34
  }
33
35
  ```
34
36
 
37
+ Code in the exported function runs when the plugin loads. Use `session.start` only for work that should run when Amp starts a specific thread session.
38
+
35
39
  After changing a plugin, open the command palette and run `plugins: reload`.
36
40
 
37
41
  ## Documentation
package/index.d.ts CHANGED
@@ -13,9 +13,7 @@ declare module '@ampcode/plugin' {
13
13
  * import type { PluginAPI } from '@ampcode/plugin'
14
14
  *
15
15
  * export default function (amp: PluginAPI) {
16
- * amp.on('session.start', (event, ctx) => {
17
- * ctx.ui.notify('Welcome')
18
- * })
16
+ * amp.logger.log('Plugin initialized')
19
17
  * }
20
18
  * ```
21
19
  */
@@ -81,7 +79,7 @@ declare module '@ampcode/plugin' {
81
79
  id: string,
82
80
  options: PluginCommandOptions,
83
81
  handler: (ctx: PluginCommandContext) => void | Promise<void>,
84
- ): Subscription
82
+ ): CommandSubscription
85
83
 
86
84
  /**
87
85
  * Register a tool that the agent can call.
@@ -129,6 +127,20 @@ declare module '@ampcode/plugin' {
129
127
  * If no initial value is provided, the item is hidden until its first update.
130
128
  */
131
129
  createStatusItem(initial?: StatusItemValue): StatusItem
130
+
131
+ /**
132
+ * Observable that emits the currently active thread (the one the user is focused on
133
+ * in the UI), or `null` when no thread is active.
134
+ *
135
+ * Use this to determine whether the thread that triggered an event is the one the user
136
+ * is currently looking at, or is running in the background. For example, in a
137
+ * `tool.call` handler, compare `event.thread.id` to
138
+ * `amp.experimental.activeThread.current` to decide whether to surface a UI prompt
139
+ * (active) or take a non-interactive default (background).
140
+ */
141
+ activeThread: Observable<{ id: ThreadID } | null> & {
142
+ readonly current: { id: ThreadID } | null
143
+ }
132
144
  }
133
145
 
134
146
  /**
@@ -143,7 +155,12 @@ declare module '@ampcode/plugin' {
143
155
  /** Text to show. */
144
156
  text: string
145
157
 
146
- /** URL to open when clicked, if any. */
158
+ /**
159
+ * URL to open when clicked, if any.
160
+ *
161
+ * Use a `command:` URI to execute a command registered by a plugin or the
162
+ * command palette. For example, `command:foo` runs the command with ID `foo`.
163
+ */
147
164
  url?: string
148
165
  }
149
166
 
@@ -197,21 +214,33 @@ declare module '@ampcode/plugin' {
197
214
  export type PluginConfigurationTarget = 'workspace' | 'global'
198
215
 
199
216
  /**
200
- * Observable-like interface for Amp configuration.
201
- * Provides a limited subset of Observable functionality for plugins.
217
+ * Minimal Observable interface used by plugin APIs that stream values over time.
218
+ *
219
+ * Subscribers receive subsequent values until they unsubscribe.
202
220
  */
203
- export interface PluginConfiguration<T> {
221
+ export interface Observable<T> {
204
222
  /**
205
- * Subscribe to configuration changes.
223
+ * Subscribe to values emitted by this observable.
206
224
  */
207
225
  subscribe(observer: PluginConfigurationObserver<T>): Subscription
208
226
  subscribe(onNext: (value: T) => void): Subscription
209
227
 
210
228
  /**
211
- * Pipe operators for transforming the configuration observable.
229
+ * Pipe operators for transforming this observable.
230
+ */
231
+ pipe<Out>(op: (input: Observable<T>) => Out): Out
232
+
233
+ /**
234
+ * Return this observable for interop with observable libraries.
212
235
  */
213
- pipe<Out>(op: (input: PluginConfiguration<T>) => Out): Out
236
+ [Symbol.observable](): Observable<T>
237
+ }
214
238
 
239
+ /**
240
+ * Observable-like interface for Amp configuration.
241
+ * Provides a limited subset of Observable functionality for plugins.
242
+ */
243
+ export interface PluginConfiguration<T> extends Observable<T> {
215
244
  /**
216
245
  * Get the current configuration value.
217
246
  */
@@ -441,6 +470,9 @@ declare module '@ampcode/plugin' {
441
470
  /** Message body shown below the title */
442
471
  message?: string
443
472
 
473
+ /** Initially selected option value */
474
+ initialValue?: string
475
+
444
476
  /** Entries to display as choices */
445
477
  options: string[]
446
478
  }
@@ -482,11 +514,12 @@ declare module '@ampcode/plugin' {
482
514
 
483
515
  /**
484
516
  * Event payload for session.start event.
485
- * Fired when the plugin session starts and before the first event for each thread.
517
+ * Fired when Amp starts a thread session, such as when the user sends the first
518
+ * message in a new thread or opens/switches to an existing thread.
486
519
  */
487
520
  export interface SessionStartEvent {
488
- /** The active thread for this session, when available */
489
- thread?: { id: ThreadID }
521
+ /** The thread that started running */
522
+ thread: { id: ThreadID }
490
523
  }
491
524
 
492
525
  /**
@@ -711,10 +744,11 @@ declare module '@ampcode/plugin' {
711
744
 
712
745
  /**
713
746
  * Context passed as the second argument to event handlers.
714
- * `session.start` may be emitted before a thread exists, while all other events are thread-scoped.
747
+ * All plugin events are thread-scoped.
715
748
  */
716
- export type PluginEventContext<E extends keyof PluginEventMap> = PluginEventContextBase &
717
- (E extends 'session.start' ? { thread?: PluginThread } : { thread: PluginThread })
749
+ export type PluginEventContext<E extends keyof PluginEventMap> = PluginEventContextBase & {
750
+ thread: PluginThread
751
+ }
718
752
 
719
753
  /**
720
754
  * Handler return type based on whether the event expects a response.
@@ -769,6 +803,18 @@ declare module '@ampcode/plugin' {
769
803
  */
770
804
  export type IsPluginUINotAvailableError = (error: Error) => boolean
771
805
 
806
+ /**
807
+ * Whether a registered command is selectable in the command palette.
808
+ *
809
+ * - `enabled`: shown and selectable.
810
+ * - `disabled`: shown but not selectable; `reason` is displayed alongside the command.
811
+ * - `hidden`: not shown in the palette at all.
812
+ */
813
+ export type CommandAvailability =
814
+ | { type: 'enabled' }
815
+ | { type: 'disabled'; reason: string }
816
+ | { type: 'hidden' }
817
+
772
818
  /**
773
819
  * Options for registering a command.
774
820
  */
@@ -781,6 +827,31 @@ declare module '@ampcode/plugin' {
781
827
 
782
828
  /** Human-readable description of what this command does */
783
829
  description?: string
830
+
831
+ /**
832
+ * Initial availability of the command in the command palette.
833
+ * Defaults to `{ type: 'enabled' }`.
834
+ *
835
+ * Use the {@link CommandSubscription.setAvailability} method on the
836
+ * subscription returned by {@link PluginAPI.registerCommand} to update
837
+ * availability dynamically.
838
+ */
839
+ availability?: CommandAvailability
840
+ }
841
+
842
+ /**
843
+ * Subscription returned by {@link PluginAPI.registerCommand}.
844
+ *
845
+ * Allows updating the command's availability in the palette in addition to
846
+ * unregistering it.
847
+ */
848
+ export interface CommandSubscription extends Subscription {
849
+ /**
850
+ * Update whether this command is selectable in the command palette.
851
+ * Triggers a refresh in the host so the palette reflects the new state
852
+ * on its next read.
853
+ */
854
+ setAvailability(status: CommandAvailability): void
784
855
  }
785
856
 
786
857
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampcode/plugin",
3
- "version": "0.0.0-20260511003151-g13ad60d",
3
+ "version": "0.0.0-20260513003404-g32e421b",
4
4
  "description": "Amp Plugin API",
5
5
  "homepage": "https://ampcode.com/manual/plugin-api",
6
6
  "author": {