@@ -3,7 +3,6 @@ package vibes
33import (
44 "context"
55 "fmt"
6- "strings"
76)
87
98func (s * Script ) Call (ctx context.Context , name string , args []Value , opts CallOptions ) (Value , error ) {
@@ -58,41 +57,8 @@ func (s *Script) Call(ctx context.Context, name string, args []Value, opts CallO
5857 allowRequire : opts .AllowRequire ,
5958 }
6059
61- if len (opts .Capabilities ) > 0 {
62- binding := CapabilityBinding {Context : exec .ctx , Engine : s .engine }
63- for _ , adapter := range opts .Capabilities {
64- if adapter == nil {
65- continue
66- }
67- scope := & capabilityContractScope {
68- contracts : map [string ]CapabilityMethodContract {},
69- }
70- if provider , ok := adapter .(CapabilityContractProvider ); ok {
71- for methodName , contract := range provider .CapabilityContracts () {
72- name := strings .TrimSpace (methodName )
73- if name == "" {
74- return NewNil (), fmt .Errorf ("capability contract method name must be non-empty" )
75- }
76- if _ , exists := exec .capabilityContractsByName [name ]; exists {
77- return NewNil (), fmt .Errorf ("duplicate capability contract for %s" , name )
78- }
79- exec .capabilityContractsByName [name ] = contract
80- scope .contracts [name ] = contract
81- }
82- }
83- globals , err := adapter .Bind (binding )
84- if err != nil {
85- return NewNil (), err
86- }
87- for name , val := range globals {
88- rebound := rebinder .rebindValue (val )
89- root .Define (name , rebound )
90- if len (scope .contracts ) > 0 {
91- scope .roots = append (scope .roots , rebound )
92- }
93- bindCapabilityContracts (rebound , scope , exec .capabilityContracts , exec .capabilityContractScopes )
94- }
95- }
60+ if err := bindCapabilitiesForCall (exec , root , rebinder , opts .Capabilities ); err != nil {
61+ return NewNil (), err
9662 }
9763
9864 if exec .strictEffects {
0 commit comments