mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
updated generic webhook to use sdk as test case and fixed issues
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
# Import the provider builder to ensure it's registered
|
||||
from backend.sdk.registry import AutoRegistry
|
||||
|
||||
from .triggers import GenericWebhookTriggerBlock, generic_webhook
|
||||
|
||||
# Ensure the SDK registry is patched to include our webhook manager
|
||||
AutoRegistry.patch_integrations()
|
||||
|
||||
__all__ = ["GenericWebhookTriggerBlock", "generic_webhook"]
|
||||
@@ -3,10 +3,7 @@ import logging
|
||||
from fastapi import Request
|
||||
from strenum import StrEnum
|
||||
|
||||
from backend.data import integrations
|
||||
from backend.integrations.providers import ProviderName
|
||||
|
||||
from ._manual_base import ManualWebhookManagerBase
|
||||
from backend.sdk import ManualWebhookManagerBase, Webhook
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -16,12 +13,11 @@ class GenericWebhookType(StrEnum):
|
||||
|
||||
|
||||
class GenericWebhooksManager(ManualWebhookManagerBase):
|
||||
PROVIDER_NAME = ProviderName.GENERIC_WEBHOOK
|
||||
WebhookType = GenericWebhookType
|
||||
|
||||
@classmethod
|
||||
async def validate_payload(
|
||||
cls, webhook: integrations.Webhook, request: Request
|
||||
cls, webhook: Webhook, request: Request
|
||||
) -> tuple[dict, str]:
|
||||
payload = await request.json()
|
||||
event_type = GenericWebhookType.PLAIN
|
||||
@@ -1,13 +1,21 @@
|
||||
from backend.data.block import (
|
||||
from backend.sdk import (
|
||||
Block,
|
||||
BlockCategory,
|
||||
BlockManualWebhookConfig,
|
||||
BlockOutput,
|
||||
BlockSchema,
|
||||
ProviderBuilder,
|
||||
ProviderName,
|
||||
SchemaField,
|
||||
)
|
||||
|
||||
from ._webhook import GenericWebhooksManager, GenericWebhookType
|
||||
|
||||
generic_webhook = (
|
||||
ProviderBuilder("generic_webhook")
|
||||
.with_webhook_manager(GenericWebhooksManager)
|
||||
.build()
|
||||
)
|
||||
from backend.data.model import SchemaField
|
||||
from backend.integrations.providers import ProviderName
|
||||
from backend.integrations.webhooks.generic import GenericWebhookType
|
||||
|
||||
|
||||
class GenericWebhookTriggerBlock(Block):
|
||||
@@ -36,7 +44,7 @@ class GenericWebhookTriggerBlock(Block):
|
||||
input_schema=GenericWebhookTriggerBlock.Input,
|
||||
output_schema=GenericWebhookTriggerBlock.Output,
|
||||
webhook_config=BlockManualWebhookConfig(
|
||||
provider=ProviderName.GENERIC_WEBHOOK,
|
||||
provider=ProviderName(generic_webhook.name),
|
||||
webhook_type=GenericWebhookType.PLAIN,
|
||||
),
|
||||
test_input={"constants": {"key": "value"}, "payload": self.example_payload},
|
||||
|
||||
@@ -19,7 +19,6 @@ class ProviderName(str, Enum):
|
||||
D_ID = "d_id"
|
||||
E2B = "e2b"
|
||||
FAL = "fal"
|
||||
GENERIC_WEBHOOK = "generic_webhook"
|
||||
GITHUB = "github"
|
||||
GOOGLE = "google"
|
||||
GOOGLE_MAPS = "google_maps"
|
||||
|
||||
@@ -12,7 +12,6 @@ def load_webhook_managers() -> dict["ProviderName", type["BaseWebhooksManager"]]
|
||||
webhook_managers = {}
|
||||
|
||||
from .compass import CompassWebhookManager
|
||||
from .generic import GenericWebhooksManager
|
||||
from .github import GithubWebhooksManager
|
||||
from .slant3d import Slant3DWebhooksManager
|
||||
|
||||
@@ -23,7 +22,6 @@ def load_webhook_managers() -> dict["ProviderName", type["BaseWebhooksManager"]]
|
||||
CompassWebhookManager,
|
||||
GithubWebhooksManager,
|
||||
Slant3DWebhooksManager,
|
||||
GenericWebhooksManager,
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
@@ -34,6 +34,7 @@ from backend.data.block import (
|
||||
BlockType,
|
||||
BlockWebhookConfig,
|
||||
)
|
||||
from backend.data.integrations import Webhook
|
||||
from backend.data.model import APIKeyCredentials, CredentialsField
|
||||
from backend.data.model import CredentialsMetaInput as _CredentialsMetaInput
|
||||
from backend.data.model import (
|
||||
@@ -156,6 +157,7 @@ __all__ = [
|
||||
"ProviderName",
|
||||
"BaseWebhooksManager",
|
||||
"ManualWebhookManagerBase",
|
||||
"Webhook",
|
||||
# Provider-Specific (when available)
|
||||
"BaseOAuthHandler",
|
||||
# Utilities
|
||||
|
||||
@@ -68,6 +68,16 @@ class AutoRegistry:
|
||||
|
||||
# Register webhook manager if provided
|
||||
if provider.webhook_manager:
|
||||
# Dynamically set PROVIDER_NAME if not already set
|
||||
if (
|
||||
not hasattr(provider.webhook_manager, "PROVIDER_NAME")
|
||||
or provider.webhook_manager.PROVIDER_NAME is None
|
||||
):
|
||||
# Import ProviderName to create dynamic enum value
|
||||
from backend.integrations.providers import ProviderName
|
||||
|
||||
# This works because ProviderName has _missing_ method
|
||||
provider.webhook_manager.PROVIDER_NAME = ProviderName(provider.name)
|
||||
cls._webhook_managers[provider.name] = provider.webhook_manager
|
||||
|
||||
# Register default credentials
|
||||
@@ -171,7 +181,13 @@ class AutoRegistry:
|
||||
# Add SDK-registered managers
|
||||
sdk_managers = cls.get_webhook_managers()
|
||||
if isinstance(sdk_managers, dict):
|
||||
managers.update(sdk_managers) # type: ignore
|
||||
# Import ProviderName for conversion
|
||||
from backend.integrations.providers import ProviderName
|
||||
|
||||
# Convert string keys to ProviderName for consistency
|
||||
for provider_str, manager in sdk_managers.items():
|
||||
provider_name = ProviderName(provider_str)
|
||||
managers[provider_name] = manager
|
||||
return managers
|
||||
|
||||
webhooks.load_webhook_managers = patched_load
|
||||
|
||||
@@ -512,7 +512,7 @@ def _get_provider_oauth_handler(
|
||||
|
||||
handler_class = HANDLERS_BY_NAME[provider_key]
|
||||
frontend_base_url = settings.config.frontend_base_url
|
||||
|
||||
|
||||
if not frontend_base_url:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
|
||||
@@ -37,8 +37,6 @@ import type { GetV1GetSpecificGraphParams } from "../../models/getV1GetSpecificG
|
||||
|
||||
import type { Graph } from "../../models/graph";
|
||||
|
||||
import type { GraphExecution } from "../../models/graphExecution";
|
||||
|
||||
import type { GraphExecutionMeta } from "../../models/graphExecutionMeta";
|
||||
|
||||
import type { GraphModel } from "../../models/graphModel";
|
||||
@@ -47,6 +45,8 @@ import type { HTTPValidationError } from "../../models/hTTPValidationError";
|
||||
|
||||
import type { PostV1ExecuteGraphAgentParams } from "../../models/postV1ExecuteGraphAgentParams";
|
||||
|
||||
import type { PostV1StopGraphExecutionsParams } from "../../models/postV1StopGraphExecutionsParams";
|
||||
|
||||
import type { SetGraphActiveVersion } from "../../models/setGraphActiveVersion";
|
||||
|
||||
import { customMutator } from "../../../mutators/custom-mutator";
|
||||
@@ -1498,7 +1498,7 @@ export const usePostV1ExecuteGraphAgent = <
|
||||
* @summary Stop graph execution
|
||||
*/
|
||||
export type postV1StopGraphExecutionResponse200 = {
|
||||
data: GraphExecution;
|
||||
data: GraphExecutionMeta;
|
||||
status: 200;
|
||||
};
|
||||
|
||||
@@ -1608,6 +1608,130 @@ export const usePostV1StopGraphExecution = <
|
||||
|
||||
return useMutation(mutationOptions, queryClient);
|
||||
};
|
||||
/**
|
||||
* @summary Stop graph executions
|
||||
*/
|
||||
export type postV1StopGraphExecutionsResponse200 = {
|
||||
data: GraphExecutionMeta[];
|
||||
status: 200;
|
||||
};
|
||||
|
||||
export type postV1StopGraphExecutionsResponse422 = {
|
||||
data: HTTPValidationError;
|
||||
status: 422;
|
||||
};
|
||||
|
||||
export type postV1StopGraphExecutionsResponseComposite =
|
||||
| postV1StopGraphExecutionsResponse200
|
||||
| postV1StopGraphExecutionsResponse422;
|
||||
|
||||
export type postV1StopGraphExecutionsResponse =
|
||||
postV1StopGraphExecutionsResponseComposite & {
|
||||
headers: Headers;
|
||||
};
|
||||
|
||||
export const getPostV1StopGraphExecutionsUrl = (
|
||||
params: PostV1StopGraphExecutionsParams,
|
||||
) => {
|
||||
const normalizedParams = new URLSearchParams();
|
||||
|
||||
Object.entries(params || {}).forEach(([key, value]) => {
|
||||
if (value !== undefined) {
|
||||
normalizedParams.append(key, value === null ? "null" : value.toString());
|
||||
}
|
||||
});
|
||||
|
||||
const stringifiedParams = normalizedParams.toString();
|
||||
|
||||
return stringifiedParams.length > 0
|
||||
? `/api/executions?${stringifiedParams}`
|
||||
: `/api/executions`;
|
||||
};
|
||||
|
||||
export const postV1StopGraphExecutions = async (
|
||||
params: PostV1StopGraphExecutionsParams,
|
||||
options?: RequestInit,
|
||||
): Promise<postV1StopGraphExecutionsResponse> => {
|
||||
return customMutator<postV1StopGraphExecutionsResponse>(
|
||||
getPostV1StopGraphExecutionsUrl(params),
|
||||
{
|
||||
...options,
|
||||
method: "POST",
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
export const getPostV1StopGraphExecutionsMutationOptions = <
|
||||
TError = HTTPValidationError,
|
||||
TContext = unknown,
|
||||
>(options?: {
|
||||
mutation?: UseMutationOptions<
|
||||
Awaited<ReturnType<typeof postV1StopGraphExecutions>>,
|
||||
TError,
|
||||
{ params: PostV1StopGraphExecutionsParams },
|
||||
TContext
|
||||
>;
|
||||
request?: SecondParameter<typeof customMutator>;
|
||||
}): UseMutationOptions<
|
||||
Awaited<ReturnType<typeof postV1StopGraphExecutions>>,
|
||||
TError,
|
||||
{ params: PostV1StopGraphExecutionsParams },
|
||||
TContext
|
||||
> => {
|
||||
const mutationKey = ["postV1StopGraphExecutions"];
|
||||
const { mutation: mutationOptions, request: requestOptions } = options
|
||||
? options.mutation &&
|
||||
"mutationKey" in options.mutation &&
|
||||
options.mutation.mutationKey
|
||||
? options
|
||||
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
||||
: { mutation: { mutationKey }, request: undefined };
|
||||
|
||||
const mutationFn: MutationFunction<
|
||||
Awaited<ReturnType<typeof postV1StopGraphExecutions>>,
|
||||
{ params: PostV1StopGraphExecutionsParams }
|
||||
> = (props) => {
|
||||
const { params } = props ?? {};
|
||||
|
||||
return postV1StopGraphExecutions(params, requestOptions);
|
||||
};
|
||||
|
||||
return { mutationFn, ...mutationOptions };
|
||||
};
|
||||
|
||||
export type PostV1StopGraphExecutionsMutationResult = NonNullable<
|
||||
Awaited<ReturnType<typeof postV1StopGraphExecutions>>
|
||||
>;
|
||||
|
||||
export type PostV1StopGraphExecutionsMutationError = HTTPValidationError;
|
||||
|
||||
/**
|
||||
* @summary Stop graph executions
|
||||
*/
|
||||
export const usePostV1StopGraphExecutions = <
|
||||
TError = HTTPValidationError,
|
||||
TContext = unknown,
|
||||
>(
|
||||
options?: {
|
||||
mutation?: UseMutationOptions<
|
||||
Awaited<ReturnType<typeof postV1StopGraphExecutions>>,
|
||||
TError,
|
||||
{ params: PostV1StopGraphExecutionsParams },
|
||||
TContext
|
||||
>;
|
||||
request?: SecondParameter<typeof customMutator>;
|
||||
},
|
||||
queryClient?: QueryClient,
|
||||
): UseMutationResult<
|
||||
Awaited<ReturnType<typeof postV1StopGraphExecutions>>,
|
||||
TError,
|
||||
{ params: PostV1StopGraphExecutionsParams },
|
||||
TContext
|
||||
> => {
|
||||
const mutationOptions = getPostV1StopGraphExecutionsMutationOptions(options);
|
||||
|
||||
return useMutation(mutationOptions, queryClient);
|
||||
};
|
||||
/**
|
||||
* @summary Get all executions
|
||||
*/
|
||||
|
||||
12
autogpt_platform/frontend/src/app/api/__generated__/models/postV1StopGraphExecutionsParams.ts
generated
Normal file
12
autogpt_platform/frontend/src/app/api/__generated__/models/postV1StopGraphExecutionsParams.ts
generated
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Generated by orval v7.10.0 🍺
|
||||
* Do not edit manually.
|
||||
* AutoGPT Agent Server
|
||||
* This server is used to execute agents that are created by the AutoGPT system.
|
||||
* OpenAPI spec version: 0.1
|
||||
*/
|
||||
|
||||
export type PostV1StopGraphExecutionsParams = {
|
||||
graph_id: string;
|
||||
graph_exec_id: string;
|
||||
};
|
||||
@@ -1480,7 +1480,7 @@
|
||||
"description": "Successful Response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": { "$ref": "#/components/schemas/GraphExecution" }
|
||||
"schema": { "$ref": "#/components/schemas/GraphExecutionMeta" }
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1496,6 +1496,49 @@
|
||||
}
|
||||
},
|
||||
"/api/executions": {
|
||||
"post": {
|
||||
"tags": ["v1", "graphs"],
|
||||
"summary": "Stop graph executions",
|
||||
"operationId": "postV1Stop graph executions",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "graph_id",
|
||||
"in": "query",
|
||||
"required": true,
|
||||
"schema": { "type": "string", "title": "Graph Id" }
|
||||
},
|
||||
{
|
||||
"name": "graph_exec_id",
|
||||
"in": "query",
|
||||
"required": true,
|
||||
"schema": { "type": "string", "title": "Graph Exec Id" }
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful Response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/GraphExecutionMeta"
|
||||
},
|
||||
"title": "Response Postv1Stop Graph Executions"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"422": {
|
||||
"description": "Validation Error",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": { "$ref": "#/components/schemas/HTTPValidationError" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"get": {
|
||||
"tags": ["v1", "graphs"],
|
||||
"summary": "Get all executions",
|
||||
@@ -1506,10 +1549,10 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/GraphExecutionMeta"
|
||||
},
|
||||
"type": "array",
|
||||
"title": "Response Getv1Get All Executions"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user