MCPcopy Index your code
hub / github.com/simstudioai/sim / processContextsServer

Function processContextsServer

apps/sim/lib/copilot/chat/process-contents.ts:64–216  ·  view source on GitHub ↗
(
  contexts: ChatContext[] | undefined,
  userId: string,
  userMessage?: string,
  currentWorkspaceId?: string,
  chatId?: string
)

Source from the content-addressed store, hash-verified

62
63// Server-side variant (recommended for use in API routes)
64export async function processContextsServer(
65 contexts: ChatContext[] | undefined,
66 userId: string,
67 userMessage?: string,
68 currentWorkspaceId?: string,
69 chatId?: string
70): Promise<AgentContext[]> {
71 if (!Array.isArray(contexts) || contexts.length === 0) return []
72 const tasks = contexts.map(async (ctx) => {
73 try {
74 if (ctx.kind === 'skill' && ctx.skillId && currentWorkspaceId) {
75 return await processSkillFromDb(
76 ctx.skillId,
77 currentWorkspaceId,
78 ctx.label ? `@${ctx.label}` : '@'
79 )
80 }
81 if (ctx.kind === 'past_chat' && ctx.chatId) {
82 return await processPastChatFromDb(
83 ctx.chatId,
84 userId,
85 ctx.label ? `@${ctx.label}` : '@',
86 currentWorkspaceId
87 )
88 }
89 if ((ctx.kind === 'workflow' || ctx.kind === 'current_workflow') && ctx.workflowId) {
90 return await processWorkflowFromDb(
91 ctx.workflowId,
92 userId,
93 ctx.label ? `@${ctx.label}` : '@',
94 ctx.kind,
95 currentWorkspaceId,
96 chatId
97 )
98 }
99 if (ctx.kind === 'knowledge' && ctx.knowledgeId) {
100 return await processKnowledgeFromDb(
101 ctx.knowledgeId,
102 userId,
103 ctx.label ? `@${ctx.label}` : '@',
104 currentWorkspaceId
105 )
106 }
107 if (ctx.kind === 'blocks' && ctx.blockIds?.length > 0) {
108 return await processBlockMetadata(
109 ctx.blockIds[0],
110 ctx.label ? `@${ctx.label}` : '@',
111 userId,
112 currentWorkspaceId
113 )
114 }
115 if (ctx.kind === 'logs' && ctx.executionId) {
116 return await processExecutionLogFromDb(
117 ctx.executionId,
118 userId,
119 ctx.label ? `@${ctx.label}` : '@',
120 currentWorkspaceId
121 )

Callers 3

resolveAgentContextsFunction · 0.90
route.tsFile · 0.90

Calls 15

processSkillFromDbFunction · 0.85
processPastChatFromDbFunction · 0.85
processWorkflowFromDbFunction · 0.85
processKnowledgeFromDbFunction · 0.85
processBlockMetadataFunction · 0.85
resolveTableResourceFunction · 0.85
resolveFileResourceFunction · 0.85
resolveFolderResourceFunction · 0.85

Tested by

no test coverage detected