Files
simstudioai--sim/apps/sim/tools/cloudflare/update_zone_setting.ts
T
wehub-resource-sync d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (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 / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

145 lines
5.0 KiB
TypeScript

import type {
CloudflareUpdateZoneSettingParams,
CloudflareUpdateZoneSettingResponse,
} from '@/tools/cloudflare/types'
import type { ToolConfig } from '@/tools/types'
export const updateZoneSettingTool: ToolConfig<
CloudflareUpdateZoneSettingParams,
CloudflareUpdateZoneSettingResponse
> = {
id: 'cloudflare_update_zone_setting',
name: 'Cloudflare Update Zone Setting',
description:
'Updates a specific zone setting such as SSL mode, security level, cache level, or other configuration.',
version: '1.0.0',
params: {
zoneId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'The zone ID to update settings for',
},
settingId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description:
'Setting to update (e.g., "ssl", "security_level", "cache_level", "always_use_https", "browser_cache_ttl", "http3", "min_tls_version", "ciphers")',
},
value: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description:
'New value for the setting as a string or JSON string for complex values (e.g., "full" for SSL, "medium" for security_level, "aggressive" for cache_level, \'["ECDHE-RSA-AES128-GCM-SHA256"]\' for ciphers)',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Cloudflare API Token',
},
},
request: {
url: (params) =>
`https://api.cloudflare.com/client/v4/zones/${params.zoneId}/settings/${params.settingId}`,
method: 'PATCH',
headers: (params) => ({
Authorization: `Bearer ${params.apiKey}`,
'Content-Type': 'application/json',
}),
body: (params) => {
// A block reference can pass an already-structured array/object straight
// through despite the declared string param type — send it as-is rather
// than stringifying it (String([...]) comma-joins, String({...}) yields
// "[object Object]", neither of which is the JSON shape Cloudflare expects).
if (params.value !== null && typeof params.value === 'object') {
return { value: params.value }
}
// Wand-generated values can also arrive as a non-string primitive
// (e.g. a number, or null/undefined) at runtime despite the declared
// param type — coerce null/undefined to '' rather than the literal
// "null"/"undefined" strings String() would otherwise produce.
const trimmed = (params.value == null ? '' : String(params.value)).trim()
// browser_cache_ttl is the one setting whose value must be a number.
// Number('') is 0, not NaN, so an empty value must be rejected explicitly.
if (params.settingId === 'browser_cache_ttl') {
const numeric = trimmed === '' ? Number.NaN : Number(trimmed)
return { value: Number.isNaN(numeric) ? trimmed : numeric }
}
// Only parse JSON object/array literals (e.g. ciphers). Scalar settings like
// min_tls_version ("1.2") or tls_1_3 ("on") must stay strings — a blind JSON.parse would
// silently coerce them to numbers/booleans and the Cloudflare API would reject the type.
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
try {
return { value: JSON.parse(trimmed) }
} catch {
return { value: trimmed }
}
}
return { value: trimmed }
},
},
transformResponse: async (response: Response) => {
const data = await response.json()
if (!data.success) {
return {
success: false,
output: { id: '', value: '', editable: false, modified_on: '' },
error: data.errors?.[0]?.message ?? 'Failed to update zone setting',
}
}
const setting = data.result
return {
success: true,
output: {
id: setting?.id ?? '',
value:
typeof setting?.value === 'object' && setting?.value !== null
? JSON.stringify(setting.value)
: String(setting?.value ?? ''),
editable: setting?.editable ?? false,
modified_on: setting?.modified_on ?? '',
...(setting?.time_remaining != null
? { time_remaining: setting.time_remaining as number }
: {}),
},
}
},
outputs: {
id: {
type: 'string',
description: 'Setting identifier (e.g., ssl, cache_level, security_level)',
},
value: {
type: 'string',
description:
'Updated setting value as a string. Simple values returned as-is (e.g., "full", "on"). Complex values are JSON-stringified.',
},
editable: {
type: 'boolean',
description: 'Whether the setting can be modified for the current zone plan',
},
modified_on: {
type: 'string',
description: 'ISO 8601 timestamp when the setting was last modified',
},
time_remaining: {
type: 'number',
description:
'Seconds remaining until the setting can be modified again (only present for rate-limited settings)',
optional: true,
},
},
}