@ampcode/plugin 0.0.0-20260610024544-gdeae2c5 → 0.0.0-20260612025159-g6d2b3bd

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 +1 -1
  2. package/index.d.ts +183 -14
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -36,7 +36,7 @@ export default function (amp: PluginAPI) {
36
36
 
37
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
38
 
39
- After changing a plugin, open the command palette and run `plugins: reload`.
39
+ After changing a plugin, open the command palette and run `plugins: reload`, or restart Amp.
40
40
 
41
41
  ## Documentation
42
42
 
package/index.d.ts CHANGED
@@ -25,7 +25,7 @@ declare module '@ampcode/plugin' {
25
25
  /** Logger scoped to this plugin */
26
26
  logger: PluginLogger
27
27
 
28
- /** System capabilities and environment information */
28
+ /** System capabilities and information */
29
29
  system: PluginSystem
30
30
 
31
31
  /** Observable configuration that streams changes */
@@ -132,6 +132,13 @@ declare module '@ampcode/plugin' {
132
132
  */
133
133
  createAgent(config: CreateAgentConfig): Agent
134
134
 
135
+ /**
136
+ * Get an agent handle for one of Amp's built-in agent modes (`smart`,
137
+ * `deep`, or `rush`). Threads spawned from the handle run the built-in
138
+ * mode's prompt and tools, like a thread the user started in that mode.
139
+ */
140
+ getBuiltinAgent(mode: BuiltinAgentMode, options?: GetBuiltinAgentOptions): Agent
141
+
135
142
  /** Register a custom agent mode that clients may show alongside built-in modes. */
136
143
  registerAgentMode(definition: PluginAgentModeDefinition): Subscription
137
144
 
@@ -160,7 +167,18 @@ declare module '@ampcode/plugin' {
160
167
  threads: PluginThreads
161
168
  }
162
169
 
163
- export type AgentReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high'
170
+ /** Reasoning effort levels supported by plugin agents, for models that support them. */
171
+ export type AgentReasoningEffort =
172
+ | 'none'
173
+ | 'minimal'
174
+ | 'low'
175
+ | 'medium'
176
+ | 'high'
177
+ | 'xhigh'
178
+ | 'max'
179
+
180
+ /** Amp built-in agent modes available to plugins. */
181
+ export type BuiltinAgentMode = 'smart' | 'deep' | 'rush'
164
182
 
165
183
  export type AgentToolSelection =
166
184
  | readonly string[]
@@ -193,28 +211,96 @@ declare module '@ampcode/plugin' {
193
211
  tools?: AgentToolSelection
194
212
  /** Optional reasoning effort override for models that support it. */
195
213
  reasoningEffort?: AgentReasoningEffort
214
+ /**
215
+ * Display shown for threads running this agent. Travels with the agent
216
+ * definition, so threads created from it — including by other plugins via
217
+ * a `thread.agent()` handle — carry the label.
218
+ */
219
+ display?: AgentDisplay
196
220
  }
197
221
 
198
- export interface AgentDefinition extends CreateAgentConfig {
222
+ /** Display metadata for a plugin agent. */
223
+ export interface AgentDisplay {
224
+ /** Label shown in mode pickers and thread headers, 16 characters or less. */
225
+ label: string
226
+ /** Optional label color as a hex RGB string, for example "#d97706". */
227
+ color?: string
228
+ }
229
+
230
+ export interface CustomAgentDefinition extends CreateAgentConfig {
199
231
  readonly kind: 'agent-definition'
200
232
  }
201
233
 
234
+ /** Reference to one of Amp's built-in agent modes. */
235
+ export interface BuiltinAgentDefinition {
236
+ readonly kind: 'builtin-agent'
237
+ mode: BuiltinAgentMode
238
+ /** Reasoning effort pinned on threads spawned from this agent. */
239
+ reasoningEffort?: AgentReasoningEffort
240
+ }
241
+
242
+ export type AgentDefinition = CustomAgentDefinition | BuiltinAgentDefinition
243
+
244
+ export interface GetBuiltinAgentOptions {
245
+ /** Reasoning effort pinned on threads spawned from this agent. */
246
+ reasoningEffort?: AgentReasoningEffort
247
+ }
248
+
202
249
  export interface RunAgentOptions {
203
- /** Maximum time to wait for the agent run to finish, in milliseconds. */
250
+ /** Maximum time to wait for the agent run to finish, in milliseconds (default 10 minutes). */
204
251
  timeoutMs?: number
205
- /** Parent thread for this run when the agent is being used as a subagent/tool. */
252
+ /**
253
+ * Parent thread for this run when the agent is being used as a subagent/tool.
254
+ * When omitted, the thread is created without a parent.
255
+ */
206
256
  parentThreadID?: ThreadID
207
257
  }
208
258
 
259
+ export interface CreateAgentThreadOptions {
260
+ /**
261
+ * Parent thread for the new thread when the agent is being used as a
262
+ * subagent/tool. When omitted, the thread is created without a parent.
263
+ */
264
+ parentThreadID?: ThreadID
265
+ /** Show the created thread in the client when supported. */
266
+ show?: boolean
267
+ }
268
+
269
+ /** Thread handle returned by {@link Agent.createThread}. */
270
+ export type AgentThread = PluginThread
271
+
209
272
  export interface AgentRunResult {
210
- /** Thread created for this run, when exposed by the runtime. */
211
- threadID?: `T-${string}`
273
+ /** Thread created for this run. */
274
+ threadID: `T-${string}`
212
275
  /** Final text response from the agent. */
213
276
  text: string
214
277
  }
215
278
 
279
+ /**
280
+ * A handle to a custom or built-in agent, returned by
281
+ * {@link ExperimentalPluginAPI.createAgent} and
282
+ * {@link ExperimentalPluginAPI.getBuiltinAgent}.
283
+ */
216
284
  export interface Agent {
217
285
  readonly definition: AgentDefinition
286
+
287
+ /**
288
+ * Create a background thread running this agent and return a handle for
289
+ * interacting with it: append messages, await replies with
290
+ * {@link PluginThread.waitForResponse}, observe state, or cancel.
291
+ *
292
+ * The thread keeps running independently of the caller; there is no
293
+ * lifecycle to manage.
294
+ */
295
+ createThread(options?: CreateAgentThreadOptions): Promise<AgentThread>
296
+
297
+ /**
298
+ * One-shot run: create a thread, send the message, and resolve with the
299
+ * assistant's reply once the turn finishes.
300
+ *
301
+ * When called from inside an executing plugin tool, aborting that tool
302
+ * cancels the agent's turn.
303
+ */
218
304
  run(message: string, options?: RunAgentOptions): Promise<AgentRunResult>
219
305
  }
220
306
 
@@ -222,17 +308,26 @@ declare module '@ampcode/plugin' {
222
308
  export interface PluginAgentModeDefinition {
223
309
  /** Stable identifier within the plugin. */
224
310
  key: string
225
- /** Label shown in compact mode pickers, for example "review" or "architect". */
226
- label: string
311
+ /**
312
+ * Label shown in compact mode pickers, for example "review" or "architect".
313
+ * Defaults to the agent definition's `display.label`; required when the
314
+ * agent has no display.
315
+ */
316
+ label?: string
227
317
  /** Optional longer description shown in command palettes and pickers. */
228
318
  description?: string
229
- /** Optional label color as a hex RGB string, for example "#d97706". */
319
+ /**
320
+ * Optional label color as a hex RGB string, for example "#d97706".
321
+ * Defaults to the agent definition's `display.color`.
322
+ */
230
323
  color?: string
231
324
  /** Agent definition used when creating a thread with this mode selected. */
232
325
  agent: AgentDefinition
233
326
  }
234
327
 
235
- export interface PluginAgentMode extends Omit<PluginAgentModeDefinition, 'agent'> {
328
+ export interface PluginAgentMode extends Omit<PluginAgentModeDefinition, 'agent' | 'label'> {
329
+ /** Resolved mode label (from the definition or the agent's display). */
330
+ label: string
236
331
  pluginName: string
237
332
  agent: AgentDefinition
238
333
  }
@@ -392,7 +487,46 @@ declare module '@ampcode/plugin' {
392
487
  }
393
488
 
394
489
  /**
395
- * System capabilities provided to plugins.
490
+ * Identity of the authenticated Amp user exposed to plugins.
491
+ */
492
+ export interface User {
493
+ /**
494
+ * Opaque string that identifies the user.
495
+ */
496
+ readonly id: string
497
+
498
+ /** User's email address. */
499
+ readonly email: string
500
+
501
+ /** User's first name, when set. */
502
+ readonly firstName: string | null
503
+
504
+ /** User's last name, when set. */
505
+ readonly lastName: string | null
506
+
507
+ /** User's Amp username, when set. */
508
+ readonly username: string | null
509
+
510
+ /** Workspace the user belongs to, or null when the user is not in a workspace. */
511
+ readonly workspace: Workspace | null
512
+ }
513
+
514
+ /**
515
+ * Workspace identity for the authenticated user.
516
+ */
517
+ export interface Workspace {
518
+ /** Opaque string that identifies the workspace. */
519
+ readonly id: string
520
+
521
+ /** Workspace slug/name. */
522
+ readonly name: string
523
+
524
+ /** Human-friendly workspace display name, when set. */
525
+ readonly displayName: string | null
526
+ }
527
+
528
+ /**
529
+ * System capabilities and information provided to plugins.
396
530
  */
397
531
  export interface PluginSystem {
398
532
  /**
@@ -407,6 +541,11 @@ declare module '@ampcode/plugin' {
407
541
  */
408
542
  readonly ampURL: URL
409
543
 
544
+ /**
545
+ * Identity of the authenticated Amp user, or null when Amp is not authenticated.
546
+ */
547
+ readonly user: User | null
548
+
410
549
  /**
411
550
  * Information about the executor that is running this plugin.
412
551
  */
@@ -527,6 +666,16 @@ declare module '@ampcode/plugin' {
527
666
  roles?: Array<'user' | 'assistant'>
528
667
  }
529
668
 
669
+ /**
670
+ * Agent activity state of a thread.
671
+ *
672
+ * - `idle`: the agent is not working; the last turn (if any) has finished.
673
+ * - `running`: the agent is working (inference or tool execution in progress).
674
+ * - `awaiting-approval`: the agent is blocked waiting for a tool approval.
675
+ * - `error`: the thread has an active error.
676
+ */
677
+ export type ThreadState = 'idle' | 'running' | 'awaiting-approval' | 'error'
678
+
530
679
  /**
531
680
  * Thread API for reading and manipulating the current thread.
532
681
  */
@@ -534,9 +683,29 @@ declare module '@ampcode/plugin' {
534
683
  /** Active thread ID for the current invocation context */
535
684
  id: ThreadID
536
685
 
686
+ /** Agent currently used by this thread, suitable for creating related threads. */
687
+ agent(): Promise<Agent>
688
+
537
689
  /** Current thread title stream, or `null` when no title has been set yet. */
538
690
  readonly title: Observable<string | null> & { get(): Promise<string | null> }
539
691
 
692
+ /** Agent activity state stream for this thread. */
693
+ readonly state: Observable<ThreadState> & { get(): Promise<ThreadState> }
694
+
695
+ /**
696
+ * Wait for the current or next agent turn to finish and resolve with the
697
+ * assistant's reply.
698
+ *
699
+ * Waits until the thread has been `running` (or `awaiting-approval`) and
700
+ * returns to `idle`, then resolves with the last assistant message.
701
+ * Rejects if the thread enters the `error` state or the timeout elapses
702
+ * (default 10 minutes).
703
+ */
704
+ waitForResponse(options?: { timeoutMs?: number }): Promise<ThreadAssistantMessage>
705
+
706
+ /** Stop the agent's current turn in this thread, if one is running. */
707
+ cancel(): Promise<void>
708
+
540
709
  /**
541
710
  * Read messages from the thread in a stable plugin-facing schema.
542
711
  *
@@ -888,7 +1057,7 @@ declare module '@ampcode/plugin' {
888
1057
  /** AI capabilities */
889
1058
  ai: PluginAI
890
1059
 
891
- /** System capabilities */
1060
+ /** System capabilities and information */
892
1061
  system: PluginSystem
893
1062
 
894
1063
  /** The trace span ID for this handler invocation, if tracing is enabled */
@@ -1018,7 +1187,7 @@ declare module '@ampcode/plugin' {
1018
1187
  /** AI capabilities */
1019
1188
  ai: PluginAI
1020
1189
 
1021
- /** System capabilities */
1190
+ /** System capabilities and information */
1022
1191
  system: PluginSystem
1023
1192
 
1024
1193
  /** Bun's shell API for executing commands */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampcode/plugin",
3
- "version": "0.0.0-20260610024544-gdeae2c5",
3
+ "version": "0.0.0-20260612025159-g6d2b3bd",
4
4
  "description": "Amp Plugin API",
5
5
  "homepage": "https://ampcode.com/manual/plugin-api",
6
6
  "author": {