Skip to content

Commit 4f1beca

Browse files
authored
fix(integrations): validate hugging face, elevenlabs, gamma, higgsfield and dspy (#10174)
* fix(integrations): validate hugging face, elevenlabs, gamma, higgsfield and dspy * fix(integrations): validate dspy additional inputs only for predict and reject multiple gamma folders * fix(integrations): send gamma's folder as folderId instead of the deprecated folderIds * chore(integrations): regenerate artifacts after rebase
1 parent 48594d4 commit 4f1beca

25 files changed

Lines changed: 303 additions & 81 deletions

‎apps/docs/content/docs/integrations/gamma.mdx‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ Generate a new Gamma presentation, document, webpage, or social post from text i
3737
| `cardSplit` | string | No | How to split content into cards: auto or inputTextBreaks \(default: auto\) |
3838
| `cardDimensions` | string | No | Card aspect ratio. Presentation: fluid, 16x9, 4x3. Document: fluid, pageless, letter, a4. Social: 1x1, 4x5, 9x16 |
3939
| `additionalInstructions` | string | No | Additional instructions for the AI generation \(max 2000 chars\) |
40-
| `exportAs` | string | No | Automatically export the generated gamma as pdf or pptx |
41-
| `folderIds` | string | No | Comma-separated folder IDs to store the generated gamma in |
40+
| `exportAs` | string | No | Automatically export the generated gamma as pdf, pptx, or png \(a zip of one PNG per card\). Check Status returns the download URL |
41+
| `folderIds` | string | No | ID of the folder to store the generated gamma in \(Gamma accepts one folder\) |
4242
| `textAmount` | string | No | Amount of text per card: brief, medium, detailed, or extensive |
4343
| `textTone` | string | No | Tone of the generated text, e.g. "professional", "casual" \(max 500 chars\) |
4444
| `textAudience` | string | No | Target audience for the generated text, e.g. "executives", "students" \(max 500 chars\) |
4545
| `textLanguage` | string | No | Language code for the generated text \(default: en\) |
46-
| `imageSource` | string | No | Where to source images: aiGenerated, pictographic, unsplash, webAllImages, webFreeToUse, webFreeToUseCommercially, giphy, placeholder, or noImages |
46+
| `imageSource` | string | No | Where to source images: aiGenerated, pictographic, pexels, webAllImages, webFreeToUse, webFreeToUseCommercially, giphy, themeAccent, placeholder, or noImages |
4747
| `imageModel` | string | No | AI image generation model to use when imageSource is aiGenerated |
4848
| `imageStyle` | string | No | Style directive for AI-generated images, e.g. "watercolor", "photorealistic" \(max 500 chars\) |
4949

@@ -52,6 +52,7 @@ Generate a new Gamma presentation, document, webpage, or social post from text i
5252
| Parameter | Type | Description |
5353
| --------- | ---- | ----------- |
5454
| `generationId` | string | The ID of the generation job. Use with Check Status to poll for completion. |
55+
| `warnings` | string | Warnings about request options that Gamma ignored |
5556

5657
</ReferenceDetails>
5758

@@ -68,8 +69,8 @@ Generate a new Gamma by adapting an existing template with a prompt.
6869
| `gammaId` | string | Yes | The ID of the template gamma to adapt |
6970
| `prompt` | string | Yes | Instructions for how to adapt the template \(1-100,000 tokens\) |
7071
| `themeId` | string | No | Custom Gamma workspace theme ID to apply |
71-
| `exportAs` | string | No | Automatically export the generated gamma as pdf or pptx |
72-
| `folderIds` | string | No | Comma-separated folder IDs to store the generated gamma in |
72+
| `exportAs` | string | No | Automatically export the generated gamma as pdf, pptx, or png \(a zip of one PNG per card\). Check Status returns the download URL |
73+
| `folderIds` | string | No | ID of the folder to store the generated gamma in \(Gamma accepts one folder\) |
7374
| `imageModel` | string | No | AI image generation model to use when imageSource is aiGenerated |
7475
| `imageStyle` | string | No | Style directive for AI-generated images, e.g. "watercolor", "photorealistic" \(max 500 chars\) |
7576

@@ -78,6 +79,7 @@ Generate a new Gamma by adapting an existing template with a prompt.
7879
| Parameter | Type | Description |
7980
| --------- | ---- | ----------- |
8081
| `generationId` | string | The ID of the generation job. Use with Check Status to poll for completion. |
82+
| `warnings` | string | Warnings about request options that Gamma ignored |
8183

8284
</ReferenceDetails>
8385

@@ -100,6 +102,8 @@ Check the status of a Gamma generation job. Returns the gamma URL when completed
100102
| `generationId` | string | The generation ID that was checked |
101103
| `status` | string | Generation status: pending, completed, or failed |
102104
| `gammaUrl` | string | URL of the generated gamma \(only present when status is completed\) |
105+
| `gammaId` | string | ID of the generated gamma \(only present when status is completed\) |
106+
| `exportUrl` | string | Download URL of the exported file when Export As was set \(pdf, pptx, or a zip of PNGs\). Anyone with the link can download it until it expires, about a week later |
103107
| `credits` | object | Credit usage information \(only present when status is completed\) |
104108
| ↳ `deducted` | number | Number of credits deducted for this generation |
105109
| ↳ `remaining` | number | Remaining credits in the account |
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { DSPyBlock } from '@/blocks/blocks/dspy'
3+
4+
function mapParams(params: Record<string, unknown>) {
5+
const mapper = DSPyBlock.tools.config?.params
6+
if (!mapper) throw new Error('DSPy block has no params mapper')
7+
return mapper({ operation: 'predict', baseUrl: 'https://dspy.example.com', ...params })
8+
}
9+
10+
describe('DSPy block params', () => {
11+
it('keeps Additional Inputs that an agent passes as an object', () => {
12+
expect(mapParams({ additionalInputs: { topic: 'billing' } }).additionalInputs).toEqual({
13+
topic: 'billing',
14+
})
15+
})
16+
17+
it('fails on Additional Inputs that are not valid JSON instead of dropping them', () => {
18+
expect(() => mapParams({ additionalInputs: '{"topic": ' })).toThrow(
19+
'Additional Inputs must be valid JSON'
20+
)
21+
})
22+
23+
it('fails on Additional Inputs that an agent passes as an array instead of dropping them', () => {
24+
expect(() =>
25+
DSPyBlock.tools.config?.params?.(
26+
{ baseUrl: 'https://dspy.example.com', additionalInputs: ['billing'] },
27+
{ operation: 'predict' }
28+
)
29+
).toThrow()
30+
})
31+
32+
it('ignores stale Additional Inputs on operations that do not send them', () => {
33+
expect(
34+
mapParams({ operation: 'react', additionalInputs: '{"topic": ' }).additionalInputs
35+
).toBeUndefined()
36+
})
37+
38+
it('fails on Additional Inputs that are JSON but not an object', () => {
39+
expect(() => mapParams({ additionalInputs: '["billing"]' })).toThrow(
40+
'Additional Inputs must be a JSON object'
41+
)
42+
})
43+
})

‎apps/sim/blocks/blocks/dspy.ts‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
1+
import { isPlainRecord } from '@sim/utils/object'
12
import { DsPyIcon } from '@/components/icons'
23
import type { BlockConfig, BlockMeta } from '@/blocks/types'
34
import { IntegrationType } from '@/blocks/types'
5+
import { failToolCallOnError, mapperOperation } from '@/blocks/utils'
6+
7+
/** Predict's Additional Inputs: a JSON object as text from the canvas, or an object from an agent. */
8+
function parseAdditionalInputs(value: unknown): Record<string, unknown> | undefined {
9+
if (value === undefined || value === null) return undefined
10+
if (typeof value === 'string' && !value.trim()) return undefined
11+
let parsed: unknown = value
12+
if (typeof value === 'string') {
13+
try {
14+
parsed = JSON.parse(value)
15+
} catch {
16+
throw new Error('Additional Inputs must be valid JSON')
17+
}
18+
}
19+
if (!isPlainRecord(parsed)) {
20+
throw new Error('Additional Inputs must be a JSON object')
21+
}
22+
return parsed
23+
}
424

525
export const DSPyBlock: BlockConfig = {
626
type: 'dspy',
@@ -142,17 +162,13 @@ export const DSPyBlock: BlockConfig = {
142162
access: ['dspy_predict', 'dspy_chain_of_thought', 'dspy_react'],
143163
config: {
144164
tool: (params) => `dspy_${params.operation}`,
145-
params: (params) => {
165+
params: (params, context) => {
146166
const { operation, additionalInputs, maxIterations, ...rest } = params
147167

148-
let parsedAdditionalInputs: Record<string, unknown> | undefined
149-
if (additionalInputs && typeof additionalInputs === 'string') {
150-
try {
151-
parsedAdditionalInputs = JSON.parse(additionalInputs)
152-
} catch {
153-
// Ignore parse errors
154-
}
155-
}
168+
const parsedAdditionalInputs =
169+
mapperOperation(params, context) === 'predict'
170+
? failToolCallOnError(context, () => parseAdditionalInputs(additionalInputs))
171+
: undefined
156172

157173
let parsedMaxIterations: number | undefined
158174
if (maxIterations) {

‎apps/sim/blocks/blocks/gamma.ts‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,13 @@ Return ONLY the dimension value string, nothing else.`,
176176
options: [
177177
{ label: 'AI Generated', id: 'aiGenerated' },
178178
{ label: 'Pictographic', id: 'pictographic' },
179-
{ label: 'Unsplash', id: 'unsplash' },
179+
{ label: 'Pexels', id: 'pexels' },
180+
{ label: 'Unsplash', id: 'unsplash', hidden: true },
180181
{ label: 'Web (All Images)', id: 'webAllImages' },
181182
{ label: 'Web (Free to Use)', id: 'webFreeToUse' },
182183
{ label: 'Web (Free Commercial)', id: 'webFreeToUseCommercially' },
183184
{ label: 'Giphy', id: 'giphy' },
185+
{ label: 'Theme Accent', id: 'themeAccent' },
184186
{ label: 'Placeholder', id: 'placeholder' },
185187
{ label: 'No Images', id: 'noImages' },
186188
],
@@ -212,6 +214,7 @@ Return ONLY the dimension value string, nothing else.`,
212214
{ label: 'None', id: '' },
213215
{ label: 'PDF', id: 'pdf' },
214216
{ label: 'PPTX', id: 'pptx' },
217+
{ label: 'PNG (zip)', id: 'png' },
215218
],
216219
value: () => '',
217220
condition: { field: 'operation', value: ['generate', 'generate_from_template'] },
@@ -227,21 +230,11 @@ Return ONLY the dimension value string, nothing else.`,
227230
},
228231
{
229232
id: 'folderIds',
230-
title: 'Folder IDs',
233+
title: 'Folder ID',
231234
type: 'short-input',
232-
placeholder: 'Comma-separated folder IDs',
235+
placeholder: 'Folder ID (use List Folders to find)',
233236
condition: { field: 'operation', value: ['generate', 'generate_from_template'] },
234237
mode: 'advanced',
235-
wandConfig: {
236-
enabled: true,
237-
prompt: `Generate a comma-separated list of Gamma folder IDs.
238-
The user will describe which folders to store the generated gamma in.
239-
Each folder ID is a string identifier from the Gamma workspace.
240-
Use the List Folders operation to find available folder IDs first.
241-
Return ONLY the comma-separated IDs, nothing else.
242-
Example: "folder_abc123, folder_def456"`,
243-
placeholder: 'Describe which folders to store the gamma in...',
244-
},
245238
},
246239
// Generate from Template inputs
247240
{
@@ -342,7 +335,7 @@ Example: "folder_abc123, folder_def456"`,
342335
imageStyle: { type: 'string', description: 'Image style directive' },
343336
exportAs: { type: 'string', description: 'Export format' },
344337
themeId: { type: 'string', description: 'Theme ID' },
345-
folderIds: { type: 'string', description: 'Comma-separated folder IDs' },
338+
folderIds: { type: 'string', description: 'Folder ID' },
346339
gammaId: { type: 'string', description: 'Template gamma ID' },
347340
prompt: { type: 'string', description: 'Template adaptation prompt' },
348341
generationId: { type: 'string', description: 'Generation ID to check' },
@@ -354,6 +347,9 @@ Example: "folder_abc123, folder_def456"`,
354347
generationId: { type: 'string', description: 'Generation job ID' },
355348
status: { type: 'string', description: 'Generation status' },
356349
gammaUrl: { type: 'string', description: 'URL of the generated gamma' },
350+
gammaId: { type: 'string', description: 'ID of the generated gamma' },
351+
exportUrl: { type: 'string', description: 'Download URL of the exported file' },
352+
warnings: { type: 'string', description: 'Warnings about request options Gamma ignored' },
357353
credits: { type: 'json', description: 'Credit usage (deducted, remaining)' },
358354
error: { type: 'json', description: 'Error details if generation failed' },
359355
themes: { type: 'json', description: 'List of themes' },
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { HuggingFaceBlock } from '@/blocks/blocks/huggingface'
3+
4+
describe('Hugging Face block params', () => {
5+
it('sends a temperature of 0 instead of dropping it', () => {
6+
const mapper = HuggingFaceBlock.tools.config?.params
7+
if (!mapper) throw new Error('Hugging Face block has no params mapper')
8+
9+
const result = mapper({
10+
apiKey: 'hf_test',
11+
provider: 'novita',
12+
model: 'org/model',
13+
content: 'hi',
14+
temperature: 0,
15+
})
16+
17+
expect(result.temperature).toBe(0)
18+
})
19+
})

‎apps/sim/blocks/blocks/huggingface.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ export const HuggingFaceBlock: BlockConfig = {
107107
model: params.model,
108108
content: params.content,
109109
systemPrompt: params.systemPrompt,
110-
temperature: params.temperature ? Number.parseFloat(params.temperature) : undefined,
110+
temperature:
111+
params.temperature === undefined ||
112+
params.temperature === null ||
113+
params.temperature === ''
114+
? undefined
115+
: Number.parseFloat(params.temperature),
111116
maxTokens: params.maxTokens ? Number.parseInt(params.maxTokens) : undefined,
112117
stream: false, // Always false
113118
}

‎apps/sim/tools/dspy/chain_of_thought.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { DSPyChainOfThoughtParams, DSPyChainOfThoughtResponse } from '@/tools/dspy/types'
2+
import { buildDSPyUrl } from '@/tools/dspy/utils'
23
import type { ToolConfig } from '@/tools/types'
34

45
export const chainOfThoughtTool: ToolConfig<DSPyChainOfThoughtParams, DSPyChainOfThoughtResponse> =
@@ -48,11 +49,7 @@ export const chainOfThoughtTool: ToolConfig<DSPyChainOfThoughtParams, DSPyChainO
4849
select: (params) => ({ question: params.question, context: params.context }),
4950
},
5051
method: 'POST',
51-
url: (params) => {
52-
const baseUrl = params.baseUrl.replace(/\/$/, '')
53-
const endpoint = params.endpoint || '/predict'
54-
return `${baseUrl}${endpoint}`
55-
},
52+
url: (params) => buildDSPyUrl(params.baseUrl, params.endpoint),
5653
headers: (params) => {
5754
const headers: Record<string, string> = {
5855
'Content-Type': 'application/json',

‎apps/sim/tools/dspy/predict.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { DSPyPredictParams, DSPyPredictResponse } from '@/tools/dspy/types'
2+
import { buildDSPyUrl } from '@/tools/dspy/utils'
23
import type { ToolConfig } from '@/tools/types'
34

45
export const predictTool: ToolConfig<DSPyPredictParams, DSPyPredictResponse> = {
@@ -58,11 +59,7 @@ export const predictTool: ToolConfig<DSPyPredictParams, DSPyPredictResponse> = {
5859
select: (params) => ({ input: params.input, context: params.context }),
5960
},
6061
method: 'POST',
61-
url: (params) => {
62-
const baseUrl = params.baseUrl.replace(/\/$/, '')
63-
const endpoint = params.endpoint || '/predict'
64-
return `${baseUrl}${endpoint}`
65-
},
62+
url: (params) => buildDSPyUrl(params.baseUrl, params.endpoint),
6663
headers: (params) => {
6764
const headers: Record<string, string> = {
6865
'Content-Type': 'application/json',

‎apps/sim/tools/dspy/react.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { DSPyReActParams, DSPyReActResponse } from '@/tools/dspy/types'
2-
import { parseTrajectory } from '@/tools/dspy/utils'
2+
import { buildDSPyUrl, parseTrajectory } from '@/tools/dspy/utils'
33
import type { ToolConfig } from '@/tools/types'
44

55
export const reactTool: ToolConfig<DSPyReActParams, DSPyReActResponse> = {
@@ -54,11 +54,7 @@ export const reactTool: ToolConfig<DSPyReActParams, DSPyReActResponse> = {
5454
select: (params) => ({ task: params.task, context: params.context }),
5555
},
5656
method: 'POST',
57-
url: (params) => {
58-
const baseUrl = params.baseUrl.replace(/\/$/, '')
59-
const endpoint = params.endpoint || '/predict'
60-
return `${baseUrl}${endpoint}`
61-
},
57+
url: (params) => buildDSPyUrl(params.baseUrl, params.endpoint),
6258
headers: (params) => {
6359
const headers: Record<string, string> = {
6460
'Content-Type': 'application/json',

‎apps/sim/tools/dspy/utils.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { buildDSPyUrl } from '@/tools/dspy/utils'
3+
4+
describe('buildDSPyUrl', () => {
5+
it('adds the slash an endpoint path was typed without', () => {
6+
expect(buildDSPyUrl('https://dspy.example.com/', 'predict')).toBe(
7+
'https://dspy.example.com/predict'
8+
)
9+
})
10+
11+
it('defaults to /predict', () => {
12+
expect(buildDSPyUrl('https://dspy.example.com', '')).toBe('https://dspy.example.com/predict')
13+
})
14+
})

0 commit comments

Comments
 (0)