@ampcode/plugin 0.0.0-20260610024544-gdeae2c5 → 0.0.0-20260611025527-ge01a364

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