@ampcode/plugin 0.0.0-20260629024814-g800cf02 → 0.0.0-20260702003754-g0f76a16

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 +2 -1
  2. package/index.d.ts +90 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -10,7 +10,8 @@ Plugins can:
10
10
  - **Add tools** — `amp.registerTool(...)` for custom tools the agent can call
11
11
  - **Add commands** — `amp.registerCommand(...)` for command palette actions
12
12
  - **Show UI** — `ctx.ui.notify(...)`, `ctx.ui.confirm(...)`, `ctx.ui.input(...)`, and `ctx.ui.select(...)`
13
- - **Classify with AI** — `amp.ai.ask(...)` for yes/no decisions with confidence and reasoning
13
+ - **Use AI** — `amp.ai.ask(...)` for thread-scoped yes/no classification that defaults to no
14
+ reasoning unless `{ reasoningEffort }` is set
14
15
 
15
16
  ## Locations
16
17
 
package/index.d.ts CHANGED
@@ -253,7 +253,7 @@ declare module '@ampcode/plugin' {
253
253
  * Run `amp plugins show-agent-options --json` for the public model IDs intended for
254
254
  * plugin agents.
255
255
  */
256
- model: string
256
+ model: PluginAIModel
257
257
  /** Instructions appended to Amp's base agent prompt. */
258
258
  instructions: string
259
259
  /**
@@ -420,16 +420,104 @@ declare module '@ampcode/plugin' {
420
420
  reason: string
421
421
  }
422
422
 
423
+ export type PluginAIModelProvider =
424
+ | 'amp'
425
+ | 'anthropic'
426
+ | 'baseten'
427
+ | 'fireworks'
428
+ | 'openai'
429
+ | 'vertexai'
430
+ | 'xai'
431
+
432
+ /** Model identifier in `provider/model` format, such as `openai/gpt-5.5`. */
433
+ export type PluginAIModel = `${PluginAIModelProvider}/${string}`
434
+
435
+ export type PluginAIFieldSchema = {
436
+ type: string | string[]
437
+ description?: string
438
+ [key: string]: unknown
439
+ }
440
+
441
+ export type PluginAIJSONSchema = {
442
+ type: 'object'
443
+ properties?: Record<string, PluginAIFieldSchema>
444
+ required?: string[]
445
+ additionalProperties?: boolean
446
+ [key: string]: unknown
447
+ }
448
+
449
+ /**
450
+ * Options for an AI operation.
451
+ */
452
+ export interface PluginAIOptions {
453
+ /** Thread to bill and route the AI request through. Required outside a thread-bound handler. */
454
+ threadID?: ThreadID
455
+ /** Model identifier in `provider/model` format. Defaults to Amp's fast classifier model. */
456
+ model?: PluginAIModel
457
+ /** Optional reasoning effort override for models that support it. Defaults to no reasoning. */
458
+ reasoningEffort?: AgentReasoningEffort
459
+ /** Optional system instructions. */
460
+ system?: string
461
+ /** Maximum output tokens. */
462
+ maxTokens?: number
463
+ }
464
+
465
+ /**
466
+ * Options for an AI ask operation.
467
+ */
468
+ export interface PluginAIAskOptions extends PluginAIOptions {}
469
+
470
+ export interface PluginAIObjectSchema {
471
+ name: string
472
+ description?: string
473
+ fields: Record<string, PluginAIFieldSchema>
474
+ }
475
+
476
+ export interface PluginAIGenerateTextRequest extends PluginAIOptions {
477
+ /** The prompt to send to the model. */
478
+ prompt: string
479
+ /** Omit schema to receive a text response. */
480
+ schema?: never
481
+ }
482
+
483
+ export interface PluginAIGenerateObjectRequest extends PluginAIOptions {
484
+ /** The prompt to send to the model. */
485
+ prompt: string
486
+ /** Schema for structured output. Supplying a schema returns the validated object. */
487
+ schema: PluginAIObjectSchema
488
+ }
489
+
423
490
  /**
424
491
  * AI capabilities provided to plugins.
425
492
  */
426
493
  export interface PluginAI {
494
+ /**
495
+ * Ask an AI model for a text response.
496
+ *
497
+ * Calls are routed through the current thread. Pass `threadID` when calling outside a
498
+ * thread-bound handler.
499
+ */
500
+ generate(request: PluginAIGenerateTextRequest): Promise<string>
501
+
502
+ /**
503
+ * Ask an AI model for a structured JSON object matching the provided schema.
504
+ *
505
+ * Calls are routed through the current thread. Pass `threadID` when calling outside a
506
+ * thread-bound handler.
507
+ */
508
+ generate<T extends Record<string, unknown> = Record<string, unknown>>(
509
+ request: PluginAIGenerateObjectRequest,
510
+ ): Promise<T>
511
+
427
512
  /**
428
513
  * Ask an AI model a yes/no question and get a confidence-based response with reasoning.
514
+ * This is a convenience wrapper around {@link PluginAI.generate}.
515
+ *
429
516
  * @param question - The yes/no question to ask
517
+ * @param options - Thread to bill and route the AI request through. Omit inside a thread-bound handler.
430
518
  * @returns Object with result, probability, and reason
431
519
  */
432
- ask(question: string): Promise<PluginAIAskResult>
520
+ ask(question: string, options?: PluginAIAskOptions): Promise<PluginAIAskResult>
433
521
  }
434
522
 
435
523
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampcode/plugin",
3
- "version": "0.0.0-20260629024814-g800cf02",
3
+ "version": "0.0.0-20260702003754-g0f76a16",
4
4
  "description": "Amp Plugin API",
5
5
  "homepage": "https://ampcode.com/manual/plugin-api",
6
6
  "author": {