@@ -100,7 +100,6 @@ def __init__(
100100 client : Client ,
101101 name : str ,
102102 primitive_func : PrimitiveFunctionType ,
103- func : Callable ,
104103 ):
105104 PrimitiveFunction .__init__ (self , endpoint , client , name , primitive_func )
106105
@@ -158,21 +157,30 @@ def build_call(
158157
159158
160159class Registry :
161- """Registry of local functions."""
160+ """Registry of functions."""
162161
163- __slots__ = ("_functions " , "_endpoint " , "_client " )
162+ __slots__ = ("functions " , "endpoint " , "client " )
164163
165- def __init__ (self , endpoint : str , client : Client ):
166- """Initialize a local function registry.
164+ def __init__ (
165+ self , endpoint : str , api_key : str | None = None , api_url : str | None = None
166+ ):
167+ """Initialize a function registry.
167168
168169 Args:
169170 endpoint: URL of the endpoint that the function is accessible from.
170- client: Client for the Dispatch API. Used to dispatch calls to
171- local functions.
171+
172+ api_key: Dispatch API key to use for authentication when
173+ dispatching calls to functions. Uses the value of the
174+ DISPATCH_API_KEY environment variable by default.
175+
176+ api_url: The URL of the Dispatch API to use when dispatching calls
177+ to functions. Uses the value of the DISPATCH_API_URL environment
178+ variable if set, otherwise defaults to the public Dispatch API
179+ (DEFAULT_API_URL).
172180 """
173- self ._functions : Dict [str , PrimitiveFunction ] = {}
174- self ._endpoint = endpoint
175- self ._client = client
181+ self .functions : Dict [str , PrimitiveFunction ] = {}
182+ self .endpoint = endpoint
183+ self .client = Client ( api_key = api_key , api_url = api_url )
176184
177185 @overload
178186 def function (self , func : Callable [P , Coroutine [Any , Any , T ]]) -> Function [P , T ]: ...
@@ -215,9 +223,7 @@ def primitive_func(input: Input) -> Output:
215223 primitive_func .__qualname__ = f"{ name } _primitive"
216224 primitive_func = durable (primitive_func )
217225
218- wrapped_func = Function [P , T ](
219- self ._endpoint , self ._client , name , primitive_func , func
220- )
226+ wrapped_func = Function [P , T ](self .endpoint , self .client , name , primitive_func )
221227 self ._register (name , wrapped_func )
222228 return wrapped_func
223229
@@ -228,20 +234,20 @@ def primitive_function(
228234 name = primitive_func .__qualname__
229235 logger .info ("registering primitive function: %s" , name )
230236 wrapped_func = PrimitiveFunction (
231- self ._endpoint , self ._client , name , primitive_func
237+ self .endpoint , self .client , name , primitive_func
232238 )
233239 self ._register (name , wrapped_func )
234240 return wrapped_func
235241
236242 def _register (self , name : str , wrapped_func : PrimitiveFunction ):
237- if name in self ._functions :
243+ if name in self .functions :
238244 raise ValueError (f"function already registered with name '{ name } '" )
239- self ._functions [name ] = wrapped_func
245+ self .functions [name ] = wrapped_func
240246
241247 def set_client (self , client : Client ):
242- """Set the Client instance used to dispatch calls to local functions."""
243- self ._client = client
244- for fn in self ._functions .values ():
248+ """Set the Client instance used to dispatch calls to registered functions."""
249+ self .client = client
250+ for fn in self .functions .values ():
245251 fn ._client = client
246252
247253
0 commit comments