Skip to content

Commit 4339c8f

Browse files
committed
improvement(blocks): extract model config subBlocks into shared utils
1 parent 99ae543 commit 4339c8f

File tree

2 files changed

+251
-231
lines changed

2 files changed

+251
-231
lines changed

apps/sim/blocks/blocks/agent.ts

Lines changed: 4 additions & 230 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,8 @@ import { createLogger } from '@sim/logger'
22
import { AgentIcon } from '@/components/icons'
33
import type { BlockConfig } from '@/blocks/types'
44
import { AuthMode } from '@/blocks/types'
5-
import { getApiKeyCondition } from '@/blocks/utils'
6-
import {
7-
getBaseModelProviders,
8-
getMaxTemperature,
9-
getProviderIcon,
10-
getReasoningEffortValuesForModel,
11-
getThinkingLevelsForModel,
12-
getVerbosityValuesForModel,
13-
MODELS_WITH_REASONING_EFFORT,
14-
MODELS_WITH_THINKING,
15-
MODELS_WITH_VERBOSITY,
16-
providers,
17-
supportsTemperature,
18-
} from '@/providers/utils'
5+
import { getApiKeyCondition, getModelConfigSubBlocks, MODEL_CONFIG_INPUTS } from '@/blocks/utils'
6+
import { getBaseModelProviders, getProviderIcon, providers } from '@/providers/utils'
197
import { useProvidersStore } from '@/stores/providers'
208
import type { ToolResponse } from '@/tools/types'
219

