(name: string, input: string, parentIds?: ICommonObject)
| 914 | } |
| 915 | |
| 916 | async onChainStart(name: string, input: string, parentIds?: ICommonObject) { |
| 917 | const returnIds: ICommonObject = { |
| 918 | langSmith: {}, |
| 919 | langFuse: {}, |
| 920 | lunary: {}, |
| 921 | langWatch: {}, |
| 922 | arize: {}, |
| 923 | phoenix: {}, |
| 924 | opik: {} |
| 925 | } |
| 926 | |
| 927 | if (Object.prototype.hasOwnProperty.call(this.handlers, 'langSmith')) { |
| 928 | if (!parentIds || !Object.keys(parentIds).length) { |
| 929 | const parentRunConfig: RunTreeConfig = { |
| 930 | name, |
| 931 | run_type: 'chain', |
| 932 | inputs: { |
| 933 | text: input |
| 934 | }, |
| 935 | serialized: {}, |
| 936 | project_name: this.handlers['langSmith'].langSmithProject, |
| 937 | client: this.handlers['langSmith'].client, |
| 938 | ...this.nodeData?.inputs?.analytics?.langSmith |
| 939 | } |
| 940 | const parentRun = new RunTree(parentRunConfig) |
| 941 | await parentRun.postRun() |
| 942 | // Merge rather than replace: AnalyticHandler is a per-chatId singleton, so recursive |
| 943 | // executeAgentFlow calls (e.g. iterationAgentflow) re-enter onChainStart on the same |
| 944 | // instance. Replacing would drop the outer call's parent entry and orphan its trace. |
| 945 | this.handlers['langSmith'].chainRun = { |
| 946 | ...this.handlers['langSmith'].chainRun, |
| 947 | [parentRun.id]: parentRun |
| 948 | } |
| 949 | returnIds['langSmith'].chainRun = parentRun.id |
| 950 | } else { |
| 951 | const parentRun: RunTree | undefined = this.handlers['langSmith'].chainRun[parentIds['langSmith'].chainRun] |
| 952 | if (parentRun) { |
| 953 | const childChainRun = await parentRun.createChild({ |
| 954 | name, |
| 955 | run_type: 'chain', |
| 956 | inputs: { |
| 957 | text: input |
| 958 | } |
| 959 | }) |
| 960 | await childChainRun.postRun() |
| 961 | this.handlers['langSmith'].chainRun = { |
| 962 | ...this.handlers['langSmith'].chainRun, |
| 963 | [childChainRun.id]: childChainRun |
| 964 | } |
| 965 | returnIds['langSmith'].chainRun = childChainRun.id |
| 966 | } |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | if (Object.prototype.hasOwnProperty.call(this.handlers, 'langFuse')) { |
| 971 | let langfuseTraceClient: LangfuseTraceClient |
| 972 | |
| 973 | if (!parentIds || !Object.keys(parentIds).length) { |
no test coverage detected