Files
simstudioai--sim/apps/sim/tools/wordpress/search_content.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

136 lines
3.8 KiB
TypeScript

import type { ToolConfig } from '@/tools/types'
import {
WORDPRESS_COM_API_BASE,
type WordPressSearchContentParams,
type WordPressSearchContentResponse,
} from '@/tools/wordpress/types'
export const searchContentTool: ToolConfig<
WordPressSearchContentParams,
WordPressSearchContentResponse
> = {
id: 'wordpress_search_content',
name: 'WordPress Search Content',
description: 'Search across all content types in WordPress.com (posts, pages, media)',
version: '1.0.0',
oauth: {
required: true,
provider: 'wordpress',
requiredScopes: ['global'],
},
params: {
siteId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'WordPress.com site ID or domain (e.g., 12345678 or mysite.wordpress.com)',
},
query: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Search query',
},
perPage: {
type: 'number',
required: false,
visibility: 'user-or-llm',
description: 'Number of results per request (default: 10, max: 100)',
},
page: {
type: 'number',
required: false,
visibility: 'user-or-llm',
description: 'Page number for pagination',
},
type: {
type: 'string',
required: false,
visibility: 'user-only',
description: 'Filter by search index type: post, term, or post-format',
},
subtype: {
type: 'string',
required: false,
visibility: 'user-only',
description:
'Filter by subtype within the selected type (e.g., post or page when type is post)',
},
},
request: {
url: (params) => {
const queryParams = new URLSearchParams()
queryParams.append('search', params.query)
if (params.perPage) queryParams.append('per_page', String(params.perPage))
if (params.page) queryParams.append('page', String(params.page))
if (params.type) queryParams.append('type', params.type)
if (params.subtype) queryParams.append('subtype', params.subtype)
return `${WORDPRESS_COM_API_BASE}/${params.siteId}/search?${queryParams.toString()}`
},
method: 'GET',
headers: (params) => ({
'Content-Type': 'application/json',
Authorization: `Bearer ${params.accessToken}`,
}),
},
transformResponse: async (response: Response) => {
if (!response.ok) {
const error = await response.json().catch(() => ({}))
throw new Error(error.message || `WordPress API error: ${response.status}`)
}
const data = await response.json()
const total = Number.parseInt(response.headers.get('X-WP-Total') || '0', 10)
const totalPages = Number.parseInt(response.headers.get('X-WP-TotalPages') || '0', 10)
return {
success: true,
output: {
results: data.map((result: any) => ({
id: result.id,
title: result.title,
url: result.url,
type: result.type,
subtype: result.subtype,
})),
total,
totalPages,
},
}
},
outputs: {
results: {
type: 'array',
description: 'Search results',
items: {
type: 'object',
properties: {
id: { type: 'number', description: 'Content ID' },
title: { type: 'string', description: 'Content title' },
url: { type: 'string', description: 'Content URL' },
type: { type: 'string', description: 'Content type (post, term, or post-format)' },
subtype: {
type: 'string',
description: 'Subtype within the content type (e.g., post, page)',
},
},
},
},
total: {
type: 'number',
description: 'Total number of results',
},
totalPages: {
type: 'number',
description: 'Total number of result pages',
},
},
}