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
2 changes: 1 addition & 1 deletion apps/realtime/src/database/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const socketDb = drizzle(
prepare: false,
idle_timeout: 10,
connect_timeout: 20,
max: 30,
max: 15,
onnotice: () => {},
}),
{ schema }
Expand Down
6 changes: 2 additions & 4 deletions apps/sim/app/api/mcp/servers/[id]/refresh/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { db } from '@sim/db'
import { mcpServers, workflow, workflowBlocks } from '@sim/db/schema'
import { createLogger } from '@sim/logger'
import { toError } from '@sim/utils/errors'
import { and, eq, isNull } from 'drizzle-orm'
import { and, eq, inArray, isNull } from 'drizzle-orm'
import type { NextRequest } from 'next/server'
import { mcpServerIdParamsSchema } from '@/lib/api/contracts/mcp'
import { validationErrorResponse } from '@/lib/api/server'
Expand Down Expand Up @@ -77,13 +77,11 @@ async function syncToolSchemasToWorkflows(
subBlocks: workflowBlocks.subBlocks,
})
.from(workflowBlocks)
.where(eq(workflowBlocks.type, 'agent'))
.where(and(eq(workflowBlocks.type, 'agent'), inArray(workflowBlocks.workflowId, workflowIds)))

const updatedWorkflowIds = new Set<string>()

for (const block of agentBlocks) {
if (!workflowIds.includes(block.workflowId)) continue

const subBlocks = block.subBlocks as Record<string, unknown> | null
if (!subBlocks) continue

Expand Down
8 changes: 4 additions & 4 deletions apps/sim/app/api/mcp/tools/stored/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { db } from '@sim/db'
import { workflow, workflowBlocks } from '@sim/db/schema'
import { createLogger } from '@sim/logger'
import { toError } from '@sim/utils/errors'
import { eq } from 'drizzle-orm'
import { and, eq, inArray } from 'drizzle-orm'
import type { NextRequest } from 'next/server'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { withMcpAuth } from '@/lib/mcp/middleware'
Expand Down Expand Up @@ -33,13 +33,13 @@ export const GET = withRouteHandler(
const agentBlocks = await db
.select({ workflowId: workflowBlocks.workflowId, subBlocks: workflowBlocks.subBlocks })
.from(workflowBlocks)
.where(eq(workflowBlocks.type, 'agent'))
.where(
and(eq(workflowBlocks.type, 'agent'), inArray(workflowBlocks.workflowId, workflowIds))
)

const storedTools: StoredMcpTool[] = []

for (const block of agentBlocks) {
if (!workflowMap.has(block.workflowId)) continue

const subBlocks = block.subBlocks as Record<string, unknown> | null
if (!subBlocks) continue

Expand Down
27 changes: 24 additions & 3 deletions apps/sim/lib/copilot/vfs/workspace-vfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@sim/db/schema'
import { createLogger } from '@sim/logger'
import { toError } from '@sim/utils/errors'
import { and, desc, eq, isNotNull, isNull, ne } from 'drizzle-orm'
import { and, desc, eq, isNotNull, isNull, ne, sql } from 'drizzle-orm'
import { listApiKeys } from '@/lib/api-key/service'
import { buildWorkspaceMd, type WorkspaceMdData } from '@/lib/copilot/chat/workspace-context'
import { extractDocumentStyle } from '@/lib/copilot/vfs/document-style'
Expand Down Expand Up @@ -1157,7 +1157,27 @@ export class WorkspaceVFS {
.select({
id: copilotChats.id,
title: copilotChats.title,
messages: copilotChats.messages,
messageCount: sql<number>`COALESCE(jsonb_array_length(${copilotChats.messages}), 0)`,
Comment thread
waleedlatif1 marked this conversation as resolved.
messages: sql<unknown[]>`COALESCE((
SELECT jsonb_agg(
jsonb_build_object(
'role', m->>'role',
'content', m->'content',
'contentBlocks', COALESCE((
SELECT jsonb_agg(jsonb_build_object('type', 'text', 'content', b->'content'))
FROM jsonb_array_elements(
CASE WHEN jsonb_typeof(m->'contentBlocks') = 'array'
THEN m->'contentBlocks'
ELSE '[]'::jsonb
END
) AS b
WHERE b->>'type' = 'text'
), '[]'::jsonb)
Comment thread
waleedlatif1 marked this conversation as resolved.
)
)
FROM jsonb_array_elements(${copilotChats.messages}) AS m
WHERE m->>'role' IN ('user', 'assistant')
), '[]'::jsonb)`,
Comment thread
waleedlatif1 marked this conversation as resolved.
createdAt: copilotChats.createdAt,
updatedAt: copilotChats.updatedAt,
})
Expand All @@ -1177,13 +1197,14 @@ export class WorkspaceVFS {
const safeName = sanitizeName(title)
const prefix = `tasks/${safeName}/`
const messages = Array.isArray(task.messages) ? task.messages : []
const messageCount = Number(task.messageCount) || 0

this.files.set(
`${prefix}session.md`,
serializeTaskSession({
id: task.id,
title,
messageCount: messages.length,
messageCount,
createdAt: task.createdAt,
updatedAt: task.updatedAt,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/db/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const postgresClient = postgres(connectionString, {
prepare: false,
idle_timeout: 20,
connect_timeout: 30,
max: 30,
max: 15,
onnotice: () => {},
})

Expand Down
Loading