-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Public Tasks API with API key auth and webhook callbacks #1
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
Open
pec1985
wants to merge
9
commits into
main
Choose a base branch
from
feat/public-tasks-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
95a7e4c
feat: add public Tasks API with API key auth and webhook support
pec1985 a3f8a74
feat: add API key management UI to settings page
pec1985 46c0c80
fix: address CodeRabbit review — race conditions, error handling, web…
pec1985 48ec784
fix: mark failed task creation as error, clean up copy timeout on unm…
pec1985 ab54402
fix: SSE fetch timeout, clear stale errors, validate model format
pec1985 69d9eca
fix: SSRF protection for webhookUrl, connection-only SSE timeout, pre…
pec1985 e02cb2c
chore: remove redundant ApiKeySettings — Better Auth profile already …
pec1985 0137478
fix: add background color to dialog in light mode
pec1985 5095a18
merge: resolve conflicts with main in chat.ts (preserve webhook + pas…
pec1985 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /** | ||
| * Webhook invocation utility with retry logic. | ||
| * | ||
| * Fires a POST to the caller-supplied webhook URL when a task | ||
| * reaches a terminal state (completed, error, terminated). | ||
| */ | ||
|
|
||
| export interface WebhookPayload { | ||
| taskId: string; | ||
| status: 'completed' | 'error' | 'terminated'; | ||
| repoUrl?: string; | ||
| branch?: string; | ||
| summary?: string; | ||
| prUrl?: string; | ||
| error?: string; | ||
| completedAt: string; | ||
| } | ||
|
|
||
| interface WebhookOptions { | ||
| /** Maximum number of delivery attempts (default: 3). */ | ||
| maxAttempts?: number; | ||
| /** Initial backoff in ms before the first retry (default: 1000). */ | ||
| initialBackoffMs?: number; | ||
| } | ||
|
|
||
| /** | ||
| * Deliver a webhook payload via POST with exponential-backoff retry. | ||
| * | ||
| * Returns `true` if the webhook was delivered (2xx response), | ||
| * `false` if all attempts failed. | ||
| */ | ||
| export async function deliverWebhook( | ||
| url: string, | ||
| payload: WebhookPayload, | ||
| options: WebhookOptions = {}, | ||
| ): Promise<boolean> { | ||
| const maxAttempts = options.maxAttempts ?? 3; | ||
| const initialBackoffMs = options.initialBackoffMs ?? 1_000; | ||
|
|
||
| for (let attempt = 1; attempt <= maxAttempts; attempt++) { | ||
| try { | ||
| const response = await fetch(url, { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| 'User-Agent': 'Agentuity-Coder/1.0', | ||
| 'X-Webhook-Attempt': String(attempt), | ||
| }, | ||
| body: JSON.stringify(payload), | ||
| signal: AbortSignal.timeout(10_000), // 10s timeout per attempt | ||
| }); | ||
|
|
||
| if (response.ok) { | ||
| return true; | ||
| } | ||
|
|
||
| // Non-retryable client errors (4xx except 429) | ||
| if (response.status >= 400 && response.status < 500 && response.status !== 429) { | ||
| console.warn( | ||
| `[webhook] Non-retryable ${response.status} from ${url} (attempt ${attempt}/${maxAttempts})`, | ||
| ); | ||
| return false; | ||
| } | ||
| } catch (err) { | ||
| console.warn( | ||
| `[webhook] Delivery attempt ${attempt}/${maxAttempts} to ${url} failed:`, | ||
| err instanceof Error ? err.message : err, | ||
| ); | ||
| } | ||
|
|
||
| // Exponential backoff before next retry | ||
| if (attempt < maxAttempts) { | ||
| const backoff = initialBackoffMs * Math.pow(2, attempt - 1); | ||
| await new Promise((r) => setTimeout(r, backoff)); | ||
| } | ||
| } | ||
|
|
||
| console.error(`[webhook] All ${maxAttempts} attempts to ${url} failed`); | ||
| return false; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.