11import { db , dbReplica } from '@sim/db'
2- import { knowledgeBase } from '@sim/db/schema'
2+ import { knowledgeBase , workflowSchedule } from '@sim/db/schema'
33import { createLogger } from '@sim/logger'
44import {
55 authorizeWorkflowByWorkspacePermission ,
66 getActiveWorkflowRecord ,
77} from '@sim/workflow-authz'
88import { and , eq , isNull } from 'drizzle-orm'
9+ import { normalizeVfsSegment } from '@/lib/copilot/vfs/normalize-segment'
910import {
1011 buildVfsFolderPathMap ,
1112 canonicalBlockVfsPath ,
@@ -168,6 +169,16 @@ export async function processContextsServer(
168169 path : result . path ,
169170 }
170171 }
172+ if ( ctx . kind === 'scheduledtask' && ctx . scheduleId && currentWorkspaceId ) {
173+ const result = await resolveScheduledTaskResource ( ctx . scheduleId , currentWorkspaceId )
174+ if ( ! result ) return null
175+ return {
176+ type : 'active_resource' ,
177+ tag : ctx . label ? `@${ ctx . label } ` : '@' ,
178+ content : result . content ,
179+ path : result . path ,
180+ }
181+ }
171182 if ( ctx . kind === 'docs' ) {
172183 try {
173184 const { searchDocumentationServerTool } = await import (
@@ -695,6 +706,9 @@ export async function resolveActiveResourceContext(
695706 case 'filefolder' : {
696707 return await resolveFileFolderResource ( resourceId , workspaceId )
697708 }
709+ case 'scheduledtask' : {
710+ return await resolveScheduledTaskResource ( resourceId , workspaceId )
711+ }
698712 default :
699713 return null
700714 }
@@ -718,6 +732,34 @@ async function resolveTableResource(
718732 }
719733}
720734
735+ async function resolveScheduledTaskResource (
736+ scheduleId : string ,
737+ workspaceId : string
738+ ) : Promise < AgentContext | null > {
739+ const [ row ] = await db
740+ . select ( { id : workflowSchedule . id , jobTitle : workflowSchedule . jobTitle } )
741+ . from ( workflowSchedule )
742+ . where (
743+ and (
744+ eq ( workflowSchedule . id , scheduleId ) ,
745+ eq ( workflowSchedule . sourceWorkspaceId , workspaceId ) ,
746+ eq ( workflowSchedule . sourceType , 'job' ) ,
747+ isNull ( workflowSchedule . archivedAt )
748+ )
749+ )
750+ . limit ( 1 )
751+ if ( ! row ) return null
752+ // The VFS materializes jobs at `jobs/{sanitized title}/meta.json` (see
753+ // workspace-vfs `materializeJobs`); emit the same lightweight path pointer so
754+ // the agent reads it via the VFS instead of us inlining the (heavy) row.
755+ return {
756+ type : 'active_resource' ,
757+ tag : '@active_resource' ,
758+ content : '' ,
759+ path : `jobs/${ normalizeVfsSegment ( row . jobTitle || row . id ) } /meta.json` ,
760+ }
761+ }
762+
721763async function resolveFileResource (
722764 fileId : string ,
723765 workspaceId : string
0 commit comments