invoke method
Runs handle under a time ceiling and a progress heartbeat; a call that outlives its ceiling is cancelled and answered with toolTimeout.
Implementation
Future<CallToolResult> invoke(
GlintSession session,
CallToolRequest request,
) async {
final call = CallProgress(
tool: definition.name,
token: request.meta?.progressToken,
send: session.rawProgressNotifier,
);
final ceiling = _safeCeiling(session, request.arguments ?? const {});
final answer = Completer<CallToolResult>();
final start = DateTime.now();
unawaited(call.run(() => _invoke(session, request)).then((result) {
if (!answer.isCompleted) answer.complete(result);
}, onError: (Object e, StackTrace st) {
if (!answer.isCompleted) answer.completeError(e, st);
}));
call.watch(
ceiling: ceiling,
heartbeatEvery: heartbeatEvery,
onCeiling: () {
if (answer.isCompleted) return;
final response = _timeoutResponse(call, ceiling, request.arguments ?? const {});
call.run(() => logCall(session, request, response, start));
call.abandon();
answer.complete(response.toCallResult());
},
);
try {
return await answer.future;
} finally {
call.stop();
}
}