Files
simstudioai--sim/apps/sim/tools/youtube/channel_info.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

162 lines
4.5 KiB
TypeScript

import type { ToolConfig } from '@/tools/types'
import type { YouTubeChannelInfoParams, YouTubeChannelInfoResponse } from '@/tools/youtube/types'
export const youtubeChannelInfoTool: ToolConfig<
YouTubeChannelInfoParams,
YouTubeChannelInfoResponse
> = {
id: 'youtube_channel_info',
name: 'YouTube Channel Info',
description:
'Get detailed information about a YouTube channel including statistics, branding, and content details.',
version: '1.1.0',
params: {
channelId: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description:
'YouTube channel ID starting with "UC" (24-character string, use either channelId or username)',
},
username: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'YouTube channel username (use either channelId or username)',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'YouTube API Key',
},
},
request: {
url: (params: YouTubeChannelInfoParams) => {
let url =
'https://www.googleapis.com/youtube/v3/channels?part=snippet,statistics,contentDetails,brandingSettings'
if (params.channelId) {
url += `&id=${encodeURIComponent(params.channelId)}`
} else if (params.username) {
url += `&forUsername=${encodeURIComponent(params.username)}`
}
url += `&key=${params.apiKey}`
return url
},
method: 'GET',
headers: () => ({
'Content-Type': 'application/json',
}),
},
transformResponse: async (response: Response): Promise<YouTubeChannelInfoResponse> => {
const data = await response.json()
if (!data.items || data.items.length === 0) {
return {
success: false,
output: {
channelId: '',
title: '',
description: '',
subscriberCount: 0,
videoCount: 0,
viewCount: 0,
publishedAt: '',
thumbnail: '',
customUrl: null,
country: null,
uploadsPlaylistId: null,
bannerImageUrl: null,
hiddenSubscriberCount: false,
},
error: 'Channel not found',
}
}
const item = data.items[0]
return {
success: true,
output: {
channelId: item.id ?? '',
title: item.snippet?.title ?? '',
description: item.snippet?.description ?? '',
subscriberCount: Number(item.statistics?.subscriberCount || 0),
videoCount: Number(item.statistics?.videoCount || 0),
viewCount: Number(item.statistics?.viewCount || 0),
publishedAt: item.snippet?.publishedAt ?? '',
thumbnail:
item.snippet?.thumbnails?.high?.url ||
item.snippet?.thumbnails?.medium?.url ||
item.snippet?.thumbnails?.default?.url ||
'',
customUrl: item.snippet?.customUrl ?? null,
country: item.snippet?.country ?? null,
uploadsPlaylistId: item.contentDetails?.relatedPlaylists?.uploads ?? null,
bannerImageUrl: item.brandingSettings?.image?.bannerExternalUrl ?? null,
hiddenSubscriberCount: item.statistics?.hiddenSubscriberCount ?? false,
},
}
},
outputs: {
channelId: {
type: 'string',
description: 'YouTube channel ID',
},
title: {
type: 'string',
description: 'Channel name',
},
description: {
type: 'string',
description: 'Channel description',
},
subscriberCount: {
type: 'number',
description: 'Number of subscribers (0 if hidden)',
},
videoCount: {
type: 'number',
description: 'Number of public videos',
},
viewCount: {
type: 'number',
description: 'Total channel views',
},
publishedAt: {
type: 'string',
description: 'Channel creation date',
},
thumbnail: {
type: 'string',
description: 'Channel thumbnail/avatar URL',
},
customUrl: {
type: 'string',
description: 'Channel custom URL (handle)',
optional: true,
},
country: {
type: 'string',
description: 'Country the channel is associated with',
optional: true,
},
uploadsPlaylistId: {
type: 'string',
description: 'Playlist ID containing all channel uploads (use with playlist_items)',
optional: true,
},
bannerImageUrl: {
type: 'string',
description: 'Channel banner image URL',
optional: true,
},
hiddenSubscriberCount: {
type: 'boolean',
description: 'Whether the subscriber count is hidden',
},
},
}