6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
131 lines
3.4 KiB
TypeScript
131 lines
3.4 KiB
TypeScript
import { hmacSha256Hex } from '@sim/security/hmac'
|
|
import { generateId } from '@sim/utils/id'
|
|
import type { RequestResponse, WebhookRequestParams } from '@/tools/http/types'
|
|
import type { ToolConfig } from '@/tools/types'
|
|
|
|
/**
|
|
* Generates HMAC-SHA256 signature for webhook payload
|
|
*/
|
|
function generateSignature(secret: string, timestamp: number, body: string): string {
|
|
const signatureBase = `${timestamp}.${body}`
|
|
return hmacSha256Hex(signatureBase, secret)
|
|
}
|
|
|
|
export const webhookRequestTool: ToolConfig<WebhookRequestParams, RequestResponse> = {
|
|
id: 'webhook_request',
|
|
name: 'Webhook Request',
|
|
description: 'Send a webhook request with automatic headers and optional HMAC signing',
|
|
version: '1.0.0',
|
|
|
|
params: {
|
|
url: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-or-llm',
|
|
description: 'The webhook URL to send the request to',
|
|
},
|
|
body: {
|
|
type: 'object',
|
|
visibility: 'user-or-llm',
|
|
description: 'JSON payload to send',
|
|
},
|
|
secret: {
|
|
type: 'string',
|
|
visibility: 'user-or-llm',
|
|
description: 'Optional secret for HMAC-SHA256 signature',
|
|
},
|
|
headers: {
|
|
type: 'object',
|
|
visibility: 'user-or-llm',
|
|
description: 'Additional headers to include',
|
|
},
|
|
},
|
|
|
|
request: {
|
|
url: (params: WebhookRequestParams) => params.url,
|
|
|
|
method: () => 'POST',
|
|
|
|
headers: (params: WebhookRequestParams) => {
|
|
const timestamp = Date.now()
|
|
const deliveryId = generateId()
|
|
|
|
const webhookHeaders: Record<string, string> = {
|
|
'Content-Type': 'application/json',
|
|
'X-Webhook-Timestamp': timestamp.toString(),
|
|
'X-Delivery-ID': deliveryId,
|
|
'Idempotency-Key': deliveryId,
|
|
}
|
|
|
|
if (params.secret) {
|
|
const bodyString =
|
|
typeof params.body === 'string' ? params.body : JSON.stringify(params.body || {})
|
|
const signature = generateSignature(params.secret, timestamp, bodyString)
|
|
webhookHeaders['X-Webhook-Signature'] = `t=${timestamp},v1=${signature}`
|
|
}
|
|
|
|
const userHeaders = params.headers || {}
|
|
|
|
return { ...webhookHeaders, ...userHeaders }
|
|
},
|
|
|
|
body: (params: WebhookRequestParams) => params.body as Record<string, any>,
|
|
},
|
|
|
|
transformResponse: async (response: Response) => {
|
|
const contentType = response.headers.get('content-type') || ''
|
|
|
|
const headers: Record<string, string> = {}
|
|
response.headers.forEach((value, key) => {
|
|
headers[key] = value
|
|
})
|
|
|
|
const data = await (contentType.includes('application/json')
|
|
? response.json()
|
|
: response.text())
|
|
|
|
if (
|
|
contentType.includes('application/json') &&
|
|
typeof data === 'object' &&
|
|
data !== null &&
|
|
data.data !== undefined &&
|
|
data.status !== undefined
|
|
) {
|
|
return {
|
|
success: data.success,
|
|
output: {
|
|
data: data.data,
|
|
status: data.status,
|
|
headers: data.headers || {},
|
|
},
|
|
error: data.success ? undefined : data.error,
|
|
}
|
|
}
|
|
|
|
return {
|
|
success: response.ok,
|
|
output: {
|
|
data,
|
|
status: response.status,
|
|
headers,
|
|
},
|
|
error: undefined,
|
|
}
|
|
},
|
|
|
|
outputs: {
|
|
data: {
|
|
type: 'json',
|
|
description: 'Response data from the webhook endpoint',
|
|
},
|
|
status: {
|
|
type: 'number',
|
|
description: 'HTTP status code',
|
|
},
|
|
headers: {
|
|
type: 'object',
|
|
description: 'Response headers',
|
|
},
|
|
},
|
|
}
|