# Example Request/Response Extension

### Package.json

{% hint style="warning" %}
Note: do **not** name any file `main.swift` or `main.cs`
{% endhint %}

```json
{
  "name": "positron-prompt",
  "version": "1.0.0",
  "positron": {
    "command": "prompt",
    "className": "PromptPlugin",
    "platforms": {
      "darwin": "mac/Prompt.swift",
      "win32": "win/Prompt.cs"
    }
  }
}
```

### mac/Prompt.swift

{% code lineNumbers="true" %}

```swift
import Cocoa

public class PromptPlugin {
        static func handle(windowId: Int, args: [String]) {
       
        guard let window = windows[windowId] else { return }
        guard let message = args.first else {
            printError("prompt — missing message argument")
            return
        }
        let alert = NSAlert()
        alert.messageText = message
        alert.addButton(withTitle: "OK")
        alert.addButton(withTitle: "Cancel")

        let inputField = NSTextField(frame: NSRect(x: 0, y: 0, width: 200, height: 24))
        alert.accessoryView = inputField

        if args.count > 1 {
            inputField.stringValue = args[1]
        }

        alert.beginSheetModal(for: window) { response in
            if response == .alertFirstButtonReturn {
                let userInput = inputField.stringValue
                AppDelegate.shared?.ipcClient.send(
                    IPCResponse(windowId: windowId, event: "prompt-reply-\(windowId)", data: ["input": userInput])
                )
            } else {
                AppDelegate.shared?.ipcClient.send(
                    IPCResponse(windowId: windowId, event: "prompt-reply-\(windowId)", data: ["input": ""])
                )
            }
        }
    }
}
```

{% endcode %}

### win/Prompt.cs

{% code lineNumbers="true" %}

```csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;

namespace PositronWindows
{
    public static class PromptPlugin
    {
        public static void Handle(int windowId, List<string> args)
        {
                    if (args.Count < 2)
                    {
                        error("prompt — expected message and defaultValue arguments");
                        break;
                    }
                    {
                        var message = args[0];
                        var defaultValue = args[1];
                        string result = Interaction.InputBox(message, "Prompt", defaultValue);
                        _ipcClient.Send(new IPCResponse
                        {
                            windowId = windowId,
                            @event = "prompt-reply-" + windowId,
                            data = new() { { "input", result } }
                        });
                    }
        }
    }
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://positronjs.gitbook.io/v1/extensions/create/example-request-response-extension.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
