@@ -31,7 +31,7 @@ import {
3131 ElementValue ,
3232 TextReference ,
3333} from 'golem:agent/common@1.5.0' ;
34- import { RemoteMethod } from '../baseAgent' ;
34+ import { BaseAgent , RemoteMethod } from '../baseAgent' ;
3535import { AgentMethodParamRegistry } from './registry/agentMethodParamRegistry' ;
3636import { AgentConstructorParamRegistry } from './registry/agentConstructorParamRegistry' ;
3737import { AgentMethodRegistry } from './registry/agentMethodRegistry' ;
@@ -40,19 +40,20 @@ import {
4040 serializeTsValueToTextReference ,
4141} from './mapping/values/serializer' ;
4242import { TypeInfoInternal } from './typeInfoInternal' ;
43- import {
44- deserializeDataValue ,
45- ParameterDetail ,
46- serializeToDataValue ,
47- } from './mapping/values/dataValue' ;
43+ import { deserializeDataValue , serializeToDataValue } from './mapping/values/dataValue' ;
4844import { randomUuid } from '../host/hostapi' ;
4945import { AgentId } from '../agentId' ;
5046import * as util from 'node:util' ;
5147
52- export function getRemoteClient < T extends new ( ...args : any [ ] ) => any > (
48+ type AgentClass < T extends BaseAgent = BaseAgent > = {
49+ readonly name : string ;
50+ readonly prototype : T ;
51+ } ;
52+
53+ export function getRemoteClient (
5354 agentClassName : AgentClassName ,
5455 agentType : AgentType ,
55- ctor : T ,
56+ ctor : AgentClass ,
5657) {
5758 const metadata = TypeMetadata . get ( ctor . name ) ;
5859
@@ -63,7 +64,7 @@ export function getRemoteClient<T extends new (...args: any[]) => any>(
6364 }
6465 const shared = new WasmRpxProxyHandlerShared ( metadata , agentClassName , agentType ) ;
6566
66- return ( ...args : any [ ] ) => {
67+ return ( ...args : unknown [ ] ) => {
6768 const instance = Object . create ( ctor . prototype ) ;
6869
6970 const constructedId = shared . constructAgentId ( args ) ;
@@ -72,10 +73,10 @@ export function getRemoteClient<T extends new (...args: any[]) => any>(
7273 } ;
7374}
7475
75- export function getPhantomRemoteClient < T extends new ( phantomId : Uuid , ... args : any [ ] ) => any > (
76+ export function getPhantomRemoteClient (
7677 agentClassName : AgentClassName ,
7778 agentType : AgentType ,
78- ctor : T ,
79+ ctor : AgentClass ,
7980) {
8081 const metadata = TypeMetadata . get ( ctor . name ) ;
8182
@@ -87,7 +88,7 @@ export function getPhantomRemoteClient<T extends new (phantomId: Uuid, ...args:
8788
8889 const shared = new WasmRpxProxyHandlerShared ( metadata , agentClassName , agentType ) ;
8990
90- return ( finalPhantomId : Uuid , ...args : any [ ] ) => {
91+ return ( finalPhantomId : Uuid , ...args : unknown [ ] ) => {
9192 const instance = Object . create ( ctor . prototype ) ;
9293
9394 const constructedId = shared . constructAgentId ( args , finalPhantomId ) ;
@@ -96,10 +97,10 @@ export function getPhantomRemoteClient<T extends new (phantomId: Uuid, ...args:
9697 } ;
9798}
9899
99- export function getNewPhantomRemoteClient < T extends new ( ... args : any [ ] ) => any > (
100+ export function getNewPhantomRemoteClient (
100101 agentClassName : AgentClassName ,
101102 agentType : AgentType ,
102- ctor : T ,
103+ ctor : AgentClass ,
103104) {
104105 const metadata = TypeMetadata . get ( ctor . name ) ;
105106
@@ -110,7 +111,7 @@ export function getNewPhantomRemoteClient<T extends new (...args: any[]) => any>
110111 }
111112 const shared = new WasmRpxProxyHandlerShared ( metadata , agentClassName , agentType ) ;
112113
113- return ( ...args : any [ ] ) => {
114+ return ( ...args : unknown [ ] ) => {
114115 const instance = Object . create ( ctor . prototype ) ;
115116
116117 const finalPhantomId = randomUuid ( ) ;
@@ -166,7 +167,7 @@ class WasmRpxProxyHandlerShared {
166167 }
167168 }
168169
169- constructAgentId ( args : any [ ] , phantomId ?: Uuid ) : ConstructedAgentId {
170+ constructAgentId ( args : unknown [ ] , phantomId ?: Uuid ) : ConstructedAgentId {
170171 let constructorDataValue : DataValue ;
171172
172173 if ( args . length === 1 && this . constructorParamTypes [ 0 ] . tag === 'multimodal' ) {
@@ -289,12 +290,12 @@ class WasmRpxProxyHandlerShared {
289290 }
290291}
291292
292- class WasmRpcProxyHandler implements ProxyHandler < any > {
293+ class WasmRpcProxyHandler implements ProxyHandler < Record < string , unknown > > {
293294 private readonly shared : WasmRpxProxyHandlerShared ;
294295 private readonly agentId : AgentId ;
295296 private readonly wasmRpc : WasmRpc ;
296297
297- private readonly methodProxyCache = new Map < string , RemoteMethod < any [ ] , any > > ( ) ;
298+ private readonly methodProxyCache = new Map < string , RemoteMethod < unknown [ ] , unknown > > ( ) ;
298299
299300 private readonly getIdMethod : ( ) => AgentId = ( ) => this . agentId ;
300301 private readonly phantomIdMethod : ( ) => Uuid | undefined = ( ) => {
@@ -314,8 +315,8 @@ class WasmRpcProxyHandler implements ProxyHandler<any> {
314315 ) ;
315316 }
316317
317- get ( target : any , prop : string | symbol ) {
318- const val = target [ prop ] ;
318+ get ( target : Record < string , unknown > , prop : string | symbol ) {
319+ const val = target [ prop . toString ( ) ] ;
319320 const propString = prop . toString ( ) ;
320321
321322 if ( typeof val === 'function' ) {
@@ -349,12 +350,12 @@ class WasmRpcProxyHandler implements ProxyHandler<any> {
349350 return undefined ;
350351 }
351352
352- private createMethodProxy ( prop : string ) : RemoteMethod < any [ ] , any > {
353+ private createMethodProxy ( prop : string ) : RemoteMethod < unknown [ ] , unknown > {
353354 const methodInfo = this . shared . getMethodInfo ( prop ) ;
354355 const agentIdString = this . agentId . value ;
355356 const wasmRpc = this . wasmRpc ;
356357
357- async function invokeAndAwait ( ...fnArgs : any [ ] ) {
358+ async function invokeAndAwait ( ...fnArgs : unknown [ ] ) {
358359 const inputDataValue = serializeArgs ( methodInfo . params , fnArgs ) ;
359360
360361 const rpcResultFuture = wasmRpc . asyncInvokeAndAwait ( methodInfo . name , inputDataValue ) ;
@@ -383,26 +384,29 @@ class WasmRpcProxyHandler implements ProxyHandler<any> {
383384 return deserializeRpcResult ( resultDataValue , methodInfo . returnType ) ;
384385 }
385386
386- function invokeFireAndForget ( ...fnArgs : any [ ] ) {
387+ function invokeFireAndForget ( ...fnArgs : unknown [ ] ) {
387388 const inputDataValue = serializeArgs ( methodInfo . params , fnArgs ) ;
388389 wasmRpc . invoke ( methodInfo . name , inputDataValue ) ;
389390 }
390391
391- function invokeSchedule ( ts : Datetime , ...fnArgs : any [ ] ) {
392+ function invokeSchedule ( ts : Datetime , ...fnArgs : unknown [ ] ) {
392393 const inputDataValue = serializeArgs ( methodInfo . params , fnArgs ) ;
393394 wasmRpc . scheduleInvocation ( ts , methodInfo . name , inputDataValue ) ;
394395 }
395396
396- const methodFn : any = ( ...args : any [ ] ) => invokeAndAwait ( ...args ) ;
397-
398- methodFn . trigger = ( ...args : any [ ] ) => invokeFireAndForget ( ...args ) ;
399- methodFn . schedule = ( ts : Datetime , ...args : any [ ] ) => invokeSchedule ( ts , ...args ) ;
397+ const methodFn : RemoteMethod < unknown [ ] , unknown > = Object . assign (
398+ ( ...args : unknown [ ] ) => invokeAndAwait ( ...args ) ,
399+ {
400+ trigger : ( ...args : unknown [ ] ) => invokeFireAndForget ( ...args ) ,
401+ schedule : ( ts : Datetime , ...args : unknown [ ] ) => invokeSchedule ( ts , ...args ) ,
402+ } ,
403+ ) ;
400404
401- return methodFn as RemoteMethod < any [ ] , any > ;
405+ return methodFn ;
402406 }
403407}
404408
405- function serializeArgs ( params : CachedParamInfo [ ] , fnArgs : any [ ] ) : DataValue {
409+ function serializeArgs ( params : CachedParamInfo [ ] , fnArgs : unknown [ ] ) : DataValue {
406410 const elementValues : ElementValue [ ] = [ ] ;
407411 for ( const [ index , fnArg ] of fnArgs . entries ( ) ) {
408412 const param = params [ index ] ;
@@ -441,14 +445,8 @@ function serializeArgs(params: CachedParamInfo[], fnArgs: any[]): DataValue {
441445 `Failed to serialize multimodal arg ${ param . name } : ${ dataValueEither . val } ` ,
442446 ) ;
443447 }
444- // For a multimodal param, the serialized DataValue is itself the result;
445- // we wrap it as a single tuple with the multimodal elements
446448 const multimodalDv = dataValueEither . val ;
447449 if ( multimodalDv . tag === 'multimodal' ) {
448- // Each multimodal element becomes part of the overall DataValue
449- // But since params are tuple-based, we need to wrap multimodal as a single element
450- // The server expects each param as an ElementValue in the tuple
451- // For multimodal, we serialize the whole thing as a component-model WitValue
452450 for ( const [ , ev ] of multimodalDv . val ) {
453451 elementValues . push ( ev ) ;
454452 }
@@ -464,7 +462,10 @@ function serializeArgs(params: CachedParamInfo[], fnArgs: any[]): DataValue {
464462 return { tag : 'tuple' , val : elementValues } ;
465463}
466464
467- function deserializeRpcResult ( resultDataValue : DataValue , typeInfoInternal : TypeInfoInternal ) : any {
465+ function deserializeRpcResult < T = unknown > (
466+ resultDataValue : DataValue ,
467+ typeInfoInternal : TypeInfoInternal ,
468+ ) : T {
468469 return Either . getOrThrowWith (
469470 deserializeDataValue (
470471 resultDataValue ,
@@ -477,5 +478,5 @@ function deserializeRpcResult(resultDataValue: DataValue, typeInfoInternal: Type
477478 { tag : 'anonymous' } ,
478479 ) ,
479480 ( err ) => new Error ( `Failed to deserialize return value of RPC call: ${ err } ` ) ,
480- ) [ 0 ] ;
481+ ) [ 0 ] as T ;
481482}
0 commit comments