MCPcopy Create free account
hub / github.com/ShipSecAI/studio / execute

Function execute

worker/src/components/core/artifact-writer.ts:160–235  ·  view source on GitHub ↗
({ inputs, params }, context)

Source from the content-addressed store, hash-verified

158 },
159 },
160 async execute({ inputs, params }, context) {
161 const destinations: ('run' | 'library')[] = [];
162 if (params.saveToRunArtifacts) {
163 destinations.push('run');
164 }
165 if (params.publishToArtifactLibrary) {
166 destinations.push('library');
167 }
168
169 // Resolve artifact name with dynamic placeholders
170 const artifactNameTemplate = inputs.artifactName || '{{run_id}}-{{timestamp}}';
171 const resolvedArtifactName = substituteArtifactName(artifactNameTemplate, {
172 runId: context.runId,
173 componentRef: context.componentRef,
174 });
175
176 // Build full filename with extension
177 const extension = params.fileExtension || '.txt';
178 const fileName = resolvedArtifactName.endsWith(extension)
179 ? resolvedArtifactName
180 : `${resolvedArtifactName}${extension}`;
181
182 // Serialize content to string - if already a string, use as-is; otherwise JSON stringify
183 const rawContent = inputs.content;
184 let serializedContent: string;
185 if (rawContent === undefined || rawContent === null) {
186 serializedContent = '';
187 } else if (typeof rawContent === 'string') {
188 serializedContent = rawContent;
189 } else {
190 // Serialize arrays, objects, and other types to JSON
191 serializedContent = JSON.stringify(rawContent, null, 2);
192 }
193
194 if (destinations.length === 0) {
195 context.logger.info('[ArtifactWriter] No destinations selected; skipping upload.');
196 return {
197 artifactId: undefined,
198 artifactName: resolvedArtifactName,
199 fileName,
200 size: Buffer.byteLength(serializedContent),
201 destinations: [],
202 saved: false,
203 };
204 }
205
206 if (!context.artifacts) {
207 throw new ConfigurationError(
208 'Artifact service is not available in this execution environment. Ensure the worker is configured with artifact storage.',
209 { configKey: 'artifacts' },
210 );
211 }
212
213 const buffer = Buffer.from(serializedContent, 'utf-8');
214 context.logger.info(
215 `[ArtifactWriter] Uploading '${fileName}' (${buffer.byteLength} bytes) to ${destinations.join(
216 ', ',
217 )}`,

Callers

nothing calls this directly

Calls 5

substituteArtifactNameFunction · 0.85
infoMethod · 0.80
fromMethod · 0.80
uploadMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected