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

Function buildWorkspaceMd

apps/sim/lib/copilot/chat/workspace-context.ts:117–307  ·  view source on GitHub ↗
(data: WorkspaceMdData)

Source from the content-addressed store, hash-verified

115 * is what lets the mothership cache it in the prompt prefix across turns.
116 */
117export function buildWorkspaceMd(data: WorkspaceMdData): string {
118 const sections: string[] = []
119
120 if (data.workspace) {
121 sections.push(
122 `## Workspace\n- **Name**: ${data.workspace.name}\n- **ID**: ${data.workspace.id}\n- **Owner**: ${data.workspace.ownerId}`
123 )
124 }
125
126 if (data.members.length > 0) {
127 const lines = [...data.members]
128 .sort((a, b) => stableCompare(a.email, b.email))
129 .map((m) => {
130 const display = m.name ? `${m.name} (${m.email})` : m.email
131 return `- ${display} — ${m.permissionType}`
132 })
133 sections.push(`## Members\n${lines.join('\n')}`)
134 }
135
136 if (data.workflows.length > 0) {
137 const rootWorkflows: typeof data.workflows = []
138 const folderWorkflows = new Map<string, typeof data.workflows>()
139
140 for (const wf of data.workflows) {
141 if (wf.folderPath) {
142 const existing = folderWorkflows.get(wf.folderPath) ?? []
143 existing.push(wf)
144 folderWorkflows.set(wf.folderPath, existing)
145 } else {
146 rootWorkflows.push(wf)
147 }
148 }
149
150 const formatWf = (wf: (typeof data.workflows)[0], indent: string) => {
151 const parts = [`${indent}- **${wf.name}** (${wf.id})`]
152 const workflowDir = canonicalWorkflowVfsDir({ name: wf.name, folderPath: wf.folderPath })
153 parts.push(`${indent} VFS dir: \`${workflowDir}\``)
154 parts.push(`${indent} VFS state path: \`${workflowDir}/state.json\``)
155 if (wf.description) parts.push(`${indent} ${wf.description}`)
156 // `deployed` is a structural flag (kept); `lastRunAt` is intentionally
157 // omitted — it changes on every run and would bust the cached prompt
158 // prefix that carries this inventory. Current run data lives in
159 // workflows/{name}/executions.json.
160 if (wf.isDeployed) parts[0] += ' — deployed'
161 return parts.join('\n')
162 }
163
164 const lines: string[] = []
165 lines.push(
166 'Use the canonical VFS dir/state path shown under each workflow. Paths are percent-encoded per segment; copy them verbatim and do not infer paths from display names.'
167 )
168 for (const wf of [...rootWorkflows].sort(byNameThenId)) {
169 lines.push(formatWf(wf, ''))
170 }
171 const sortedFolders = [...folderWorkflows.entries()].sort((a, b) => stableCompare(a[0], b[0]))
172 for (const [folder, wfs] of sortedFolders) {
173 lines.push(`- 📁 **${folder}/**`)
174 for (const wf of [...wfs].sort(byNameThenId)) {

Callers 5

materializeMethod · 0.90
buildWorkspaceContextMdFunction · 0.85
generateWorkspaceContextFunction · 0.85

Calls 7

stableCompareFunction · 0.85
formatWfFunction · 0.85
fileLineFunction · 0.85
joinMethod · 0.80
getMethod · 0.65
setMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected