(call: JobMessage)
| 136 | } |
| 137 | |
| 138 | private async processCall(call: JobMessage): Promise<void> { |
| 139 | const registration = this.tools.find((fn) => fn.name === call.function); |
| 140 | |
| 141 | if (!registration) { |
| 142 | log("Received call for unknown function", { |
| 143 | function: call.function, |
| 144 | }); |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | log("Executing job", { |
| 149 | id: call.id, |
| 150 | function: call.function, |
| 151 | registered: !!registration, |
| 152 | }); |
| 153 | |
| 154 | const onComplete = async (result: Result) => { |
| 155 | log("Persisting job result", { |
| 156 | id: call.id, |
| 157 | function: call.function, |
| 158 | resultType: result.type, |
| 159 | functionExecutionTime: result.functionExecutionTime, |
| 160 | }); |
| 161 | |
| 162 | await this.client |
| 163 | .createJobResult({ |
| 164 | body: { |
| 165 | result: result.content, |
| 166 | resultType: result.type, |
| 167 | meta: { |
| 168 | functionExecutionTime: result.functionExecutionTime, |
| 169 | }, |
| 170 | }, |
| 171 | params: { |
| 172 | jobId: call.id, |
| 173 | clusterId: this.clusterId!, |
| 174 | }, |
| 175 | }) |
| 176 | .then(async (res) => { |
| 177 | if (res.status === 204) { |
| 178 | log("Completed job", call.id, call.function); |
| 179 | } else { |
| 180 | throw new AgentRPCError(`Failed to persist call: ${res.status}`, { |
| 181 | jobId: call.id, |
| 182 | body: JSON.stringify(res.body), |
| 183 | }); |
| 184 | } |
| 185 | }); |
| 186 | }; |
| 187 | |
| 188 | const args = call.input; |
| 189 | |
| 190 | log("Executing fn", { |
| 191 | id: call.id, |
| 192 | function: call.function, |
| 193 | registeredFn: registration.handler, |
| 194 | args, |
| 195 | }); |
no test coverage detected