-
Notifications
You must be signed in to change notification settings - Fork 3.3k
REST API and Web UI Now Support Dynamic Pattern Variables #1533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REST API and Web UI Now Support Dynamic Pattern Variables #1533
Conversation
## CHANGES - Add Variables field to PromptRequest struct - Pass pattern variables through chat handler - Create API variables documentation example - Add pattern variables UI in web interface - Create pattern variables store in Svelte - Include variables in chat service requests - Add JSON textarea for variable input
## CHANGES - Create `PatternApplyRequest` struct for request body parsing - Implement `ApplyPattern` method for POST /patterns/:name/apply - Register manual routes for pattern operations in `NewPatternsHandler` - Refactor `Get` method to return raw pattern content - Merge query parameters with request body variables in `ApplyPattern` - Use `StorageHandler` for pattern-related storage operations
…hods - Refactor `cleanPatternOutput` to use a dedicated return variable. - Hoist `processResponse` function for improved stream readability. - Remove unnecessary whitespace and trailing newlines from file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds support for passing dynamic pattern variables through the REST API and Web UI, matching CLI functionality.
- Introduces a new
/patterns/:name/apply
endpoint for rendering patterns with variables. - Extends the chat API (
/chat
) and UI components to accept and propagate avariables
map. - Updates internal services and stores to manage and transmit pattern variables in requests.
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
web/src/lib/store/pattern-store.ts | Adds patternVariables writable store for JSON input. |
web/src/lib/services/ChatService.ts | Includes variables in chat request options; renames cleaning variable. |
web/src/lib/interfaces/chat-interface.ts | Adds optional variables field to ChatPrompt interface. |
web/src/lib/components/chat/DropdownGroup.svelte | Adds textarea for JSON pattern variables with live parsing. |
restapi/patterns.go | Registers new apply route; custom GET returns raw pattern. |
restapi/chat.go | Adds Variables to PromptRequest and passes through to handler. |
restapi/docs/API_VARIABLES_EXAMPLE.md | Documents usage of pattern variables with examples. |
Comments suppressed due to low confidence (4)
restapi/patterns.go:60
- Consider adding automated tests for the new
/patterns/:name/apply
endpoint to verify variable merging (query vs. body) and error handling for invalid JSON.
// ApplyPattern handles the POST /patterns/:name/apply route
restapi/patterns.go:48
- [nitpick] The returned pattern
Description
is always empty. It would improve clarity to populate this field from the stored pattern metadata so API consumers get the actual description.
Description: "",
web/src/lib/services/ChatService.ts:184
- The
selectedStrategy
store is used but not imported in this file, causing a reference error. Please importselectedStrategy
from your strategy store (e.g.,import { selectedStrategy } from '$lib/store/strategy-store';
).
strategyName: get(selectedStrategy), // Add selected strategy to prompt
restapi/patterns.go:81
- After processing the pattern with
GetApplyVariables
, the handler does not send a success response. You should addc.JSON(http.StatusOK, pattern)
to return the applied pattern to the client.
pattern, err := h.patterns.GetApplyVariables(name, variables, request.Input)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good for me. Thank you
REST API and Web UI Now Support Dynamic Pattern Variables
Summary
This PR adds support for pattern variables in the REST API, allowing users to pass dynamic variables to patterns when making chat requests. This brings the REST API to feature parity with the CLI's pattern variable functionality.
Related Issues
Closes #1446
Screenshots
Before fix (on main)
The translate pattern needs a
lang_code
variable. Note that selecting the pattern does not have it show up in the Web UI.After fix (on PR branch)
Files Changed
Modified Files
restapi/chat.go
Variables
field toPromptRequest
struct to accept pattern variables from API requestsrestapi/patterns.go
ApplyPattern
endpoint (POST /patterns/:name/apply
) for applying patterns with variablesGet
method to return raw pattern content without variable processingPatternApplyRequest
struct for the new apply endpointweb/src/lib/components/chat/DropdownGroup.svelte
web/src/lib/interfaces/chat-interface.ts
variables
field toChatPrompt
interfaceweb/src/lib/services/ChatService.ts
createChatPrompt
method to include pattern variables from the storeweb/src/lib/store/pattern-store.ts
patternVariables
writable store to manage pattern variables stateAdded Files
restapi/docs/API_VARIABLES_EXAMPLE.md
Deleted Files
These appear to be some non-pattern-related raycast scripts.
Code Changes
Key Changes in
restapi/chat.go
Added pattern variables to the chat processing:
Key Changes in
restapi/patterns.go
New endpoint for applying patterns with variables:
Key Changes in Web UI
Added JSON textarea for pattern variables:
Reason for Changes
Impact of Changes
Test Plan
Manual Testing:
translate
patternAPI Testing:
Web UI Testing:
Additional Notes
{{variable_name}}
){{input}}
variable is handled automatically and should not be included in the variables map