mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
improvement(mem0) (#311)
* improvement(mem0): slider value * improvement: removed unused/unnecessary parameters and reorganized block
This commit is contained in:
+12
-6
@@ -8,6 +8,8 @@ interface SliderInputProps {
|
||||
defaultValue: number
|
||||
blockId: string
|
||||
subBlockId: string
|
||||
step?: number
|
||||
integer?: boolean
|
||||
}
|
||||
|
||||
export function SliderInput({
|
||||
@@ -16,6 +18,8 @@ export function SliderInput({
|
||||
defaultValue,
|
||||
blockId,
|
||||
subBlockId,
|
||||
step = 0.1,
|
||||
integer = false,
|
||||
}: SliderInputProps) {
|
||||
const [value, setValue] = useSubBlockValue<number>(blockId, subBlockId)
|
||||
|
||||
@@ -26,12 +30,14 @@ export function SliderInput({
|
||||
// If value exceeds max, scale it down proportionally
|
||||
if (value > max) {
|
||||
const prevMax = Math.max(max * 2, value) // Assume previous max was at least the current value
|
||||
return (value / prevMax) * max
|
||||
const scaledValue = (value / prevMax) * max
|
||||
return integer ? Math.round(scaledValue) : scaledValue
|
||||
}
|
||||
|
||||
// Otherwise just clamp it
|
||||
return Math.min(Math.max(value, min), max)
|
||||
}, [value, min, max, defaultValue])
|
||||
const clampedValue = Math.min(Math.max(value, min), max)
|
||||
return integer ? Math.round(clampedValue) : clampedValue
|
||||
}, [value, min, max, defaultValue, integer])
|
||||
|
||||
// Update the value if it needs normalization
|
||||
useEffect(() => {
|
||||
@@ -46,8 +52,8 @@ export function SliderInput({
|
||||
value={[normalizedValue]}
|
||||
min={min}
|
||||
max={max}
|
||||
step={0.1}
|
||||
onValueChange={(value) => setValue(value[0])}
|
||||
step={integer ? 1 : step}
|
||||
onValueChange={(value) => setValue(integer ? Math.round(value[0]) : value[0])}
|
||||
className="[&_[role=slider]]:h-4 [&_[role=slider]]:w-4 [&_[class*=SliderTrack]]:h-1"
|
||||
/>
|
||||
<div
|
||||
@@ -62,7 +68,7 @@ export function SliderInput({
|
||||
top: '24px',
|
||||
}}
|
||||
>
|
||||
{Number(normalizedValue).toFixed(1)}
|
||||
{integer ? Math.round(normalizedValue).toString() : Number(normalizedValue).toFixed(1)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -12,10 +12,10 @@ import { DateInput } from './components/date-input'
|
||||
import { Dropdown } from './components/dropdown'
|
||||
import { EvalInput } from './components/eval-input'
|
||||
import { FileSelectorInput } from './components/file-selector/file-selector-input'
|
||||
import { ProjectSelectorInput } from './components/project-selector/project-selector-input'
|
||||
import { FileUpload } from './components/file-upload'
|
||||
import { FolderSelectorInput } from './components/folder-selector/components/folder-selector-input'
|
||||
import { LongInput } from './components/long-input'
|
||||
import { ProjectSelectorInput } from './components/project-selector/project-selector-input'
|
||||
import { ScheduleConfig } from './components/schedule/schedule-config'
|
||||
import { ShortInput } from './components/short-input'
|
||||
import { SliderInput } from './components/slider-input'
|
||||
@@ -90,6 +90,8 @@ export function SubBlock({ blockId, config, isConnecting }: SubBlockProps) {
|
||||
min={config.min}
|
||||
max={config.max}
|
||||
defaultValue={(config.min || 0) + ((config.max || 100) - (config.min || 0)) / 2}
|
||||
step={config.step}
|
||||
integer={config.integer}
|
||||
/>
|
||||
)
|
||||
case 'table':
|
||||
|
||||
+15
-23
@@ -24,36 +24,14 @@ export const Mem0Block: BlockConfig<Mem0Response> = {
|
||||
],
|
||||
placeholder: 'Select an operation',
|
||||
},
|
||||
{
|
||||
id: 'limit',
|
||||
title: 'Result Limit',
|
||||
type: 'slider',
|
||||
layout: 'full',
|
||||
min: 1,
|
||||
max: 50,
|
||||
condition: {
|
||||
field: 'operation',
|
||||
value: ['search', 'get'],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'userId',
|
||||
title: 'User ID',
|
||||
type: 'short-input',
|
||||
layout: 'half',
|
||||
layout: 'full',
|
||||
placeholder: 'Enter user identifier',
|
||||
value: () => 'userid', // Default to the working user ID from curl example
|
||||
},
|
||||
{
|
||||
id: 'version',
|
||||
title: 'API Version',
|
||||
type: 'dropdown',
|
||||
layout: 'half',
|
||||
options: [
|
||||
{ label: 'v2 (Default)', id: 'v2' },
|
||||
{ label: 'v1', id: 'v1' }
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'messages',
|
||||
title: 'Messages',
|
||||
@@ -118,6 +96,20 @@ export const Mem0Block: BlockConfig<Mem0Response> = {
|
||||
placeholder: 'Enter your Mem0 API key',
|
||||
password: true,
|
||||
},
|
||||
{
|
||||
id: 'limit',
|
||||
title: 'Result Limit',
|
||||
type: 'slider',
|
||||
layout: 'full',
|
||||
min: 1,
|
||||
max: 50,
|
||||
step: 1,
|
||||
integer: true,
|
||||
condition: {
|
||||
field: 'operation',
|
||||
value: ['search', 'get'],
|
||||
},
|
||||
},
|
||||
],
|
||||
tools: {
|
||||
access: [
|
||||
|
||||
@@ -123,6 +123,9 @@ export interface SubBlockConfig {
|
||||
acceptedTypes?: string
|
||||
multiple?: boolean
|
||||
maxSize?: number
|
||||
// Slider-specific properties
|
||||
step?: number
|
||||
integer?: boolean
|
||||
}
|
||||
|
||||
// Main block definition
|
||||
|
||||
Generated
+105
@@ -15169,6 +15169,111 @@
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/wooorm"
|
||||
}
|
||||
},
|
||||
"node_modules/react-email/node_modules/@next/swc-darwin-x64": {
|
||||
"version": "15.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-15.3.1.tgz",
|
||||
"integrity": "sha512-q+aw+cJ2ooVYdCEqZVk+T4Ni10jF6Fo5DfpEV51OupMaV5XL6pf3GCzrk6kSSZBsMKZtVC1Zm/xaNBFpA6bJ2g==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/react-email/node_modules/@next/swc-linux-arm64-gnu": {
|
||||
"version": "15.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-15.3.1.tgz",
|
||||
"integrity": "sha512-wBQ+jGUI3N0QZyWmmvRHjXjTWFy8o+zPFLSOyAyGFI94oJi+kK/LIZFJXeykvgXUk1NLDAEFDZw/NVINhdk9FQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/react-email/node_modules/@next/swc-linux-arm64-musl": {
|
||||
"version": "15.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-15.3.1.tgz",
|
||||
"integrity": "sha512-IIxXEXRti/AulO9lWRHiCpUUR8AR/ZYLPALgiIg/9ENzMzLn3l0NSxVdva7R/VDcuSEBo0eGVCe3evSIHNz0Hg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/react-email/node_modules/@next/swc-linux-x64-gnu": {
|
||||
"version": "15.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-15.3.1.tgz",
|
||||
"integrity": "sha512-bfI4AMhySJbyXQIKH5rmLJ5/BP7bPwuxauTvVEiJ/ADoddaA9fgyNNCcsbu9SlqfHDoZmfI6g2EjzLwbsVTr5A==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/react-email/node_modules/@next/swc-linux-x64-musl": {
|
||||
"version": "15.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-15.3.1.tgz",
|
||||
"integrity": "sha512-FeAbR7FYMWR+Z+M5iSGytVryKHiAsc0x3Nc3J+FD5NVbD5Mqz7fTSy8CYliXinn7T26nDMbpExRUI/4ekTvoiA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/react-email/node_modules/@next/swc-win32-arm64-msvc": {
|
||||
"version": "15.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-15.3.1.tgz",
|
||||
"integrity": "sha512-yP7FueWjphQEPpJQ2oKmshk/ppOt+0/bB8JC8svPUZNy0Pi3KbPx2Llkzv1p8CoQa+D2wknINlJpHf3vtChVBw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/react-email/node_modules/@next/swc-win32-x64-msvc": {
|
||||
"version": "15.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.3.1.tgz",
|
||||
"integrity": "sha512-3PMvF2zRJAifcRNni9uMk/gulWfWS+qVI/pagd+4yLF5bcXPZPPH2xlYRYOsUjmCJOXSTAC2PjRzbhsRzR2fDQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,12 +22,6 @@ export const mem0AddMemoriesTool: ToolConfig = {
|
||||
required: true,
|
||||
description: 'Array of message objects with role and content',
|
||||
},
|
||||
version: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
default: 'v2',
|
||||
description: 'API version to use (v1 or v2). Use v2 if unsure.',
|
||||
},
|
||||
},
|
||||
request: {
|
||||
url: 'https://api.mem0.ai/v1/memories/',
|
||||
@@ -61,7 +55,7 @@ export const mem0AddMemoriesTool: ToolConfig = {
|
||||
// Prepare request body
|
||||
const body: Record<string, any> = {
|
||||
messages: messagesArray,
|
||||
version: params.version || 'v2',
|
||||
version: 'v2',
|
||||
user_id: params.userId
|
||||
}
|
||||
|
||||
|
||||
@@ -38,12 +38,6 @@ export const mem0GetMemoriesTool: ToolConfig = {
|
||||
default: 10,
|
||||
description: 'Maximum number of results to return',
|
||||
},
|
||||
version: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
default: 'v2',
|
||||
description: 'API version to use (v1 or v2). Use v2 if unsure.',
|
||||
},
|
||||
},
|
||||
request: {
|
||||
url: (params: Record<string, any>) => {
|
||||
|
||||
@@ -28,12 +28,6 @@ export const mem0SearchMemoriesTool: ToolConfig = {
|
||||
default: 10,
|
||||
description: 'Maximum number of results to return',
|
||||
},
|
||||
version: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
default: 'v2',
|
||||
description: 'API version to use (v1 or v2). Use v2 if unsure.',
|
||||
},
|
||||
},
|
||||
request: {
|
||||
url: 'https://api.mem0.ai/v2/memories/search/',
|
||||
|
||||
Reference in New Issue
Block a user