(name: string, description: string, inputSchema: Record<string, z.ZodTypeAny>, handler: LegacyHandler)
| 325 | |
| 326 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 327 | function customToolFor(name: string, description: string, inputSchema: Record<string, z.ZodTypeAny>, handler: LegacyHandler): AdcpCustomToolConfig<any, undefined> { |
| 328 | return { |
| 329 | description, |
| 330 | inputSchema, |
| 331 | handler: async (args: unknown, extra: unknown) => { |
| 332 | const params = (args as Record<string, unknown>) ?? {}; |
| 333 | const authInfo = ((extra as { authInfo?: { clientId?: string } } | undefined)?.authInfo) ?? undefined; |
| 334 | const trainingCtx: TrainingContext = { |
| 335 | mode: 'open', |
| 336 | principal: authInfo?.clientId ?? 'anonymous', |
| 337 | }; |
| 338 | const { context: callerContext, ...handlerArgs } = params; |
| 339 | return runWithSessionContext(async () => { |
| 340 | let result: unknown; |
| 341 | try { |
| 342 | result = await Promise.resolve(handler(handlerArgs as ToolArgs, trainingCtx)); |
| 343 | } catch (err) { |
| 344 | logger.error({ err, tool: name }, 'framework custom-tool handler threw'); |
| 345 | return serviceUnavailable(err, callerContext); |
| 346 | } |
| 347 | try { |
| 348 | await flushDirtySessions(); |
| 349 | } catch (err) { |
| 350 | logger.error({ err, tool: name }, 'framework custom-tool flushDirtySessions threw'); |
| 351 | return serviceUnavailable(err, callerContext); |
| 352 | } |
| 353 | return toAdaptedResponse(result, callerContext); |
| 354 | }); |
| 355 | }, |
| 356 | }; |
| 357 | } |
| 358 | |
| 359 | const ACCOUNT_REF = z.object({ |
| 360 | publisher_id: z.string().optional(), |
no test coverage detected