22
33import { createHash } from "node:crypto" ;
44
5- import {
6- DataFormat ,
7- DeploymentNamespace ,
8- FunctionPutInputsItem ,
9- } from "../proto/modal_proto/api" ;
5+ import { DataFormat , DeploymentNamespace } from "../proto/modal_proto/api" ;
106import type { LookupOptions } from "./app" ;
117import { client } from "./client" ;
128import { FunctionCall } from "./function_call" ;
@@ -18,6 +14,8 @@ import {
1814 ControlPlaneStrategy ,
1915 GetOutput ,
2016 getOutputsFromControlPlane ,
17+ InputPlaneStrategy ,
18+ InvocationStrategy ,
2119 pollForOutputs ,
2220} from "./invocation_strategy" ;
2321
@@ -28,11 +26,13 @@ const maxObjectSizeBytes = 2 * 1024 * 1024; // 2 MiB
2826export class Function_ {
2927 readonly functionId : string ;
3028 readonly methodName : string | undefined ;
29+ private readonly inputPlaneUrl : string | undefined ;
3130
3231 /** @ignore */
33- constructor ( functionId : string , methodName ?: string ) {
32+ constructor ( functionId : string , methodName ?: string , inputPlaneUrl ?: string ) {
3433 this . functionId = functionId ;
3534 this . methodName = methodName ;
35+ this . inputPlaneUrl = inputPlaneUrl ;
3636 }
3737
3838 static async lookup (
@@ -47,7 +47,11 @@ export class Function_ {
4747 namespace : DeploymentNamespace . DEPLOYMENT_NAMESPACE_WORKSPACE ,
4848 environmentName : environmentName ( options . environment ) ,
4949 } ) ;
50- return new Function_ ( resp . functionId ) ;
50+ return new Function_ (
51+ resp . functionId ,
52+ undefined ,
53+ resp . handleMetadata ?. inputPlaneUrl ,
54+ ) ;
5155 } catch ( err ) {
5256 if ( err instanceof ClientError && err . code === Status . NOT_FOUND )
5357 throw new NotFoundError ( `Function '${ appName } /${ name } ' not found` ) ;
@@ -60,8 +64,10 @@ export class Function_ {
6064 args : any [ ] = [ ] ,
6165 kwargs : Record < string , any > = { } ,
6266 ) : Promise < any > {
63- const input = await this . #createInput( args , kwargs ) ;
64- const invocationStrategy = new ControlPlaneStrategy ( this . functionId , input ) ;
67+ const invocationStrategy = await this . #createInvocationStrategy(
68+ args ,
69+ kwargs ,
70+ ) ;
6571 return await invocationStrategy . remote ( ) ;
6672 }
6773
@@ -70,16 +76,18 @@ export class Function_ {
7076 args : any [ ] = [ ] ,
7177 kwargs : Record < string , any > = { } ,
7278 ) : Promise < FunctionCall > {
73- const input = await this . #createInput( args , kwargs ) ;
74- const invocationStrategy = new ControlPlaneStrategy ( this . functionId , input ) ;
79+ const invocationStrategy = await this . #createInvocationStrategy(
80+ args ,
81+ kwargs ,
82+ ) ;
7583 const functionCallId = await invocationStrategy . spawn ( ) ;
7684 return new FunctionCall ( functionCallId ) ;
7785 }
7886
79- async #createInput (
87+ async #createInvocationStrategy (
8088 args : any [ ] = [ ] ,
8189 kwargs : Record < string , any > = { } ,
82- ) : Promise < FunctionPutInputsItem > {
90+ ) : Promise < InvocationStrategy > {
8391 const payload = dumps ( [ args , kwargs ] ) ;
8492
8593 let argsBlobId : string | undefined = undefined ;
@@ -88,7 +96,7 @@ export class Function_ {
8896 }
8997
9098 // Single input sync invocation
91- return {
99+ const input = {
92100 idx : 0 ,
93101 input : {
94102 args : argsBlobId ? undefined : payload ,
@@ -98,6 +106,11 @@ export class Function_ {
98106 finalInput : false , // This field isn't specified in the Python client, so it defaults to false.
99107 } ,
100108 } ;
109+ if ( this . inputPlaneUrl ) {
110+ return new InputPlaneStrategy ( this . functionId , this . inputPlaneUrl , input ) ;
111+ }
112+
113+ return new ControlPlaneStrategy ( this . functionId , input ) ;
101114 }
102115}
103116
0 commit comments