@ampcode/plugin 0.0.0-20260510003105-g670fa0a → 0.0.0-20260512003045-g373e11b

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 +34 -13
  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
  */
@@ -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
  /**
@@ -197,16 +209,23 @@ declare module '@ampcode/plugin' {
197
209
  export type PluginConfigurationTarget = 'workspace' | 'global'
198
210
 
199
211
  /**
200
- * Observable-like interface for Amp configuration.
201
- * Provides a limited subset of Observable functionality for plugins.
212
+ * Minimal Observable interface used by plugin APIs that stream values over time.
213
+ *
214
+ * Subscribers receive subsequent values until they unsubscribe.
202
215
  */
203
- export interface PluginConfiguration<T> {
216
+ export interface Observable<T> {
204
217
  /**
205
- * Subscribe to configuration changes.
218
+ * Subscribe to values emitted by this observable.
206
219
  */
207
220
  subscribe(observer: PluginConfigurationObserver<T>): Subscription
208
221
  subscribe(onNext: (value: T) => void): Subscription
222
+ }
209
223
 
224
+ /**
225
+ * Observable-like interface for Amp configuration.
226
+ * Provides a limited subset of Observable functionality for plugins.
227
+ */
228
+ export interface PluginConfiguration<T> extends Observable<T> {
210
229
  /**
211
230
  * Pipe operators for transforming the configuration observable.
212
231
  */
@@ -482,11 +501,12 @@ declare module '@ampcode/plugin' {
482
501
 
483
502
  /**
484
503
  * Event payload for session.start event.
485
- * Fired when the plugin session starts and before the first event for each thread.
504
+ * Fired when Amp starts a thread session, such as when the user sends the first
505
+ * message in a new thread or opens/switches to an existing thread.
486
506
  */
487
507
  export interface SessionStartEvent {
488
- /** The active thread for this session, when available */
489
- thread?: { id: ThreadID }
508
+ /** The thread that started running */
509
+ thread: { id: ThreadID }
490
510
  }
491
511
 
492
512
  /**
@@ -711,10 +731,11 @@ declare module '@ampcode/plugin' {
711
731
 
712
732
  /**
713
733
  * 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.
734
+ * All plugin events are thread-scoped.
715
735
  */
716
- export type PluginEventContext<E extends keyof PluginEventMap> = PluginEventContextBase &
717
- (E extends 'session.start' ? { thread?: PluginThread } : { thread: PluginThread })
736
+ export type PluginEventContext<E extends keyof PluginEventMap> = PluginEventContextBase & {
737
+ thread: PluginThread
738
+ }
718
739
 
719
740
  /**
720
741
  * Handler return type based on whether the event expects a response.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampcode/plugin",
3
- "version": "0.0.0-20260510003105-g670fa0a",
3
+ "version": "0.0.0-20260512003045-g373e11b",
4
4
  "description": "Amp Plugin API",
5
5
  "homepage": "https://ampcode.com/manual/plugin-api",
6
6
  "author": {