Skip to content

Commit c3c506c

Browse files
committed
rewrite gemini provider with official sdk + add thinking capability
1 parent 784b22a commit c3c506c

File tree

7 files changed

+942
-974
lines changed

7 files changed

+942
-974
lines changed

apps/sim/blocks/blocks/agent.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import {
99
getMaxTemperature,
1010
getProviderIcon,
1111
getReasoningEffortValuesForModel,
12+
getThinkingLevelsForModel,
1213
getVerbosityValuesForModel,
1314
MODELS_WITH_REASONING_EFFORT,
15+
MODELS_WITH_THINKING,
1416
MODELS_WITH_VERBOSITY,
1517
providers,
1618
supportsTemperature,
@@ -215,6 +217,57 @@ export const AgentBlock: BlockConfig<AgentResponse> = {
215217
value: MODELS_WITH_VERBOSITY,
216218
},
217219
},
220+
{
221+
id: 'thinkingLevel',
222+
title: 'Thinking Level',
223+
type: 'dropdown',
224+
placeholder: 'Select thinking level...',
225+
options: [
226+
{ label: 'minimal', id: 'minimal' },
227+
{ label: 'low', id: 'low' },
228+
{ label: 'medium', id: 'medium' },
229+
{ label: 'high', id: 'high' },
230+
],
231+
dependsOn: ['model'],
232+
fetchOptions: async (blockId: string) => {
233+
const { useSubBlockStore } = await import('@/stores/workflows/subblock/store')
234+
const { useWorkflowRegistry } = await import('@/stores/workflows/registry/store')
235+
236+
const activeWorkflowId = useWorkflowRegistry.getState().activeWorkflowId
237+
if (!activeWorkflowId) {
238+
return [
239+
{ label: 'low', id: 'low' },
240+
{ label: 'high', id: 'high' },
241+
]
242+
}
243+
244+
const workflowValues = useSubBlockStore.getState().workflowValues[activeWorkflowId]
245+
const blockValues = workflowValues?.[blockId]
246+
const modelValue = blockValues?.model as string
247+
248+
if (!modelValue) {
249+
return [
250+
{ label: 'low', id: 'low' },
251+
{ label: 'high', id: 'high' },
252+
]
253+
}
254+
255+
const validOptions = getThinkingLevelsForModel(modelValue)
256+
if (!validOptions) {
257+
return [
258+
{ label: 'low', id: 'low' },
259+
{ label: 'high', id: 'high' },
260+
]
261+
}
262+
263+
return validOptions.map((opt) => ({ label: opt, id: opt }))
264+
},
265+
value: () => 'high',
266+
condition: {
267+
field: 'model',
268+
value: MODELS_WITH_THINKING,
269+
},
270+
},
218271

219272
{
220273
id: 'azureEndpoint',
@@ -609,6 +662,7 @@ Example 3 (Array Input):
609662
temperature: { type: 'number', description: 'Response randomness level' },
610663
reasoningEffort: { type: 'string', description: 'Reasoning effort level for GPT-5 models' },
611664
verbosity: { type: 'string', description: 'Verbosity level for GPT-5 models' },
665+
thinkingLevel: { type: 'string', description: 'Thinking level for Gemini 3 models' },
612666
tools: { type: 'json', description: 'Available tools configuration' },
613667
},
614668
outputs: {

apps/sim/lib/core/utils/display-filters.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ function filterUserFile(data: any): any {
4141
const DISPLAY_FILTERS = [filterUserFile]
4242

4343
export function filterForDisplay(data: any): any {
44-
const seen = new WeakSet()
44+
const seen = new Set<object>()
4545
return filterForDisplayInternal(data, seen, 0)
4646
}
4747

4848
function getObjectType(data: unknown): string {
4949
return Object.prototype.toString.call(data).slice(8, -1)
5050
}
5151

52-
function filterForDisplayInternal(data: any, seen: WeakSet<object>, depth: number): any {
52+
function filterForDisplayInternal(data: any, seen: Set<object>, depth: number): any {
5353
try {
5454
if (data === null || data === undefined) {
5555
return data
@@ -93,6 +93,7 @@ function filterForDisplayInternal(data: any, seen: WeakSet<object>, depth: numbe
9393
return '[Unknown Type]'
9494
}
9595

96+
// True circular reference: object is an ancestor in the current path
9697
if (seen.has(data)) {
9798
return '[Circular Reference]'
9899
}
@@ -131,18 +132,24 @@ function filterForDisplayInternal(data: any, seen: WeakSet<object>, depth: numbe
131132
return `[ArrayBuffer: ${(data as ArrayBuffer).byteLength} bytes]`
132133

133134
case 'Map': {
135+
seen.add(data)
134136
const obj: Record<string, any> = {}
135137
for (const [key, value] of (data as Map<any, any>).entries()) {
136138
const keyStr = typeof key === 'string' ? key : String(key)
137139
obj[keyStr] = filterForDisplayInternal(value, seen, depth + 1)
138140
}
141+
seen.delete(data)
139142
return obj
140143
}
141144

142-
case 'Set':
143-
return Array.from(data as Set<any>).map((item) =>
145+
case 'Set': {
146+
seen.add(data)
147+
const result = Array.from(data as Set<any>).map((item) =>
144148
filterForDisplayInternal(item, seen, depth + 1)
145149
)
150+
seen.delete(data)
151+
return result
152+
}
146153

147154
case 'WeakMap':
148155
return '[WeakMap]'
@@ -161,17 +168,22 @@ function filterForDisplayInternal(data: any, seen: WeakSet<object>, depth: numbe
161168
return `[${objectType}: ${(data as ArrayBufferView).byteLength} bytes]`
162169
}
163170

171+
// Add to current path before processing children
164172
seen.add(data)
165173

166174
for (const filterFn of DISPLAY_FILTERS) {
167-
const result = filterFn(data)
168-
if (result !== data) {
169-
return filterForDisplayInternal(result, seen, depth + 1)
175+
const filtered = filterFn(data)
176+
if (filtered !== data) {
177+
const result = filterForDisplayInternal(filtered, seen, depth + 1)
178+
seen.delete(data)
179+
return result
170180
}
171181
}
172182

173183
if (Array.isArray(data)) {
174-
return data.map((item) => filterForDisplayInternal(item, seen, depth + 1))
184+
const result = data.map((item) => filterForDisplayInternal(item, seen, depth + 1))
185+
seen.delete(data)
186+
return result
175187
}
176188

177189
const result: Record<string, any> = {}
@@ -182,6 +194,8 @@ function filterForDisplayInternal(data: any, seen: WeakSet<object>, depth: numbe
182194
result[key] = '[Error accessing property]'
183195
}
184196
}
197+
// Remove from current path after processing children
198+
seen.delete(data)
185199
return result
186200
} catch {
187201
return '[Unserializable]'

0 commit comments

Comments
 (0)