MCPcopy
hub / github.com/simstudioai/sim / executeImport

Function executeImport

apps/sim/lib/copilot/tools/handlers/materialize-file.ts:80–188  ·  view source on GitHub ↗
(
  fileName: string,
  chatId: string,
  workspaceId: string,
  userId: string
)

Source from the content-addressed store, hash-verified

78}
79
80async function executeImport(
81 fileName: string,
82 chatId: string,
83 workspaceId: string,
84 userId: string
85): Promise<ToolCallResult> {
86 const row = await findMothershipUploadRowByChatAndName(chatId, fileName)
87 if (!row) {
88 return {
89 success: false,
90 error: `Upload not found: "${fileName}". Use glob("uploads/*") to list available uploads.`,
91 }
92 }
93
94 const buffer = await fetchWorkspaceFileBuffer(toFileRecord(row))
95 const content = buffer.toString('utf-8')
96
97 let parsed: unknown
98 try {
99 parsed = JSON.parse(content)
100 } catch {
101 return { success: false, error: `"${fileName}" is not valid JSON.` }
102 }
103
104 const { data: workflowData, errors } = parseWorkflowJson(content)
105 if (!workflowData || errors.length > 0) {
106 return {
107 success: false,
108 error: `Invalid workflow JSON: ${errors.join(', ')}`,
109 }
110 }
111
112 const { name: rawName, description: workflowDescription } = extractWorkflowMetadata(parsed)
113
114 const workflowId = generateId()
115 const now = new Date()
116 const dedupedName = await deduplicateWorkflowName(rawName, workspaceId, null)
117
118 await db.insert(workflow).values({
119 id: workflowId,
120 userId,
121 workspaceId,
122 folderId: null,
123 name: dedupedName,
124 description: workflowDescription,
125 lastSynced: now,
126 createdAt: now,
127 updatedAt: now,
128 isDeployed: false,
129 runCount: 0,
130 variables: {},
131 })
132
133 const saveResult = await saveWorkflowToNormalizedTables(workflowId, workflowData)
134 if (!saveResult.success) {
135 await db.delete(workflow).where(eq(workflow.id, workflowId))
136 return { success: false, error: `Failed to save workflow state: ${saveResult.error}` }
137 }

Callers 1

executeMaterializeFileFunction · 0.85

Calls 15

fetchWorkspaceFileBufferFunction · 0.90
parseWorkflowJsonFunction · 0.90
extractWorkflowMetadataFunction · 0.90
generateIdFunction · 0.90
deduplicateWorkflowNameFunction · 0.90
recordAuditFunction · 0.90
toFileRecordFunction · 0.85
parseMethod · 0.80
joinMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected