@@ -22,12 +22,12 @@ import {
2222 SUPPORTED_NODEJS_VERSION ,
2323} from '../lib/consts.js' ;
2424import { execWithLog } from '../lib/exec.js' ;
25- import { deleteFile } from '../lib/files.js' ;
2625import { useActorConfig } from '../lib/hooks/useActorConfig.js' ;
2726import { ProjectLanguage , useCwdProject } from '../lib/hooks/useCwdProject.js' ;
2827import { useModuleVersion } from '../lib/hooks/useModuleVersion.js' ;
2928import { CRAWLEE_INPUT_KEY_ENV , resolveInputKey , TEMP_INPUT_KEY_PREFIX } from '../lib/input-key.js' ;
3029import { getAjvValidator , getDefaultsFromInputSchema , readInputSchema } from '../lib/input_schema.js' ;
30+ import { deleteKvsRecord , writeKvsRecord } from '../lib/kvs-metadata.js' ;
3131import { error , info , warning } from '../lib/outputs.js' ;
3232import { replaceSecretsValue } from '../lib/secrets.js' ;
3333import {
@@ -39,6 +39,7 @@ import {
3939 getLocalUserInfo ,
4040 isNodeVersionSupported ,
4141 isPythonVersionSupported ,
42+ type LocalInput ,
4243 purgeDefaultDataset ,
4344 purgeDefaultKeyValueStore ,
4445 purgeDefaultQueue ,
@@ -50,13 +51,27 @@ interface TempInputResult {
5051}
5152
5253interface OverwrittenInputResult {
53- existingInput : ReturnType < typeof getLocalInput > ;
54+ existingInput : LocalInput | undefined ;
55+ inputKey : string ;
5456 inputFilePath : string ;
5557 writtenAt : number ;
5658}
5759
5860type ValidateAndStoreInputResult = TempInputResult | OverwrittenInputResult ;
5961
62+ /**
63+ * Write the input as a record, so a storage client resolves the bare key to `<key>.json`
64+ * through the sidecar instead of probing extensions.
65+ */
66+ const writeInputRecord = async ( storePath : string , key : string , input : Record < string , unknown > ) =>
67+ writeKvsRecord ( {
68+ storePath,
69+ key,
70+ fileName : `${ key } .json` ,
71+ contentType : 'application/json; charset=utf-8' ,
72+ body : JSON . stringify ( input , null , 2 ) ,
73+ } ) ;
74+
6075enum RunType {
6176 DirectFile = 0 ,
6277 Module = 1 ,
@@ -456,8 +471,8 @@ export class RunCommand extends ApifyCommand<typeof RunCommand> {
456471 } finally {
457472 if ( storedInputResults ) {
458473 if ( 'tempInputKey' in storedInputResults ) {
459- // Temp input file : just delete it, user's INPUT.json was never touched
460- await deleteFile ( storedInputResults . tempInputFilePath ) ;
474+ // Temp input record : just delete it, user's INPUT.json was never touched
475+ await deleteKvsRecord ( storedInputResults . tempInputFilePath , storedInputResults . tempInputKey ) ;
461476 } else if ( storedInputResults . existingInput ) {
462477 // Check if the input file was modified since we modified it. If it was, we abort the re-overwrite and warn the user
463478 const stats = await stat ( storedInputResults . inputFilePath ) ;
@@ -478,7 +493,7 @@ export class RunCommand extends ApifyCommand<typeof RunCommand> {
478493 await writeFile ( storedInputResults . inputFilePath , storedInputResults . existingInput . body ) ;
479494 } else {
480495 // No file -> we made it -> we delete it
481- await deleteFile ( storedInputResults . inputFilePath ) ;
496+ await deleteKvsRecord ( storedInputResults . inputFilePath , storedInputResults . inputKey ) ;
482497 }
483498 }
484499 }
@@ -511,7 +526,7 @@ export class RunCommand extends ApifyCommand<typeof RunCommand> {
511526 const tempInputKey = `${ TEMP_INPUT_KEY_PREFIX } ${ resolvedInputKey } ` ;
512527 const tempInputFilePath = join ( localStorePath , `${ tempInputKey } .json` ) ;
513528
514- await writeFile ( tempInputFilePath , JSON . stringify ( inputOverride . input , null , 2 ) ) ;
529+ await writeInputRecord ( localStorePath , tempInputKey , inputOverride . input ) ;
515530
516531 return {
517532 tempInputKey,
@@ -570,7 +585,7 @@ export class RunCommand extends ApifyCommand<typeof RunCommand> {
570585 const tempInputFilePath = join ( localStorePath , `${ tempInputKey } .json` ) ;
571586
572587 await mkdir ( localStorePath , { recursive : true } ) ;
573- await writeFile ( tempInputFilePath , JSON . stringify ( fullInputOverride , null , 2 ) ) ;
588+ await writeInputRecord ( localStorePath , tempInputKey , fullInputOverride ) ;
574589
575590 return {
576591 tempInputKey,
@@ -581,10 +596,11 @@ export class RunCommand extends ApifyCommand<typeof RunCommand> {
581596 if ( ! existingInput ) {
582597 await mkdir ( localStorePath , { recursive : true } ) ;
583598 // No input -> use defaults for this run
584- await writeFile ( inputFilePath , JSON . stringify ( defaults , null , 2 ) ) ;
599+ await writeInputRecord ( localStorePath , resolvedInputKey , defaults ) ;
585600
586601 return {
587602 existingInput,
603+ inputKey : resolvedInputKey ,
588604 inputFilePath,
589605 writtenAt : Date . now ( ) ,
590606 } ;
@@ -616,7 +632,7 @@ export class RunCommand extends ApifyCommand<typeof RunCommand> {
616632 const tempInputKey = `${ TEMP_INPUT_KEY_PREFIX } ${ resolvedInputKey } ` ;
617633 const tempInputFilePath = join ( localStorePath , `${ tempInputKey } .json` ) ;
618634
619- await writeFile ( tempInputFilePath , JSON . stringify ( fullInput , null , 2 ) ) ;
635+ await writeInputRecord ( localStorePath , tempInputKey , fullInput ) ;
620636
621637 return {
622638 tempInputKey,
0 commit comments