Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions apps/docs/content/docs/integrations/buffer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ Create a post in Buffer for a channel — add it to the queue, share it immediat
| ↳ `videoBitRate` | number | VideoMetadata videoBitRate |
| ↳ `videoCodec` | string | VideoMetadata videoCodec |
| ↳ `width` | number | VideoMetadata width |
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment |
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment \(removed by Buffer, always null\) |
| ↳ `expandedUrl` | string | LinkAttachment expandedUrl |
| ↳ `text` | string | LinkAttachment text |
| ↳ `thumbnail` | string | LinkAttachment thumbnail |
Expand Down Expand Up @@ -601,7 +601,7 @@ Edit an existing Buffer post — update its text, schedule, or media. Attaching
| ↳ `videoBitRate` | number | VideoMetadata videoBitRate |
| ↳ `videoCodec` | string | VideoMetadata videoCodec |
| ↳ `width` | number | VideoMetadata width |
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment |
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment \(removed by Buffer, always null\) |
| ↳ `expandedUrl` | string | LinkAttachment expandedUrl |
| ↳ `text` | string | LinkAttachment text |
| ↳ `thumbnail` | string | LinkAttachment thumbnail |
Expand Down Expand Up @@ -924,7 +924,7 @@ List posts in a Buffer organization, optionally filtered by channel and status (
| ↳ `videoBitRate` | number | VideoMetadata videoBitRate |
| ↳ `videoCodec` | string | VideoMetadata videoCodec |
| ↳ `width` | number | VideoMetadata width |
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment |
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment \(removed by Buffer, always null\) |
| ↳ `expandedUrl` | string | LinkAttachment expandedUrl |
| ↳ `text` | string | LinkAttachment text |
| ↳ `thumbnail` | string | LinkAttachment thumbnail |
Expand Down Expand Up @@ -1222,7 +1222,7 @@ List posts in a Buffer organization, optionally filtered by channel and status (
| ↳ `videoBitRate` | number | VideoMetadata videoBitRate |
| ↳ `videoCodec` | string | VideoMetadata videoCodec |
| ↳ `width` | number | VideoMetadata width |
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment |
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment \(removed by Buffer, always null\) |
| ↳ `expandedUrl` | string | LinkAttachment expandedUrl |
| ↳ `text` | string | LinkAttachment text |
| ↳ `thumbnail` | string | LinkAttachment thumbnail |
Expand Down Expand Up @@ -1542,7 +1542,7 @@ Get a single Buffer post by ID, including its status, schedule, and media
| ↳ `videoBitRate` | number | VideoMetadata videoBitRate |
| ↳ `videoCodec` | string | VideoMetadata videoCodec |
| ↳ `width` | number | VideoMetadata width |
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment |
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment \(removed by Buffer, always null\) |
| ↳ `expandedUrl` | string | LinkAttachment expandedUrl |
| ↳ `text` | string | LinkAttachment text |
| ↳ `thumbnail` | string | LinkAttachment thumbnail |
Expand Down
9 changes: 4 additions & 5 deletions apps/sim/blocks/blocks/spotify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ export const SpotifyBlock: BlockConfig = {
spotify_follow_playlist: [{ text: 'Follow playlist', field: 'playlistId', core: true }],
spotify_unfollow_playlist: [{ text: 'Unfollow playlist', field: 'playlistId', core: true }],
spotify_check_playlist_followers: [
{ text: 'Check whether', field: 'userIds', core: true },
{ text: 'follow playlist', field: 'playlistId', core: true },
{ text: 'Check whether you follow playlist', field: 'playlistId', core: true },
],
spotify_get_current_user: ['Read the current user profile'],
spotify_get_user_profile: [
Expand Down Expand Up @@ -703,8 +702,8 @@ export const SpotifyBlock: BlockConfig = {
id: 'userIds',
title: 'User IDs',
type: 'short-input',
placeholder: 'Comma-separated user IDs to check (max 5)',
required: true,
placeholder: 'Not used: Spotify checks the current user',
mode: 'advanced',
condition: { field: 'operation', value: 'spotify_check_playlist_followers' },
},

Expand Down Expand Up @@ -895,7 +894,7 @@ export const SpotifyBlock: BlockConfig = {
id: 'limit',
title: 'Limit',
type: 'short-input',
placeholder: 'Number of results (1-50, default: 20)',
placeholder: 'Number of results (leave empty for the default)',
condition: {
field: 'operation',
value: [
Expand Down
5 changes: 0 additions & 5 deletions apps/sim/lib/internal/buffer/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,6 @@ describe('Buffer operations', () => {
error: 'Post.isCustomScheduled must be a boolean',
},
{ corruption: { allowedActions: [42] }, error: 'Post.allowedActions[] must be a string' },
{ corruption: { status: 'invalid-status' }, error: 'Post.status must be one of' },
{
corruption: { allowedActions: ['invalid-action'] },
error: 'Post.allowedActions[] must be one of',
},
{
corruption: {
channel: {
Expand Down
33 changes: 33 additions & 0 deletions apps/sim/tools/buffer/schema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, expect, it } from 'vitest'
import post from '@/tools/buffer/__fixtures__/post.json'
import { bufferSelection, projectBufferObject } from '@/tools/buffer/schema'

/** The field names a GraphQL selection set picks at its own level, without nested selections. */
function topLevelFields(selection: string): string[] {
let depth = 0
let flat = ''
for (const char of selection) {
if (char === '{') depth++
else if (char === '}') depth--
else if (depth === 0) flat += char
}
return flat.split(/\s+/).filter(Boolean)
}

describe('Buffer response schema', () => {
it('keeps a channel whose allowedActions include a value added by Buffer after this schema', () => {
const channel = projectBufferObject('Channel', {
...post.channel,
allowedActions: ['shuffleQueue', 'emptyQueue', 'someFutureAction'],
})

expect(channel.allowedActions).toEqual(['shuffleQueue', 'emptyQueue', 'someFutureAction'])
})

it('never selects ThreadedPost.linkAttachment, which Buffer removes on 2026-12-15', () => {
const fields = topLevelFields(bufferSelection('ThreadedPost'))

expect(fields).toEqual(expect.arrayContaining(['assets', 'metadata', 'text']))
expect(fields).not.toContain('linkAttachment')
})
})
39 changes: 33 additions & 6 deletions apps/sim/tools/buffer/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import type { OutputProperty } from '@/tools/types'

interface BufferSchemaType {
fields?: Record<string, string>
/**
* Fields Buffer has removed or is removing from the API. They stay in the outputs (always null)
* so saved references keep resolving, but are never selected, since querying a removed field
* fails the whole GraphQL request.
*/
retired?: string[]
members?: string[]
values?: string[]
defaults?: string[]
Expand Down Expand Up @@ -48,6 +54,7 @@ export function bufferSelection(type: string): string {
return `__typename ${schema.members.map((member) => `... on ${member} { ${bufferSelection(member)} }`).join(' ')}`
}
return Object.entries(schema.fields ?? {})
.filter(([field]) => !schema.retired?.includes(field))
.map(([field, wireType]) => {
const selection = bufferSelection(baseType(wireType))
return selection ? `${field} { ${selection} }` : field
Expand Down Expand Up @@ -77,7 +84,9 @@ export function bufferOutputProperties(type: string): Record<string, OutputPrope
const object = Boolean(nested?.fields || nested?.members)
const property: OutputProperty = {
type: object ? 'object' : scalarType(nestedType),
description: `${type} ${field}`,
description: schema.retired?.includes(field)
? `${type} ${field} (removed by Buffer, always null)`
: `${type} ${field}`,
...(object ? { properties: bufferOutputProperties(nestedType) } : {}),
}
properties[field] = wireType.startsWith('[')
Expand Down Expand Up @@ -133,12 +142,12 @@ export function projectBufferObject(type: string, value: unknown): unknown {
}
return object
? projectBufferObject(nestedType, entry)
: parseValue(nestedType, entry, `Buffer response ${type}.${field}[]`)
: parseValue(nestedType, entry, `Buffer response ${type}.${field}[]`, 'output')
})
} else {
result[field] = object
? projectBufferObject(nestedType, candidate)
: parseValue(nestedType, candidate, `Buffer response ${type}.${field}`)
: parseValue(nestedType, candidate, `Buffer response ${type}.${field}`, 'output')
}
}
return result
Expand Down Expand Up @@ -202,7 +211,16 @@ export function bufferInputDescription(type: string, description: string): strin
: description
}

function parseValue(wireType: string, value: unknown, path: string): unknown {
/**
* Validates one wire value. Enum membership is enforced only on inputs: Buffer adds enum values
* to responses without notice (GraphQL clients must tolerate them), so an output keeps any string.
*/
function parseValue(
wireType: string,
value: unknown,
path: string,
direction: 'input' | 'output' = 'input'
): unknown {
if (value == null) {
if (wireType.endsWith('!')) throw new Error(`${path} is required`)
return null
Expand All @@ -211,12 +229,14 @@ function parseValue(wireType: string, value: unknown, path: string): unknown {
if (type.startsWith('[')) {
if (!Array.isArray(value)) throw new Error(`${path} must be an array`)
if (value.length > 1000) throw new Error(`${path} exceeds the integration limit of 1000 items`)
return value.map((entry, index) => parseValue(type.slice(1, -1), entry, `${path}[${index}]`))
return value.map((entry, index) =>
parseValue(type.slice(1, -1), entry, `${path}[${index}]`, direction)
)
}
const schema = BUFFER_SCHEMA[type]
if (schema?.fields) return parseBufferInput(type, value, path)
if (typeof value !== scalarType(type)) throw new Error(`${path} must be a ${scalarType(type)}`)
if (schema?.values && !schema.values.includes(String(value)))
if (direction === 'input' && schema?.values && !schema.values.includes(String(value)))
throw new Error(`${path} must be one of ${schema.values.join(', ')}`)
if (type === 'Int' && !Number.isInteger(value)) throw new Error(`${path} must be an integer`)
if ((type === 'Int' || type === 'Float') && !Number.isFinite(value))
Expand Down Expand Up @@ -385,8 +405,13 @@ const BUFFER_SCHEMA: Record<string, BufferSchemaType> = {
},
ChannelAction: {
values: [
'approvePosts',
'backfillChannel',
'cleanQueue',
'deleteDrafts',
'emptyQueue',
'exportInsights',
'interactWithTakeaways',
'manageCapabilities',
'manageChannelSettings',
'manageComments',
Expand All @@ -399,6 +424,7 @@ const BUFFER_SCHEMA: Record<string, BufferSchemaType> = {
'reconnectChannel',
'removeChannel',
'scheduleUpdates',
'shuffleQueue',
'viewCapabilities',
'viewChannel',
'viewComments',
Expand Down Expand Up @@ -1415,6 +1441,7 @@ const BUFFER_SCHEMA: Record<string, BufferSchemaType> = {
metadata: 'ThreadItemMetadata',
text: 'String!',
},
retired: ['linkAttachment'],
},
ThreadedPostInput: {
fields: {
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/tools/generated/tool-metadata.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/sim/tools/generated/tool-outputs.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/sim/tools/spotify/add_tracks_to_playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const spotifyAddTracksToPlaylistTool: ToolConfig<
},

request: {
url: (params) => `https://api.spotify.com/v1/playlists/${params.playlistId}/tracks`,
url: (params) => `https://api.spotify.com/v1/playlists/${params.playlistId}/items`,
method: 'POST',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
Expand Down
39 changes: 29 additions & 10 deletions apps/sim/tools/spotify/check_following.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { sendRemainingSpotifyLibraryChunks, spotifyLibraryUrl } from '@/tools/spotify/utils'
import type { ToolConfig, ToolResponse } from '@/tools/types'

interface SpotifyCheckFollowingParams {
Expand All @@ -10,6 +11,15 @@ interface SpotifyCheckFollowingResponse extends ToolResponse {
output: { results: boolean[] }
}

/** The library URI type for `type`, rejecting anything other than `artist` or `user`. */
function followType(type: string): 'artist' | 'user' {
const normalized = String(type ?? '')
.trim()
.toLowerCase()
if (normalized === 'artist' || normalized === 'user') return normalized
throw new Error('Type must be "artist" or "user"')
}

export const spotifyCheckFollowingTool: ToolConfig<
SpotifyCheckFollowingParams,
SpotifyCheckFollowingResponse
Expand Down Expand Up @@ -41,22 +51,31 @@ export const spotifyCheckFollowingTool: ToolConfig<
},

request: {
url: (params) => {
const ids = params.ids
.split(',')
.map((id) => id.trim())
.slice(0, 50)
.join(',')
return `https://api.spotify.com/v1/me/following/contains?type=${params.type}&ids=${ids}`
},
url: (params) =>
spotifyLibraryUrl(params.ids, followType(params.type), {
contains: true,
maxIds: 50,
}),
method: 'GET',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
}),
},

transformResponse: async (response): Promise<SpotifyCheckFollowingResponse> => {
const results = await response.json()
transformResponse: async (response, params, context): Promise<SpotifyCheckFollowingResponse> => {
const results: boolean[] = [
...(await response.json()),
...(params
? await sendRemainingSpotifyLibraryChunks(
params,
params.ids,
followType(params.type),
'GET',
{ contains: true, maxIds: 50 },
context?.signal
)
: []),
]
return { success: true, output: { results } }
},

Expand Down
22 changes: 10 additions & 12 deletions apps/sim/tools/spotify/check_playlist_followers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { spotifyLibraryUrl } from '@/tools/spotify/utils'
import type { ToolConfig, ToolResponse } from '@/tools/types'

interface SpotifyCheckPlaylistFollowersParams {
Expand All @@ -16,7 +17,7 @@ export const spotifyCheckPlaylistFollowersTool: ToolConfig<
> = {
id: 'spotify_check_playlist_followers',
name: 'Spotify Check Playlist Followers',
description: 'Check if users follow a playlist.',
description: 'Check if the current user follows a playlist.',
version: '1.0.0',

oauth: {
Expand All @@ -34,21 +35,15 @@ export const spotifyCheckPlaylistFollowersTool: ToolConfig<
},
userIds: {
type: 'string',
required: true,
required: false,
visibility: 'user-or-llm',
description: 'Comma-separated user IDs to check (max 5)',
description:
'Not used: Spotify only checks whether the current user follows the playlist, whatever IDs are given',
},
},

request: {
url: (params) => {
const ids = params.userIds
.split(',')
.map((id) => id.trim())
.slice(0, 5)
.join(',')
return `https://api.spotify.com/v1/playlists/${params.playlistId}/followers/contains?ids=${ids}`
},
url: (params) => spotifyLibraryUrl(params.playlistId, 'playlist', { contains: true }),
method: 'GET',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
Expand All @@ -61,6 +56,9 @@ export const spotifyCheckPlaylistFollowersTool: ToolConfig<
},

outputs: {
results: { type: 'json', description: 'Array of booleans for each user' },
results: {
type: 'json',
description: 'Array with one boolean: whether the current user follows the playlist',
},
},
}
Loading
Loading