@@ -8,10 +8,31 @@ import {
88import { load } from "../load/index.js" ;
99import { getChatModelByClassName } from "../chat_models/universal.js" ;
1010
11- // TODO: Make this the default, add web entrypoint in next breaking release
12-
1311export { basePush as push } from "./base.js" ;
1412
13+ function _idEquals ( a : string [ ] , b : string [ ] ) : boolean {
14+ if ( ! Array . isArray ( a ) || ! Array . isArray ( b ) ) {
15+ return false ;
16+ }
17+ if ( a . length !== b . length ) {
18+ return false ;
19+ }
20+ for ( let i = 0 ; i < a . length ; i ++ ) {
21+ if ( a [ i ] !== b [ i ] ) {
22+ return false ;
23+ }
24+ }
25+ return true ;
26+ }
27+
28+ function isRunnableBinding ( a : string [ ] ) : boolean {
29+ const wellKnownIds = [
30+ [ "langchain_core" , "runnables" , "RunnableBinding" ] ,
31+ [ "langchain" , "schema" , "runnable" , "RunnableBinding" ] ,
32+ ] ;
33+ return wellKnownIds . some ( ( id ) => _idEquals ( a , id ) ) ;
34+ }
35+
1536/**
1637 * Pull a prompt from the hub.
1738 * @param ownerRepoCommit The name of the repo containing the prompt, as well as an optional commit hash separated by a slash.
@@ -33,9 +54,14 @@ export async function pull<T extends Runnable>(
3354 const promptObject = await basePull ( ownerRepoCommit , options ) ;
3455 let modelClass ;
3556 if ( options ?. includeModel ) {
36- if ( Array . isArray ( promptObject . manifest . kwargs ?. last ?. kwargs ?. bound ?. id ) ) {
37- const modelName =
38- promptObject . manifest . kwargs ?. last ?. kwargs ?. bound ?. id . at ( - 1 ) ;
57+ const chatModelObject = isRunnableBinding (
58+ promptObject . manifest . kwargs ?. last ?. id
59+ )
60+ ? promptObject . manifest . kwargs ?. last ?. kwargs ?. bound
61+ : promptObject . manifest . kwargs ?. last ;
62+
63+ if ( Array . isArray ( chatModelObject ?. id ) ) {
64+ const modelName = chatModelObject ?. id . at ( - 1 ) ;
3965
4066 if ( modelName ) {
4167 modelClass = await getChatModelByClassName ( modelName ) ;
0 commit comments