(obj: Record<string, any>, contextLabel: string)
| 224 | const resolvedInputs = { ...inputs }; |
| 225 | |
| 226 | async function unspill(obj: Record<string, any>, contextLabel: string) { |
| 227 | for (const [key, value] of Object.entries(obj)) { |
| 228 | if (isSpilledDataMarker(value)) { |
| 229 | if (!globalStorage) { |
| 230 | console.warn( |
| 231 | `[Activity] ${contextLabel} '${key}' is spilled but no storage service is available`, |
| 232 | ); |
| 233 | continue; |
| 234 | } |
| 235 | |
| 236 | try { |
| 237 | let fullData: any; |
| 238 | if (spilledObjectsCache.has(value.storageRef)) { |
| 239 | fullData = spilledObjectsCache.get(value.storageRef); |
| 240 | } else { |
| 241 | const content = await globalStorage.downloadFile(value.storageRef); |
| 242 | fullData = JSON.parse(content.buffer.toString('utf8')); |
| 243 | spilledObjectsCache.set(value.storageRef, fullData); |
| 244 | } |
| 245 | |
| 246 | const handle = (value as any).__spilled_handle__; |
| 247 | if (handle && handle !== '__self__') { |
| 248 | if ( |
| 249 | fullData && |
| 250 | typeof fullData === 'object' && |
| 251 | Object.prototype.hasOwnProperty.call(fullData, handle) |
| 252 | ) { |
| 253 | obj[key] = fullData[handle]; |
| 254 | } else { |
| 255 | console.warn( |
| 256 | `[Activity] Spilled handle '${handle}' not found in downloaded data for ${contextLabel.toLowerCase()} '${key}'`, |
| 257 | ); |
| 258 | obj[key] = undefined; |
| 259 | warningsToReport.push({ |
| 260 | target: key, |
| 261 | sourceRef: 'spilled-storage', |
| 262 | sourceHandle: String(handle), |
| 263 | }); |
| 264 | } |
| 265 | } else { |
| 266 | obj[key] = fullData; |
| 267 | } |
| 268 | } catch (err) { |
| 269 | console.error( |
| 270 | `[Activity] Failed to resolve spilled ${contextLabel.toLowerCase()} '${key}':`, |
| 271 | err, |
| 272 | ); |
| 273 | throw ApplicationFailure.retryable( |
| 274 | `Failed to resolve spilled ${contextLabel.toLowerCase()} '${key}': ${err instanceof Error ? err.message : String(err)}`, |
| 275 | 'SpillResolutionError', |
| 276 | ); |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | await unspill(resolvedParams, 'Parameter'); |
| 283 | await unspill(resolvedInputs, 'Input'); |
no test coverage detected