@@ -148,171 +136,7 @@ Return ONLY the JSON array.`,
148136
value: providers.vertex.models,
149137
},
150138
},
151-
{
152-
id: 'reasoningEffort',
153-
title: 'Reasoning Effort',
154-
type: 'dropdown',
155-
placeholder: 'Select reasoning effort...',
156-
options: [
157-
{ label: 'auto', id: 'auto' },
158-
{ label: 'low', id: 'low' },
159-
{ label: 'medium', id: 'medium' },
160-
{ label: 'high', id: 'high' },
161-
],
162-
dependsOn: ['model'],
163-
fetchOptions: async (blockId: string) => {
164-
const { useSubBlockStore } = await import('@/stores/workflows/subblock/store')
165-
const { useWorkflowRegistry } = await import('@/stores/workflows/registry/store')
166-
167-
const autoOption = { label: 'auto', id: 'auto' }
168-
169-
const activeWorkflowId = useWorkflowRegistry.getState().activeWorkflowId
170-
if (!activeWorkflowId) {
171-
return [
172-
autoOption,
173-
{ label: 'low', id: 'low' },
174-
{ label: 'medium', id: 'medium' },
175-
{ label: 'high', id: 'high' },
176-
]
177-
}
178-
179-
const workflowValues = useSubBlockStore.getState().workflowValues[activeWorkflowId]
180-
const blockValues = workflowValues?.[blockId]
181-
const modelValue = blockValues?.model as string
182-
183-
if (!modelValue) {
184-
return [
185-
autoOption,
186-
{ label: 'low', id: 'low' },
187-
{ label: 'medium', id: 'medium' },
188-
{ label: 'high', id: 'high' },
189-
]
190-
}
191-
192-
const validOptions = getReasoningEffortValuesForModel(modelValue)
193-
if (!validOptions) {
194-
return [
195-
autoOption,
196-
{ label: 'low', id: 'low' },
197-
{ label: 'medium', id: 'medium' },
198-
{ label: 'high', id: 'high' },
199-
]
200-
}
201-
202-
return [autoOption, ...validOptions.map((opt) => ({ label: opt, id: opt }))]
203-
},
204-
mode: 'advanced',
205-
condition: {
206-
field: 'model',
207-
value: MODELS_WITH_REASONING_EFFORT,
208-
},
209-
},
210-
{
211-
id: 'verbosity',
212-
title: 'Verbosity',
213-
type: 'dropdown',
214-
placeholder: 'Select verbosity...',
215-
options: [
216-
{ label: 'auto', id: 'auto' },
217-
{ label: 'low', id: 'low' },
218-
{ label: 'medium', id: 'medium' },
219-
{ label: 'high', id: 'high' },
220-
],
221-
dependsOn: ['model'],
222-
fetchOptions: async (blockId: string) => {
223-
const { useSubBlockStore } = await import('@/stores/workflows/subblock/store')
224-
const { useWorkflowRegistry } = await import('@/stores/workflows/registry/store')
225-
226-
const autoOption = { label: 'auto', id: 'auto' }
227-
228-
const activeWorkflowId = useWorkflowRegistry.getState().activeWorkflowId
229-
if (!activeWorkflowId) {
230-
return [
231-
autoOption,
232-
{ label: 'low', id: 'low' },
233-
{ label: 'medium', id: 'medium' },
234-
{ label: 'high', id: 'high' },
235-
]
236-
}
237-
238-
const workflowValues = useSubBlockStore.getState().workflowValues[activeWorkflowId]
239-
const blockValues = workflowValues?.[blockId]
240-
const modelValue = blockValues?.model as string
241-
242-
if (!modelValue) {
243-
return [
244-
autoOption,
245-
{ label: 'low', id: 'low' },
246-
{ label: 'medium', id: 'medium' },
247-
{ label: 'high', id: 'high' },
248-
]
249-
}
250-
251-
const validOptions = getVerbosityValuesForModel(modelValue)
252-
if (!validOptions) {
253-
return [
254-
autoOption,
255-
{ label: 'low', id: 'low' },
256-
{ label: 'medium', id: 'medium' },
257-
{ label: 'high', id: 'high' },
258-
]
259-
}
260-
261-
return [autoOption, ...validOptions.map((opt) => ({ label: opt, id: opt }))]
262-
},
263-
mode: 'advanced',
264-
condition: {
265-
field: 'model',
266-
value: MODELS_WITH_VERBOSITY,
267-
},
268-
},
269-
{
270-
id: 'thinkingLevel',
271-
title: 'Thinking Level',
272-
type: 'dropdown',
273-
placeholder: 'Select thinking level...',
274-
options: [
275-
{ label: 'none', id: 'none' },
276-
{ label: 'minimal', id: 'minimal' },
277-
{ label: 'low', id: 'low' },
278-
{ label: 'medium', id: 'medium' },
279-
{ label: 'high', id: 'high' },
280-
{ label: 'max', id: 'max' },
281-
],
282-
dependsOn: ['model'],
283-
fetchOptions: async (blockId: string) => {
284-
const { useSubBlockStore } = await import('@/stores/workflows/subblock/store')
285-
const { useWorkflowRegistry } = await import('@/stores/workflows/registry/store')
286-
287-
const noneOption = { label: 'none', id: 'none' }
288-
289-
const activeWorkflowId = useWorkflowRegistry.getState().activeWorkflowId
290-
if (!activeWorkflowId) {
291-
return [noneOption, { label: 'low', id: 'low' }, { label: 'high', id: 'high' }]
292-
}
293-
294-
const workflowValues = useSubBlockStore.getState().workflowValues[activeWorkflowId]
295-
const blockValues = workflowValues?.[blockId]
296-
const modelValue = blockValues?.model as string
297-
298-
if (!modelValue) {
299-
return [noneOption, { label: 'low', id: 'low' }, { label: 'high', id: 'high' }]
300-
}
301-
302-
const validOptions = getThinkingLevelsForModel(modelValue)
303-
if (!validOptions) {
304-
return [noneOption, { label: 'low', id: 'low' }, { label: 'high', id: 'high' }]
305-
}
306-
307-
return [noneOption, ...validOptions.map((opt) => ({ label: opt, id: opt }))]
308-
},
309-
mode: 'advanced',
310-
condition: {
311-
field: 'model',
312-
value: MODELS_WITH_THINKING,
313-
},
314-
},
315-
139+
...getModelConfigSubBlocks(),
316140
{
317141
id: 'azureEndpoint',
318142
title: 'Azure Endpoint',
@@ -466,49 +290,6 @@ Return ONLY the JSON array.`,
466290
value: ['sliding_window_tokens'],
467291
},
468292
},
469-
{
470-
id: 'temperature',
471-
title: 'Temperature',
472-
type: 'slider',
473-
min: 0,
474-
max: 1,
475-
defaultValue: 0.3,
476-
mode: 'advanced',
477-
condition: () => ({
478-
field: 'model',
479-
value: (() => {
480-
const allModels = Object.keys(getBaseModelProviders())
481-
return allModels.filter(
482-
(model) => supportsTemperature(model) && getMaxTemperature(model) === 1
483-
)
484-
})(),
485-
}),
486-
},
487-
{
488-
id: 'temperature',
489-
title: 'Temperature',
490-
type: 'slider',
491-
min: 0,
492-
max: 2,
493-
defaultValue: 0.3,
494-
mode: 'advanced',
495-
condition: () => ({
496-
field: 'model',
497-
value: (() => {
498-
const allModels = Object.keys(getBaseModelProviders())
499-
return allModels.filter(
500-
(model) => supportsTemperature(model) && getMaxTemperature(model) === 2
501-
)
502-
})(),
503-
}),
504-
},
505-
{
506-
id: 'maxTokens',
507-
title: 'Max Output Tokens',
508-
type: 'short-input',
509-
placeholder: 'Enter max tokens (e.g., 4096)...',
510-
mode: 'advanced',
511-
},
512293
{
513294
id: 'responseFormat',
514295
title: 'Response Format',
@@ -749,14 +530,7 @@ Example 3 (Array Input):
749530
required: ['schema'],
750531
},
751532
},
752-
temperature: { type: 'number', description: 'Response randomness level' },
753-
maxTokens: { type: 'number', description: 'Maximum number of tokens in the response' },
754-
reasoningEffort: { type: 'string', description: 'Reasoning effort level for GPT-5 models' },
755-
verbosity: { type: 'string', description: 'Verbosity level for GPT-5 models' },
756-
thinkingLevel: {
757-
type: 'string',
758-
description: 'Thinking level for models with extended thinking (Anthropic Claude, Gemini 3)',
759-
},
533+
...MODEL_CONFIG_INPUTS,
760534
tools: { type: 'json', description: 'Available tools configuration' },
761535
skills: { type: 'json', description: 'Selected skills configuration' },
762536
},

0 commit comments

Comments
 (0)