@@ -2,8 +2,11 @@ import { db } from '@sim/db'
22import { document , knowledgeBase , templates } from '@sim/db/schema'
33import { createLogger } from '@sim/logger'
44import { and , eq , isNull } from 'drizzle-orm'
5- import { readFileRecord } from '@/lib/copilot/vfs/file-reader'
6- import { serializeTableMeta } from '@/lib/copilot/vfs/serializers'
5+ import {
6+ serializeFileMeta ,
7+ serializeTableMeta ,
8+ serializeWorkflowMeta ,
9+ } from '@/lib/copilot/vfs/serializers'
710import { upsertWorkflowReadHashForSanitizedState } from '@/lib/copilot/workflow-read-hashes'
811import { getAllowedIntegrationsFromEnv } from '@/lib/core/config/feature-flags'
912import { getTableById } from '@/lib/table/service'
@@ -318,7 +321,7 @@ async function processWorkflowFromDb(
318321 chatId ?: string
319322) : Promise < AgentContext | null > {
320323 try {
321- let workflowName : string | undefined
324+ let workflowRecord : Awaited < ReturnType < typeof getActiveWorkflowRecord > > = null
322325
323326 if ( userId ) {
324327 const authorization = await authorizeWorkflowByWorkspacePermission ( {
@@ -332,7 +335,27 @@ async function processWorkflowFromDb(
332335 if ( currentWorkspaceId && authorization . workflow ?. workspaceId !== currentWorkspaceId ) {
333336 return null
334337 }
335- workflowName = authorization . workflow ?. name ?? undefined
338+ workflowRecord = authorization . workflow ?? null
339+ }
340+
341+ if ( ! workflowRecord ) {
342+ workflowRecord = await getActiveWorkflowRecord ( workflowId )
343+ }
344+
345+ if ( kind === 'workflow' ) {
346+ if ( ! workflowRecord ) return null
347+ const content = serializeWorkflowMeta ( {
348+ id : workflowRecord . id ,
349+ name : workflowRecord . name ,
350+ description : workflowRecord . description ,
351+ isDeployed : workflowRecord . isDeployed ,
352+ deployedAt : workflowRecord . deployedAt ,
353+ runCount : workflowRecord . runCount ,
354+ lastRunAt : workflowRecord . lastRunAt ,
355+ createdAt : workflowRecord . createdAt ,
356+ updatedAt : workflowRecord . updatedAt ,
357+ } )
358+ return { type : kind , tag, content }
336359 }
337360
338361 const normalized = await loadWorkflowFromNormalizedTables ( workflowId )
@@ -341,11 +364,6 @@ async function processWorkflowFromDb(
341364 return null
342365 }
343366
344- if ( ! workflowName ) {
345- const record = await getActiveWorkflowRecord ( workflowId )
346- workflowName = record ?. name ?? undefined
347- }
348-
349367 const workflowState = {
350368 blocks : normalized . blocks || { } ,
351369 edges : normalized . edges || [ ] ,
@@ -359,7 +377,7 @@ async function processWorkflowFromDb(
359377 const content = JSON . stringify (
360378 {
361379 workflowId,
362- workflowName : workflowName || undefined ,
380+ workflowName : workflowRecord ?. name || undefined ,
363381 state : sanitizedState ,
364382 } ,
365383 null ,
@@ -786,18 +804,15 @@ async function resolveFileResource(
786804) : Promise < AgentContext | null > {
787805 const record = await getWorkspaceFile ( workspaceId , fileId )
788806 if ( ! record ) return null
789- const fileResult = await readFileRecord ( record )
790- const meta = {
791- id : record . id ,
792- name : record . name ,
793- contentType : record . type ,
794- size : record . size ,
795- uploadedAt : record . uploadedAt . toISOString ( ) ,
796- content : fileResult ?. content || `[Could not read ${ record . name } ]` ,
797- }
798807 return {
799808 type : 'active_resource' ,
800809 tag : '@active_resource' ,
801- content : JSON . stringify ( meta , null , 2 ) ,
810+ content : serializeFileMeta ( {
811+ id : record . id ,
812+ name : record . name ,
813+ contentType : record . type ,
814+ size : record . size ,
815+ uploadedAt : record . uploadedAt ,
816+ } ) ,
802817 }
803818}
0 commit comments