@ampcode/plugin 0.0.0-20260511003151-g13ad60d → 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.
- package/README.md +6 -2
- package/index.d.ts +34 -13
- 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.
|
|
30
|
-
|
|
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.
|
|
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
|
|
201
|
-
*
|
|
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
|
|
216
|
+
export interface Observable<T> {
|
|
204
217
|
/**
|
|
205
|
-
* Subscribe to
|
|
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
|
|
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
|
|
489
|
-
thread
|
|
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
|
-
*
|
|
734
|
+
* All plugin events are thread-scoped.
|
|
715
735
|
*/
|
|
716
|
-
export type PluginEventContext<E extends keyof PluginEventMap> = PluginEventContextBase &
|
|
717
|
-
|
|
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.
|